File: io_surface_capture_device_base_mac.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (86 lines) | stat: -rw-r--r-- 3,235 bytes parent folder | download | duplicates (4)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_MEDIA_CAPTURE_IO_SURFACE_CAPTURE_DEVICE_BASE_MAC_H_
#define CONTENT_BROWSER_MEDIA_CAPTURE_IO_SURFACE_CAPTURE_DEVICE_BASE_MAC_H_

#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "content/common/content_export.h"
#include "media/capture/video/video_capture_device.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/mac/io_surface.h"

namespace content {

// Common base class for the shared functionality of the two classes that
// capture frames as IOSurfaces, DesktopCaptureDeviceMac and
// ScreenCaptureKitDeviceMac.
class CONTENT_EXPORT IOSurfaceCaptureDeviceBase
    : public media::VideoCaptureDevice {
 public:
  IOSurfaceCaptureDeviceBase();
  ~IOSurfaceCaptureDeviceBase() override;

  // OnStart is called by AllocateAndStart.
  virtual void OnStart() = 0;

  // OnStop is called by StopAndDeAllocate.
  virtual void OnStop() = 0;

  // media::VideoCaptureDevice overrides.
  void RequestRefreshFrame() override;

 protected:
  void OnReceivedIOSurfaceFromStream(
      gfx::ScopedInUseIOSurface io_surface,
      const media::VideoCaptureFormat& capture_format,
      const gfx::Rect& visible_rect,
      std::optional<gfx::Size> content_size = std::nullopt,
      std::optional<float> scale_factor = std::nullopt);
  void SendLastReceivedIOSurfaceToClient();

  // Given a source frame size `source_size`, and `capture_params_`, compute the
  // appropriate frame size and store it in `frame_size`. If custom letterboxing
  // is to be performed, store the destination rectangle for the source content
  // in `dest_rect_in_frame`.
  void ComputeFrameSizeAndDestRect(const gfx::Size& source_size,
                                   gfx::Size& frame_size,
                                   gfx::RectF& dest_rect_in_frame) const;

  Client* client() { return client_.get(); }
  const media::VideoCaptureParams& capture_params() { return capture_params_; }

 private:
  // media::VideoCaptureDevice:
  void AllocateAndStart(const media::VideoCaptureParams& params,
                        std::unique_ptr<Client> client) final;
  void StopAndDeAllocate() final;

  // This class assumes single threaded access.
  THREAD_CHECKER(thread_checker_);

  std::unique_ptr<Client> client_;

  // The parameters that were specified to AllocateAndStart.
  media::VideoCaptureParams capture_params_;

  // The time of the first call to SendLastReceivedIOSurfaceToClient. Used to
  // compute the timestamp of subsequent frames.
  base::TimeTicks first_frame_time_;

  // The most recent arguments to OnReceivedIOSurfaceFromStream. If no other
  // frames come in, then this will be repeatedly sent at `min_frame_rate_`.
  gfx::ScopedInUseIOSurface last_received_io_surface_;
  media::VideoCaptureFormat last_received_capture_format_;
  gfx::Rect last_visible_rect_;
  media::VideoFrameMetadata last_received_metadata_;

  base::WeakPtrFactory<IOSurfaceCaptureDeviceBase> weak_factory_base_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_CAPTURE_IO_SURFACE_CAPTURE_DEVICE_BASE_MAC_H_