Open3D (C++ API)  0.16.1
BitmapTrackSource.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26// ----------------------------------------------------------------------------
27// Modified from: WebRTC src/pc/video_track_source.h
28//
29// Copyright 2016 The WebRTC project authors. All Rights Reserved.
30//
31// Use of this source code is governed by a BSD-style license
32// that can be found in the LICENSE file in the root of the source
33// tree. An additional intellectual property rights grant can be found
34// in the file PATENTS. All contributing project authors may
35// be found in the AUTHORS file in the root of the source tree.
36// ----------------------------------------------------------------------------
37//
38// This is a private header. It shall be hidden from Open3D's public API. Do not
39// put this in Open3D.h.in.
40
41#pragma once
42
43#include <absl/types/optional.h>
44#include <api/notifier.h>
45#include <api/sequence_checker.h>
46#include <api/video/recordable_encoded_frame.h>
47#include <api/video/video_frame.h>
48#include <api/video/video_sink_interface.h>
49#include <api/video/video_source_interface.h>
50#include <media/base/media_channel.h>
51
52#include "open3d/core/Tensor.h"
54
55namespace open3d {
56namespace visualization {
57namespace webrtc_server {
58
75class BitmapTrackSourceInterface : public webrtc::VideoTrackSourceInterface {
76public:
77 virtual void OnFrame(const std::shared_ptr<core::Tensor>& frame) = 0;
78};
79
80class BitmapTrackSource : public webrtc::Notifier<BitmapTrackSourceInterface> {
81public:
82 explicit BitmapTrackSource(bool remote);
83 void SetState(webrtc::MediaSourceInterface::SourceState new_state);
84 webrtc::MediaSourceInterface::SourceState state() const override {
85 return state_;
86 }
87 bool remote() const override { return remote_; }
88 bool is_screencast() const override { return false; }
89 absl::optional<bool> needs_denoising() const override {
90 return absl::nullopt;
91 }
92 bool GetStats(Stats* stats) override { return false; }
93 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
94 const rtc::VideoSinkWants& wants) override;
95 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
96 bool SupportsEncodedOutput() const override { return false; }
97 void GenerateKeyFrame() override {}
98 void AddEncodedSink(rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>*
99 sink) override {}
101 rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>* sink)
102 override {}
103
104 virtual void OnFrame(const std::shared_ptr<core::Tensor>& frame) override {
105 // Shall be implemented by child class.
106 utility::LogError("BitmapTrackSource::OnFrame called");
107 }
108
109protected:
110 virtual rtc::VideoSourceInterface<webrtc::VideoFrame>* source() = 0;
111
112private:
113 webrtc::SequenceChecker worker_thread_checker_;
114 webrtc::MediaSourceInterface::SourceState state_;
115 const bool remote_;
116};
117
118} // namespace webrtc_server
119} // namespace visualization
120} // namespace open3d
Rect frame
Definition: BitmapWindowSystem.cpp:49
#define LogError(...)
Definition: Logging.h:67
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame) override
Definition: BitmapTrackSource.h:104
bool SupportsEncodedOutput() const override
Definition: BitmapTrackSource.h:96
bool GetStats(Stats *stats) override
Definition: BitmapTrackSource.h:92
void RemoveEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: BitmapTrackSource.h:100
void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
Definition: BitmapTrackSource.cpp:67
BitmapTrackSource(bool remote)
Definition: BitmapTrackSource.cpp:47
bool remote() const override
Definition: BitmapTrackSource.h:87
virtual rtc::VideoSourceInterface< webrtc::VideoFrame > * source()=0
absl::optional< bool > needs_denoising() const override
Definition: BitmapTrackSource.h:89
void AddEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: BitmapTrackSource.h:98
void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
Definition: BitmapTrackSource.cpp:60
void SetState(webrtc::MediaSourceInterface::SourceState new_state)
Definition: BitmapTrackSource.cpp:52
webrtc::MediaSourceInterface::SourceState state() const override
Definition: BitmapTrackSource.h:84
bool is_screencast() const override
Definition: BitmapTrackSource.h:88
void GenerateKeyFrame() override
Definition: BitmapTrackSource.h:97
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame)=0
constexpr nullopt_t nullopt
Definition: Optional.h:171
Definition: PinholeCameraIntrinsic.cpp:35