From f8d33a36170a2495a8e06e040317b144a770540c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 6 Feb 2011 10:59:54 +0100 Subject: [PATCH] avidec: simplify read_gab2_sub Use avio functions instead of bytestream ones (also drops dependency on lavc and removes a bunch of warnings). Drop custom version of avio_get_str16 and use that instead. Tested on mewmew-ssa.avi sample. Signed-off-by: Ronald S. Bultje (cherry picked from commit 47fdf00a77e82a0e30422ed08d5b295e9ae8d506) --- libavformat/avidec.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 27a9d1fbc3..931a17c441 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -25,7 +25,6 @@ #include #include "libavutil/intreadwrite.h" #include "libavutil/bswap.h" -#include "libavcodec/bytestream.h" #include "avformat.h" #include "avi.h" #include "dv.h" @@ -748,39 +747,32 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) static int read_gab2_sub(AVStream *st, AVPacket *pkt) { if (!strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data+5) == 2) { - uint8_t desc[256], *d = desc; - uint8_t *end, *ptr = pkt->data+7; - unsigned int size, desc_len = bytestream_get_le32(&ptr); - int score = AVPROBE_SCORE_MAX / 2; + uint8_t desc[256]; + int score = AVPROBE_SCORE_MAX / 2, ret; AVIStream *ast = st->priv_data; AVInputFormat *sub_demuxer; AVRational time_base; - ByteIOContext *pb; + ByteIOContext *pb = av_alloc_put_byte(pkt->data + 7, + pkt->size - 7, + 0, NULL, NULL, NULL, NULL); AVProbeData pd; + unsigned int desc_len = get_le32(pb); - if (desc_len > FFMAX(pkt->size-17, 0)) - return 0; + if (desc_len > pb->buf_end - pb->buf_ptr) + goto error; - end = ptr + desc_len; - while (ptr < end-1) { - uint8_t tmp; - uint32_t ch; - GET_UTF16(ch, ptr < end-1 ? bytestream_get_le16(&ptr) : 0, break;); - PUT_UTF8(ch, tmp, if(d-desc < sizeof(desc)-1) *d++ = tmp;); - } - *d = 0; + ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc)); + url_fskip(pb, desc_len - ret); if (*desc) av_metadata_set2(&st->metadata, "title", desc, 0); - ptr = end + 2; - size = bytestream_get_le32(&ptr); - size = FFMIN(size, pkt->size+pkt->data-ptr); + get_le16(pb); /* flags? */ + get_le32(pb); /* data size */ - pd = (AVProbeData) { .buf = ptr, .buf_size = size }; + pd = (AVProbeData) { .buf = pb->buf_ptr, .buf_size = pb->buf_end - pb->buf_ptr }; if (!(sub_demuxer = av_probe_input_format2(&pd, 1, &score))) - return 0; + goto error; - pb = av_alloc_put_byte(ptr, size, 0, NULL, NULL, NULL, NULL); if (!av_open_input_stream(&ast->sub_ctx, pb, "", sub_demuxer, NULL)) { av_read_packet(ast->sub_ctx, &ast->sub_pkt); *st->codec = *ast->sub_ctx->streams[0]->codec; @@ -791,6 +783,8 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) { ast->sub_buffer = pkt->data; memset(pkt, 0, sizeof(*pkt)); return 1; +error: + av_freep(&pb); } return 0; } -- 2.11.0