LCOV - code coverage report
Current view: top level - libavfilter - audio.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 39 84.6 %
Date: 2017-12-14 08:27:08 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) Stefano Sabatini | stefasab at gmail.com
       3             :  * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
       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/avassert.h"
      23             : #include "libavutil/channel_layout.h"
      24             : #include "libavutil/common.h"
      25             : 
      26             : #include "audio.h"
      27             : #include "avfilter.h"
      28             : #include "internal.h"
      29             : 
      30             : #define BUFFER_ALIGN 0
      31             : 
      32             : 
      33           0 : AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
      34             : {
      35           0 :     return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
      36             : }
      37             : 
      38      290113 : AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
      39             : {
      40      290113 :     AVFrame *frame = NULL;
      41      290113 :     int channels = link->channels;
      42             : 
      43      290113 :     av_assert0(channels == av_get_channel_layout_nb_channels(link->channel_layout) || !av_get_channel_layout_nb_channels(link->channel_layout));
      44             : 
      45      290113 :     if (!link->frame_pool) {
      46        1291 :         link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
      47        1291 :                                                     nb_samples, link->format, BUFFER_ALIGN);
      48        1291 :         if (!link->frame_pool)
      49           0 :             return NULL;
      50             :     } else {
      51      288822 :         int pool_channels = 0;
      52      288822 :         int pool_nb_samples = 0;
      53      288822 :         int pool_align = 0;
      54      288822 :         enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
      55             : 
      56      288822 :         if (ff_frame_pool_get_audio_config(link->frame_pool,
      57             :                                            &pool_channels, &pool_nb_samples,
      58             :                                            &pool_format, &pool_align) < 0) {
      59           0 :             return NULL;
      60             :         }
      61             : 
      62      575736 :         if (pool_channels != channels || pool_nb_samples < nb_samples ||
      63      573828 :             pool_format != link->format || pool_align != BUFFER_ALIGN) {
      64             : 
      65        1908 :             ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
      66        1908 :             link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
      67        1908 :                                                         nb_samples, link->format, BUFFER_ALIGN);
      68        1908 :             if (!link->frame_pool)
      69           0 :                 return NULL;
      70             :         }
      71             :     }
      72             : 
      73      290113 :     frame = ff_frame_pool_get(link->frame_pool);
      74      290113 :     if (!frame)
      75           0 :         return NULL;
      76             : 
      77      290113 :     frame->nb_samples = nb_samples;
      78      290113 :     frame->channel_layout = link->channel_layout;
      79      290113 :     frame->sample_rate = link->sample_rate;
      80             : 
      81      290113 :     av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
      82             : 
      83      290113 :     return frame;
      84             : }
      85             : 
      86      290288 : AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
      87             : {
      88      290288 :     AVFrame *ret = NULL;
      89             : 
      90      290288 :     if (link->dstpad->get_audio_buffer)
      91         175 :         ret = link->dstpad->get_audio_buffer(link, nb_samples);
      92             : 
      93      290288 :     if (!ret)
      94      290113 :         ret = ff_default_get_audio_buffer(link, nb_samples);
      95             : 
      96      290288 :     return ret;
      97             : }

Generated by: LCOV version 1.13