1 /* 2 * Copyright (c) 2020-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 RECORDER_SOURCE_H 17 #define RECORDER_SOURCE_H 18 #include <memory> 19 #include <map> 20 #include <string> 21 #include "format.h" 22 #include "media_info.h" 23 24 namespace OHOS { 25 namespace Media { 26 /** 27 * Indicates the recorder source type 28 */ 29 enum RecorderSourceType { 30 /** input camera */ 31 RECORDER_SOURCE_CAMERA = 0, 32 /** input surface */ 33 RECORDER_SOURCE_SURFACE, 34 /** such as aac */ 35 RECORDER_SOURCE_AUDIO, 36 /** image data */ 37 RECORDER_SOURCE_IMAGE_DATA, 38 RECORDER_SOURCE_INVALID, 39 }; 40 41 /** 42 * Provides audio capture information, include input source, audio codec format , the sampling rate (Hz) 43 * the sampling rate (Hz), the audio channel count, audio bit width. 44 * 45 */ 46 struct RecorderVideoSourceConfig { 47 VideoCodecFormat videoFormat = HEVC; 48 int32_t width = 0; 49 int32_t height = 0; 50 int32_t frameRate = 0; 51 int32_t bitRate = 0; 52 double captureRate = 0.0; 53 int32_t degree = 0; 54 float speed = 1.0f; 55 }; 56 57 /** 58 * Provides audio capture information, include input source, audio codec format , the sampling rate (Hz) 59 * the sampling rate (Hz), the audio channel count, audio bit width. 60 * 61 */ 62 struct RecorderAudioSourceConfig { 63 AudioSourceType inputSource = AUDIO_MIC; 64 AudioCodecFormat audioFormat = FORMAT_BUTT; 65 int32_t sampleRate = 0; 66 int32_t channelCount = 0; 67 int32_t bitRate = 0; 68 AudioStreamType streamType = TYPE_MEDIA; 69 AudioBitWidth bitWidth = BIT_WIDTH_16; 70 }; 71 72 enum DataType { 73 /** Image data source */ 74 DATA_TYPE_METADATA = 0 75 }; 76 77 struct RecorderDataSourceConfig { 78 DataType dataType; 79 }; 80 81 struct RecorderSourceBuffer { 82 bool keyFrameFlag; 83 int64_t timeStamp; 84 uint64_t dataSeq; 85 size_t dataLen; 86 uint8_t *dataAddr; 87 }; 88 89 class RecorderSource { 90 public: 91 /** 92 * A constructor used to create a {@code RecorderSource} instance based on a file descriptor. 93 */ RecorderSource()94 RecorderSource() 95 { 96 sourceType_ = RECORDER_SOURCE_INVALID; 97 }; 98 ~RecorderSource()99 virtual ~RecorderSource(){}; 100 101 /** 102 * get the source-type of the the source. 103 * 104 * @return returns the source type, see {@link RecorderSourceType}. 105 */ GetSourceType()106 RecorderSourceType GetSourceType() const 107 { 108 return sourceType_; 109 } 110 virtual int32_t Start() = 0; 111 112 virtual int32_t AcquireBuffer(RecorderSourceBuffer &buffer, bool isBlocking) = 0; 113 114 virtual int32_t ReleaseBuffer(RecorderSourceBuffer &buffer) = 0; 115 116 virtual int32_t Stop() = 0; 117 118 virtual int32_t Resume() = 0; 119 120 virtual int32_t Pause() = 0; 121 122 virtual int32_t Release() = 0; 123 124 private: 125 RecorderSourceType sourceType_; 126 }; 127 } // namespace Media 128 } // namespace OHOS 129 130 #endif // RECORDER_SOURCE_H 131