File: DVDVideoPPFFmpeg.cpp

package info (click to toggle)
kodi 2%3A21.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 143,076 kB
  • sloc: cpp: 694,471; xml: 52,618; ansic: 38,300; python: 7,161; sh: 4,289; javascript: 2,325; makefile: 1,791; perl: 969; java: 513; cs: 390; objc: 340
file content (132 lines) | stat: -rw-r--r-- 3,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "DVDVideoPPFFmpeg.h"
#include "utils/log.h"
#include "cores/FFmpeg.h"
#include "cores/VideoPlayer/Process/ProcessInfo.h"

extern "C" {
#include <libavutil/mem.h>
}

CDVDVideoPPFFmpeg::CDVDVideoPPFFmpeg(CProcessInfo &processInfo):
  m_sType(""), m_processInfo(processInfo)
{
  m_pMode = m_pContext = NULL;
  m_iInitWidth = m_iInitHeight = 0;
  m_deinterlace = false;
}

CDVDVideoPPFFmpeg::~CDVDVideoPPFFmpeg()
{
  Dispose();
}

void CDVDVideoPPFFmpeg::Dispose()
{
  if (m_pMode)
  {
    pp_free_mode(m_pMode);
    m_pMode = NULL;
  }
  if(m_pContext)
  {
    pp_free_context(m_pContext);
    m_pContext = NULL;
  }

  m_iInitWidth = 0;
  m_iInitHeight = 0;
}

bool CDVDVideoPPFFmpeg::CheckInit(int iWidth, int iHeight)
{
  if (m_iInitWidth != iWidth || m_iInitHeight != iHeight)
  {
    if (m_pContext || m_pMode)
    {
      Dispose();
    }

    m_pContext = pp_get_context(iWidth, iHeight, PPCPUFlags() | PP_FORMAT_420);

    m_iInitWidth = iWidth;
    m_iInitHeight = iHeight;

    m_pMode = pp_get_mode_by_name_and_quality(m_sType.c_str(), PP_QUALITY_MAX);
  }

  if (m_pMode)
    return true;
  else
    return false;
}

void CDVDVideoPPFFmpeg::SetType(const std::string& mType, bool deinterlace)
{
  m_deinterlace = deinterlace;

  if (mType == m_sType)
    return;

  m_sType = mType;

  if(m_pContext || m_pMode)
    Dispose();
}

void CDVDVideoPPFFmpeg::Process(VideoPicture* pPicture)
{
  VideoPicture* pSource = pPicture;
  CVideoBuffer *videoBuffer;

  if (pSource->videoBuffer->GetFormat() != AV_PIX_FMT_YUV420P)
    return;

  if (!CheckInit(pSource->iWidth, pSource->iHeight))
  {
    CLog::Log(LOGERROR, "Initialization of ffmpeg postprocessing failed");
    return;
  }

  uint8_t* srcPlanes[YuvImage::MAX_PLANES], *dstPlanes[YuvImage::MAX_PLANES];
  int srcStrides[YuvImage::MAX_PLANES]{};
  pSource->videoBuffer->GetPlanes(srcPlanes);
  pSource->videoBuffer->GetStrides(srcStrides);

  videoBuffer = m_processInfo.GetVideoBufferManager().Get(AV_PIX_FMT_YUV420P,
                                                          srcStrides[0] * pPicture->iHeight +
                                                          srcStrides[1] * pPicture->iHeight, nullptr);
  if (!videoBuffer)
  {
    return;
  }

  videoBuffer->SetDimensions(pPicture->iWidth, pPicture->iHeight, srcStrides);
  videoBuffer->GetPlanes(dstPlanes);
  //! @bug libpostproc isn't const correct
  pp_postprocess(const_cast<const uint8_t **>(srcPlanes), srcStrides,
                 dstPlanes, srcStrides,
                 pSource->iWidth, pSource->iHeight,
                 pSource->qp_table, pSource->qstride,
                 m_pMode, m_pContext,
                 pSource->pict_type | pSource->qscale_type ? PP_PICT_TYPE_QP2 : 0);

  // https://github.com/FFmpeg/FFmpeg/blob/991d417692/doc/APIchanges#L18-L20
  av_free(pSource->qp_table);

  pPicture->SetParams(*pSource);
  if (pPicture->videoBuffer)
    pPicture->videoBuffer->Release();
  pPicture->videoBuffer = videoBuffer;

  if (m_deinterlace)
    pPicture->iFlags &= ~DVP_FLAG_INTERLACED;
}