pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_VIDEO_RECEIVE_STREAM_H_ |
| 12 | #define VIDEO_VIDEO_RECEIVE_STREAM_H_ |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 13 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 14 | #include <memory> |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "call/rtp_packet_sink_interface.h" |
| 18 | #include "call/syncable.h" |
| 19 | #include "call/video_receive_stream.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
| 21 | #include "modules/rtp_rtcp/include/flexfec_receiver.h" |
| 22 | #include "modules/video_coding/frame_buffer2.h" |
| 23 | #include "modules/video_coding/video_coding_impl.h" |
| 24 | #include "rtc_base/sequenced_task_checker.h" |
| 25 | #include "system_wrappers/include/clock.h" |
| 26 | #include "video/receive_statistics_proxy.h" |
| 27 | #include "video/rtp_streams_synchronizer.h" |
| 28 | #include "video/rtp_video_stream_receiver.h" |
| 29 | #include "video/transport_adapter.h" |
| 30 | #include "video/video_stream_decoder.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
| 33 | |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 34 | class CallStats; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 35 | class IvfFileWriter; |
Peter Boström | d1d66ba | 2016-02-08 14:07:14 +0100 | [diff] [blame] | 36 | class ProcessThread; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 37 | class RTPFragmentationHeader; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 38 | class RtpStreamReceiverInterface; |
| 39 | class RtpStreamReceiverControllerInterface; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 40 | class RtxReceiveStream; |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 41 | class VCMTiming; |
| 42 | class VCMJitterEstimator; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 43 | |
| 44 | namespace internal { |
| 45 | |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 46 | class VideoReceiveStream : public webrtc::VideoReceiveStream, |
nisse | 30f118e | 2016-05-03 01:09:11 -0700 | [diff] [blame] | 47 | public rtc::VideoSinkInterface<VideoFrame>, |
philipel | 83f831a | 2016-03-12 03:30:23 -0800 | [diff] [blame] | 48 | public EncodedImageCallback, |
| 49 | public NackSender, |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 50 | public KeyFrameRequestSender, |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 51 | public video_coding::OnCompleteFrameCallback, |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 52 | public Syncable, |
| 53 | public CallStatsObserver { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 54 | public: |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 55 | VideoReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller, |
| 56 | int num_cpu_cores, |
nisse | 0245da0 | 2016-11-30 03:35:20 -0800 | [diff] [blame] | 57 | PacketRouter* packet_router, |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 58 | VideoReceiveStream::Config config, |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 59 | ProcessThread* process_thread, |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 60 | CallStats* call_stats); |
Jelena Marusic | cd67022 | 2015-07-16 09:30:09 +0200 | [diff] [blame] | 61 | ~VideoReceiveStream() override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 62 | |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 63 | const Config& config() const { return config_; } |
| 64 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 65 | void SignalNetworkState(NetworkState state); |
| 66 | bool DeliverRtcp(const uint8_t* packet, size_t length); |
Jelena Marusic | cd67022 | 2015-07-16 09:30:09 +0200 | [diff] [blame] | 67 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 68 | void SetSync(Syncable* audio_syncable); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 69 | |
| 70 | // Implements webrtc::VideoReceiveStream. |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 71 | void Start() override; |
| 72 | void Stop() override; |
| 73 | |
Jelena Marusic | cd67022 | 2015-07-16 09:30:09 +0200 | [diff] [blame] | 74 | webrtc::VideoReceiveStream::Stats GetStats() const override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 75 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 76 | // Takes ownership of the file, is responsible for closing it later. |
| 77 | // Calling this method will close and finalize any current log. |
| 78 | // Giving rtc::kInvalidPlatformFileValue disables logging. |
| 79 | // If a frame to be written would make the log too large the write fails and |
| 80 | // the log is closed and finalized. A |byte_limit| of 0 means no limit. |
| 81 | void EnableEncodedFrameRecording(rtc::PlatformFile file, |
| 82 | size_t byte_limit) override; |
| 83 | |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 84 | void AddSecondarySink(RtpPacketSinkInterface* sink) override; |
| 85 | void RemoveSecondarySink(const RtpPacketSinkInterface* sink) override; |
| 86 | |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 87 | // Implements rtc::VideoSinkInterface<VideoFrame>. |
| 88 | void OnFrame(const VideoFrame& video_frame) override; |
| 89 | |
| 90 | // Implements EncodedImageCallback. |
| 91 | EncodedImageCallback::Result OnEncodedImage( |
| 92 | const EncodedImage& encoded_image, |
| 93 | const CodecSpecificInfo* codec_specific_info, |
| 94 | const RTPFragmentationHeader* fragmentation) override; |
| 95 | |
| 96 | // Implements NackSender. |
| 97 | void SendNack(const std::vector<uint16_t>& sequence_numbers) override; |
| 98 | |
| 99 | // Implements KeyFrameRequestSender. |
| 100 | void RequestKeyFrame() override; |
| 101 | |
| 102 | // Implements video_coding::OnCompleteFrameCallback. |
| 103 | void OnCompleteFrame( |
philipel | e7c891f | 2018-02-22 14:35:06 +0100 | [diff] [blame] | 104 | std::unique_ptr<video_coding::EncodedFrame> frame) override; |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 105 | |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 106 | // Implements CallStatsObserver::OnRttUpdate |
| 107 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 108 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 109 | // Implements Syncable. |
| 110 | int id() const override; |
| 111 | rtc::Optional<Syncable::Info> GetInfo() const override; |
| 112 | uint32_t GetPlayoutTimestamp() const override; |
| 113 | void SetMinimumPlayoutDelay(int delay_ms) override; |
| 114 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 115 | private: |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 116 | static void DecodeThreadFunction(void* ptr); |
philipel | 2dfea3e | 2017-02-28 07:19:43 -0800 | [diff] [blame] | 117 | bool Decode(); |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 118 | |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 119 | rtc::SequencedTaskChecker worker_sequence_checker_; |
| 120 | rtc::SequencedTaskChecker module_process_sequence_checker_; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 121 | |
pbos@webrtc.org | e75a1bf | 2013-09-18 11:52:42 +0000 | [diff] [blame] | 122 | TransportAdapter transport_adapter_; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 123 | const VideoReceiveStream::Config config_; |
sprang | 113bdca | 2016-10-11 03:10:10 -0700 | [diff] [blame] | 124 | const int num_cpu_cores_; |
Peter Boström | 1d04ac6 | 2016-02-05 11:25:46 +0100 | [diff] [blame] | 125 | ProcessThread* const process_thread_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 126 | Clock* const clock_; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 127 | |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 128 | rtc::PlatformThread decode_thread_; |
| 129 | |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 130 | CallStats* const call_stats_; |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 131 | |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 132 | // Shared by media and rtx stream receivers, since the latter has no RtpRtcp |
| 133 | // module of its own. |
| 134 | const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; |
| 135 | |
philipel | 721d402 | 2016-12-15 07:10:57 -0800 | [diff] [blame] | 136 | std::unique_ptr<VCMTiming> timing_; // Jitter buffer experiment. |
Peter Boström | 0b25072 | 2016-04-22 18:23:15 +0200 | [diff] [blame] | 137 | vcm::VideoReceiver video_receiver_; |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 138 | std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> incoming_video_stream_; |
Peter Boström | f751bf8 | 2016-02-05 14:00:53 +0100 | [diff] [blame] | 139 | ReceiveStatisticsProxy stats_proxy_; |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 140 | RtpVideoStreamReceiver rtp_video_stream_receiver_; |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 141 | std::unique_ptr<VideoStreamDecoder> video_stream_decoder_; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 142 | RtpStreamsSynchronizer rtp_stream_sync_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 143 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 144 | rtc::CriticalSection ivf_writer_lock_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 145 | std::unique_ptr<IvfFileWriter> ivf_writer_ RTC_GUARDED_BY(ivf_writer_lock_); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 146 | |
| 147 | // Members for the new jitter buffer experiment. |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 148 | std::unique_ptr<VCMJitterEstimator> jitter_estimator_; |
| 149 | std::unique_ptr<video_coding::FrameBuffer> frame_buffer_; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 150 | |
| 151 | std::unique_ptr<RtpStreamReceiverInterface> media_receiver_; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 152 | std::unique_ptr<RtxReceiveStream> rtx_receive_stream_; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 153 | std::unique_ptr<RtpStreamReceiverInterface> rtx_receiver_; |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 154 | |
| 155 | // Whenever we are in an undecodable state (stream has just started or due to |
| 156 | // a decoding error) we require a keyframe to restart the stream. |
| 157 | bool keyframe_required_ = true; |
| 158 | |
| 159 | // If we have successfully decoded any frame. |
| 160 | bool frame_decoded_ = false; |
philipel | 48462b6 | 2017-09-26 02:54:58 -0700 | [diff] [blame] | 161 | |
| 162 | int64_t last_keyframe_request_ms_ = 0; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 163 | }; |
mflodman@webrtc.org | f3973e8 | 2013-12-13 09:40:45 +0000 | [diff] [blame] | 164 | } // namespace internal |
| 165 | } // namespace webrtc |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 166 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 167 | #endif // VIDEO_VIDEO_RECEIVE_STREAM_H_ |