mp1parse.c 6.52 KB
Newer Older
1

2
#define BUFFER 20
Wim Taymans's avatar
Wim Taymans committed
3
4
#define VIDEO_DECODER "mpeg_play"

5
#include <gnome.h>
Wim Taymans's avatar
Wim Taymans committed
6
7
8
#include <gst/gst.h>

extern gboolean _gst_plugin_spew;
9
gboolean idle_func(gpointer data);
Wim Taymans's avatar
Wim Taymans committed
10

11
void eof(GstElement *src) {
12
13
  g_print("have eos, quitting\n");
  exit(0);
Wim Taymans's avatar
Wim Taymans committed
14
15
}

16
void new_pad_created(GstElement *parse,GstPad *pad,GstElement *pipeline) {
17
  GstElement *parse_audio, *parse_video, *decode, *decode_video, *play, *videoscale, *show;
18
19
  GstElement *audio_queue, *video_queue;
  GstElement *audio_thread, *video_thread;
20

21
  GtkWidget *appwindow;
22

23
  g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
Wim Taymans's avatar
Wim Taymans committed
24
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PAUSED);
Wim Taymans's avatar
Wim Taymans committed
25
26

  // connect to audio pad
27
  //if (0) {
Wim Taymans's avatar
Wim Taymans committed
28
  if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
29
30
31
32
33
    // construct internal pipeline elements
    parse_audio = gst_elementfactory_make("mp3parse","parse_audio");
    g_return_if_fail(parse_audio != NULL);
    decode = gst_elementfactory_make("mpg123","decode_audio");
    g_return_if_fail(decode != NULL);
34
    play = gst_elementfactory_make("osssink","play_audio");
35
36
37
38
39
40
41
42
43
44
45
    g_return_if_fail(play != NULL);

    // create the thread and pack stuff into it
    audio_thread = gst_thread_new("audio_thread");
    g_return_if_fail(audio_thread != NULL);
    gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(parse_audio));
    gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(decode));
    gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));

    // set up pad connections
    gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
46
                              gst_element_get_pad(parse_audio,"sink"),"sink");
47
48
49
50
51
52
53
    gst_pad_connect(gst_element_get_pad(parse_audio,"src"),
                    gst_element_get_pad(decode,"sink"));
    gst_pad_connect(gst_element_get_pad(decode,"src"),
                    gst_element_get_pad(play,"sink"));

    // construct queue and connect everything in the main pipelie
    audio_queue = gst_elementfactory_make("queue","audio_queue");
Wim Taymans's avatar
Wim Taymans committed
54
    gtk_object_set(GTK_OBJECT(audio_queue),"max_level",BUFFER,NULL);
55
56
57
58
59
60
61
62
63
    gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_queue));
    gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_thread));
    gst_pad_connect(pad,
                    gst_element_get_pad(audio_queue,"sink"));
    gst_pad_connect(gst_element_get_pad(audio_queue,"src"),
                    gst_element_get_pad(audio_thread,"sink"));

    // set up thread state and kick things off
    gtk_object_set(GTK_OBJECT(audio_thread),"create_thread",TRUE,NULL);
Wim Taymans's avatar
Wim Taymans committed
64
    g_print("setting to READY state\n");
65
  } else if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) {
66
  //} else if (0) {
67
68
69
70

    // construct internal pipeline elements
    parse_video = gst_elementfactory_make("mp1videoparse","parse_video");
    g_return_if_fail(parse_video != NULL);
Wim Taymans's avatar
Wim Taymans committed
71
    decode_video = gst_elementfactory_make(VIDEO_DECODER,"decode_video");
72
    g_return_if_fail(decode_video != NULL);
73
74
75
76
77
    videoscale = gst_elementfactory_make("videoscale","videoscale");
    g_return_if_fail(videoscale != NULL);
    gtk_object_set(GTK_OBJECT(videoscale),"width",704, "height", 576,NULL);


78
79
    show = gst_elementfactory_make("videosink","show");
    g_return_if_fail(show != NULL);
80
    //gtk_object_set(GTK_OBJECT(show),"width",640, "height", 480,NULL);
81

82
83
    appwindow = gnome_app_new("MPEG1 player","MPEG1 player");
    gnome_app_set_contents(GNOME_APP(appwindow),
Wim Taymans's avatar
Wim Taymans committed
84
      	        gst_util_get_pointer_arg(GTK_OBJECT(show),"widget"));
85
		gtk_widget_show_all(appwindow);
86
87
88
89
90

    // create the thread and pack stuff into it
    video_thread = gst_thread_new("video_thread");
    g_return_if_fail(video_thread != NULL);
    gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(parse_video));
91
    gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(decode_video));
