~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to libavformat/pcm.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * PCM common functions
 
3
 * Copyright (c) 2003 Fabrice Bellard
 
4
 *
 
5
 * This file is part of Libav.
 
6
 *
 
7
 * Libav is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 *
 
12
 * Libav is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with Libav; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
 */
 
21
 
 
22
#include "avformat.h"
 
23
#include "pcm.h"
 
24
 
 
25
int pcm_read_seek(AVFormatContext *s,
 
26
                  int stream_index, int64_t timestamp, int flags)
 
27
{
 
28
    AVStream *st;
 
29
    int block_align, byte_rate;
 
30
    int64_t pos, ret;
 
31
 
 
32
    st = s->streams[0];
 
33
 
 
34
    block_align = st->codec->block_align ? st->codec->block_align :
 
35
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
 
36
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
 
37
        block_align * st->codec->sample_rate;
 
38
 
 
39
    if (block_align <= 0 || byte_rate <= 0)
 
40
        return -1;
 
41
    if (timestamp < 0) timestamp = 0;
 
42
 
 
43
    /* compute the position by aligning it to block_align */
 
44
    pos = av_rescale_rnd(timestamp * byte_rate,
 
45
                         st->time_base.num,
 
46
                         st->time_base.den * (int64_t)block_align,
 
47
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
 
48
    pos *= block_align;
 
49
 
 
50
    /* recompute exact position */
 
51
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
 
52
    if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
 
53
        return ret;
 
54
    return 0;
 
55
}