static gchar * gst_stream_subtitle_information_to_string (GstDiscovererStreamInfo * info, gint depth) { GstDiscovererSubtitleInfo *subtitle_info; GString *s; gchar *tmp; const gchar *ctmp; int len = 400; const GstTagList *tags; GstCaps *caps; g_return_val_if_fail (info != NULL, NULL); s = g_string_sized_new (len); my_g_string_append_printf (s, depth, "Codec:\n"); caps = gst_discoverer_stream_info_get_caps (info); tmp = gst_caps_to_string (caps); gst_caps_unref (caps); my_g_string_append_printf (s, depth, " %s\n", tmp); g_free (tmp); my_g_string_append_printf (s, depth, "Additional info:\n"); if (gst_discoverer_stream_info_get_misc (info)) { tmp = gst_structure_to_string (gst_discoverer_stream_info_get_misc (info)); my_g_string_append_printf (s, depth, " %s\n", tmp); g_free (tmp); } else { my_g_string_append_printf (s, depth, " None\n"); } subtitle_info = (GstDiscovererSubtitleInfo *) info; ctmp = gst_discoverer_subtitle_info_get_language (subtitle_info); my_g_string_append_printf (s, depth, "Language: %s\n", ctmp ? ctmp : "<unknown>"); my_g_string_append_printf (s, depth, "Tags:\n"); tags = gst_discoverer_stream_info_get_tags (info); if (tags) { tmp = gst_structure_to_string ((GstStructure *) tags); my_g_string_append_printf (s, depth, " %s\n", tmp); g_free (tmp); } else { my_g_string_append_printf (s, depth, " None\n"); } if (verbose) my_g_string_append_printf (s, depth, "\n"); return g_string_free (s, FALSE); }
/** * @brief Funtion for new caps. * * GstBaseSink method implementation. */ static gboolean gst_tensor_sink2_set_caps (GstBaseSink * sink, GstCaps * caps) { GstTensorSink2 *self; self = GST_TENSOR_SINK2 (sink); g_mutex_lock (&self->mutex); gst_caps_replace (&self->in_caps, caps); g_mutex_unlock (&self->mutex); if (DBG) { guint caps_size, i; caps_size = gst_caps_get_size (caps); GST_DEBUG_OBJECT (self, "set caps, size is %d", caps_size); for (i = 0; i < caps_size; i++) { GstStructure *structure = gst_caps_get_structure (caps, i); gchar *str = gst_structure_to_string (structure); GST_DEBUG_OBJECT (self, "[%d] %s", i, str); g_free (str); } } return TRUE; }
static void gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s, guint depth) { gchar *tmp; GstCaps *caps; const GstStructure *misc; my_g_string_append_printf (s, depth, "Codec:\n"); caps = gst_discoverer_stream_info_get_caps (info); tmp = gst_caps_to_string (caps); gst_caps_unref (caps); my_g_string_append_printf (s, depth, " %s\n", tmp); g_free (tmp); my_g_string_append_printf (s, depth, "Additional info:\n"); if ((misc = gst_discoverer_stream_info_get_misc (info))) { tmp = gst_structure_to_string (misc); my_g_string_append_printf (s, depth, " %s\n", tmp); g_free (tmp); } else { my_g_string_append_printf (s, depth, " None\n"); } my_g_string_append_printf (s, depth, "Stream ID: %s\n", gst_discoverer_stream_info_get_stream_id (info)); }
static gboolean gst_fake_sink_event (GstBaseSink * bsink, GstEvent * event) { GstFakeSink *sink = GST_FAKE_SINK (bsink); if (!sink->silent) { const GstStructure *s; gchar *sstr; GST_OBJECT_LOCK (sink); g_free (sink->last_message); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); sink->last_message = g_strdup_printf ("event ******* E (type: %d, %s) %p", GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (sink); gst_fake_sink_notify_last_message (sink); } if (GST_BASE_SINK_CLASS (parent_class)->event) { return GST_BASE_SINK_CLASS (parent_class)->event (bsink, event); } else { return TRUE; } }
static gboolean gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc * dtmfsrc, GstEvent * event) { gboolean result = FALSE; gchar *struct_str; const GstStructure *structure; GstState state; GstStateChangeReturn ret; ret = gst_element_get_state (GST_ELEMENT (dtmfsrc), &state, NULL, 0); if (ret != GST_STATE_CHANGE_SUCCESS || state != GST_STATE_PLAYING) { GST_DEBUG_OBJECT (dtmfsrc, "Received event while not in PLAYING state"); goto ret; } GST_DEBUG_OBJECT (dtmfsrc, "Received event is of our interest"); structure = gst_event_get_structure (event); struct_str = gst_structure_to_string (structure); GST_DEBUG_OBJECT (dtmfsrc, "Event has structure %s", struct_str); g_free (struct_str); if (structure && gst_structure_has_name (structure, "dtmf-event")) result = gst_rtp_dtmf_src_handle_dtmf_event (dtmfsrc, structure); ret: return result; }
/** * @brief set_caps vmethod implementation */ static gboolean gst_tensor_reposink_set_caps (GstBaseSink * sink, GstCaps * caps) { GstTensorRepoSink *self; self = GST_TENSOR_REPOSINK (sink); gst_caps_replace (&self->in_caps, caps); /* debug print caps */ if (!self->silent) { GstStructure *structure; gchar *str; guint caps_size, i; caps_size = gst_caps_get_size (caps); GST_DEBUG_OBJECT (self, "set caps, size is %d", caps_size); for (i = 0; i < caps_size; i++) { structure = gst_caps_get_structure (caps, i); str = gst_structure_to_string (structure); GST_DEBUG_OBJECT (self, "[%d] %s", i, str); g_free (str); } } return TRUE; }
static gboolean gst_fake_src_event_handler (GstBaseSrc * basesrc, GstEvent * event) { GstFakeSrc *src; src = GST_FAKE_SRC (basesrc); if (!src->silent) { const GstStructure *s; gchar *sstr; GST_OBJECT_LOCK (src); g_free (src->last_message); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); src->last_message = g_strdup_printf ("event ******* E (type: %d, %s) %p", GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (src); g_object_notify (G_OBJECT (src), "last_message"); } return GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event); }
static gboolean gst_fake_src_event_handler (GstBaseSrc * basesrc, GstEvent * event) { GstFakeSrc *src; src = GST_FAKE_SRC (basesrc); if (!src->silent) { const GstStructure *s; const gchar *tstr; gchar *sstr; GST_OBJECT_LOCK (src); g_free (src->last_message); tstr = gst_event_type_get_name (GST_EVENT_TYPE (event)); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); src->last_message = g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p", GST_DEBUG_PAD_NAME (GST_BASE_SRC_CAST (src)->srcpad), tstr, GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (src); g_object_notify_by_pspec ((GObject *) src, pspec_last_message); } return GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event); }
static gboolean gst_goo_decgsmfr_sink_setcaps (GstPad *pad, GstCaps *caps) { GstStructure *structure; GstGooDecGsmFr *self; GooComponent *component; gchar *str_caps; guint sample_rate = DEFAULT_BITRATE; guint channels = CHANNELS_DEFAULT; self = GST_GOO_DECGSMFR (GST_PAD_PARENT (pad)); component = (GooComponent *) GST_GOO_AUDIO_FILTER (self)->component; GST_DEBUG_OBJECT (self, "sink_setcaps"); g_return_val_if_fail (gst_caps_get_size (caps) == 1, FALSE); structure = gst_caps_get_structure (caps, 0); str_caps = gst_structure_to_string (structure); GST_DEBUG_OBJECT (self, "sink caps: %s", str_caps); g_free (str_caps); if (gst_goo_util_structure_is_parsed (structure)) g_object_set (G_OBJECT (self), "process-mode", 0, NULL); gst_structure_get_int (structure, "rate", &sample_rate); gst_structure_get_int (structure, "channels", &channels); return gst_pad_set_caps (pad, caps); }
static gboolean gst_fake_sink_event (GstBaseSink * bsink, GstEvent * event) { GstFakeSink *sink = GST_FAKE_SINK (bsink); if (!sink->silent) { const GstStructure *s; const gchar *tstr; gchar *sstr; GST_OBJECT_LOCK (sink); g_free (sink->last_message); if (GST_EVENT_TYPE (event) == GST_EVENT_SINK_MESSAGE) { GstMessage *msg; const GstStructure *structure; gst_event_parse_sink_message (event, &msg); structure = gst_message_get_structure (msg); sstr = gst_structure_to_string (structure); sink->last_message = g_strdup_printf ("message ******* (%s:%s) M (type: %d, %s) %p", GST_DEBUG_PAD_NAME (GST_BASE_SINK_CAST (sink)->sinkpad), GST_MESSAGE_TYPE (msg), sstr, msg); gst_message_unref (msg); } else { tstr = gst_event_type_get_name (GST_EVENT_TYPE (event)); if ((s = gst_event_get_structure (event))) { sstr = gst_structure_to_string (s); } else { sstr = g_strdup (""); } sink->last_message = g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p", GST_DEBUG_PAD_NAME (GST_BASE_SINK_CAST (sink)->sinkpad), tstr, GST_EVENT_TYPE (event), sstr, event); } g_free (sstr); GST_OBJECT_UNLOCK (sink); gst_fake_sink_notify_last_message (sink); } return GST_BASE_SINK_CLASS (parent_class)->event (bsink, event); }
static void print_info (GstDiscovererInfo * info, GError * err) { GstDiscovererResult result = gst_discoverer_info_get_result (info); GstDiscovererStreamInfo *sinfo; g_print ("Done discovering %s\n", gst_discoverer_info_get_uri (info)); switch (result) { case GST_DISCOVERER_OK: { break; } case GST_DISCOVERER_URI_INVALID: { g_print ("URI is not valid\n"); break; } case GST_DISCOVERER_ERROR: { g_print ("An error was encountered while discovering the file\n"); g_print (" %s\n", err->message); break; } case GST_DISCOVERER_TIMEOUT: { g_print ("Analyzing URI timed out\n"); break; } case GST_DISCOVERER_BUSY: { g_print ("Discoverer was busy\n"); break; } case GST_DISCOVERER_MISSING_PLUGINS: { g_print ("Missing plugins\n"); if (verbose) { gchar *tmp = gst_structure_to_string (gst_discoverer_info_get_misc (info)); g_print (" (%s)\n", tmp); g_free (tmp); } break; } } if ((sinfo = gst_discoverer_info_get_stream_info (info))) { g_print ("\nTopology:\n"); print_topology (sinfo, 1); g_print ("\nProperties:\n"); print_properties (info, 1); gst_discoverer_stream_info_unref (sinfo); } g_print ("\n"); }
static void element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) { gchar *s; s = gst_structure_to_string (gst_message_get_structure (message)); GST_DEBUG ("Received message: %s", s); g_free (s); messages++; }
std::string VideoV4lSource::srcCaps(unsigned int framerateIndex) const { std::ostringstream capsStr; GstStateChangeReturn ret = gst_element_set_state(source_, GST_STATE_READY); if (ret not_eq GST_STATE_CHANGE_SUCCESS) THROW_ERROR("Could not change v4l2src state to READY"); GstPad *srcPad = gst_element_get_static_pad(source_, "src"); GstCaps *caps = gst_pad_get_caps(srcPad); GstStructure *structure = gst_caps_get_structure(caps, 0); const GValue *val = gst_structure_get_value(structure, "framerate"); LOG_DEBUG("Caps structure from v4l2src srcpad: " << gst_structure_to_string(structure)); gint framerate_numerator, framerate_denominator; if (GST_VALUE_HOLDS_LIST(val)) { // trying another one if (framerateIndex >= gst_value_list_get_size(val)) THROW_ERROR("Framerate index out of range"); framerate_numerator = gst_value_get_fraction_numerator((gst_value_list_get_value(val, framerateIndex))); framerate_denominator = gst_value_get_fraction_denominator((gst_value_list_get_value(val, framerateIndex))); } else { // FIXME: this is really bad, we should be iterating over framerates and resolutions until we find a good one if (framerateIndex > 0) LOG_ERROR("Caps parameters haven't been changed and have failed before"); framerate_numerator = gst_value_get_fraction_numerator(val); framerate_denominator = gst_value_get_fraction_denominator(val); } gst_caps_unref(caps); gst_object_unref(srcPad); // use default from gst std::string capsSuffix = boost::lexical_cast<std::string>(framerate_numerator); capsSuffix += "/"; capsSuffix += boost::lexical_cast<std::string>(framerate_denominator); if (v4l2util::isInterlaced(deviceStr())) capsSuffix +=", interlaced=true"; capsSuffix += ", pixel-aspect-ratio="; capsSuffix += config_.pixelAspectRatio(); capsStr << "video/x-raw-yuv, width=" << config_.captureWidth() << ", height=" << config_.captureHeight() << ", framerate=" << capsSuffix; LOG_DEBUG("V4l2src caps are " << capsStr.str()); ret = gst_element_set_state(source_, GST_STATE_NULL); if (ret not_eq GST_STATE_CHANGE_SUCCESS) THROW_ERROR("Could not change v4l2src state to NULL"); return capsStr.str(); }
static gboolean stats_cb (guint8 d, const GstStructure * stats, gpointer user_data) { if (d == domain) { gchar *stats_str = gst_structure_to_string (stats); g_print ("Got stats: %s\n", stats_str); g_free (stats_str); } return TRUE; }
static void print_caps (const GstCaps *caps) { int i; for (i = 0; i < gst_caps_get_size (caps); i++) { GstStructure *structure = gst_caps_get_structure (caps, i); gchar *tmp = gst_structure_to_string (structure); g_print ("%s`- %s\n", i ? " " : "", tmp); g_free (tmp); } }
static gboolean handle_bus_message (GstBus * bus, GstMessage * message, GstClock * client_clock) { if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) { const GstStructure *s = gst_message_get_structure (message); gchar *str; if (s == NULL) return TRUE; str = gst_structure_to_string (s); g_print ("%s\n", str); g_free (str); } return TRUE; }
/* print the stats of a source */ static void print_source_stats (GObject * source) { GstStructure *stats; gchar *str; /* get the source stats */ g_object_get (source, "stats", &stats, NULL); /* simply dump the stats structure */ str = gst_structure_to_string (stats); g_print ("source stats: %s\n", str); gst_structure_free (stats); g_free (str); }
static void print_message (GstMessage * message) { const GstStructure *s; s = gst_message_get_structure (message); g_print ("Got Message from element \"%s\"\n", GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message)))); if (s) { gchar *sstr; sstr = gst_structure_to_string (s); g_print ("%s\n", sstr); g_free (sstr); } }
/* called when a stream has received an RTCP packet from the client */ static void on_ssrc_active (GObject * session, GObject * source, GstRTSPMedia * media) { GstStructure *stats; GST_INFO ("source %p in session %p is active", source, session); g_object_get (source, "stats", &stats, NULL); if (stats) { gchar *sstr; sstr = gst_structure_to_string (stats); g_print ("structure: %s\n", sstr); g_free (sstr); gst_structure_free (stats); } }
bool ofxGstRTPServer::on_message(GstMessage * msg){ // read messages from the pipeline like dropped packages switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ELEMENT:{ GstObject * messageSrc = GST_MESSAGE_SRC(msg); ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg); ofLogVerbose(LOG_NAME) << "Message source type: " << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(messageSrc)); ofLogVerbose(LOG_NAME) << "With structure name: " << gst_structure_get_name(gst_message_get_structure(msg)); ofLogVerbose(LOG_NAME) << gst_structure_to_string(gst_message_get_structure(msg)); return true; } case GST_MESSAGE_QOS:{ GstObject * messageSrc = GST_MESSAGE_SRC(msg); ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg); ofLogVerbose(LOG_NAME) << "Message source type: " << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(messageSrc)); GstFormat format; guint64 processed; guint64 dropped; gst_message_parse_qos_stats(msg,&format,&processed,&dropped); ofLogVerbose(LOG_NAME) << "format " << gst_format_get_name(format) << " processed " << processed << " dropped " << dropped; gint64 jitter; gdouble proportion; gint quality; gst_message_parse_qos_values(msg,&jitter,&proportion,&quality); ofLogVerbose(LOG_NAME) << "jitter " << jitter << " proportion " << proportion << " quality " << quality; gboolean live; guint64 running_time; guint64 stream_time; guint64 timestamp; guint64 duration; gst_message_parse_qos(msg,&live,&running_time,&stream_time,×tamp,&duration); ofLogVerbose(LOG_NAME) << "live stream " << live << " runninng_time " << running_time << " stream_time " << stream_time << " timestamp " << timestamp << " duration " << duration; return true; } default: //ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg); return false; } }
static void message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) { const GstStructure *s; s = gst_message_get_structure (message); g_print ("message from \"%s\" (%s): ", GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), gst_message_type_get_name (GST_MESSAGE_TYPE (message))); if (s) { gchar *sstr; sstr = gst_structure_to_string (s); g_print ("%s\n", sstr); g_free (sstr); } else { g_print ("no message details\n"); } }
void media_bus_message(GstBus *bus, GstMessage *message, gpointer user_data) { switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: { GError *err = NULL; gchar *dbg = NULL; gst_message_parse_error(message, &err, &dbg); if (err) { g_error("RTSP Pipeline ERROR: %s", err->message); g_error_free(err); } if (dbg) { g_message("Debug details: %s", dbg); g_free(dbg); } break; } /* case GST_MESSAGE_STATE_CHANGED: case GST_MESSAGE_STREAM_STATUS: case GST_MESSAGE_TAG: case GST_MESSAGE_NEW_CLOCK: { // Ignore break; } */ default: { const GstStructure* mstruct = gst_message_get_structure(message); char* struct_info = mstruct ? gst_structure_to_string(mstruct) : g_strdup("no-struct"); g_message("RTSP bus Message '%s' from '%s': %s", GST_MESSAGE_TYPE_NAME(message), GST_MESSAGE_SRC_NAME(message), struct_info); g_free(struct_info); break; } } }
static void lgm_device_parse_structure (GstStructure * s, GHashTable * table) { gint width, height; const GValue *val; gchar *struct_str; struct_str = gst_structure_to_string (s); GST_DEBUG ("Parsing structure: %s\n", struct_str); g_free (struct_str); width = lgm_device_fixate_int_value (gst_structure_get_value (s, "width")); height = lgm_device_fixate_int_value (gst_structure_get_value (s, "height")); val = gst_structure_get_value (s, "framerate"); if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION) { lgm_device_add_format_from_fps_val (table, width, height, val); } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) { /* For sources returning template caps or ranges set framerate to 0/0 */ lgm_device_add_format (table, width, height, 0, 0); } else if (G_VALUE_TYPE (val) == GST_TYPE_ARRAY) { guint n, len; len = gst_value_array_get_size (val); for (n = 0; n < len; n++) { const GValue *kid = gst_value_array_get_value (val, n); lgm_device_add_format_from_fps_val (table, width, height, kid); } } else if (G_VALUE_TYPE (val) == GST_TYPE_LIST) { guint n, len; len = gst_value_list_get_size (val); for (n = 0; n < len; n++) { const GValue *kid = gst_value_list_get_value (val, n); lgm_device_add_format_from_fps_val (table, width, height, kid); } } }
static GstPadProbeReturn _appsrc_event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer udata) { GstEvent *event = GST_PAD_PROBE_INFO_DATA (info); GstElement *appsrc = udata; const GstStructure *s; gchar *sstr; App *app = &s_app; GST_DEBUG ("element:%s got an event:%s", GST_ELEMENT_NAME (appsrc), GST_EVENT_TYPE_NAME (event)); if (GST_EVENT_TYPE (event) == GST_EVENT_CUSTOM_UPSTREAM) { s = gst_event_get_structure (event); sstr = gst_structure_to_string (s); if (g_str_equal (sstr, "application/x-custom;")) app->nb_received_event++; g_free (sstr); } else if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) { app->nb_received_event++; } return GST_PAD_PROBE_OK; }
bool ofGstUtils::gstHandleMessage(GstBus * bus, GstMessage * msg){ if(appsink && appsink->on_message(msg)) return true; /*ofLogVerbose("ofGstUtils") << "gstHandleMessage(): got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg);*/ switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_BUFFERING: gint pctBuffered; gst_message_parse_buffering(msg,&pctBuffered); ofLogVerbose("ofGstUtils") << "gstHandleMessage(): buffering " << pctBuffered; if(pctBuffered<100){ gst_element_set_state (gstPipeline, GST_STATE_PAUSED); }else if(!bPaused){ gst_element_set_state (gstPipeline, GST_STATE_PLAYING); } break; #if GST_VERSION_MAJOR==0 case GST_MESSAGE_DURATION:{ GstFormat format=GST_FORMAT_TIME; gst_element_query_duration(gstPipeline,&format,&durationNanos); }break; #else case GST_MESSAGE_DURATION_CHANGED: gst_element_query_duration(gstPipeline,GST_FORMAT_TIME,&durationNanos); break; #endif case GST_MESSAGE_STATE_CHANGED:{ GstState oldstate, newstate, pendstate; gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendstate); if(isStream && newstate==GST_STATE_PAUSED && !bPlaying ){ bLoaded = true; bPlaying = true; if(!bPaused){ //ofLogVerbose("ofGstUtils") << "gstHandleMessage(): setting stream pipeline to play"; play(); } } /*ofLogVerbose("ofGstUtils") << "gstHandleMessage(): " << GST_MESSAGE_SRC_NAME(msg) << " state changed from " << getName(oldstate) << " to " << getName(newstate) << " (" + getName(pendstate) << ")";*/ }break; case GST_MESSAGE_ASYNC_DONE: ofLogVerbose("ofGstUtils") << "gstHandleMessage(): async done"; break; case GST_MESSAGE_ERROR: { GError *err; gchar *debug; gst_message_parse_error(msg, &err, &debug); gchar * name = gst_element_get_name(GST_MESSAGE_SRC (msg)); ofLogError("ofGstUtils") << "gstHandleMessage(): embedded video playback halted for plugin, module " << name << " reported: " << err->message; g_free(name); g_error_free(err); g_free(debug); gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL); }break; case GST_MESSAGE_EOS:{ ofLogVerbose("ofGstUtils") << "gstHandleMessage(): end of the stream"; bool isClosing = closing; eos_cb(); if(isClosing){ busWatchID = 0; return false; } switch(loopMode){ case OF_LOOP_NORMAL:{ GstFormat format = GST_FORMAT_TIME; GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT); if(speed>0){ if(!gst_element_seek(GST_ELEMENT(gstPipeline), speed, format, flags, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, -1)) { ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek"; } }else if(speed<0){ if(!gst_element_seek(GST_ELEMENT(gstPipeline),speed, format, flags, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, durationNanos-1000000)) { ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek"; } } }break; case OF_LOOP_PALINDROME:{ GstFormat format = GST_FORMAT_TIME; GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT); gint64 pos; #if GST_VERSION_MAJOR==0 gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos); #else gst_element_query_position(GST_ELEMENT(gstPipeline),format,&pos); #endif float loopSpeed; if(pos>0) loopSpeed=-speed; else loopSpeed=speed; if(!gst_element_seek(GST_ELEMENT(gstPipeline), loopSpeed, GST_FORMAT_UNDEFINED, flags, GST_SEEK_TYPE_NONE, 0, GST_SEEK_TYPE_NONE, 0)) { ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek"; } }break; default: break; } }break; case GST_MESSAGE_LATENCY: gst_bin_recalculate_latency (GST_BIN (getPipeline())); break; case GST_MESSAGE_REQUEST_STATE: { GstState state; gchar *name = gst_object_get_path_string (GST_MESSAGE_SRC (msg)); gst_message_parse_request_state (msg, &state); gst_element_set_state (getPipeline(), state); g_free (name); break; } case GST_MESSAGE_HAVE_CONTEXT:{ GstContext *context; const gchar *context_type; gchar *context_str; gst_message_parse_have_context (msg, &context); context_type = gst_context_get_context_type (context); context_str = gst_structure_to_string (gst_context_get_structure (context)); ofLogNotice("ofGstUtils","Got context from element '%s': %s=%s\n", GST_ELEMENT_NAME (GST_MESSAGE_SRC (msg)), context_type, context_str); g_free (context_str); gst_context_unref (context); break; } default: ofLogVerbose("ofGstUtils") << "gstHandleMessage(): unhandled message from " << GST_MESSAGE_SRC_NAME(msg); break; } return true; }
static gboolean gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event) { GstIdentity *identity; gboolean ret = TRUE; identity = GST_IDENTITY (trans); if (!identity->silent) { const GstStructure *s; const gchar *tstr; gchar *sstr; GST_OBJECT_LOCK (identity); g_free (identity->last_message); tstr = gst_event_type_get_name (GST_EVENT_TYPE (event)); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); identity->last_message = g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p", GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (identity); gst_identity_notify_last_message (identity); } if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) { if (trans->have_segment == FALSE) { GstEvent *news; GstSegment segment; gst_event_copy_segment (event, &segment); gst_event_copy_segment (event, &trans->segment); trans->have_segment = TRUE; /* This is the first segment, send out a (0, -1) segment */ gst_segment_init (&segment, segment.format); news = gst_event_new_segment (&segment); gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news); } } /* Reset previous timestamp, duration and offsets on NEWSEGMENT * to prevent false warnings when checking for perfect streams */ if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE; identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE; } if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { /* eat up segments */ gst_event_unref (event); ret = TRUE; } else { if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) { GST_OBJECT_LOCK (identity); if (identity->clock_id) { GST_DEBUG_OBJECT (identity, "unlock clock wait"); gst_clock_id_unschedule (identity->clock_id); gst_clock_id_unref (identity->clock_id); identity->clock_id = NULL; } GST_OBJECT_UNLOCK (identity); } ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event); } return ret; }
static void print_plugin_automatic_install_info_codecs (GstElementFactory * factory) { GstPadDirection direction; const gchar *type_name; const gchar *klass; const GList *static_templates, *l; GstCaps *caps = NULL; guint i, num; klass = gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS); g_return_if_fail (klass != NULL); if (strstr (klass, "Demuxer") || strstr (klass, "Decoder") || strstr (klass, "Depay") || strstr (klass, "Parser")) { type_name = "decoder"; direction = GST_PAD_SINK; } else if (strstr (klass, "Muxer") || strstr (klass, "Encoder") || strstr (klass, "Pay")) { type_name = "encoder"; direction = GST_PAD_SRC; } else { return; } /* decoder/demuxer sink pads should always be static and there should only * be one, the same applies to encoders/muxers and source pads */ static_templates = gst_element_factory_get_static_pad_templates (factory); for (l = static_templates; l != NULL; l = l->next) { GstStaticPadTemplate *tmpl = NULL; tmpl = (GstStaticPadTemplate *) l->data; if (tmpl->direction == direction) { caps = gst_static_pad_template_get_caps (tmpl); break; } } if (caps == NULL) { g_printerr ("Couldn't find static pad template for %s '%s'\n", type_name, GST_OBJECT_NAME (factory)); return; } caps = gst_caps_make_writable (caps); num = gst_caps_get_size (caps); for (i = 0; i < num; ++i) { GstStructure *s; gchar *s_str; s = gst_caps_get_structure (caps, i); /* remove fields that are almost always just MIN-MAX of some sort * in order to make the caps look less messy */ gst_structure_remove_field (s, "pixel-aspect-ratio"); gst_structure_remove_field (s, "framerate"); gst_structure_remove_field (s, "channels"); gst_structure_remove_field (s, "width"); gst_structure_remove_field (s, "height"); gst_structure_remove_field (s, "rate"); gst_structure_remove_field (s, "depth"); gst_structure_remove_field (s, "clock-rate"); s_str = gst_structure_to_string (s); g_print ("%s-%s\n", type_name, s_str); g_free (s_str); } gst_caps_unref (caps); }
static gboolean gst_identity_event (GstBaseTransform * trans, GstEvent * event) { GstIdentity *identity; gboolean ret = TRUE; identity = GST_IDENTITY (trans); if (!identity->silent) { const GstStructure *s; gchar *sstr; GST_OBJECT_LOCK (identity); g_free (identity->last_message); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); identity->last_message = g_strdup_printf ("event ******* (%s:%s) E (type: %d, %s) %p", GST_DEBUG_PAD_NAME (trans->sinkpad), GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (identity); g_object_notify (G_OBJECT (identity), "last_message"); } if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) { if (trans->have_newsegment == FALSE) { GstEvent *news; GstFormat format; gst_event_parse_new_segment (event, NULL, NULL, &format, NULL, NULL, NULL); /* This is the first newsegment, send out a (0, -1) newsegment */ news = gst_event_new_new_segment (TRUE, 1.0, format, 0, -1, 0); if (!(gst_pad_event_default (trans->sinkpad, news))) return FALSE; } } /* Reset previous timestamp, duration and offsets on NEWSEGMENT * to prevent false warnings when checking for perfect streams */ if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) { identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE; identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE; } ret = parent_class->event (trans, event); if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT)) { /* eat up segments */ ret = FALSE; } return ret; }
static gchar * gst_stream_video_information_to_string (GstDiscovererStreamInfo * info, gint depth) { GstDiscovererVideoInfo *video_info; GString *s; gchar *tmp; int len = 500; const GstStructure *misc; const GstTagList *tags; GstCaps *caps; g_return_val_if_fail (info != NULL, NULL); s = g_string_sized_new (len); my_g_string_append_printf (s, "Codec:\n"); caps = gst_discoverer_stream_info_get_caps (info); tmp = gst_caps_to_string (caps); gst_caps_unref (caps); my_g_string_append_printf (s, " %s\n", tmp); g_free (tmp); my_g_string_append_printf (s, "Additional info:\n"); misc = gst_discoverer_stream_info_get_misc (info); if (misc) { tmp = gst_structure_to_string (misc); my_g_string_append_printf (s, " %s\n", tmp); g_free (tmp); } else { my_g_string_append_printf (s, " None\n"); } video_info = (GstDiscovererVideoInfo *) info; my_g_string_append_printf (s, "Width: %u\n", gst_discoverer_video_info_get_width (video_info)); my_g_string_append_printf (s, "Height: %u\n", gst_discoverer_video_info_get_height (video_info)); my_g_string_append_printf (s, "Depth: %u\n", gst_discoverer_video_info_get_depth (video_info)); my_g_string_append_printf (s, "Frame rate: %u/%u\n", gst_discoverer_video_info_get_framerate_num (video_info), gst_discoverer_video_info_get_framerate_denom (video_info)); my_g_string_append_printf (s, "Pixel aspect ratio: %u/%u\n", gst_discoverer_video_info_get_par_num (video_info), gst_discoverer_video_info_get_par_denom (video_info)); my_g_string_append_printf (s, "Interlaced: %s\n", gst_discoverer_video_info_is_interlaced (video_info) ? "true" : "false"); my_g_string_append_printf (s, "Bitrate: %u\n", gst_discoverer_video_info_get_bitrate (video_info)); my_g_string_append_printf (s, "Max bitrate: %u\n", gst_discoverer_video_info_get_max_bitrate (video_info)); my_g_string_append_printf (s, "Tags:\n"); tags = gst_discoverer_stream_info_get_tags (info); if (tags) { tmp = gst_structure_to_string ((GstStructure *) tags); my_g_string_append_printf (s, " %s\n", tmp); g_free (tmp); } else { my_g_string_append_printf (s, " None\n"); } if (verbose) my_g_string_append_printf (s, "\n"); return g_string_free (s, FALSE); }
/** * FIXME: remove GOTO */ void MediaImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, MediaImpl::GstPadHandlerData* data) { g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (newPad), GST_ELEMENT_NAME (src)); GstPad *sinkPad = NULL; // Check the new pad's type. GstCaps *newPadCaps = gst_pad_query_caps (newPad, NULL); GstStructure *newPadStruct = gst_caps_get_structure (newPadCaps, 0); const gchar *newPadType = gst_structure_get_name (newPadStruct); gchar *newPadStructStr = gst_structure_to_string(newPadStruct); g_print("Structure is %s\n", newPadStructStr); g_free(newPadStructStr); if (g_str_has_prefix (newPadType, "video/x-raw")) { sinkPad = gst_element_get_static_pad (data->videoToConnect, "sink"); gst_structure_get_int(newPadStruct, "width", &data->width); gst_structure_get_int(newPadStruct, "height", &data->height); } else if (g_str_has_prefix (newPadType, "audio/x-raw")) { sinkPad = gst_element_get_static_pad (data->audioToConnect, "sink"); } else { g_print (" It has type '%s' which is not raw audio/video. Ignoring.\n", newPadType); goto exit; } // If our converter is already linked, we have nothing to do here. if (gst_pad_is_linked (sinkPad)) { // Best prefixes. if (g_str_has_prefix (newPadType, "audio/x-raw-float") || g_str_has_prefix (newPadType, "video/x-raw-int") ) { g_print (" Found a better pad.\n"); GstPad* oldPad = gst_pad_get_peer(sinkPad); gst_pad_unlink(oldPad, sinkPad); g_object_unref(oldPad); } else { g_print (" We are already linked. Ignoring.\n"); goto exit; } } // Attempt the link if (GST_PAD_LINK_FAILED (gst_pad_link (newPad, sinkPad))) { g_print (" Type is '%s' but link failed.\n", newPadType); goto exit; } else { data->videoIsConnected = true; g_print (" Link succeeded (type '%s').\n", newPadType); } exit: // Unreference the new pad's caps, if we got them. if (newPadCaps != NULL) { gst_caps_unref (newPadCaps); } // Unreference the sink pad. if (sinkPad != NULL) { gst_object_unref (sinkPad); } }