aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avidec.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-02-06 10:59:54 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-02-09 03:31:17 +0100
commitf8d33a36170a2495a8e06e040317b144a770540c (patch)
tree3697a8edcb17678b9cf954eb833e820e0d52cbf0 /libavformat/avidec.c
parentf81946729e21005fe8d6a63a938e48c09b9b14b4 (diff)
downloadffmpeg-f8d33a36170a2495a8e06e040317b144a770540c.tar.gz
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 <rsbultje@gmail.com> (cherry picked from commit 47fdf00a77e82a0e30422ed08d5b295e9ae8d506)
Diffstat (limited to 'libavformat/avidec.c')
-rw-r--r--libavformat/avidec.c38
1 files 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 <strings.h>
#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;
}