#include #include static GMainLoop *loop; GstElement *src, *pipeline, *csp, *venc, *fsink; GstElement *audio_convert, *aenc, *mux, *fsink,*alsa_src,*video_queue,*audio_queue,*audio_bin,*video_bin; GstPad *muxpad,*audio_pad,*video_pad,*mux_video_pad,*mux_audio_pad, *bin_audio_pad, *bin_video_pad; GstCaps* caps,*audio_caps; int flag = 0; static gboolean ob_in_iofunc (GIOChannel* iochannel, GIOCondition condition, gpointer data) { gchar buffer[256]; int bytes_read; gint fd; gint ret; fd = g_io_channel_unix_get_fd(iochannel); bytes_read = read(fd, buffer, 256); buffer[bytes_read-1] = '\0'; g_print("command:: %s\n", buffer); gst_element_set_state(src, GST_STATE_NULL); sleep(2); g_main_loop_quit (loop); } int main (int argc, char *argv[]) { gst_init (&argc, &argv); pipeline = gst_pipeline_new (NULL); g_assert (pipeline); audio_bin = gst_bin_new(NULL); g_assert(audio_bin); video_bin = gst_bin_new(NULL); g_assert(video_bin); src = gst_element_factory_make ("videotestsrc", "src"); g_assert (src); caps = gst_caps_new_simple("video/x-raw-rgb", "width", G_TYPE_INT, 176, "height", G_TYPE_INT, 144, NULL); csp = gst_element_factory_make ("ffmpegcolorspace", "csp"); g_assert (csp); venc = gst_element_factory_make ("ffenc_mpeg4", "venc"); g_assert (venc); video_queue = gst_element_factory_make("queue", "video_queue"); g_assert (video_queue); mux = gst_element_factory_make ("ffmux_3gp", "mux"); g_assert (mux); fsink = gst_element_factory_make ("filesink", "fsink"); g_assert (fsink); g_object_set (G_OBJECT (fsink), "location", "sinkav.3gp", NULL); alsa_src = gst_element_factory_make ("audiotestsrc", "asrc"); g_assert (src); audio_caps = gst_caps_new_simple("audio/x-raw-int", "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, "depth",G_TYPE_INT,16, NULL); audio_convert = gst_element_factory_make ("audioconvert", "aconv"); g_assert (audio_convert); aenc = gst_element_factory_make ("amrnbenc", "aenc"); g_assert (aenc); audio_queue = gst_element_factory_make("queue", "audio_queue"); g_assert (audio_queue); gst_bin_add_many (GST_BIN (audio_bin), alsa_src, audio_convert, aenc, audio_queue,NULL); gst_bin_add_many (GST_BIN (video_bin), src, csp, venc, video_queue,NULL); gst_bin_add_many(GST_BIN (pipeline), audio_bin, video_bin, NULL); gst_bin_add_many(GST_BIN (pipeline), mux, fsink, NULL); gst_element_link(mux, fsink); if(!gst_element_link_filtered(alsa_src, audio_convert, audio_caps)) { g_print("\nCouldn't Link Filter Caps\n"); } gst_element_link_many (alsa_src, audio_convert, aenc, audio_queue, NULL); audio_pad = gst_element_get_pad(audio_queue, "src"); g_assert(audio_pad); gst_element_add_pad(audio_bin, gst_ghost_pad_new("src", audio_pad)); bin_audio_pad = gst_element_get_pad(audio_bin, "src"); mux_audio_pad = gst_element_get_request_pad(mux, "audio_%d"); g_print ("new pad %s\n", gst_pad_get_name (mux_audio_pad)); g_assert(mux_audio_pad); gst_pad_link(bin_audio_pad, mux_audio_pad); if(!gst_element_link_filtered(src, csp, caps)) { g_print("\nCouldn't Link Filter Caps\n"); } gst_element_link_many (src,csp, venc, video_queue, NULL); video_pad = gst_element_get_pad(video_queue, "src"); g_assert(video_pad); gst_element_add_pad(video_bin, gst_ghost_pad_new("src", video_pad)); bin_video_pad = gst_element_get_pad(video_bin, "src"); mux_video_pad = gst_element_get_request_pad(mux, "video_%d"); g_print ("new pad %s\n", gst_pad_get_name (mux_video_pad)); g_assert(mux_video_pad); gst_pad_link(bin_video_pad, mux_video_pad); g_print("\n Before playing the pipepline \n"); gst_element_set_state(pipeline, GST_STATE_PLAYING); /* we need to run a GLib main loop to get out of here */ loop = g_main_loop_new (NULL, FALSE); GIOChannel*in; in = g_io_channel_unix_new (fileno(stdin)); g_io_add_watch(in, G_IO_IN, ob_in_iofunc, NULL); g_main_loop_run (loop); /* Free the main loop */ g_main_loop_unref (loop); return 0; }