1
/*****************************************************************************
2
* es_format.c : es_format_t helpers.
3
*****************************************************************************
4
* Copyright (C) 2008 the VideoLAN team
7
* Author: Laurent Aimar <fenrir@videolan.org>
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
/*****************************************************************************
26
*****************************************************************************/
32
#include <vlc_common.h>
36
/*****************************************************************************
37
* BinaryLog: computes the base 2 log of a binary value
38
*****************************************************************************
39
* This functions is used by MaskToShift, to get a bit index from a binary
41
*****************************************************************************/
42
static int BinaryLog( uint32_t i )
46
if( i == 0 ) return -31337;
48
if( i & 0xffff0000 ) i_log += 16;
49
if( i & 0xff00ff00 ) i_log += 8;
50
if( i & 0xf0f0f0f0 ) i_log += 4;
51
if( i & 0xcccccccc ) i_log += 2;
52
if( i & 0xaaaaaaaa ) i_log += 1;
58
* It transforms a color mask into right and left shifts
59
* FIXME copied from video_output.c
61
static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
63
uint32_t i_low, i_high; /* lower hand higher bits of the mask */
67
*pi_left = *pi_right = 0;
72
i_low = i_high = i_mask;
74
i_low &= - (int32_t)i_low; /* lower bit of the mask */
75
i_high += i_low; /* higher bit of the mask */
77
/* Transform bits into an index. Also deal with i_high overflow, which
78
* is faster than changing the BinaryLog code to handle 64 bit integers. */
79
i_low = BinaryLog (i_low);
80
i_high = i_high ? BinaryLog (i_high) : 32;
82
/* Update pointers and return */
84
*pi_right = (8 - i_high + i_low);
88
void video_format_FixRgb( video_format_t *p_fmt )
90
/* FIXME find right default mask */
91
if( !p_fmt->i_rmask || !p_fmt->i_gmask || !p_fmt->i_bmask )
93
switch( p_fmt->i_chroma )
95
case VLC_FOURCC('R','V','1','5'):
96
p_fmt->i_rmask = 0x7c00;
97
p_fmt->i_gmask = 0x03e0;
98
p_fmt->i_bmask = 0x001f;
101
case VLC_FOURCC('R','V','1','6'):
102
p_fmt->i_rmask = 0xf800;
103
p_fmt->i_gmask = 0x07e0;
104
p_fmt->i_bmask = 0x001f;
107
case VLC_FOURCC('R','V','2','4'):
108
p_fmt->i_rmask = 0xff0000;
109
p_fmt->i_gmask = 0x00ff00;
110
p_fmt->i_bmask = 0x0000ff;
112
case VLC_FOURCC('R','V','3','2'):
113
p_fmt->i_rmask = 0x00ff0000;
114
p_fmt->i_gmask = 0x0000ff00;
115
p_fmt->i_bmask = 0x000000ff;
123
MaskToShift( &p_fmt->i_lrshift, &p_fmt->i_rrshift,
125
MaskToShift( &p_fmt->i_lgshift, &p_fmt->i_rgshift,
127
MaskToShift( &p_fmt->i_lbshift, &p_fmt->i_rbshift,
131
void es_format_Init( es_format_t *fmt,
132
int i_cat, vlc_fourcc_t i_codec )
135
fmt->i_codec = i_codec;
139
fmt->psz_language = NULL;
140
fmt->psz_description = NULL;
142
fmt->i_extra_languages = 0;
143
fmt->p_extra_languages = NULL;
145
memset( &fmt->audio, 0, sizeof(audio_format_t) );
146
memset( &fmt->audio_replay_gain, 0, sizeof(audio_replay_gain_t) );
147
memset( &fmt->video, 0, sizeof(video_format_t) );
148
memset( &fmt->subs, 0, sizeof(subs_format_t) );
150
fmt->b_packetized = true;
156
int es_format_Copy( es_format_t *dst, const es_format_t *src )
159
memcpy( dst, src, sizeof( es_format_t ) );
160
if( src->psz_language )
161
dst->psz_language = strdup( src->psz_language );
162
if( src->psz_description )
163
dst->psz_description = strdup( src->psz_description );
164
if( src->i_extra > 0 )
166
dst->i_extra = src->i_extra;
167
dst->p_extra = malloc( src->i_extra );
168
memcpy( dst->p_extra, src->p_extra, src->i_extra );
176
if( src->subs.psz_encoding )
177
dst->subs.psz_encoding = strdup( src->subs.psz_encoding );
179
if( src->video.p_palette )
181
dst->video.p_palette =
182
(video_palette_t*)malloc( sizeof( video_palette_t ) );
183
memcpy( dst->video.p_palette, src->video.p_palette,
184
sizeof( video_palette_t ) );
187
dst->i_extra_languages = src->i_extra_languages;
188
if( dst->i_extra_languages )
189
dst->p_extra_languages = (extra_languages_t*)
190
malloc(dst->i_extra_languages * sizeof(*dst->p_extra_languages ));
191
for( i = 0; i < dst->i_extra_languages; i++ ) {
192
if( src->p_extra_languages[i].psz_language )
193
dst->p_extra_languages[i].psz_language = strdup( src->p_extra_languages[i].psz_language );
195
dst->p_extra_languages[i].psz_language = NULL;
196
if( src->p_extra_languages[i].psz_description )
197
dst->p_extra_languages[i].psz_description = strdup( src->p_extra_languages[i].psz_description );
199
dst->p_extra_languages[i].psz_description = NULL;
204
void es_format_Clean( es_format_t *fmt )
206
free( fmt->psz_language );
207
free( fmt->psz_description );
209
if( fmt->i_extra > 0 ) free( fmt->p_extra );
211
free( fmt->video.p_palette );
212
free( fmt->subs.psz_encoding );
214
if( fmt->i_extra_languages > 0 && fmt->p_extra_languages )
217
for( i = 0; i < fmt->i_extra_languages; i++ )
219
free( fmt->p_extra_languages[i].psz_language );
220
free( fmt->p_extra_languages[i].psz_description );
222
free( fmt->p_extra_languages );
225
/* es_format_Clean can be called multiple times */
226
memset( fmt, 0, sizeof(*fmt) );