Commit 4986a429 authored by Fabrice Bellard's avatar Fabrice Bellard

seek support for PCM formats

Originally committed as revision 2497 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent ccd39ae6
...@@ -114,7 +114,7 @@ static int au_probe(AVProbeData *p) ...@@ -114,7 +114,7 @@ static int au_probe(AVProbeData *p)
/* au input */ /* au input */
static int au_read_header(AVFormatContext *s, static int au_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
{ {
int size; int size;
unsigned int tag; unsigned int tag;
...@@ -187,6 +187,7 @@ static AVInputFormat au_iformat = { ...@@ -187,6 +187,7 @@ static AVInputFormat au_iformat = {
au_read_header, au_read_header,
au_read_packet, au_read_packet,
au_read_close, au_read_close,
pcm_read_seek,
}; };
#ifdef CONFIG_ENCODERS #ifdef CONFIG_ENCODERS
......
...@@ -107,6 +107,48 @@ static int raw_read_close(AVFormatContext *s) ...@@ -107,6 +107,48 @@ static int raw_read_close(AVFormatContext *s)
return 0; return 0;
} }
int pcm_read_seek(AVFormatContext *s,
int stream_index, int64_t timestamp)
{
AVStream *st;
int block_align, byte_rate;
int64_t pos;
st = s->streams[0];
switch(st->codec.codec_id) {
case CODEC_ID_PCM_S16LE:
case CODEC_ID_PCM_S16BE:
case CODEC_ID_PCM_U16LE:
case CODEC_ID_PCM_U16BE:
block_align = 2 * st->codec.channels;
byte_rate = block_align * st->codec.sample_rate;
break;
case CODEC_ID_PCM_S8:
case CODEC_ID_PCM_U8:
case CODEC_ID_PCM_MULAW:
case CODEC_ID_PCM_ALAW:
block_align = st->codec.channels;
byte_rate = block_align * st->codec.sample_rate;
break;
default:
block_align = st->codec.block_align;
byte_rate = st->codec.bit_rate / 8;
break;
}
if (block_align <= 0 || byte_rate <= 0)
return -1;
/* compute the position by aligning it to block_align */
pos = (timestamp * byte_rate) / AV_TIME_BASE;
pos = (pos / block_align) * block_align;
/* recompute exact position */
st->cur_dts = (pos * AV_TIME_BASE) / byte_rate;
url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
return 0;
}
/* ac3 read */ /* ac3 read */
static int ac3_read_header(AVFormatContext *s, static int ac3_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
...@@ -119,6 +161,7 @@ static int ac3_read_header(AVFormatContext *s, ...@@ -119,6 +161,7 @@ static int ac3_read_header(AVFormatContext *s,
st->codec.codec_type = CODEC_TYPE_AUDIO; st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_AC3; st->codec.codec_id = CODEC_ID_AC3;
st->need_parsing = 1;
/* the parameters will be extracted from the compressed bitstream */ /* the parameters will be extracted from the compressed bitstream */
return 0; return 0;
} }
...@@ -135,10 +178,13 @@ static int video_read_header(AVFormatContext *s, ...@@ -135,10 +178,13 @@ static int video_read_header(AVFormatContext *s,
st->codec.codec_type = CODEC_TYPE_VIDEO; st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = s->iformat->value; st->codec.codec_id = s->iformat->value;
st->need_parsing = 1;
/* for mjpeg, specify frame rate */ /* for mjpeg, specify frame rate */
/* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) { if (st->codec.codec_id == CODEC_ID_MJPEG ||
if (ap) { st->codec.codec_id == CODEC_ID_MPEG4) {
if (ap && ap->frame_rate) {
st->codec.frame_rate = ap->frame_rate; st->codec.frame_rate = ap->frame_rate;
st->codec.frame_rate_base = ap->frame_rate_base; st->codec.frame_rate_base = ap->frame_rate_base;
} else { } else {
...@@ -356,9 +402,8 @@ AVOutputFormat mjpeg_oformat = { ...@@ -356,9 +402,8 @@ AVOutputFormat mjpeg_oformat = {
#endif //CONFIG_ENCODERS #endif //CONFIG_ENCODERS
/* pcm formats */ /* pcm formats */
#if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS)
#define PCMDEF(name, long_name, ext, codec) \ #define PCMINPUTDEF(name, long_name, ext, codec) \
AVInputFormat pcm_ ## name ## _iformat = {\ AVInputFormat pcm_ ## name ## _iformat = {\
#name,\ #name,\
long_name,\ long_name,\
...@@ -367,24 +412,20 @@ AVInputFormat pcm_ ## name ## _iformat = {\ ...@@ -367,24 +412,20 @@ AVInputFormat pcm_ ## name ## _iformat = {\
raw_read_header,\ raw_read_header,\
raw_read_packet,\ raw_read_packet,\
raw_read_close,\ raw_read_close,\
pcm_read_seek,\
.extensions = ext,\ .extensions = ext,\
.value = codec,\ .value = codec,\
}; };
#if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS)
#define PCMDEF(name, long_name, ext, codec) \
PCMINPUTDEF(name, long_name, ext, codec)
#else #else
#define PCMDEF(name, long_name, ext, codec) \ #define PCMDEF(name, long_name, ext, codec) \
AVInputFormat pcm_ ## name ## _iformat = {\ PCMINPUTDEF(name, long_name, ext, codec)\
#name,\
long_name,\
0,\
NULL,\
raw_read_header,\
raw_read_packet,\
raw_read_close,\
.extensions = ext,\
.value = codec,\
};\
\ \
AVOutputFormat pcm_ ## name ## _oformat = {\ AVOutputFormat pcm_ ## name ## _oformat = {\
#name,\ #name,\
......
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