avcodec/tak: remove GetBitContext usage from avpriv_tak_parse_streaminfo()

This prevents potential ABI issues with GetBitContext.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2017-10-22 20:29:53 -03:00
parent 984b882b76
commit 6bd665b7c5
3 changed files with 26 additions and 6 deletions

View File

@ -90,7 +90,7 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
return 0;
}
void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)
{
uint64_t channel_mask = 0;
int frame_type, i;
@ -125,6 +125,19 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
}
int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size)
{
GetBitContext gb;
int ret = init_get_bits8(&gb, buf, size);
if (ret < 0)
return AVERROR_INVALIDDATA;
ff_tak_parse_streaminfo(s, &gb);
return 0;
}
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
TAKStreamInfo *ti, int log_level_offset)
{
@ -144,7 +157,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
}
if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
avpriv_tak_parse_streaminfo(gb, ti);
ff_tak_parse_streaminfo(ti, gb);
if (get_bits(gb, 6))
skip_bits(gb, 25);

View File

@ -143,10 +143,14 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
/**
* Parse the Streaminfo metadata block.
* @param[in] gb pointer to GetBitContext
* @param[out] s storage for parsed information
* @param[in] buf input buffer
* @param[in] size size of input buffer in bytes
* @return non-zero on error, 0 if OK
*/
void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size);
void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb);
/**
* Validate and decode a frame header.

View File

@ -103,7 +103,6 @@ static int tak_read_header(AVFormatContext *s)
}
}
init_get_bits8(&gb, buffer, size - 3);
break;
case TAK_METADATA_MD5: {
uint8_t md5[16];
@ -145,7 +144,9 @@ static int tak_read_header(AVFormatContext *s)
if (type == TAK_METADATA_STREAMINFO) {
TAKStreamInfo ti;
avpriv_tak_parse_streaminfo(&gb, &ti);
ret = avpriv_tak_parse_streaminfo(&ti, buffer, size -3);
if (ret < 0)
return AVERROR_INVALIDDATA;
if (ti.samples > 0)
st->duration = ti.samples;
st->codecpar->bits_per_coded_sample = ti.bps;
@ -161,11 +162,13 @@ static int tak_read_header(AVFormatContext *s)
} else if (type == TAK_METADATA_LAST_FRAME) {
if (size != 11)
return AVERROR_INVALIDDATA;
init_get_bits8(&gb, buffer, size - 3);
tc->mlast_frame = 1;
tc->data_end = get_bits64(&gb, TAK_LAST_FRAME_POS_BITS) +
get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
av_freep(&buffer);
} else if (type == TAK_METADATA_ENCODER) {
init_get_bits8(&gb, buffer, size - 3);
av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",
get_bits_long(&gb, TAK_ENCODER_VERSION_BITS));
av_freep(&buffer);