Commit 400b0ea6 authored by mru's avatar mru

move static variables to private context struct


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@7838 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent d33f8f8b
...@@ -36,6 +36,13 @@ ...@@ -36,6 +36,13 @@
#define CONVERT_BIAS 384 #define CONVERT_BIAS 384
#endif #endif
typedef struct DTSContext {
dts_state_t *state;
uint8_t buf[BUFFER_SIZE];
uint8_t *bufptr;
uint8_t *bufpos;
} DTSContext;
static inline int16_t static inline int16_t
convert(int32_t i) convert(int32_t i)
{ {
...@@ -188,18 +195,15 @@ static int ...@@ -188,18 +195,15 @@ 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)
{ {
DTSContext *s = avctx->priv_data;
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 *bufptr = buf;
static uint8_t *bufpos = buf + HEADER_SIZE;
int16_t *out_samples = data; int16_t *out_samples = data;
static int sample_rate; int sample_rate;
static int frame_length; int frame_length;
static int flags; int flags;
int bit_rate; int bit_rate;
int len; int len;
dts_state_t *state = avctx->priv_data;
level_t level; level_t level;
sample_t bias; sample_t bias;
int i; int i;
...@@ -212,25 +216,25 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -212,25 +216,25 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
len = end - start; len = end - start;
if(!len) if(!len)
break; break;
if(len > bufpos - bufptr) if(len > s->bufpos - s->bufptr)
len = bufpos - bufptr; len = s->bufpos - s->bufptr;
memcpy(bufptr, start, len); memcpy(s->bufptr, start, len);
bufptr += len; s->bufptr += len;
start += len; start += len;
if(bufptr != bufpos) if(s->bufptr != s->bufpos)
return start - buff; return start - buff;
if(bufpos != buf + HEADER_SIZE) if(s->bufpos != s->buf + HEADER_SIZE)
break; break;
length = dts_syncinfo(state, buf, &flags, &sample_rate, &bit_rate, length = dts_syncinfo(s->state, s->buf, &flags, &sample_rate,
&frame_length); &bit_rate, &frame_length);
if(!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(s->bufptr = s->buf; s->bufptr < s->buf + HEADER_SIZE - 1; s->bufptr++)
bufptr[0] = bufptr[1]; s->bufptr[0] = s->bufptr[1];
continue; continue;
} }
bufpos = buf + length; s->bufpos = s->buf + length;
} }
flags = 2; /* ???????????? */ flags = 2; /* ???????????? */
...@@ -238,7 +242,7 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -238,7 +242,7 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
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(s->state, s->buf, &flags, &level, bias)) {
av_log(avctx, AV_LOG_ERROR, "dts_frame() failed\n"); av_log(avctx, AV_LOG_ERROR, "dts_frame() failed\n");
goto end; goto end;
} }
...@@ -247,16 +251,16 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -247,16 +251,16 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
avctx->channels = channels_multi(flags); avctx->channels = channels_multi(flags);
avctx->bit_rate = bit_rate; avctx->bit_rate = bit_rate;
for(i = 0; i < dts_blocks_num(state); i++) { for(i = 0; i < dts_blocks_num(s->state); i++) {
int chans; int chans;
if(dts_block(state)) { if(dts_block(s->state)) {
av_log(avctx, AV_LOG_ERROR, "dts_block() failed\n"); av_log(avctx, AV_LOG_ERROR, "dts_block() failed\n");
goto end; goto end;
} }
chans = channels_multi(flags); chans = channels_multi(flags);
convert2s16_multi(dts_samples(state), out_samples, convert2s16_multi(dts_samples(s->state), out_samples,
flags & (DTS_CHANNEL_MASK | DTS_LFE)); flags & (DTS_CHANNEL_MASK | DTS_LFE));
out_samples += 256 * chans; out_samples += 256 * chans;
...@@ -264,24 +268,29 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -264,24 +268,29 @@ dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
} }
end: end:
bufptr = buf; s->bufptr = s->buf;
bufpos = buf + HEADER_SIZE; s->bufpos = s->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); DTSContext *s = avctx->priv_data;
if(avctx->priv_data == NULL) s->bufptr = s->buf;
s->bufpos = s->buf + HEADER_SIZE;
s->state = dts_init(0);
if(s->state == NULL)
return -1; return -1;
return 0; return 0;
} }
static int static int
dts_decode_end(AVCodecContext * s) dts_decode_end(AVCodecContext * avctx)
{ {
DTSContext *s = avctx->priv_data;
dts_free(s->state);
return 0; return 0;
} }
...@@ -289,7 +298,7 @@ AVCodec dts_decoder = { ...@@ -289,7 +298,7 @@ AVCodec dts_decoder = {
"dts", "dts",
CODEC_TYPE_AUDIO, CODEC_TYPE_AUDIO,
CODEC_ID_DTS, CODEC_ID_DTS,
sizeof(dts_state_t *), sizeof(DTSContext),
dts_decode_init, dts_decode_init,
NULL, NULL,
dts_decode_end, dts_decode_end,
......
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