1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jun 14 18:21:53 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jun 14 20:40:47 2007 +0100
1.3 @@ -14,147 +14,145 @@
1.4 #define G_MENCODER_GET_PRIVATE(obj) \
1.5 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
1.6
1.7 -//#define SUPPORT_MULT_INPUT 0
1.8 +// #define SUPPORT_MULT_INPUT 0
1.9
1.10 typedef struct _GMencoderPrivate GMencoderPrivate;
1.11 typedef struct _SetupInfo SetupInfo;
1.12
1.13 -struct _SetupInfo
1.14 -{
1.15 - gchar *video_encode;
1.16 - gchar *mux_name;
1.17 - gchar **video_encode_prop;
1.18 - gdouble video_fps;
1.19 - gdouble video_rate;
1.20 - guint video_width;
1.21 - guint video_height;
1.22 - gchar *audio_encode;
1.23 - gchar **audio_encode_prop;
1.24 - guint audio_rate;
1.25 +struct _SetupInfo {
1.26 + gchar *video_encode;
1.27 + gchar *mux_name;
1.28 + gchar **video_encode_prop;
1.29 + gdouble video_fps;
1.30 + gdouble video_rate;
1.31 + guint video_width;
1.32 + guint video_height;
1.33 + gchar *audio_encode;
1.34 + gchar **audio_encode_prop;
1.35 + guint audio_rate;
1.36 };
1.37
1.38
1.39 -struct _GMencoderPrivate
1.40 -{
1.41 - GstElement *pipe;
1.42 - GstElement *abin;
1.43 - GstElement *vbin;
1.44 - GstElement *sink;
1.45 - GstElement *src;
1.46 - gboolean ready;
1.47 - SetupInfo *info;
1.48 - GstClockTime videot;
1.49 - GstClockTime audiot;
1.50 - gint fd;
1.51 - gint sources;
1.52 - gint tick_id;
1.53 - gint64 duration;
1.54 +struct _GMencoderPrivate {
1.55 + GstElement *pipe;
1.56 + GstElement *abin;
1.57 + GstElement *vbin;
1.58 + GstElement *sink;
1.59 + GstElement *src;
1.60 + gboolean ready;
1.61 + SetupInfo *info;
1.62 + GstClockTime videot;
1.63 + GstClockTime audiot;
1.64 + gint fd;
1.65 + gint sources;
1.66 + gint tick_id;
1.67 + gint64 duration;
1.68 };
1.69
1.70 -enum
1.71 -{
1.72 - PAUSED,
1.73 - PLAYING,
1.74 - STOPED,
1.75 - EOS,
1.76 - ERROR,
1.77 - LAST_SIGNAL
1.78 +enum {
1.79 + PAUSED,
1.80 + PLAYING,
1.81 + STOPED,
1.82 + EOS,
1.83 + ERROR,
1.84 + LAST_SIGNAL
1.85 };
1.86
1.87 -static void g_mencoder_class_init(GMencoderClass * klass);
1.88 -static void g_mencoder_init(GMencoder * object);
1.89 -static void g_mencoder_dispose(GObject * object);
1.90 -static void g_mencoder_finalize(GObject * object);
1.91 +static void g_mencoder_class_init(GMencoderClass * klass);
1.92 +static void g_mencoder_init(GMencoder * object);
1.93 +static void g_mencoder_dispose(GObject * object);
1.94 +static void g_mencoder_finalize(GObject * object);
1.95 static GstElement *_create_audio_bin(const gchar * encode,
1.96 - gchar ** encode_prop, gint rate);
1.97 + gchar ** encode_prop, gint rate);
1.98 static GstElement *_create_video_bin(const gchar * encode,
1.99 - gchar ** encode_prop,
1.100 - gdouble fps,
1.101 - gint rate, guint width, guint height);
1.102 + gchar ** encode_prop,
1.103 + gdouble fps,
1.104 + gint rate, guint width, guint height);
1.105
1.106 -static gboolean
1.107 +static gboolean
1.108 _pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data);
1.109
1.110 -static void _decodebin_new_pad_cb(GstElement * object,
1.111 - GstPad * pad,
1.112 - gboolean flag, gpointer user_data);
1.113 +static void _decodebin_new_pad_cb(GstElement * object,
1.114 + GstPad * pad,
1.115 + gboolean flag, gpointer user_data);
1.116
1.117 -static void _decodebin_unknown_type_cb(GstElement * object,
1.118 - GstPad * pad,
1.119 - GstCaps * caps, gpointer user_data);
1.120 +static void _decodebin_unknown_type_cb(GstElement * object,
1.121 + GstPad * pad,
1.122 + GstCaps * caps,
1.123 + gpointer user_data);
1.124
1.125 -static void _close_output(GMencoder * self);
1.126 -static void _open_output(GMencoder * self, const gchar * uri);
1.127 +static void _close_output(GMencoder * self);
1.128 +static void _open_output(GMencoder * self, const gchar * uri);
1.129
1.130 static GstElement *_create_source(const gchar * uri);
1.131 static GstElement *_create_pipeline(GMencoder * self,
1.132 - const gchar * video_encode,
1.133 - const gchar * mux_name,
1.134 - gchar ** video_encode_prop,
1.135 - gdouble video_fps,
1.136 - gdouble video_rate,
1.137 - guint video_width,
1.138 - guint video_height,
1.139 - const gchar * audio_encode,
1.140 - gchar ** audio_encode_prop,
1.141 - guint audio_rate);
1.142 + const gchar * video_encode,
1.143 + const gchar * mux_name,
1.144 + gchar ** video_encode_prop,
1.145 + gdouble video_fps,
1.146 + gdouble video_rate,
1.147 + guint video_width,
1.148 + guint video_height,
1.149 + const gchar * audio_encode,
1.150 + gchar ** audio_encode_prop,
1.151 + guint audio_rate);
1.152
1.153 static gboolean _tick_cb(gpointer data);
1.154
1.155 -static guint g_mencoder_signals[LAST_SIGNAL] = { 0 };
1.156 +static guint g_mencoder_signals[LAST_SIGNAL] = { 0 };
1.157
1.158 G_DEFINE_TYPE(GMencoder, g_mencoder, G_TYPE_OBJECT)
1.159 - static void g_mencoder_class_init(GMencoderClass * klass)
1.160 + static void g_mencoder_class_init(GMencoderClass * klass)
1.161 {
1.162 - GObjectClass *object_class;
1.163 - object_class = (GObjectClass *) klass;
1.164 - g_type_class_add_private(klass, sizeof(GMencoderPrivate));
1.165 + GObjectClass *object_class;
1.166 + object_class = (GObjectClass *) klass;
1.167 + g_type_class_add_private(klass, sizeof(GMencoderPrivate));
1.168
1.169 - object_class->dispose = g_mencoder_dispose;
1.170 - object_class->finalize = g_mencoder_finalize;
1.171 + object_class->dispose = g_mencoder_dispose;
1.172 + object_class->finalize = g_mencoder_finalize;
1.173
1.174 - g_mencoder_signals[PAUSED] =
1.175 - g_signal_new("paused",
1.176 - G_OBJECT_CLASS_TYPE(object_class),
1.177 - G_SIGNAL_RUN_FIRST,
1.178 - 0, NULL, NULL,
1.179 - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.180 + g_mencoder_signals[PAUSED] =
1.181 + g_signal_new("paused",
1.182 + G_OBJECT_CLASS_TYPE(object_class),
1.183 + G_SIGNAL_RUN_FIRST,
1.184 + 0, NULL, NULL,
1.185 + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.186
1.187 - g_mencoder_signals[PLAYING] =
1.188 - g_signal_new("playing",
1.189 - G_OBJECT_CLASS_TYPE(object_class),
1.190 - G_SIGNAL_RUN_FIRST,
1.191 - 0, NULL, NULL,
1.192 - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.193 + g_mencoder_signals[PLAYING] =
1.194 + g_signal_new("playing",
1.195 + G_OBJECT_CLASS_TYPE(object_class),
1.196 + G_SIGNAL_RUN_FIRST,
1.197 + 0, NULL, NULL,
1.198 + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.199
1.200 - g_mencoder_signals[STOPED] =
1.201 - g_signal_new("stoped",
1.202 - G_OBJECT_CLASS_TYPE(object_class),
1.203 - G_SIGNAL_RUN_FIRST,
1.204 - 0, NULL, NULL,
1.205 - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.206 + g_mencoder_signals[STOPED] =
1.207 + g_signal_new("stoped",
1.208 + G_OBJECT_CLASS_TYPE(object_class),
1.209 + G_SIGNAL_RUN_FIRST,
1.210 + 0, NULL, NULL,
1.211 + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.212
1.213 - g_mencoder_signals[EOS] =
1.214 - g_signal_new("eos",
1.215 - G_OBJECT_CLASS_TYPE(object_class),
1.216 - G_SIGNAL_RUN_FIRST,
1.217 - 0, NULL, NULL,
1.218 - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.219 + g_mencoder_signals[EOS] =
1.220 + g_signal_new("eos",
1.221 + G_OBJECT_CLASS_TYPE(object_class),
1.222 + G_SIGNAL_RUN_FIRST,
1.223 + 0, NULL, NULL,
1.224 + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1.225
1.226 - g_mencoder_signals[ERROR] =
1.227 - g_signal_new("error",
1.228 - G_OBJECT_CLASS_TYPE(object_class),
1.229 - G_SIGNAL_RUN_LAST,
1.230 - 0, NULL, NULL,
1.231 - g_cclosure_marshal_VOID__STRING,
1.232 - G_TYPE_NONE, 1, G_TYPE_STRING);
1.233 + g_mencoder_signals[ERROR] =
1.234 + g_signal_new("error",
1.235 + G_OBJECT_CLASS_TYPE(object_class),
1.236 + G_SIGNAL_RUN_LAST,
1.237 + 0, NULL, NULL,
1.238 + g_cclosure_marshal_VOID__STRING,
1.239 + G_TYPE_NONE, 1, G_TYPE_STRING);
1.240 }
1.241
1.242 static void
1.243 g_mencoder_init(GMencoder * self)
1.244 {
1.245 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.246 - priv->info = g_new0(SetupInfo, 1);
1.247 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.248 + priv->info = g_new0(SetupInfo, 1);
1.249 }
1.250
1.251 static void
1.252 @@ -165,328 +163,314 @@
1.253 static void
1.254 g_mencoder_finalize(GObject * object)
1.255 {
1.256 - //TODO: clear vars
1.257 - g_mencoder_close_stream(G_MENCODER(object));
1.258 + // TODO: clear vars
1.259 + g_mencoder_close_stream(G_MENCODER(object));
1.260 }
1.261
1.262 -GMencoder *
1.263 +GMencoder *
1.264 g_mencoder_new(void)
1.265 {
1.266 - return g_object_new(G_TYPE_MENCODER, NULL);
1.267 + return g_object_new(G_TYPE_MENCODER, NULL);
1.268 }
1.269
1.270
1.271 static void
1.272 -_obj_set_prop(GObject * obj, const gchar * prop_name, const gchar * prop_val)
1.273 +_obj_set_prop(GObject * obj, const gchar * prop_name,
1.274 + const gchar * prop_val)
1.275 {
1.276 - GValue p = { 0 };
1.277 - GValue v = { 0 };
1.278 - GParamSpec *s = NULL;
1.279 - GObjectClass *k = G_OBJECT_GET_CLASS(obj);
1.280 + GValue p = { 0 };
1.281 + GValue v = { 0 };
1.282 + GParamSpec *s = NULL;
1.283 + GObjectClass *k = G_OBJECT_GET_CLASS(obj);
1.284
1.285
1.286 - g_value_init(&v, G_TYPE_STRING);
1.287 - g_value_set_string(&v, prop_val);
1.288 + g_value_init(&v, G_TYPE_STRING);
1.289 + g_value_set_string(&v, prop_val);
1.290
1.291 - s = g_object_class_find_property(k, prop_name);
1.292 - if (s == NULL)
1.293 - {
1.294 - g_print("Invalid property name: %s\n", prop_name);
1.295 - return;
1.296 - }
1.297 + s = g_object_class_find_property(k, prop_name);
1.298 + if (s == NULL) {
1.299 + g_print("Invalid property name: %s\n", prop_name);
1.300 + return;
1.301 + }
1.302
1.303 - g_value_init(&p, s->value_type);
1.304 - switch (s->value_type)
1.305 - {
1.306 - case G_TYPE_INT:
1.307 - g_value_set_int(&p, atoi(prop_val));
1.308 - break;
1.309 - case G_TYPE_STRING:
1.310 - g_value_set_string(&p, prop_val);
1.311 - break;
1.312 - default:
1.313 - return;
1.314 - }
1.315 + g_value_init(&p, s->value_type);
1.316 + switch (s->value_type) {
1.317 + case G_TYPE_INT:
1.318 + g_value_set_int(&p, atoi(prop_val));
1.319 + break;
1.320 + case G_TYPE_STRING:
1.321 + g_value_set_string(&p, prop_val);
1.322 + break;
1.323 + default:
1.324 + return;
1.325 + }
1.326
1.327 - g_object_set_property(obj, prop_name, &p);
1.328 - g_value_unset(&v);
1.329 - g_value_unset(&p);
1.330 + g_object_set_property(obj, prop_name, &p);
1.331 + g_value_unset(&v);
1.332 + g_value_unset(&p);
1.333 }
1.334
1.335 static GstElement *
1.336 _create_element_with_prop(const gchar * factory_name,
1.337 - const gchar * element_name, gchar ** prop)
1.338 + const gchar * element_name, gchar ** prop)
1.339 {
1.340 - GstElement *ret;
1.341 - int i;
1.342 + GstElement *ret;
1.343 + int i;
1.344
1.345 - ret = gst_element_factory_make(factory_name, element_name);
1.346 - if (ret == NULL)
1.347 - return NULL;
1.348 + ret = gst_element_factory_make(factory_name, element_name);
1.349 + if (ret == NULL)
1.350 + return NULL;
1.351
1.352 - if (prop != NULL)
1.353 - {
1.354 - for (i = 0; i < g_strv_length(prop); i++)
1.355 - {
1.356 - if (prop[i] != NULL)
1.357 - {
1.358 - char **v = g_strsplit(prop[i], "=", 2);
1.359 - if (g_strv_length(v) == 2)
1.360 - {
1.361 - _obj_set_prop(G_OBJECT(ret), v[0], v[1]);
1.362 - }
1.363 - g_strfreev(v);
1.364 - }
1.365 - }
1.366 - }
1.367 + if (prop != NULL) {
1.368 + for (i = 0; i < g_strv_length(prop); i++) {
1.369 + if (prop[i] != NULL) {
1.370 + char **v = g_strsplit(prop[i], "=", 2);
1.371 + if (g_strv_length(v) == 2) {
1.372 + _obj_set_prop(G_OBJECT(ret), v[0], v[1]);
1.373 + }
1.374 + g_strfreev(v);
1.375 + }
1.376 + }
1.377 + }
1.378
1.379 - return ret;
1.380 + return ret;
1.381
1.382 }
1.383
1.384 static GstElement *
1.385 _create_audio_bin(const gchar * encode, gchar ** encode_prop, gint rate)
1.386 {
1.387 - GstElement *abin = NULL;
1.388 - GstElement *aqueue = NULL;
1.389 - GstElement *aconvert = NULL;
1.390 - GstElement *aencode = NULL;
1.391 - GstElement *aqueue_src = NULL;
1.392 - GstPad *apad = NULL;
1.393 + GstElement *abin = NULL;
1.394 + GstElement *aqueue = NULL;
1.395 + GstElement *aconvert = NULL;
1.396 + GstElement *aencode = NULL;
1.397 + GstElement *aqueue_src = NULL;
1.398 + GstPad *apad = NULL;
1.399
1.400 - //audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=upd_audio host=224.0.0.1 port=5002
1.401 - abin = gst_bin_new("abin");
1.402 - aqueue = gst_element_factory_make("queue", "aqueue");
1.403 - aconvert = gst_element_factory_make("audioconvert", "aconvert");
1.404 - aencode =
1.405 - _create_element_with_prop((encode ? encode : "lame"), "aencode",
1.406 - encode_prop);
1.407 - aqueue_src = gst_element_factory_make("queue", "aqueue_src");
1.408 + // audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay !
1.409 + // udpsink name=upd_audio host=224.0.0.1 port=5002
1.410 + abin = gst_bin_new("abin");
1.411 + aqueue = gst_element_factory_make("queue", "aqueue");
1.412 + aconvert = gst_element_factory_make("audioconvert", "aconvert");
1.413 + aencode =
1.414 + _create_element_with_prop((encode ? encode : "lame"), "aencode",
1.415 + encode_prop);
1.416 + aqueue_src = gst_element_factory_make("queue", "aqueue_src");
1.417
1.418 - if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL)
1.419 - || (aencode == NULL) || (aqueue_src == NULL))
1.420 - {
1.421 - g_warning("Audio elements not found");
1.422 - goto error;
1.423 - }
1.424 + if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL)
1.425 + || (aencode == NULL) || (aqueue_src == NULL)) {
1.426 + g_warning("Audio elements not found");
1.427 + goto error;
1.428 + }
1.429
1.430 - g_object_set(G_OBJECT(aencode), "bitrate", 32, NULL);
1.431 - /*
1.432 - if (rate > 0) {
1.433 - g_object_set (G_OBJECT (aencode), "bitrate", 32, NULL);
1.434 + g_object_set(G_OBJECT(aencode), "bitrate", 32, NULL);
1.435 + /*
1.436 + * if (rate > 0) { g_object_set (G_OBJECT (aencode), "bitrate", 32,
1.437 + * NULL); }
1.438 + */
1.439 +
1.440 + gst_bin_add_many(GST_BIN(abin), aqueue, aconvert, aencode, aqueue_src,
1.441 + NULL);
1.442 + if (gst_element_link_many(aqueue, aconvert, aencode, aqueue_src, NULL)
1.443 + == FALSE) {
1.444 + g_warning("Not Link audio elements");
1.445 }
1.446 - */
1.447 + // TODO: apply audio rate
1.448
1.449 - gst_bin_add_many(GST_BIN(abin), aqueue, aconvert, aencode, aqueue_src,
1.450 - NULL);
1.451 - if (gst_element_link_many(aqueue, aconvert, aencode, aqueue_src, NULL) ==
1.452 - FALSE)
1.453 - {
1.454 - g_warning("Not Link audio elements");
1.455 - }
1.456 + // ghost pad the audio bin
1.457 + apad = gst_element_get_pad(aqueue, "sink");
1.458 + gst_element_add_pad(abin, gst_ghost_pad_new("sink", apad));
1.459 + gst_object_unref(apad);
1.460
1.461 - //TODO: apply audio rate
1.462 + apad = gst_element_get_pad(aqueue_src, "src");
1.463 + gst_element_add_pad(abin, gst_ghost_pad_new("src", apad));
1.464 + gst_object_unref(apad);
1.465
1.466 - // ghost pad the audio bin
1.467 - apad = gst_element_get_pad(aqueue, "sink");
1.468 - gst_element_add_pad(abin, gst_ghost_pad_new("sink", apad));
1.469 - gst_object_unref(apad);
1.470 + return abin;
1.471 + error:
1.472 + if (abin != NULL)
1.473 + gst_object_unref(abin);
1.474
1.475 - apad = gst_element_get_pad(aqueue_src, "src");
1.476 - gst_element_add_pad(abin, gst_ghost_pad_new("src", apad));
1.477 - gst_object_unref(apad);
1.478 + if (aqueue != NULL)
1.479 + gst_object_unref(aqueue);
1.480
1.481 - return abin;
1.482 -error:
1.483 - if (abin != NULL)
1.484 - gst_object_unref(abin);
1.485 + if (aconvert != NULL)
1.486 + gst_object_unref(aconvert);
1.487
1.488 - if (aqueue != NULL)
1.489 - gst_object_unref(aqueue);
1.490 + if (aencode != NULL)
1.491 + gst_object_unref(aencode);
1.492
1.493 - if (aconvert != NULL)
1.494 - gst_object_unref(aconvert);
1.495 + if (aqueue_src != NULL)
1.496 + gst_object_unref(aqueue_src);
1.497
1.498 - if (aencode != NULL)
1.499 - gst_object_unref(aencode);
1.500 + if (apad != NULL)
1.501 + gst_object_unref(apad);
1.502
1.503 - if (aqueue_src != NULL)
1.504 - gst_object_unref(aqueue_src);
1.505 -
1.506 - if (apad != NULL)
1.507 - gst_object_unref(apad);
1.508 -
1.509 - return NULL;
1.510 + return NULL;
1.511 }
1.512
1.513
1.514
1.515
1.516 -//queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! colorspace ! rate ! encode ! queue
1.517 +// queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! colorspace
1.518 +// ! rate ! encode ! queue
1.519 static GstElement *
1.520 _create_video_bin(const gchar * encode,
1.521 - gchar ** encode_prop,
1.522 - gdouble fps, gint rate, guint width, guint height)
1.523 + gchar ** encode_prop,
1.524 + gdouble fps, gint rate, guint width, guint height)
1.525 {
1.526 - GstElement *vbin = NULL;
1.527 - GstElement *vqueue = NULL;
1.528 - GstElement *vqueue_src = NULL;
1.529 - GstElement *vcolorspace = NULL;
1.530 - GstElement *vencode = NULL;
1.531 - GstElement *vrate = NULL;
1.532 - GstPad *vpad = NULL;
1.533 + GstElement *vbin = NULL;
1.534 + GstElement *vqueue = NULL;
1.535 + GstElement *vqueue_src = NULL;
1.536 + GstElement *vcolorspace = NULL;
1.537 + GstElement *vencode = NULL;
1.538 + GstElement *vrate = NULL;
1.539 + GstPad *vpad = NULL;
1.540
1.541 - vbin = gst_bin_new("vbin");
1.542 - vqueue = gst_element_factory_make("queue", "vqueue");
1.543 - vcolorspace = gst_element_factory_make("ffmpegcolorspace", "colorspace");
1.544 + vbin = gst_bin_new("vbin");
1.545 + vqueue = gst_element_factory_make("queue", "vqueue");
1.546 + vcolorspace =
1.547 + gst_element_factory_make("ffmpegcolorspace", "colorspace");
1.548
1.549 - vencode = _create_element_with_prop((encode !=
1.550 - NULL ? encode : "ffenc_mpeg1video"),
1.551 - "vencode", encode_prop);
1.552 - vqueue_src = gst_element_factory_make("queue", "queue_src");
1.553 + vencode = _create_element_with_prop((encode !=
1.554 + NULL ? encode :
1.555 + "ffenc_mpeg1video"), "vencode",
1.556 + encode_prop);
1.557 + vqueue_src = gst_element_factory_make("queue", "queue_src");
1.558
1.559 - if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL)
1.560 - || (vencode == NULL) || (vqueue_src == NULL))
1.561 - {
1.562 - g_warning("Video elements not found");
1.563 - goto error;
1.564 - }
1.565 + if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL)
1.566 + || (vencode == NULL) || (vqueue_src == NULL)) {
1.567 + g_warning("Video elements not found");
1.568 + goto error;
1.569 + }
1.570
1.571 - gst_bin_add_many(GST_BIN(vbin), vqueue, vcolorspace, vencode, vqueue_src,
1.572 - NULL);
1.573 + gst_bin_add_many(GST_BIN(vbin), vqueue, vcolorspace, vencode,
1.574 + vqueue_src, NULL);
1.575
1.576 - if ((width > 0) && (height > 0))
1.577 - {
1.578 - //Scalling video
1.579 - GstCaps *vcaps;
1.580 - GstElement *vscale = gst_element_factory_make("videoscale", "vscale");
1.581 + if ((width > 0) && (height > 0)) {
1.582 + // Scalling video
1.583 + GstCaps *vcaps;
1.584 + GstElement *vscale =
1.585 + gst_element_factory_make("videoscale", "vscale");
1.586
1.587 - gst_bin_add(GST_BIN(vbin), vscale);
1.588 + gst_bin_add(GST_BIN(vbin), vscale);
1.589
1.590 - vcaps = gst_caps_new_simple("video/x-raw-yuv",
1.591 - "width", G_TYPE_INT, width,
1.592 - "height", G_TYPE_INT, height, NULL);
1.593 + vcaps = gst_caps_new_simple("video/x-raw-yuv",
1.594 + "width", G_TYPE_INT, width,
1.595 + "height", G_TYPE_INT, height, NULL);
1.596
1.597 - gst_element_link(vqueue, vscale);
1.598 + gst_element_link(vqueue, vscale);
1.599
1.600 - if (gst_element_link_filtered(vscale, vcolorspace, vcaps) == FALSE)
1.601 - {
1.602 - g_warning("Fail to resize video");
1.603 - gst_object_unref(vcaps);
1.604 - gst_object_unref(vscale);
1.605 - goto error;
1.606 - }
1.607 - gst_caps_unref(vcaps);
1.608 - }
1.609 - else
1.610 - {
1.611 - gst_element_link(vqueue, vcolorspace);
1.612 - }
1.613 + if (gst_element_link_filtered(vscale, vcolorspace, vcaps) == FALSE) {
1.614 + g_warning("Fail to resize video");
1.615 + gst_object_unref(vcaps);
1.616 + gst_object_unref(vscale);
1.617 + goto error;
1.618 + }
1.619 + gst_caps_unref(vcaps);
1.620 + } else {
1.621 + gst_element_link(vqueue, vcolorspace);
1.622 + }
1.623
1.624 - if (fps > 0)
1.625 - {
1.626 - //Changing the video fps
1.627 - GstCaps *vcaps;
1.628 - vrate = gst_element_factory_make("videorate", "vrate");
1.629 + if (fps > 0) {
1.630 + // Changing the video fps
1.631 + GstCaps *vcaps;
1.632 + vrate = gst_element_factory_make("videorate", "vrate");
1.633
1.634 - gst_bin_add(GST_BIN(vbin), vrate);
1.635 + gst_bin_add(GST_BIN(vbin), vrate);
1.636
1.637 - if (gst_element_link(vcolorspace, vrate) == FALSE)
1.638 - {
1.639 - g_warning("Fail to link video elements");
1.640 - goto error;
1.641 - }
1.642 + if (gst_element_link(vcolorspace, vrate) == FALSE) {
1.643 + g_warning("Fail to link video elements");
1.644 + goto error;
1.645 + }
1.646
1.647 - vcaps = gst_caps_new_simple("video/x-raw-yuv",
1.648 - "framerate", GST_TYPE_FRACTION,
1.649 - (int) (fps * 1000), 1000, NULL);
1.650 + vcaps = gst_caps_new_simple("video/x-raw-yuv",
1.651 + "framerate", GST_TYPE_FRACTION,
1.652 + (int) (fps * 1000), 1000, NULL);
1.653
1.654 - if (gst_element_link_filtered(vrate, vencode, vcaps) == FALSE)
1.655 - {
1.656 - g_warning("Fail to link vrate with vencode.");
1.657 - goto error;
1.658 - }
1.659 - gst_caps_unref(vcaps);
1.660 - }
1.661 - else
1.662 - {
1.663 - if (gst_element_link(vcolorspace, vencode) == FALSE)
1.664 - {
1.665 - g_warning("Fail to link colorspace and video encode element.");
1.666 - goto error;
1.667 - }
1.668 - }
1.669 + if (gst_element_link_filtered(vrate, vencode, vcaps) == FALSE) {
1.670 + g_warning("Fail to link vrate with vencode.");
1.671 + goto error;
1.672 + }
1.673 + gst_caps_unref(vcaps);
1.674 + } else {
1.675 + if (gst_element_link(vcolorspace, vencode) == FALSE) {
1.676 + g_warning("Fail to link colorspace and video encode element.");
1.677 + goto error;
1.678 + }
1.679 + }
1.680
1.681 - gst_element_link(vencode, vqueue_src);
1.682 + gst_element_link(vencode, vqueue_src);
1.683
1.684 - // ghost pad the video bin
1.685 - vpad = gst_element_get_pad(vqueue, "sink");
1.686 - gst_element_add_pad(vbin, gst_ghost_pad_new("sink", vpad));
1.687 - gst_object_unref(vpad);
1.688 + // ghost pad the video bin
1.689 + vpad = gst_element_get_pad(vqueue, "sink");
1.690 + gst_element_add_pad(vbin, gst_ghost_pad_new("sink", vpad));
1.691 + gst_object_unref(vpad);
1.692
1.693 - vpad = gst_element_get_pad(vqueue_src, "src");
1.694 - gst_element_add_pad(vbin, gst_ghost_pad_new("src", vpad));
1.695 - gst_object_unref(vpad);
1.696 + vpad = gst_element_get_pad(vqueue_src, "src");
1.697 + gst_element_add_pad(vbin, gst_ghost_pad_new("src", vpad));
1.698 + gst_object_unref(vpad);
1.699
1.700 - return vbin;
1.701 + return vbin;
1.702
1.703 -error:
1.704 - if (vpad != NULL)
1.705 - gst_object_unref(vpad);
1.706 + error:
1.707 + if (vpad != NULL)
1.708 + gst_object_unref(vpad);
1.709
1.710 - if (vbin != NULL)
1.711 - gst_object_unref(vbin);
1.712 + if (vbin != NULL)
1.713 + gst_object_unref(vbin);
1.714
1.715 - if (vqueue != NULL)
1.716 - gst_object_unref(vqueue);
1.717 + if (vqueue != NULL)
1.718 + gst_object_unref(vqueue);
1.719
1.720 - if (vencode != NULL)
1.721 - gst_object_unref(vencode);
1.722 + if (vencode != NULL)
1.723 + gst_object_unref(vencode);
1.724
1.725 - if (vqueue_src != NULL)
1.726 - gst_object_unref(vqueue_src);
1.727 + if (vqueue_src != NULL)
1.728 + gst_object_unref(vqueue_src);
1.729
1.730 - if (vcolorspace != NULL)
1.731 - gst_object_unref(vcolorspace);
1.732 + if (vcolorspace != NULL)
1.733 + gst_object_unref(vcolorspace);
1.734
1.735 - return NULL;
1.736 + return NULL;
1.737 }
1.738
1.739
1.740
1.741 void
1.742 g_mencoder_setup_stream(GMencoder * self,
1.743 - const gchar * mux_name,
1.744 - const gchar * video_encode,
1.745 - gchar ** video_encode_prop,
1.746 - gdouble video_fps,
1.747 - gdouble video_rate,
1.748 - guint video_width,
1.749 - guint video_height,
1.750 - const gchar * audio_encode,
1.751 - gchar ** audio_encode_prop,
1.752 - guint audio_rate, const gchar * out_uri)
1.753 + const gchar * mux_name,
1.754 + const gchar * video_encode,
1.755 + gchar ** video_encode_prop,
1.756 + gdouble video_fps,
1.757 + gdouble video_rate,
1.758 + guint video_width,
1.759 + guint video_height,
1.760 + const gchar * audio_encode,
1.761 + gchar ** audio_encode_prop,
1.762 + guint audio_rate, const gchar * out_uri)
1.763 {
1.764 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.765 - if (priv->ready == TRUE)
1.766 - {
1.767 - g_warning("Stream already configured. You need close stream first.");
1.768 - return;
1.769 - }
1.770 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.771 + if (priv->ready == TRUE) {
1.772 + g_warning
1.773 + ("Stream already configured. You need close stream first.");
1.774 + return;
1.775 + }
1.776
1.777 - _close_output(self);
1.778 - _open_output(self, out_uri);
1.779 + _close_output(self);
1.780 + _open_output(self, out_uri);
1.781
1.782 - priv->sources = 0;
1.783 - priv->pipe = _create_pipeline(self,
1.784 - video_encode,
1.785 - mux_name,
1.786 - video_encode_prop,
1.787 - video_fps,
1.788 - video_rate,
1.789 - video_width,
1.790 - video_height,
1.791 - audio_encode, audio_encode_prop, audio_rate);
1.792 + priv->sources = 0;
1.793 + priv->pipe = _create_pipeline(self,
1.794 + video_encode,
1.795 + mux_name,
1.796 + video_encode_prop,
1.797 + video_fps,
1.798 + video_rate,
1.799 + video_width,
1.800 + video_height,
1.801 + audio_encode, audio_encode_prop,
1.802 + audio_rate);
1.803
1.804 }
1.805
1.806 @@ -494,96 +478,93 @@
1.807 gboolean
1.808 g_mencoder_append_uri(GMencoder * self, const gchar * uri)
1.809 {
1.810 - GstPad *pad_src;
1.811 - GstPad *pad_sink;
1.812 - GstElement *src;
1.813 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.814 - gboolean ret = FALSE;
1.815 - GstElement *ap = NULL;
1.816 - GstElement *vp = NULL;
1.817 + GstPad *pad_src;
1.818 + GstPad *pad_sink;
1.819 + GstElement *src;
1.820 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.821 + gboolean ret = FALSE;
1.822 + GstElement *ap = NULL;
1.823 + GstElement *vp = NULL;
1.824
1.825
1.826 - g_return_val_if_fail(priv->pipe != NULL, FALSE);
1.827 - g_return_val_if_fail(priv->ready == FALSE, FALSE);
1.828 + g_return_val_if_fail(priv->pipe != NULL, FALSE);
1.829 + g_return_val_if_fail(priv->ready == FALSE, FALSE);
1.830
1.831 #ifndef SUPPORT_MULT_INPUT
1.832 - g_return_val_if_fail(priv->sources < 1, FALSE);
1.833 + g_return_val_if_fail(priv->sources < 1, FALSE);
1.834 #endif
1.835
1.836 - src = _create_source(uri);
1.837 - if (src == NULL)
1.838 - return FALSE;
1.839 + src = _create_source(uri);
1.840 + if (src == NULL)
1.841 + return FALSE;
1.842
1.843 - priv->src = gst_bin_get_by_name(GST_BIN(src), "src");
1.844 + priv->src = gst_bin_get_by_name(GST_BIN(src), "src");
1.845
1.846 - gst_bin_add(GST_BIN(priv->pipe), src);
1.847 + gst_bin_add(GST_BIN(priv->pipe), src);
1.848
1.849 #ifdef SUPPORT_MULT_INPUT
1.850 - ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "ap");
1.851 - vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vp");
1.852 + ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "ap");
1.853 + vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vp");
1.854 #else
1.855 - ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin");
1.856 - vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin");
1.857 + ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin");
1.858 + vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin");
1.859 #endif
1.860
1.861 - if ((vp == NULL) || (ap == NULL))
1.862 - {
1.863 - g_warning("Fail to get output bin");
1.864 - goto error;
1.865 - }
1.866 + if ((vp == NULL) || (ap == NULL)) {
1.867 + g_warning("Fail to get output bin");
1.868 + goto error;
1.869 + }
1.870
1.871 - pad_src = gst_element_get_pad(src, "src_audio");
1.872 - pad_sink = gst_element_get_compatible_pad(ap,
1.873 - pad_src,
1.874 - gst_pad_get_caps(pad_src));
1.875 + pad_src = gst_element_get_pad(src, "src_audio");
1.876 + pad_sink = gst_element_get_compatible_pad(ap,
1.877 + pad_src,
1.878 + gst_pad_get_caps(pad_src));
1.879
1.880 - if ((pad_sink == NULL) || (pad_src == NULL))
1.881 - goto error;
1.882 + if ((pad_sink == NULL) || (pad_src == NULL))
1.883 + goto error;
1.884
1.885 - GstPadLinkReturn lret = gst_pad_link(pad_src, pad_sink);
1.886 - if (lret != GST_PAD_LINK_OK)
1.887 - goto error;
1.888 + GstPadLinkReturn lret = gst_pad_link(pad_src, pad_sink);
1.889 + if (lret != GST_PAD_LINK_OK)
1.890 + goto error;
1.891
1.892 - gst_object_unref(pad_src);
1.893 - gst_object_unref(pad_sink);
1.894 + gst_object_unref(pad_src);
1.895 + gst_object_unref(pad_sink);
1.896
1.897 - pad_src = gst_element_get_pad(src, "src_video");
1.898 - pad_sink = gst_element_get_compatible_pad(vp,
1.899 - pad_src,
1.900 - gst_pad_get_caps(pad_src));
1.901 + pad_src = gst_element_get_pad(src, "src_video");
1.902 + pad_sink = gst_element_get_compatible_pad(vp,
1.903 + pad_src,
1.904 + gst_pad_get_caps(pad_src));
1.905
1.906 - if ((pad_src == NULL) || (pad_sink == NULL))
1.907 - goto error;
1.908 + if ((pad_src == NULL) || (pad_sink == NULL))
1.909 + goto error;
1.910
1.911 - if (gst_pad_link(pad_src, pad_sink) != GST_PAD_LINK_OK)
1.912 - {
1.913 - g_warning("invalid source. video");
1.914 - goto error;
1.915 - }
1.916 + if (gst_pad_link(pad_src, pad_sink) != GST_PAD_LINK_OK) {
1.917 + g_warning("invalid source. video");
1.918 + goto error;
1.919 + }
1.920
1.921 - priv->sources++;
1.922 - ret = TRUE;
1.923 -error:
1.924 + priv->sources++;
1.925 + ret = TRUE;
1.926 + error:
1.927
1.928 - if ((src != NULL) && (ret == FALSE))
1.929 - {
1.930 - gst_bin_remove(GST_BIN(priv->pipe), src);
1.931 - gst_object_unref(src);
1.932 - }
1.933 + if ((src != NULL) && (ret == FALSE)) {
1.934 + gst_bin_remove(GST_BIN(priv->pipe), src);
1.935 + gst_object_unref(src);
1.936 + }
1.937
1.938 - if (ap != NULL)
1.939 - gst_object_unref(ap);
1.940 + if (ap != NULL)
1.941 + gst_object_unref(ap);
1.942
1.943 - if (vp != NULL)
1.944 - gst_object_unref(vp);
1.945 + if (vp != NULL)
1.946 + gst_object_unref(vp);
1.947
1.948 - if (pad_src != NULL)
1.949 - gst_object_unref(pad_src);
1.950 + if (pad_src != NULL)
1.951 + gst_object_unref(pad_src);
1.952
1.953 - if (pad_sink != NULL)
1.954 - gst_object_unref(pad_sink);
1.955 + if (pad_sink != NULL)
1.956 + gst_object_unref(pad_sink);
1.957
1.958 - return ret;
1.959 + return ret;
1.960 }
1.961
1.962
1.963 @@ -591,217 +572,206 @@
1.964 void
1.965 g_mencoder_remove_uri(GMencoder * self, const gchar * uri)
1.966 {
1.967 - // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.968 - //TODO: remove src
1.969 + // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.970 + // TODO: remove src
1.971 }
1.972
1.973 void
1.974 g_mencoder_play_stream(GMencoder * self)
1.975 {
1.976 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.977 - g_return_if_fail(priv->ready == FALSE);
1.978 - priv->ready = TRUE;
1.979 - gst_element_set_state(priv->pipe, GST_STATE_PLAYING);
1.980 - priv->tick_id = g_timeout_add(500, _tick_cb, self);
1.981 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.982 + g_return_if_fail(priv->ready == FALSE);
1.983 + priv->ready = TRUE;
1.984 + gst_element_set_state(priv->pipe, GST_STATE_PLAYING);
1.985 + priv->tick_id = g_timeout_add(500, _tick_cb, self);
1.986 }
1.987
1.988 void
1.989 g_mencoder_pause_stream(GMencoder * self)
1.990 {
1.991 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.992 - g_return_if_fail(priv->ready == TRUE);
1.993 - gst_element_set_state(priv->pipe, GST_STATE_PAUSED);
1.994 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.995 + g_return_if_fail(priv->ready == TRUE);
1.996 + gst_element_set_state(priv->pipe, GST_STATE_PAUSED);
1.997 }
1.998
1.999 void
1.1000 g_mencoder_close_stream(GMencoder * self)
1.1001 {
1.1002
1.1003 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1004 - if (priv->tick_id != 0)
1.1005 - {
1.1006 - g_source_remove(priv->tick_id);
1.1007 - priv->tick_id = 0;
1.1008 - }
1.1009 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1010 + if (priv->tick_id != 0) {
1.1011 + g_source_remove(priv->tick_id);
1.1012 + priv->tick_id = 0;
1.1013 + }
1.1014
1.1015 - if (priv->pipe != NULL)
1.1016 - {
1.1017 - //TODO: fixe pipeline dispose
1.1018 - //gst_element_set_state (priv->pipe, GST_STATE_NULL);
1.1019 - //g_debug ("SETING STATE TO NULL: OK");
1.1020 - //gst_element_set_state (priv->pipe, GST_STATE_NULL);
1.1021 - //gst_object_unref (priv->pipe);
1.1022 - gst_object_unref(priv->src);
1.1023 - priv->src = NULL;
1.1024 - priv->pipe = NULL;
1.1025 - priv->abin = NULL;
1.1026 - priv->vbin = NULL;
1.1027 - priv->sink = NULL;
1.1028 - }
1.1029 - priv->ready = FALSE;
1.1030 + if (priv->pipe != NULL) {
1.1031 + // TODO: fixe pipeline dispose
1.1032 + // gst_element_set_state (priv->pipe, GST_STATE_NULL);
1.1033 + // g_debug ("SETING STATE TO NULL: OK");
1.1034 + // gst_element_set_state (priv->pipe, GST_STATE_NULL);
1.1035 + // gst_object_unref (priv->pipe);
1.1036 + gst_object_unref(priv->src);
1.1037 + priv->src = NULL;
1.1038 + priv->pipe = NULL;
1.1039 + priv->abin = NULL;
1.1040 + priv->vbin = NULL;
1.1041 + priv->sink = NULL;
1.1042 + }
1.1043 + priv->ready = FALSE;
1.1044 }
1.1045
1.1046 static GstElement *
1.1047 _create_pipeline(GMencoder * self,
1.1048 - const gchar * video_encode,
1.1049 - const gchar * mux_name,
1.1050 - gchar ** video_encode_prop,
1.1051 - gdouble video_fps,
1.1052 - gdouble video_rate,
1.1053 - guint video_width,
1.1054 - guint video_height,
1.1055 - const gchar * audio_encode,
1.1056 - gchar ** audio_encode_prop, guint audio_rate)
1.1057 + const gchar * video_encode,
1.1058 + const gchar * mux_name,
1.1059 + gchar ** video_encode_prop,
1.1060 + gdouble video_fps,
1.1061 + gdouble video_rate,
1.1062 + guint video_width,
1.1063 + guint video_height,
1.1064 + const gchar * audio_encode,
1.1065 + gchar ** audio_encode_prop, guint audio_rate)
1.1066 {
1.1067 - GstBus *bus = NULL;
1.1068 - GstElement *pipe = NULL;
1.1069 - GstElement *sink = NULL;
1.1070 - GstElement *mux = NULL;
1.1071 - GstElement *abin = NULL;
1.1072 - GstElement *vbin = NULL;
1.1073 - GstElement *queue = NULL;
1.1074 - GstPad *aux_pad = NULL;
1.1075 - GstPad *mux_pad = NULL;
1.1076 + GstBus *bus = NULL;
1.1077 + GstElement *pipe = NULL;
1.1078 + GstElement *sink = NULL;
1.1079 + GstElement *mux = NULL;
1.1080 + GstElement *abin = NULL;
1.1081 + GstElement *vbin = NULL;
1.1082 + GstElement *queue = NULL;
1.1083 + GstPad *aux_pad = NULL;
1.1084 + GstPad *mux_pad = NULL;
1.1085 #ifdef SUPPORT_MULT_INPUT
1.1086 - GstElement *ap = NULL;
1.1087 - GstElement *vp = NULL;
1.1088 + GstElement *ap = NULL;
1.1089 + GstElement *vp = NULL;
1.1090 #endif
1.1091 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1092 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1093
1.1094 - pipe = gst_pipeline_new("pipe");
1.1095 + pipe = gst_pipeline_new("pipe");
1.1096
1.1097 #ifdef SUPPORT_MULT_INPUT
1.1098 - ap = gst_element_factory_make("concatmux", "ap");
1.1099 - vp = gst_element_factory_make("concatmux", "vp");
1.1100 - gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL);
1.1101 + ap = gst_element_factory_make("concatmux", "ap");
1.1102 + vp = gst_element_factory_make("concatmux", "vp");
1.1103 + gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL);
1.1104 #endif
1.1105
1.1106 - mux = gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"), "mux");
1.1107 - if (mux == NULL)
1.1108 - goto error;
1.1109 + mux =
1.1110 + gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"),
1.1111 + "mux");
1.1112 + if (mux == NULL)
1.1113 + goto error;
1.1114
1.1115 - queue = gst_element_factory_make("queue", "queueu_sink");
1.1116 + queue = gst_element_factory_make("queue", "queueu_sink");
1.1117
1.1118
1.1119 - sink = gst_element_factory_make("fdsink", "sink");
1.1120 - if (sink == NULL)
1.1121 - goto error;
1.1122 + sink = gst_element_factory_make("fdsink", "sink");
1.1123 + if (sink == NULL)
1.1124 + goto error;
1.1125
1.1126 - g_object_set(G_OBJECT(sink), "fd", priv->fd, "sync", FALSE, NULL);
1.1127 + g_object_set(G_OBJECT(sink), "fd", priv->fd, "sync", FALSE, NULL);
1.1128
1.1129 - abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate);
1.1130 - if (abin == NULL)
1.1131 - goto error;
1.1132 + abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate);
1.1133 + if (abin == NULL)
1.1134 + goto error;
1.1135
1.1136 - vbin =
1.1137 - _create_video_bin(video_encode, video_encode_prop, video_fps, video_rate,
1.1138 - video_width, video_height);
1.1139 - if (vbin == NULL)
1.1140 - goto error;
1.1141 + vbin =
1.1142 + _create_video_bin(video_encode, video_encode_prop, video_fps,
1.1143 + video_rate, video_width, video_height);
1.1144 + if (vbin == NULL)
1.1145 + goto error;
1.1146
1.1147 - // Finish Pipe
1.1148 - gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL);
1.1149 + // Finish Pipe
1.1150 + gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL);
1.1151
1.1152
1.1153 #ifdef SUPPORT_MULT_INPUT
1.1154 - if (gst_element_link(ap, abin) == FALSE)
1.1155 - {
1.1156 - g_warning("Fail to link concat and abin");
1.1157 - goto error;
1.1158 - }
1.1159 + if (gst_element_link(ap, abin) == FALSE) {
1.1160 + g_warning("Fail to link concat and abin");
1.1161 + goto error;
1.1162 + }
1.1163
1.1164 - if (gst_element_link(vp, vbin) == FALSE)
1.1165 - {
1.1166 - g_warning("Fail to link concat and vbin");
1.1167 - }
1.1168 + if (gst_element_link(vp, vbin) == FALSE) {
1.1169 + g_warning("Fail to link concat and vbin");
1.1170 + }
1.1171 #endif
1.1172
1.1173 - //Link bins with mux
1.1174 - aux_pad = gst_element_get_pad(abin, "src");
1.1175 - mux_pad =
1.1176 - gst_element_get_compatible_pad(mux, aux_pad, GST_PAD_CAPS(aux_pad));
1.1177 - if (mux_pad == NULL)
1.1178 - {
1.1179 - g_warning("Mux element no have audio PAD");
1.1180 - goto error;
1.1181 - }
1.1182 - GstPadLinkReturn ret = gst_pad_link(aux_pad, mux_pad);
1.1183 - if (ret != GST_PAD_LINK_OK)
1.1184 - {
1.1185 - g_warning("Fail link audio and mux: %d", ret);
1.1186 - goto error;
1.1187 + // Link bins with mux
1.1188 + aux_pad = gst_element_get_pad(abin, "src");
1.1189 + mux_pad =
1.1190 + gst_element_get_compatible_pad(mux, aux_pad,
1.1191 + GST_PAD_CAPS(aux_pad));
1.1192 + if (mux_pad == NULL) {
1.1193 + g_warning("Mux element no have audio PAD");
1.1194 + goto error;
1.1195 + }
1.1196 + GstPadLinkReturn ret = gst_pad_link(aux_pad, mux_pad);
1.1197 + if (ret != GST_PAD_LINK_OK) {
1.1198 + g_warning("Fail link audio and mux: %d", ret);
1.1199 + goto error;
1.1200
1.1201 - }
1.1202 - gst_object_unref(aux_pad);
1.1203 - gst_object_unref(mux_pad);
1.1204 + }
1.1205 + gst_object_unref(aux_pad);
1.1206 + gst_object_unref(mux_pad);
1.1207
1.1208 - aux_pad = gst_element_get_pad(vbin, "src");
1.1209 - mux_pad =
1.1210 - gst_element_get_compatible_pad(mux, aux_pad, GST_PAD_CAPS(aux_pad));
1.1211 - if (mux_pad == NULL)
1.1212 - {
1.1213 - g_warning("Mux element no have video PAD");
1.1214 - goto error;
1.1215 - }
1.1216 - ret = gst_pad_link(aux_pad, mux_pad);
1.1217 - if (ret != GST_PAD_LINK_OK)
1.1218 - {
1.1219 - g_warning("Fail link video and mux: %d", ret);
1.1220 - goto error;
1.1221 - }
1.1222 - gst_object_unref(aux_pad);
1.1223 - gst_object_unref(mux_pad);
1.1224 - aux_pad = NULL;
1.1225 - mux_pad = NULL;
1.1226 + aux_pad = gst_element_get_pad(vbin, "src");
1.1227 + mux_pad =
1.1228 + gst_element_get_compatible_pad(mux, aux_pad,
1.1229 + GST_PAD_CAPS(aux_pad));
1.1230 + if (mux_pad == NULL) {
1.1231 + g_warning("Mux element no have video PAD");
1.1232 + goto error;
1.1233 + }
1.1234 + ret = gst_pad_link(aux_pad, mux_pad);
1.1235 + if (ret != GST_PAD_LINK_OK) {
1.1236 + g_warning("Fail link video and mux: %d", ret);
1.1237 + goto error;
1.1238 + }
1.1239 + gst_object_unref(aux_pad);
1.1240 + gst_object_unref(mux_pad);
1.1241 + aux_pad = NULL;
1.1242 + mux_pad = NULL;
1.1243
1.1244 - //Link mux with sink
1.1245 - gst_element_link_many(mux, queue, sink, NULL);
1.1246 + // Link mux with sink
1.1247 + gst_element_link_many(mux, queue, sink, NULL);
1.1248
1.1249 - bus = gst_pipeline_get_bus(GST_PIPELINE(pipe));
1.1250 - gst_bus_add_watch(bus, _pipeline_bus_cb, self);
1.1251 - gst_object_unref(bus);
1.1252 - return pipe;
1.1253 + bus = gst_pipeline_get_bus(GST_PIPELINE(pipe));
1.1254 + gst_bus_add_watch(bus, _pipeline_bus_cb, self);
1.1255 + gst_object_unref(bus);
1.1256 + return pipe;
1.1257
1.1258 -error:
1.1259 - g_warning("Invalid uri");
1.1260 + error:
1.1261 + g_warning("Invalid uri");
1.1262
1.1263 - if (pipe != NULL)
1.1264 - {
1.1265 - gst_object_unref(pipe);
1.1266 - }
1.1267 + if (pipe != NULL) {
1.1268 + gst_object_unref(pipe);
1.1269 + }
1.1270
1.1271
1.1272 - if (mux != NULL)
1.1273 - {
1.1274 - gst_object_unref(mux);
1.1275 - }
1.1276 + if (mux != NULL) {
1.1277 + gst_object_unref(mux);
1.1278 + }
1.1279
1.1280 - if (mux_pad != NULL)
1.1281 - {
1.1282 - gst_object_unref(mux_pad);
1.1283 - }
1.1284 + if (mux_pad != NULL) {
1.1285 + gst_object_unref(mux_pad);
1.1286 + }
1.1287
1.1288 - if (aux_pad != NULL)
1.1289 - {
1.1290 - gst_object_unref(mux_pad);
1.1291 - }
1.1292 + if (aux_pad != NULL) {
1.1293 + gst_object_unref(mux_pad);
1.1294 + }
1.1295
1.1296 - if (sink != NULL)
1.1297 - {
1.1298 - gst_object_unref(sink);
1.1299 - }
1.1300 + if (sink != NULL) {
1.1301 + gst_object_unref(sink);
1.1302 + }
1.1303
1.1304 - if (abin != NULL)
1.1305 - {
1.1306 - gst_object_unref(abin);
1.1307 - }
1.1308 + if (abin != NULL) {
1.1309 + gst_object_unref(abin);
1.1310 + }
1.1311
1.1312 - if (vbin != NULL)
1.1313 - {
1.1314 - gst_object_unref(vbin);
1.1315 - }
1.1316 + if (vbin != NULL) {
1.1317 + gst_object_unref(vbin);
1.1318 + }
1.1319
1.1320 - return FALSE;
1.1321 + return FALSE;
1.1322 }
1.1323
1.1324
1.1325 @@ -814,252 +784,234 @@
1.1326 _create_source(const gchar * uri)
1.1327 {
1.1328
1.1329 - GstElement *bsrc = NULL;
1.1330 - GstElement *src = NULL;
1.1331 - GstElement *queue = NULL;
1.1332 - GstElement *aqueue = NULL;
1.1333 - GstElement *vqueue = NULL;
1.1334 - GstElement *decode = NULL;
1.1335 - GstPad *src_pad = NULL;
1.1336 + GstElement *bsrc = NULL;
1.1337 + GstElement *src = NULL;
1.1338 + GstElement *queue = NULL;
1.1339 + GstElement *aqueue = NULL;
1.1340 + GstElement *vqueue = NULL;
1.1341 + GstElement *decode = NULL;
1.1342 + GstPad *src_pad = NULL;
1.1343
1.1344
1.1345 - bsrc = gst_bin_new(NULL);
1.1346 + bsrc = gst_bin_new(NULL);
1.1347
1.1348 - //src = gst_element_factory_make ("gnomevfssrc", "src");
1.1349 - //g_object_set (G_OBJECT (src), "location", uri, NULL);
1.1350 - src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
1.1351 - if (src == NULL)
1.1352 - goto error;
1.1353 + // src = gst_element_factory_make ("gnomevfssrc", "src");
1.1354 + // g_object_set (G_OBJECT (src), "location", uri, NULL);
1.1355 + src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
1.1356 + if (src == NULL)
1.1357 + goto error;
1.1358
1.1359 - decode = gst_element_factory_make("decodebin", "decode");
1.1360 - if (decode == NULL)
1.1361 - goto error;
1.1362 + decode = gst_element_factory_make("decodebin", "decode");
1.1363 + if (decode == NULL)
1.1364 + goto error;
1.1365
1.1366 - queue = gst_element_factory_make("queue", "queue_src");
1.1367 - aqueue = gst_element_factory_make("queue", "aqueue");
1.1368 - if (aqueue == NULL)
1.1369 - goto error;
1.1370 + queue = gst_element_factory_make("queue", "queue_src");
1.1371 + aqueue = gst_element_factory_make("queue", "aqueue");
1.1372 + if (aqueue == NULL)
1.1373 + goto error;
1.1374
1.1375 - vqueue = gst_element_factory_make("queue", "vqueue");
1.1376 - if (vqueue == NULL)
1.1377 - goto error;
1.1378 + vqueue = gst_element_factory_make("queue", "vqueue");
1.1379 + if (vqueue == NULL)
1.1380 + goto error;
1.1381
1.1382 - gst_bin_add_many(GST_BIN(bsrc), src, queue, decode, aqueue, vqueue, NULL);
1.1383 - gst_element_link_many(src, queue, decode, NULL);
1.1384 + gst_bin_add_many(GST_BIN(bsrc), src, queue, decode, aqueue, vqueue,
1.1385 + NULL);
1.1386 + gst_element_link_many(src, queue, decode, NULL);
1.1387
1.1388 - g_signal_connect(G_OBJECT(decode),
1.1389 - "new-decoded-pad",
1.1390 - G_CALLBACK(_decodebin_new_pad_cb), bsrc);
1.1391 + g_signal_connect(G_OBJECT(decode),
1.1392 + "new-decoded-pad",
1.1393 + G_CALLBACK(_decodebin_new_pad_cb), bsrc);
1.1394
1.1395 - g_signal_connect(G_OBJECT(decode),
1.1396 - "unknown-type",
1.1397 - G_CALLBACK(_decodebin_unknown_type_cb), pipe);
1.1398 + g_signal_connect(G_OBJECT(decode),
1.1399 + "unknown-type",
1.1400 + G_CALLBACK(_decodebin_unknown_type_cb), pipe);
1.1401
1.1402 - src_pad = gst_element_get_pad(aqueue, "src");
1.1403 - gst_element_add_pad(bsrc, gst_ghost_pad_new("src_audio", src_pad));
1.1404 - gst_object_unref(src_pad);
1.1405 + src_pad = gst_element_get_pad(aqueue, "src");
1.1406 + gst_element_add_pad(bsrc, gst_ghost_pad_new("src_audio", src_pad));
1.1407 + gst_object_unref(src_pad);
1.1408
1.1409 - src_pad = gst_element_get_pad(vqueue, "src");
1.1410 - gst_element_add_pad(bsrc, gst_ghost_pad_new("src_video", src_pad));
1.1411 - gst_object_unref(src_pad);
1.1412 + src_pad = gst_element_get_pad(vqueue, "src");
1.1413 + gst_element_add_pad(bsrc, gst_ghost_pad_new("src_video", src_pad));
1.1414 + gst_object_unref(src_pad);
1.1415
1.1416 - return bsrc;
1.1417 + return bsrc;
1.1418
1.1419 -error:
1.1420 - if (src != NULL)
1.1421 - {
1.1422 - gst_object_unref(src);
1.1423 - }
1.1424 + error:
1.1425 + if (src != NULL) {
1.1426 + gst_object_unref(src);
1.1427 + }
1.1428
1.1429 - if (decode != NULL)
1.1430 - {
1.1431 - gst_object_unref(decode);
1.1432 - }
1.1433 + if (decode != NULL) {
1.1434 + gst_object_unref(decode);
1.1435 + }
1.1436
1.1437 - if (aqueue != NULL)
1.1438 - {
1.1439 - gst_object_unref(aqueue);
1.1440 - }
1.1441 + if (aqueue != NULL) {
1.1442 + gst_object_unref(aqueue);
1.1443 + }
1.1444
1.1445 - if (vqueue != NULL)
1.1446 - {
1.1447 - gst_object_unref(vqueue);
1.1448 - }
1.1449 + if (vqueue != NULL) {
1.1450 + gst_object_unref(vqueue);
1.1451 + }
1.1452
1.1453 - return NULL;
1.1454 + return NULL;
1.1455 }
1.1456
1.1457 static void
1.1458 _open_output(GMencoder * self, const gchar * uri)
1.1459 {
1.1460 - gchar **i;
1.1461 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1462 + gchar **i;
1.1463 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.1464
1.1465 - i = g_strsplit(uri, "://", 0);
1.1466 - if (strcmp(i[0], "fd") == 0)
1.1467 - {
1.1468 - priv->fd = atoi(i[1]);
1.1469 - }
1.1470 - else if (strcmp(i[0], "file") == 0)
1.1471 - {
1.1472 - priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC,
1.1473 - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
1.1474 - }
1.1475 - else
1.1476 - {
1.1477 - g_warning("Output uri not supported");
1.1478 - }
1.1479 + i = g_strsplit(uri, "://", 0);
1.1480 + if (strcmp(i[0], "fd") == 0) {
1.1481 + priv->fd = atoi(i[1]);
1.1482 + } else if (strcmp(i[0], "file") == 0) {
1.1483 + priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC,
1.1484 + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
1.1485 + } else {
1.1486 + g_warning("Output uri not supported");
1.1487 + }
1.1488
1.1489 - g_strfreev(i);
1.1490 + g_strfreev(i);
1.1491 }
1.1492
1.1493 -static gboolean
1.1494 +static gboolean
1.1495 _pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data)
1.1496 {
1.1497 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1.1498 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1.1499
1.1500 - switch (GST_MESSAGE_TYPE(msg))
1.1501 - {
1.1502 + switch (GST_MESSAGE_TYPE(msg)) {
1.1503
1.1504 - case GST_MESSAGE_STATE_CHANGED:
1.1505 - {
1.1506 - GstState oldstate;
1.1507 - GstState newstate;
1.1508 - GstState pendingstate;
1.1509 + case GST_MESSAGE_STATE_CHANGED:
1.1510 + {
1.1511 + GstState oldstate;
1.1512 + GstState newstate;
1.1513 + GstState pendingstate;
1.1514
1.1515
1.1516 - gst_message_parse_state_changed(msg, &oldstate,
1.1517 - &newstate, &pendingstate);
1.1518 + gst_message_parse_state_changed(msg, &oldstate,
1.1519 + &newstate, &pendingstate);
1.1520
1.1521 - if (pendingstate != GST_STATE_VOID_PENDING)
1.1522 - break;
1.1523 + if (pendingstate != GST_STATE_VOID_PENDING)
1.1524 + break;
1.1525
1.1526 - if ((oldstate == GST_STATE_READY) && (newstate == GST_STATE_PAUSED))
1.1527 - {
1.1528 - if (priv->ready)
1.1529 - g_signal_emit(user_data, g_mencoder_signals[PAUSED], 0);
1.1530 - }
1.1531 - else if ((oldstate == GST_STATE_PAUSED) &&
1.1532 - (newstate == GST_STATE_PLAYING))
1.1533 - {
1.1534 - g_signal_emit(user_data, g_mencoder_signals[PLAYING], 0);
1.1535 - }
1.1536 - else if ((oldstate == GST_STATE_READY) &&
1.1537 - (newstate == GST_STATE_NULL))
1.1538 - {
1.1539 - g_signal_emit(user_data, g_mencoder_signals[STOPED], 0);
1.1540 - }
1.1541 - break;
1.1542 - }
1.1543 + if ((oldstate == GST_STATE_READY)
1.1544 + && (newstate == GST_STATE_PAUSED)) {
1.1545 + if (priv->ready)
1.1546 + g_signal_emit(user_data, g_mencoder_signals[PAUSED],
1.1547 + 0);
1.1548 + } else if ((oldstate == GST_STATE_PAUSED)
1.1549 + && (newstate == GST_STATE_PLAYING)) {
1.1550 + g_signal_emit(user_data, g_mencoder_signals[PLAYING], 0);
1.1551 + } else if ((oldstate == GST_STATE_READY) &&
1.1552 + (newstate == GST_STATE_NULL)) {
1.1553 + g_signal_emit(user_data, g_mencoder_signals[STOPED], 0);
1.1554 + }
1.1555 + break;
1.1556 + }
1.1557
1.1558 - case GST_MESSAGE_ERROR:
1.1559 - {
1.1560 - GError *error;
1.1561 - gchar *debug;
1.1562 - gchar *err_str;
1.1563 + case GST_MESSAGE_ERROR:
1.1564 + {
1.1565 + GError *error;
1.1566 + gchar *debug;
1.1567 + gchar *err_str;
1.1568
1.1569 - if (priv->tick_id != 0)
1.1570 - {
1.1571 - g_source_remove(priv->tick_id);
1.1572 - priv->tick_id = 0;
1.1573 - }
1.1574 + if (priv->tick_id != 0) {
1.1575 + g_source_remove(priv->tick_id);
1.1576 + priv->tick_id = 0;
1.1577 + }
1.1578
1.1579 - gst_message_parse_error(msg, &error, &debug);
1.1580 - err_str = g_strdup_printf("Error [%d] %s (%s)", error->code,
1.1581 - error->message, debug);
1.1582 - priv->ready = FALSE;
1.1583 - g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, err_str);
1.1584 - g_free(err_str);
1.1585 - g_clear_error(&error);
1.1586 - g_free(debug);
1.1587 - break;
1.1588 - }
1.1589 + gst_message_parse_error(msg, &error, &debug);
1.1590 + err_str = g_strdup_printf("Error [%d] %s (%s)", error->code,
1.1591 + error->message, debug);
1.1592 + priv->ready = FALSE;
1.1593 + g_signal_emit(user_data, g_mencoder_signals[ERROR], 0,
1.1594 + err_str);
1.1595 + g_free(err_str);
1.1596 + g_clear_error(&error);
1.1597 + g_free(debug);
1.1598 + break;
1.1599 + }
1.1600
1.1601 - case GST_MESSAGE_EOS:
1.1602 - priv->ready = FALSE;
1.1603 - g_signal_emit(user_data, g_mencoder_signals[EOS], 0);
1.1604 - break;
1.1605 + case GST_MESSAGE_EOS:
1.1606 + priv->ready = FALSE;
1.1607 + g_signal_emit(user_data, g_mencoder_signals[EOS], 0);
1.1608 + break;
1.1609
1.1610 - case GST_MESSAGE_DURATION:
1.1611 - {
1.1612 - GstFormat format;
1.1613 - gint64 duration;
1.1614 - gst_message_parse_duration(msg, &format, &duration);
1.1615 - if (format == GST_FORMAT_BYTES)
1.1616 - priv->duration = duration;
1.1617 - break;
1.1618 - }
1.1619 - default:
1.1620 - {
1.1621 - break;
1.1622 - }
1.1623 - }
1.1624 - return TRUE;
1.1625 + case GST_MESSAGE_DURATION:
1.1626 + {
1.1627 + GstFormat format;
1.1628 + gint64 duration;
1.1629 + gst_message_parse_duration(msg, &format, &duration);
1.1630 + if (format == GST_FORMAT_BYTES)
1.1631 + priv->duration = duration;
1.1632 + break;
1.1633 + }
1.1634 + default:
1.1635 + {
1.1636 + break;
1.1637 + }
1.1638 + }
1.1639 + return TRUE;
1.1640 }
1.1641
1.1642
1.1643
1.1644 static void
1.1645 _decodebin_new_pad_cb(GstElement * object,
1.1646 - GstPad * pad, gboolean flag, gpointer user_data)
1.1647 + GstPad * pad, gboolean flag, gpointer user_data)
1.1648 {
1.1649 - GstCaps *caps;
1.1650 - gchar *str_caps = NULL;
1.1651 - GstElement *sink_element;
1.1652 - GstPad *sink_pad;
1.1653 + GstCaps *caps;
1.1654 + gchar *str_caps = NULL;
1.1655 + GstElement *sink_element;
1.1656 + GstPad *sink_pad;
1.1657
1.1658 - caps = gst_pad_get_caps(pad);
1.1659 - str_caps = gst_caps_to_string(caps);
1.1660 - if (strstr(str_caps, "audio") != NULL)
1.1661 - {
1.1662 - sink_element = gst_bin_get_by_name(GST_BIN(user_data), "aqueue");
1.1663 - }
1.1664 - else if (strstr(str_caps, "video") != NULL)
1.1665 - {
1.1666 - sink_element = gst_bin_get_by_name(GST_BIN(user_data), "vqueue");
1.1667 - }
1.1668 - else
1.1669 - {
1.1670 - g_warning("invalid caps %s", str_caps);
1.1671 - }
1.1672 + caps = gst_pad_get_caps(pad);
1.1673 + str_caps = gst_caps_to_string(caps);
1.1674 + if (strstr(str_caps, "audio") != NULL) {
1.1675 + sink_element = gst_bin_get_by_name(GST_BIN(user_data), "aqueue");
1.1676 + } else if (strstr(str_caps, "video") != NULL) {
1.1677 + sink_element = gst_bin_get_by_name(GST_BIN(user_data), "vqueue");
1.1678 + } else {
1.1679 + g_warning("invalid caps %s", str_caps);
1.1680 + }
1.1681
1.1682 - sink_pad = gst_element_get_pad(sink_element, "sink");
1.1683 - gst_pad_link(pad, sink_pad);
1.1684 + sink_pad = gst_element_get_pad(sink_element, "sink");
1.1685 + gst_pad_link(pad, sink_pad);
1.1686
1.1687 - gst_object_unref(sink_element);
1.1688 - gst_object_unref(sink_pad);
1.1689 - g_free(str_caps);
1.1690 - gst_caps_unref(caps);
1.1691 + gst_object_unref(sink_element);
1.1692 + gst_object_unref(sink_pad);
1.1693 + g_free(str_caps);
1.1694 + gst_caps_unref(caps);
1.1695 }
1.1696
1.1697 static void
1.1698 _decodebin_unknown_type_cb(GstElement * object,
1.1699 - GstPad * pad, GstCaps * caps, gpointer user_data)
1.1700 + GstPad * pad, GstCaps * caps,
1.1701 + gpointer user_data)
1.1702 {
1.1703 - g_warning("Unknown Type");
1.1704 - //priv->ready = FALSE;
1.1705 + g_warning("Unknown Type");
1.1706 + // priv->ready = FALSE;
1.1707 }
1.1708
1.1709 -static gboolean
1.1710 +static gboolean
1.1711 _tick_cb(gpointer user_data)
1.1712 {
1.1713 - GstFormat format = GST_FORMAT_BYTES;
1.1714 - gint64 cur = 0;
1.1715 + GstFormat format = GST_FORMAT_BYTES;
1.1716 + gint64 cur = 0;
1.1717
1.1718 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1.1719 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1.1720
1.1721 - if (priv->duration == 0)
1.1722 - {
1.1723 - gint64 d = 0;
1.1724 - if (gst_element_query_duration(priv->src, &format, &d))
1.1725 - priv->duration = d;
1.1726 - }
1.1727 + if (priv->duration == 0) {
1.1728 + gint64 d = 0;
1.1729 + if (gst_element_query_duration(priv->src, &format, &d))
1.1730 + priv->duration = d;
1.1731 + }
1.1732
1.1733 - if (priv->duration != 0)
1.1734 - {
1.1735 - gst_element_query_position(priv->src, &format, &cur);
1.1736 - g_print("PROGRESS:%lli\n", (99 * cur) / priv->duration);
1.1737 - }
1.1738 + if (priv->duration != 0) {
1.1739 + gst_element_query_position(priv->src, &format, &cur);
1.1740 + g_print("PROGRESS:%lli\n", (99 * cur) / priv->duration);
1.1741 + }
1.1742
1.1743 - return TRUE;
1.1744 + return TRUE;
1.1745 }