vlc_es.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_es.h: Elementary stream formats descriptions
00003  *****************************************************************************
00004  * Copyright (C) 1999-2001 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_ES_H
00025 #define VLC_ES_H 1
00026 
00027 /* FIXME: i'm not too sure about this include but it fixes compilation of
00028  * video chromas -- dionoea */
00029 #include "vlc_common.h"
00030 
00031 /**
00032  * \file
00033  * This file defines the elementary streams format types
00034  */
00035 
00036 /**
00037  * video palette data
00038  * \see video_format_t
00039  * \see subs_format_t
00040  */
00041 struct video_palette_t
00042 {
00043     int i_entries;      /**< to keep the compatibility with ffmpeg's palette */
00044     uint8_t palette[256][4];                   /**< 4-byte RGBA/YUVA palette */
00045 };
00046 
00047 /**
00048  * audio replay gain description
00049  */
00050 #define AUDIO_REPLAY_GAIN_MAX (2)
00051 #define AUDIO_REPLAY_GAIN_TRACK (0)
00052 #define AUDIO_REPLAY_GAIN_ALBUM (1)
00053 typedef struct
00054 {
00055     /* true if we have the peak value */
00056     bool pb_peak[AUDIO_REPLAY_GAIN_MAX];
00057     /* peak value where 1.0 means full sample value */
00058     float      pf_peak[AUDIO_REPLAY_GAIN_MAX];
00059 
00060     /* true if we have the gain value */
00061     bool pb_gain[AUDIO_REPLAY_GAIN_MAX];
00062     /* gain value in dB */
00063     float      pf_gain[AUDIO_REPLAY_GAIN_MAX];
00064 } audio_replay_gain_t;
00065 
00066 /**
00067  * audio format description
00068  */
00069 struct audio_format_t
00070 {
00071     vlc_fourcc_t i_format;                          /**< audio format fourcc */
00072     unsigned int i_rate;                              /**< audio sample-rate */
00073 
00074     /* Describes the channels configuration of the samples (ie. number of
00075      * channels which are available in the buffer, and positions). */
00076     uint32_t     i_physical_channels;
00077 
00078     /* Describes from which original channels, before downmixing, the
00079      * buffer is derived. */
00080     uint32_t     i_original_channels;
00081 
00082     /* Optional - for A/52, SPDIF and DTS types : */
00083     /* Bytes used by one compressed frame, depends on bitrate. */
00084     unsigned int i_bytes_per_frame;
00085 
00086     /* Number of sampleframes contained in one compressed frame. */
00087     unsigned int i_frame_length;
00088     /* Please note that it may be completely arbitrary - buffers are not
00089      * obliged to contain a integral number of so-called "frames". It's
00090      * just here for the division :
00091      * buffer_size = i_nb_samples * i_bytes_per_frame / i_frame_length
00092      */
00093 
00094     /* FIXME ? (used by the codecs) */
00095     unsigned     i_bitspersample;
00096     unsigned     i_blockalign;
00097     uint8_t      i_channels; /* must be <=32 */
00098     uint8_t      i_flavor;
00099 };
00100 
00101 #ifdef WORDS_BIGENDIAN
00102 #   define AUDIO_FMT_S16_NE VLC_FOURCC('s','1','6','b')
00103 #   define AUDIO_FMT_U16_NE VLC_FOURCC('u','1','6','b')
00104 #else
00105 #   define AUDIO_FMT_S16_NE VLC_FOURCC('s','1','6','l')
00106 #   define AUDIO_FMT_U16_NE VLC_FOURCC('u','1','6','l')
00107 #endif
00108 
00109 /**
00110  * video format description
00111  */
00112 struct video_format_t
00113 {
00114     vlc_fourcc_t i_chroma;                               /**< picture chroma */
00115     unsigned int i_aspect;                                 /**< aspect ratio */
00116 
00117     unsigned int i_width;                                 /**< picture width */
00118     unsigned int i_height;                               /**< picture height */
00119     unsigned int i_x_offset;               /**< start offset of visible area */
00120     unsigned int i_y_offset;               /**< start offset of visible area */
00121     unsigned int i_visible_width;                 /**< width of visible area */
00122     unsigned int i_visible_height;               /**< height of visible area */
00123 
00124     unsigned int i_bits_per_pixel;             /**< number of bits per pixel */
00125 
00126     unsigned int i_sar_num;                   /**< sample/pixel aspect ratio */
00127     unsigned int i_sar_den;
00128 
00129     unsigned int i_frame_rate;                     /**< frame rate numerator */
00130     unsigned int i_frame_rate_base;              /**< frame rate denominator */
00131 
00132     int i_rmask, i_gmask, i_bmask;          /**< color masks for RGB chroma */
00133     int i_rrshift, i_lrshift;
00134     int i_rgshift, i_lgshift;
00135     int i_rbshift, i_lbshift;
00136     video_palette_t *p_palette;              /**< video palette from demuxer */
00137 };
00138 
00139 /**
00140  * subtitles format description
00141  */
00142 struct subs_format_t
00143 {
00144     /* the character encoding of the text of the subtitle.
00145      * all gettext recognized shorts can be used */
00146     char *psz_encoding;
00147 
00148 
00149     int  i_x_origin; /**< x coordinate of the subtitle. 0 = left */
00150     int  i_y_origin; /**< y coordinate of the subtitle. 0 = top */
00151 
00152     struct
00153     {
00154         /*  */
00155         uint32_t palette[16+1];
00156 
00157         /* the width of the original movie the spu was extracted from */
00158         int i_original_frame_width;
00159         /* the height of the original movie the spu was extracted from */
00160         int i_original_frame_height;
00161     } spu;
00162 
00163     struct
00164     {
00165         int i_id;
00166     } dvb;
00167 };
00168 
00169 /**
00170  * ES definition
00171  */
00172 typedef struct extra_languages_t
00173 {
00174         char *psz_language;
00175         char *psz_description;
00176 } extra_languages_t;
00177 
00178 
00179 struct es_format_t
00180 {
00181     int             i_cat;
00182     vlc_fourcc_t    i_codec;
00183 
00184     int             i_id;       /* -1: let the core mark the right id
00185                                    >=0: valid id */
00186     int             i_group;    /* -1 : standalone
00187                                    >= 0 then a "group" (program) is created
00188                                         for each value */
00189     int             i_priority; /*  -2 : mean not selectable by the users
00190                                     -1 : mean not selected by default even
00191                                         when no other stream
00192                                     >=0: priority */
00193 
00194     char            *psz_language;
00195     char            *psz_description;
00196     int             i_extra_languages;
00197     extra_languages_t *p_extra_languages;
00198 
00199     audio_format_t  audio;
00200     audio_replay_gain_t audio_replay_gain;
00201     video_format_t video;
00202     subs_format_t  subs;
00203 
00204     unsigned int   i_bitrate;
00205 
00206     bool     b_packetized; /* wether the data is packetized
00207                                     (ie. not truncated) */
00208     int     i_extra;
00209     void    *p_extra;
00210 
00211 };
00212 
00213 /* ES Categories */
00214 #define UNKNOWN_ES      0x00
00215 #define VIDEO_ES        0x01
00216 #define AUDIO_ES        0x02
00217 #define SPU_ES          0x03
00218 #define NAV_ES          0x04
00219 
00220 static inline void es_format_Init( es_format_t *fmt,
00221                                    int i_cat, vlc_fourcc_t i_codec )
00222 {
00223     fmt->i_cat                  = i_cat;
00224     fmt->i_codec                = i_codec;
00225     fmt->i_id                   = -1;
00226     fmt->i_group                = 0;
00227     fmt->i_priority             = 0;
00228     fmt->psz_language           = NULL;
00229     fmt->psz_description        = NULL;
00230 
00231     fmt->i_extra_languages      = 0;
00232     fmt->p_extra_languages      = NULL;
00233 
00234     memset( &fmt->audio, 0, sizeof(audio_format_t) );
00235     memset( &fmt->audio_replay_gain, 0, sizeof(audio_replay_gain_t) );
00236     memset( &fmt->video, 0, sizeof(video_format_t) );
00237     memset( &fmt->subs, 0, sizeof(subs_format_t) );
00238 
00239     fmt->b_packetized           = true;
00240     fmt->i_bitrate              = 0;
00241     fmt->i_extra                = 0;
00242     fmt->p_extra                = NULL;
00243 }
00244 
00245 static inline int es_format_Copy( es_format_t *dst, const es_format_t *src )
00246 {
00247     int i;
00248     memcpy( dst, src, sizeof( es_format_t ) );
00249     if( src->psz_language )
00250          dst->psz_language = strdup( src->psz_language );
00251     if( src->psz_description )
00252         dst->psz_description = strdup( src->psz_description );
00253     if( src->i_extra > 0 )
00254     {
00255         dst->i_extra = src->i_extra;
00256         dst->p_extra = malloc( src->i_extra );
00257         memcpy( dst->p_extra, src->p_extra, src->i_extra );
00258     }
00259     else
00260     {
00261         dst->i_extra = 0;
00262         dst->p_extra = NULL;
00263     }
00264 
00265     if( src->subs.psz_encoding )
00266         dst->subs.psz_encoding = strdup( src->subs.psz_encoding );
00267 
00268     if( src->video.p_palette )
00269     {
00270         dst->video.p_palette =
00271             (video_palette_t*)malloc( sizeof( video_palette_t ) );
00272         memcpy( dst->video.p_palette, src->video.p_palette,
00273                 sizeof( video_palette_t ) );
00274     }
00275 
00276     dst->i_extra_languages = src->i_extra_languages;
00277     if( dst->i_extra_languages )
00278         dst->p_extra_languages = (extra_languages_t*)
00279             malloc(dst->i_extra_languages * sizeof(*dst->p_extra_languages ));
00280     for( i = 0; i < dst->i_extra_languages; i++ ) {
00281         if( src->p_extra_languages[i].psz_language )
00282             dst->p_extra_languages[i].psz_language = strdup( src->p_extra_languages[i].psz_language );
00283         else
00284             dst->p_extra_languages[i].psz_language = NULL;
00285         if( src->p_extra_languages[i].psz_description )
00286             dst->p_extra_languages[i].psz_description = strdup( src->p_extra_languages[i].psz_description );
00287         else
00288             dst->p_extra_languages[i].psz_description = NULL;
00289     }
00290     return VLC_SUCCESS;
00291 }
00292 
00293 static inline void es_format_Clean( es_format_t *fmt )
00294 {
00295     free( fmt->psz_language );
00296     free( fmt->psz_description );
00297 
00298     if( fmt->i_extra > 0 ) free( fmt->p_extra );
00299 
00300     free( fmt->video.p_palette );
00301     free( fmt->subs.psz_encoding );
00302 
00303     if( fmt->i_extra_languages > 0 && fmt->p_extra_languages )
00304     {
00305         int i;
00306         for( i = 0; i < fmt->i_extra_languages; i++ )
00307         {
00308             free( fmt->p_extra_languages[i].psz_language );
00309             free( fmt->p_extra_languages[i].psz_description );
00310         }
00311         free( fmt->p_extra_languages );
00312     }
00313 
00314     /* es_format_Clean can be called multiple times */
00315     memset( fmt, 0, sizeof(*fmt) );
00316 }
00317 #endif

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1