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 #ifndef HISTREAMER_SCENE_RECORDER_STD_REC_UTILS_H 17 #define HISTREAMER_SCENE_RECORDER_STD_REC_UTILS_H 18 19 #include "i_recorder_engine.h" 20 #include "hst_recorder_param.h" 21 #include "pipeline/core/error_code.h" 22 #include "plugin/common/plugin_source_tags.h" 23 #include "plugin/core/plugin_meta.h" 24 #include "utils/constants.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Record { 29 /** 30 * @brief Max number of sources supported for multi-source concurrent recording. 31 */ 32 constexpr uint8_t VIDEO_SOURCE_MAX_COUNT = 1; 33 constexpr uint8_t AUDIO_SOURCE_MAX_COUNT = 1; 34 35 /** 36 * @brief Invalid source id, represent that the source set fail result 37 */ 38 constexpr int32_t INVALID_SOURCE_ID = -1; 39 40 struct SourceIdGenerator { 41 static const uint32_t SOURCE_MASK = 0xF00; 42 static const uint32_t VIDEO_MASK = 0x100; 43 static const uint32_t AUDIO_MASK = 0x200; 44 static const uint32_t INDEX_MASK = 0xFF; 45 /** 46 SourceId is currently represented as int32_t, and internal descripted as source kind mask + index : 47 high 20bits(reserverd) + 4bits(source kind mask) + 8bits(index). 48 The handle can uniquely identify the recorder source. 49 */ GenerateAudioSourceIdSourceIdGenerator50 static int32_t GenerateAudioSourceId(uint32_t index) 51 { 52 return static_cast<int32_t>(AUDIO_MASK + (INDEX_MASK & index)); 53 } 54 GenerateVideoSourceIdSourceIdGenerator55 static int32_t GenerateVideoSourceId(uint32_t index) 56 { 57 return static_cast<int32_t>(VIDEO_MASK + (INDEX_MASK & index)); 58 } 59 IsAudioSourceIdGenerator60 static int32_t IsAudio(int32_t sourceId) 61 { 62 return ((sourceId > 0) && 63 ((static_cast<uint32_t>(sourceId) & SOURCE_MASK) == AUDIO_MASK)); 64 } 65 IsVideoSourceIdGenerator66 static int32_t IsVideo(int32_t sourceId) 67 { 68 return ((sourceId > 0) && 69 ((static_cast<uint32_t>(sourceId) & SOURCE_MASK) == VIDEO_MASK)); 70 } 71 }; 72 73 const std::map<OutputFormatType, std::string> g_outputFormatToMimeMap = { 74 {OutputFormatType::FORMAT_DEFAULT, MEDIA_MIME_CONTAINER_MP4}, 75 {OutputFormatType::FORMAT_MPEG_4, MEDIA_MIME_CONTAINER_MP4}, 76 {OutputFormatType::FORMAT_M4A, MEDIA_MIME_CONTAINER_MP4}, 77 }; 78 79 int TransErrorCode(ErrorCode errorCode); 80 Plugin::SrcInputType TransAudioInputType(OHOS::Media::AudioSourceType sourceType); 81 Plugin::SrcInputType TransVideoInputType(OHOS::Media::VideoSourceType sourceType); 82 bool TransAudioEncoderFmt(OHOS::Media::AudioCodecFormat aFormat, Plugin::Meta& encoderMeta); 83 bool TransVideoEncoderFmt(OHOS::Media::VideoCodecFormat vFormat, Plugin::Meta& encoderMeta); 84 bool GenerateFilePath(const std::string& dirPath, OutputFormatType outputFormatType, std::string& filePath); 85 bool CastRecorderParam(int32_t sourceId, const RecorderParam& param, HstRecParam& out); 86 } // namespace Record 87 } // namespace Media 88 } // namespace OHOS 89 90 #endif // HISTREAMER_SCENE_RECORDER_STD_REC_UTILS_H 91