• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/pcm.c

Go to the documentation of this file.
00001 /*
00002  * PCM common functions
00003  * Copyright (c) 2003 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "pcm.h"
00024 
00025 int pcm_read_seek(AVFormatContext *s,
00026                   int stream_index, int64_t timestamp, int flags)
00027 {
00028     AVStream *st;
00029     int block_align, byte_rate;
00030     int64_t pos, ret;
00031 
00032     st = s->streams[0];
00033 
00034     block_align = st->codec->block_align ? st->codec->block_align :
00035         (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
00036     byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
00037         block_align * st->codec->sample_rate;
00038 
00039     if (block_align <= 0 || byte_rate <= 0)
00040         return -1;
00041     if (timestamp < 0) timestamp = 0;
00042 
00043     /* compute the position by aligning it to block_align */
00044     pos = av_rescale_rnd(timestamp * byte_rate,
00045                          st->time_base.num,
00046                          st->time_base.den * (int64_t)block_align,
00047                          (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
00048     pos *= block_align;
00049 
00050     /* recompute exact position */
00051     st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
00052     if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
00053         return ret;
00054     return 0;
00055 }

Generated on Wed Apr 11 2012 07:31:34 for FFmpeg by  doxygen 1.7.1