mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-04 21:42:25 +00:00
matroskademux: use bytereader based GstEbmlRead as a helper
... rather than basing on it by inheritance. Also use more common code for push and pull mode. Fixes #619198. Fixes #611117.
This commit is contained in:
parent
973c8ddfdf
commit
085e333283
4 changed files with 1160 additions and 1857 deletions
File diff suppressed because it is too large
Load diff
|
@ -23,6 +23,7 @@
|
||||||
#define __GST_EBML_READ_H__
|
#define __GST_EBML_READ_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
#include <gst/base/gstbytereader.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -39,47 +40,42 @@ G_BEGIN_DECLS
|
||||||
#define GST_EBML_READ_GET_CLASS(obj) \
|
#define GST_EBML_READ_GET_CLASS(obj) \
|
||||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EBML_READ, GstEbmlReadClass))
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EBML_READ, GstEbmlReadClass))
|
||||||
|
|
||||||
/* custom flow return code */
|
GST_DEBUG_CATEGORY_EXTERN (ebmlread_debug);
|
||||||
#define GST_FLOW_END GST_FLOW_CUSTOM_SUCCESS
|
|
||||||
|
|
||||||
typedef struct _GstEbmlLevel {
|
/* custom flow return code */
|
||||||
guint64 start;
|
#define GST_FLOW_PARSE GST_FLOW_CUSTOM_ERROR
|
||||||
guint64 length;
|
|
||||||
} GstEbmlLevel;
|
typedef struct _GstEbmlMaster {
|
||||||
|
guint64 offset;
|
||||||
|
GstByteReader br;
|
||||||
|
} GstEbmlMaster;
|
||||||
|
|
||||||
typedef struct _GstEbmlRead {
|
typedef struct _GstEbmlRead {
|
||||||
GstElement parent;
|
GstElement *el;
|
||||||
|
|
||||||
GstBuffer *cached_buffer;
|
GstBuffer *buf;
|
||||||
gboolean push_cache;
|
|
||||||
|
|
||||||
GstPad *sinkpad;
|
|
||||||
guint64 offset;
|
guint64 offset;
|
||||||
|
|
||||||
GList *level;
|
GArray *readers;
|
||||||
} GstEbmlRead;
|
} GstEbmlRead;
|
||||||
|
|
||||||
typedef struct _GstEbmlReadClass {
|
typedef const guint8 * (*GstPeekData) (gpointer * context, guint peek);
|
||||||
GstElementClass parent;
|
|
||||||
} GstEbmlReadClass;
|
|
||||||
|
|
||||||
GType gst_ebml_read_get_type (void);
|
/* returns UNEXPECTED if not enough data */
|
||||||
|
GstFlowReturn gst_ebml_peek_id_length (guint32 * _id, guint64 * _length,
|
||||||
|
guint * _needed,
|
||||||
|
GstPeekData peek, gpointer * ctx,
|
||||||
|
GstElement * el, guint64 offset);
|
||||||
|
|
||||||
void gst_ebml_level_free (GstEbmlLevel *level);
|
void gst_ebml_read_init (GstEbmlRead * ebml,
|
||||||
|
GstElement * el, GstBuffer * buf,
|
||||||
void gst_ebml_read_reset_cache (GstEbmlRead * ebml,
|
|
||||||
GstBuffer * buffer,
|
|
||||||
guint64 offset);
|
guint64 offset);
|
||||||
|
|
||||||
GstFlowReturn gst_ebml_peek_id (GstEbmlRead *ebml,
|
void gst_ebml_read_clear (GstEbmlRead * ebml);
|
||||||
guint *level_up,
|
|
||||||
guint32 *id);
|
|
||||||
|
|
||||||
GstFlowReturn gst_ebml_read_seek (GstEbmlRead *ebml,
|
GstFlowReturn gst_ebml_peek_id (GstEbmlRead * ebml, guint32 * id);
|
||||||
guint64 offset);
|
|
||||||
|
|
||||||
gint64 gst_ebml_read_get_length (GstEbmlRead *ebml);
|
|
||||||
|
|
||||||
|
/* return _PARSE if not enough data to read what is needed, _ERROR or _OK */
|
||||||
GstFlowReturn gst_ebml_read_skip (GstEbmlRead *ebml);
|
GstFlowReturn gst_ebml_read_skip (GstEbmlRead *ebml);
|
||||||
|
|
||||||
GstFlowReturn gst_ebml_read_buffer (GstEbmlRead *ebml,
|
GstFlowReturn gst_ebml_read_buffer (GstEbmlRead *ebml,
|
||||||
|
@ -113,6 +109,8 @@ GstFlowReturn gst_ebml_read_date (GstEbmlRead *ebml,
|
||||||
GstFlowReturn gst_ebml_read_master (GstEbmlRead *ebml,
|
GstFlowReturn gst_ebml_read_master (GstEbmlRead *ebml,
|
||||||
guint32 *id);
|
guint32 *id);
|
||||||
|
|
||||||
|
GstFlowReturn gst_ebml_read_pop_master (GstEbmlRead *ebml);
|
||||||
|
|
||||||
GstFlowReturn gst_ebml_read_binary (GstEbmlRead *ebml,
|
GstFlowReturn gst_ebml_read_binary (GstEbmlRead *ebml,
|
||||||
guint32 *id,
|
guint32 *id,
|
||||||
guint8 **binary,
|
guint8 **binary,
|
||||||
|
@ -122,6 +120,51 @@ GstFlowReturn gst_ebml_read_header (GstEbmlRead *read,
|
||||||
gchar **doctype,
|
gchar **doctype,
|
||||||
guint *version);
|
guint *version);
|
||||||
|
|
||||||
|
/* Returns current (absolute) position of Ebml parser,
|
||||||
|
* i.e. taking into account offset provided at init */
|
||||||
|
static inline guint64
|
||||||
|
gst_ebml_read_get_pos (GstEbmlRead * ebml)
|
||||||
|
{
|
||||||
|
GstEbmlMaster *m;
|
||||||
|
|
||||||
|
g_return_val_if_fail (ebml->readers, 0);
|
||||||
|
g_return_val_if_fail (ebml->readers->len, 0);
|
||||||
|
|
||||||
|
m = &(g_array_index (ebml->readers, GstEbmlMaster, ebml->readers->len - 1));
|
||||||
|
return m->offset + gst_byte_reader_get_pos (&m->br);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns starting offset of Ebml parser */
|
||||||
|
static inline guint64
|
||||||
|
gst_ebml_read_get_offset (GstEbmlRead * ebml)
|
||||||
|
{
|
||||||
|
return ebml->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline GstByteReader *
|
||||||
|
gst_ebml_read_br (GstEbmlRead * ebml)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (ebml->readers, NULL);
|
||||||
|
g_return_val_if_fail (ebml->readers->len, NULL);
|
||||||
|
|
||||||
|
return &(g_array_index (ebml->readers,
|
||||||
|
GstEbmlMaster, ebml->readers->len - 1).br);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline gboolean
|
||||||
|
gst_ebml_read_has_remaining (GstEbmlRead * ebml, guint64 bytes_needed,
|
||||||
|
gboolean auto_pop)
|
||||||
|
{
|
||||||
|
gboolean res;
|
||||||
|
|
||||||
|
res = (gst_byte_reader_get_remaining (gst_ebml_read_br (ebml)) >= bytes_needed);
|
||||||
|
if (G_LIKELY (!res && auto_pop)) {
|
||||||
|
gst_ebml_read_pop_master (ebml);
|
||||||
|
}
|
||||||
|
|
||||||
|
return G_LIKELY (res);
|
||||||
|
}
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_EBML_READ_H__ */
|
#endif /* __GST_EBML_READ_H__ */
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -43,13 +43,14 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GST_MATROSKA_DEMUX_STATE_START,
|
GST_MATROSKA_DEMUX_STATE_START,
|
||||||
|
GST_MATROSKA_DEMUX_STATE_SEGMENT,
|
||||||
GST_MATROSKA_DEMUX_STATE_HEADER,
|
GST_MATROSKA_DEMUX_STATE_HEADER,
|
||||||
GST_MATROSKA_DEMUX_STATE_DATA,
|
GST_MATROSKA_DEMUX_STATE_DATA,
|
||||||
GST_MATROSKA_DEMUX_STATE_SEEK
|
GST_MATROSKA_DEMUX_STATE_SEEK
|
||||||
} GstMatroskaDemuxState;
|
} GstMatroskaDemuxState;
|
||||||
|
|
||||||
typedef struct _GstMatroskaDemux {
|
typedef struct _GstMatroskaDemux {
|
||||||
GstEbmlRead parent;
|
GstElement parent;
|
||||||
|
|
||||||
/* < private > */
|
/* < private > */
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ typedef struct _GstMatroskaDemux {
|
||||||
GstMatroskaDemuxState state;
|
GstMatroskaDemuxState state;
|
||||||
guint level_up;
|
guint level_up;
|
||||||
guint64 seek_block;
|
guint64 seek_block;
|
||||||
|
gboolean seek_first;
|
||||||
|
|
||||||
/* did we parse cues/tracks/segmentinfo already? */
|
/* did we parse cues/tracks/segmentinfo already? */
|
||||||
gboolean index_parsed;
|
gboolean index_parsed;
|
||||||
|
@ -82,6 +84,7 @@ typedef struct _GstMatroskaDemux {
|
||||||
gboolean segmentinfo_parsed;
|
gboolean segmentinfo_parsed;
|
||||||
gboolean attachments_parsed;
|
gboolean attachments_parsed;
|
||||||
GList *tags_parsed;
|
GList *tags_parsed;
|
||||||
|
GList *seek_parsed;
|
||||||
|
|
||||||
/* start-of-segment */
|
/* start-of-segment */
|
||||||
guint64 ebml_segment_start;
|
guint64 ebml_segment_start;
|
||||||
|
@ -101,12 +104,17 @@ typedef struct _GstMatroskaDemux {
|
||||||
GstEvent *new_segment;
|
GstEvent *new_segment;
|
||||||
GstTagList *global_tags;
|
GstTagList *global_tags;
|
||||||
|
|
||||||
/* push based mode usual suspects */
|
/* pull mode caching */
|
||||||
|
GstBuffer *cached_buffer;
|
||||||
|
|
||||||
|
/* push and pull mode */
|
||||||
guint64 offset;
|
guint64 offset;
|
||||||
GstAdapter *adapter;
|
|
||||||
/* some state saving */
|
/* some state saving */
|
||||||
GstClockTime cluster_time;
|
GstClockTime cluster_time;
|
||||||
guint64 cluster_offset;
|
guint64 cluster_offset;
|
||||||
|
|
||||||
|
/* push based mode usual suspects */
|
||||||
|
GstAdapter *adapter;
|
||||||
/* index stuff */
|
/* index stuff */
|
||||||
gboolean seekable;
|
gboolean seekable;
|
||||||
gboolean building_index;
|
gboolean building_index;
|
||||||
|
@ -122,7 +130,7 @@ typedef struct _GstMatroskaDemux {
|
||||||
} GstMatroskaDemux;
|
} GstMatroskaDemux;
|
||||||
|
|
||||||
typedef struct _GstMatroskaDemuxClass {
|
typedef struct _GstMatroskaDemuxClass {
|
||||||
GstEbmlReadClass parent;
|
GstElementClass parent;
|
||||||
} GstMatroskaDemuxClass;
|
} GstMatroskaDemuxClass;
|
||||||
|
|
||||||
gboolean gst_matroska_demux_plugin_init (GstPlugin *plugin);
|
gboolean gst_matroska_demux_plugin_init (GstPlugin *plugin);
|
||||||
|
|
Loading…
Reference in a new issue