Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion src/gst-plugins/gst-nvdynamicsrcbin/gstnvdsdynamicsrcbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstnvdsmeta.h"

/* Custom metadata type for source identification */
Expand Down Expand Up @@ -203,6 +204,11 @@ static GstPadProbeReturn srcbin_src_pad_probe_callback(GstPad *pad, GstPadProbeI
if (GST_PAD_PROBE_INFO_TYPE(info) & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) {
GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
if (GST_EVENT_TYPE(event) == GST_EVENT_CUSTOM_DOWNSTREAM) {
/* The still-frame event only drains the decoder at the end of a
* file; it is internal to the bin and not forwarded downstream */
if (gst_video_event_parse_still_frame(event, NULL)) {
return GST_PAD_PROBE_DROP;
}
const GstStructure *structure = gst_event_get_structure(event);
if(structure && gst_structure_has_name(structure, "custom-stream-start-event")) {
// Get source_id from the custom event
Expand Down Expand Up @@ -337,6 +343,30 @@ static void parsebin_pad_added_handler(GstElement *src, GstPad *new_pad, gpointe

gint stream_start_count = 0;

/* Name of the event that marks the end of a file inside the bin */
#define FILE_END_EVENT_NAME "nvdsdynamicsrcbin-file-end"

/* Turn the EOS of a file into a FILE_END_EVENT_NAME event before queue_parsebin
*
* queue_parsebin stays in the bin for all files. If it received the EOS, its
* task would pause with EOS once it has pushed the EOS. The next file can be
* linked while that push is still running (the events pushed for the end of
* the file wait for the elements downstream, e.g. nvinfer); its stream-start
* then clears the EOS state before the task pauses, nothing restarts the task
* afterwards and every buffer of the next file gets EOS, so playback stops
* with no error. A custom serialized event keeps its place in the data flow
* without putting the queue in EOS.
*/
static GstPadProbeReturn queue_parsebin_sink_eos_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) {
GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
if (GST_EVENT_TYPE(event) == GST_EVENT_EOS) {
GST_PAD_PROBE_INFO_DATA(info) = gst_event_new_custom(
GST_EVENT_CUSTOM_DOWNSTREAM, gst_structure_new_empty(FILE_END_EVENT_NAME));
gst_event_unref(event);
}
return GST_PAD_PROBE_OK;
}

/* Custom event generator probe
* Generates and injects custom events for stream start and EOS handling
*/
Expand Down Expand Up @@ -373,7 +403,8 @@ static GstPadProbeReturn custom_event_generator_probe(GstPad *pad, GstPadProbeIn
}
return GST_PAD_PROBE_OK;
}
else if (GST_EVENT_TYPE(event) == GST_EVENT_EOS) {
else if (GST_EVENT_TYPE(event) == GST_EVENT_CUSTOM_DOWNSTREAM &&
gst_event_has_name(event, FILE_END_EVENT_NAME)) {
gint current_source_id = -1;

g_mutex_lock(&srcbin->source_id_list_lock);
Expand All @@ -387,6 +418,13 @@ static GstPadProbeReturn custom_event_generator_probe(GstPad *pad, GstPadProbeIn
}
g_mutex_unlock(&srcbin->source_id_list_lock);

/* The decoder still holds the last frames of the file. A still-frame
* event makes it drain them without going EOS, so that the
* custom-eos-event below follows the file's last frame. */
if (!gst_pad_push_event(pad, gst_video_event_new_still_frame(TRUE))) {
GST_WARNING_OBJECT(srcbin, "Failed to push still-frame event");
}

// Create the custom event
GstEvent *custom_event = gst_event_new_custom(
GST_EVENT_CUSTOM_DOWNSTREAM,
Expand Down Expand Up @@ -518,6 +556,23 @@ static void dynamic_src_bin_terminate(DynamicSrcBin *srcbin) {
}
}

/* Keep RECONFIGURE events from parsebin away from filesrc ! queue
*
* Upstream of parsebin is an unparsed byte stream, so there is nothing to
* renegotiate there. parsebin links its internal elements and its src pad
* while filesrc is still reading the file, and each link sends a RECONFIGURE
* upstream. If one arrives right after filesrc pushed the file's last buffer,
* filesrc renegotiates and its serialized ALLOCATION query is queued behind
* that buffer; the queue drops the query when the demuxer returns EOS for the
* buffer, filesrc never returns and the file's EOS is never produced.
*/
static GstPadProbeReturn parsebin_sink_reconfigure_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) {
if (GST_EVENT_TYPE(GST_PAD_PROBE_INFO_EVENT(info)) == GST_EVENT_RECONFIGURE) {
return GST_PAD_PROBE_DROP;
}
return GST_PAD_PROBE_OK;
}

static void srcbin_child_added(GstChildProxy *child_proxy, GObject *object,
gchar *name, gpointer user_data) {
DynamicSrcBin *srcbin = DYNAMIC_SRC_BIN(user_data);
Expand All @@ -529,6 +584,16 @@ static void srcbin_child_added(GstChildProxy *child_proxy, GObject *object,
// Update the callback name here
g_signal_connect(srcbin->parsebin, "pad-added",
G_CALLBACK(parsebin_pad_added_handler), srcbin);

GstPad *parsebin_sink_pad = gst_element_get_static_pad(srcbin->parsebin, "sink");
if (parsebin_sink_pad) {
gst_pad_add_probe(parsebin_sink_pad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
parsebin_sink_reconfigure_probe, srcbin, NULL);
gst_object_unref(parsebin_sink_pad);
}
else {
GST_ERROR_OBJECT(srcbin, "Failed to get parsebin's sink pad");
}
}
}

Expand Down Expand Up @@ -687,6 +752,20 @@ static void dynamic_src_bin_init(DynamicSrcBin *srcbin) {
gst_object_unref(ghost_pad);
gst_object_unref(decoder_src_pad);

// Add probe to queue_parsebin's sink pad
GstPad *queue_parsebin_sink_pad = gst_element_get_static_pad(srcbin->queue_parsebin, "sink");
if (queue_parsebin_sink_pad) {
gst_pad_add_probe(queue_parsebin_sink_pad,
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
queue_parsebin_sink_eos_probe,
srcbin,
NULL);
gst_object_unref(queue_parsebin_sink_pad);
}
else {
GST_ERROR_OBJECT(srcbin, "Failed to get queue_parsebin's sink pad");
}

// Add probe to queue_parsebin's src pad
GstPad *queue_parsebin_src_pad = gst_element_get_static_pad(srcbin->queue_parsebin, "src");
if (queue_parsebin_src_pad) {
Expand Down