blob: ac1afc694ee7c3fde3069b4c363eb0e9fd24e0ec [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +00001/*
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
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_RECEIVE_STREAM_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000013
pbos@webrtc.orge02d4752014-01-20 14:43:55 +000014#include <map>
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000015#include <string>
16#include <vector>
17
18#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000019#include "webrtc/config.h"
20#include "webrtc/frame_callback.h"
21#include "webrtc/transport.h"
22#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000023
24namespace webrtc {
25
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000026namespace newapi {
27// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
28// RTCP mode is described by RFC 5506.
29enum RtcpMode {
30 kRtcpCompound,
31 kRtcpReducedSize
32};
33} // namespace newapi
34
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000035class VideoDecoder;
36
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000037// TODO(mflodman) Move all these settings to VideoDecoder and move the
38// declaration to common_types.h.
39struct ExternalVideoDecoder {
pbos@webrtc.orgeceb5322013-05-28 08:04:45 +000040 ExternalVideoDecoder()
41 : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000042 // The actual decoder.
43 VideoDecoder* decoder;
44
45 // Received RTP packets with this payload type will be sent to this decoder
46 // instance.
47 int payload_type;
48
49 // 'true' if the decoder handles rendering as well.
50 bool renderer;
51
52 // The expected delay for decoding and rendering, i.e. the frame will be
53 // delivered this many milliseconds, if possible, earlier than the ideal
54 // render time.
55 // Note: Ignored if 'renderer' is false.
56 int expected_delay_ms;
57};
58
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000059class VideoReceiveStream {
60 public:
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000061 struct Stats {
62 Stats()
63 : network_frame_rate(0),
64 decode_frame_rate(0),
65 render_frame_rate(0),
66 key_frames(0),
67 delta_frames(0),
68 video_packets(0),
69 retransmitted_packets(0),
70 fec_packets(0),
71 padding_packets(0),
72 discarded_packets(0),
73 received_bitrate_bps(0),
74 receive_side_delay_ms(0) {}
75 RtpStatistics rtp_stats;
76 int network_frame_rate;
77 int decode_frame_rate;
78 int render_frame_rate;
79 uint32_t key_frames;
80 uint32_t delta_frames;
81 uint32_t video_packets;
82 uint32_t retransmitted_packets;
83 uint32_t fec_packets;
84 uint32_t padding_packets;
85 uint32_t discarded_packets;
86 int32_t received_bitrate_bps;
87 int receive_side_delay_ms;
88 };
89
90 class StatsCallback {
91 public:
92 virtual ~StatsCallback() {}
93 virtual void ReceiveStats(const Stats& stats) = 0;
94 };
95
96 struct Config {
97 Config()
98 : renderer(NULL),
99 render_delay_ms(0),
100 audio_channel_id(0),
101 pre_decode_callback(NULL),
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000102 pre_render_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000103 target_delay_ms(0) {}
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000104 // Codecs the receive stream can receive.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000105 std::vector<VideoCodec> codecs;
106
107 // Receive-stream specific RTP settings.
108 struct Rtp {
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000109 Rtp()
110 : remote_ssrc(0),
111 local_ssrc(0),
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000112 rtcp_mode(newapi::kRtcpReducedSize),
113 remb(false) {}
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000114
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000115 // Synchronization source (stream identifier) to be received.
116 uint32_t remote_ssrc;
117 // Sender SSRC used for sending RTCP (such as receiver reports).
118 uint32_t local_ssrc;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000119
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000120 // See RtcpMode for description.
121 newapi::RtcpMode rtcp_mode;
122
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000123 // Extended RTCP settings.
124 struct RtcpXr {
125 RtcpXr() : receiver_reference_time_report(false) {}
126
127 // True if RTCP Receiver Reference Time Report Block extension
128 // (RFC 3611) should be enabled.
129 bool receiver_reference_time_report;
130 } rtcp_xr;
131
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000132 // See draft-alvestrand-rmcat-remb for information.
133 bool remb;
134
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000135 // See NackConfig for description.
136 NackConfig nack;
137
138 // See FecConfig for description.
139 FecConfig fec;
140
pbos@webrtc.orge02d4752014-01-20 14:43:55 +0000141 // RTX settings for video payloads that may be received. RTX is disabled
142 // if there's no config present.
143 std::map<int, RtxConfig> rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000144
145 // RTP header extensions used for the received stream.
146 std::vector<RtpExtension> extensions;
147 } rtp;
148
149 // VideoRenderer will be called for each decoded frame. 'NULL' disables
150 // rendering of this stream.
151 VideoRenderer* renderer;
152
153 // Expected delay needed by the renderer, i.e. the frame will be delivered
154 // this many milliseconds, if possible, earlier than the ideal render time.
155 // Only valid if 'renderer' is set.
156 int render_delay_ms;
157
158 // Audio channel corresponding to this video stream, used for audio/video
159 // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
160 // when creating the VideoEngine instance. '-1' disables a/v sync.
161 int audio_channel_id;
162
163 // Called for each incoming video frame, i.e. in encoded state. E.g. used
164 // when
165 // saving the stream to a file. 'NULL' disables the callback.
166 EncodedFrameObserver* pre_decode_callback;
167
168 // Called for each decoded frame. E.g. used when adding effects to the
169 // decoded
170 // stream. 'NULL' disables the callback.
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000171 I420FrameCallback* pre_render_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000172
173 // External video decoders to be used if incoming payload type matches the
174 // registered type for an external decoder.
175 std::vector<ExternalVideoDecoder> external_decoders;
176
177 // Target delay in milliseconds. A positive value indicates this stream is
178 // used for streaming instead of a real-time call.
179 int target_delay_ms;
180
181 // Callback for periodically receiving receiver stats.
182 StatsCallback* stats_callback;
183 };
184
pbos@webrtc.org53c85732013-11-20 11:36:47 +0000185 virtual void StartReceiving() = 0;
186 virtual void StopReceiving() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000187
188 // TODO(mflodman) Replace this with callback.
189 virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
190
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000191 protected:
192 virtual ~VideoReceiveStream() {}
193};
194
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000195} // namespace webrtc
196
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000197#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_