From c47c6b4c2b173d19522d3ed93c3f31c9b61fc185 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 27 Aug 2021 21:58:25 +1000 Subject: [PATCH] isomp4: Use a function pointer for buffer splitting. Swap the `need_process` boolean check on qtdemux streams for a direct function pointer to the splitting function, so we can stop adding extra cases to the single growing `gst_qtdemux_process_buffer()` function. Part-of: --- subprojects/gst-plugins-good/gst/isomp4/qtdemux.c | 14 +++++++------- subprojects/gst-plugins-good/gst/isomp4/qtdemux.h | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c index a1a2b91..299553b 100644 --- a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c +++ b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c @@ -1849,7 +1849,7 @@ _create_stream (GstQTDemux * demux, guint32 track_id) stream->discont = TRUE; /* we enable clipping for raw audio/video streams */ stream->need_clip = FALSE; - stream->need_process = FALSE; + stream->process_func = NULL; stream->segment_index = -1; stream->time_position = 0; stream->sample_index = -1; @@ -6044,8 +6044,8 @@ gst_qtdemux_decorate_and_push_buffer (GstQTDemux * qtdemux, /* we're going to modify the metadata */ buf = gst_buffer_make_writable (buf); - if (G_UNLIKELY (stream->need_process)) - buf = gst_qtdemux_process_buffer (qtdemux, stream, buf); + if (G_UNLIKELY (stream->process_func)) + buf = stream->process_func (qtdemux, stream, buf); if (!buf) { goto exit; @@ -14947,7 +14947,7 @@ qtdemux_sub_caps (GstQTDemux * qtdemux, QtDemuxStream * stream, case FOURCC_mp4s: _codec ("DVD subtitle"); caps = gst_caps_new_empty_simple ("subpicture/x-dvd"); - stream->need_process = TRUE; + stream->process_func = gst_qtdemux_process_buffer; break; case FOURCC_text: _codec ("Quicktime timed text"); @@ -14958,7 +14958,7 @@ qtdemux_sub_caps (GstQTDemux * qtdemux, QtDemuxStream * stream, caps = gst_caps_new_simple ("text/x-raw", "format", G_TYPE_STRING, "utf8", NULL); /* actual text piece needs to be extracted */ - stream->need_process = TRUE; + stream->process_func = gst_qtdemux_process_buffer; break; case FOURCC_stpp: _codec ("XML subtitles"); @@ -14969,7 +14969,7 @@ qtdemux_sub_caps (GstQTDemux * qtdemux, QtDemuxStream * stream, caps = gst_caps_new_simple ("closedcaption/x-cea-608", "format", G_TYPE_STRING, "s334-1a", NULL); - stream->need_process = TRUE; + stream->process_func = gst_qtdemux_process_buffer; stream->need_split = TRUE; break; case FOURCC_c708: @@ -14977,7 +14977,7 @@ qtdemux_sub_caps (GstQTDemux * qtdemux, QtDemuxStream * stream, caps = gst_caps_new_simple ("closedcaption/x-cea-708", "format", G_TYPE_STRING, "cdp", NULL); - stream->need_process = TRUE; + stream->process_func = gst_qtdemux_process_buffer; break; default: diff --git a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.h b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.h index 81fb9d2..742915c 100644 --- a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.h +++ b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.h @@ -55,6 +55,8 @@ typedef struct _QtDemuxSegment QtDemuxSegment; typedef struct _QtDemuxRandomAccessEntry QtDemuxRandomAccessEntry; typedef struct _QtDemuxStreamStsdEntry QtDemuxStreamStsdEntry; +typedef GstBuffer * (*QtDemuxProcessFunc)(GstQTDemux * qtdemux, QtDemuxStream * stream, GstBuffer * buf); + enum QtDemuxState { QTDEMUX_STATE_INITIAL, /* Initial state (haven't got the header yet) */ @@ -391,8 +393,10 @@ struct _QtDemuxStream * data */ gboolean need_clip; - /* buffer needs some custom processing, e.g. subtitles */ - gboolean need_process; + /* If the buffer needs some custom processing, e.g. subtitles, pass them + * through this function */ + QtDemuxProcessFunc process_func; + /* buffer needs potentially be split, e.g. CEA608 subtitles */ gboolean need_split; -- 2.7.4