mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/vag: fix demuxing stereo files
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
c38a6077ee
commit
c37d2cd01c
|
@ -23,10 +23,6 @@
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
typedef struct VAGDemuxContext {
|
|
||||||
int64_t data_end;
|
|
||||||
} VAGDemuxContext;
|
|
||||||
|
|
||||||
static int vag_probe(AVProbeData *p)
|
static int vag_probe(AVProbeData *p)
|
||||||
{
|
{
|
||||||
if (memcmp(p->buf, "VAGp\0\0\0", 7))
|
if (memcmp(p->buf, "VAGp\0\0\0", 7))
|
||||||
|
@ -37,8 +33,8 @@ static int vag_probe(AVProbeData *p)
|
||||||
|
|
||||||
static int vag_read_header(AVFormatContext *s)
|
static int vag_read_header(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
VAGDemuxContext *c = s->priv_data;
|
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
|
int64_t pos;
|
||||||
|
|
||||||
st = avformat_new_stream(s, NULL);
|
st = avformat_new_stream(s, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
|
@ -49,13 +45,24 @@ static int vag_read_header(AVFormatContext *s)
|
||||||
st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX;
|
st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX;
|
||||||
st->codec->channels = 1 + (avio_rb32(s->pb) == 0x00000004);
|
st->codec->channels = 1 + (avio_rb32(s->pb) == 0x00000004);
|
||||||
avio_skip(s->pb, 4);
|
avio_skip(s->pb, 4);
|
||||||
c->data_end = avio_rb32(s->pb);
|
if (st->codec->channels > 1) {
|
||||||
st->duration = (c->data_end - avio_tell(s->pb)) / (16 * st->codec->channels) * 28;
|
st->duration = avio_rb32(s->pb);
|
||||||
|
} else {
|
||||||
|
st->duration = avio_rb32(s->pb) / 16 * 28;
|
||||||
|
}
|
||||||
st->codec->sample_rate = avio_rb32(s->pb);
|
st->codec->sample_rate = avio_rb32(s->pb);
|
||||||
if (st->codec->sample_rate <= 0)
|
if (st->codec->sample_rate <= 0)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
st->codec->block_align = 16 * st->codec->channels;
|
pos = avio_tell(s->pb);
|
||||||
avio_skip(s->pb, 28);
|
avio_seek(s->pb, 0x1000, SEEK_SET);
|
||||||
|
if (avio_rl32(s->pb) == MKTAG('V','A','G','p')) {
|
||||||
|
st->codec->block_align = 0x1000 * st->codec->channels;
|
||||||
|
avio_seek(s->pb, 0, SEEK_SET);
|
||||||
|
st->duration = st->duration / 16 * 28;
|
||||||
|
} else {
|
||||||
|
st->codec->block_align = 16 * st->codec->channels;
|
||||||
|
avio_seek(s->pb, st->codec->channels > 1 ? 0x80 : 0x30, SEEK_SET);
|
||||||
|
}
|
||||||
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
|
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -63,21 +70,14 @@ static int vag_read_header(AVFormatContext *s)
|
||||||
|
|
||||||
static int vag_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int vag_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
VAGDemuxContext *c = s->priv_data;
|
|
||||||
AVCodecContext *codec = s->streams[0]->codec;
|
AVCodecContext *codec = s->streams[0]->codec;
|
||||||
int size;
|
|
||||||
|
|
||||||
size = FFMIN(c->data_end - avio_tell(s->pb), codec->block_align);
|
return av_get_packet(s->pb, pkt, codec->block_align);
|
||||||
if (size <= 0)
|
|
||||||
return AVERROR_EOF;
|
|
||||||
|
|
||||||
return av_get_packet(s->pb, pkt, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AVInputFormat ff_vag_demuxer = {
|
AVInputFormat ff_vag_demuxer = {
|
||||||
.name = "vag",
|
.name = "vag",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Sony VAG"),
|
.long_name = NULL_IF_CONFIG_SMALL("Sony VAG"),
|
||||||
.priv_data_size = sizeof(VAGDemuxContext),
|
|
||||||
.read_probe = vag_probe,
|
.read_probe = vag_probe,
|
||||||
.read_header = vag_read_header,
|
.read_header = vag_read_header,
|
||||||
.read_packet = vag_read_packet,
|
.read_packet = vag_read_packet,
|
||||||
|
|
Loading…
Reference in New Issue