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 "foundation/utils/constants.h"
18 
19 namespace OHOS {
20 namespace Media {
21 namespace Plugin {
22 namespace FFCodecMap {
CodecId2Cap(AVCodecID codecId,bool encoder,Plugin::Capability & cap)23 bool CodecId2Cap(AVCodecID codecId, bool encoder, Plugin::Capability& cap)
24 {
25     switch (codecId) {
26         case AV_CODEC_ID_MP3:
27             cap.SetMime(MEDIA_MIME_AUDIO_MPEG)
28                 .AppendFixedKey<uint32_t>(Capability::Key::AUDIO_MPEG_VERSION, 1)
29                 .AppendIntervalKey<uint32_t>(Capability::Key::AUDIO_MPEG_LAYER, 1, 3); // 3
30             return true;
31         case AV_CODEC_ID_FLAC:
32             cap.SetMime(MEDIA_MIME_AUDIO_FLAC);
33             return true;
34         case AV_CODEC_ID_AAC:
35             cap.SetMime(MEDIA_MIME_AUDIO_AAC);
36             return true;
37         case AV_CODEC_ID_AAC_LATM:
38             cap.SetMime(MEDIA_MIME_AUDIO_AAC_LATM);
39             return true;
40         case AV_CODEC_ID_H264:
41             cap.SetMime(MEDIA_MIME_VIDEO_H264);
42             return true;
43         case AV_CODEC_ID_VORBIS:
44             cap.SetMime(MEDIA_MIME_AUDIO_VORBIS);
45             return true;
46         case AV_CODEC_ID_APE:
47             cap.SetMime(MEDIA_MIME_AUDIO_APE);
48             return true;
49         default:
50             break;
51     }
52     return false;
53 }
FormatName2Cap(const std::string & fmtName,CapabilitySet & outCaps)54 bool FormatName2Cap(const std::string& fmtName, CapabilitySet& outCaps)
55 {
56     if (fmtName == "mp4") {
57         outCaps.emplace_back(Capability(MEDIA_MIME_CONTAINER_MP4));
58         return true;
59     } else if (fmtName == "h264") {
60         outCaps.emplace_back(Capability(MEDIA_MIME_VIDEO_H264));
61         return true;
62     }
63     return false;
64 }
Mime2CodecId(const std::string & mime,AVCodecID & codecId)65 bool Mime2CodecId(const std::string& mime, AVCodecID& codecId)
66 {
67     if (mime == MEDIA_MIME_AUDIO_AAC) {
68         codecId = AV_CODEC_ID_AAC;
69         return true;
70     } else if (mime == MEDIA_MIME_VIDEO_H264) {
71         codecId = AV_CODEC_ID_H264;
72         return true;
73     }
74     return false;
75 }
76 } // FFCodecMap
77 } // Plugin
78 } // Media
79 } // OHOS