Open3D (C++ API)  0.18.0+252c867
ImageCapturer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 //
8 // This is a private header. It shall be hidden from Open3D's public API. Do not
9 // put this in Open3D.h.in.
10 
11 #pragma once
12 
13 #include <api/video/i420_buffer.h>
14 #include <libyuv/convert.h>
15 #include <libyuv/video_common.h>
16 #include <media/base/video_broadcaster.h>
17 #include <media/base/video_common.h>
18 
19 #include <memory>
20 
21 #include "open3d/core/Tensor.h"
22 #include "open3d/utility/Logging.h"
24 
25 namespace open3d {
26 namespace visualization {
27 namespace webrtc_server {
28 
29 class ImageCapturer : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
30 public:
31  ImageCapturer(const std::string& url_,
32  const std::map<std::string, std::string>& opts);
33  virtual ~ImageCapturer();
34 
35  static ImageCapturer* Create(
36  const std::string& url,
37  const std::map<std::string, std::string>& opts);
38 
39  ImageCapturer(const std::map<std::string, std::string>& opts);
40 
41  virtual void AddOrUpdateSink(
42  rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
43  const rtc::VideoSinkWants& wants) override;
44 
45  virtual void RemoveSink(
46  rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
47 
48  void OnCaptureResult(const std::shared_ptr<core::Tensor>& frame);
49 
50 protected:
51  int width_;
52  int height_;
53  rtc::VideoBroadcaster broadcaster_;
54 };
55 
57 public:
58  static rtc::scoped_refptr<BitmapTrackSourceInterface> Create(
59  const std::string& window_uid,
60  const std::map<std::string, std::string>& opts) {
61  std::unique_ptr<ImageCapturer> capturer =
62  absl::WrapUnique(ImageCapturer::Create(window_uid, opts));
63  if (!capturer) {
64  return nullptr;
65  }
66  rtc::scoped_refptr<BitmapTrackSourceInterface> video_source =
67  new rtc::RefCountedObject<ImageTrackSource>(
68  std::move(capturer));
69  return video_source;
70  }
71 
72  void OnFrame(const std::shared_ptr<core::Tensor>& frame) final override {
73  capturer_->OnCaptureResult(frame);
74  }
75 
76 protected:
77  explicit ImageTrackSource(std::unique_ptr<ImageCapturer> capturer)
78  : BitmapTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
79 
80 private:
81  rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
82  return capturer_.get();
83  }
84  std::unique_ptr<ImageCapturer> capturer_;
85 };
86 
87 } // namespace webrtc_server
88 } // namespace visualization
89 } // namespace open3d
Rect frame
Definition: BitmapWindowSystem.cpp:30
int width_
Definition: ImageCapturer.h:51
int height_
Definition: ImageCapturer.h:52
virtual void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
Definition: ImageCapturer.cpp:103
virtual void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
Definition: ImageCapturer.cpp:97
virtual ~ImageCapturer()
Definition: ImageCapturer.cpp:29
static ImageCapturer * Create(const std::string &url, const std::map< std::string, std::string > &opts)
Definition: ImageCapturer.cpp:31
void OnCaptureResult(const std::shared_ptr< core::Tensor > &frame)
Definition: ImageCapturer.cpp:48
ImageCapturer(const std::string &url_, const std::map< std::string, std::string > &opts)
Definition: ImageCapturer.cpp:25
rtc::VideoBroadcaster broadcaster_
Definition: ImageCapturer.h:53
void OnFrame(const std::shared_ptr< core::Tensor > &frame) final override
Definition: ImageCapturer.h:72
ImageTrackSource(std::unique_ptr< ImageCapturer > capturer)
Definition: ImageCapturer.h:77
static rtc::scoped_refptr< BitmapTrackSourceInterface > Create(const std::string &window_uid, const std::map< std::string, std::string > &opts)
Definition: ImageCapturer.h:58
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Device.h:107