Android-cuttlefish cvd tool
video_track_source_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <media/base/video_broadcaster.h>
20#include <pc/video_track_source.h>
21
23
24namespace cuttlefish {
25namespace webrtc_streaming {
26
27class VideoTrackSourceImpl : public webrtc::VideoTrackSource {
28 public:
29 VideoTrackSourceImpl(int width, int height);
30
31 void OnFrame(std::shared_ptr<VideoFrameBuffer> frame, int64_t timestamp_us);
32
33 // Returns false if no stats are available, e.g, for a remote source, or a
34 // source which has not seen its first frame yet.
35 //
36 // Implementation should avoid blocking.
37 bool GetStats(Stats* stats) override;
38
39 bool SupportsEncodedOutput() const override;
40 void GenerateKeyFrame() override {}
42 rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>* sink) override {}
44 rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>* sink) override {}
45
46 rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override;
47
48 private:
49 int width_;
51 rtc::VideoBroadcaster broadcaster_;
52};
53
54// Wraps a VideoTrackSourceImpl as an implementation of the VideoSink interface.
55// This is needed as the VideoTrackSourceImpl is a reference counted object that
56// should only be referenced by rtc::scoped_refptr pointers, but the
57// VideoSink interface is not a reference counted object and therefore not
58// compatible with that kind of pointers. This class can be referenced by a
59// shared pointer and it in turn holds a scoped_refptr to the wrapped object.
61 public:
63
64 VideoTrackSourceImplSinkWrapper(rtc::scoped_refptr<VideoTrackSourceImpl> obj)
65 : track_source_impl_(obj) {}
66
67 void OnFrame(std::shared_ptr<VideoFrameBuffer> frame,
68 int64_t timestamp_us) override {
69 track_source_impl_->OnFrame(frame, timestamp_us);
70 }
71
72 private:
73 rtc::scoped_refptr<VideoTrackSourceImpl> track_source_impl_;
74};
75
76} // namespace webrtc_streaming
77} // namespace cuttlefish
Definition: video_sink.h:26
rtc::scoped_refptr< VideoTrackSourceImpl > track_source_impl_
Definition: video_track_source_impl.h:73
void OnFrame(std::shared_ptr< VideoFrameBuffer > frame, int64_t timestamp_us) override
Definition: video_track_source_impl.h:67
VideoTrackSourceImplSinkWrapper(rtc::scoped_refptr< VideoTrackSourceImpl > obj)
Definition: video_track_source_impl.h:64
Definition: video_track_source_impl.h:27
void GenerateKeyFrame() override
Definition: video_track_source_impl.h:40
void OnFrame(std::shared_ptr< VideoFrameBuffer > frame, int64_t timestamp_us)
Definition: video_track_source_impl.cpp:55
VideoTrackSourceImpl(int width, int height)
Definition: video_track_source_impl.cpp:52
int width_
Definition: video_track_source_impl.h:49
void RemoveEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: video_track_source_impl.h:43
rtc::VideoSourceInterface< webrtc::VideoFrame > * source() override
Definition: video_track_source_impl.cpp:73
void AddEncodedSink(rtc::VideoSinkInterface< webrtc::RecordableEncodedFrame > *sink) override
Definition: video_track_source_impl.h:41
rtc::VideoBroadcaster broadcaster_
Definition: video_track_source_impl.h:51
bool GetStats(Stats *stats) override
Definition: video_track_source_impl.cpp:66
int height_
Definition: video_track_source_impl.h:50
bool SupportsEncodedOutput() const override
Definition: video_track_source_impl.cpp:72
Definition: alloc_utils.cpp:23