ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ImageCapturer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 //
8 // This is a private header. It shall be hidden from CloudViewer's public API.
9 // Do not put this in CloudViewer.h.in.
10 
11 #pragma once
12 
13 #include <Logging.h>
14 #include <api/video/i420_buffer.h>
15 #include <libyuv/convert.h>
16 #include <libyuv/video_common.h>
17 #include <media/base/video_broadcaster.h>
18 #include <media/base/video_common.h>
19 
20 #include <memory>
21 
22 #include "core/Tensor.h"
24 
25 namespace cloudViewer {
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 cloudViewer
Rect frame
static ImageCapturer * Create(const std::string &url, const std::map< std::string, std::string > &opts)
ImageCapturer(const std::string &url_, const std::map< std::string, std::string > &opts)
virtual void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
virtual void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
void OnCaptureResult(const std::shared_ptr< core::Tensor > &frame)
ImageTrackSource(std::unique_ptr< ImageCapturer > capturer)
Definition: ImageCapturer.h:77
void OnFrame(const std::shared_ptr< core::Tensor > &frame) final override
Definition: ImageCapturer.h:72
static rtc::scoped_refptr< BitmapTrackSourceInterface > Create(const std::string &window_uid, const std::map< std::string, std::string > &opts)
Definition: ImageCapturer.h:58
Generic file read and write utility for python interface.
Definition: Eigen.h:85