// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // Copyright (c) 2018-2023 www.open3d.org // SPDX-License-Identifier: MIT // ---------------------------------------------------------------------------- // // This is a private header. It shall be hidden from Open3D's public API. Do not // put this in Open3D.h.in. #pragma once #include #include #include #include #include #include #include "open3d/core/Tensor.h" #include "open3d/utility/Logging.h" #include "open3d/visualization/webrtc_server/BitmapTrackSource.h" namespace open3d { namespace visualization { namespace webrtc_server { class ImageCapturer : public rtc::VideoSourceInterface { public: ImageCapturer(const std::string& url_, const std::map& opts); virtual ~ImageCapturer(); static ImageCapturer* Create( const std::string& url, const std::map& opts); ImageCapturer(const std::map& opts); virtual void AddOrUpdateSink( rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) override; virtual void RemoveSink( rtc::VideoSinkInterface* sink) override; void OnCaptureResult(const std::shared_ptr& frame); protected: int width_; int height_; rtc::VideoBroadcaster broadcaster_; }; class ImageTrackSource : public BitmapTrackSource { public: static rtc::scoped_refptr Create( const std::string& window_uid, const std::map& opts) { std::unique_ptr capturer = absl::WrapUnique(ImageCapturer::Create(window_uid, opts)); if (!capturer) { return nullptr; } rtc::scoped_refptr video_source = new rtc::RefCountedObject( std::move(capturer)); return video_source; } void OnFrame(const std::shared_ptr& frame) final override { capturer_->OnCaptureResult(frame); } protected: explicit ImageTrackSource(std::unique_ptr capturer) : BitmapTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {} private: rtc::VideoSourceInterface* source() override { return capturer_.get(); } std::unique_ptr capturer_; }; } // namespace webrtc_server } // namespace visualization } // namespace open3d