blob: 55e5a626ae1a0e396b1e8b53c49712f895c03028 [file] [log] [blame]
mflodman@webrtc.org06e80262013-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.org5e0cbcf2013-12-18 09:46:22 +000011#ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_RECEIVE_STREAM_H_
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000013
14#include <string>
15#include <vector>
16
17#include "webrtc/common_types.h"
pbos@webrtc.org24e20892013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/transport.h"
21#include "webrtc/video_renderer.h"
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000022
23namespace webrtc {
24
pbos@webrtc.org51e01012013-10-17 14:14:42 +000025namespace newapi {
26// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
27// RTCP mode is described by RFC 5506.
28enum RtcpMode {
29 kRtcpCompound,
30 kRtcpReducedSize
31};
32} // namespace newapi
33
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000034class VideoDecoder;
35
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000036// TODO(mflodman) Move all these settings to VideoDecoder and move the
37// declaration to common_types.h.
38struct ExternalVideoDecoder {
pbos@webrtc.orgb2d1a402013-05-28 08:04:45 +000039 ExternalVideoDecoder()
40 : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000041 // The actual decoder.
42 VideoDecoder* decoder;
43
44 // Received RTP packets with this payload type will be sent to this decoder
45 // instance.
46 int payload_type;
47
48 // 'true' if the decoder handles rendering as well.
49 bool renderer;
50
51 // The expected delay for decoding and rendering, i.e. the frame will be
52 // delivered this many milliseconds, if possible, earlier than the ideal
53 // render time.
54 // Note: Ignored if 'renderer' is false.
55 int expected_delay_ms;
56};
57
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000058class VideoReceiveStream {
59 public:
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000060 struct Stats {
61 Stats()
62 : network_frame_rate(0),
63 decode_frame_rate(0),
64 render_frame_rate(0),
65 key_frames(0),
66 delta_frames(0),
67 video_packets(0),
68 retransmitted_packets(0),
69 fec_packets(0),
70 padding_packets(0),
71 discarded_packets(0),
72 received_bitrate_bps(0),
73 receive_side_delay_ms(0) {}
74 RtpStatistics rtp_stats;
75 int network_frame_rate;
76 int decode_frame_rate;
77 int render_frame_rate;
78 uint32_t key_frames;
79 uint32_t delta_frames;
80 uint32_t video_packets;
81 uint32_t retransmitted_packets;
82 uint32_t fec_packets;
83 uint32_t padding_packets;
84 uint32_t discarded_packets;
85 int32_t received_bitrate_bps;
86 int receive_side_delay_ms;
87 };
88
89 class StatsCallback {
90 public:
91 virtual ~StatsCallback() {}
92 virtual void ReceiveStats(const Stats& stats) = 0;
93 };
94
95 struct Config {
96 Config()
97 : renderer(NULL),
98 render_delay_ms(0),
99 audio_channel_id(0),
100 pre_decode_callback(NULL),
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000101 pre_render_callback(NULL),
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000102 target_delay_ms(0) {}
pbos@webrtc.orgce851092013-08-05 12:01:36 +0000103 // Codecs the receive stream can receive.
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000104 std::vector<VideoCodec> codecs;
105
106 // Receive-stream specific RTP settings.
107 struct Rtp {
pbos@webrtc.org4b50db12013-12-03 10:13:04 +0000108 Rtp()
109 : remote_ssrc(0),
110 local_ssrc(0),
mflodman@webrtc.org7ff40892013-12-13 16:36:28 +0000111 rtcp_mode(newapi::kRtcpReducedSize),
112 remb(false) {}
pbos@webrtc.org51e01012013-10-17 14:14:42 +0000113
pbos@webrtc.org4b50db12013-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.org6f1c3ef2013-06-05 11:33:21 +0000118
pbos@webrtc.org51e01012013-10-17 14:14:42 +0000119 // See RtcpMode for description.
120 newapi::RtcpMode rtcp_mode;
121
asapersson@webrtc.orgb4263e02014-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.org7ff40892013-12-13 16:36:28 +0000131 // See draft-alvestrand-rmcat-remb for information.
132 bool remb;
133
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000134 // See NackConfig for description.
135 NackConfig nack;
136
137 // See FecConfig for description.
138 FecConfig fec;
139
140 // RTX settings for possible payloads. RTX is disabled if the vector is
141 // empty.
142 std::vector<RtxConfig> rtx;
143
144 // RTP header extensions used for the received stream.
145 std::vector<RtpExtension> extensions;
146 } rtp;
147
148 // VideoRenderer will be called for each decoded frame. 'NULL' disables
149 // rendering of this stream.
150 VideoRenderer* renderer;
151
152 // Expected delay needed by the renderer, i.e. the frame will be delivered
153 // this many milliseconds, if possible, earlier than the ideal render time.
154 // Only valid if 'renderer' is set.
155 int render_delay_ms;
156
157 // Audio channel corresponding to this video stream, used for audio/video
158 // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
159 // when creating the VideoEngine instance. '-1' disables a/v sync.
160 int audio_channel_id;
161
162 // Called for each incoming video frame, i.e. in encoded state. E.g. used
163 // when
164 // saving the stream to a file. 'NULL' disables the callback.
165 EncodedFrameObserver* pre_decode_callback;
166
167 // Called for each decoded frame. E.g. used when adding effects to the
168 // decoded
169 // stream. 'NULL' disables the callback.
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000170 I420FrameCallback* pre_render_callback;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000171
172 // External video decoders to be used if incoming payload type matches the
173 // registered type for an external decoder.
174 std::vector<ExternalVideoDecoder> external_decoders;
175
176 // Target delay in milliseconds. A positive value indicates this stream is
177 // used for streaming instead of a real-time call.
178 int target_delay_ms;
179
180 // Callback for periodically receiving receiver stats.
181 StatsCallback* stats_callback;
182 };
183
pbos@webrtc.org7f9f8402013-11-20 11:36:47 +0000184 virtual void StartReceiving() = 0;
185 virtual void StopReceiving() = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000186
187 // TODO(mflodman) Replace this with callback.
188 virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
189
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000190 protected:
191 virtual ~VideoReceiveStream() {}
192};
193
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000194} // namespace webrtc
195
mflodman@webrtc.org5e0cbcf2013-12-18 09:46:22 +0000196#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_