• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer Matroska muxer/demuxer
2  * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2011 Debarshi Ray <rishi@gnu.org>
4  *
5  * matroska-read-common.h: shared by matroska file/stream demuxer and parser
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef __GST_MATROSKA_READ_COMMON_H__
24 #define __GST_MATROSKA_READ_COMMON_H__
25 
26 #include <glib.h>
27 #include <gst/gst.h>
28 #include <gst/base/gstadapter.h>
29 
30 #include "matroska-ids.h"
31 
32 G_BEGIN_DECLS
33 
34 GST_DEBUG_CATEGORY_EXTERN(matroskareadcommon_debug);
35 
36 typedef enum {
37   GST_MATROSKA_READ_STATE_START,
38   GST_MATROSKA_READ_STATE_SEGMENT,
39   GST_MATROSKA_READ_STATE_HEADER,
40   GST_MATROSKA_READ_STATE_DATA,
41   GST_MATROSKA_READ_STATE_SEEK,
42   GST_MATROSKA_READ_STATE_SCANNING
43 } GstMatroskaReadState;
44 
45 typedef struct _GstMatroskaReadCommon {
46 #if 0
47   GstIndex                *element_index;
48   gint                     element_index_writer_id;
49 #endif
50 
51   /* pads */
52   GstPad                  *sinkpad;
53   GPtrArray               *src;
54   guint                    num_streams;
55 
56   /* metadata */
57   gchar                   *muxing_app;
58   gchar                   *writing_app;
59   gint64                   created;
60 
61   /* state */
62   GstMatroskaReadState     state;
63 
64   /* stream type */
65   gboolean                 is_webm;
66   gboolean                 has_video;
67 
68   /* did we parse cues/tracks/segmentinfo already? */
69   gboolean                 index_parsed;
70   gboolean                 segmentinfo_parsed;
71   gboolean                 attachments_parsed;
72   gboolean                 chapters_parsed;
73   GList                   *tags_parsed;
74 
75   /* chapters stuff */
76   /* Internal toc is used to keep track of the internal UID
77    * which are different from the external StringUID used
78    * in the user toc */
79   GstToc                  *toc;
80   GstToc                  *internal_toc;
81   gboolean                toc_updated;
82 
83   /* start-of-segment and length */
84   guint64                  ebml_segment_start;
85   guint64                  ebml_segment_length;
86 
87   /* a cue (index) table */
88   GArray                  *index;
89 
90   /* timescale in the file */
91   guint64                  time_scale;
92 
93   /* keeping track of playback position */
94   GstSegment               segment;
95 
96   GstTagList              *global_tags;
97   gboolean                 global_tags_changed;
98 
99   /* pull mode caching */
100   GstBuffer *cached_buffer;
101   guint8 *cached_data;
102   GstMapInfo cached_map;
103 
104   /* push and pull mode */
105   guint64                  offset;
106 
107   guint64                  start_resync_offset;
108 
109   /* state to restore after scanning for invalid data */
110   gint                     state_to_restore;
111 
112   /* push based mode usual suspects */
113   GstAdapter              *adapter;
114 
115   /* cache for track tags that forward-reference their tracks */
116   GHashTable *cached_track_taglists ;
117 
118 } GstMatroskaReadCommon;
119 
120 GstFlowReturn gst_matroska_decode_content_encodings (GArray * encodings);
121 gboolean gst_matroska_decode_data (GArray * encodings, gpointer * data_out,
122     gsize * size_out, GstMatroskaTrackEncodingScope scope, gboolean free);
123 gboolean
124 gst_matroska_parse_protection_meta (gpointer * data_out, gsize * size_out,
125     GstStructure * info_protect, gboolean * encrypted);
126 gint gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
127     gpointer user_data);
128 GstMatroskaIndex * gst_matroska_read_common_do_index_seek (
129     GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64
130     seek_pos, GArray ** _index, gint * _entry_index, GstSearchMode snap_dir);
131 void gst_matroska_read_common_found_global_tag (GstMatroskaReadCommon * common,
132     GstElement * el, GstTagList * taglist);
133 gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common);
134 GstMatroskaTrackContext * gst_matroska_read_common_get_seek_track (
135     GstMatroskaReadCommon * common, GstMatroskaTrackContext * track);
136 GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
137     common, GstEbmlRead * ebml);
138 GstFlowReturn gst_matroska_read_common_parse_info (GstMatroskaReadCommon *
139     common, GstElement * el, GstEbmlRead * ebml);
140 GstFlowReturn gst_matroska_read_common_parse_attachments (
141     GstMatroskaReadCommon * common, GstElement * el, GstEbmlRead * ebml);
142 GstFlowReturn gst_matroska_read_common_parse_chapters (GstMatroskaReadCommon *
143     common, GstEbmlRead * ebml);
144 GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon *
145     common, GstEbmlRead * ebml);
146 GstFlowReturn gst_matroska_read_common_parse_metadata (GstMatroskaReadCommon *
147     common, GstElement * el, GstEbmlRead * ebml);
148 GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
149     common, GstEbmlRead * ebml, const gchar * parent_name, guint id);
150 GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon *
151     common, guint64 offset, guint size, GstBuffer ** p_buf, guint8 ** bytes);
152 GstFlowReturn gst_matroska_read_common_peek_id_length_pull (GstMatroskaReadCommon *
153     common, GstElement * el, guint32 * _id, guint64 * _length, guint *
154     _needed);
155 GstFlowReturn gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommon *
156     common, GstElement * el, guint32 * _id, guint64 * _length, guint *
157     _needed);
158 gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common,
159     guint track_num);
160 GstFlowReturn gst_matroska_read_common_read_track_encodings (
161     GstMatroskaReadCommon * common, GstEbmlRead * ebml,
162     GstMatroskaTrackContext * context);
163 void gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
164     GstClockTime time, gboolean full);
165 void gst_matroska_read_common_free_parsed_el (gpointer mem, gpointer user_data);
166 void gst_matroska_read_common_init (GstMatroskaReadCommon * ctx);
167 void gst_matroska_read_common_finalize (GstMatroskaReadCommon * ctx);
168 void gst_matroska_read_common_reset (GstElement * element,
169     GstMatroskaReadCommon * ctx);
170 gboolean gst_matroska_read_common_tracknumber_unique (GstMatroskaReadCommon *
171     common, guint64 num);
172 
173 G_END_DECLS
174 
175 #endif /* __GST_MATROSKA_READ_COMMON_H__ */
176