/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of mediastreamer2
* (see https://gitlab.linphone.org/BC/public/mediastreamer2).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
#include
#include "videotoolbox-h265-utilities.h"
using namespace std;
namespace mediastreamer {
CFStringRef VideoToolboxH265Utilities::_kVTProfileLevel_HEVC_Main_AutoLevel = nullptr;
VideoToolboxH265Utilities::GetParameterSetNativeFunc
VideoToolboxH265Utilities::_CMVideoFormatDescriptionGetHEVCParameterSetAtIndex = nullptr;
VideoToolboxH265Utilities::CreateFormatDescriptionNativeFunc
VideoToolboxH265Utilities::_CMVideoFormatDescriptionCreateFromHEVCParameterSets = nullptr;
VideoToolboxH265Utilities::VideoToolboxH265Utilities() {
if (_kVTProfileLevel_HEVC_Main_AutoLevel == nullptr) {
_kVTProfileLevel_HEVC_Main_AutoLevel =
*reinterpret_cast(dlsym(RTLD_DEFAULT, "kVTProfileLevel_HEVC_Main_AutoLevel"));
}
if (_CMVideoFormatDescriptionGetHEVCParameterSetAtIndex == nullptr) {
void *symPtr = dlsym(RTLD_DEFAULT, "CMVideoFormatDescriptionGetHEVCParameterSetAtIndex");
_CMVideoFormatDescriptionGetHEVCParameterSetAtIndex = reinterpret_cast(symPtr);
}
if (_CMVideoFormatDescriptionCreateFromHEVCParameterSets == nullptr) {
void *symPtr = dlsym(RTLD_DEFAULT, "CMVideoFormatDescriptionCreateFromHEVCParameterSets");
_CMVideoFormatDescriptionCreateFromHEVCParameterSets =
reinterpret_cast(symPtr);
}
}
CMVideoCodecType VideoToolboxH265Utilities::getCodecType() const {
return kCMVideoCodecType_HEVC;
}
CFStringRef VideoToolboxH265Utilities::getDefaultProfileLevel() const {
return _kVTProfileLevel_HEVC_Main_AutoLevel;
}
void VideoToolboxH265Utilities::getParameterSet(const CMFormatDescriptionRef format,
size_t offset,
const uint8_t *¶meterSet,
size_t ¶meterSetSize,
size_t ¶meterSetsCount) const {
OSStatus status = _CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(
format, offset, ¶meterSet, ¶meterSetSize, ¶meterSetsCount, nullptr);
if (status != noErr) throw AppleOSError(status);
}
CMFormatDescriptionRef VideoToolboxH265Utilities::createFormatDescription(size_t paramterSetsCount,
const uint8_t *parameterSets[],
const size_t parameterSetSizes[]) const {
CMFormatDescriptionRef formatDesc;
OSStatus status = _CMVideoFormatDescriptionCreateFromHEVCParameterSets(nullptr, paramterSetsCount, parameterSets,
parameterSetSizes, 4, nullptr, &formatDesc);
if (status != noErr) {
throw AppleOSError(status);
}
return formatDesc;
}
} // namespace mediastreamer