]> git.sesse.net Git - vlc/blob - include/vlc_es.h
* viedo_format_t -> video_format_t
[vlc] / include / vlc_es.h
1 /*****************************************************************************
2  * vlc_es.h: Elementary stream formats descriptions
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_ES_H
25 #define _VLC_ES_H 1
26
27 /**
28  * \file
29  * This file defines the elementary streams format types
30  */
31
32 /**
33  * video palette data
34  * \see video_format_t
35  * \see subs_format_t
36  */
37 struct video_palette_t
38 {
39     int i_dummy;        /**< to keep the compatibility with ffmpeg's palette */
40     uint8_t palette[256][4];                   /**< 4-byte RGBA/YUVA palette */
41 };
42
43 /**
44  * audio format description
45  */
46 struct audio_format_t
47 {
48     vlc_fourcc_t i_format;                          /**< audio format fourcc */
49     unsigned int i_rate;                              /**< audio sample-rate */
50
51     /* Describes the channels configuration of the samples (ie. number of
52      * channels which are available in the buffer, and positions). */
53     uint32_t     i_physical_channels;
54
55     /* Describes from which original channels, before downmixing, the
56      * buffer is derived. */
57     uint32_t     i_original_channels;
58
59     /* Optional - for A/52, SPDIF and DTS types : */
60     /* Bytes used by one compressed frame, depends on bitrate. */
61     unsigned int i_bytes_per_frame;
62
63     /* Number of sampleframes contained in one compressed frame. */
64     unsigned int        i_frame_length;
65     /* Please note that it may be completely arbitrary - buffers are not
66      * obliged to contain a integral number of so-called "frames". It's
67      * just here for the division :
68      * buffer_size = i_nb_samples * i_bytes_per_frame / i_frame_length
69      */
70
71     /* FIXME ? (used by the codecs) */
72     int i_channels;
73     int i_blockalign;
74     int i_bitspersample;
75 };
76
77 /**
78  * video format description
79  */
80 struct video_format_t
81 {
82     vlc_fourcc_t i_chroma;                               /**< picture chroma */
83     unsigned int i_aspect;                                 /**< aspect ratio */
84
85     unsigned int i_width;                                 /**< picture width */
86     unsigned int i_height;                               /**< picture height */
87     unsigned int i_x_offset;               /**< start offset of visible area */
88     unsigned int i_y_offset;               /**< start offset of visible area */
89     unsigned int i_visible_width;                 /**< width of visible area */
90     unsigned int i_visible_height;               /**< height of visible area */
91
92     unsigned int i_bits_per_pixel;             /**< number of bits per pixel */
93
94     unsigned int i_frame_rate;                     /**< frame rate numerator */
95     unsigned int i_frame_rate_base;              /**< frame rate denominator */
96
97     int i_rmask, i_rgmask, i_bmask;          /**< color masks for RGB chroma */
98     video_palette_t *p_palette;              /**< video palette from demuxer */
99 };
100
101 /**
102  * subtitles format description
103  */
104 struct subs_format_t
105 {
106     char *psz_encoding;
107
108     struct
109     {
110         /* FIXME */
111         uint32_t palette[16+1];
112     } spu;
113
114     struct
115     {
116         int i_id;
117     } dvb;
118 };
119
120 /**
121  * ES definition
122  */
123 struct es_format_t
124 {
125     int             i_cat;
126     vlc_fourcc_t    i_codec;
127
128     int             i_id;       /* -1: let the core mark the right id
129                                    >=0: valid id */
130     int             i_group;    /* -1 : standalone
131                                    >= 0 then a "group" (program) is created
132                                         for each value */
133     int             i_priority; /*  -2 : mean not selectable by the users
134                                     -1 : mean not selected by default even
135                                         when no other stream
136                                     >=0: priority */
137     char            *psz_language;
138     char            *psz_description;
139
140     audio_format_t audio;
141     video_format_t video;
142     subs_format_t  subs;
143
144     int            i_bitrate;
145
146     vlc_bool_t     b_packetized; /* wether the data is packetized
147                                     (ie. not truncated) */
148     int     i_extra;
149     void    *p_extra;
150
151 };
152
153 /* ES Categories */
154 #define UNKNOWN_ES      0x00
155 #define VIDEO_ES        0x01
156 #define AUDIO_ES        0x02
157 #define SPU_ES          0x03
158 #define NAV_ES          0x04
159
160 static inline void es_format_Init( es_format_t *fmt,
161                                    int i_cat, vlc_fourcc_t i_codec )
162 {
163     fmt->i_cat                  = i_cat;
164     fmt->i_codec                = i_codec;
165     fmt->i_id                   = -1;
166     fmt->i_group                = 0;
167     fmt->i_priority             = 0;
168     fmt->psz_language           = NULL;
169     fmt->psz_description        = NULL;
170
171     memset( &fmt->audio, 0, sizeof(audio_format_t) );
172     memset( &fmt->video, 0, sizeof(video_format_t) );
173     memset( &fmt->subs, 0, sizeof(subs_format_t) );
174
175     fmt->b_packetized           = VLC_TRUE;
176     fmt->i_bitrate              = 0;
177     fmt->i_extra                = 0;
178     fmt->p_extra                = NULL;
179 }
180
181 static inline void es_format_Copy( es_format_t *dst, es_format_t *src )
182 {
183     memcpy( dst, src, sizeof( es_format_t ) );
184     if( src->psz_language )
185          dst->psz_language = strdup( src->psz_language );
186     if( src->psz_description )
187         dst->psz_description = strdup( src->psz_description );
188     if( src->i_extra > 0 )
189     {
190         dst->i_extra = src->i_extra;
191         dst->p_extra = malloc( src->i_extra );
192         memcpy( dst->p_extra, src->p_extra, src->i_extra );
193     }
194     else
195     {
196         dst->i_extra = 0;
197         dst->p_extra = NULL;
198     }
199
200     if( src->subs.psz_encoding )
201         dst->subs.psz_encoding = strdup( src->subs.psz_encoding );
202
203     if( src->video.p_palette )
204     {
205         dst->video.p_palette = (video_palette_t*)malloc( sizeof( video_palette_t ) );
206         memcpy( dst->video.p_palette, src->video.p_palette, sizeof( video_palette_t ) );
207     }
208 }
209
210 static inline void es_format_Clean( es_format_t *fmt )
211 {
212     if( fmt->psz_language ) free( fmt->psz_language );
213     fmt->psz_language = NULL;
214
215     if( fmt->psz_description ) free( fmt->psz_description );
216     fmt->psz_description = NULL;
217
218     if( fmt->i_extra > 0 ) free( fmt->p_extra );
219     fmt->i_extra = 0; fmt->p_extra = NULL;
220
221     if( fmt->video.p_palette ) free( fmt->video.p_palette );
222     fmt->video.p_palette = NULL;
223
224     if( fmt->subs.psz_encoding ) free( fmt->subs.psz_encoding );
225     fmt->subs.psz_encoding = NULL;
226 }
227
228 #endif