1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <future> 20 #include <mutex> 21 #include <unordered_set> 22 23 #include <fmt/format.h> 24 25 #include "common/libs/utils/result.h" 26 #include "host/frontend/webrtc/libdevice/video_frame_buffer.h" 27 28 namespace cuttlefish { 29 30 class ScreenshotHandler { 31 public: 32 ScreenshotHandler() = default; 33 ~ScreenshotHandler() = default; 34 35 using SharedFrame = std::shared_ptr<webrtc_streaming::VideoFrameBuffer>; 36 using SharedFrameFuture = std::shared_future<SharedFrame>; 37 using SharedFramePromise = std::promise<SharedFrame>; 38 39 Result<void> Screenshot(std::uint32_t display_number, 40 const std::string& screenshot_path); 41 42 void OnFrame(std::uint32_t display_number, SharedFrame& buffer); 43 44 private: 45 std::mutex pending_screenshot_displays_mutex_; 46 // Promises used to share a frame for a given display from the display handler 47 // thread to the snapshot thread for processing. 48 std::unordered_map<std::uint32_t, SharedFramePromise> 49 pending_screenshot_displays_; 50 }; 51 52 } // namespace cuttlefish 53