* Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avformat.h"
+#include "internal.h"
#define AUD_HEADER_SIZE 12
#define AUD_CHUNK_PREAMBLE_SIZE 8
AVFormatParameters *ap)
{
WsAudDemuxContext *wsaud = s->priv_data;
- ByteIOContext *pb = s->pb;
+ AVIOContext *pb = s->pb;
AVStream *st;
unsigned char header[AUD_HEADER_SIZE];
- if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
+ if (avio_read(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
return AVERROR(EIO);
wsaud->audio_samplerate = AV_RL16(&header[0]);
if (header[11] == 99)
wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8;
/* initialize the audio decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
- av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
+ avpriv_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = wsaud->audio_type;
st->codec->codec_tag = 0; /* no tag */
AVPacket *pkt)
{
WsAudDemuxContext *wsaud = s->priv_data;
- ByteIOContext *pb = s->pb;
+ AVIOContext *pb = s->pb;
unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
unsigned int chunk_size;
int ret = 0;
- if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
+ if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
AUD_CHUNK_PREAMBLE_SIZE)
return AVERROR(EIO);
AVFormatParameters *ap)
{
WsVqaDemuxContext *wsvqa = s->priv_data;
- ByteIOContext *pb = s->pb;
+ AVIOContext *pb = s->pb;
AVStream *st;
unsigned char *header;
unsigned char scratch[VQA_PREAMBLE_SIZE];
unsigned int chunk_size;
/* initialize the video decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
- av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
+ avpriv_set_pts_info(st, 33, 1, VQA_FRAMERATE);
wsvqa->video_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_WS_VQA;
st->codec->codec_tag = 0; /* no fourcc */
/* skip to the start of the VQA header */
- url_fseek(pb, 20, SEEK_SET);
+ avio_seek(pb, 20, SEEK_SET);
/* the VQA header needs to go to the decoder */
st->codec->extradata_size = VQA_HEADER_SIZE;
st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
header = (unsigned char *)st->codec->extradata;
- if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
+ if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
VQA_HEADER_SIZE) {
av_free(st->codec->extradata);
return AVERROR(EIO);
/* initialize the audio decoder stream for VQA v1 or nonzero samplerate */
if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
- av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
+ avpriv_set_pts_info(st, 33, 1, VQA_FRAMERATE);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
if (AV_RL16(&header[0]) == 1)
st->codec->codec_id = CODEC_ID_WESTWOOD_SND1;
/* there are 0 or more chunks before the FINF chunk; iterate until
* FINF has been skipped and the file will be ready to be demuxed */
do {
- if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
+ if (avio_read(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
av_free(st->codec->extradata);
return AVERROR(EIO);
}
break;
}
- url_fseek(pb, chunk_size, SEEK_CUR);
+ avio_skip(pb, chunk_size);
} while (chunk_tag != FINF_TAG);
return 0;
AVPacket *pkt)
{
WsVqaDemuxContext *wsvqa = s->priv_data;
- ByteIOContext *pb = s->pb;
+ AVIOContext *pb = s->pb;
int ret = -1;
unsigned char preamble[VQA_PREAMBLE_SIZE];
unsigned int chunk_type;
unsigned int chunk_size;
int skip_byte;
- while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) {
+ while (avio_read(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) {
chunk_type = AV_RB32(&preamble[0]);
chunk_size = AV_RB32(&preamble[4]);
skip_byte = chunk_size & 0x01;
+ if ((chunk_type == SND2_TAG || chunk_type == SND1_TAG) && wsvqa->audio_channels == 0) {
+ av_log(s, AV_LOG_ERROR, "audio chunk without any audio header information found\n");
+ return AVERROR_INVALIDDATA;
+ }
+
if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) {
if (av_new_packet(pkt, chunk_size))
return AVERROR(EIO);
- ret = get_buffer(pb, pkt->data, chunk_size);
+ ret = avio_read(pb, pkt->data, chunk_size);
if (ret != chunk_size) {
av_free_packet(pkt);
return AVERROR(EIO);
}
/* stay on 16-bit alignment */
if (skip_byte)
- url_fseek(pb, 1, SEEK_CUR);
+ avio_skip(pb, 1);
return ret;
} else {
default:
av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type);
}
- url_fseek(pb, chunk_size + skip_byte, SEEK_CUR);
+ avio_skip(pb, chunk_size + skip_byte);
}
}
#if CONFIG_WSAUD_DEMUXER
AVInputFormat ff_wsaud_demuxer = {
- "wsaud",
- NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
- sizeof(WsAudDemuxContext),
- wsaud_probe,
- wsaud_read_header,
- wsaud_read_packet,
+ .name = "wsaud",
+ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
+ .priv_data_size = sizeof(WsAudDemuxContext),
+ .read_probe = wsaud_probe,
+ .read_header = wsaud_read_header,
+ .read_packet = wsaud_read_packet,
};
#endif
#if CONFIG_WSVQA_DEMUXER
AVInputFormat ff_wsvqa_demuxer = {
- "wsvqa",
- NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
- sizeof(WsVqaDemuxContext),
- wsvqa_probe,
- wsvqa_read_header,
- wsvqa_read_packet,
+ .name = "wsvqa",
+ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
+ .priv_data_size = sizeof(WsVqaDemuxContext),
+ .read_probe = wsvqa_probe,
+ .read_header = wsvqa_read_header,
+ .read_packet = wsvqa_read_packet,
};
#endif