static void player_gstreamer_stop (PlayerGstreamer* self, FsoDevicePlayingSound* sound) { FsoDevicePlayingSound* _tmp0_; guint32 _tmp1_; GstPipeline* _tmp2_; GstPipeline* pipeline; GeeHashMap* _tmp3_; FsoDevicePlayingSound* _tmp4_; const gchar* _tmp5_; GeeHashMap* _tmp6_; FsoDevicePlayingSound* _tmp7_; const gchar* _tmp8_; g_return_if_fail (self != NULL); g_return_if_fail (sound != NULL); _tmp0_ = sound; _tmp1_ = _tmp0_->data; _tmp2_ = _gst_object_ref0 (GST_IS_PIPELINE (_tmp1_) ? ((GstPipeline*) _tmp1_) : NULL); pipeline = _tmp2_; gst_element_set_state ((GstElement*) pipeline, GST_STATE_NULL); _tmp3_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds; _tmp4_ = sound; _tmp5_ = _tmp4_->name; gee_map_remove ((GeeMap*) _tmp3_, _tmp5_, NULL); _tmp6_ = self->priv->pipelines; _tmp7_ = sound; _tmp8_ = _tmp7_->name; gee_map_remove ((GeeMap*) _tmp6_, _tmp8_, NULL); _gst_object_unref0 (pipeline); }
static gboolean gst_validate_runner_should_monitor (GstValidateRunner * self, GstElement * element) { gint i; GstValidateMonitor *monitor; if (!GST_IS_PIPELINE (element)) { return FALSE; } if (self->priv->user_created) return FALSE; if (!self->priv->pipeline_names_strv) return TRUE; monitor = gst_validate_get_monitor (G_OBJECT (element)); if (monitor) { GST_ERROR_OBJECT (self, "Pipeline %" GST_PTR_FORMAT " is already" " monitored by %" GST_PTR_FORMAT " using runner: %" GST_PTR_FORMAT " NOT monitoring again.", element, monitor, gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (monitor))); } for (i = 0; self->priv->pipeline_names_strv[i]; i++) { if (g_pattern_match_simple (self->priv->pipeline_names_strv[i], GST_OBJECT_NAME (element))) return TRUE; } return FALSE; }
/** * gst_pipeline_get_pipeline_clock: * @pipeline: a [GstPipeline]() * * Gets the current clock used by _pipeline_. * * Unlike [gst_element_get_clock](), this function will always return a * clock, even if the pipeline is not in the PLAYING state. * * Returns: (transfer full): a [GstClock](), unref after usage. * Since: 1.6 */ GstClock * gst_pipeline_get_pipeline_clock (GstPipeline * pipeline) { g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL); return gst_pipeline_provide_clock_func (GST_ELEMENT_CAST (pipeline)); }
static void _check_message_received (GstBus * bus, GstMessage * message, gpointer user_data) { GMainLoop *main_loop = (GMainLoop *) user_data; GST_DEBUG_OBJECT (GST_MESSAGE_SRC (message), "%s: %" GST_PTR_FORMAT, GST_MESSAGE_TYPE_NAME (message), message); switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_STATE_CHANGED: if (GST_IS_PIPELINE (GST_MESSAGE_SRC (message))) { GstState oldstate, newstate, pending; gst_message_parse_state_changed (message, &oldstate, &newstate, &pending); switch (GST_STATE_TRANSITION (oldstate, newstate)) { case GST_STATE_CHANGE_PAUSED_TO_PLAYING: goto done; break; default: break; } } break; case GST_MESSAGE_ERROR: GST_WARNING_OBJECT (GST_MESSAGE_SRC (message), "error: %" GST_PTR_FORMAT, message); _check_run_main_loop_error = TRUE; goto done; case GST_MESSAGE_SEGMENT_DONE: case GST_MESSAGE_EOS: if (GST_IS_PIPELINE (GST_MESSAGE_SRC (message))) { GST_INFO_OBJECT (GST_MESSAGE_SRC (message), "%s: %" GST_PTR_FORMAT, GST_MESSAGE_TYPE_NAME (message), message); goto done; } break; default: GST_WARNING_OBJECT (GST_MESSAGE_SRC (message), "unexpected messges: %s", GST_MESSAGE_TYPE_NAME (message)); } return; done: if (g_main_loop_is_running (main_loop)) g_main_loop_quit (main_loop); }
static GstElement * setup_pipeline (const gchar * pipe_descr) { GstElement *pipeline; pipeline = gst_parse_launch (pipe_descr, NULL); g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL); return pipeline; }
static GstElement * setup_pipeline (const gchar * pipe_descr) { GstElement *pipeline; pipeline = gst_parse_launch (pipe_descr, NULL); fail_unless (GST_IS_PIPELINE (pipeline)); return pipeline; }
/** * gst_pipeline_set_auto_flush_bus: * @pipeline: a [GstPipeline]() * @auto_flush: whether or not to automatically flush the bus when * the pipeline goes from READY to NULL state * * Usually, when a pipeline goes from READY to NULL state, it automatically * flushes all pending messages on the bus, which is done for refcounting * purposes, to break circular references. * * This means that applications that update state using (async) bus messages * (e.g. do certain things when a pipeline goes from PAUSED to READY) might * not get to see messages when the pipeline is shut down, because they might * be flushed before they can be dispatched in the main thread. This behaviour * can be disabled using this function. * * It is important that all messages on the bus are handled when the * automatic flushing is disabled else memory leaks will be introduced. * * MT safe. */ void gst_pipeline_set_auto_flush_bus (GstPipeline * pipeline, gboolean auto_flush) { g_return_if_fail (GST_IS_PIPELINE (pipeline)); GST_OBJECT_LOCK (pipeline); pipeline->priv->auto_flush_bus = auto_flush; GST_OBJECT_UNLOCK (pipeline); }
/** * gst_pipeline_set_clock: (skip): * @pipeline: a [GstPipeline]() * @clock: (transfer none): the clock to set * * Set the clock for _pipeline_. The clock will be distributed * to all the elements managed by the pipeline. * * Returns: [TRUE]() if the clock could be set on the pipeline. [FALSE]() if * some element did not accept the clock. * * MT safe. */ gboolean gst_pipeline_set_clock (GstPipeline * pipeline, GstClock * clock) { g_return_val_if_fail (pipeline != NULL, FALSE); g_return_val_if_fail (GST_IS_PIPELINE (pipeline), FALSE); return GST_ELEMENT_CLASS (parent_class)->set_clock (GST_ELEMENT_CAST (pipeline), clock); }
/** * gst_pipeline_set_delay: * @pipeline: a [GstPipeline]() * @delay: the delay * * Set the expected delay needed for all elements to perform the * PAUSED to PLAYING state change. _delay_ will be added to the * base time of the elements so that they wait an additional _delay_ * amount of time before starting to process buffers and cannot be * [GST_CLOCK_TIME_NONE](). * * This option is used for tuning purposes and should normally not be * used. * * MT safe. */ void gst_pipeline_set_delay (GstPipeline * pipeline, GstClockTime delay) { g_return_if_fail (GST_IS_PIPELINE (pipeline)); g_return_if_fail (delay != GST_CLOCK_TIME_NONE); GST_OBJECT_LOCK (pipeline); pipeline->delay = delay; GST_OBJECT_UNLOCK (pipeline); }
GstClockTime gst_pipeline_get_latency (GstPipeline * pipeline) { GstClockTime latency; g_return_val_if_fail (GST_IS_PIPELINE (pipeline), GST_CLOCK_TIME_NONE); GST_OBJECT_LOCK (pipeline); latency = pipeline->priv->latency; GST_OBJECT_UNLOCK (pipeline); return latency; }
/** * gst_pipeline_get_delay: * @pipeline: a [GstPipeline]() * * Get the configured delay (see [gst_pipeline_set_delay]()). * * Returns: The configured delay. * * MT safe. */ GstClockTime gst_pipeline_get_delay (GstPipeline * pipeline) { GstClockTime res; g_return_val_if_fail (GST_IS_PIPELINE (pipeline), GST_CLOCK_TIME_NONE); GST_OBJECT_LOCK (pipeline); res = pipeline->delay; GST_OBJECT_UNLOCK (pipeline); return res; }
/** * gst_pipeline_get_auto_flush_bus: * @pipeline: a [GstPipeline]() * * Check if _pipeline_ will automatically flush messages when going to * the NULL state. * * Returns: whether the pipeline will automatically flush its bus when * going from READY to NULL state or not. * * MT safe. */ gboolean gst_pipeline_get_auto_flush_bus (GstPipeline * pipeline) { gboolean res; g_return_val_if_fail (GST_IS_PIPELINE (pipeline), FALSE); GST_OBJECT_LOCK (pipeline); res = pipeline->priv->auto_flush_bus; GST_OBJECT_UNLOCK (pipeline); return res; }
/** * gst_pipeline_set_latency: * @pipeline: a [GstPipeline]() * @latency: latency to configure * * Sets the latency that should be configured on the pipeline. Setting * GST_CLOCK_TIME_NONE will restore the default behaviour of using the minimum * latency from the LATENCY query. Setting this is usually not required and * the pipeline will figure out an appropriate latency automatically. * * Setting a too low latency, especially lower than the minimum latency from * the LATENCY query, will most likely cause the pipeline to fail. * * Since: 1.6 */ void gst_pipeline_set_latency (GstPipeline * pipeline, GstClockTime latency) { gboolean changed; g_return_if_fail (GST_IS_PIPELINE (pipeline)); GST_OBJECT_LOCK (pipeline); changed = (pipeline->priv->latency != latency); pipeline->priv->latency = latency; GST_OBJECT_UNLOCK (pipeline); if (changed) gst_bin_recalculate_latency (GST_BIN_CAST (pipeline)); }
/** * gst_pipeline_auto_clock: * @pipeline: a [GstPipeline]() * * Let _pipeline_ select a clock automatically. This is the default * behaviour. * * Use this function if you previous forced a fixed clock with * [gst_pipeline_use_clock]() and want to restore the default * pipeline clock selection algorithm. * * MT safe. */ void gst_pipeline_auto_clock (GstPipeline * pipeline) { GstClock **clock_p; g_return_if_fail (pipeline != NULL); g_return_if_fail (GST_IS_PIPELINE (pipeline)); GST_OBJECT_LOCK (pipeline); GST_OBJECT_FLAG_UNSET (pipeline, GST_PIPELINE_FLAG_FIXED_CLOCK); clock_p = &pipeline->fixed_clock; gst_object_replace ((GstObject **) clock_p, NULL); GST_OBJECT_UNLOCK (pipeline); GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline using automatic clock"); }
/** * gst_pipeline_use_clock: * @pipeline: a [GstPipeline]() * @clock: (transfer none) (allow-none): the clock to use * * Force _pipeline_ to use the given _clock_. The pipeline will * always use the given clock even if new clock providers are added * to this pipeline. * * If _clock_ is [NULL]() all clocking will be disabled which will make * the pipeline run as fast as possible. * * MT safe. */ void gst_pipeline_use_clock (GstPipeline * pipeline, GstClock * clock) { GstClock **clock_p; g_return_if_fail (GST_IS_PIPELINE (pipeline)); GST_OBJECT_LOCK (pipeline); GST_OBJECT_FLAG_SET (pipeline, GST_PIPELINE_FLAG_FIXED_CLOCK); clock_p = &pipeline->fixed_clock; gst_object_replace ((GstObject **) clock_p, (GstObject *) clock); GST_OBJECT_UNLOCK (pipeline); GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline using fixed clock %p (%s)", clock, (clock ? GST_OBJECT_NAME (clock) : "nil")); }
/** * gst_validate_monitor_factory_create: * @target: The #GstObject to create a #GstValidateMonitor for * @runner: The #GstValidateRunner to use for the new monitor * @parent: (nullable): The parent of the new monitor * * Create a new monitor for @target and starts monitoring it. * * Returns: (transfer full): The newly created #GstValidateMonitor */ GstValidateMonitor * gst_validate_monitor_factory_create (GstObject * target, GstValidateRunner * runner, GstValidateMonitor * parent) { GstValidateMonitor *monitor = NULL; g_return_val_if_fail (target != NULL, NULL); monitor = g_object_get_data ((GObject *) target, "validate-monitor"); if (monitor) { GST_INFO_OBJECT (target, "Is already monitored by %" GST_PTR_FORMAT, monitor); return g_object_ref (monitor); } if (GST_IS_PAD (target)) { monitor = GST_VALIDATE_MONITOR_CAST (gst_validate_pad_monitor_new (GST_PAD_CAST (target), runner, GST_VALIDATE_ELEMENT_MONITOR_CAST (parent))); } else if (GST_IS_PIPELINE (target)) { monitor = GST_VALIDATE_MONITOR_CAST (gst_validate_pipeline_monitor_new (GST_PIPELINE_CAST (target), runner, parent)); } else if (GST_IS_BIN (target)) { monitor = GST_VALIDATE_MONITOR_CAST (gst_validate_bin_monitor_new (GST_BIN_CAST (target), runner, parent)); } else if (GST_IS_ELEMENT (target)) { monitor = GST_VALIDATE_MONITOR_CAST (gst_validate_element_monitor_new (GST_ELEMENT_CAST (target), runner, parent)); } else { g_assert_not_reached (); } return monitor; }
gboolean shmdata_base_reader_start (shmdata_base_reader_t * reader, const char *socketPath) { if (NULL == reader) return FALSE; g_mutex_lock (&reader->mutex_); destroy_polling_g_source (reader); if (reader->install_sync_handler_) { g_debug ("installing a sync handler"); //looking for the bus, searching the top level GstElement *pipe = reader->bin_; while (pipe != NULL && !GST_IS_PIPELINE (pipe)) pipe = GST_ELEMENT_PARENT (pipe); if( GST_IS_PIPELINE (pipe)) { GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipe)); gst_bus_set_sync_handler (bus, shmdata_base_reader_message_handler, NULL); gst_object_unref (bus); } else { g_warning ("no top level pipeline found when starting, cannot install sync_handler"); g_mutex_unlock (&reader->mutex_); return FALSE; } } reader->socket_name_ = g_strdup (socketPath); //monitoring the shared memory file reader->shmfile_ = g_file_new_for_commandline_arg (reader->socket_name_); if (g_file_query_exists (reader->shmfile_, NULL)) { g_debug ("existing shmdata, attaching (%s)", reader->socket_name_); reader->initialized_ = TRUE; g_mutex_unlock (&reader->mutex_);//give hand to user reader->on_first_data_ (reader, reader->on_first_data_userData_); shmdata_base_reader_attach (reader); //attach is acquiring mutex g_mutex_lock (&reader->mutex_);//get hand back } else g_debug ("monitoring %s", reader->socket_name_); //#ifdef HAVE_OSX #if 1 //directory monitoring is not working on osx, use polling :( /* g_timeout_add (500, */ /* shmdata_base_reader_poll_shmdata_path, */ /* reader); */ //GSource *source; reader->polling_g_source_ = g_timeout_source_new (500); g_source_set_callback (reader->polling_g_source_, shmdata_base_reader_poll_shmdata_path, reader, NULL); g_source_attach (reader->polling_g_source_, reader->g_main_context_); g_source_unref (reader->polling_g_source_); #else //FIXME fix monitoring with custom gmaincontext... find how to use "g_main_context_push_thread_default"... if (reader->g_main_context_ != NULL) { g_debug ("shmdata_base_reader_start: set a custom maincontext"); g_main_context_push_thread_default (reader->g_main_context_); } GFile *dir = g_file_get_parent (reader->shmfile_); if (!g_file_supports_thread_contexts(dir)) g_debug ("does not support thread_context"); GError *error = NULL; reader->dirMonitor_ = g_file_monitor_directory (dir, G_FILE_MONITOR_NONE, NULL, &error); g_object_unref (dir); if (reader->dirMonitor_ == NULL) { g_warning ("monitor directory failled: %s", error->message); g_error_free (error); g_mutex_unlock (&reader->mutex_); return FALSE; } g_signal_connect (reader->dirMonitor_, "changed", G_CALLBACK (shmdata_base_reader_file_system_monitor_change), reader); if (reader->g_main_context_ != NULL) g_main_context_pop_thread_default (reader->g_main_context_); #endif g_debug ("shmdata reader started (%s)", reader->socket_name_); g_mutex_unlock (&reader->mutex_); return TRUE; }
static gboolean byzanz_encoder_gstreamer_run (ByzanzEncoder * encoder, GInputStream * input, GOutputStream * output, gboolean record_audio, GCancellable * cancellable, GError ** error) { ByzanzEncoderGStreamer *gstreamer = BYZANZ_ENCODER_GSTREAMER (encoder); ByzanzEncoderGStreamerClass *klass = BYZANZ_ENCODER_GSTREAMER_GET_CLASS (encoder); GstElement *sink; guint width, height; GstMessage *message; GstBus *bus; if (!byzanz_deserialize_header (input, &width, &height, cancellable, error)) return FALSE; gstreamer->surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); g_assert (klass->pipeline_string); if (record_audio) { if (klass->audio_pipeline_string == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("This format does not support recording audio.")); return FALSE; } gstreamer->pipeline = gst_parse_launch (klass->audio_pipeline_string, error); gstreamer->audiosrc = gst_bin_get_by_name (GST_BIN (gstreamer->pipeline), "audiosrc"); g_assert (gstreamer->audiosrc); } else { gstreamer->pipeline = gst_parse_launch (klass->pipeline_string, error); } if (gstreamer->pipeline == NULL) return FALSE; g_assert (GST_IS_PIPELINE (gstreamer->pipeline)); gstreamer->src = GST_APP_SRC (gst_bin_get_by_name (GST_BIN (gstreamer->pipeline), "src")); g_assert (GST_IS_APP_SRC (gstreamer->src)); sink = gst_bin_get_by_name (GST_BIN (gstreamer->pipeline), "sink"); g_assert (sink); g_object_set (sink, "stream", output, NULL); g_object_unref (sink); gstreamer->caps = gst_caps_new_simple ("video/x-raw", #if G_BYTE_ORDER == G_LITTLE_ENDIAN "format", G_TYPE_STRING, "BGRx", #elif G_BYTE_ORDER == G_BIG_ENDIAN "format", G_TYPE_STRING, "xRGB", #else #error "Please add the Cairo caps format here" #endif "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, 0, 1, NULL); g_assert (gst_caps_is_fixed (gstreamer->caps)); gst_app_src_set_caps (gstreamer->src, gstreamer->caps); gst_app_src_set_callbacks (gstreamer->src, &callbacks, gstreamer, NULL); gst_app_src_set_stream_type (gstreamer->src, GST_APP_STREAM_TYPE_STREAM); gst_app_src_set_max_bytes (gstreamer->src, 0); g_object_set (gstreamer->src, "format", GST_FORMAT_TIME, NULL); if (!gst_element_set_state (gstreamer->pipeline, GST_STATE_PLAYING)) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to start GStreamer pipeline")); return FALSE; } bus = gst_pipeline_get_bus (GST_PIPELINE (gstreamer->pipeline)); message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); g_object_unref (bus); gst_element_set_state (gstreamer->pipeline, GST_STATE_NULL); if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) { gst_message_parse_error (message, error, NULL); gst_message_unref (message); return FALSE; } gst_message_unref (message); return TRUE; }
void test_launch_lines2() { GstElement *cur; gint i; gboolean b; gchar *s = NULL; xmlfile = "test_launch_lines2"; std_log(LOG_FILENAME_LINE, "Test Started test_launch_lines2"); /** * checks: * - specifying an element works :) * - if only 1 element is requested, no bin is returned, but the element */ cur = setup_pipeline (PIPELINE1); fail_unless (G_OBJECT_TYPE (cur) == g_type_from_name ("GstFakeSrc"), "parse_launch did not produce a fakesrc"); gst_object_unref (cur); /** * checks: * - properties works * - string, int, boolean and enums can be properly set * - first test of escaping strings */ cur = setup_pipeline (PIPELINE2); g_object_get (G_OBJECT (cur), "name", &s, "num-buffers", &i, "silent", &b, NULL); fail_if (s == NULL, "name was NULL"); fail_unless (strcmp (s, "donald") == 0, "fakesrc name was not 'donald'"); fail_unless (i == 27, "num-buffers was not 27"); fail_unless (b == TRUE, "silent was not TRUE"); g_free (s); g_object_get (G_OBJECT (cur), "sizetype", &i, NULL); fail_unless (i == 3, "sizetype != 3"); g_object_get (G_OBJECT (cur), "data", &i, NULL); fail_unless (i == 2, "data != 2"); gst_object_unref (cur); /** * checks: * - specifying multiple elements without links works * - if multiple toplevel elements exist, a pipeline is returned */ cur = setup_pipeline (PIPELINE3); fail_unless (GST_BIN_NUMCHILDREN (cur) == 3, "Pipeline does not contain 3 children"); gst_object_unref (cur); /** * checks: * - test default link "!" * - test if specifying pads on links works */ cur = setup_pipeline (PIPELINE4); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - test if appending the links works, too * - check if the pipeline constructed works the same as the one before (how?) */ cur = setup_pipeline (PIPELINE5); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - test various types of bins * - test if linking across bins works * - test if escaping strings works */ cur = setup_pipeline (PIPELINE6); fail_unless (GST_IS_PIPELINE (cur), "Parse did not produce a pipeline"); g_object_get (G_OBJECT (cur), "name", &s, NULL); fail_if (s == NULL, "name was NULL"); fail_unless (strcmp (s, "john") == 0, "Name was not 'john'"); g_free (s); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - test request pads */ cur = setup_pipeline (PIPELINE7); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - multiple pads on 1 link */ cur = setup_pipeline (PIPELINE8); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - failed in grammar.y cvs version 1.17 */ cur = setup_pipeline (PIPELINE9); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - failed in grammar.y cvs version 1.17 */ cur = setup_pipeline (PIPELINE10); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - failed in grammar.y cvs version 1.18 */ cur = setup_pipeline (PIPELINE11); check_pipeline_runs (cur); gst_object_unref (cur); /** * checks: * - URI detection works */ cur = setup_pipeline (PIPELINE12); gst_object_unref (cur); /** * checks: * - URI sink detection works */ cur = setup_pipeline (PIPELINE13); gst_object_unref (cur); /* Checks handling of a assignment followed by error inside a bin. * This should warn, but ignore the error and carry on */ cur = setup_pipeline ("( filesrc blocksize=4 location=/dev/null @ )"); gst_object_unref (cur); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
bool GSCam::init_stream() { if(!gst_is_initialized()) { // Initialize gstreamer pipeline ROS_DEBUG_STREAM( "Initializing gstreamer..." ); gst_init(0,0); } ROS_DEBUG_STREAM( "Gstreamer Version: " << gst_version_string() ); GError *error = 0; // Assignment to zero is a gst requirement pipeline_ = gst_parse_launch(gsconfig_.c_str(), &error); if (pipeline_ == NULL) { ROS_FATAL_STREAM( error->message ); return false; } // Create RGB sink sink_ = gst_element_factory_make("appsink",NULL); GstCaps * caps = image_encoding_ == sensor_msgs::image_encodings::RGB8 ? gst_caps_new_simple("video/x-raw-rgb", NULL) : gst_caps_new_simple("video/x-raw-gray", NULL); gst_app_sink_set_caps(GST_APP_SINK(sink_), caps); gst_caps_unref(caps); // Set whether the sink should sync // Sometimes setting this to true can cause a large number of frames to be // dropped gst_base_sink_set_sync( GST_BASE_SINK(sink_), (sync_sink_) ? TRUE : FALSE); if(GST_IS_PIPELINE(pipeline_)) { GstPad *outpad = gst_bin_find_unlinked_pad(GST_BIN(pipeline_), GST_PAD_SRC); g_assert(outpad); GstElement *outelement = gst_pad_get_parent_element(outpad); g_assert(outelement); gst_object_unref(outpad); if(!gst_bin_add(GST_BIN(pipeline_), sink_)) { ROS_FATAL("gst_bin_add() failed"); gst_object_unref(outelement); gst_object_unref(pipeline_); return false; } if(!gst_element_link(outelement, sink_)) { ROS_FATAL("GStreamer: cannot link outelement(\"%s\") -> sink\n", gst_element_get_name(outelement)); gst_object_unref(outelement); gst_object_unref(pipeline_); return false; } gst_object_unref(outelement); } else { GstElement* launchpipe = pipeline_; pipeline_ = gst_pipeline_new(NULL); g_assert(pipeline_); gst_object_unparent(GST_OBJECT(launchpipe)); gst_bin_add_many(GST_BIN(pipeline_), launchpipe, sink_, NULL); if(!gst_element_link(launchpipe, sink_)) { ROS_FATAL("GStreamer: cannot link launchpipe -> sink"); gst_object_unref(pipeline_); return false; } } gst_element_set_state(pipeline_, GST_STATE_PAUSED); if (gst_element_get_state(pipeline_, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) { ROS_FATAL("Failed to PAUSE stream, check your gstreamer configuration."); return false; } else { ROS_DEBUG_STREAM("Stream is PAUSED."); } // Create ROS camera interface camera_pub_ = image_transport_.advertiseCamera("camera/image_raw", 1); return true; }
static void test_with_caps (GstElement * src, GstElement * videocrop, GstCaps * caps) { GstClockTime time_run; GstElement *pipeline; GTimer *timer; GstBus *bus; GstPad *pad; guint hcrop; guint vcrop; /* caps must be writable, we can't check that here though */ g_assert (GST_CAPS_REFCOUNT_VALUE (caps) == 1); timer = g_timer_new (); vcrop = 0; hcrop = 0; pipeline = GST_ELEMENT (gst_element_get_parent (videocrop)); g_assert (GST_IS_PIPELINE (pipeline)); /* at this point the pipeline is in PLAYING state; we only want to capture * errors resulting from our on-the-fly changing of the filtercaps */ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); /* pad to block */ pad = gst_element_get_static_pad (src, "src"); time_run = 0; do { GstClockTime wait_time, waited_for_block; if (check_bus_for_errors (bus, 0)) break; wait_time = GST_SECOND / FRAMERATE; GST_LOG ("hcrop = %3d, vcrop = %3d", vcrop, hcrop); g_timer_reset (timer); /* need to block the streaming thread while changing these properties, * otherwise we might get random not-negotiated errors (when caps are * changed in between upstream calling pad_alloc_buffer() and pushing * the processed buffer?) */ gst_pad_set_blocked (pad, TRUE); g_object_set (videocrop, "left", hcrop, "top", vcrop, NULL); gst_pad_set_blocked (pad, FALSE); waited_for_block = g_timer_elapsed (timer, NULL) * (double) GST_SECOND; /* GST_LOG ("waited: %" GST_TIME_FORMAT ", frame len: %" GST_TIME_FORMAT, GST_TIME_ARGS (waited_for_block), GST_TIME_ARGS (wait_time)); */ ++vcrop; ++hcrop; if (wait_time > waited_for_block) { g_usleep ((wait_time - waited_for_block) / GST_MSECOND); } time_run += wait_time; } while (time_run < (TIME_PER_TEST * GST_SECOND)); g_timer_destroy (timer); gst_object_unref (bus); gst_object_unref (pad); }
static gboolean player_gstreamer_onGstreamerMessage (PlayerGstreamer* self, GstBus* bus, GstMessage* message, FsoDevicePlayingSound* sound) { gboolean result = FALSE; Block1Data* _data1_; FsoDevicePlayingSound* _tmp0_; FsoDevicePlayingSound* _tmp1_; FsoFrameworkLogger* _tmp2_; GstMessage* _tmp3_; GstMessageType _tmp4_; const gchar* _tmp5_ = NULL; FsoDevicePlayingSound* _tmp6_; const gchar* _tmp7_; const gchar* _tmp8_ = NULL; gchar* _tmp9_ = NULL; gchar* _tmp10_; gboolean _tmp11_ = FALSE; FsoDevicePlayingSound* _tmp12_; guint32 _tmp13_; GstPipeline* _tmp14_; GstPipeline* pipeline; GstMessage* _tmp15_; GstMessageType _tmp16_; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (bus != NULL, FALSE); g_return_val_if_fail (message != NULL, FALSE); g_return_val_if_fail (sound != NULL, FALSE); _data1_ = g_slice_new0 (Block1Data); _data1_->_ref_count_ = 1; _data1_->self = g_object_ref (self); _tmp0_ = sound; _tmp1_ = _fso_device_playing_sound_ref0 (_tmp0_); _data1_->sound = _tmp1_; _tmp2_ = fso_framework_theLogger; _tmp3_ = message; _tmp4_ = _tmp3_->type; _tmp5_ = gst_message_type_get_name (_tmp4_); _tmp6_ = _data1_->sound; _tmp7_ = _tmp6_->name; _tmp8_ = string_to_string (_tmp7_); _tmp9_ = g_strconcat ("Gstreamer: ", _tmp5_, " for sound ", _tmp8_, NULL); _tmp10_ = _tmp9_; _tmp11_ = fso_framework_logger_debug (_tmp2_, _tmp10_); g_assert (_tmp11_); _g_free0 (_tmp10_); _tmp12_ = _data1_->sound; _tmp13_ = _tmp12_->data; _tmp14_ = _gst_object_ref0 (GST_IS_PIPELINE (_tmp13_) ? ((GstPipeline*) _tmp13_) : NULL); pipeline = _tmp14_; _tmp15_ = message; _tmp16_ = _tmp15_->type; switch (_tmp16_) { case GST_MESSAGE_EOS: { { FsoDevicePlayingSound* _tmp17_; gint _tmp18_; _tmp17_ = _data1_->sound; _tmp18_ = _tmp17_->loop; _tmp17_->loop = _tmp18_ - 1; if (_tmp18_ > 0) { GstPipeline* _tmp19_; _tmp19_ = pipeline; gst_element_seek_simple ((GstElement*) _tmp19_, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, (gint64) 0); } else { FsoDevicePlayingSound* _tmp20_; _tmp20_ = _data1_->sound; player_gstreamer_stop (self, _tmp20_); } break; } } case GST_MESSAGE_ERROR: { { GError* e = NULL; gchar* debug = NULL; GstMessage* _tmp21_; GError* _tmp22_ = NULL; gchar* _tmp23_ = NULL; FsoFrameworkLogger* _tmp24_; GError* _tmp25_; const gchar* _tmp26_; const gchar* _tmp27_ = NULL; const gchar* _tmp28_; const gchar* _tmp29_ = NULL; gchar* _tmp30_ = NULL; gchar* _tmp31_; _tmp21_ = message; gst_message_parse_error (_tmp21_, &_tmp22_, &_tmp23_); _g_error_free0 (e); e = _tmp22_; _g_free0 (debug); debug = _tmp23_; _tmp24_ = fso_framework_theLogger; _tmp25_ = e; _tmp26_ = _tmp25_->message; _tmp27_ = string_to_string (_tmp26_); _tmp28_ = debug; _tmp29_ = string_to_string (_tmp28_); _tmp30_ = g_strconcat ("Gstreamer: Error ", _tmp27_, ": ", _tmp29_, NULL); _tmp31_ = _tmp30_; fso_framework_logger_warning (_tmp24_, _tmp31_); _g_free0 (_tmp31_); _g_free0 (debug); _g_error_free0 (e); break; } } case GST_MESSAGE_STATE_CHANGED: { { GstState previous = 0; GstState current = 0; GstState pending = 0; GstMessage* _tmp32_; GstState _tmp33_ = 0; GstState _tmp34_ = 0; GstState _tmp35_ = 0; gboolean _tmp36_ = FALSE; gboolean _tmp37_ = FALSE; GstState _tmp38_; gboolean _tmp40_; gboolean _tmp42_; _tmp32_ = message; gst_message_parse_state_changed (_tmp32_, &_tmp33_, &_tmp34_, &_tmp35_); previous = _tmp33_; current = _tmp34_; pending = _tmp35_; _tmp38_ = previous; if (_tmp38_ == GST_STATE_READY) { GstState _tmp39_; _tmp39_ = current; _tmp37_ = _tmp39_ == GST_STATE_PAUSED; } else { _tmp37_ = FALSE; } _tmp40_ = _tmp37_; if (_tmp40_) { GstState _tmp41_; _tmp41_ = pending; _tmp36_ = _tmp41_ == GST_STATE_PLAYING; } else { _tmp36_ = FALSE; } _tmp42_ = _tmp36_; if (_tmp42_) { FsoDevicePlayingSound* _tmp43_; gint _tmp44_; _tmp43_ = _data1_->sound; _tmp44_ = _tmp43_->length; if (_tmp44_ > 0) { FsoDevicePlayingSound* _tmp45_; gint _tmp46_; _tmp45_ = _data1_->sound; _tmp46_ = _tmp45_->length; g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) _tmp46_, _______lambda2__gsource_func, block1_data_ref (_data1_), block1_data_unref); } } else { gboolean _tmp47_ = FALSE; gboolean _tmp48_ = FALSE; GstState _tmp49_; gboolean _tmp51_; gboolean _tmp53_; _tmp49_ = previous; if (_tmp49_ == GST_STATE_PLAYING) { GstState _tmp50_; _tmp50_ = current; _tmp48_ = _tmp50_ == GST_STATE_PAUSED; } else { _tmp48_ = FALSE; } _tmp51_ = _tmp48_; if (_tmp51_) { GstState _tmp52_; _tmp52_ = pending; _tmp47_ = _tmp52_ == GST_STATE_READY; } else { _tmp47_ = FALSE; } _tmp53_ = _tmp47_; if (_tmp53_) { FsoDevicePlayingSound* _tmp54_; _tmp54_ = _data1_->sound; player_gstreamer_stop (self, _tmp54_); } else { } } break; } } default: { { FsoFrameworkLogger* _tmp55_; GstMessage* _tmp56_; GstMessageType _tmp57_; const gchar* _tmp58_ = NULL; gchar* _tmp59_ = NULL; gchar* _tmp60_; _tmp55_ = fso_framework_theLogger; _tmp56_ = message; _tmp57_ = _tmp56_->type; _tmp58_ = gst_message_type_get_name (_tmp57_); _tmp59_ = g_strconcat ("Gstreamer: Unhandled message w/ type ", _tmp58_, NULL); _tmp60_ = _tmp59_; fso_framework_logger_warning (_tmp55_, _tmp60_); _g_free0 (_tmp60_); break; } } } result = TRUE; _gst_object_unref0 (pipeline); block1_data_unref (_data1_); _data1_ = NULL; return result; }
GstElement *mmsGstLaunch(const char *pipeline_description) { GError *error = NULL; gint res = 0; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (!g_thread_supported ()) g_thread_init (NULL); gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE); #ifndef DISABLE_FAULT_HANDLER fault_setup (); sigint_setup (); play_signal_setup (); #endif // parse the pipeline description pipeline = gst_parse_launch(pipeline_description, &error); if (!pipeline) { if (error) { fprintf (stderr, "ERROR: pipeline could not be constructed: %s.\n", GST_STR_NULL (error->message)); g_error_free (error); } else { fprintf (stderr, "ERROR: pipeline could not be constructed.\n"); } return NULL; } else if (error) { fprintf (stderr, "WARNING: erroneous pipeline: %s\n", GST_STR_NULL (error->message)); g_error_free (error); return NULL; } GstState state; GstStateChangeReturn ret; /* If the top-level object is not a pipeline, place it in a pipeline. */ if (!GST_IS_PIPELINE (pipeline)) { GstElement *real_pipeline = gst_element_factory_make ("pipeline", NULL); if (real_pipeline == NULL) { fprintf (stderr, "ERROR: the 'pipeline' element wasn't found.\n"); return NULL; } gst_bin_add (GST_BIN (real_pipeline), pipeline); pipeline = real_pipeline; } fprintf (stderr, "Setting pipeline to PAUSED ...\n"); ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); switch (ret) { case GST_STATE_CHANGE_FAILURE: fprintf (stderr, "ERROR: Pipeline doesn't want to pause.\n"); res = -1; event_loop (pipeline, FALSE, GST_STATE_VOID_PENDING); goto end; case GST_STATE_CHANGE_NO_PREROLL: fprintf (stderr, "Pipeline is live and does not need PREROLL ...\n"); is_live = TRUE; break; case GST_STATE_CHANGE_ASYNC: fprintf (stderr, "Pipeline is PREROLLING ...\n"); caught_error = event_loop (pipeline, TRUE, GST_STATE_PAUSED); if (caught_error) { fprintf (stderr, "ERROR: pipeline doesn't want to preroll.\n"); goto end; } state = GST_STATE_PAUSED; // fallthrough case GST_STATE_CHANGE_SUCCESS: fprintf (stderr, "Pipeline is PREROLLED ...\n"); break; } // pipe successfully created return pipeline; end: mmsGstFree(); return NULL; }
int main(int argc, char** argv) { char *config = getenv("GSCAM_CONFIG"); if (config == NULL) { std::cout << "Problem getting GSCAM_CONFIG variable." << std::endl; exit(-1); } gst_init(0,0); std::cout << "Gstreamer Version: " << gst_version_string() << std::endl; GError *error = 0; //assignment to zero is a gst requirement GstElement *pipeline = gst_parse_launch(config,&error); if (pipeline == NULL) { std::cout << error->message << std::endl; exit(-1); } GstElement * sink = gst_element_factory_make("appsink",NULL); GstCaps * caps = gst_caps_new_simple("video/x-raw-rgb", NULL); gst_app_sink_set_caps(GST_APP_SINK(sink), caps); gst_caps_unref(caps); gst_base_sink_set_sync(GST_BASE_SINK(sink), TRUE); if(GST_IS_PIPELINE(pipeline)) { GstPad *outpad = gst_bin_find_unlinked_pad(GST_BIN(pipeline), GST_PAD_SRC); g_assert(outpad); GstElement *outelement = gst_pad_get_parent_element(outpad); g_assert(outelement); gst_object_unref(outpad); if(!gst_bin_add(GST_BIN(pipeline), sink)) { fprintf(stderr, "gst_bin_add() failed\n"); // TODO: do some unref gst_object_unref(outelement); gst_object_unref(pipeline); return -1; } if(!gst_element_link(outelement, sink)) { fprintf(stderr, "GStreamer: cannot link outelement(\"%s\") -> sink\n", gst_element_get_name(outelement)); gst_object_unref(outelement); gst_object_unref(pipeline); return -1; } gst_object_unref(outelement); } else { GstElement* launchpipe = pipeline; pipeline = gst_pipeline_new(NULL); g_assert(pipeline); gst_object_unparent(GST_OBJECT(launchpipe)); gst_bin_add_many(GST_BIN(pipeline), launchpipe, sink, NULL); if(!gst_element_link(launchpipe, sink)) { fprintf(stderr, "GStreamer: cannot link launchpipe -> sink\n"); gst_object_unref(pipeline); return -1; } } gst_element_set_state(pipeline, GST_STATE_PAUSED); if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) { std::cout << "Failed to PAUSE." << std::endl; exit(-1); } else { std::cout << "stream is PAUSED." << std::endl; } // We could probably do something with the camera name, check // errors or something, but at the moment, we don't care. std::string camera_name; if (camera_calibration_parsers::readCalibrationIni("../camera_parameters.txt", camera_name, camera_info)) { ROS_INFO("Successfully read camera calibration. Rerun camera calibrator if it is incorrect."); } else { ROS_ERROR("No camera_parameters.txt file found. Use default file if no other is available."); } ros::init(argc, argv, "gscam_publisher"); ros::NodeHandle nh; int preroll; nh.param("brown/gscam/preroll", preroll, 0); if (preroll) { //The PAUSE, PLAY, PAUSE, PLAY cycle is to ensure proper pre-roll //I am told this is needed and am erring on the side of caution. gst_element_set_state(pipeline, GST_STATE_PLAYING); if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) { std::cout << "Failed to PLAY." << std::endl; exit(-1); } else { std::cout << "stream is PLAYING." << std::endl; } gst_element_set_state(pipeline, GST_STATE_PAUSED); if (gst_element_get_state(pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) { std::cout << "Failed to PAUSE." << std::endl; exit(-1); } else { std::cout << "stream is PAUSED." << std::endl; } } image_transport::ImageTransport it(nh); // image_transport::CameraPublisher pub = it.advertiseCamera("gscam/image_raw", 1); //------------------------------------ // Added by jschoi, 2012-08-13 char topic_name[32]; if(argc==1) sprintf(topic_name, "gscam/image_raw"); else sprintf(topic_name,"%s",argv[1]); // To get the name of topic from the first arguement //------------------------------------ image_transport::CameraPublisher pub = it.advertiseCamera(topic_name, 1); ros::ServiceServer set_camera_info = nh.advertiseService("gscam/set_camera_info", setCameraInfo); std::cout << "Processing..." << std::endl; //processVideo rosPad = false; gstreamerPad = true; gst_element_set_state(pipeline, GST_STATE_PLAYING); while(nh.ok()) { // This should block until a new frame is awake, this way, we'll run at the // actual capture framerate of the device. GstBuffer* buf = gst_app_sink_pull_buffer(GST_APP_SINK(sink)); if (!buf) break; GstPad* pad = gst_element_get_static_pad(sink, "sink"); const GstCaps *caps = gst_pad_get_negotiated_caps(pad); GstStructure *structure = gst_caps_get_structure(caps,0); gst_structure_get_int(structure,"width",&width); gst_structure_get_int(structure,"height",&height); sensor_msgs::Image msg; msg.width = width; msg.height = height; msg.encoding = "rgb8"; msg.is_bigendian = false; msg.step = width*3; msg.data.resize(width*height*3); std::copy(buf->data, buf->data+(width*height*3), msg.data.begin()); pub.publish(msg, camera_info); gst_buffer_unref(buf); ros::spinOnce(); } //close out std::cout << "\nquitting..." << std::endl; gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); return 0; }