* VQF demuxer
* Copyright (c) 2009 Vitor Sessak
*
- * 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 "avformat.h"
+#include "internal.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/dict.h"
+#include "libavutil/mathematics.h"
typedef struct VqfContext {
int frame_bit_len;
buf = av_malloc(len+1);
if (!buf)
return;
- get_buffer(s->pb, buf, len);
+ avio_read(s->pb, buf, len);
buf[len] = 0;
- av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL);
+ av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL);
}
static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
VqfContext *c = s->priv_data;
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
int chunk_tag;
int rate_flag = -1;
int header_size;
int read_bitrate = 0;
int size;
+ uint8_t comm_chunk[12];
if (!st)
return AVERROR(ENOMEM);
- url_fskip(s->pb, 12);
+ avio_skip(s->pb, 12);
- header_size = get_be32(s->pb);
+ header_size = avio_rb32(s->pb);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_TWINVQ;
do {
int len;
- chunk_tag = get_le32(s->pb);
+ chunk_tag = avio_rl32(s->pb);
if (chunk_tag == MKTAG('D','A','T','A'))
break;
- len = get_be32(s->pb);
+ len = avio_rb32(s->pb);
if ((unsigned) len > INT_MAX/2) {
av_log(s, AV_LOG_ERROR, "Malformed header\n");
switch(chunk_tag){
case MKTAG('C','O','M','M'):
- st->codec->channels = get_be32(s->pb) + 1;
- read_bitrate = get_be32(s->pb);
- rate_flag = get_be32(s->pb);
- url_fskip(s->pb, len-12);
+ avio_read(s->pb, comm_chunk, 12);
+ st->codec->channels = AV_RB32(comm_chunk ) + 1;
+ read_bitrate = AV_RB32(comm_chunk + 4);
+ rate_flag = AV_RB32(comm_chunk + 8);
+ avio_skip(s->pb, len-12);
st->codec->bit_rate = read_bitrate*1000;
- st->codec->bits_per_coded_sample = 16;
break;
case MKTAG('N','A','M','E'):
add_metadata(s, "title" , len, header_size);
av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n",
((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1],
((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]);
- url_fskip(s->pb, FFMIN(len, header_size));
+ avio_skip(s->pb, FFMIN(len, header_size));
break;
}
return -1;
}
c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate;
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ /* put first 12 bytes of COMM chunk in extradata */
+ if (!(st->codec->extradata = av_malloc(12 + FF_INPUT_BUFFER_PADDING_SIZE)))
+ return AVERROR(ENOMEM);
+ st->codec->extradata_size = 12;
+ memcpy(st->codec->extradata, comm_chunk, 12);
return 0;
}
int ret;
int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
- pkt->pos = url_ftell(s->pb);
+ pkt->pos = avio_tell(s->pb);
pkt->stream_index = 0;
if (av_new_packet(pkt, size+2) < 0)
pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
pkt->data[1] = c->last_frame_bits;
- ret = get_buffer(s->pb, pkt->data+2, size);
+ ret = avio_read(s->pb, pkt->data+2, size);
if (ret<=0) {
av_free_packet(pkt);
st->cur_dts = av_rescale(pos, st->time_base.den,
st->codec->bit_rate * (int64_t)st->time_base.num);
- if ((ret = url_fseek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0)
+ if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0)
return ret;
c->remaining_bits = -7 - ((pos-7)&7);
return 0;
}
-AVInputFormat vqf_demuxer = {
- "vqf",
- NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
- sizeof(VqfContext),
- vqf_probe,
- vqf_read_header,
- vqf_read_packet,
- NULL,
- vqf_read_seek,
+AVInputFormat ff_vqf_demuxer = {
+ .name = "vqf",
+ .long_name = NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
+ .priv_data_size = sizeof(VqfContext),
+ .read_probe = vqf_probe,
+ .read_header = vqf_read_header,
+ .read_packet = vqf_read_packet,
+ .read_seek = vqf_read_seek,
.extensions = "vqf",
};