1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_VIDEO_SOURCE_SCREEN_H 17 #define OHOS_SHARING_VIDEO_SOURCE_SCREEN_H 18 19 #include <surface.h> 20 #include <thread> 21 #include "dm_common.h" 22 #include "screen_manager.h" 23 #include "sync_fence.h" 24 #include "timer.h" 25 #include "video_source_encoder.h" 26 namespace OHOS { 27 namespace Sharing { 28 29 class VideoSourceScreen : public std::enable_shared_from_this<VideoSourceScreen> { 30 public: 31 class ScreenGroupListener : public Rosen::ScreenManager::IScreenGroupListener { 32 public: 33 void OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event) override; 34 }; 35 VideoSourceScreen(sptr<OHOS::Surface> encoderSurface)36 explicit VideoSourceScreen(sptr<OHOS::Surface> encoderSurface) : encoderSurface_(encoderSurface) {} 37 ~VideoSourceScreen(); 38 39 int32_t ReleaseScreenBuffer() const; 40 int32_t InitScreenSource(const VideoSourceConfigure &configure); 41 42 void StopScreenSourceCapture(); 43 void StartScreenSourceCapture(); 44 45 private: 46 void RemoveScreenFromGroup() const; 47 void FrameRateControlTimerWorker(); 48 49 int32_t DestroyVirtualScreen() const; 50 int32_t RegisterScreenGroupListener(); 51 int32_t UnregisterScreenGroupListener() const; 52 int32_t SetEncoderSurface(sptr<OHOS::Surface> surface); 53 54 uint64_t CreateVirtualScreen(const VideoSourceConfigure &configure); 55 56 private: 57 uint64_t screenId_ = SCREEN_ID_INVALID; 58 uint64_t srcScreenId_ = SCREEN_ID_INVALID; 59 60 OHOS::sptr<OHOS::Surface> encoderSurface_ = nullptr; 61 OHOS::sptr<ScreenGroupListener> screenGroupListener_ = nullptr; 62 }; 63 } // namespace Sharing 64 } // namespace OHOS 65 #endif 66