matroskamux: additional buffer handling cleanup

This commit is contained in:
Mark Nauwelaerts 2011-12-15 21:50:42 +01:00
parent 7723d64a73
commit 0845a3718a
2 changed files with 40 additions and 52 deletions

View file

@ -575,12 +575,6 @@ gst_matroska_pad_reset (GstMatroskaPad * collect_pad, gboolean full)
collect_pad->track = NULL; collect_pad->track = NULL;
} }
/* free cached buffer */
if (collect_pad->buffer != NULL) {
gst_buffer_unref (collect_pad->buffer);
collect_pad->buffer = NULL;
}
if (!full && type != 0) { if (!full && type != 0) {
GstMatroskaTrackContext *context; GstMatroskaTrackContext *context;
@ -608,7 +602,6 @@ gst_matroska_pad_reset (GstMatroskaPad * collect_pad, gboolean full)
/* TODO: check default values for the context */ /* TODO: check default values for the context */
context->flags = GST_MATROSKA_TRACK_ENABLED | GST_MATROSKA_TRACK_DEFAULT; context->flags = GST_MATROSKA_TRACK_ENABLED | GST_MATROSKA_TRACK_DEFAULT;
collect_pad->track = context; collect_pad->track = context;
collect_pad->buffer = NULL;
collect_pad->duration = 0; collect_pad->duration = 0;
collect_pad->start_ts = GST_CLOCK_TIME_NONE; collect_pad->start_ts = GST_CLOCK_TIME_NONE;
collect_pad->end_ts = GST_CLOCK_TIME_NONE; collect_pad->end_ts = GST_CLOCK_TIME_NONE;
@ -2689,10 +2682,11 @@ gst_matroska_mux_stop_streamheader (GstMatroskaMux * mux)
* Returns: Result of the gst_pad_push issued to write the data. * Returns: Result of the gst_pad_push issued to write the data.
*/ */
static GstFlowReturn static GstFlowReturn
gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad) gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad,
GstBuffer * buf)
{ {
GstEbmlWrite *ebml = mux->ebml_write; GstEbmlWrite *ebml = mux->ebml_write;
GstBuffer *buf, *hdr; GstBuffer *hdr;
guint64 blockgroup; guint64 blockgroup;
gboolean write_duration; gboolean write_duration;
gint16 relative_timestamp; gint16 relative_timestamp;
@ -2702,8 +2696,6 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad)
GstMatroskamuxPad *pad; GstMatroskamuxPad *pad;
/* write data */ /* write data */
buf = collect_pad->buffer;
collect_pad->buffer = NULL;
pad = GST_MATROSKAMUX_PAD_CAST (collect_pad->collect.pad); pad = GST_MATROSKAMUX_PAD_CAST (collect_pad->collect.pad);
/* vorbis/theora headers are retrieved from caps and put in CodecPrivate */ /* vorbis/theora headers are retrieved from caps and put in CodecPrivate */
@ -2908,7 +2900,6 @@ gst_matroska_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
GstMatroskaMux *mux = GST_MATROSKA_MUX (user_data); GstMatroskaMux *mux = GST_MATROSKA_MUX (user_data);
GstEbmlWrite *ebml = mux->ebml_write; GstEbmlWrite *ebml = mux->ebml_write;
GstMatroskaPad *best; GstMatroskaPad *best;
gboolean popped;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GST_DEBUG_OBJECT (mux, "Collected pads"); GST_DEBUG_OBJECT (mux, "Collected pads");
@ -2927,7 +2918,6 @@ gst_matroska_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
mux->state = GST_MATROSKA_MUX_STATE_DATA; mux->state = GST_MATROSKA_MUX_STATE_DATA;
} }
do {
/* provided with stream to write from */ /* provided with stream to write from */
best = (GstMatroskaPad *) data; best = (GstMatroskaPad *) data;
@ -2941,25 +2931,25 @@ gst_matroska_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
} }
gst_pad_push_event (mux->srcpad, gst_event_new_eos ()); gst_pad_push_event (mux->srcpad, gst_event_new_eos ());
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_UNEXPECTED;
break; goto exit;
} }
best->buffer = buf; /* if we have a best stream, should also have a buffer */
popped = TRUE; g_assert (buf);
GST_DEBUG_OBJECT (best->collect.pad, "best pad - buffer ts %" GST_DEBUG_OBJECT (best->collect.pad, "best pad - buffer ts %"
GST_TIME_FORMAT " dur %" GST_TIME_FORMAT, GST_TIME_FORMAT " dur %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (best->buffer)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (best->buffer))); GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
/* make note of first and last encountered timestamps, so we can calculate /* make note of first and last encountered timestamps, so we can calculate
* the actual duration later when we send an updated header on eos */ * the actual duration later when we send an updated header on eos */
if (GST_BUFFER_TIMESTAMP_IS_VALID (best->buffer)) { if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
GstClockTime start_ts = GST_BUFFER_TIMESTAMP (best->buffer); GstClockTime start_ts = GST_BUFFER_TIMESTAMP (buf);
GstClockTime end_ts = start_ts; GstClockTime end_ts = start_ts;
if (GST_BUFFER_DURATION_IS_VALID (best->buffer)) if (GST_BUFFER_DURATION_IS_VALID (buf))
end_ts += GST_BUFFER_DURATION (best->buffer); end_ts += GST_BUFFER_DURATION (buf);
else if (best->track->default_duration) else if (best->track->default_duration)
end_ts += best->track->default_duration; end_ts += best->track->default_duration;
@ -2972,9 +2962,9 @@ gst_matroska_mux_handle_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
} }
/* write one buffer */ /* write one buffer */
ret = gst_matroska_mux_write_data (mux, best); ret = gst_matroska_mux_write_data (mux, best, buf);
} while (ret == GST_FLOW_OK && !popped);
exit:
return ret; return ret;
} }

View file

@ -59,8 +59,6 @@ typedef struct
GstCollectData2 collect; /* we extend the CollectData */ GstCollectData2 collect; /* we extend the CollectData */
GstMatroskaTrackContext *track; GstMatroskaTrackContext *track;
GstBuffer *buffer; /* the queued buffer for this pad */
guint64 duration; guint64 duration;
GstClockTime start_ts; GstClockTime start_ts;
GstClockTime end_ts; /* last timestamp + (if available) duration */ GstClockTime end_ts; /* last timestamp + (if available) duration */