1 /*
2  * Copyright (c) 2022-2022 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 #ifndef HISTREAMER_ST_TEST_RECORDER
16 #define HISTREAMER_ST_TEST_RECORDER
17 #include <memory>
18 #include <string>
19 #include "audio_capture_creator.h"
20 #include "i_recorder_engine.h"
21 
22 namespace OHOS::Media::Test {
23 const std::string OUTPUT_DIR_NAME = "audio_record_result";
24 
25 class AudioRecordSource {
26 public:
AudioRecordSource(std::string pcmPath,int32_t sampleRate,int32_t channel,int32_t bitRate,AudioSourceType sourceType=AudioSourceType::AUDIO_MIC,AudioCodecFormat encodeType=AudioCodecFormat::AAC_LC,OutputFormatType outputFormat=OutputFormatType::FORMAT_M4A)27     explicit AudioRecordSource(std::string pcmPath,
28                                int32_t sampleRate,
29                                int32_t channel,
30                                int32_t bitRate,
31                                AudioSourceType sourceType = AudioSourceType::AUDIO_MIC,
32                                AudioCodecFormat encodeType = AudioCodecFormat::AAC_LC,
33                                OutputFormatType outputFormat = OutputFormatType::FORMAT_M4A)
34         :pcmPath_(std::move(pcmPath)),
35         sampleRate_(sampleRate),
36         channel_(channel),
37         bitRate_(bitRate),
38         sourceType_(sourceType),
39         encodeType_(encodeType),
40         outputFormat_(outputFormat)
41     {}
42 public:
UseOutFd(int32_t fdUri)43     void UseOutFd(int32_t fdUri)
44     {
45         isFD_ = true;
46         outFD_ = fdUri;
47     }
48 
GetBitRate(int64_t & bitrate) const49     void GetBitRate(int64_t& bitrate) const
50     {
51         bitrate = bitRate_;
52     }
53 
GetSampleRate(int32_t & sampleRate) const54     void GetSampleRate(int32_t& sampleRate) const
55     {
56         sampleRate = sampleRate_;
57     }
58 
GetChannel(int32_t & channel) const59     void GetChannel(int32_t& channel) const
60     {
61         channel = channel_;
62     }
63 
64 private:
65     std::string pcmPath_;
66     int32_t sampleRate_;
67     int32_t channel_;
68     int32_t bitRate_;
69     int32_t outFD_ {-1};
70     bool isFD_ {false};
71     AudioSourceType sourceType_;
72     AudioCodecFormat encodeType_;
73     OutputFormatType outputFormat_;
74 
75     friend class TestRecorderImpl;
76 };
77 
78 class TestRecorder {
79 public:
80     static std::unique_ptr<TestRecorder> CreateAudioRecorder();
81     static std::string GetOutputDir();
82     virtual ~TestRecorder() = default;
83     virtual int32_t Configure(const AudioRecordSource& recordSource) = 0;
84     virtual int32_t Prepare() = 0;
85     virtual int32_t Start() = 0;
86     virtual int32_t Pause() = 0;
87     virtual int32_t Resume() = 0;
88     virtual int32_t Stop() = 0;
89     virtual int32_t Reset() = 0;
90     virtual int32_t Release() = 0;
91 };
92 }
93 #endif