hlsdemux: Extract ID3 tags, strip them from the output and provide them as tags

They often don't only contain the PCR information but also other
metadata, like title. Give this information to the pipeline.

Also strip the tags from the stream as we a) already parsed them now and
b) decoders don't like these tags to happen in the middle of the stream
(i.e. the start of each fragment) and tagdemux only can strip them off
the beginning and end.
This commit is contained in:
Sebastian Dröge 2016-12-19 11:40:28 +02:00
parent b5791efcc0
commit ee647ca4be
3 changed files with 28 additions and 11 deletions

View file

@ -265,13 +265,15 @@ gst_hlsdemux_tsreader_find_pcrs_mpegts (GstHLSTSReader * r,
static gboolean static gboolean
gst_hlsdemux_tsreader_find_pcrs_id3 (GstHLSTSReader * r, gst_hlsdemux_tsreader_find_pcrs_id3 (GstHLSTSReader * r,
GstBuffer * buffer, GstClockTime * first_pcr, GstClockTime * last_pcr) GstBuffer ** buffer_out, GstClockTime * first_pcr, GstClockTime * last_pcr,
GstTagList ** tags)
{ {
GstMapInfo info; GstMapInfo info;
guint32 tag_size; guint32 tag_size;
gsize size; gsize size;
GstTagList *taglist; GstTagList *taglist;
GstSample *priv_data = NULL; GstSample *priv_data = NULL;
GstBuffer *buffer = *buffer_out;
GstBuffer *tag_buf; GstBuffer *tag_buf;
guint64 pts; guint64 pts;
@ -297,10 +299,17 @@ gst_hlsdemux_tsreader_find_pcrs_id3 (GstHLSTSReader * r,
* not try and read again */ * not try and read again */
r->have_id3 = TRUE; r->have_id3 = TRUE;
*buffer_out =
gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, tag_size, -1);
/* Parse the tag */ /* Parse the tag */
taglist = gst_tag_list_from_id3v2_tag (buffer); taglist = gst_tag_list_from_id3v2_tag (buffer);
if (taglist == NULL) if (taglist == NULL) {
gst_buffer_unref (buffer);
return TRUE; /* Invalid tag, stop trying */ return TRUE; /* Invalid tag, stop trying */
}
*tags = taglist;
/* Extract the timestamps */ /* Extract the timestamps */
if (!gst_tag_list_get_sample (taglist, GST_TAG_PRIVATE_DATA, &priv_data)) if (!gst_tag_list_get_sample (taglist, GST_TAG_PRIVATE_DATA, &priv_data))
@ -330,19 +339,22 @@ gst_hlsdemux_tsreader_find_pcrs_id3 (GstHLSTSReader * r,
out: out:
if (priv_data) if (priv_data)
gst_sample_unref (priv_data); gst_sample_unref (priv_data);
gst_buffer_unref (buffer);
gst_tag_list_unref (taglist);
return TRUE; return TRUE;
} }
gboolean gboolean
gst_hlsdemux_tsreader_find_pcrs (GstHLSTSReader * r, gst_hlsdemux_tsreader_find_pcrs (GstHLSTSReader * r,
GstBuffer * buffer, GstClockTime * first_pcr, GstClockTime * last_pcr) GstBuffer ** buffer, GstClockTime * first_pcr, GstClockTime * last_pcr,
GstTagList ** tags)
{ {
*tags = NULL;
if (r->rtype == GST_HLS_TSREADER_MPEGTS) if (r->rtype == GST_HLS_TSREADER_MPEGTS)
return gst_hlsdemux_tsreader_find_pcrs_mpegts (r, buffer, first_pcr, return gst_hlsdemux_tsreader_find_pcrs_mpegts (r, *buffer, first_pcr,
last_pcr); last_pcr);
return gst_hlsdemux_tsreader_find_pcrs_id3 (r, buffer, first_pcr, last_pcr); return gst_hlsdemux_tsreader_find_pcrs_id3 (r, buffer, first_pcr, last_pcr,
tags);
} }

View file

@ -767,6 +767,7 @@ gst_hls_demux_handle_buffer (GstAdaptiveDemux * demux,
GstHLSDemux *hlsdemux = GST_HLS_DEMUX_CAST (demux); GstHLSDemux *hlsdemux = GST_HLS_DEMUX_CAST (demux);
GstMapInfo info; GstMapInfo info;
GstClockTime first_pcr, last_pcr; GstClockTime first_pcr, last_pcr;
GstTagList *tags;
if (buffer == NULL) if (buffer == NULL)
return GST_FLOW_OK; return GST_FLOW_OK;
@ -832,14 +833,18 @@ gst_hls_demux_handle_buffer (GstAdaptiveDemux * demux,
hls_stream->pending_pcr_buffer = NULL; hls_stream->pending_pcr_buffer = NULL;
} }
if (!gst_hlsdemux_tsreader_find_pcrs (&hls_stream->tsreader, buffer, if (!gst_hlsdemux_tsreader_find_pcrs (&hls_stream->tsreader, &buffer,
&first_pcr, &last_pcr) &first_pcr, &last_pcr, &tags)
&& !at_eos) { && !at_eos) {
// Store this buffer for later // Store this buffer for later
hls_stream->pending_pcr_buffer = buffer; hls_stream->pending_pcr_buffer = buffer;
return GST_FLOW_OK; return GST_FLOW_OK;
} }
if (tags) {
gst_adaptive_demux_stream_set_tags (stream, tags);
}
if (buffer) { if (buffer) {
buffer = gst_buffer_make_writable (buffer); buffer = gst_buffer_make_writable (buffer);
GST_BUFFER_OFFSET (buffer) = hls_stream->current_offset; GST_BUFFER_OFFSET (buffer) = hls_stream->current_offset;

View file

@ -154,8 +154,8 @@ struct _GstHLSDemuxClass
void gst_hlsdemux_tsreader_init (GstHLSTSReader *r); void gst_hlsdemux_tsreader_init (GstHLSTSReader *r);
void gst_hlsdemux_tsreader_set_type (GstHLSTSReader *r, GstHLSTSReaderType rtype); void gst_hlsdemux_tsreader_set_type (GstHLSTSReader *r, GstHLSTSReaderType rtype);
gboolean gst_hlsdemux_tsreader_find_pcrs (GstHLSTSReader *r, GstBuffer *buffer, gboolean gst_hlsdemux_tsreader_find_pcrs (GstHLSTSReader *r, GstBuffer **buffer,
GstClockTime *first_pcr, GstClockTime *last_pcr); GstClockTime *first_pcr, GstClockTime *last_pcr, GstTagList **tags);
GType gst_hls_demux_get_type (void); GType gst_hls_demux_get_type (void);