c++ - Gstreamer appsrc: odd behaviour of need-data callback -
i'm implementing gstreamer media player own source of data using appsrc
. works fine except 1 thing:
when stream reaches it's end, callback emits "end-of-stream"
signal. signals sending fucntion
g_signal_emit_by_name(appsrc, "end-of-stream", &ret)
returns gstflowreturn
value gst_flow_ok
. calls need-data
callback again, returns "end-of-stream"
signal again. , time gstflowreturn
value (-3)
gst_flow unexpected
. assume not expect "end-of-stream"
signal when recieved one, why requests more data than? maybe because didn't set size
value iof steam?
gstreamer version 0.10.
callback function code (appsrc
type seekable btw):
static void cb_need_data (gstelement *appsrc, guint size, gpointer user_data) { gstbuffer *buffer; gstflowreturn ret; appsrcdata* data = static_cast<appsrcdata*>(user_data); buffer = gst_buffer_new_and_alloc(size); int read = fread(gst_buffer_data(buffer), 1, size, data->file); gst_buffer_size(buffer) = read; g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret); if (ret != gst_flow_ok) { /* wrong, stop pushing */ g_printerr("gst_flow != ok, return value %d\n", ret); g_main_loop_quit (data->loop); } if(feof(data->file) || read == 0) { g_signal_emit_by_name(appsrc, "end-of-stream", &ret); if (ret != gst_flow_ok) { g_printerr("eof reached, gst_flow != ok, return value %d\naborting...", ret); g_main_loop_quit (data->loop); } } }
you should provide corrections code(if not there already) should alleviate issue , overall application:
- never try , send buffer without first checking if has data. so, check buffer data , length make sure data not null , length >0
- you can flag stream ended in user_data. when send eos, set item in userdata indicate has been sent , if appsrc requests more data, check if has been sent , not send else buffer.
- listen eos on pipeline bus can destroy stream , close loop when eos message handled can sure mediasink has received eos , can safely dispose of pipeline , loop without losing data.
Comments
Post a Comment