• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "ffmpeg_codec_map.h"
17 #include "utils/constants.h"
18 
19 namespace OHOS {
20 namespace Media {
21 namespace FFCodecMap {
22 using namespace OHOS::Media;
23 
CodecId2Cap(AVCodecID codecId,bool encoder,Plugin::Capability & cap)24 bool CodecId2Cap(AVCodecID codecId, bool encoder, Plugin::Capability& cap)
25 {
26     switch (codecId) {
27         case AV_CODEC_ID_MP3:
28             cap.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_MPEG)
29                 .AppendFixedKey<uint32_t>(Plugin::Capability::Key::AUDIO_MPEG_VERSION, 1)
30                 .AppendIntervalKey<uint32_t>(Plugin::Capability::Key::AUDIO_MPEG_LAYER, 1, 3); // 3
31             return true;
32         case AV_CODEC_ID_FLAC:
33             cap.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_FLAC);
34             return true;
35         case AV_CODEC_ID_AAC:
36             cap.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_AAC);
37             return true;
38         case AV_CODEC_ID_AAC_LATM:
39             cap.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_AAC_LATM);
40             return true;
41         default:
42             break;
43     }
44     return false;
45 }
FormatName2Cap(const std::string & fmtName,Plugin::CapabilitySet & outCaps)46 bool FormatName2Cap(const std::string& fmtName, Plugin::CapabilitySet& outCaps)
47 {
48     if (fmtName == "mp4") {
49         outCaps.emplace_back(Plugin::Capability(MEDIA_MIME_CONTAINER_MP4));
50         return true;
51     }
52     return false;
53 }
Mime2CodecId(const std::string & mime,AVCodecID & codecId)54 bool Mime2CodecId(const std::string& mime, AVCodecID& codecId)
55 {
56     if (mime == MEDIA_MIME_AUDIO_AAC) {
57         codecId = AV_CODEC_ID_AAC;
58         return true;
59     }
60     return false;
61 }
62 } // FFCodecMap
63 } // Media
64 } // OHOS