LCOV - code coverage report
Current view: top level - fftools - ffmpeg_cuvid.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 30 0.0 %
Date: 2017-10-22 09:09:27 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include "libavutil/hwcontext.h"
      20             : #include "libavutil/pixdesc.h"
      21             : 
      22             : #include "ffmpeg.h"
      23             : 
      24           0 : static void cuvid_uninit(AVCodecContext *avctx)
      25             : {
      26           0 :     InputStream *ist = avctx->opaque;
      27           0 :     av_buffer_unref(&ist->hw_frames_ctx);
      28           0 : }
      29             : 
      30           0 : int cuvid_init(AVCodecContext *avctx)
      31             : {
      32           0 :     InputStream *ist = avctx->opaque;
      33             :     AVHWFramesContext *frames_ctx;
      34             :     int ret;
      35             : 
      36           0 :     av_log(avctx, AV_LOG_VERBOSE, "Initializing cuvid hwaccel\n");
      37             : 
      38           0 :     if (!hw_device_ctx) {
      39           0 :         ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA,
      40           0 :                                      ist->hwaccel_device, NULL, 0);
      41           0 :         if (ret < 0) {
      42           0 :             av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n");
      43           0 :             return ret;
      44             :         }
      45             :     }
      46             : 
      47           0 :     av_buffer_unref(&ist->hw_frames_ctx);
      48           0 :     ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
      49           0 :     if (!ist->hw_frames_ctx) {
      50           0 :         av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n");
      51           0 :         return AVERROR(ENOMEM);
      52             :     }
      53             : 
      54           0 :     frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
      55             : 
      56           0 :     frames_ctx->format = AV_PIX_FMT_CUDA;
      57           0 :     frames_ctx->sw_format = avctx->sw_pix_fmt;
      58           0 :     frames_ctx->width = avctx->width;
      59           0 :     frames_ctx->height = avctx->height;
      60             : 
      61           0 :     av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n",
      62             :            av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height);
      63             : 
      64           0 :     ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
      65           0 :     if (ret < 0) {
      66           0 :         av_log(avctx, AV_LOG_ERROR, "Error initializing a CUDA frame pool\n");
      67           0 :         return ret;
      68             :     }
      69             : 
      70           0 :     ist->hwaccel_uninit = cuvid_uninit;
      71             : 
      72           0 :     return 0;
      73             : }

Generated by: LCOV version 1.13