1 /* AVI muxer plugin for GStreamer 2 * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net> 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_AVI_MUX_H__ 22 #define __GST_AVI_MUX_H__ 23 24 25 #include <gst/gst.h> 26 #include <gst/base/gstcollectpads.h> 27 #include <gst/riff/riff-ids.h> 28 #include <gst/audio/audio.h> 29 #include "avi-ids.h" 30 31 G_BEGIN_DECLS 32 33 #define GST_TYPE_AVI_MUX \ 34 (gst_avi_mux_get_type()) 35 #define GST_AVI_MUX(obj) \ 36 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVI_MUX,GstAviMux)) 37 #define GST_AVI_MUX_CLASS(klass) \ 38 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AVI_MUX,GstAviMuxClass)) 39 #define GST_IS_AVI_MUX(obj) \ 40 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVI_MUX)) 41 #define GST_IS_AVI_MUX_CLASS(klass) \ 42 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AVI_MUX)) 43 44 #define GST_AVI_INDEX_OF_INDEXES 0 45 #define GST_AVI_INDEX_OF_CHUNKS 1 46 47 /* this allows indexing up to 64GB avi file */ 48 #define GST_AVI_SUPERINDEX_COUNT 32 49 50 /* max size */ 51 #define GST_AVI_MAX_SIZE 0x40000000 52 53 typedef struct _gst_avi_superindex_entry { 54 guint64 offset; 55 guint32 size; 56 guint32 duration; 57 } gst_avi_superindex_entry; 58 59 typedef struct _gst_riff_strh_full { 60 gst_riff_strh parent; 61 /* rcFrame, RECT structure (struct of 4 shorts) */ 62 gint16 left; 63 gint16 top; 64 gint16 right; 65 gint16 bottom; 66 } gst_riff_strh_full; 67 68 typedef struct _GstAviPad GstAviPad; 69 typedef struct _GstAviMux GstAviMux; 70 typedef struct _GstAviMuxClass GstAviMuxClass; 71 72 typedef GstFlowReturn (*GstAviPadHook) (GstAviMux * avi, GstAviPad * avipad, 73 GstBuffer * buffer); 74 75 struct _GstAviPad { 76 /* do not extend, link to it */ 77 /* is NULL if original sink request pad has been removed */ 78 GstCollectData *collect; 79 80 /* type */ 81 gboolean is_video; 82 gboolean connected; 83 84 /* chunk tag */ 85 gchar *tag; 86 87 /* stream header */ 88 gst_riff_strh hdr; 89 90 /* odml super indexes */ 91 gst_avi_superindex_entry idx[GST_AVI_SUPERINDEX_COUNT]; 92 gint idx_index; 93 gchar *idx_tag; 94 95 /* stream specific hook */ 96 GstAviPadHook hook; 97 }; 98 99 typedef struct _GstAviVideoPad { 100 GstAviPad parent; 101 102 /* stream format */ 103 gst_riff_strf_vids vids; 104 /* extra data */ 105 GstBuffer *vids_codec_data; 106 /* ODML video properties */ 107 gst_riff_vprp vprp; 108 109 GstBuffer *prepend_buffer; 110 111 } GstAviVideoPad; 112 113 typedef struct _GstAviAudioPad { 114 GstAviPad parent; 115 116 /* stream format */ 117 gst_riff_strf_auds auds; 118 /* additional fields for WAVEFORMATEX */ 119 gboolean write_waveformatex; 120 guint16 valid_bits_per_sample; 121 guint32 channel_mask; 122 123 /* for raw audio */ 124 gboolean needs_reorder; 125 GstAudioFormat audio_format; 126 GstAudioChannelPosition gst_positions[64], wav_positions[64]; 127 128 /* audio info for bps calculation */ 129 guint32 audio_size; 130 guint64 audio_time; 131 /* max audio chunk size for vbr */ 132 guint32 max_audio_chunk; 133 134 /* counts the number of samples to put in indx chunk 135 * useful for raw audio where usually there are more than 136 * 1 sample in each GstBuffer */ 137 gint samples; 138 139 /* extra data */ 140 GstBuffer *auds_codec_data; 141 } GstAviAudioPad; 142 143 typedef struct _GstAviCollectData { 144 /* extend the CollectData */ 145 GstCollectData collect; 146 147 GstAviPad *avipad; 148 } GstAviCollectData; 149 150 struct _GstAviMux { 151 GstElement element; 152 153 /* pads */ 154 GstPad *srcpad; 155 /* sinkpads, video first */ 156 GSList *sinkpads; 157 /* video restricted to 1 pad */ 158 guint video_pads, audio_pads; 159 GstCollectPads *collect; 160 161 /* the AVI header */ 162 /* still some single stream video data in mux struct */ 163 gst_riff_avih avi_hdr; 164 /* total number of (video) frames */ 165 guint32 total_frames; 166 /* amount of total data (bytes) */ 167 guint64 total_data; 168 /* amount of data (bytes) in the AVI/AVIX block; 169 * actually the movi list, so counted from and including the movi tag */ 170 guint32 data_size, datax_size; 171 /* num (video) frames in the AVI/AVIX block */ 172 guint32 num_frames, numx_frames; 173 /* size of hdrl list, including tag as usual */ 174 175 /* total size of extra codec data */ 176 guint32 codec_data_size; 177 /* state info */ 178 gboolean write_header; 179 gboolean restart; 180 181 /* tags */ 182 GstTagList *tags_snap; 183 184 /* information about the AVI index ('idx') */ 185 gst_riff_index_entry *idx; 186 gint idx_index, idx_count; 187 /* offset of *chunk* (relative to a base offset); entered in the index */ 188 guint32 idx_offset; 189 /* size of idx1 chunk (including! chunk header and size bytes) */ 190 guint32 idx_size; 191 192 /* are we a big file already? */ 193 gboolean is_bigfile; 194 guint64 avix_start; 195 196 /* whether to use "large AVI files" or just stick to small indexed files */ 197 gboolean enable_large_avi; 198 }; 199 200 struct _GstAviMuxClass { 201 GstElementClass parent_class; 202 }; 203 204 GType gst_avi_mux_get_type(void); 205 206 G_END_DECLS 207 208 209 #endif /* __GST_AVI_MUX_H__ */ 210