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