hlsdemux2: Split the stream object out

Move the stream object to a separate file to split the demux level behaviour
from the stream behaviour better.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
This commit is contained in:
Jan Schmidt 2022-11-18 00:26:41 +11:00 committed by GStreamer Marge Bot
parent 5baf5f4b1e
commit 42b0dd8c41
8 changed files with 2432 additions and 2313 deletions

View file

@ -3584,6 +3584,12 @@ gst_adaptive_demux_is_live (GstAdaptiveDemux * demux)
return FALSE;
}
const gchar *
gst_adaptive_demux_get_manifest_ref_uri (GstAdaptiveDemux * d)
{
return d->manifest_base_uri ? d->manifest_base_uri : d->manifest_uri;
}
static void
handle_manifest_download_complete (DownloadRequest * request,
DownloadRequestState state, GstAdaptiveDemux * demux)

View file

@ -457,6 +457,7 @@ GstAdaptiveDemuxTrack *gst_adaptive_demux_track_new (GstAdaptiveDemux *demux,
GstAdaptiveDemuxTrack *gst_adaptive_demux_track_ref (GstAdaptiveDemuxTrack *track);
void gst_adaptive_demux_track_unref (GstAdaptiveDemuxTrack *track);
const gchar *gst_adaptive_demux_get_manifest_ref_uri (GstAdaptiveDemux * demux);
gboolean gst_adaptive_demux_start_new_period (GstAdaptiveDemux * demux);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,177 @@
/* GStreamer
* Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
* Copyright (C) 2010 Andoni Morales Alastruey <ylatuya@gmail.com>
* Copyright (C) 2015 Tim-Philipp Müller <tim@centricular.com>
*
* gsthlsdemux-stream.h:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_HLS_DEMUX_STREAM_H__
#define __GST_HLS_DEMUX_STREAM_H__
#include <gst/gst.h>
#include <gst/base/gstadapter.h>
#include "m3u8.h"
#include "gstisoff.h"
#include <gstadaptivedemux.h>
#include "gsthlsdemux.h"
#include "gsthlsdemux-preloader.h"
#if defined(HAVE_OPENSSL)
#include <openssl/evp.h>
#elif defined(HAVE_NETTLE)
#include <nettle/aes.h>
#include <nettle/cbc.h>
#elif defined(HAVE_LIBGCRYPT)
#include <gcrypt.h>
#endif
G_BEGIN_DECLS
#define GST_TYPE_HLS_DEMUX_STREAM \
(gst_hls_demux_stream_get_type())
#define GST_HLS_DEMUX_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX_STREAM,GstHLSDemuxStream))
#define GST_HLS_DEMUX_STREAM_CAST(obj) ((GstHLSDemuxStream *)obj)
#define GST_HLS_DEMUX_STREAM_GET_DEMUX(obj) (GST_HLS_DEMUX_CAST(GST_ADAPTIVE_DEMUX2_STREAM(stream)->demux))
typedef struct _GstHLSDemuxStream GstHLSDemuxStream;
typedef GstAdaptiveDemux2StreamClass GstHLSDemuxStreamClass;
typedef enum {
GST_HLS_PARSER_NONE,
GST_HLS_PARSER_MPEGTS,
GST_HLS_PARSER_ID3,
GST_HLS_PARSER_WEBVTT,
GST_HLS_PARSER_ISOBMFF
} GstHLSParserType;
struct _GstHLSDemuxStream
{
GstAdaptiveDemux2Stream adaptive_demux_stream;
/* A stream either variants or renditions */
gboolean is_variant;
/* A copy of the demuxer flag, stored when the
* stream is created, so it can't change after
* the stream starts downloading things */
gboolean llhls_enabled;
/* Rendition-specific fields */
GstStreamType rendition_type; /* FIXME: Also used by variant streams */
gchar *lang;
gchar *name;
GstHLSRenditionStream *current_rendition;
/* rendition to switch to */
GstHLSRenditionStream *pending_rendition;
/* End of Rendition-specific fields */
/* Whether the underlying playlist was fetched on creation */
gboolean playlist_fetched;
GstClockTime playlist_last_update_time;
/* The media playlist currently used */
GstHLSMediaPlaylist *playlist;
/* The current header / init_file data */
GstM3U8InitFile *init_file;
/* The segment (from the above playlist) currently being used */
GstM3U8MediaSegment *current_segment;
/* When playing partial segments in LL-HLS, in_partial_segments is TRUE,
* and part_no is the current part index in the current_segment */
gboolean in_partial_segments;
guint part_idx;
/* Preload helper, that manages blocking preload downloads */
GstHLSDemuxPreloader *preloader;
/* Whether we need to typefind the next buffer */
gboolean do_typefind;
/* for collecting data until typefind succeeds */
GstBuffer *pending_typefind_buffer;
/* for chunking data into 16 byte multiples for decryption */
GstAdapter *pending_encrypted_data;
/* last decrypted buffer for pkcs7 unpadding. We only know that it is the last
* on ::finish_fragment() */
GstBuffer *pending_decrypted_buffer;
/* Current offset (in bytes) in fragment data we pushed downstream. Resets to
* -1 at every fragment start */
guint64 current_offset;
gboolean reset_pts;
/* decryption tooling */
#if defined(HAVE_OPENSSL)
# if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX aes_ctx;
# else
EVP_CIPHER_CTX *aes_ctx;
# endif
#elif defined(HAVE_NETTLE)
struct CBC_CTX (struct aes128_ctx, AES_BLOCK_SIZE) aes_ctx;
#elif defined(HAVE_LIBGCRYPT)
gcry_cipher_hd_t aes_ctx;
#endif
gchar *current_key;
guint8 *current_iv;
/* The type of parser used for data handling */
GstHLSParserType parser_type;
/* Is content processing required ? */
gboolean process_buffer_content;
/* Data to be analyzed by */
GstBuffer *pending_segment_data;
/* TRUE if pending_segment_data contains data from a header/index */
gboolean pending_data_is_header;
/* ISOBMFF */
GstMoovBox *moov;
/* Presentation offset to use and report. This value will be appended to all
* "output" stream times. Not enabled (i.e 0) if variant is ISOBMFF
*/
GstClockTime presentation_offset;
gboolean pdt_tag_sent;
};
GstFlowReturn
gst_hls_demux_stream_seek (GstAdaptiveDemux2Stream * stream, gboolean forward,
GstSeekFlags flags, GstClockTimeDiff ts, GstClockTimeDiff * final_ts);
GstFlowReturn
gst_hls_demux_stream_update_media_playlist (GstHLSDemuxStream * stream, gchar ** uri, GError ** err);
void
gst_hls_demux_stream_clear_pending_data (GstHLSDemuxStream * hls_stream,
gboolean force);
GstHLSParserResult gst_hlsdemux_stream_handle_internal_time (
GstHLSDemuxStream *hls_stream,
GstClockTime internal_time);
G_END_DECLS
#endif /* __GST_HLS_DEMUX_STREAM_H__ */

