Commit ac49ddc6 authored by Måns Rullgård's avatar Måns Rullgård

cosmetic: indent sensibly so code can be read at all

Originally committed as revision 7835 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent d6ceace3
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
#define CONVERT_BIAS 384 #define CONVERT_BIAS 384
#endif #endif
static inline static inline int16_t
int16_t convert (int32_t i) convert(int32_t i)
{ {
#ifdef LIBDTS_FIXED #ifdef LIBDTS_FIXED
i >>= 15; i >>= 15;
...@@ -56,265 +56,255 @@ int16_t convert (int32_t i) ...@@ -56,265 +56,255 @@ int16_t convert (int32_t i)
} }
static void static void
convert2s16_2 (sample_t * _f, int16_t * s16) convert2s16_2(sample_t * _f, int16_t * s16)
{ {
int i; int i;
int32_t * f = (int32_t *) _f; int32_t *f = (int32_t *) _f;
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[2 * i] = convert(f[i]);
s16[2*i] = convert (f[i]); s16[2 * i + 1] = convert(f[i + 256]);
s16[2*i+1] = convert (f[i+256]);
} }
} }
static void static void
convert2s16_4 (sample_t * _f, int16_t * s16) convert2s16_4(sample_t * _f, int16_t * s16)
{ {
int i; int i;
int32_t * f = (int32_t *) _f; int32_t *f = (int32_t *) _f;
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[4 * i] = convert(f[i]);
s16[4*i] = convert (f[i]); s16[4 * i + 1] = convert(f[i + 256]);
s16[4*i+1] = convert (f[i+256]); s16[4 * i + 2] = convert(f[i + 512]);
s16[4*i+2] = convert (f[i+512]); s16[4 * i + 3] = convert(f[i + 768]);
s16[4*i+3] = convert (f[i+768]);
} }
} }
static void static void
convert2s16_5 (sample_t * _f, int16_t * s16) convert2s16_5(sample_t * _f, int16_t * s16)
{ {
int i; int i;
int32_t * f = (int32_t *) _f; int32_t *f = (int32_t *) _f;
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[5 * i] = convert(f[i]);
s16[5*i] = convert (f[i]); s16[5 * i + 1] = convert(f[i + 256]);
s16[5*i+1] = convert (f[i+256]); s16[5 * i + 2] = convert(f[i + 512]);
s16[5*i+2] = convert (f[i+512]); s16[5 * i + 3] = convert(f[i + 768]);
s16[5*i+3] = convert (f[i+768]); s16[5 * i + 4] = convert(f[i + 1024]);
s16[5*i+4] = convert (f[i+1024]);
} }
} }
static void static void
convert2s16_multi (sample_t * _f, int16_t * s16, int flags) convert2s16_multi(sample_t * _f, int16_t * s16, int flags)
{ {
int i; int i;
int32_t * f = (int32_t *) _f; int32_t *f = (int32_t *) _f;
switch (flags) switch (flags) {
{
case DTS_MONO: case DTS_MONO:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[5 * i] = s16[5 * i + 1] = s16[5 * i + 2] = s16[5 * i + 3] =
s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; 0;
s16[5*i+4] = convert (f[i]); s16[5 * i + 4] = convert(f[i]);
} }
break; break;
case DTS_CHANNEL: case DTS_CHANNEL:
case DTS_STEREO: case DTS_STEREO:
case DTS_DOLBY: case DTS_DOLBY:
convert2s16_2 (_f, s16); convert2s16_2(_f, s16);
break; break;
case DTS_3F: case DTS_3F:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[5 * i] = convert(f[i]);
s16[5*i] = convert (f[i]); s16[5 * i + 1] = convert(f[i + 512]);
s16[5*i+1] = convert (f[i+512]); s16[5 * i + 2] = s16[5 * i + 3] = 0;
s16[5*i+2] = s16[5*i+3] = 0; s16[5 * i + 4] = convert(f[i + 256]);
s16[5*i+4] = convert (f[i+256]);
} }
break; break;
case DTS_2F2R: case DTS_2F2R:
convert2s16_4 (_f, s16); convert2s16_4(_f, s16);
break; break;
case DTS_3F2R: case DTS_3F2R:
convert2s16_5 (_f, s16); convert2s16_5(_f, s16);
break; break;
case DTS_MONO | DTS_LFE: case DTS_MONO | DTS_LFE:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[6 * i] = s16[6 * i + 1] = s16[6 * i + 2] = s16[6 * i + 3] =
s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; 0;
s16[6*i+4] = convert (f[i+256]); s16[6 * i + 4] = convert(f[i + 256]);
s16[6*i+5] = convert (f[i]); s16[6 * i + 5] = convert(f[i]);
} }
break; break;
case DTS_CHANNEL | DTS_LFE: case DTS_CHANNEL | DTS_LFE:
case DTS_STEREO | DTS_LFE: case DTS_STEREO | DTS_LFE:
case DTS_DOLBY | DTS_LFE: case DTS_DOLBY | DTS_LFE:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[6 * i] = convert(f[i + 256]);
s16[6*i] = convert (f[i+256]); s16[6 * i + 1] = convert(f[i + 512]);
s16[6*i+1] = convert (f[i+512]); s16[6 * i + 2] = s16[6 * i + 3] = s16[6 * i + 4] = 0;
s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; s16[6 * i + 5] = convert(f[i]);
s16[6*i+5] = convert (f[i]);
} }
break; break;
case DTS_3F | DTS_LFE: case DTS_3F | DTS_LFE:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[6 * i] = convert(f[i + 256]);
s16[6*i] = convert (f[i+256]); s16[6 * i + 1] = convert(f[i + 768]);
s16[6*i+1] = convert (f[i+768]); s16[6 * i + 2] = s16[6 * i + 3] = 0;
s16[6*i+2] = s16[6*i+3] = 0; s16[6 * i + 4] = convert(f[i + 512]);
s16[6*i+4] = convert (f[i+512]); s16[6 * i + 5] = convert(f[i]);
s16[6*i+5] = convert (f[i]);
} }
break; break;
case DTS_2F2R | DTS_LFE: case DTS_2F2R | DTS_LFE:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[6 * i] = convert(f[i + 256]);
s16[6*i] = convert (f[i+256]); s16[6 * i + 1] = convert(f[i + 512]);
s16[6*i+1] = convert (f[i+512]); s16[6 * i + 2] = convert(f[i + 768]);
s16[6*i+2] = convert (f[i+768]); s16[6 * i + 3] = convert(f[i + 1024]);
s16[6*i+3] = convert (f[i+1024]); s16[6 * i + 4] = 0;
s16[6*i+4] = 0; s16[6 * i + 5] = convert(f[i]);
s16[6*i+5] = convert (f[i]);
} }
break; break;
case DTS_3F2R | DTS_LFE: case DTS_3F2R | DTS_LFE:
for (i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{ s16[6 * i] = convert(f[i + 256]);
s16[6*i] = convert (f[i+256]); s16[6 * i + 1] = convert(f[i + 768]);
s16[6*i+1] = convert (f[i+768]); s16[6 * i + 2] = convert(f[i + 1024]);
s16[6*i+2] = convert (f[i+1024]); s16[6 * i + 3] = convert(f[i + 1280]);
s16[6*i+3] = convert (f[i+1280]); s16[6 * i + 4] = convert(f[i + 512]);
s16[6*i+4] = convert (f[i+512]); s16[6 * i + 5] = convert(f[i]);
s16[6*i+5] = convert (f[i]);
} }
break; break;
} }
} }
static int static int
channels_multi (int flags) channels_multi(int flags)
{ {
if (flags & DTS_LFE) if(flags & DTS_LFE)
return 6; return 6;
else if (flags & 1) /* center channel */ else if(flags & 1) /* center channel */
return 5; return 5;
else if ((flags & DTS_CHANNEL_MASK) == DTS_2F2R) else if((flags & DTS_CHANNEL_MASK) == DTS_2F2R)
return 4; return 4;
else else
return 2; return 2;
} }
static int static int
dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size, dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
uint8_t *buff, int buff_size) uint8_t * buff, int buff_size)
{ {
uint8_t * start = buff; uint8_t *start = buff;
uint8_t * end = buff + buff_size; uint8_t *end = buff + buff_size;
static uint8_t buf[BUFFER_SIZE]; static uint8_t buf[BUFFER_SIZE];
static uint8_t * bufptr = buf; static uint8_t *bufptr = buf;
static uint8_t * bufpos = buf + HEADER_SIZE; static uint8_t *bufpos = buf + HEADER_SIZE;
int16_t *out_samples = data; int16_t *out_samples = data;
static int sample_rate; static int sample_rate;
static int frame_length; static int frame_length;
static int flags; static int flags;
int bit_rate; int bit_rate;
int len; int len;
dts_state_t *state = avctx->priv_data; dts_state_t *state = avctx->priv_data;
*data_size = 0; *data_size = 0;
while (1) while(1) {
{ len = end - start;
len = end - start; if(!len)
if (!len) break;
break; if(len > bufpos - bufptr)
if (len > bufpos - bufptr) len = bufpos - bufptr;
len = bufpos - bufptr; memcpy(bufptr, start, len);
memcpy (bufptr, start, len); bufptr += len;
bufptr += len; start += len;
start += len; if(bufptr != bufpos)
if (bufptr != bufpos) return start - buff;
return start - buff; if(bufpos != buf + HEADER_SIZE)
if (bufpos != buf + HEADER_SIZE) break;
break;
{ {
int length; int length;
length = dts_syncinfo (state, buf, &flags, &sample_rate, length =
&bit_rate, &frame_length); dts_syncinfo(state, buf, &flags, &sample_rate, &bit_rate,
if (!length) &frame_length);
{ if(!length) {
av_log (NULL, AV_LOG_INFO, "skip\n"); av_log(NULL, AV_LOG_INFO, "skip\n");
for (bufptr = buf; bufptr < buf + HEADER_SIZE-1; bufptr++) for(bufptr = buf; bufptr < buf + HEADER_SIZE - 1; bufptr++)
bufptr[0] = bufptr[1]; bufptr[0] = bufptr[1];
continue; continue;
}
bufpos = buf + length;
} }
bufpos = buf + length;
}
} }
{ {
level_t level; level_t level;
sample_t bias; sample_t bias;
int i; int i;
flags = 2; /* ???????????? */ flags = 2; /* ???????????? */
level = CONVERT_LEVEL; level = CONVERT_LEVEL;
bias = CONVERT_BIAS; bias = CONVERT_BIAS;
flags |= DTS_ADJUST_LEVEL; flags |= DTS_ADJUST_LEVEL;
if (dts_frame (state, buf, &flags, &level, bias)) if(dts_frame(state, buf, &flags, &level, bias))
goto error;
avctx->sample_rate = sample_rate;
avctx->channels = channels_multi(flags);
avctx->bit_rate = bit_rate;
for(i = 0; i < dts_blocks_num(state); i++) {
if(dts_block(state))
goto error; goto error;
avctx->sample_rate = sample_rate; {
avctx->channels = channels_multi (flags); int chans;
avctx->bit_rate = bit_rate;
for (i = 0; i < dts_blocks_num (state); i++) chans = channels_multi(flags);
{ convert2s16_multi(dts_samples(state), out_samples,
if (dts_block (state)) flags & (DTS_CHANNEL_MASK | DTS_LFE));
goto error;
{
int chans;
chans = channels_multi (flags);
convert2s16_multi (dts_samples (state), out_samples,
flags & (DTS_CHANNEL_MASK | DTS_LFE));
out_samples += 256 * chans; out_samples += 256 * chans;
*data_size += 256 * sizeof (int16_t) * chans; *data_size += 256 * sizeof(int16_t) * chans;
}
}
bufptr = buf;
bufpos = buf + HEADER_SIZE;
return start-buff;
error:
av_log (NULL, AV_LOG_ERROR, "error\n");
bufptr = buf;
bufpos = buf + HEADER_SIZE;
} }
}
bufptr = buf;
bufpos = buf + HEADER_SIZE;
return start - buff;
error:
av_log(NULL, AV_LOG_ERROR, "error\n");
bufptr = buf;
bufpos = buf + HEADER_SIZE;
}
return start-buff; return start - buff;
} }
static int static int
dts_decode_init (AVCodecContext *avctx) dts_decode_init(AVCodecContext * avctx)
{ {
avctx->priv_data = dts_init (0); avctx->priv_data = dts_init(0);
if (avctx->priv_data == NULL) if(avctx->priv_data == NULL)
return -1; return -1;
return 0; return 0;
} }
static int static int
dts_decode_end (AVCodecContext *s) dts_decode_end(AVCodecContext * s)
{ {
return 0; return 0;
} }
AVCodec dts_decoder = { AVCodec dts_decoder = {
"dts", "dts",
CODEC_TYPE_AUDIO, CODEC_TYPE_AUDIO,
CODEC_ID_DTS, CODEC_ID_DTS,
sizeof (dts_state_t *), sizeof(dts_state_t *),
dts_decode_init, dts_decode_init,
NULL, NULL,
dts_decode_end, dts_decode_end,
dts_decode_frame, dts_decode_frame,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment