[FFmpeg-devel] [PATCH 2/2] avidec: simplify read_gab2_sub
Anton Khirnov
anton
Sun Feb 6 11:07:06 CET 2011
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.
---
libavformat/avidec.c | 38 ++++++++++++++++----------------------
1 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 0e399b5..9d5ffe5 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"
@@ -749,39 +748,32 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
static const uint8_t gab2_header[] = {'G', 'A', 'B', '2', 0, 2, 0};
if (!memcmp(pkt->data, gab2_header, sizeof(gab2_header))) {
- uint8_t desc[256], *d = desc;
- uint8_t *end, *ptr = pkt->data + sizeof(gab2_header);
- 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 + sizeof(gab2_header),
+ pkt->size - sizeof(gab2_header),
+ 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;
@@ -792,6 +784,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;
}
--
1.7.2.3
More information about the ffmpeg-devel
mailing list