1 /*****************************************************************************
2 * vlc_es.h: Elementary stream formats descriptions
3 *****************************************************************************
4 * Copyright (C) 1999-2001 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #if !defined( __LIBVLC__ )
25 #error You are not libvlc or one of its plugins. You cannot include this file
31 /* FIXME: i'm not too sure about this include but it fixes compilation of
32 * video chromas -- dionoea */
33 #include "vlc_common.h"
37 * This file defines the elementary streams format types
45 struct video_palette_t
47 int i_entries; /**< to keep the compatibility with ffmpeg's palette */
48 uint8_t palette[256][4]; /**< 4-byte RGBA/YUVA palette */
52 * audio replay gain description
54 #define AUDIO_REPLAY_GAIN_MAX (2)
55 #define AUDIO_REPLAY_GAIN_TRACK (0)
56 #define AUDIO_REPLAY_GAIN_ALBUM (1)
59 /* true if we have the peak value */
60 bool pb_peak[AUDIO_REPLAY_GAIN_MAX];
61 /* peak value where 1.0 means full sample value */
62 float pf_peak[AUDIO_REPLAY_GAIN_MAX];
64 /* true if we have the gain value */
65 bool pb_gain[AUDIO_REPLAY_GAIN_MAX];
66 /* gain value in dB */
67 float pf_gain[AUDIO_REPLAY_GAIN_MAX];
68 } audio_replay_gain_t;
71 * audio format description
75 vlc_fourcc_t i_format; /**< audio format fourcc */
76 unsigned int i_rate; /**< audio sample-rate */
78 /* Describes the channels configuration of the samples (ie. number of
79 * channels which are available in the buffer, and positions). */
80 uint32_t i_physical_channels;
82 /* Describes from which original channels, before downmixing, the
83 * buffer is derived. */
84 uint32_t i_original_channels;
86 /* Optional - for A/52, SPDIF and DTS types : */
87 /* Bytes used by one compressed frame, depends on bitrate. */
88 unsigned int i_bytes_per_frame;
90 /* Number of sampleframes contained in one compressed frame. */
91 unsigned int i_frame_length;
92 /* Please note that it may be completely arbitrary - buffers are not
93 * obliged to contain a integral number of so-called "frames". It's
94 * just here for the division :
95 * buffer_size = i_nb_samples * i_bytes_per_frame / i_frame_length
98 /* FIXME ? (used by the codecs) */
99 unsigned i_bitspersample;
100 unsigned i_blockalign;
101 uint8_t i_channels; /* must be <=32 */
105 #ifdef WORDS_BIGENDIAN
106 # define AUDIO_FMT_S16_NE VLC_FOURCC('s','1','6','b')
107 # define AUDIO_FMT_U16_NE VLC_FOURCC('u','1','6','b')
109 # define AUDIO_FMT_S16_NE VLC_FOURCC('s','1','6','l')
110 # define AUDIO_FMT_U16_NE VLC_FOURCC('u','1','6','l')
114 * video format description
116 struct video_format_t
118 vlc_fourcc_t i_chroma; /**< picture chroma */
119 unsigned int i_aspect; /**< aspect ratio */
121 unsigned int i_width; /**< picture width */
122 unsigned int i_height; /**< picture height */
123 unsigned int i_x_offset; /**< start offset of visible area */
124 unsigned int i_y_offset; /**< start offset of visible area */
125 unsigned int i_visible_width; /**< width of visible area */
126 unsigned int i_visible_height; /**< height of visible area */
128 unsigned int i_bits_per_pixel; /**< number of bits per pixel */
130 unsigned int i_sar_num; /**< sample/pixel aspect ratio */
131 unsigned int i_sar_den;
133 unsigned int i_frame_rate; /**< frame rate numerator */
134 unsigned int i_frame_rate_base; /**< frame rate denominator */
136 int i_rmask, i_gmask, i_bmask; /**< color masks for RGB chroma */
137 int i_rrshift, i_lrshift;
138 int i_rgshift, i_lgshift;
139 int i_rbshift, i_lbshift;
140 video_palette_t *p_palette; /**< video palette from demuxer */
144 * subtitles format description
148 /* the character encoding of the text of the subtitle.
149 * all gettext recognized shorts can be used */
153 int i_x_origin; /**< x coordinate of the subtitle. 0 = left */
154 int i_y_origin; /**< y coordinate of the subtitle. 0 = top */
159 uint32_t palette[16+1];
161 /* the width of the original movie the spu was extracted from */
162 int i_original_frame_width;
163 /* the height of the original movie the spu was extracted from */
164 int i_original_frame_height;
176 typedef struct extra_languages_t
179 char *psz_description;
186 vlc_fourcc_t i_codec;
188 int i_id; /* -1: let the core mark the right id
190 int i_group; /* -1 : standalone
191 >= 0 then a "group" (program) is created
193 int i_priority; /* -2 : mean not selectable by the users
194 -1 : mean not selected by default even
199 char *psz_description;
200 int i_extra_languages;
201 extra_languages_t *p_extra_languages;
203 audio_format_t audio;
204 audio_replay_gain_t audio_replay_gain;
205 video_format_t video;
208 unsigned int i_bitrate;
210 bool b_packetized; /* wether the data is packetized
211 (ie. not truncated) */
218 #define UNKNOWN_ES 0x00
219 #define VIDEO_ES 0x01
220 #define AUDIO_ES 0x02
224 static inline void es_format_Init( es_format_t *fmt,
225 int i_cat, vlc_fourcc_t i_codec )
228 fmt->i_codec = i_codec;
232 fmt->psz_language = NULL;
233 fmt->psz_description = NULL;
235 fmt->i_extra_languages = 0;
236 fmt->p_extra_languages = NULL;
238 memset( &fmt->audio, 0, sizeof(audio_format_t) );
239 memset( &fmt->audio_replay_gain, 0, sizeof(audio_replay_gain_t) );
240 memset( &fmt->video, 0, sizeof(video_format_t) );
241 memset( &fmt->subs, 0, sizeof(subs_format_t) );
243 fmt->b_packetized = true;
249 static inline int es_format_Copy( es_format_t *dst, const es_format_t *src )
252 memcpy( dst, src, sizeof( es_format_t ) );
253 if( src->psz_language )
254 dst->psz_language = strdup( src->psz_language );
255 if( src->psz_description )
256 dst->psz_description = strdup( src->psz_description );
257 if( src->i_extra > 0 )
259 dst->i_extra = src->i_extra;
260 dst->p_extra = malloc( src->i_extra );
261 memcpy( dst->p_extra, src->p_extra, src->i_extra );
269 if( src->subs.psz_encoding )
270 dst->subs.psz_encoding = strdup( src->subs.psz_encoding );
272 if( src->video.p_palette )
274 dst->video.p_palette =
275 (video_palette_t*)malloc( sizeof( video_palette_t ) );
276 memcpy( dst->video.p_palette, src->video.p_palette,
277 sizeof( video_palette_t ) );
280 dst->i_extra_languages = src->i_extra_languages;
281 if( dst->i_extra_languages )
282 dst->p_extra_languages = (extra_languages_t*)
283 malloc(dst->i_extra_languages * sizeof(*dst->p_extra_languages ));
284 for( i = 0; i < dst->i_extra_languages; i++ ) {
285 if( src->p_extra_languages[i].psz_language )
286 dst->p_extra_languages[i].psz_language = strdup( src->p_extra_languages[i].psz_language );
288 dst->p_extra_languages[i].psz_language = NULL;
289 if( src->p_extra_languages[i].psz_description )
290 dst->p_extra_languages[i].psz_description = strdup( src->p_extra_languages[i].psz_description );
292 dst->p_extra_languages[i].psz_description = NULL;
297 static inline void es_format_Clean( es_format_t *fmt )
299 free( fmt->psz_language );
300 free( fmt->psz_description );
302 if( fmt->i_extra > 0 ) free( fmt->p_extra );
304 free( fmt->video.p_palette );
305 free( fmt->subs.psz_encoding );
307 if( fmt->i_extra_languages > 0 && fmt->p_extra_languages )
310 for( i = 0; i < fmt->i_extra_languages; i++ )
312 free( fmt->p_extra_languages[i].psz_language );
313 free( fmt->p_extra_languages[i].psz_description );
315 free( fmt->p_extra_languages );
318 /* es_format_Clean can be called multiple times */
319 memset( fmt, 0, sizeof(*fmt) );