Debian Codegraph @

src/videofilters/h26x/videotoolbox-h265-utilities.cpp

raw
1 /*
2 * Copyright (c) 2010-2022 Belledonne Communications SARL.
3 *
4 * This file is part of mediastreamer2
5 * (see https://gitlab.linphone.org/BC/public/mediastreamer2).
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <dlfcn.h>
22
23 #include "videotoolbox-h265-utilities.h"
24
25 using namespace std;
26
27 namespace mediastreamer {
28
29 CFStringRef VideoToolboxH265Utilities::_kVTProfileLevel_HEVC_Main_AutoLevel = nullptr;
30 VideoToolboxH265Utilities::GetParameterSetNativeFunc
31 VideoToolboxH265Utilities::_CMVideoFormatDescriptionGetHEVCParameterSetAtIndex = nullptr;
32 VideoToolboxH265Utilities::CreateFormatDescriptionNativeFunc
33 VideoToolboxH265Utilities::_CMVideoFormatDescriptionCreateFromHEVCParameterSets = nullptr;
34
35 VideoToolboxH265Utilities::VideoToolboxH265Utilities() {
36 if (_kVTProfileLevel_HEVC_Main_AutoLevel == nullptr) {
37 _kVTProfileLevel_HEVC_Main_AutoLevel =
38 *reinterpret_cast<CFStringRef *>(dlsym(RTLD_DEFAULT, "kVTProfileLevel_HEVC_Main_AutoLevel"));
39 }
40 if (_CMVideoFormatDescriptionGetHEVCParameterSetAtIndex == nullptr) {
41 void *symPtr = dlsym(RTLD_DEFAULT, "CMVideoFormatDescriptionGetHEVCParameterSetAtIndex");
42 _CMVideoFormatDescriptionGetHEVCParameterSetAtIndex = reinterpret_cast<GetParameterSetNativeFunc>(symPtr);
43 }
44 if (_CMVideoFormatDescriptionCreateFromHEVCParameterSets == nullptr) {
45 void *symPtr = dlsym(RTLD_DEFAULT, "CMVideoFormatDescriptionCreateFromHEVCParameterSets");
46 _CMVideoFormatDescriptionCreateFromHEVCParameterSets =
47 reinterpret_cast<CreateFormatDescriptionNativeFunc>(symPtr);
48 }
49 }
50
51 CMVideoCodecType VideoToolboxH265Utilities::getCodecType() const {
52 return kCMVideoCodecType_HEVC;
53 }
54
55 CFStringRef VideoToolboxH265Utilities::getDefaultProfileLevel() const {
56 return _kVTProfileLevel_HEVC_Main_AutoLevel;
57 }
58
59 void VideoToolboxH265Utilities::getParameterSet(const CMFormatDescriptionRef format,
60 size_t offset,
61 const uint8_t *&parameterSet,
62 size_t &parameterSetSize,
63 size_t &parameterSetsCount) const {
64 OSStatus status = _CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(
65 format, offset, &parameterSet, &parameterSetSize, &parameterSetsCount, nullptr);
66 if (status != noErr) throw AppleOSError(status);
67 }
68
69 CMFormatDescriptionRef VideoToolboxH265Utilities::createFormatDescription(size_t paramterSetsCount,
70 const uint8_t *parameterSets[],
71 const size_t parameterSetSizes[]) const {
72 CMFormatDescriptionRef formatDesc;
73 OSStatus status = _CMVideoFormatDescriptionCreateFromHEVCParameterSets(nullptr, paramterSetsCount, parameterSets,
74 parameterSetSizes, 4, nullptr, &formatDesc);
75 if (status != noErr) {
76 throw AppleOSError(status);
77 }
78 return formatDesc;
79 }
80
81 } // namespace mediastreamer