Line data Source code
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 :
11 : #ifndef WEBRTC_VIDEO_VIDEO_RECEIVE_STREAM_H_
12 : #define WEBRTC_VIDEO_VIDEO_RECEIVE_STREAM_H_
13 :
14 : #include <memory>
15 : #include <vector>
16 :
17 : #include "webrtc/common_video/include/incoming_video_stream.h"
18 : #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
19 : #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h"
20 : #include "webrtc/modules/video_coding/frame_buffer2.h"
21 : #include "webrtc/modules/video_coding/video_coding_impl.h"
22 : #include "webrtc/system_wrappers/include/clock.h"
23 : #include "webrtc/video/receive_statistics_proxy.h"
24 : #include "webrtc/video/rtp_stream_receiver.h"
25 : #include "webrtc/video/rtp_streams_synchronizer.h"
26 : #include "webrtc/video/transport_adapter.h"
27 : #include "webrtc/video/video_stream_decoder.h"
28 : #include "webrtc/video_receive_stream.h"
29 :
30 : namespace webrtc {
31 :
32 : class CallStats;
33 : class CongestionController;
34 : class IvfFileWriter;
35 : class ProcessThread;
36 : class RTPFragmentationHeader;
37 : class VoiceEngine;
38 : class VieRemb;
39 : class VCMTiming;
40 : class VCMJitterEstimator;
41 :
42 : namespace internal {
43 :
44 : class VideoReceiveStream : public webrtc::VideoReceiveStream,
45 : public rtc::VideoSinkInterface<VideoFrame>,
46 : public EncodedImageCallback,
47 : public NackSender,
48 : public KeyFrameRequestSender,
49 : public video_coding::OnCompleteFrameCallback {
50 : public:
51 : VideoReceiveStream(int num_cpu_cores,
52 : CongestionController* congestion_controller,
53 : PacketRouter* packet_router,
54 : VideoReceiveStream::Config config,
55 : webrtc::VoiceEngine* voice_engine,
56 : ProcessThread* process_thread,
57 : CallStats* call_stats,
58 : VieRemb* remb);
59 : ~VideoReceiveStream() override;
60 :
61 : void SignalNetworkState(NetworkState state);
62 : bool DeliverRtcp(const uint8_t* packet, size_t length);
63 : bool DeliverRtp(const uint8_t* packet,
64 : size_t length,
65 : const PacketTime& packet_time);
66 :
67 : bool OnRecoveredPacket(const uint8_t* packet, size_t length);
68 :
69 : // webrtc::VideoReceiveStream implementation.
70 : void Start() override;
71 : void Stop() override;
72 :
73 : webrtc::VideoReceiveStream::Stats GetStats() const override;
74 :
75 : // Overrides rtc::VideoSinkInterface<VideoFrame>.
76 : void OnFrame(const VideoFrame& video_frame) override;
77 :
78 : // Implements video_coding::OnCompleteFrameCallback.
79 : void OnCompleteFrame(
80 : std::unique_ptr<video_coding::FrameObject> frame) override;
81 :
82 : // Overrides EncodedImageCallback.
83 : EncodedImageCallback::Result OnEncodedImage(
84 : const EncodedImage& encoded_image,
85 : const CodecSpecificInfo* codec_specific_info,
86 : const RTPFragmentationHeader* fragmentation) override;
87 :
88 0 : const Config& config() const { return config_; }
89 :
90 : void SetSyncChannel(VoiceEngine* voice_engine, int audio_channel_id) override;
91 :
92 : // Implements NackSender.
93 : void SendNack(const std::vector<uint16_t>& sequence_numbers) override;
94 :
95 : // Implements KeyFrameRequestSender.
96 : void RequestKeyFrame() override;
97 :
98 : // Takes ownership of the file, is responsible for closing it later.
99 : // Calling this method will close and finalize any current log.
100 : // Giving rtc::kInvalidPlatformFileValue disables logging.
101 : // If a frame to be written would make the log too large the write fails and
102 : // the log is closed and finalized. A |byte_limit| of 0 means no limit.
103 : void EnableEncodedFrameRecording(rtc::PlatformFile file,
104 : size_t byte_limit) override;
105 :
106 :
107 : bool GetRemoteRTCPSenderInfo(RTCPSenderInfo* sender_info) const override;
108 : private:
109 : static bool DecodeThreadFunction(void* ptr);
110 : void Decode();
111 :
112 : TransportAdapter transport_adapter_;
113 : const VideoReceiveStream::Config config_;
114 : const int num_cpu_cores_;
115 : ProcessThread* const process_thread_;
116 : Clock* const clock_;
117 :
118 : rtc::PlatformThread decode_thread_;
119 :
120 : CongestionController* const congestion_controller_;
121 : CallStats* const call_stats_;
122 :
123 : std::unique_ptr<VCMTiming> timing_; // Jitter buffer experiment.
124 : vcm::VideoReceiver video_receiver_;
125 : std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> incoming_video_stream_;
126 : ReceiveStatisticsProxy stats_proxy_;
127 : RtpStreamReceiver rtp_stream_receiver_;
128 : std::unique_ptr<VideoStreamDecoder> video_stream_decoder_;
129 : RtpStreamsSynchronizer rtp_stream_sync_;
130 :
131 : rtc::CriticalSection ivf_writer_lock_;
132 : std::unique_ptr<IvfFileWriter> ivf_writer_ GUARDED_BY(ivf_writer_lock_);
133 :
134 : // Members for the new jitter buffer experiment.
135 : const bool jitter_buffer_experiment_;
136 : std::unique_ptr<VCMJitterEstimator> jitter_estimator_;
137 : std::unique_ptr<video_coding::FrameBuffer> frame_buffer_;
138 : };
139 : } // namespace internal
140 : } // namespace webrtc
141 :
142 : #endif // WEBRTC_VIDEO_VIDEO_RECEIVE_STREAM_H_
|