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_DATA_SOURCE_H 17 #define RECORDER_DATA_SOURCE_H 18 19 #include <memory> 20 #include <map> 21 #include <string> 22 #include <thread> 23 #include <mutex> 24 #include <vector> 25 #include <condition_variable> 26 #include "format.h" 27 #include "media_errors.h" 28 #include "media_info.h" 29 #include "recorder_source.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 class RecorderDataSource : public RecorderSource, IBufferConsumerListener { 38 public: 39 40 RecorderDataSource(); 41 ~RecorderDataSource() override; 42 43 std::shared_ptr<OHOS::Surface> GetSurface(); 44 45 int32_t Start() override; 46 47 int32_t AcquireBuffer(RecorderSourceBuffer &buffer, bool isBlocking) override; 48 49 int32_t ReleaseBuffer(RecorderSourceBuffer &buffer) override; 50 51 int32_t Stop() override; 52 53 int32_t Resume() override; 54 55 int32_t Pause() override; 56 57 int32_t Release() override; 58 59 void OnBufferAvailable() override; 60 private: 61 std::shared_ptr<Surface> surface_; 62 std::mutex lock_; 63 std::condition_variable frameAvailableCondition_; 64 int32_t frameAvailableCount_; 65 std::vector<SurfaceBuffer*> acquiredBuffers_; 66 SurfaceBuffer *acquireBuffer_; 67 bool started_; 68 }; 69 } // namespace Media 70 } // namespace OHOS 71 72 #endif // RECORDER_VIDEO_SOURCE_H 73