• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef RECORDER_SERVICE_SERVER_H
17 #define RECORDER_SERVICE_SERVER_H
18 
19 #include "i_recorder_service.h"
20 #include "i_recorder_engine.h"
21 #include "nocopyable.h"
22 #include "task_queue.h"
23 #include "watchdog.h"
24 
25 namespace OHOS {
26 namespace Media {
27 enum class RecorderWatchDogStatus : int32_t {
28     WATCHDOG_WATCHING = 0,
29     WATCHDOG_PAUSE,
30 };
31 class RecorderServer : public IRecorderService, public IRecorderEngineObs, public NoCopyable {
32 public:
33     static std::shared_ptr<IRecorderService> Create();
34     RecorderServer();
35     ~RecorderServer();
36 
37     enum RecStatus {
38         REC_INITIALIZED = 0,
39         REC_CONFIGURED,
40         REC_PREPARED,
41         REC_RECORDING,
42         REC_PAUSED,
43         REC_ERROR,
44     };
45 
46     // IRecorderService override
47     int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId) override;
48     int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder) override;
49     int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height) override;
50     int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate) override;
51     int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate) override;
52     int32_t SetCaptureRate(int32_t sourceId, double fps) override;
53     sptr<OHOS::Surface> GetSurface(int32_t sourceId) override;
54     int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId) override;
55     int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder) override;
56     int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate) override;
57     int32_t SetAudioChannels(int32_t sourceId, int32_t num) override;
58     int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate) override;
59     int32_t SetDataSource(DataSourceType dataType, int32_t &sourceId) override;
60     int32_t SetMaxDuration(int32_t duration) override;
61     int32_t SetOutputFormat(OutputFormatType format) override;
62     int32_t SetOutputFile(int32_t fd) override;
63     int32_t SetNextOutputFile(int32_t fd) override;
64     int32_t SetMaxFileSize(int64_t size) override;
65     void SetLocation(float latitude, float longitude) override;
66     void SetOrientationHint(int32_t rotation) override;
67     int32_t SetRecorderCallback(const std::shared_ptr<RecorderCallback> &callback) override;
68     int32_t Prepare() override;
69     int32_t Start() override;
70     int32_t Pause() override;
71     int32_t Resume() override;
72     int32_t Stop(bool block) override;
73     int32_t Reset() override;
74     int32_t Release() override;
75     int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration) override;
76     int32_t SetParameter(int32_t sourceId, const Format &format) override;
77     int32_t DumpInfo(int32_t fd);
78 
79     // IRecorderEngineObs override
80     void OnError(ErrorType errorType, int32_t errorCode) override;
81     void OnInfo(InfoType type, int32_t extra) override;
82 
83 private:
84     int32_t Init();
85     const std::string &GetStatusDescription(OHOS::Media::RecorderServer::RecStatus status);
86 
87     std::unique_ptr<IRecorderEngine> recorderEngine_ = nullptr;
88     std::shared_ptr<RecorderCallback> recorderCb_ = nullptr;
89     RecStatus status_ = REC_INITIALIZED;
90     std::mutex mutex_;
91     std::mutex cbMutex_;
92     TaskQueue taskQue_;
93     struct ConfigInfo {
94         VideoSourceType videoSource;
95         AudioSourceType audioSource;
96         VideoCodecFormat videoCodec;
97         AudioCodecFormat audioCodec;
98         int32_t width;
99         int32_t height;
100         int32_t frameRate;
101         int32_t bitRate;
102         double captureRate;
103         int32_t audioSampleRate;
104         int32_t audioChannel;
105         int32_t audioBitRate;
106         int32_t maxDuration;
107         OutputFormatType format;
108         int64_t maxFileSize;
109     } config_;
110     std::string lastErrMsg_;
111 
112     std::atomic<bool> watchdogPause_ = false;
113 };
114 } // namespace Media
115 } // namespace OHOS
116 #endif // RECORDER_SERVICE_SERVER_H
117