00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/mathematics.h"
00023 #include "avformat.h"
00024 #include "pcm.h"
00025
00026 int ff_pcm_read_seek(AVFormatContext *s,
00027 int stream_index, int64_t timestamp, int flags)
00028 {
00029 AVStream *st;
00030 int block_align, byte_rate;
00031 int64_t pos, ret;
00032
00033 st = s->streams[0];
00034
00035 block_align = st->codec->block_align ? st->codec->block_align :
00036 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
00037 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
00038 block_align * st->codec->sample_rate;
00039
00040 if (block_align <= 0 || byte_rate <= 0)
00041 return -1;
00042 if (timestamp < 0) timestamp = 0;
00043
00044
00045 pos = av_rescale_rnd(timestamp * byte_rate,
00046 st->time_base.num,
00047 st->time_base.den * (int64_t)block_align,
00048 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
00049 pos *= block_align;
00050
00051
00052 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
00053 if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
00054 return ret;
00055 return 0;
00056 }