Wim Taymans's avatar
Wim Taymans committed
92
    //gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(videoscale));
93
    gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(show));
94
95
96

    // set up pad connections
    gst_element_add_ghost_pad(GST_ELEMENT(video_thread),
97
                              gst_element_get_pad(parse_video,"sink"),"sink");
98
    gst_pad_connect(gst_element_get_pad(parse_video,"src"),
99
100
                    gst_element_get_pad(decode_video,"sink"));
    gst_pad_connect(gst_element_get_pad(decode_video,"src"),
101
102
    //                gst_element_get_pad(videoscale,"sink"));
    //gst_pad_connect(gst_element_get_pad(videoscale,"src"),
103
                    gst_element_get_pad(show,"sink"));
104
105
106

    // construct queue and connect everything in the main pipeline
    video_queue = gst_elementfactory_make("queue","video_queue");
Wim Taymans's avatar
Wim Taymans committed
107
    gtk_object_set(GTK_OBJECT(video_queue),"max_level",BUFFER,NULL);
108
109
110
111
112
113
114
115
116
    gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_queue));
    gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_thread));
    gst_pad_connect(pad,
                    gst_element_get_pad(video_queue,"sink"));
    gst_pad_connect(gst_element_get_pad(video_queue,"src"),
                    gst_element_get_pad(video_thread,"sink"));

    // set up thread state and kick things off
    gtk_object_set(GTK_OBJECT(video_thread),"create_thread",TRUE,NULL);
Wim Taymans's avatar
Wim Taymans committed
117
    g_print("setting to READY state\n");
Wim Taymans's avatar
Wim Taymans committed
118
  }
119
  g_print("\n");
Wim Taymans's avatar
Wim Taymans committed
120
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
Wim Taymans's avatar
Wim Taymans committed
121
122
}

Wim Taymans's avatar
Wim Taymans committed
123
int main(int argc,char *argv[]) {
124
  GstElement *pipeline, *src, *parse;
Wim Taymans's avatar
Wim Taymans committed
125
126
127

  g_print("have %d args\n",argc);

128
  //_gst_plugin_spew = TRUE;
Wim Taymans's avatar
Wim Taymans committed
129
  g_thread_init(NULL);
Wim Taymans's avatar
Wim Taymans committed
130
  gst_init(&argc,&argv);
131
	gnome_init("MPEG1 Video player","0.0.1",argc,argv);
Wim Taymans's avatar
Wim Taymans committed
132
133

  pipeline = gst_pipeline_new("pipeline");
Wim Taymans's avatar
Wim Taymans committed
134
  g_return_val_if_fail(pipeline != NULL, -1);
Wim Taymans's avatar
Wim Taymans committed
135

136
  //src = gst_elementfactory_make("disksrc","src");
137
  src = gst_elementfactory_make("disksrc","src");
Wim Taymans's avatar
Wim Taymans committed
138
  g_return_val_if_fail(src != NULL, -1);
Wim Taymans's avatar
Wim Taymans committed
139
140
  gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
  g_print("should be using file '%s'\n",argv[1]);
141
142

  parse = gst_elementfactory_make("mpeg1parse","parse");
Wim Taymans's avatar
Wim Taymans committed
143
  g_return_val_if_fail(parse != NULL, -1);
Wim Taymans's avatar
Wim Taymans committed
144
145
146
147

  gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
  gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));

Wim Taymans's avatar
Wim Taymans committed
148
  gtk_signal_connect(GTK_OBJECT(parse),"new_pad",
149
                      GTK_SIGNAL_FUNC(new_pad_created),pipeline);
Wim Taymans's avatar
Wim Taymans committed
150

Wim Taymans's avatar
Wim Taymans committed
151
152
153
154
155
156
  gtk_signal_connect(GTK_OBJECT(src),"eos",
                      GTK_SIGNAL_FUNC(eof),NULL);

  gst_pad_connect(gst_element_get_pad(src,"src"),
                  gst_element_get_pad(parse,"sink"));

Wim Taymans's avatar
Wim Taymans committed
157
158
159
  g_print("setting to READY state\n");
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_READY);
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
160

Wim Taymans's avatar
Wim Taymans committed
161
  g_print("about to enter loop\n");
Wim Taymans's avatar
Wim Taymans committed
162

163
  g_idle_add(idle_func,pipeline);
164

Wim Taymans's avatar
Wim Taymans committed
165
  gdk_threads_enter();
166
  gtk_main();
Wim Taymans's avatar
Wim Taymans committed
167
168
169
  gdk_threads_leave();

  return 0;
170
171
172
}

gboolean idle_func(gpointer data) {
173
  gst_bin_iterate(GST_BIN(data));
174
  return TRUE;
Wim Taymans's avatar
Wim Taymans committed
175
}