LCOV - code coverage report
Current view: top level - libavformat - pvfdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 23 13.0 %
Date: 2017-12-12 11:08:38 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * PVF demuxer
       3             :  * Copyright (c) 2012 Paul B Mahol
       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 "libavcodec/internal.h"
      23             : #include "avformat.h"
      24             : #include "internal.h"
      25             : #include "pcm.h"
      26             : 
      27        6130 : static int pvf_probe(AVProbeData *p)
      28             : {
      29        6130 :     if (!memcmp(p->buf, "PVF1\n", 5))
      30           0 :         return AVPROBE_SCORE_MAX;
      31        6130 :     return 0;
      32             : }
      33             : 
      34           0 : static int pvf_read_header(AVFormatContext *s)
      35             : {
      36             :     char buffer[32];
      37             :     AVStream *st;
      38             :     int bps, channels, sample_rate;
      39             : 
      40           0 :     avio_skip(s->pb, 5);
      41           0 :     ff_get_line(s->pb, buffer, sizeof(buffer));
      42           0 :     if (sscanf(buffer, "%d %d %d",
      43             :                &channels,
      44             :                &sample_rate,
      45             :                &bps) != 3)
      46           0 :         return AVERROR_INVALIDDATA;
      47             : 
      48           0 :     if (channels <= 0 || channels > FF_SANE_NB_CHANNELS ||
      49           0 :         bps <= 0 || bps > INT_MAX / FF_SANE_NB_CHANNELS || sample_rate <= 0)
      50           0 :         return AVERROR_INVALIDDATA;
      51             : 
      52           0 :     st = avformat_new_stream(s, NULL);
      53           0 :     if (!st)
      54           0 :         return AVERROR(ENOMEM);
      55             : 
      56           0 :     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
      57           0 :     st->codecpar->channels    = channels;
      58           0 :     st->codecpar->sample_rate = sample_rate;
      59           0 :     st->codecpar->codec_id    = ff_get_pcm_codec_id(bps, 0, 1, 0xFFFF);
      60           0 :     st->codecpar->bits_per_coded_sample = bps;
      61           0 :     st->codecpar->block_align = bps * st->codecpar->channels / 8;
      62             : 
      63           0 :     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
      64             : 
      65           0 :     return 0;
      66             : }
      67             : 
      68             : AVInputFormat ff_pvf_demuxer = {
      69             :     .name           = "pvf",
      70             :     .long_name      = NULL_IF_CONFIG_SMALL("PVF (Portable Voice Format)"),
      71             :     .read_probe     = pvf_probe,
      72             :     .read_header    = pvf_read_header,
      73             :     .read_packet    = ff_pcm_read_packet,
      74             :     .read_seek      = ff_pcm_read_seek,
      75             :     .extensions     = "pvf",
      76             :     .flags          = AVFMT_GENERIC_INDEX,
      77             : };

Generated by: LCOV version 1.13