Commit f8d33a36 authored by Anton Khirnov's avatar Anton Khirnov Committed by Michael Niedermayer

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: 's avatarRonald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit 47fdf00a)
parent f8194672
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment