LCOV - code coverage report
Current view: top level - libavcodec - nvdec_mpeg12.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 40 0.0 %
Date: 2017-12-12 11:08:38 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * MPEG-1/2 HW decode acceleration through NVDEC
       3             :  *
       4             :  * Copyright (c) 2017 Philip Langdale
       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 "avcodec.h"
      24             : #include "mpegvideo.h"
      25             : #include "nvdec.h"
      26             : #include "decode.h"
      27             : 
      28           0 : static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
      29             : {
      30           0 :     MpegEncContext *s = avctx->priv_data;
      31             : 
      32           0 :     NVDECContext      *ctx = avctx->internal->hwaccel_priv_data;
      33           0 :     CUVIDPICPARAMS     *pp = &ctx->pic_params;
      34           0 :     CUVIDMPEG2PICPARAMS *ppc = &pp->CodecSpecific.mpeg2;
      35             :     FrameDecodeData *fdd;
      36             :     NVDECFrame *cf;
      37           0 :     AVFrame *cur_frame = s->current_picture.f;
      38             : 
      39             :     int ret, i;
      40             : 
      41           0 :     ret = ff_nvdec_start_frame(avctx, cur_frame);
      42           0 :     if (ret < 0)
      43           0 :         return ret;
      44             : 
      45           0 :     fdd = (FrameDecodeData*)cur_frame->private_ref->data;
      46           0 :     cf  = (NVDECFrame*)fdd->hwaccel_priv;
      47             : 
      48           0 :     *pp = (CUVIDPICPARAMS) {
      49           0 :         .PicWidthInMbs     = (cur_frame->width  + 15) / 16,
      50           0 :         .FrameHeightInMbs  = (cur_frame->height + 15) / 16,
      51           0 :         .CurrPicIdx        = cf->idx,
      52             : 
      53           0 :         .intra_pic_flag    = s->pict_type == AV_PICTURE_TYPE_I,
      54           0 :         .ref_pic_flag      = s->pict_type == AV_PICTURE_TYPE_I ||
      55           0 :                              s->pict_type == AV_PICTURE_TYPE_P,
      56             : 
      57             :         .CodecSpecific.mpeg2 = {
      58           0 :             .ForwardRefIdx     = ff_nvdec_get_ref_idx(s->last_picture.f),
      59           0 :             .BackwardRefIdx    = ff_nvdec_get_ref_idx(s->next_picture.f),
      60             : 
      61           0 :             .picture_coding_type        = s->pict_type,
      62           0 :             .full_pel_forward_vector    = s->full_pel[0],
      63           0 :             .full_pel_backward_vector   = s->full_pel[1],
      64           0 :             .f_code                     = { { s->mpeg_f_code[0][0],
      65           0 :                                               s->mpeg_f_code[0][1] },
      66           0 :                                             { s->mpeg_f_code[1][0],
      67           0 :                                               s->mpeg_f_code[1][1] } },
      68           0 :             .intra_dc_precision         = s->intra_dc_precision,
      69           0 :             .frame_pred_frame_dct       = s->frame_pred_frame_dct,
      70           0 :             .concealment_motion_vectors = s->concealment_motion_vectors,
      71           0 :             .q_scale_type               = s->q_scale_type,
      72           0 :             .intra_vlc_format           = s->intra_vlc_format,
      73           0 :             .alternate_scan             = s->alternate_scan,
      74           0 :             .top_field_first            = s->top_field_first,
      75             :         }
      76             :     };
      77             : 
      78           0 :     for (i = 0; i < 64; ++i) {
      79           0 :         ppc->QuantMatrixIntra[i] = s->intra_matrix[i];
      80           0 :         ppc->QuantMatrixInter[i] = s->inter_matrix[i];
      81             :     }
      82             : 
      83           0 :     return 0;
      84             : }
      85             : 
      86           0 : static int nvdec_mpeg12_frame_params(AVCodecContext *avctx,
      87             :                                   AVBufferRef *hw_frames_ctx)
      88             : {
      89             :     // Each frame can at most have one P and one B reference
      90           0 :     return ff_nvdec_frame_params(avctx, hw_frames_ctx, 2);
      91             : }
      92             : 
      93             : #if CONFIG_MPEG2_NVDEC_HWACCEL
      94             : const AVHWAccel ff_mpeg2_nvdec_hwaccel = {
      95             :     .name                 = "mpeg2_nvdec",
      96             :     .type                 = AVMEDIA_TYPE_VIDEO,
      97             :     .id                   = AV_CODEC_ID_MPEG2VIDEO,
      98             :     .pix_fmt              = AV_PIX_FMT_CUDA,
      99             :     .start_frame          = nvdec_mpeg12_start_frame,
     100             :     .end_frame            = ff_nvdec_simple_end_frame,
     101             :     .decode_slice         = ff_nvdec_simple_decode_slice,
     102             :     .frame_params         = nvdec_mpeg12_frame_params,
     103             :     .init                 = ff_nvdec_decode_init,
     104             :     .uninit               = ff_nvdec_decode_uninit,
     105             :     .priv_data_size       = sizeof(NVDECContext),
     106             : };
     107             : #endif
     108             : 
     109             : #if CONFIG_MPEG1_NVDEC_HWACCEL
     110             : const AVHWAccel ff_mpeg1_nvdec_hwaccel = {
     111             :     .name                 = "mpeg1_nvdec",
     112             :     .type                 = AVMEDIA_TYPE_VIDEO,
     113             :     .id                   = AV_CODEC_ID_MPEG1VIDEO,
     114             :     .pix_fmt              = AV_PIX_FMT_CUDA,
     115             :     .start_frame          = nvdec_mpeg12_start_frame,
     116             :     .end_frame            = ff_nvdec_simple_end_frame,
     117             :     .decode_slice         = ff_nvdec_simple_decode_slice,
     118             :     .frame_params         = nvdec_mpeg12_frame_params,
     119             :     .init                 = ff_nvdec_decode_init,
     120             :     .uninit               = ff_nvdec_decode_uninit,
     121             :     .priv_data_size       = sizeof(NVDECContext),
     122             : };
     123             : #endif

Generated by: LCOV version 1.13