• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_VIDEO_SOURCE_H
17 #define RECORDER_VIDEO_SOURCE_H
18 
19 #include "recorder_source.h"
20 #include <memory>
21 #include <map>
22 #include <string>
23 #include <thread>
24 #include <mutex>
25 #include <vector>
26 #include <condition_variable>
27 #include "format.h"
28 #include "media_errors.h"
29 #include "media_info.h"
30 #include "surface.h"
31 
32 namespace OHOS {
33 namespace Media {
34 using OHOS::Surface;
35 using OHOS::SurfaceBuffer;
36 using OHOS::IBufferConsumerListener;
37 
38 class RecorderVideoSource : public RecorderSource, public IBufferConsumerListener {
39 public:
40 
41     RecorderVideoSource();
42     ~RecorderVideoSource() override;
43 
44     std::shared_ptr<OHOS::Surface> GetSurface();
45 
46     int32_t SetSurfaceSize(int32_t width, int32_t height);
47 
48     int32_t Start() override;
49 
50     int32_t AcquireBuffer(RecorderSourceBuffer &buffer, bool isBlocking) override;
51 
52     int32_t ReleaseBuffer(RecorderSourceBuffer &buffer) override;
53 
54     int32_t Stop() override;
55 
56     int32_t Resume() override;
57 
58     int32_t Pause() override;
59 
60     int32_t Release() override;
61 
62     void OnBufferAvailable() override;
63 
64 private:
65     std::shared_ptr<Surface> surface_;
66     std::mutex lock_;
67     std::condition_variable frameAvailableCondition_;
68     int32_t frameAvailableCount_;
69     std::vector<SurfaceBuffer*> acquiredBuffers;
70     SurfaceBuffer *acquireBuffer_;
71     bool started_;
72 };
73 }  // namespace Media
74 }  // namespace OHOS
75 
76 #endif  // RECORDER_VIDEO_SOURCE_H
77