Open3D (C++ API)  0.17.0
BitmapTrackSource.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 // Modified from: WebRTC src/pc/video_track_source.h
9 //
10 // Copyright 2016 The WebRTC project authors. All Rights Reserved.
11 //
12 // Use of this source code is governed by a BSD-style license
13 // that can be found in the LICENSE file in the root of the source
14 // tree. An additional intellectual property rights grant can be found
15 // in the file PATENTS. All contributing project authors may
16 // be found in the AUTHORS file in the root of the source tree.
17 // ----------------------------------------------------------------------------
18 //
19 // This is a private header. It shall be hidden from Open3D's public API. Do not
20 // put this in Open3D.h.in.
21 
22 #pragma once
23 
24 #include <absl/types/optional.h>
25 #include <api/notifier.h>
26 #include <api/sequence_checker.h>
27 #include <api/video/recordable_encoded_frame.h>
28 #include <api/video/video_frame.h>
29 #include <api/video/video_sink_interface.h>
30 #include <api/video/video_source_interface.h>
31 #include <media/base/media_channel.h>
32 
33 #include "open3d/core/Tensor.h"
34 #include "open3d/utility/Logging.h"
35 
36 namespace open3d {
37 namespace visualization {
38 namespace webrtc_server {
39 
56 class BitmapTrackSourceInterface : public webrtc::VideoTrackSourceInterface {
57 public:
58  virtual void OnFrame(const std::shared_ptr<core::Tensor>& frame) = 0;
59 };
60 
61 class BitmapTrackSource : public webrtc::Notifier<BitmapTrackSourceInterface> {
62 public:
63  explicit BitmapTrackSource(bool remote);
64  void SetState(webrtc::MediaSourceInterface::SourceState new_state);
65  webrtc::MediaSourceInterface::SourceState state() const override {
66  return state_;
67  }
68  bool remote() const override { return remote_; }
69  bool is_screencast() const override { return false; }
70  absl::optional<bool> needs_denoising() const override {
71  return absl::nullopt;
72  }
73  bool GetStats(Stats* stats) override { return false; }
74  void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
75  const rtc::VideoSinkWants& wants) override;
76  void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
77  bool SupportsEncodedOutput() const override { return false; }
78  void GenerateKeyFrame() override {}
79  void AddEncodedSink(rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>*
80  sink) override {}
82  rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>* sink)
83  override {}
84 
85  virtual void OnFrame(const std::shared_ptr<core::Tensor>& frame) override {
86  // Shall be implemented by child class.
87  utility::LogError("BitmapTrackSource::OnFrame called");
88  }
89 
90 protected:
91  virtual rtc::VideoSourceInterface<webrtc::VideoFrame>* source() = 0;
92 
93 private:
94  webrtc::SequenceChecker worker_thread_checker_;
95  webrtc::MediaSourceInterface::SourceState state_;
96  const bool remote_;
97 };
98 
99 } // namespace webrtc_server
100 } // namespace visualization
101 } // namespace open3d
Rect frame
Definition: BitmapWindowSystem.cpp:30
#define LogError(...)
Definition: Logging.h:48
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame) override
Definition: BitmapTrackSource.h:85
bool SupportsEncodedOutput() const override
Definition: BitmapTrackSource.h:77
bool GetStats(Stats *stats) override
Definition: BitmapTrackSource.h:73
void RemoveEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: BitmapTrackSource.h:81
void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
Definition: BitmapTrackSource.cpp:48
absl::optional< bool > needs_denoising() const override
Definition: BitmapTrackSource.h:70
BitmapTrackSource(bool remote)
Definition: BitmapTrackSource.cpp:28
bool remote() const override
Definition: BitmapTrackSource.h:68
void AddEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: BitmapTrackSource.h:79
void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
Definition: BitmapTrackSource.cpp:41
virtual rtc::VideoSourceInterface< webrtc::VideoFrame > * source()=0
void SetState(webrtc::MediaSourceInterface::SourceState new_state)
Definition: BitmapTrackSource.cpp:33
webrtc::MediaSourceInterface::SourceState state() const override
Definition: BitmapTrackSource.h:65
bool is_screencast() const override
Definition: BitmapTrackSource.h:69
void GenerateKeyFrame() override
Definition: BitmapTrackSource.h:78
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame)=0
constexpr nullopt_t nullopt
Definition: Optional.h:152
Definition: PinholeCameraIntrinsic.cpp:16