blob: e54872812e66f88a9893d09bb77876c7c6bd705e [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
11#ifndef WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
13
14#include <string>
15#include <vector>
16
17#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-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.org65f995a2013-04-18 12:02:52 +000022
23namespace webrtc {
24
pbos@webrtc.orgc11148b2013-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.org65f995a2013-04-18 12:02:52 +000034class VideoDecoder;
35
mflodman@webrtc.org65f995a2013-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.orgeceb5322013-05-28 08:04:45 +000039 ExternalVideoDecoder()
40 : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
mflodman@webrtc.org65f995a2013-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.org65f995a2013-04-18 12:02:52 +000058class VideoReceiveStream {
59 public:
pbos@webrtc.org025f4f12013-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.orgfe1ef932013-10-21 10:34:43 +0000101 pre_render_callback(NULL),
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000102 target_delay_ms(0) {}
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000103 // Codecs the receive stream can receive.
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000104 std::vector<VideoCodec> codecs;
105
106 // Receive-stream specific RTP settings.
107 struct Rtp {
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000108 Rtp()
109 : remote_ssrc(0),
110 local_ssrc(0),
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000111 rtcp_mode(newapi::kRtcpReducedSize),
112 remb(false) {}
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
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000122 // See draft-alvestrand-rmcat-remb for information.
123 bool remb;
124
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000125 // See NackConfig for description.
126 NackConfig nack;
127
128 // See FecConfig for description.
129 FecConfig fec;
130
131 // RTX settings for possible payloads. RTX is disabled if the vector is
132 // empty.
133 std::vector<RtxConfig> rtx;
134
135 // RTP header extensions used for the received stream.
136 std::vector<RtpExtension> extensions;
137 } rtp;
138
139 // VideoRenderer will be called for each decoded frame. 'NULL' disables
140 // rendering of this stream.
141 VideoRenderer* renderer;
142
143 // Expected delay needed by the renderer, i.e. the frame will be delivered
144 // this many milliseconds, if possible, earlier than the ideal render time.
145 // Only valid if 'renderer' is set.
146 int render_delay_ms;
147
148 // Audio channel corresponding to this video stream, used for audio/video
149 // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
150 // when creating the VideoEngine instance. '-1' disables a/v sync.
151 int audio_channel_id;
152
153 // Called for each incoming video frame, i.e. in encoded state. E.g. used
154 // when
155 // saving the stream to a file. 'NULL' disables the callback.
156 EncodedFrameObserver* pre_decode_callback;
157
158 // Called for each decoded frame. E.g. used when adding effects to the
159 // decoded
160 // stream. 'NULL' disables the callback.
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000161 I420FrameCallback* pre_render_callback;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000162
163 // External video decoders to be used if incoming payload type matches the
164 // registered type for an external decoder.
165 std::vector<ExternalVideoDecoder> external_decoders;
166
167 // Target delay in milliseconds. A positive value indicates this stream is
168 // used for streaming instead of a real-time call.
169 int target_delay_ms;
170
171 // Callback for periodically receiving receiver stats.
172 StatsCallback* stats_callback;
173 };
174
pbos@webrtc.org53c85732013-11-20 11:36:47 +0000175 virtual void StartReceiving() = 0;
176 virtual void StopReceiving() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000177
178 // TODO(mflodman) Replace this with callback.
179 virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
180
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000181 protected:
182 virtual ~VideoReceiveStream() {}
183};
184
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000185} // namespace webrtc
186
187#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_