blob: 0f2151df03e2e8ffa84d883f1007c4ff188e1336 [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.
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000029enum RtcpMode { kRtcpCompound, kRtcpReducedSize };
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000030} // namespace newapi
31
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000032class VideoDecoder;
33
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000034class VideoReceiveStream {
35 public:
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000036 // TODO(mflodman) Move all these settings to VideoDecoder and move the
37 // declaration to common_types.h.
38 struct Decoder {
39 Decoder()
40 : decoder(NULL),
41 payload_type(0),
pbos@webrtc.org32e85282015-01-15 10:09:39 +000042 is_renderer(false),
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000043 expected_delay_ms(0) {}
pbos@webrtc.org32e85282015-01-15 10:09:39 +000044 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000045
46 // The actual decoder instance.
47 VideoDecoder* decoder;
48
49 // Received RTP packets with this payload type will be sent to this decoder
50 // instance.
51 int payload_type;
52
53 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
54 // used to unpack incoming packets.
55 std::string payload_name;
56
57 // 'true' if the decoder handles rendering as well.
pbos@webrtc.org32e85282015-01-15 10:09:39 +000058 bool is_renderer;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000059
60 // The expected delay for decoding and rendering, i.e. the frame will be
61 // delivered this many milliseconds, if possible, earlier than the ideal
62 // render time.
63 // Note: Ignored if 'renderer' is false.
64 int expected_delay_ms;
65 };
66
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000067 struct Stats {
68 int network_frame_rate = 0;
69 int decode_frame_rate = 0;
70 int render_frame_rate = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000071
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000072 // Decoder stats.
73 FrameCounts frame_counts;
74 int decode_ms = 0;
75 int max_decode_ms = 0;
76 int current_delay_ms = 0;
77 int target_delay_ms = 0;
78 int jitter_buffer_ms = 0;
79 int min_playout_delay_ms = 0;
80 int render_delay_ms = 0;
81
82 int total_bitrate_bps = 0;
83 int discarded_packets = 0;
84
85 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000086 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000087 StreamDataCounters rtp_stats;
88 RtcpPacketTypeCounter rtcp_packet_type_counts;
89 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000090 };
91
92 struct Config {
93 Config()
94 : renderer(NULL),
95 render_delay_ms(0),
pbos@webrtc.org3bf3d232014-10-31 12:59:34 +000096 audio_channel_id(-1),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000097 pre_decode_callback(NULL),
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +000098 pre_render_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000099 target_delay_ms(0) {}
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000100 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000101
102 // Decoders for every payload that we can receive.
103 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000104
105 // Receive-stream specific RTP settings.
106 struct Rtp {
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000107 Rtp()
108 : remote_ssrc(0),
109 local_ssrc(0),
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000110 rtcp_mode(newapi::kRtcpReducedSize),
pbos@webrtc.orgbd249bc2014-07-07 04:45:15 +0000111 remb(true) {}
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000112 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000113
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000114 // Synchronization source (stream identifier) to be received.
115 uint32_t remote_ssrc;
116 // Sender SSRC used for sending RTCP (such as receiver reports).
117 uint32_t local_ssrc;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000118
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000119 // See RtcpMode for description.
120 newapi::RtcpMode rtcp_mode;
121
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000122 // Extended RTCP settings.
123 struct RtcpXr {
124 RtcpXr() : receiver_reference_time_report(false) {}
125
126 // True if RTCP Receiver Reference Time Report Block extension
127 // (RFC 3611) should be enabled.
128 bool receiver_reference_time_report;
129 } rtcp_xr;
130
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000131 // See draft-alvestrand-rmcat-remb for information.
132 bool remb;
133
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000134 // See NackConfig for description.
135 NackConfig nack;
136
137 // See FecConfig for description.
138 FecConfig fec;
139
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000140 // RTX settings for incoming video payloads that may be received. RTX is
141 // disabled if there's no config present.
142 struct Rtx {
143 Rtx() : ssrc(0), payload_type(0) {}
144
145 // SSRCs to use for the RTX streams.
146 uint32_t ssrc;
147
148 // Payload type to use for the RTX stream.
149 int payload_type;
150 };
151
152 // Map from video RTP payload type -> RTX config.
153 typedef std::map<int, Rtx> RtxMap;
154 RtxMap rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000155
156 // RTP header extensions used for the received stream.
157 std::vector<RtpExtension> extensions;
158 } rtp;
159
160 // VideoRenderer will be called for each decoded frame. 'NULL' disables
161 // rendering of this stream.
162 VideoRenderer* renderer;
163
164 // Expected delay needed by the renderer, i.e. the frame will be delivered
165 // this many milliseconds, if possible, earlier than the ideal render time.
166 // Only valid if 'renderer' is set.
167 int render_delay_ms;
168
169 // Audio channel corresponding to this video stream, used for audio/video
170 // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
171 // when creating the VideoEngine instance. '-1' disables a/v sync.
172 int audio_channel_id;
173
174 // Called for each incoming video frame, i.e. in encoded state. E.g. used
175 // when
176 // saving the stream to a file. 'NULL' disables the callback.
177 EncodedFrameObserver* pre_decode_callback;
178
179 // Called for each decoded frame. E.g. used when adding effects to the
180 // decoded
181 // stream. 'NULL' disables the callback.
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000182 I420FrameCallback* pre_render_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000183
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000184 // Target delay in milliseconds. A positive value indicates this stream is
185 // used for streaming instead of a real-time call.
186 int target_delay_ms;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000187 };
188
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21 +0000189 virtual void Start() = 0;
190 virtual void Stop() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000191
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000192 // TODO(pbos): Add info on currently-received codec to Stats.
193 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000194
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000195 protected:
196 virtual ~VideoReceiveStream() {}
197};
198
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000199} // namespace webrtc
200
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000201#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_