View file

@ -32,6 +32,7 @@
#include <string.h>
#include "gsthlsdemux.h"
#include "gsthlsdemux-stream.h"
GST_DEBUG_CATEGORY_EXTERN (gst_hls_demux2_debug);
#define GST_CAT_DEFAULT gst_hls_demux2_debug
@ -389,7 +390,7 @@ gst_hlsdemux_handle_content_mpegts (GstHLSDemux * demux,
return GST_HLS_PARSER_RESULT_NEED_MORE_DATA;
/* We have the first internal time, figure out if we are in sync or not */
return gst_hlsdemux_handle_internal_time (demux, hls_stream, internal_time);
return gst_hlsdemux_stream_handle_internal_time (hls_stream, internal_time);
}
GstHLSParserResult
@ -496,13 +497,12 @@ out:
gst_buffer_unmap (*buffer, &info);
if (smallest_ts != GST_CLOCK_TIME_NONE) {
ret = gst_hlsdemux_handle_internal_time (demux, hls_stream, smallest_ts);
ret = gst_hlsdemux_stream_handle_internal_time (hls_stream, smallest_ts);
}
return ret;
}
GstHLSParserResult
gst_hlsdemux_handle_content_id3 (GstHLSDemux * demux,
GstHLSDemuxStream * hls_stream, gboolean draining, GstBuffer ** buffer)
@ -561,7 +561,7 @@ gst_hlsdemux_handle_content_id3 (GstHLSDemux * demux,
gst_buffer_unmap (tag_buf, &info);
ret = gst_hlsdemux_handle_internal_time (demux, hls_stream, internal);
ret = gst_hlsdemux_stream_handle_internal_time (hls_stream, internal);
out:
if (priv_data)
@ -855,7 +855,7 @@ gst_hlsdemux_handle_content_webvtt (GstHLSDemux * demux,
segment_end = segment_start + current_segment->duration;
tolerance = MAX (current_segment->duration / 2, 500 * GST_MSECOND);
map = gst_hls_find_time_map (demux, current_segment->discont_sequence);
map = gst_hls_demux_find_time_map (demux, current_segment->discont_sequence);
builder = g_ptr_array_new_with_free_func (g_free);

View file

@ -30,16 +30,6 @@
#include "m3u8.h"
#include "gstisoff.h"
#include "gstadaptivedemux.h"
#include "gsthlsdemux-preloader.h"
#if defined(HAVE_OPENSSL)
#include <openssl/evp.h>
#elif defined(HAVE_NETTLE)
#include <nettle/aes.h>
#include <nettle/cbc.h>
#elif defined(HAVE_LIBGCRYPT)
#include <gcrypt.h>
#endif
G_BEGIN_DECLS
@ -61,22 +51,7 @@ G_BEGIN_DECLS
typedef struct _GstHLSDemux2 GstHLSDemux;
typedef struct _GstHLSDemux2Class GstHLSDemuxClass;
#define GST_TYPE_HLS_DEMUX_STREAM \
(gst_hls_demux_stream_get_type())
#define GST_HLS_DEMUX_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX_STREAM,GstHLSDemuxStream))
#define GST_HLS_DEMUX_STREAM_CAST(obj) ((GstHLSDemuxStream *)obj)
typedef struct _GstHLSDemuxStream GstHLSDemuxStream;
typedef GstAdaptiveDemux2StreamClass GstHLSDemuxStreamClass;
typedef enum {
GST_HLS_PARSER_NONE,
GST_HLS_PARSER_MPEGTS,
GST_HLS_PARSER_ID3,
GST_HLS_PARSER_WEBVTT,
GST_HLS_PARSER_ISOBMFF
} GstHLSParserType;
typedef enum {
/* More data is needed to parse the fragment */
@ -90,103 +65,6 @@ typedef enum {
GST_HLS_PARSER_RESULT_RESYNC
} GstHLSParserResult;
struct _GstHLSDemuxStream
{
GstAdaptiveDemux2Stream adaptive_demux_stream;
/* A stream either variants or renditions */
gboolean is_variant;
/* A copy of the demuxer flag, stored when the
* stream is created, so it can't change after
* the stream starts downloading things */
gboolean llhls_enabled;
/* Rendition-specific fields */
GstStreamType rendition_type; /* FIXME: Also used by variant streams */
gchar *lang;
gchar *name;
GstHLSRenditionStream *current_rendition;
/* rendition to switch to */
GstHLSRenditionStream *pending_rendition;
/* End of Rendition-specific fields */
/* Whether the underlying playlist was fetched on creation */
gboolean playlist_fetched;
GstClockTime playlist_last_update_time;
/* The media playlist currently used */
GstHLSMediaPlaylist *playlist;
/* The current header / init_file data */
GstM3U8InitFile *init_file;
/* The segment (from the above playlist) currently being used */
GstM3U8MediaSegment *current_segment;
/* When playing partial segments in LL-HLS, in_partial_segments is TRUE,
* and part_no is the current part index in the current_segment */
gboolean in_partial_segments;
guint part_idx;
/* Preload helper, that manages blocking preload downloads */
GstHLSDemuxPreloader *preloader;
/* Whether we need to typefind the next buffer */
gboolean do_typefind;
/* for collecting data until typefind succeeds */
GstBuffer *pending_typefind_buffer;
/* for chunking data into 16 byte multiples for decryption */
GstAdapter *pending_encrypted_data;
/* last decrypted buffer for pkcs7 unpadding. We only know that it is the last
* on ::finish_fragment() */
GstBuffer *pending_decrypted_buffer;
/* Current offset (in bytes) in fragment data we pushed downstream. Resets to
* -1 at every fragment start */
guint64 current_offset;
gboolean reset_pts;
/* decryption tooling */
#if defined(HAVE_OPENSSL)
# if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX aes_ctx;
# else
EVP_CIPHER_CTX *aes_ctx;
# endif
#elif defined(HAVE_NETTLE)
struct CBC_CTX (struct aes128_ctx, AES_BLOCK_SIZE) aes_ctx;
#elif defined(HAVE_LIBGCRYPT)
gcry_cipher_hd_t aes_ctx;
#endif
gchar *current_key;
guint8 *current_iv;
/* The type of parser used for data handling */
GstHLSParserType parser_type;
/* Is content processing required ? */
gboolean process_buffer_content;
/* Data to be analyzed by */
GstBuffer *pending_segment_data;
/* TRUE if pending_segment_data contains data from a header/index */
gboolean pending_data_is_header;
/* ISOBMFF */
GstMoovBox *moov;
/* Presentation offset to use and report. This value will be appended to all
* "output" stream times. Not enabled (i.e 0) if variant is ISOBMFF
*/
GstClockTime presentation_offset;
gboolean pdt_tag_sent;
};
typedef struct {
guint8 data[16];
} GstHLSKey;
@ -229,11 +107,30 @@ struct _GstHLSDemux2Class
GstAdaptiveDemuxClass parent_class;
};
GstAdaptiveDemuxTrack *
gst_hls_demux_new_track_for_rendition (GstHLSDemux * demux,
GstHLSRenditionStream * rendition,
GstCaps * caps, GstStreamFlags flags, GstTagList * tags);
void gst_hls_demux_start_rendition_streams (GstHLSDemux * hlsdemux);
void gst_hls_demux_reset_for_lost_sync (GstHLSDemux * hlsdemux);
const GstHLSKey *gst_hls_demux_get_key (GstHLSDemux * demux,
const gchar * key_url, const gchar * referer, gboolean allow_cache);
void
gst_hls_demux_setup_initial_playlist (GstHLSDemux * demux,
GstHLSMediaPlaylist * playlist);
gboolean gst_hls_demux_change_variant_playlist (GstHLSDemux * demux,
guint max_bitrate, gboolean * changed);
void gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn,
GstClockTimeDiff stream_time, GDateTime * pdt);
void gst_hls_update_time_mappings (GstHLSDemux * demux,
GstHLSMediaPlaylist * playlist);
gchar *gst_hls_buf_to_utf8_text (GstBuffer * buf);
/* Private */
GstHLSParserResult gst_hlsdemux_handle_content_mpegts (GstHLSDemux *demux,
GstHLSDemuxStream *hls_stream,
gboolean draining,
@ -254,14 +151,10 @@ GstHLSParserResult gst_hlsdemux_handle_content_webvtt (GstHLSDemux *demux
gboolean draining,
GstBuffer **buffer);
GstHLSParserResult gst_hlsdemux_handle_internal_time (GstHLSDemux *demux,
GstHLSDemuxStream *hls_stream,
GstClockTime internal_time);
GstClockTimeDiff gst_hls_internal_to_stream_time (GstHLSTimeMap *map,
GstClockTime internal_time);
GstHLSTimeMap *gst_hls_find_time_map (GstHLSDemux * demux, gint64 dsn);
GstHLSTimeMap *gst_hls_demux_find_time_map (GstHLSDemux * demux, gint64 dsn);
GType gst_hls_demux2_get_type (void);
GType gst_hls_demux_stream_get_type (void);

View file

@ -1,5 +1,6 @@
hls_sources = [
'hls/gsthlsdemux.c',
'hls/gsthlsdemux-stream.c',
'hls/gsthlsdemux-preloader.c',
'hls/gsthlsdemux-util.c',
'hls/gsthlselement.c',