LCOV - code coverage report
Current view: top level - libavfilter - video.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 44 72.7 %
Date: 2018-02-20 21:25:12 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 2007 Bobby Bingham
       3             :  * Copyright Stefano Sabatini <stefasab gmail com>
       4             :  * Copyright Vitor Sessak <vitor1001 gmail com>
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include <string.h>
      24             : #include <stdio.h>
      25             : 
      26             : #include "libavutil/avassert.h"
      27             : #include "libavutil/buffer.h"
      28             : #include "libavutil/hwcontext.h"
      29             : #include "libavutil/imgutils.h"
      30             : #include "libavutil/mem.h"
      31             : 
      32             : #include "avfilter.h"
      33             : #include "internal.h"
      34             : #include "video.h"
      35             : 
      36             : #define BUFFER_ALIGN 32
      37             : 
      38             : 
      39       37714 : AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
      40             : {
      41       37714 :     return ff_get_video_buffer(link->dst->outputs[0], w, h);
      42             : }
      43             : 
      44       43248 : AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
      45             : {
      46       43248 :     AVFrame *frame = NULL;
      47       43248 :     int pool_width = 0;
      48       43248 :     int pool_height = 0;
      49       43248 :     int pool_align = 0;
      50       43248 :     enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
      51             : 
      52       43248 :     if (link->hw_frames_ctx &&
      53           0 :         ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
      54             :         int ret;
      55           0 :         AVFrame *frame = av_frame_alloc();
      56             : 
      57           0 :         if (!frame)
      58           0 :             return NULL;
      59             : 
      60           0 :         ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
      61           0 :         if (ret < 0)
      62           0 :             av_frame_free(&frame);
      63             : 
      64           0 :         return frame;
      65             :     }
      66             : 
      67       43248 :     if (!link->frame_pool) {
      68        3986 :         link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
      69        3986 :                                                     link->format, BUFFER_ALIGN);
      70        3986 :         if (!link->frame_pool)
      71           0 :             return NULL;
      72             :     } else {
      73       39262 :         if (ff_frame_pool_get_video_config(link->frame_pool,
      74             :                                            &pool_width, &pool_height,
      75             :                                            &pool_format, &pool_align) < 0) {
      76           0 :             return NULL;
      77             :         }
      78             : 
      79       78523 :         if (pool_width != w || pool_height != h ||
      80       78522 :             pool_format != link->format || pool_align != BUFFER_ALIGN) {
      81             : 
      82           1 :             ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
      83           1 :             link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
      84           1 :                                                         link->format, BUFFER_ALIGN);
      85           1 :             if (!link->frame_pool)
      86           0 :                 return NULL;
      87             :         }
      88             :     }
      89             : 
      90       43248 :     frame = ff_frame_pool_get(link->frame_pool);
      91       43248 :     if (!frame)
      92           0 :         return NULL;
      93             : 
      94       43248 :     frame->sample_aspect_ratio = link->sample_aspect_ratio;
      95             : 
      96       43248 :     return frame;
      97             : }
      98             : 
      99       81536 : AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
     100             : {
     101       81536 :     AVFrame *ret = NULL;
     102             : 
     103       81536 :     FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
     104             : 
     105       81536 :     if (link->dstpad->get_video_buffer)
     106       38460 :         ret = link->dstpad->get_video_buffer(link, w, h);
     107             : 
     108       81536 :     if (!ret)
     109       43076 :         ret = ff_default_get_video_buffer(link, w, h);
     110             : 
     111       81536 :     return ret;
     112             : }

Generated by: LCOV version 1.13