LCOV - code coverage report
Current view: top level - libavformat - pcm.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 26 80.8 %
Date: 2017-12-11 04:34:20 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * PCM common functions
       3             :  * Copyright (c) 2003 Fabrice Bellard
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg 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             :  * FFmpeg 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 FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include "libavutil/mathematics.h"
      23             : #include "avformat.h"
      24             : #include "internal.h"
      25             : #include "pcm.h"
      26             : 
      27             : #define RAW_SAMPLES     1024
      28             : 
      29        5867 : int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
      30             : {
      31             :     int ret, size;
      32             : 
      33        5867 :     size= RAW_SAMPLES*s->streams[0]->codecpar->block_align;
      34        5867 :     if (size <= 0)
      35           0 :         return AVERROR(EINVAL);
      36             : 
      37        5867 :     ret= av_get_packet(s->pb, pkt, size);
      38             : 
      39        5867 :     pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
      40        5867 :     pkt->stream_index = 0;
      41             : 
      42        5867 :     return ret;
      43             : }
      44             : 
      45         602 : int ff_pcm_read_seek(AVFormatContext *s,
      46             :                      int stream_index, int64_t timestamp, int flags)
      47             : {
      48             :     AVStream *st;
      49             :     int block_align, byte_rate;
      50             :     int64_t pos, ret;
      51             : 
      52         602 :     st = s->streams[0];
      53             : 
      54         602 :     block_align = st->codecpar->block_align ? st->codecpar->block_align :
      55           0 :         (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
      56         602 :     byte_rate = st->codecpar->bit_rate ? st->codecpar->bit_rate >> 3 :
      57           0 :         block_align * st->codecpar->sample_rate;
      58             : 
      59         602 :     if (block_align <= 0 || byte_rate <= 0)
      60           0 :         return -1;
      61         602 :     if (timestamp < 0) timestamp = 0;
      62             : 
      63             :     /* compute the position by aligning it to block_align */
      64        1806 :     pos = av_rescale_rnd(timestamp * byte_rate,
      65         602 :                          st->time_base.num,
      66         602 :                          st->time_base.den * (int64_t)block_align,
      67         602 :                          (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
      68         602 :     pos *= block_align;
      69             : 
      70             :     /* recompute exact position */
      71         602 :     st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
      72         602 :     if ((ret = avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET)) < 0)
      73           0 :         return ret;
      74         602 :     return 0;
      75             : }

Generated by: LCOV version 1.13