11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <libgnomevfs/gnome-vfs.h>
14 #include <gst/interfaces/tuner.h>
16 #include "gmencoder.h"
18 #define G_MENCODER_GET_PRIVATE(obj) \
19 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
21 typedef struct _GMencoderPrivate GMencoderPrivate;
22 typedef struct _SetupInfo SetupInfo;
27 gchar **video_encode_prop;
33 gchar **audio_encode_prop;
38 struct _GMencoderPrivate {
54 gboolean send_chunked;
73 static void g_mencoder_class_init(GMencoderClass * klass);
74 static void g_mencoder_init(GMencoder * object);
75 static void g_mencoder_dispose(GObject * object);
76 static void g_mencoder_finalize(GObject * object);
77 static GstElement *_create_audio_bin(const gchar * encode,
78 gchar ** encode_prop, gint rate);
79 static GstElement *_create_video_bin(const gchar * encode,
82 gint rate, guint width, guint height,
83 gboolean use_deinterlace);
86 _pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data);
88 static void _decodebin_new_pad_cb(GstElement * object,
90 gboolean flag, gpointer user_data);
92 static void _decodebin_unknown_type_cb(GstElement * object,
97 static void _close_output(GMencoder * self);
98 static gboolean _open_output(GMencoder * self, const gchar * uri);
100 static GstElement *_create_source(GMencoder *self, const gchar * uri);
101 static GstElement *_create_pipeline(GMencoder * self,
102 const gchar * video_encode,
103 const gchar * mux_name,
104 gchar ** video_encode_prop,
109 const gchar * audio_encode,
110 gchar ** audio_encode_prop,
112 gboolean deinterlace);
113 static void _flush_queue (GMencoder *self);
114 static void _buffer_arrive_cb (GstElement* object,
117 static gboolean _tick_cb(gpointer data);
119 static guint g_mencoder_signals[LAST_SIGNAL] = { 0 };
121 G_DEFINE_TYPE(GMencoder, g_mencoder, G_TYPE_OBJECT)
123 static void g_mencoder_class_init(GMencoderClass * klass)
125 GObjectClass *object_class;
126 object_class = (GObjectClass *) klass;
127 g_type_class_add_private(klass, sizeof(GMencoderPrivate));
129 object_class->dispose = g_mencoder_dispose;
130 object_class->finalize = g_mencoder_finalize;
132 g_mencoder_signals[PAUSED] =
133 g_signal_new("paused",
134 G_OBJECT_CLASS_TYPE(object_class),
137 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
139 g_mencoder_signals[PLAYING] =
140 g_signal_new("playing",
141 G_OBJECT_CLASS_TYPE(object_class),
144 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
146 g_mencoder_signals[STOPED] =
147 g_signal_new("stoped",
148 G_OBJECT_CLASS_TYPE(object_class),
151 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
153 g_mencoder_signals[EOS] =
155 G_OBJECT_CLASS_TYPE(object_class),
158 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
160 g_mencoder_signals[ERROR] =
161 g_signal_new("error",
162 G_OBJECT_CLASS_TYPE(object_class),
165 g_cclosure_marshal_VOID__STRING,
166 G_TYPE_NONE, 1, G_TYPE_STRING);
170 g_mencoder_init(GMencoder * self)
172 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
173 priv->info = g_new0(SetupInfo, 1);
177 g_mencoder_dispose(GObject * object)
182 g_mencoder_finalize(GObject * object)
184 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(object);
187 g_mencoder_close_stream(G_MENCODER(object));
194 return g_object_new(G_TYPE_MENCODER, NULL);
199 _obj_set_prop(GObject * obj, const gchar * prop_name,
200 const gchar * prop_val)
204 GParamSpec *s = NULL;
205 GObjectClass *k = G_OBJECT_GET_CLASS(obj);
208 g_value_init(&v, G_TYPE_STRING);
209 g_value_set_string(&v, prop_val);
211 s = g_object_class_find_property(k, prop_name);
213 g_print("Invalid property name: %s\n", prop_name);
217 g_value_init(&p, s->value_type);
218 switch (s->value_type) {
220 g_value_set_int(&p, atoi(prop_val));
223 g_value_set_ulong (&p, atol(prop_val));
226 g_value_set_string(&p, prop_val);
229 g_value_set_boolean(&p, (gboolean) atoi (prop_val));
232 g_value_set_double(&p, atof (prop_val));
235 g_value_set_float(&p, (float) atof (prop_val));
238 g_value_set_enum(&p, atoi(prop_val));
239 g_warning ("Property %s of type %s. Not supported using default enum",
240 prop_name, g_type_name (s->value_type));
244 g_object_set_property(obj, prop_name, &p);
250 _create_element_with_prop(const gchar * factory_name,
251 const gchar * element_name, gchar ** prop)
256 ret = gst_element_factory_make(factory_name, element_name);
261 for (i = 0; i < g_strv_length(prop); i++) {
262 if (prop[i] != NULL) {
263 char **v = g_strsplit(prop[i], "=", 2);
264 if (g_strv_length(v) == 2) {
265 _obj_set_prop(G_OBJECT(ret), v[0], v[1]);
277 _create_audio_bin(const gchar * encode, gchar ** encode_prop, gint rate)
279 GstElement *abin = NULL;
280 GstElement *aqueue = NULL;
281 GstElement *aconvert = NULL;
282 GstElement *aencode = NULL;
283 GstElement *aqueue_src = NULL;
286 // audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay !
287 // udpsink name=upd_audio host=224.0.0.1 port=5002
288 abin = gst_bin_new("abin");
289 aqueue = gst_element_factory_make("queue", "aqueue");
290 aconvert = gst_element_factory_make("audioconvert", "aconvert");
292 _create_element_with_prop((encode ? encode : "lame"), "aencode",
294 aqueue_src = gst_element_factory_make("queue", "aqueue_src");
296 if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL)
297 || (aencode == NULL) || (aqueue_src == NULL)) {
298 g_warning("Audio elements not found");
302 g_object_set(G_OBJECT(aencode), "bitrate", 32, NULL);
304 * if (rate > 0) { g_object_set (G_OBJECT (aencode), "bitrate", 32,
308 gst_bin_add_many(GST_BIN(abin), aqueue, aconvert, aencode, aqueue_src,
310 if (gst_element_link_many(aqueue, aconvert, aencode, aqueue_src, NULL)
312 g_warning("Not Link audio elements");
314 // TODO: apply audio rate
316 // ghost pad the audio bin
317 apad = gst_element_get_pad(aqueue, "sink");
318 gst_element_add_pad(abin, gst_ghost_pad_new("sink", apad));
319 gst_object_unref(apad);
321 apad = gst_element_get_pad(aqueue_src, "src");
322 gst_element_add_pad(abin, gst_ghost_pad_new("src", apad));
323 gst_object_unref(apad);
328 gst_object_unref(abin);
331 gst_object_unref(aqueue);
333 if (aconvert != NULL)
334 gst_object_unref(aconvert);
337 gst_object_unref(aencode);
339 if (aqueue_src != NULL)
340 gst_object_unref(aqueue_src);
343 gst_object_unref(apad);
351 // queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! colorspace
352 // ! rate ! encode ! queue
354 _create_video_bin(const gchar * encode,
355 gchar ** encode_prop,
356 gdouble fps, gint rate, guint width, guint height,
357 gboolean use_deinterlace)
359 GstElement *vbin = NULL;
360 GstElement *vqueue = NULL;
361 GstElement *vqueue_src = NULL;
362 GstElement *vcolorspace = NULL;
363 GstElement *vencode = NULL;
364 GstElement *vrate = NULL;
365 GstElement *deinterlace = NULL;
366 GstElement *walk = NULL;
369 vbin = gst_bin_new("vbin");
370 vqueue = gst_element_factory_make("queue", "vqueue");
372 gst_element_factory_make("ffmpegcolorspace", "colorspace");
374 if (use_deinterlace) {
375 deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace");
376 if (deinterlace == NULL) {
377 g_warning ("Fail to create deinterlace element: Continue without deinterlace.");
382 vencode = _create_element_with_prop((encode !=
384 "ffenc_mpeg1video"), "vencode",
386 vqueue_src = gst_element_factory_make("queue", "queue_src");
388 if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL)
389 || (vencode == NULL) || (vqueue_src == NULL)) {
390 g_warning("Video elements not found");
394 gst_bin_add_many(GST_BIN(vbin), vqueue, vcolorspace, vencode,
397 if (deinterlace != NULL) {
398 gst_bin_add(GST_BIN(vbin), deinterlace);
399 gst_element_link (vqueue, deinterlace);
405 if ((width > 0) && (height > 0)) {
409 gst_element_factory_make("videoscale", "vscale");
411 g_object_set (G_OBJECT (vscale), "method", 1, NULL);
413 gst_bin_add(GST_BIN(vbin), vscale);
415 vcaps = gst_caps_new_simple("video/x-raw-yuv",
416 "width", G_TYPE_INT, width,
417 "height", G_TYPE_INT, height, NULL);
419 gst_element_link(walk, vscale);
421 if (gst_element_link_filtered(vscale, vcolorspace, vcaps) == FALSE) {
422 g_warning("Fail to resize video");
423 gst_object_unref(vcaps);
424 gst_object_unref(vscale);
427 gst_caps_unref(vcaps);
429 gst_element_link(walk, vcolorspace);
433 // Changing the video fps
435 vrate = gst_element_factory_make("videorate", "vrate");
437 gst_bin_add(GST_BIN(vbin), vrate);
439 if (gst_element_link(vcolorspace, vrate) == FALSE) {
440 g_warning("Fail to link video elements");
444 vcaps = gst_caps_new_simple("video/x-raw-yuv",
445 "framerate", GST_TYPE_FRACTION,
446 (int) (fps * 1000), 1000, NULL);
448 if (gst_element_link_filtered(vrate, vencode, vcaps) == FALSE) {
449 g_warning("Fail to link vrate with vencode.");
452 gst_caps_unref(vcaps);
454 if (gst_element_link(vcolorspace, vencode) == FALSE) {
455 g_warning("Fail to link colorspace and video encode element.");
460 gst_element_link(vencode, vqueue_src);
462 // ghost pad the video bin
463 vpad = gst_element_get_pad(vqueue, "sink");
464 gst_element_add_pad(vbin, gst_ghost_pad_new("sink", vpad));
465 gst_object_unref(vpad);
467 vpad = gst_element_get_pad(vqueue_src, "src");
468 gst_element_add_pad(vbin, gst_ghost_pad_new("src", vpad));
469 gst_object_unref(vpad);
475 gst_object_unref(vpad);
478 gst_object_unref(vbin);
481 gst_object_unref(vqueue);
484 gst_object_unref(vencode);
486 if (vqueue_src != NULL)
487 gst_object_unref(vqueue_src);
489 if (vcolorspace != NULL)
490 gst_object_unref(vcolorspace);
498 g_mencoder_setup_stream(GMencoder * self,
500 gboolean deinterlace,
501 const gchar * mux_name,
502 const gchar * video_encode,
503 gchar ** video_encode_prop,
508 const gchar * audio_encode,
509 gchar ** audio_encode_prop,
510 guint audio_rate, const gchar * out_uri)
512 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
513 if (priv->ready == TRUE) {
515 ("Stream already configured. You need close stream first.");
520 if (_open_output(self, out_uri) == FALSE) {
525 priv->send_chunked = chunked;
526 priv->pipe = _create_pipeline(self,
534 audio_encode, audio_encode_prop,
538 return (priv->pipe != NULL);
543 g_mencoder_append_uri(GMencoder * self, const gchar * uri)
548 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
549 gboolean ret = FALSE;
550 GstElement *ap = NULL;
551 GstElement *vp = NULL;
554 g_return_val_if_fail(priv->pipe != NULL, FALSE);
555 g_return_val_if_fail(priv->ready == FALSE, FALSE);
557 src = _create_source(self, uri);
561 priv->src = gst_bin_get_by_name(GST_BIN(src), "src");
563 gst_bin_add(GST_BIN(priv->pipe), src);
565 ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin");
566 vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin");
568 if ((vp == NULL) || (ap == NULL)) {
569 g_warning("Fail to get output bin");
573 pad_src = gst_element_get_pad(src, "src_audio");
574 pad_sink = gst_element_get_compatible_pad(ap,
576 gst_pad_get_caps(pad_src));
578 if ((pad_sink == NULL) || (pad_src == NULL))
581 GstPadLinkReturn lret = gst_pad_link(pad_src, pad_sink);
582 if (lret != GST_PAD_LINK_OK)
585 gst_object_unref(pad_src);
586 gst_object_unref(pad_sink);
588 pad_src = gst_element_get_pad(src, "src_video");
589 pad_sink = gst_element_get_compatible_pad(vp,
591 gst_pad_get_caps(pad_src));
593 if ((pad_src == NULL) || (pad_sink == NULL))
596 if (gst_pad_link(pad_src, pad_sink) != GST_PAD_LINK_OK) {
597 g_warning("invalid source. video");
605 if ((src != NULL) && (ret == FALSE)) {
606 gst_bin_remove(GST_BIN(priv->pipe), src);
607 gst_object_unref(src);
611 gst_object_unref(ap);
614 gst_object_unref(vp);
617 gst_object_unref(pad_src);
619 if (pad_sink != NULL)
620 gst_object_unref(pad_sink);
628 g_mencoder_remove_uri(GMencoder * self, const gchar * uri)
630 // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
635 g_mencoder_play_stream(GMencoder * self)
637 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
638 g_return_if_fail(priv->ready == FALSE);
640 gst_element_set_state(priv->pipe, GST_STATE_PLAYING);
641 priv->tick_id = g_timeout_add(500, _tick_cb, self);
645 g_mencoder_pause_stream(GMencoder * self)
647 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
648 g_return_if_fail(priv->ready == TRUE);
649 gst_element_set_state(priv->pipe, GST_STATE_PAUSED);
653 g_mencoder_close_stream(GMencoder * self)
656 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
657 if (priv->tick_id != 0) {
658 g_source_remove(priv->tick_id);
662 if (priv->pipe != NULL) {
663 // TODO: fixe pipeline dispose
664 //gst_element_set_state (priv->pipe, GST_STATE_NULL);
665 // g_debug ("SETING STATE TO NULL: OK");
666 // gst_element_set_state (priv->pipe, GST_STATE_NULL);
667 //gst_object_unref (priv->pipe);
668 //gst_object_unref(priv->src);
678 _create_pipeline(GMencoder * self,
679 const gchar * video_encode,
680 const gchar * mux_name,
681 gchar ** video_encode_prop,
686 const gchar * audio_encode,
687 gchar ** audio_encode_prop, guint audio_rate,
688 gboolean deinterlace)
691 GstElement *pipe = NULL;
692 GstElement *sink = NULL;
693 GstElement *mux = NULL;
694 GstElement *abin = NULL;
695 GstElement *vbin = NULL;
696 GstElement *queue = NULL;
697 GstElement *identity = NULL;
698 GstPad *aux_pad = NULL;
699 GstPad *mux_pad = NULL;
700 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
702 pipe = gst_pipeline_new("pipe");
705 gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"),
710 queue = gst_element_factory_make("queue", "queueu_sink");
711 identity = gst_element_factory_make ("identity", "identity");
712 sink = gst_element_factory_make("fdsink", "sink");
713 g_object_set (sink, "fd", priv->out_fd, NULL);
714 g_signal_connect (G_OBJECT (identity),
716 G_CALLBACK (_buffer_arrive_cb),
719 abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate);
724 _create_video_bin(video_encode, video_encode_prop, video_fps,
725 video_rate, video_width, video_height, deinterlace);
730 gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, identity, sink, NULL);
733 // Link bins with mux
734 aux_pad = gst_element_get_pad(abin, "src");
736 gst_element_get_compatible_pad(mux, aux_pad,
737 GST_PAD_CAPS(aux_pad));
738 if (mux_pad == NULL) {
739 g_warning("Mux element no have audio PAD");
742 GstPadLinkReturn ret = gst_pad_link(aux_pad, mux_pad);
743 if (ret != GST_PAD_LINK_OK) {
744 g_warning("Fail link audio and mux: %d", ret);
748 gst_object_unref(aux_pad);
749 gst_object_unref(mux_pad);
751 aux_pad = gst_element_get_pad(vbin, "src");
753 gst_element_get_compatible_pad(mux, aux_pad,
754 GST_PAD_CAPS(aux_pad));
755 if (mux_pad == NULL) {
756 g_warning("Mux element no have video PAD");
759 ret = gst_pad_link(aux_pad, mux_pad);
760 if (ret != GST_PAD_LINK_OK) {
761 g_warning("Fail link video and mux: %d", ret);
764 gst_object_unref(aux_pad);
765 gst_object_unref(mux_pad);
769 // Link mux with sink
770 gst_element_link_many(mux, queue, identity, sink, NULL);
772 bus = gst_pipeline_get_bus(GST_PIPELINE(pipe));
773 gst_bus_add_watch(bus, _pipeline_bus_cb, self);
774 gst_object_unref(bus);
779 g_warning("Invalid uri");
782 gst_object_unref(pipe);
787 gst_object_unref(mux);
790 if (mux_pad != NULL) {
791 gst_object_unref(mux_pad);
794 if (aux_pad != NULL) {
795 gst_object_unref(mux_pad);
799 gst_object_unref(sink);
803 gst_object_unref(abin);
807 gst_object_unref(vbin);
815 _close_output(GMencoder * self)
820 _create_v4l_source (GMencoder *self, const gchar * uri)
823 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
826 info = g_strsplit (uri+6, ":", 3);
827 if (g_strv_length (info) != 3) {
831 priv->v4lsrc = gst_element_factory_make ("v4l2src", "src");
832 g_debug ("channel %s, norm %s, frequ %s", info[0], info[1], info[2]);
833 g_object_set (G_OBJECT (priv->v4lsrc),
836 "frequency", atoi (info[2]),
843 _create_source(GMencoder *self, const gchar * uri)
846 GstElement *bsrc = NULL;
847 GstElement *src = NULL;
848 GstElement *queue = NULL;
849 GstElement *aqueue = NULL;
850 GstElement *vqueue = NULL;
851 GstElement *decode = NULL;
852 GstPad *src_pad = NULL;
855 bsrc = gst_bin_new(NULL);
857 // src = gst_element_factory_make ("gnomevfssrc", "src");
858 // g_object_set (G_OBJECT (src), "location", uri, NULL);
859 if (strncmp (uri, "v4l://", 6) == 0) {
861 src = _create_v4l_source (self, uri);
865 src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
871 decode = gst_element_factory_make("decodebin", "decode");
875 queue = gst_element_factory_make("queue", "queue_src");
876 aqueue = gst_element_factory_make("queue", "aqueue");
880 vqueue = gst_element_factory_make("queue", "vqueue");
884 gst_bin_add_many(GST_BIN(bsrc), src, queue, decode, aqueue, vqueue,
886 gst_element_link_many(src, queue, decode, NULL);
888 g_signal_connect(G_OBJECT(decode),
890 G_CALLBACK(_decodebin_new_pad_cb), bsrc);
892 g_signal_connect(G_OBJECT(decode),
894 G_CALLBACK(_decodebin_unknown_type_cb), pipe);
896 src_pad = gst_element_get_pad(aqueue, "src");
897 gst_element_add_pad(bsrc, gst_ghost_pad_new("src_audio", src_pad));
898 gst_object_unref(src_pad);
900 src_pad = gst_element_get_pad(vqueue, "src");
901 gst_element_add_pad(bsrc, gst_ghost_pad_new("src_video", src_pad));
902 gst_object_unref(src_pad);
907 g_debug ("Fail to create source element");
909 gst_object_unref(src);
912 if (decode != NULL) {
913 gst_object_unref(decode);
916 if (aqueue != NULL) {
917 gst_object_unref(aqueue);
920 if (vqueue != NULL) {
921 gst_object_unref(vqueue);
928 _open_output(GMencoder * self, const gchar * uri)
931 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
935 i = g_strsplit(uri, "://", 0);
936 if (strcmp(i[0], "fd") == 0) {
937 priv->out_fd = atoi (i[1]);
939 priv->out_fd = open (i[1], O_CREAT|O_WRONLY|O_TRUNC, 0666);
943 return (priv->out_fd > 0);
947 _pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data)
949 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
951 switch (GST_MESSAGE_TYPE(msg)) {
953 case GST_MESSAGE_STATE_CHANGED:
957 GstState pendingstate;
960 gst_message_parse_state_changed(msg, &oldstate,
961 &newstate, &pendingstate);
963 if (pendingstate != GST_STATE_VOID_PENDING)
966 if ((oldstate == GST_STATE_READY)
967 && (newstate == GST_STATE_PAUSED)) {
969 g_signal_emit(user_data, g_mencoder_signals[PAUSED],
971 } else if ((oldstate == GST_STATE_PAUSED)
972 && (newstate == GST_STATE_PLAYING)) {
973 g_signal_emit(user_data, g_mencoder_signals[PLAYING], 0);
974 } else if ((oldstate == GST_STATE_READY) &&
975 (newstate == GST_STATE_NULL)) {
976 g_signal_emit(user_data, g_mencoder_signals[STOPED], 0);
981 case GST_MESSAGE_ERROR:
987 if (priv->tick_id != 0) {
988 g_source_remove(priv->tick_id);
992 gst_message_parse_error(msg, &error, &debug);
993 err_str = g_strdup_printf("Error [%d] %s (%s)", error->code,
994 error->message, debug);
996 g_signal_emit(user_data, g_mencoder_signals[ERROR], 0,
999 g_clear_error(&error);
1004 case GST_MESSAGE_EOS:
1005 priv->ready = FALSE;
1006 _flush_queue (G_MENCODER (user_data));
1007 g_signal_emit(user_data, g_mencoder_signals[EOS], 0);
1010 case GST_MESSAGE_DURATION:
1014 gst_message_parse_duration(msg, &format, &duration);
1015 if (format == GST_FORMAT_BYTES)
1016 priv->duration = duration;
1030 _decodebin_new_pad_cb(GstElement * object,
1031 GstPad * pad, gboolean flag, gpointer user_data)
1034 gchar *str_caps = NULL;
1035 GstElement *sink_element;
1038 caps = gst_pad_get_caps(pad);
1039 str_caps = gst_caps_to_string(caps);
1040 if (strstr(str_caps, "audio") != NULL) {
1041 sink_element = gst_bin_get_by_name(GST_BIN(user_data), "aqueue");
1042 } else if (strstr(str_caps, "video") != NULL) {
1043 sink_element = gst_bin_get_by_name(GST_BIN(user_data), "vqueue");
1045 g_warning("invalid caps %s", str_caps);
1048 sink_pad = gst_element_get_pad(sink_element, "sink");
1049 gst_pad_link(pad, sink_pad);
1051 gst_object_unref(sink_element);
1052 gst_object_unref(sink_pad);
1054 gst_caps_unref(caps);
1058 _decodebin_unknown_type_cb(GstElement * object,
1059 GstPad * pad, GstCaps * caps,
1062 g_warning("Unknown Type");
1063 // priv->ready = FALSE;
1067 _tick_cb(gpointer user_data)
1069 GstFormat format = GST_FORMAT_BYTES;
1072 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1074 if (priv->duration == 0) {
1076 if (gst_element_query_duration(priv->src, &format, &d))
1080 if (priv->duration != 0) {
1081 gst_element_query_position(priv->src, &format, &cur);
1082 g_print("PROGRESS:%lli\n", (99 * cur) / priv->duration);
1090 _chunke_buffer (GstBuffer *buf)
1095 b_send = g_byte_array_new ();
1096 msg = g_strdup_printf ("%x\r\n", GST_BUFFER_SIZE(buf));
1097 b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar));
1100 b_send = g_byte_array_append (b_send, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
1102 msg = g_strdup ("\r\n");
1103 b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar));
1106 g_free (GST_BUFFER_DATA(buf));
1108 GST_BUFFER_SIZE(buf)=b_send->len;
1109 GST_BUFFER_DATA(buf)=b_send->data;
1111 g_byte_array_free (b_send, FALSE);
1115 _flush_queue (GMencoder *self)
1118 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1121 if (priv->send_chunked) {
1123 end_msg = g_strdup ("0\r\n\r\n");
1124 gnome_vfs_write (priv->handle,
1125 (const guint8*) end_msg,
1126 strlen(end_msg) * sizeof(gchar),
1134 _buffer_arrive_cb (GstElement* object,
1138 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1140 if (priv->send_chunked) {
1141 _chunke_buffer (buf);