| 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 |
#pragma once |
| 22 |
|
| 23 |
#include <exception> |
| 24 |
#include <string> |
| 25 |
|
| 26 |
#include <VideoToolbox/VideoToolbox.h> |
| 27 |
|
| 28 |
#include "mediastreamer2/msqueue.h" |
| 29 |
|
| 30 |
#include "h26x-utils.h" |
| 31 |
|
| 32 |
namespace mediastreamer { |
| 33 |
|
| 34 |
std::string toString(OSStatus status); |
| 35 |
|
| 36 |
class AppleOSError : public std::exception { |
| 37 |
public: |
| 38 |
AppleOSError(OSStatus status) : _desc(toString(status)) { |
| 39 |
} |
| 40 |
const char *what() const noexcept override { |
| 41 |
return _desc.c_str(); |
| 42 |
} |
| 43 |
|
| 44 |
private: |
| 45 |
std::string _desc; |
| 46 |
}; |
| 47 |
|
| 48 |
class VideoToolboxUtilities { |
| 49 |
public: |
| 50 |
virtual ~VideoToolboxUtilities() = default; |
| 51 |
|
| 52 |
virtual CMVideoCodecType getCodecType() const = 0; |
| 53 |
virtual CFStringRef getDefaultProfileLevel() const = 0; |
| 54 |
|
| 55 |
bool encoderIsAvailable() const; |
| 56 |
void getParameterSets(const CMFormatDescriptionRef format, MSQueue *outPs) const; |
| 57 |
CMFormatDescriptionRef createFormatDescription(const H26xParameterSetsStore &psStore) const; |
| 58 |
|
| 59 |
static VideoToolboxUtilities *create(const std::string &mime); |
| 60 |
|
| 61 |
protected: |
| 62 |
virtual void getParameterSet(const CMFormatDescriptionRef format, |
| 63 |
size_t offset, |
| 64 |
const uint8_t *¶meterSet, |
| 65 |
size_t ¶meterSetSize, |
| 66 |
size_t ¶meterSetsCount) const = 0; |
| 67 |
virtual CMFormatDescriptionRef createFormatDescription(size_t parameterSetsCount, |
| 68 |
const uint8_t *parameterSets[], |
| 69 |
const size_t parameterSetSizes[]) const = 0; |
| 70 |
|
| 71 |
static void loadCodecAvailability(); |
| 72 |
|
| 73 |
static std::map<CMVideoCodecType, bool> _codecAvailability; |
| 74 |
}; |
| 75 |
|
| 76 |
} // namespace mediastreamer |