]> git.sesse.net Git - vlc/blob - include/vlc_es.h
Chroma API change. Chromas are now normal video filters (almost).
[vlc] / include / vlc_es.h
1 /*****************************************************************************
2  * vlc_es.h: Elementary stream formats descriptions
3  *****************************************************************************
4  * Copyright (C) 1999-2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #if !defined( __LIBVLC__ )
25   #error You are not libvlc or one of its plugins. You cannot include this file
26 #endif
27
28 #ifndef _VLC_ES_H
29 #define _VLC_ES_H 1
30
31 /* FIXME: i'm not too sure about this include but it fixes compilation of
32  * video chromas -- dionoea */
33 #include "vlc_common.h"
34
35 /**
36  * \file
37  * This file defines the elementary streams format types
38  */
39
40 /**
41  * video palette data
42  * \see video_format_t
43  * \see subs_format_t
44  */
45 struct video_palette_t
46 {
47     int i_entries;      /**< to keep the compatibility with ffmpeg's palette */
48     uint8_t palette[256][4];                   /**< 4-byte RGBA/YUVA palette */
49 };
50
51 /**
52  * audio replay gain description
53  */
54 #define AUDIO_REPLAY_GAIN_MAX (2)
55 #define AUDIO_REPLAY_GAIN_TRACK (0)
56 #define AUDIO_REPLAY_GAIN_ALBUM (1)
57 typedef struct
58 {
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];
63
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;
69
70 /**
71  * audio format description
72  */
73 struct audio_format_t
74 {
75     vlc_fourcc_t i_format;                          /**< audio format fourcc */
76     unsigned int i_rate;                              /**< audio sample-rate */
77
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;
81
82     /* Describes from which original channels, before downmixing, the
83      * buffer is derived. */
84     uint32_t     i_original_channels;
85
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;
89
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
96      */
97
98     /* FIXME ? (used by the codecs) */
99     unsigned     i_bitspersample;
100     unsigned     i_blockalign;
101     uint8_t      i_channels; /* must be <=32 */
102     uint8_t      i_flavor;
103 };
104
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')
108 #else
109 #   define AUDIO_FMT_S16_NE VLC_FOURCC('s','1','6','l')
110 #   define AUDIO_FMT_U16_NE VLC_FOURCC('u','1','6','l')
111 #endif
112
113 /**
114  * video format description
115  */
116 struct video_format_t
117 {
118     vlc_fourcc_t i_chroma;                               /**< picture chroma */
119     unsigned int i_aspect;                                 /**< aspect ratio */
120
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 */
127
128     unsigned int i_bits_per_pixel;             /**< number of bits per pixel */
129
130     unsigned int i_sar_num;                   /**< sample/pixel aspect ratio */
131     unsigned int i_sar_den;
132
133     unsigned int i_frame_rate;                     /**< frame rate numerator */
134     unsigned int i_frame_rate_base;              /**< frame rate denominator */
135
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 */
141 };
142
143 /**
144  * subtitles format description
145  */
146 struct subs_format_t
147 {
148     /* the character encoding of the text of the subtitle.
149      * all gettext recognized shorts can be used */
150     char *psz_encoding;
151
152
153     int  i_x_origin; /**< x coordinate of the subtitle. 0 = left */
154     int  i_y_origin; /**< y coordinate of the subtitle. 0 = top */
155
156     struct
157     {
158         /*  */
159         uint32_t palette[16+1];
160
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;
165     } spu;
166
167     struct
168     {
169         int i_id;
170     } dvb;
171 };
172
173 /**
174  * ES definition
175  */
176 typedef struct extra_languages_t
177 {
178         char *psz_language;
179         char *psz_description;
180 } extra_languages_t;
181
182
183 struct es_format_t
184 {
185     int             i_cat;
186     vlc_fourcc_t    i_codec;
187
188     int             i_id;       /* -1: let the core mark the right id
189                                    >=0: valid id */
190     int             i_group;    /* -1 : standalone
191                                    >= 0 then a "group" (program) is created
192                                         for each value */
193     int             i_priority; /*  -2 : mean not selectable by the users
194                                     -1 : mean not selected by default even
195                                         when no other stream
196                                     >=0: priority */
197
198     char            *psz_language;
199     char            *psz_description;
200     int             i_extra_languages;
201     extra_languages_t *p_extra_languages;
202
203     audio_format_t  audio;
204     audio_replay_gain_t audio_replay_gain;
205     video_format_t video;
206     subs_format_t  subs;
207
208     unsigned int   i_bitrate;
209
210     bool     b_packetized; /* wether the data is packetized
211                                     (ie. not truncated) */
212     int     i_extra;
213     void    *p_extra;
214
215 };
216
217 /* ES Categories */
218 #define UNKNOWN_ES      0x00
219 #define VIDEO_ES        0x01
220 #define AUDIO_ES        0x02
221 #define SPU_ES          0x03
222 #define NAV_ES          0x04
223
224 static inline void es_format_Init( es_format_t *fmt,
225                                    int i_cat, vlc_fourcc_t i_codec )
226 {
227     fmt->i_cat                  = i_cat;
228     fmt->i_codec                = i_codec;
229     fmt->i_id                   = -1;
230     fmt->i_group                = 0;
231     fmt->i_priority             = 0;
232     fmt->psz_language           = NULL;
233     fmt->psz_description        = NULL;
234
235     fmt->i_extra_languages      = 0;
236     fmt->p_extra_languages      = NULL;
237
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) );
242
243     fmt->b_packetized           = true;
244     fmt->i_bitrate              = 0;
245     fmt->i_extra                = 0;
246     fmt->p_extra                = NULL;
247 }
248
249 static inline int es_format_Copy( es_format_t *dst, const es_format_t *src )
250 {
251     int i;
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 )
258     {
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 );
262     }
263     else
264     {
265         dst->i_extra = 0;
266         dst->p_extra = NULL;
267     }
268
269     if( src->subs.psz_encoding )
270         dst->subs.psz_encoding = strdup( src->subs.psz_encoding );
271
272     if( src->video.p_palette )
273     {
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 ) );
278     }
279
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 );
287         else
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 );
291         else
292             dst->p_extra_languages[i].psz_description = NULL;
293     }
294     return VLC_SUCCESS;
295 }
296
297 static inline void es_format_Clean( es_format_t *fmt )
298 {
299     free( fmt->psz_language );
300     free( fmt->psz_description );
301
302     if( fmt->i_extra > 0 ) free( fmt->p_extra );
303
304     free( fmt->video.p_palette );
305     free( fmt->subs.psz_encoding );
306
307     if( fmt->i_extra_languages > 0 && fmt->p_extra_languages )
308     {
309         int i;
310         for( i = 0; i < fmt->i_extra_languages; i++ )
311         {
312             free( fmt->p_extra_languages[i].psz_language );
313             free( fmt->p_extra_languages[i].psz_description );
314         }
315         free( fmt->p_extra_languages );
316     }
317
318     /* es_format_Clean can be called multiple times */
319     memset( fmt, 0, sizeof(*fmt) );
320 }
321 #endif