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 #include "recorder_napi_utils.h"
17 #include <map>
18 #include <string>
19 #include "media_errors.h"
20
21 namespace OHOS {
22 namespace Media {
23 const std::map<std::string_view, int32_t> g_mimeStrToCodecFormat = {
24 { CodecMimeType::AUDIO_AAC, AudioCodecFormat::AAC_LC },
25 { CodecMimeType::VIDEO_AVC, VideoCodecFormat::H264 },
26 { CodecMimeType::VIDEO_MPEG4, VideoCodecFormat::MPEG4 },
27 };
28
29 const std::map<std::string, OutputFormatType> g_extensionToOutputFormat = {
30 { "mp4", OutputFormatType::FORMAT_MPEG_4 },
31 { "m4a", OutputFormatType::FORMAT_M4A },
32 };
33
MapMimeToAudioCodecFormat(const std::string & mime,AudioCodecFormat & codecFormat)34 int32_t MapMimeToAudioCodecFormat(const std::string &mime, AudioCodecFormat &codecFormat)
35 {
36 auto iter = g_mimeStrToCodecFormat.find(mime);
37 if (iter != g_mimeStrToCodecFormat.end()) {
38 codecFormat = static_cast<AudioCodecFormat>(iter->second);
39 }
40 return MSERR_INVALID_VAL;
41 }
42
MapMimeToVideoCodecFormat(const std::string & mime,VideoCodecFormat & codecFormat)43 int32_t MapMimeToVideoCodecFormat(const std::string &mime, VideoCodecFormat &codecFormat)
44 {
45 auto iter = g_mimeStrToCodecFormat.find(mime);
46 if (iter != g_mimeStrToCodecFormat.end()) {
47 codecFormat = static_cast<VideoCodecFormat>(iter->second);
48 }
49 return MSERR_INVALID_VAL;
50 }
51
MapExtensionNameToOutputFormat(const std::string & extension,OutputFormatType & type)52 int32_t MapExtensionNameToOutputFormat(const std::string &extension, OutputFormatType &type)
53 {
54 auto iter = g_extensionToOutputFormat.find(extension);
55 if (iter != g_extensionToOutputFormat.end()) {
56 type = iter->second;
57 }
58 return MSERR_INVALID_VAL;
59 }
60 } // namespace Media
61 } // namespace OHOS