mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-23 19:37:42 +00:00
shorten: split reading of file header into a separate functions
This commit is contained in:
parent
9ef6c7977f
commit
a1f7885a8b
@ -273,44 +273,9 @@ static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_siz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int read_header(ShortenContext *s)
|
||||||
static int shorten_decode_frame(AVCodecContext *avctx,
|
|
||||||
void *data, int *data_size,
|
|
||||||
AVPacket *avpkt)
|
|
||||||
{
|
|
||||||
const uint8_t *buf = avpkt->data;
|
|
||||||
int buf_size = avpkt->size;
|
|
||||||
ShortenContext *s = avctx->priv_data;
|
|
||||||
int i, input_buf_size = 0;
|
|
||||||
int16_t *samples = data;
|
|
||||||
if(s->max_framesize == 0){
|
|
||||||
s->max_framesize= 1024; // should hopefully be enough for the first header
|
|
||||||
s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(1 && s->max_framesize){//FIXME truncated
|
|
||||||
buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
|
|
||||||
input_buf_size= buf_size;
|
|
||||||
|
|
||||||
if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
|
|
||||||
// printf("memmove\n");
|
|
||||||
memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
|
|
||||||
s->bitstream_index=0;
|
|
||||||
}
|
|
||||||
memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
|
|
||||||
buf= &s->bitstream[s->bitstream_index];
|
|
||||||
buf_size += s->bitstream_size;
|
|
||||||
s->bitstream_size= buf_size;
|
|
||||||
|
|
||||||
if(buf_size < s->max_framesize){
|
|
||||||
*data_size = 0;
|
|
||||||
return input_buf_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init_get_bits(&s->gb, buf, buf_size*8);
|
|
||||||
skip_bits(&s->gb, s->bitindex);
|
|
||||||
if (!s->blocksize)
|
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
int maxnlpc = 0;
|
int maxnlpc = 0;
|
||||||
/* shorten signature */
|
/* shorten signature */
|
||||||
if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
|
if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
|
||||||
@ -367,11 +332,55 @@ static int shorten_decode_frame(AVCodecContext *avctx,
|
|||||||
for (i=0; i<s->header_size; i++)
|
for (i=0; i<s->header_size; i++)
|
||||||
s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
|
s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
|
||||||
|
|
||||||
if (decode_wave_header(avctx, s->header, s->header_size) < 0)
|
if (decode_wave_header(s->avctx, s->header, s->header_size) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
s->cur_chan = 0;
|
s->cur_chan = 0;
|
||||||
s->bitshift = 0;
|
s->bitshift = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int shorten_decode_frame(AVCodecContext *avctx,
|
||||||
|
void *data, int *data_size,
|
||||||
|
AVPacket *avpkt)
|
||||||
|
{
|
||||||
|
const uint8_t *buf = avpkt->data;
|
||||||
|
int buf_size = avpkt->size;
|
||||||
|
ShortenContext *s = avctx->priv_data;
|
||||||
|
int i, input_buf_size = 0;
|
||||||
|
int16_t *samples = data;
|
||||||
|
if(s->max_framesize == 0){
|
||||||
|
s->max_framesize= 1024; // should hopefully be enough for the first header
|
||||||
|
s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(1 && s->max_framesize){//FIXME truncated
|
||||||
|
buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
|
||||||
|
input_buf_size= buf_size;
|
||||||
|
|
||||||
|
if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
|
||||||
|
// printf("memmove\n");
|
||||||
|
memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
|
||||||
|
s->bitstream_index=0;
|
||||||
|
}
|
||||||
|
memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
|
||||||
|
buf= &s->bitstream[s->bitstream_index];
|
||||||
|
buf_size += s->bitstream_size;
|
||||||
|
s->bitstream_size= buf_size;
|
||||||
|
|
||||||
|
if(buf_size < s->max_framesize){
|
||||||
|
*data_size = 0;
|
||||||
|
return input_buf_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
init_get_bits(&s->gb, buf, buf_size*8);
|
||||||
|
skip_bits(&s->gb, s->bitindex);
|
||||||
|
if (!s->blocksize)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
if ((ret = read_header(s)) < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user