From 4e7f94f5faf249a393de9cd50bccbc2f25293be5 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Fri, 26 Apr 2019 00:01:31 +0200 Subject: mpegtsmux: expose the vmethods necessary for ATSC E-AC-3 handling --- gst/mpegtsmux/tsmux/tsmux.c | 4 +-- gst/mpegtsmux/tsmux/tsmux.h | 4 +-- gst/mpegtsmux/tsmux/tsmuxstream.c | 51 ++++++++++++++++++++++++++++++++++++--- gst/mpegtsmux/tsmux/tsmuxstream.h | 14 +++++++++-- 4 files changed, 63 insertions(+), 10 deletions(-) (limited to 'gst/mpegtsmux/tsmux') diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c index aa2cc436e..a303e281e 100644 --- a/gst/mpegtsmux/tsmux/tsmux.c +++ b/gst/mpegtsmux/tsmux/tsmux.c @@ -561,7 +561,7 @@ tsmux_get_new_pid (TsMux * mux) /** * tsmux_create_stream: * @mux: a #TsMux - * @stream_type: a #TsMuxStreamType + * @stream_type: the stream type * @pid: the PID of the new stream. * * Create a new stream of @stream_type in the muxer session @mux. @@ -572,7 +572,7 @@ tsmux_get_new_pid (TsMux * mux) * Returns: a new #TsMuxStream. */ TsMuxStream * -tsmux_create_stream (TsMux * mux, TsMuxStreamType stream_type, guint16 pid, +tsmux_create_stream (TsMux * mux, guint stream_type, guint16 pid, gchar * language) { TsMuxStream *stream; diff --git a/gst/mpegtsmux/tsmux/tsmux.h b/gst/mpegtsmux/tsmux/tsmux.h index 42b877593..0f5713b4f 100644 --- a/gst/mpegtsmux/tsmux/tsmux.h +++ b/gst/mpegtsmux/tsmux/tsmux.h @@ -102,7 +102,7 @@ typedef struct TsMux TsMux; typedef gboolean (*TsMuxWriteFunc) (GstBuffer * buf, void *user_data, gint64 new_pcr); typedef void (*TsMuxAllocFunc) (GstBuffer ** buf, void *user_data); -typedef TsMuxStream * (*TsMuxNewStreamFunc) (guint16 new_pid, TsMuxStreamType stream_type, void *user_data); +typedef TsMuxStream * (*TsMuxNewStreamFunc) (guint16 new_pid, guint stream_type, void *user_data); struct TsMuxSection { TsMuxPacketInfo pi; @@ -215,7 +215,7 @@ void tsmux_resend_si (TsMux *mux); gboolean tsmux_add_mpegts_si_section (TsMux * mux, GstMpegtsSection * section); /* stream management */ -TsMuxStream * tsmux_create_stream (TsMux *mux, TsMuxStreamType stream_type, guint16 pid, gchar *language); +TsMuxStream * tsmux_create_stream (TsMux *mux, guint stream_type, guint16 pid, gchar *language); TsMuxStream * tsmux_find_stream (TsMux *mux, guint16 pid); void tsmux_program_add_stream (TsMuxProgram *program, TsMuxStream *stream); diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.c b/gst/mpegtsmux/tsmux/tsmuxstream.c index 7945fc0f9..12397717f 100644 --- a/gst/mpegtsmux/tsmux/tsmuxstream.c +++ b/gst/mpegtsmux/tsmux/tsmuxstream.c @@ -122,7 +122,7 @@ struct TsMuxStreamBuffer * Returns: a new #TsMuxStream. */ TsMuxStream * -tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type) +tsmux_stream_new (guint16 pid, guint stream_type) { TsMuxStream *stream = g_slice_new0 (TsMuxStream); @@ -220,7 +220,7 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type) stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER; break; default: - g_critical ("Stream type 0x%0x not yet implemented", stream_type); + /* Might be a custom stream type implemented by a subclass */ break; } @@ -232,6 +232,10 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type) stream->pcr_ref = 0; stream->next_pcr = -1; + stream->get_es_descrs = + (TsMuxStreamGetESDescriptorsFunc) tsmux_stream_default_get_es_descrs; + stream->get_es_descrs_data = NULL; + return stream; } @@ -295,6 +299,25 @@ tsmux_stream_set_buffer_release_func (TsMuxStream * stream, stream->buffer_release = func; } +/** + * tsmux_stream_set_get_es_descriptors_func: + * @stream: a #TsMuxStream + * @func: a user callback function + * @user_data: user data passed to @func + * + * Set the callback function and user data to be called when @stream has + * to create Elementary Stream Descriptors. + */ +void +tsmux_stream_set_get_es_descriptors_func (TsMuxStream * stream, + TsMuxStreamGetESDescriptorsFunc func, void *user_data) +{ + g_return_if_fail (stream != NULL); + + stream->get_es_descrs = func; + stream->get_es_descrs_data = user_data; +} + /* Advance the current packet stream position by len bytes. * Mustn't consume more than available in the current packet */ static void @@ -727,7 +750,7 @@ tsmux_stream_add_data (TsMuxStream * stream, guint8 * data, guint len, } /** - * tsmux_stream_get_es_descrs: + * tsmux_stream_default_get_es_descrs: * @stream: a #TsMuxStream * @buf: a buffer to hold the ES descriptor * @len: the length used in @buf @@ -738,7 +761,7 @@ tsmux_stream_add_data (TsMuxStream * stream, guint8 * data, guint len, * @buf and @len must be at least #TSMUX_MIN_ES_DESC_LEN. */ void -tsmux_stream_get_es_descrs (TsMuxStream * stream, +tsmux_stream_default_get_es_descrs (TsMuxStream * stream, GstMpegtsPMTStream * pmt_stream) { GstMpegtsDescriptor *descriptor; @@ -1039,6 +1062,26 @@ tsmux_stream_get_es_descrs (TsMuxStream * stream, } } +/** + * tsmux_stream_get_es_descrs: + * @stream: a #TsMuxStream + * @buf: a buffer to hold the ES descriptor + * @len: the length used in @buf + * + * Write an Elementary Stream Descriptor for @stream into @buf. the number of + * bytes consumed in @buf will be updated in @len. + * + * @buf and @len must be at least #TSMUX_MIN_ES_DESC_LEN. + */ +void +tsmux_stream_get_es_descrs (TsMuxStream * stream, + GstMpegtsPMTStream * pmt_stream) +{ + g_return_if_fail (stream->get_es_descrs != NULL); + + return stream->get_es_descrs (stream, pmt_stream, stream->get_es_descrs_data); +} + /** * tsmux_stream_pcr_ref: * @stream: a #TsMuxStream diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.h b/gst/mpegtsmux/tsmux/tsmuxstream.h index 3b160207e..4b60d1fed 100644 --- a/gst/mpegtsmux/tsmux/tsmuxstream.h +++ b/gst/mpegtsmux/tsmux/tsmuxstream.h @@ -91,6 +91,7 @@ typedef enum TsMuxStreamState TsMuxStreamState; typedef struct TsMuxStreamBuffer TsMuxStreamBuffer; typedef void (*TsMuxStreamBufferReleaseFunc) (guint8 *data, void *user_data); +typedef void (*TsMuxStreamGetESDescriptorsFunc) (TsMuxStream *stream, GstMpegtsPMTStream *pmt_stream, void *user_data); /* Stream type assignments * @@ -159,7 +160,7 @@ enum TsMuxStreamState { struct TsMuxStream { TsMuxStreamState state; TsMuxPacketInfo pi; - TsMuxStreamType stream_type; + guint stream_type; /* stream_id (13818-1) */ guint8 id; @@ -181,6 +182,10 @@ struct TsMuxStream { /* helper to release collected buffers */ TsMuxStreamBufferReleaseFunc buffer_release; + /* Override or extend the default Elementary Stream descriptors */ + TsMuxStreamGetESDescriptorsFunc get_es_descrs; + void *get_es_descrs_data; + /* optional fixed PES size for stream type */ guint16 pes_payload_size; /* current PES payload size being written */ @@ -232,7 +237,7 @@ struct TsMuxStream { }; /* stream management */ -TsMuxStream * tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type); +TsMuxStream * tsmux_stream_new (guint16 pid, guint stream_type); void tsmux_stream_free (TsMuxStream *stream); guint16 tsmux_stream_get_pid (TsMuxStream *stream); @@ -240,6 +245,10 @@ guint16 tsmux_stream_get_pid (TsMuxStream *stream); void tsmux_stream_set_buffer_release_func (TsMuxStream *stream, TsMuxStreamBufferReleaseFunc func); +void tsmux_stream_set_get_es_descriptors_func (TsMuxStream *stream, + TsMuxStreamGetESDescriptorsFunc func, + void *user_data); + /* Add a new buffer to the pool of available bytes. If pts or dts are not -1, they * indicate the PTS or DTS of the first access unit within this packet */ void tsmux_stream_add_data (TsMuxStream *stream, guint8 *data, guint len, @@ -252,6 +261,7 @@ gboolean tsmux_stream_is_pcr (TsMuxStream *stream); gboolean tsmux_stream_at_pes_start (TsMuxStream *stream); void tsmux_stream_get_es_descrs (TsMuxStream *stream, GstMpegtsPMTStream *pmt_stream); +void tsmux_stream_default_get_es_descrs (TsMuxStream * stream, GstMpegtsPMTStream * pmt_stream); gint tsmux_stream_bytes_in_buffer (TsMuxStream *stream); gint tsmux_stream_bytes_avail (TsMuxStream *stream); -- cgit v1.2.1