Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
ImageCapturer.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 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/scoped_refptr.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#include <rtc_base/ref_counted_object.h>
19
20#include <memory>
21
22#include "open3d/core/Tensor.h"
25
26namespace open3d {
27namespace visualization {
28namespace webrtc_server {
29
30class ImageCapturer : public webrtc::VideoSourceInterface<webrtc::VideoFrame> {
31public:
32 ImageCapturer(const std::string& url_,
33 const std::map<std::string, std::string>& opts);
34 virtual ~ImageCapturer();
35
36 static ImageCapturer* Create(
37 const std::string& url,
38 const std::map<std::string, std::string>& opts);
39
40 ImageCapturer(const std::map<std::string, std::string>& opts);
41
42 virtual void AddOrUpdateSink(
43 webrtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
44 const webrtc::VideoSinkWants& wants) override;
45
46 virtual void RemoveSink(
47 webrtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
48
49 void OnCaptureResult(const std::shared_ptr<core::Tensor>& frame);
50
51protected:
52 int width_;
54 webrtc::VideoBroadcaster broadcaster_;
55};
56
58public:
59 static webrtc::scoped_refptr<BitmapTrackSourceInterface> Create(
60 const std::string& window_uid,
61 const std::map<std::string, std::string>& opts) {
62 std::unique_ptr<ImageCapturer> capturer =
63 absl::WrapUnique(ImageCapturer::Create(window_uid, opts));
64 if (!capturer) {
65 return nullptr;
66 }
67 return webrtc::scoped_refptr<BitmapTrackSourceInterface>(
68 new webrtc::RefCountedObject<ImageTrackSource>(
69 std::move(capturer)));
70 }
71
72 void OnFrame(const std::shared_ptr<core::Tensor>& frame) final override {
73 capturer_->OnCaptureResult(frame);
74 }
75
76protected:
77 explicit ImageTrackSource(std::unique_ptr<ImageCapturer> capturer)
78 : BitmapTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
79
80private:
81 webrtc::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:31
int height_
Definition ImageCapturer.h:53
virtual ~ImageCapturer()
Definition ImageCapturer.cpp:32
static ImageCapturer * Create(const std::string &url, const std::map< std::string, std::string > &opts)
Definition ImageCapturer.cpp:34
virtual void RemoveSink(webrtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
Definition ImageCapturer.cpp:113
void OnCaptureResult(const std::shared_ptr< core::Tensor > &frame)
Definition ImageCapturer.cpp:51
virtual void AddOrUpdateSink(webrtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const webrtc::VideoSinkWants &wants) override
Definition ImageCapturer.cpp:107
webrtc::VideoBroadcaster broadcaster_
Definition ImageCapturer.h:54
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 webrtc::scoped_refptr< BitmapTrackSourceInterface > Create(const std::string &window_uid, const std::map< std::string, std::string > &opts)
Definition ImageCapturer.h:59
Definition PinholeCameraIntrinsic.cpp:16
Definition Device.h:113