Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / matroska / matroska-read-common.h
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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, 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   /* did we parse cues/tracks/segmentinfo already? */
65   gboolean                 index_parsed;
66   gboolean                 segmentinfo_parsed;
67   gboolean                 attachments_parsed;
68   GList                   *tags_parsed;
69
70   /* start-of-segment */
71   guint64                  ebml_segment_start;
72
73   /* a cue (index) table */
74   GArray                  *index;
75
76   /* timescale in the file */
77   guint64                  time_scale;
78
79   /* keeping track of playback position */
80   GstSegment               segment;
81
82   GstTagList              *global_tags;
83
84   /* pull mode caching */
85   GstBuffer *cached_buffer;
86   guint8 *cached_data;
87
88   /* push and pull mode */
89   guint64                  offset;
90
91   /* push based mode usual suspects */
92   GstAdapter              *adapter;
93 } GstMatroskaReadCommon;
94
95 GstFlowReturn gst_matroska_decode_content_encodings (GArray * encodings);
96 gboolean gst_matroska_decode_data (GArray * encodings, gpointer * data_out,
97     gsize * size_out, GstMatroskaTrackEncodingScope scope, gboolean free);
98 gint gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
99     gpointer user_data);
100 GstMatroskaIndex * gst_matroska_read_common_do_index_seek (
101     GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64
102     seek_pos, GArray ** _index, gint * _entry_index);
103 void gst_matroska_read_common_found_global_tag (GstMatroskaReadCommon * common,
104     GstElement * el, GstTagList * taglist);
105 gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common);
106 GstMatroskaTrackContext * gst_matroska_read_common_get_seek_track (
107     GstMatroskaReadCommon * common, GstMatroskaTrackContext * track);
108 GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
109     common, GstEbmlRead * ebml);
110 GstFlowReturn gst_matroska_read_common_parse_info (GstMatroskaReadCommon *
111     common, GstElement * el, GstEbmlRead * ebml);
112 GstFlowReturn gst_matroska_read_common_parse_attachments (
113     GstMatroskaReadCommon * common, GstElement * el, GstEbmlRead * ebml);
114 GstFlowReturn gst_matroska_read_common_parse_chapters (GstMatroskaReadCommon *
115     common, GstEbmlRead * ebml);
116 GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon *
117     common, GstEbmlRead * ebml);
118 GstFlowReturn gst_matroska_read_common_parse_metadata (GstMatroskaReadCommon *
119     common, GstElement * el, GstEbmlRead * ebml);
120 GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
121     common, GstEbmlRead * ebml, const gchar * parent_name, guint id);
122 GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon *
123     common, guint64 offset, guint size, GstBuffer ** p_buf, guint8 ** bytes);
124 GstFlowReturn gst_matroska_read_common_peek_id_length_pull (GstMatroskaReadCommon *
125     common, GstElement * el, guint32 * _id, guint64 * _length, guint *
126     _needed);
127 GstFlowReturn gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommon *
128     common, GstElement * el, guint32 * _id, guint64 * _length, guint *
129     _needed);
130 gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common,
131     guint track_num);
132 GstFlowReturn gst_matroska_read_common_read_track_encodings (
133     GstMatroskaReadCommon * common, GstEbmlRead * ebml,
134     GstMatroskaTrackContext * context);
135 void gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
136     GstClockTime time, gboolean full);
137 gboolean gst_matroska_read_common_tracknumber_unique (GstMatroskaReadCommon *
138     common, guint64 num);
139
140 G_END_DECLS
141
142 #endif /* __GST_MATROSKA_READ_COMMON_H__ */