Songyue Han | ef3ee05 | 2024-10-29 23:31:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2024 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _NDK_MEDIA_CODEC_INFO_PRIV_H |
| 18 | #define _NDK_MEDIA_CODEC_INFO_PRIV_H |
| 19 | |
| 20 | #include <media/MediaCodecInfo.h> |
| 21 | #include <media/NdkMediaCodecInfo.h> |
| 22 | |
| 23 | struct ACodecAudioCapabilities { |
| 24 | std::shared_ptr<android::AudioCapabilities> mAudioCaps; |
| 25 | |
| 26 | std::vector<int> mSampleRates; |
| 27 | std::vector<AIntRange> mSampleRateRanges; |
| 28 | std::vector<AIntRange> mInputChannelCountRanges; |
| 29 | |
| 30 | void initSampleRates() { |
| 31 | mSampleRates = mAudioCaps->getSupportedSampleRates(); |
| 32 | } |
| 33 | |
| 34 | void initSampleRateRanges() { |
| 35 | const std::vector<android::Range<int>>& sampleRateRanges |
| 36 | = mAudioCaps->getSupportedSampleRateRanges(); |
| 37 | for (auto it = sampleRateRanges.begin(); it != sampleRateRanges.end(); it++) { |
| 38 | mSampleRateRanges.emplace_back(it->lower(), it->upper()); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void initInputChannelCountRanges() { |
| 43 | const std::vector<android::Range<int>>& inputChannels |
| 44 | = mAudioCaps->getInputChannelCountRanges(); |
| 45 | for (auto it = inputChannels.begin(); it != inputChannels.end(); it++) { |
| 46 | mInputChannelCountRanges.emplace_back(it->lower(), it->upper()); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | ACodecAudioCapabilities(std::shared_ptr<android::AudioCapabilities> audioCaps) |
| 51 | : mAudioCaps(audioCaps) { |
| 52 | initSampleRates(); |
| 53 | initSampleRateRanges(); |
| 54 | initInputChannelCountRanges(); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | struct ACodecPerformancePoint { |
| 59 | std::shared_ptr<const android::VideoCapabilities::PerformancePoint> mPerformancePoint; |
| 60 | |
| 61 | ACodecPerformancePoint(std::shared_ptr<const android::VideoCapabilities::PerformancePoint> |
| 62 | performancePoint) : mPerformancePoint(performancePoint) {} |
| 63 | }; |
| 64 | |
| 65 | struct ACodecVideoCapabilities { |
| 66 | std::shared_ptr<android::VideoCapabilities> mVideoCaps; |
| 67 | |
| 68 | std::vector<ACodecPerformancePoint> mPerformancePoints; |
| 69 | |
| 70 | void initPerformancePoints() { |
| 71 | const std::vector<android::VideoCapabilities::PerformancePoint>& performancePoints |
| 72 | = mVideoCaps->getSupportedPerformancePoints(); |
| 73 | for (auto it = performancePoints.begin(); it != performancePoints.end(); it++) { |
| 74 | mPerformancePoints.emplace_back( |
| 75 | std::shared_ptr<const android::VideoCapabilities::PerformancePoint>(&(*it))); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ACodecVideoCapabilities(std::shared_ptr<android::VideoCapabilities> videoCaps) |
| 80 | : mVideoCaps(videoCaps) { |
| 81 | initPerformancePoints(); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | struct ACodecEncoderCapabilities { |
| 86 | std::shared_ptr<android::EncoderCapabilities> mEncoderCaps; |
| 87 | |
| 88 | ACodecEncoderCapabilities(std::shared_ptr<android::EncoderCapabilities> encoderCaps) |
| 89 | : mEncoderCaps(encoderCaps) {} |
| 90 | }; |
| 91 | |
| 92 | struct AMediaCodecInfo { |
| 93 | std::string mName; |
| 94 | android::sp<android::MediaCodecInfo> mInfo; |
| 95 | std::string mMediaType; |
| 96 | std::shared_ptr<android::CodecCapabilities> mCodecCaps; |
| 97 | |
| 98 | std::shared_ptr<const ACodecAudioCapabilities> mAAudioCaps; |
| 99 | std::shared_ptr<const ACodecVideoCapabilities> mAVideoCaps; |
| 100 | std::shared_ptr<const ACodecEncoderCapabilities> mAEncoderCaps; |
| 101 | |
| 102 | AMediaCodecInfo(std::string name, android::sp<android::MediaCodecInfo> info, |
| 103 | std::shared_ptr<android::CodecCapabilities> codecCaps, std::string mediaType) |
| 104 | : mName(name), mInfo(info), mMediaType(mediaType), mCodecCaps(codecCaps) { |
| 105 | if (!mName.empty() && mInfo != nullptr && !mMediaType.empty() && mCodecCaps != nullptr) { |
| 106 | if (mCodecCaps->getAudioCapabilities() != nullptr) { |
| 107 | mAAudioCaps = std::make_shared<const ACodecAudioCapabilities>( |
| 108 | mCodecCaps->getAudioCapabilities()); |
| 109 | } |
| 110 | if (mCodecCaps->getVideoCapabilities() != nullptr) { |
| 111 | mAVideoCaps = std::make_shared<const ACodecVideoCapabilities>( |
| 112 | mCodecCaps->getVideoCapabilities()); |
| 113 | } |
| 114 | if (mCodecCaps->getEncoderCapabilities() != nullptr) { |
| 115 | mAEncoderCaps = std::make_shared<const ACodecEncoderCapabilities>( |
| 116 | mCodecCaps->getEncoderCapabilities()); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | #endif //_NDK_MEDIA_CODEC_INFO_PRIV_H |