1 /* 2 * Copyright (C) 2023 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 MEDIA_AVCODEC_MIME_TYPE_H 17 #define MEDIA_AVCODEC_MIME_TYPE_H 18 #include <string_view> 19 #include <string> 20 #include <unordered_set> 21 22 namespace OHOS { 23 namespace MediaAVCodec { 24 /** 25 * @enum Media mime type 26 * 27 * @since 4.0 28 */ 29 class AVCodecMimeType { 30 public: 31 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_AAC = "audio/mp4a-latm"; 32 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_FLAC = "audio/flac"; 33 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_VORBIS = "audio/vorbis"; 34 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_AMRNB = "audio/3gpp"; 35 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_OPUS = "audio/opus"; 36 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_MPEG = "audio/mpeg"; 37 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_AMRWB = "audio/amr-wb"; 38 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_VIVID = "audio/av3a"; 39 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_G711MU = "audio/g711mu"; 40 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_G711A = "audio/g711a"; 41 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_L2HC = "audio/l2hc"; 42 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape"; 43 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_LBVC = "audio/lbvc"; 44 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_COOK = "audio/cook"; 45 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_AC3 = "audio/ac3"; 46 static constexpr std::string_view MEDIA_MIMETYPE_AUDIO_RAW = "audio/raw"; 47 48 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_AVC = "video/avc"; 49 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_MPEG4 = "video/mp4v-es"; 50 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_HEVC = "video/hevc"; 51 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_RV30 = "video/rv30"; 52 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_RV40 = "video/rv40"; 53 54 static constexpr std::string_view MEDIA_MIMETYPE_IMAGE_JPG = "image/jpeg"; 55 static constexpr std::string_view MEDIA_MIMETYPE_IMAGE_PNG = "image/png"; 56 static constexpr std::string_view MEDIA_MIMETYPE_IMAGE_BMP = "image/bmp"; 57 58 static constexpr std::string_view MEDIA_MIMETYPE_VIDEO_VVC = "video/vvc"; 59 GetAudioCodecOuterSupportTable(bool isEncoder)60 static const std::unordered_set<std::string_view> &GetAudioCodecOuterSupportTable(bool isEncoder) 61 { 62 static const std::unordered_set<std::string_view> ENCODE_OUTER_SUPPORT_TABLE = { 63 MEDIA_MIMETYPE_AUDIO_AAC, 64 MEDIA_MIMETYPE_AUDIO_FLAC, 65 MEDIA_MIMETYPE_AUDIO_G711MU, 66 MEDIA_MIMETYPE_AUDIO_MPEG, 67 #ifdef AV_CODEC_AUDIO_VIVID_CAPACITY 68 MEDIA_MIMETYPE_AUDIO_OPUS, 69 MEDIA_MIMETYPE_AUDIO_AMRNB, 70 MEDIA_MIMETYPE_AUDIO_AMRWB 71 #endif 72 }; 73 static const std::unordered_set<std::string_view> DECODE_OUTER_SUPPORT_TABLE = { 74 MEDIA_MIMETYPE_AUDIO_AAC, 75 MEDIA_MIMETYPE_AUDIO_FLAC, 76 MEDIA_MIMETYPE_AUDIO_G711MU, 77 MEDIA_MIMETYPE_AUDIO_G711A, 78 MEDIA_MIMETYPE_AUDIO_RAW, 79 MEDIA_MIMETYPE_AUDIO_VORBIS, 80 MEDIA_MIMETYPE_AUDIO_MPEG, 81 MEDIA_MIMETYPE_AUDIO_AMRNB, 82 MEDIA_MIMETYPE_AUDIO_AMRWB, 83 MEDIA_MIMETYPE_AUDIO_APE, 84 #ifdef AV_CODEC_AUDIO_VIVID_CAPACITY 85 MEDIA_MIMETYPE_AUDIO_OPUS, 86 MEDIA_MIMETYPE_AUDIO_VIVID 87 #endif 88 }; 89 return isEncoder ? ENCODE_OUTER_SUPPORT_TABLE : DECODE_OUTER_SUPPORT_TABLE; 90 } 91 CheckAudioCodecMimeSupportOuter(const std::string & mime,bool isEncoder)92 static bool CheckAudioCodecMimeSupportOuter(const std::string &mime, bool isEncoder) 93 { 94 return GetAudioCodecOuterSupportTable(isEncoder).count(mime); 95 } 96 97 private: 98 AVCodecMimeType() = delete; 99 ~AVCodecMimeType() = delete; 100 }; 101 } // namespace MediaAVCodec 102 } // namespace OHOS 103 #endif // MEDIA_AVCODEC_MIME_TYPE_H