LCOV - code coverage report
Current view: top level - libavcodec - nvdec_mpeg4.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 49 0.0 %
Date: 2017-12-15 18:13:28 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  * MPEG-4 Part 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 "mpeg4video.h"
      25             : #include "nvdec.h"
      26             : #include "decode.h"
      27             : 
      28           0 : static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
      29             : {
      30           0 :     Mpeg4DecContext *m = avctx->priv_data;
      31           0 :     MpegEncContext *s = &m->m;
      32             : 
      33           0 :     NVDECContext      *ctx = avctx->internal->hwaccel_priv_data;
      34           0 :     CUVIDPICPARAMS     *pp = &ctx->pic_params;
      35           0 :     CUVIDMPEG4PICPARAMS *ppc = &pp->CodecSpecific.mpeg4;
      36             :     FrameDecodeData *fdd;
      37             :     NVDECFrame *cf;
      38           0 :     AVFrame *cur_frame = s->current_picture.f;
      39             : 
      40             :     int ret, i;
      41             : 
      42           0 :     ret = ff_nvdec_start_frame(avctx, cur_frame);
      43           0 :     if (ret < 0)
      44           0 :         return ret;
      45             : 
      46           0 :     fdd = (FrameDecodeData*)cur_frame->private_ref->data;
      47           0 :     cf  = (NVDECFrame*)fdd->hwaccel_priv;
      48             : 
      49           0 :     *pp = (CUVIDPICPARAMS) {
      50           0 :         .PicWidthInMbs     = (cur_frame->width  + 15) / 16,
      51           0 :         .FrameHeightInMbs  = (cur_frame->height + 15) / 16,
      52           0 :         .CurrPicIdx        = cf->idx,
      53             : 
      54           0 :         .intra_pic_flag    = s->pict_type == AV_PICTURE_TYPE_I,
      55           0 :         .ref_pic_flag      = s->pict_type == AV_PICTURE_TYPE_I ||
      56           0 :                              s->pict_type == AV_PICTURE_TYPE_P ||
      57           0 :                              s->pict_type == AV_PICTURE_TYPE_S,
      58             : 
      59             :         .CodecSpecific.mpeg4 = {
      60           0 :             .ForwardRefIdx                = ff_nvdec_get_ref_idx(s->last_picture.f),
      61           0 :             .BackwardRefIdx               = ff_nvdec_get_ref_idx(s->next_picture.f),
      62             : 
      63           0 :             .video_object_layer_width     = s->width,
      64           0 :             .video_object_layer_height    = s->height,
      65           0 :             .vop_time_increment_bitcount  = m->time_increment_bits,
      66           0 :             .top_field_first              = s->top_field_first,
      67           0 :             .resync_marker_disable        = !m->resync_marker,
      68           0 :             .quant_type                   = s->mpeg_quant,
      69           0 :             .quarter_sample               = s->quarter_sample,
      70           0 :             .short_video_header           = avctx->codec->id == AV_CODEC_ID_H263,
      71           0 :             .divx_flags                   = s->divx_packed ? 5 : 0,
      72             : 
      73           0 :             .vop_coding_type              = s->pict_type - AV_PICTURE_TYPE_I,
      74             :             .vop_coded                    = 1,
      75           0 :             .vop_rounding_type            = s->no_rounding,
      76           0 :             .alternate_vertical_scan_flag = s->alternate_scan,
      77           0 :             .interlaced                   = !s->progressive_sequence,
      78           0 :             .vop_fcode_forward            = s->f_code,
      79           0 :             .vop_fcode_backward           = s->b_code,
      80           0 :             .trd                          = { s->pp_time, s->pp_field_time >> 1 },
      81           0 :             .trb                          = { s->pb_time, s->pb_field_time >> 1 },
      82             : 
      83           0 :             .gmc_enabled                  = s->pict_type == AV_PICTURE_TYPE_S &&
      84           0 :                                             m->vol_sprite_usage == GMC_SPRITE,
      85             :         }
      86             :     };
      87             : 
      88           0 :     for (i = 0; i < 64; ++i) {
      89           0 :         ppc->QuantMatrixIntra[i] = s->intra_matrix[i];
      90           0 :         ppc->QuantMatrixInter[i] = s->inter_matrix[i];
      91             :     }
      92             : 
      93             :     // We need to pass the full frame buffer and not just the slice
      94           0 :     return ff_nvdec_simple_decode_slice(avctx, buffer, size);
      95             : }
      96             : 
      97           0 : static int nvdec_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
      98             : {
      99           0 :     return 0;
     100             : }
     101             : 
     102           0 : static int nvdec_mpeg4_frame_params(AVCodecContext *avctx,
     103             :                                   AVBufferRef *hw_frames_ctx)
     104             : {
     105             :     // Each frame can at most have one P and one B reference
     106           0 :     return ff_nvdec_frame_params(avctx, hw_frames_ctx, 2);
     107             : }
     108             : 
     109             : const AVHWAccel ff_mpeg4_nvdec_hwaccel = {
     110             :     .name                 = "mpeg4_nvdec",
     111             :     .type                 = AVMEDIA_TYPE_VIDEO,
     112             :     .id                   = AV_CODEC_ID_MPEG4,
     113             :     .pix_fmt              = AV_PIX_FMT_CUDA,
     114             :     .start_frame          = nvdec_mpeg4_start_frame,
     115             :     .end_frame            = ff_nvdec_simple_end_frame,
     116             :     .decode_slice         = nvdec_mpeg4_decode_slice,
     117             :     .frame_params         = nvdec_mpeg4_frame_params,
     118             :     .init                 = ff_nvdec_decode_init,
     119             :     .uninit               = ff_nvdec_decode_uninit,
     120             :     .priv_data_size       = sizeof(NVDECContext),
     121             : };

Generated by: LCOV version 1.13