1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CODEC_CAPABILITY_H 17 #define CODEC_CAPABILITY_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <vector> 22 #include "av_common.h" 23 #include "nocopyable.h" 24 25 namespace OHOS { 26 namespace Media { 27 class CodecRange { 28 public: 29 int32_t minVal; 30 int32_t maxVal; CodecRange()31 CodecRange() : minVal(0), maxVal(0) {} CodecRange(const int32_t & min,const int32_t & max)32 CodecRange(const int32_t &min, const int32_t &max) 33 { 34 if (min <= max) { 35 this->minVal = min; 36 this->maxVal = max; 37 } else { 38 this->minVal = 0; 39 this->maxVal = 0; 40 } 41 } 42 Create(const int32_t & min,const int32_t & max)43 CodecRange Create(const int32_t &min, const int32_t &max) 44 { 45 return CodecRange(min, max); 46 } 47 Marshalling(Parcel & parcel)48 bool Marshalling(Parcel &parcel) const 49 { 50 return parcel.WriteInt32(minVal) 51 && parcel.WriteInt32(maxVal); 52 } 53 Unmarshalling(Parcel & parcel)54 void Unmarshalling(Parcel &parcel) 55 { 56 minVal = parcel.ReadInt32(); 57 maxVal = parcel.ReadInt32(); 58 } 59 }; 60 61 class EncoderCapabilityData { 62 public: 63 std::string mimeType = ""; 64 std::string type = ""; 65 CodecRange bitrate; 66 CodecRange frameRate; 67 CodecRange width; 68 CodecRange height; 69 CodecRange channels; 70 std::vector<int32_t> sampleRate; 71 Marshalling(Parcel & parcel)72 bool Marshalling(Parcel &parcel) const 73 { 74 if (!parcel.WriteString(mimeType)) { 75 return false; 76 } 77 if (!parcel.WriteString(type)) { 78 return false; 79 } 80 if (!(bitrate.Marshalling(parcel) && frameRate.Marshalling(parcel) 81 && width.Marshalling(parcel) && height.Marshalling(parcel) 82 && channels.Marshalling(parcel))) { 83 return false; 84 } 85 size_t size = sampleRate.size(); 86 if (!parcel.WriteUint64(size)) { 87 return false; 88 } 89 for (const auto &i : sampleRate) { 90 if (!parcel.WriteInt32(i)) { 91 return false; 92 } 93 } 94 return true; 95 } 96 Unmarshalling(Parcel & parcel)97 void Unmarshalling(Parcel &parcel) 98 { 99 mimeType = parcel.ReadString(); 100 type = parcel.ReadString(); 101 bitrate.Unmarshalling(parcel); 102 frameRate.Unmarshalling(parcel); 103 width.Unmarshalling(parcel); 104 height.Unmarshalling(parcel); 105 channels.Unmarshalling(parcel); 106 size_t size = parcel.ReadUint64(); 107 for (size_t i = 0; i < size; i++) { 108 sampleRate.push_back(parcel.ReadInt32()); 109 } 110 } 111 }; 112 } // namespace Media 113 } // namespace OHOS 114 #endif // CODEC_CAPABILITY_H