1 /* ASF muxer plugin for GStreamer
2  * Copyright (C) 2009 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 
21 #ifndef __GST_ASF_MUX_H__
22 #define __GST_ASF_MUX_H__
23 
24 
25 #include <gst/gst.h>
26 #include <gst/base/gstcollectpads.h>
27 #include <gst/riff/riff-media.h>
28 
29 #include "gstasfobjects.h"
30 
31 G_BEGIN_DECLS
32 #define GST_TYPE_ASF_MUX \
33   (gst_asf_mux_get_type())
34 #define GST_ASF_MUX(obj) \
35   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ASF_MUX,GstAsfMux))
36 #define GST_ASF_MUX_CLASS(klass) \
37   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ASF_MUX,GstAsfMuxClass))
38 #define GST_IS_ASF_MUX(obj) \
39   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ASF_MUX))
40 #define GST_IS_ASF_MUX_CLASS(klass) \
41   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ASF_MUX))
42 #define GST_ASF_MUX_CAST(obj) ((GstAsfMux*)(obj))
43 typedef struct _GstAsfMux GstAsfMux;
44 typedef struct _GstAsfMuxClass GstAsfMuxClass;
45 typedef struct _GstAsfPad GstAsfPad;
46 typedef struct _GstAsfAudioPad GstAsfAudioPad;
47 typedef struct _GstAsfVideoPad GstAsfVideoPad;
48 typedef enum _GstAsfMuxState GstAsfMuxState;
49 
50 enum _GstAsfMuxState
51 {
52   GST_ASF_MUX_STATE_NONE,
53   GST_ASF_MUX_STATE_HEADERS,
54   GST_ASF_MUX_STATE_DATA,
55   GST_ASF_MUX_STATE_EOS
56 };
57 
58 struct _GstAsfPad
59 {
60   GstCollectData collect;
61 
62   gboolean is_audio;
63   guint8 stream_number;
64   guint8 media_object_number;
65   guint32 bitrate;
66 
67   GstClockTime play_duration;
68   GstClockTime first_ts;
69 
70   GstBuffer *codec_data;
71 
72   /* stream only metadata */
73   GstTagList *taglist;
74 };
75 
76 struct _GstAsfAudioPad
77 {
78   GstAsfPad pad;
79 
80   gst_riff_strf_auds audioinfo;
81 };
82 
83 struct _GstAsfVideoPad
84 {
85   GstAsfPad pad;
86 
87   gst_riff_strf_vids vidinfo;
88 
89   /* Simple Index Entries */
90   GSList *simple_index;
91   gboolean has_keyframe;        /* if we have received one at least */
92   guint32 last_keyframe_packet;
93   guint16 last_keyframe_packet_count;
94   guint16 max_keyframe_packet_count;
95   GstClockTime next_index_time;
96   guint64 time_interval;
97 };
98 
99 struct _GstAsfMux
100 {
101   GstElement element;
102 
103   /* output stream state */
104   GstAsfMuxState state;
105 
106   /* counter to assign stream numbers */
107   guint8 stream_number;
108 
109   /* counting variables */
110   guint64 file_size;
111   guint64 data_object_size;
112   guint64 total_data_packets;
113 
114   /*
115    * data object size field position
116    * needed for updating when finishing the file
117    */
118   guint64 data_object_position;
119   guint64 file_properties_object_position;
120 
121   /* payloads still to be sent in a packet */
122   guint32 payload_data_size;
123   guint32 payload_parsing_info_size;
124   GSList *payloads;
125 
126   Guid file_id;
127 
128   /* properties */
129   guint32 prop_packet_size;
130   guint64 prop_preroll;
131   gboolean prop_merge_stream_tags;
132   guint64 prop_padding;
133   gboolean prop_streamable;
134 
135   /* same as properties, but those are stored here to be
136    * used without modification while muxing a single file */
137   guint32 packet_size;
138   guint64 preroll;              /* milisecs */
139   gboolean merge_stream_tags;
140 
141   GstClockTime first_ts;
142 
143   /* pads */
144   GstPad *srcpad;
145 
146   GstCollectPads *collect;
147 };
148 
149 struct _GstAsfMuxClass
150 {
151   GstElementClass parent_class;
152 };
153 
154 GType gst_asf_mux_get_type (void);
155 gboolean gst_asf_mux_plugin_init (GstPlugin * plugin);
156 
157 G_END_DECLS
158 #endif /* __GST_ASF_MUX_H__ */
159