1 /*
2  * Copyright (C) 2023 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 "host/frontend/webrtc/libdevice/local_recorder.h"
20 
21 #include <atomic>
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "common/libs/fs/shared_fd.h"
28 
29 namespace webrtc {
30 class VideoTrackSourceInterface;
31 }
32 
33 namespace cuttlefish {
34 namespace webrtc_streaming {
35 
36 class Source {
37 public:
38   size_t width_;
39   size_t height_;
40   std::shared_ptr<webrtc::VideoTrackSourceInterface> video_;
41 };
42 
43 class RecordingManager {
44 public:
45   RecordingManager();
46 
47   void AddSource(size_t width, size_t height,
48            std::shared_ptr<webrtc::VideoTrackSourceInterface> video,
49            const std::string& label);
50   void RemoveSource(const std::string& label);
51   void Start();
52   void Stop();
53   void WaitForSources(size_t num_sources);
54 
55 private:
56   bool recording_;
57   std::string recording_directory_;
58   std::string instance_name_;
59   std::mutex mutex_;
60   std::condition_variable video_source_ready_signal_;
61   std::map<std::string, std::unique_ptr<Source>> sources_;
62   std::map<std::string,
63            std::unique_ptr<cuttlefish::webrtc_streaming::LocalRecorder>> local_recorders_;
64 
65   void StartSingleRecorder(const std::string& label);
66 };
67 
68 }  // namespace webrtc_streaming
69 }  // namespace cuttlefish