fa3c6337302a953b10715bfd94831e32b8362e4b
[platform/upstream/gstreamer.git] / test / mpeg2parse.c
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4
5 #include <gst/gst.h>
6
7 extern gboolean _gst_plugin_spew;
8
9 static int ac3fd;
10 static gchar *desired_stream;
11
12 void mpeg2parse_write_ac3(GstPad *pad,GstBuffer *buf) {
13   g_print(".");
14 //  g_print("MPEG2PARSE: got AC3 buffer of size %d\n",GST_BUFFER_SIZE(buf));
15   write(ac3fd,GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf));
16   gst_buffer_unref(buf);
17 }
18
19 void mpeg2parse_info_chain(GstPad *pad,GstBuffer *buf) {
20 //  g_print("MPEG2PARSE: got buffer of size %d\n",GST_BUFFER_SIZE(buf));
21   gst_buffer_unref(buf);
22 }
23
24 void mpeg2parse_newpad(GstElement *parser,GstPad *pad) {
25   GstPad *infopad;
26
27   g_print("MPEG2PARSE: have new pad \"%s\" from parser\n",
28           gst_pad_get_name(pad));
29
30   infopad = gst_pad_new("sink",GST_PAD_SINK);
31   if (strcmp(gst_pad_get_name(pad),desired_stream) == 0)
32     gst_pad_set_chain_function(infopad,mpeg2parse_write_ac3);
33   else
34     gst_pad_set_chain_function(infopad,mpeg2parse_info_chain);
35   gst_pad_connect(pad,infopad);
36 }
37
38 int main(int argc,char *argv[]) {
39   GstPipeline *pipeline;
40   GstElement *src, *parse, *out;
41   GstPad *infopad;
42   int i,c;
43
44   g_print("have %d args\n",argc);
45
46   _gst_plugin_spew = TRUE;
47   gst_init(&argc,&argv);
48 //  gst_plugin_load("mpeg2parse");
49   gst_plugin_load_all();
50
51   ac3fd = creat("output.ac3",S_IREAD|S_IWRITE);
52
53   pipeline = gst_pipeline_new("pipeline");
54   g_return_if_fail(pipeline != NULL);
55
56   if (strstr(argv[1],"video_ts")) {
57     src = gst_elementfactory_make("dvdsrc","src");
58     g_print("using DVD source\n");
59   } else
60     src = gst_elementfactory_make("disksrc","src");
61   g_return_if_fail(src != NULL);
62   gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
63   if (argc >= 3) {
64     gtk_object_set(GTK_OBJECT(src),"bytesperread",atoi(argv[2]),NULL);
65     g_print("block size is %d\n",atoi(argv[2]));
66   }
67   g_print("should be using file '%s'\n",argv[1]);
68
69   parse = gst_elementfactory_make("mpeg2parse","parse");
70   g_return_if_fail(parse != NULL);
71
72   gtk_signal_connect(GTK_OBJECT(parse),"new_pad",mpeg2parse_newpad,NULL);
73
74   gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
75   gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));
76
77   gst_pad_connect(gst_element_get_pad(src,"src"),
78                   gst_element_get_pad(parse,"sink"));
79
80   g_print("setting to RUNNING state\n");
81   gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_RUNNING);
82
83   if (argc >= 4) c = atoi(argv[3]);
84   else c = 4;
85   g_print("c is %d\n",c);
86
87   if (argc >= 5) desired_stream = argv[4];
88   else desired_stream = "private_stream_1.0";
89
90   g_print("\n");
91   for (i=0;i<c;i++) {
92     g_print("\n");
93     gst_src_push(GST_SRC(src));
94   }
95 }