| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "VideoBufferDRMPRIME.h" |
| 10 |
|
| 11 |
#include <mutex> |
| 12 |
|
| 13 |
|
| 14 |
extern "C" |
| 15 |
{ |
| 16 |
#include <libavcodec/avcodec.h> |
| 17 |
#include <libavutil/pixdesc.h> |
| 18 |
} |
| 19 |
|
| 20 |
namespace DRMPRIME |
| 21 |
{ |
| 22 |
|
| 23 |
KODI::UTILS::Colorimetry GetColorimetry(const VideoPicture& picture) |
| 24 |
{ |
| 25 |
switch (picture.color_space) |
| 26 |
{ |
| 27 |
case AVCOL_SPC_BT2020_CL: |
| 28 |
return KODI::UTILS::Colorimetry::BT2020_CYCC; |
| 29 |
case AVCOL_SPC_BT2020_NCL: |
| 30 |
return KODI::UTILS::Colorimetry::BT2020_YCC; |
| 31 |
default: |
| 32 |
return KODI::UTILS::Colorimetry::DEFAULT; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
std::string GetColorEncoding(const VideoPicture& picture) |
| 37 |
{ |
| 38 |
switch (picture.color_space) |
| 39 |
{ |
| 40 |
case AVCOL_SPC_BT2020_CL: |
| 41 |
case AVCOL_SPC_BT2020_NCL: |
| 42 |
return "ITU-R BT.2020 YCbCr"; |
| 43 |
case AVCOL_SPC_SMPTE170M: |
| 44 |
case AVCOL_SPC_BT470BG: |
| 45 |
case AVCOL_SPC_FCC: |
| 46 |
return "ITU-R BT.601 YCbCr"; |
| 47 |
case AVCOL_SPC_BT709: |
| 48 |
return "ITU-R BT.709 YCbCr"; |
| 49 |
case AVCOL_SPC_RESERVED: |
| 50 |
case AVCOL_SPC_UNSPECIFIED: |
| 51 |
default: |
| 52 |
if (picture.iWidth > 1024 || picture.iHeight >= 600) |
| 53 |
return "ITU-R BT.709 YCbCr"; |
| 54 |
else |
| 55 |
return "ITU-R BT.601 YCbCr"; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
std::string GetColorRange(const VideoPicture& picture) |
| 60 |
{ |
| 61 |
if (picture.color_range) |
| 62 |
return "YCbCr full range"; |
| 63 |
return "YCbCr limited range"; |
| 64 |
} |
| 65 |
|
| 66 |
KODI::UTILS::Eotf GetEOTF(const VideoPicture& picture) |
| 67 |
{ |
| 68 |
switch (picture.color_transfer) |
| 69 |
{ |
| 70 |
case AVCOL_TRC_SMPTE2084: |
| 71 |
return KODI::UTILS::Eotf::PQ; |
| 72 |
case AVCOL_TRC_ARIB_STD_B67: |
| 73 |
case AVCOL_TRC_BT2020_10: |
| 74 |
return KODI::UTILS::Eotf::HLG; |
| 75 |
default: |
| 76 |
return KODI::UTILS::Eotf::TRADITIONAL_SDR; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
const AVMasteringDisplayMetadata* GetMasteringDisplayMetadata(const VideoPicture& picture) |
| 81 |
{ |
| 82 |
return picture.hasDisplayMetadata ? &picture.displayMetadata : nullptr; |
| 83 |
} |
| 84 |
|
| 85 |
const AVContentLightMetadata* GetContentLightMetadata(const VideoPicture& picture) |
| 86 |
{ |
| 87 |
return picture.hasLightMetadata ? &picture.lightMetadata : nullptr; |
| 88 |
} |
| 89 |
|
| 90 |
} // namespace DRMPRIME |
| 91 |
|
| 92 |
CVideoBufferDRMPRIME::CVideoBufferDRMPRIME(int id) : CVideoBuffer(id) |
| 93 |
{ |
| 94 |
m_pixFormat = AV_PIX_FMT_DRM_PRIME; |
| 95 |
} |
| 96 |
|
| 97 |
CVideoBufferDRMPRIMEFFmpeg::CVideoBufferDRMPRIMEFFmpeg(IVideoBufferPool& pool, int id) |
| 98 |
: CVideoBufferDRMPRIME(id) |
| 99 |
{ |
| 100 |
m_pFrame = av_frame_alloc(); |
| 101 |
} |
| 102 |
|
| 103 |
CVideoBufferDRMPRIMEFFmpeg::~CVideoBufferDRMPRIMEFFmpeg() |
| 104 |
{ |
| 105 |
Unref(); |
| 106 |
av_frame_free(&m_pFrame); |
| 107 |
} |
| 108 |
|
| 109 |
void CVideoBufferDRMPRIMEFFmpeg::SetRef(AVFrame* frame) |
| 110 |
{ |
| 111 |
av_frame_move_ref(m_pFrame, frame); |
| 112 |
} |
| 113 |
|
| 114 |
void CVideoBufferDRMPRIMEFFmpeg::Unref() |
| 115 |
{ |
| 116 |
av_frame_unref(m_pFrame); |
| 117 |
} |
| 118 |
|
| 119 |
bool CVideoBufferDRMPRIMEFFmpeg::IsValid() const |
| 120 |
{ |
| 121 |
AVDRMFrameDescriptor* descriptor = GetDescriptor(); |
| 122 |
return descriptor && descriptor->nb_layers; |
| 123 |
} |
| 124 |
|
| 125 |
CVideoBufferPoolDRMPRIMEFFmpeg::~CVideoBufferPoolDRMPRIMEFFmpeg() |
| 126 |
{ |
| 127 |
for (auto buf : m_all) |
| 128 |
delete buf; |
| 129 |
} |
| 130 |
|
| 131 |
CVideoBuffer* CVideoBufferPoolDRMPRIMEFFmpeg::Get() |
| 132 |
{ |
| 133 |
std::unique_lock<CCriticalSection> lock(m_critSection); |
| 134 |
|
| 135 |
CVideoBufferDRMPRIMEFFmpeg* buf = nullptr; |
| 136 |
if (!m_free.empty()) |
| 137 |
{ |
| 138 |
int idx = m_free.front(); |
| 139 |
m_free.pop_front(); |
| 140 |
m_used.push_back(idx); |
| 141 |
buf = m_all[idx]; |
| 142 |
} |
| 143 |
else |
| 144 |
{ |
| 145 |
int id = m_all.size(); |
| 146 |
buf = new CVideoBufferDRMPRIMEFFmpeg(*this, id); |
| 147 |
m_all.push_back(buf); |
| 148 |
m_used.push_back(id); |
| 149 |
} |
| 150 |
|
| 151 |
buf->Acquire(GetPtr()); |
| 152 |
return buf; |
| 153 |
} |
| 154 |
|
| 155 |
void CVideoBufferPoolDRMPRIMEFFmpeg::Return(int id) |
| 156 |
{ |
| 157 |
std::unique_lock<CCriticalSection> lock(m_critSection); |
| 158 |
|
| 159 |
m_all[id]->Unref(); |
| 160 |
auto it = m_used.begin(); |
| 161 |
while (it != m_used.end()) |
| 162 |
{ |
| 163 |
if (*it == id) |
| 164 |
{ |
| 165 |
m_used.erase(it); |
| 166 |
break; |
| 167 |
} |
| 168 |
else |
| 169 |
++it; |
| 170 |
} |
| 171 |
m_free.push_back(id); |
| 172 |
} |