File: ipc_video_frame_capturer.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 3,909 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_HOST_IPC_VIDEO_FRAME_CAPTURER_H_
#define REMOTING_HOST_IPC_VIDEO_FRAME_CAPTURER_H_

#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "remoting/host/mojom/desktop_session.mojom.h"
#include "remoting/protocol/desktop_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"

namespace remoting {

class DesktopSessionProxy;
class IpcSharedBufferCore;

// Routes webrtc::DesktopCapturer calls though the IPC channel to the desktop
// session agent running in the desktop integration process.
// GetSourceList() and SelectSource() functions are not implemented, they always
// return false.
class IpcVideoFrameCapturer : public DesktopCapturer,
                              public mojom::VideoCapturerEventHandler {
 public:
  explicit IpcVideoFrameCapturer(
      scoped_refptr<DesktopSessionProxy> desktop_session_proxy);

  IpcVideoFrameCapturer(const IpcVideoFrameCapturer&) = delete;
  IpcVideoFrameCapturer& operator=(const IpcVideoFrameCapturer&) = delete;

  ~IpcVideoFrameCapturer() override;

  // Sets the new Mojo endpoints for the capturer.
  void OnCreateVideoCapturerResult(mojom::CreateVideoCapturerResultPtr result);

  // Returns a WeakPtr to this capturer. Used by DesktopSessionProxy to set
  // the Mojo endpoints for this capturer (on initial creation, and after a
  // desktop detach/attach sequence. A WeakPtr is needed since the lifetime of
  // this capturer is bound to the VideoStream.
  base::WeakPtr<IpcVideoFrameCapturer> GetWeakPtr();

  // webrtc::DesktopCapturer interface.
  void Start(Callback* callback) override;
  void CaptureFrame() override;
  bool GetSourceList(SourceList* sources) override;
  bool SelectSource(SourceId id) override;
  void SetComposeEnabled(bool enabled) override;

  // mojom::VideoCapturerEventHandler interface.
  void OnSharedMemoryRegionCreated(int id,
                                   base::ReadOnlySharedMemoryRegion region,
                                   uint32_t size) override;
  void OnSharedMemoryRegionReleased(int id) override;
  void OnCaptureResult(mojom::CaptureResultPtr result) override;

 private:
  typedef std::map<int, scoped_refptr<IpcSharedBufferCore>> SharedBuffers;

  // Called when the Mojo endpoint is disconnected. Cleans up shared buffers,
  // and sends fake responses to `callback_` where needed to keep the frame
  // scheduler in sync.
  void OnDisconnect();

  // Returns a shared buffer from the list of known buffers.
  scoped_refptr<IpcSharedBufferCore> GetSharedBufferCore(int id);

  // Points to the callback passed to webrtc::DesktopCapturer::Start().
  raw_ptr<webrtc::DesktopCapturer::Callback> callback_ = nullptr;

  // Mojo endpoint for sending capturer commands to the Desktop process.
  mojo::Remote<mojom::VideoCapturer> capturer_control_;

  // Mojo endpoint for receiving capturer events from the Desktop process.
  mojo::Receiver<mojom::VideoCapturerEventHandler> event_handler_{this};

  int pending_capture_frame_requests_ = 0;

  // Shared memory buffers by Id. Each buffer is owned by the corresponding
  // frame.
  SharedBuffers shared_buffers_;

  // Used by SelectSource() in the single-stream case. Changing the display
  // requires creating a new video-capturer in the Desktop process, and
  // connecting the new Mojo endpoints.
  scoped_refptr<DesktopSessionProxy> desktop_session_proxy_;

  // Used to cancel tasks pending on the capturer when it is stopped.
  base::WeakPtrFactory<IpcVideoFrameCapturer> weak_factory_{this};
};

}  // namespace remoting

#endif  // REMOTING_HOST_IPC_VIDEO_FRAME_CAPTURER_H_