aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-04 02:03:25 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-04 04:26:04 +0100
commit15c6be8c7da7b94b5e131396e9a82ab6fe4a6b64 (patch)
tree84db7f4851faba26561f846b4f112ef64d01b3ad /libavformat
parentf972193a15026a99eb2b08e7913a03f2123663da (diff)
parentb7beabab4b78cc253d06c0a33f15b8ff79866e85 (diff)
downloadffmpeg-15c6be8c7da7b94b5e131396e9a82ab6fe4a6b64.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: tiertexseq: set correct block_align for audio tiertexseq: set audio stream start time to 0 voc/avs: Do not change the sample rate mid-stream. segafilm: use the sample rate as the time base for audio streams ea: fix audio pts psx-str: fix audio pts vqf: set packet duration tta demuxer: set packet duration mpegaudio_parser: do not ignore information from the first parsed frame mpegaudio_parser: be less picky about the start position thp: set audio packet durations avcodec: add a Vorbis parser to get packet duration vorbisdec: read the previous window flag for long windows lavc: free the output packet when encoding failed or produced no output. lavc: preserve avpkt->destruct in ff_alloc_packet(). lavc: clarify the meaning of AVCodecContext.frame_number. mpegts: Pad the packet buffer in handle_packet(). mpegts: Do not call read_sl_header() when no bytes remain in the buffer. Conflicts: libavcodec/mpegaudio_parser.c libavcodec/version.h libavformat/mpegts.c tests/ref/fate/pva-demux Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/electronicarts.c25
-rw-r--r--libavformat/mpegts.c8
-rw-r--r--libavformat/oggparsevorbis.c1
-rw-r--r--libavformat/psxstr.c5
-rw-r--r--libavformat/rtpdec.c3
-rw-r--r--libavformat/segafilm.c11
-rw-r--r--libavformat/thp.c3
-rw-r--r--libavformat/tiertexseq.c3
-rw-r--r--libavformat/tta.c16
-rw-r--r--libavformat/utils.c6
-rw-r--r--libavformat/vocdec.c16
-rw-r--r--libavformat/vqf.c3
12 files changed, 62 insertions, 38 deletions
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 9719c6711a..968682af7e 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -70,7 +70,6 @@ typedef struct EaDemuxContext {
enum CodecID audio_codec;
int audio_stream_index;
- int audio_frame_counter;
int bytes;
int sample_rate;
@@ -472,7 +471,7 @@ static int ea_read_header(AVFormatContext *s)
st->codec->bits_per_coded_sample / 4;
st->codec->block_align = st->codec->channels*st->codec->bits_per_coded_sample;
ea->audio_stream_index = st->index;
- ea->audio_frame_counter = 0;
+ st->start_time = 0;
}
return 1;
@@ -522,24 +521,26 @@ static int ea_read_packet(AVFormatContext *s,
if (ret < 0)
return ret;
pkt->stream_index = ea->audio_stream_index;
- pkt->pts = 90000;
- pkt->pts *= ea->audio_frame_counter;
- pkt->pts /= ea->sample_rate;
switch (ea->audio_codec) {
case CODEC_ID_ADPCM_EA:
- /* 2 samples/byte, 1 or 2 samples per frame depending
- * on stereo; chunk also has 12-byte header */
- ea->audio_frame_counter += ((chunk_size - 12) * 2) /
- ea->num_channels;
+ case CODEC_ID_ADPCM_EA_R1:
+ case CODEC_ID_ADPCM_EA_R2:
+ case CODEC_ID_ADPCM_IMA_EA_EACS:
+ pkt->duration = AV_RL32(pkt->data);
+ break;
+ case CODEC_ID_ADPCM_EA_R3:
+ pkt->duration = AV_RB32(pkt->data);
+ break;
+ case CODEC_ID_ADPCM_IMA_EA_SEAD:
+ pkt->duration = ret * 2 / ea->num_channels;
break;
case CODEC_ID_PCM_S16LE_PLANAR:
case CODEC_ID_MP3:
- ea->audio_frame_counter += num_samples;
+ pkt->duration = num_samples;
break;
default:
- ea->audio_frame_counter += chunk_size /
- (ea->bytes * ea->num_channels);
+ pkt->duration = chunk_size / (ea->bytes * ea->num_channels);
}
packet_read = 1;
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 460372c116..2d86a263ab 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -714,11 +714,6 @@ static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf
int dts_flag = -1, cts_flag = -1;
int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;
- if (buf_size<=0) {
- av_log(0,AV_LOG_WARNING, "empty SL header\n");
- return 0;
- }
-
init_get_bits(&gb, buf, buf_size*8);
if (sl->use_au_start)
@@ -928,7 +923,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
/* we got the full header. We parse it and get the payload */
pes->state = MPEGTS_PAYLOAD;
pes->data_index = 0;
- if (pes->stream_type == 0x12) {
+ if (pes->stream_type == 0x12 && buf_size > 0) {
int sl_header_bytes = read_sl_header(pes, &pes->sl, p, buf_size);
pes->pes_header_size += sl_header_bytes;
p += sl_header_bytes;
@@ -1844,6 +1839,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
ts->stop_parse = 0;
packet_num = 0;
+ memset(packet + TS_PACKET_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
for(;;) {
packet_num++;
if (nb_packets != 0 && packet_num >= nb_packets ||
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index ba9b348456..b9d9f575e0 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -251,6 +251,7 @@ vorbis_header (AVFormatContext * s, int idx)
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_VORBIS;
+ st->need_parsing = AVSTREAM_PARSE_HEADERS;
if (srate > 0) {
st->codec->sample_rate = srate;
diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index 24f1c08617..ff9b7edceb 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -258,7 +258,9 @@ static int str_read_packet(AVFormatContext *s,
// st->codec->bit_rate = 0; //FIXME;
st->codec->block_align = 128;
- avpriv_set_pts_info(st, 64, 128, st->codec->sample_rate);
+ avpriv_set_pts_info(st, 64, 18 * 224 / st->codec->channels,
+ st->codec->sample_rate);
+ st->start_time = 0;
}
pkt = ret_pkt;
if (av_new_packet(pkt, 2304))
@@ -267,6 +269,7 @@ static int str_read_packet(AVFormatContext *s,
pkt->stream_index =
str->channels[channel].audio_stream_index;
+ pkt->duration = 1;
return 0;
default:
av_log(s, AV_LOG_WARNING, "Unknown sector type %02X\n", sector[0x12]);
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index dae2e581d2..440609928f 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -396,6 +396,9 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext
case CODEC_ID_H264:
st->need_parsing = AVSTREAM_PARSE_FULL;
break;
+ case CODEC_ID_VORBIS:
+ st->need_parsing = AVSTREAM_PARSE_HEADERS;
+ break;
case CODEC_ID_ADPCM_G722:
/* According to RFC 3551, the stream clock rate is 8000
* even if the sample rate is 16000. */
diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 210dedad48..c0a5e0f81e 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -197,8 +197,13 @@ static int film_read_header(AVFormatContext *s)
if (!film->sample_table)
return AVERROR(ENOMEM);
- for(i=0; i<s->nb_streams; i++)
- avpriv_set_pts_info(s->streams[i], 33, 1, film->base_clock);
+ for (i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ avpriv_set_pts_info(st, 33, 1, film->base_clock);
+ else
+ avpriv_set_pts_info(st, 64, 1, film->audio_samplerate);
+ }
audio_frame_counter = 0;
for (i = 0; i < film->sample_count; i++) {
@@ -213,8 +218,6 @@ static int film_read_header(AVFormatContext *s)
if (AV_RB32(&scratch[8]) == 0xFFFFFFFF) {
film->sample_table[i].stream = film->audio_stream_index;
film->sample_table[i].pts = audio_frame_counter;
- film->sample_table[i].pts *= film->base_clock;
- film->sample_table[i].pts /= film->audio_samplerate;
if (film->audio_type == CODEC_ID_ADPCM_ADX)
audio_frame_counter += (film->sample_table[i].sample_size * 32 /
diff --git a/libavformat/thp.c b/libavformat/thp.c
index dc30fbaf70..e71cbc4bd4 100644
--- a/libavformat/thp.c
+++ b/libavformat/thp.c
@@ -184,6 +184,9 @@ static int thp_read_packet(AVFormatContext *s,
}
pkt->stream_index = thp->audio_stream_index;
+ if (thp->audiosize >= 8)
+ pkt->duration = AV_RB32(&pkt->data[4]);
+
thp->audiosize = 0;
thp->frame++;
}
diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c
index d2d4e880c2..a0c06deab6 100644
--- a/libavformat/tiertexseq.c
+++ b/libavformat/tiertexseq.c
@@ -224,6 +224,7 @@ static int seq_read_header(AVFormatContext *s)
if (!st)
return AVERROR(ENOMEM);
+ st->start_time = 0;
avpriv_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE);
seq->audio_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -233,7 +234,7 @@ static int seq_read_header(AVFormatContext *s)
st->codec->sample_rate = SEQ_SAMPLE_RATE;
st->codec->bits_per_coded_sample = 16;
st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels;
- st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
+ st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample / 8;
return 0;
}
diff --git a/libavformat/tta.c b/libavformat/tta.c
index c2f0902535..9c31432b7b 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -27,6 +27,8 @@
typedef struct {
int totalframes, currentframe;
+ int frame_size;
+ int last_frame_size;
} TTAContext;
static int tta_probe(AVProbeData *p)
@@ -42,7 +44,7 @@ static int tta_read_header(AVFormatContext *s)
{
TTAContext *c = s->priv_data;
AVStream *st;
- int i, channels, bps, samplerate, datalen, framelen;
+ int i, channels, bps, samplerate, datalen;
uint64_t framepos, start_offset;
if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
@@ -69,8 +71,11 @@ static int tta_read_header(AVFormatContext *s)
avio_skip(s->pb, 4); // header crc
- framelen = samplerate*256/245;
- c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);
+ c->frame_size = samplerate * 256 / 245;
+ c->last_frame_size = datalen % c->frame_size;
+ if (!c->last_frame_size)
+ c->last_frame_size = c->frame_size;
+ c->totalframes = datalen / c->frame_size + (c->last_frame_size < c->frame_size);
c->currentframe = 0;
if(c->totalframes >= UINT_MAX/sizeof(uint32_t) || c->totalframes <= 0){
@@ -90,7 +95,8 @@ static int tta_read_header(AVFormatContext *s)
for (i = 0; i < c->totalframes; i++) {
uint32_t size = avio_rl32(s->pb);
- av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME);
+ av_add_index_entry(st, framepos, i * c->frame_size, size, 0,
+ AVINDEX_KEYFRAME);
framepos += size;
}
avio_skip(s->pb, 4); // seektable crc
@@ -132,6 +138,8 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, size);
pkt->dts = st->index_entries[c->currentframe++].timestamp;
+ pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size :
+ c->frame_size;
return ret;
}
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 580b9fea3e..7f6bfaa88a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -759,9 +759,6 @@ static int get_audio_frame_size(AVCodecContext *enc, int size)
{
int frame_size;
- if(enc->codec_id == CODEC_ID_VORBIS)
- return -1;
-
if (enc->frame_size <= 1) {
int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
@@ -2105,8 +2102,7 @@ static int has_codec_parameters(AVCodecContext *avctx)
case AVMEDIA_TYPE_AUDIO:
val = avctx->sample_rate && avctx->channels && avctx->sample_fmt != AV_SAMPLE_FMT_NONE;
if (!avctx->frame_size &&
- (avctx->codec_id == CODEC_ID_VORBIS ||
- avctx->codec_id == CODEC_ID_AAC ||
+ (avctx->codec_id == CODEC_ID_AAC ||
avctx->codec_id == CODEC_ID_MP1 ||
avctx->codec_id == CODEC_ID_MP2 ||
avctx->codec_id == CODEC_ID_MP3 ||
diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c
index ea06b53ecf..6df4d8d01f 100644
--- a/libavformat/vocdec.c
+++ b/libavformat/vocdec.c
@@ -86,9 +86,13 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
switch (type) {
case VOC_TYPE_VOICE_DATA:
- dec->sample_rate = 1000000 / (256 - avio_r8(pb));
- if (sample_rate)
- dec->sample_rate = sample_rate;
+ if (!dec->sample_rate) {
+ dec->sample_rate = 1000000 / (256 - avio_r8(pb));
+ if (sample_rate)
+ dec->sample_rate = sample_rate;
+ avpriv_set_pts_info(st, 64, 1, dec->sample_rate);
+ } else
+ avio_skip(pb, 1);
dec->channels = channels;
tmp_codec = avio_r8(pb);
dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id);
@@ -110,7 +114,11 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
break;
case VOC_TYPE_NEW_VOICE_DATA:
- dec->sample_rate = avio_rl32(pb);
+ if (!dec->sample_rate) {
+ dec->sample_rate = avio_rl32(pb);
+ avpriv_set_pts_info(st, 64, 1, dec->sample_rate);
+ } else
+ avio_skip(pb, 4);
dec->bits_per_coded_sample = avio_r8(pb);
dec->channels = avio_r8(pb);
tmp_codec = avio_rl16(pb);
diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index 4664c0068f..196cd39994 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -201,7 +201,7 @@ static int vqf_read_header(AVFormatContext *s)
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);
+ avpriv_set_pts_info(st, 64, size, 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)))
@@ -225,6 +225,7 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->pos = avio_tell(s->pb);
pkt->stream_index = 0;
+ pkt->duration = 1;
pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
pkt->data[1] = c->last_frame_bits;