ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
BitmapTrackSource.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 // 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 CloudViewer's public API.
20 // Do not put this in CloudViewer.h.in.
21 
22 #pragma once
23 
24 #include <Logging.h>
25 #include <absl/types/optional.h>
26 #include <api/notifier.h>
27 #include <api/sequence_checker.h>
28 #include <api/video/recordable_encoded_frame.h>
29 #include <api/video/video_frame.h>
30 #include <api/video/video_sink_interface.h>
31 #include <api/video/video_source_interface.h>
32 #include <media/base/media_channel.h>
33 
34 #include "core/Tensor.h"
35 
36 namespace cloudViewer {
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 cloudViewer
Rect frame
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame)=0
webrtc::MediaSourceInterface::SourceState state() const override
void AddEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
void SetState(webrtc::MediaSourceInterface::SourceState new_state)
absl::optional< bool > needs_denoising() const override
void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
virtual void OnFrame(const std::shared_ptr< core::Tensor > &frame) override
virtual rtc::VideoSourceInterface< webrtc::VideoFrame > * source()=0
void RemoveEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
#define LogError(...)
Definition: Logging.h:60
constexpr nullopt_t nullopt
Definition: Optional.h:136
Generic file read and write utility for python interface.