blob: 955d87569bdc266ac836fd8611fb3f48f2d2b87a [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"
Jelena Marusiccd670222015-07-16 09:30:09 +020021#include "webrtc/stream.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000022#include "webrtc/transport.h"
23#include "webrtc/video_renderer.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000024
25namespace webrtc {
26
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000027namespace newapi {
28// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
29// RTCP mode is described by RFC 5506.
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000030enum RtcpMode { kRtcpCompound, kRtcpReducedSize };
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000031} // namespace newapi
32
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000033class VideoDecoder;
34
Jelena Marusiccd670222015-07-16 09:30:09 +020035class VideoReceiveStream : public ReceiveStream {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000036 public:
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000037 // TODO(mflodman) Move all these settings to VideoDecoder and move the
38 // declaration to common_types.h.
39 struct Decoder {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000040 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000041
42 // The actual decoder instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020043 VideoDecoder* decoder = nullptr;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000044
45 // Received RTP packets with this payload type will be sent to this decoder
46 // instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020047 int payload_type = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000048
49 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
50 // used to unpack incoming packets.
51 std::string payload_name;
52
53 // 'true' if the decoder handles rendering as well.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020054 bool is_renderer = false;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000055
56 // The expected delay for decoding and rendering, i.e. the frame will be
57 // delivered this many milliseconds, if possible, earlier than the ideal
58 // render time.
59 // Note: Ignored if 'renderer' is false.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020060 int expected_delay_ms = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000061 };
62
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000063 struct Stats {
64 int network_frame_rate = 0;
65 int decode_frame_rate = 0;
66 int render_frame_rate = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000067
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000068 // Decoder stats.
69 FrameCounts frame_counts;
70 int decode_ms = 0;
71 int max_decode_ms = 0;
72 int current_delay_ms = 0;
73 int target_delay_ms = 0;
74 int jitter_buffer_ms = 0;
75 int min_playout_delay_ms = 0;
Peter Boströmc4188fd2015-04-24 15:16:03 +020076 int render_delay_ms = 10;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000077
pbosf42376c2015-08-28 07:35:32 -070078 int current_payload_type = -1;
79
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000080 int total_bitrate_bps = 0;
81 int discarded_packets = 0;
82
83 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000084 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000085 StreamDataCounters rtp_stats;
86 RtcpPacketTypeCounter rtcp_packet_type_counts;
87 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000088 };
89
90 struct Config {
solenberg4fbae2b2015-08-28 04:07:10 -070091 Config() = delete;
92 explicit Config(newapi::Transport* rtcp_send_transport)
93 : rtcp_send_transport(rtcp_send_transport) {}
94
pbos@webrtc.org32e85282015-01-15 10:09:39 +000095 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000096
97 // Decoders for every payload that we can receive.
98 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000099
100 // Receive-stream specific RTP settings.
101 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39 +0000102 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000103
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000104 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200105 uint32_t remote_ssrc = 0;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000106 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200107 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000108
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000109 // See RtcpMode for description.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200110 newapi::RtcpMode rtcp_mode = newapi::kRtcpCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000111
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000112 // Extended RTCP settings.
113 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000114 // True if RTCP Receiver Reference Time Report Block extension
115 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200116 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000117 } rtcp_xr;
118
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000119 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200120 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000121
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000122 // See NackConfig for description.
123 NackConfig nack;
124
125 // See FecConfig for description.
126 FecConfig fec;
127
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000128 // RTX settings for incoming video payloads that may be received. RTX is
129 // disabled if there's no config present.
130 struct Rtx {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000131 // SSRCs to use for the RTX streams.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200132 uint32_t ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000133
134 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200135 int payload_type = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000136 };
137
138 // Map from video RTP payload type -> RTX config.
139 typedef std::map<int, Rtx> RtxMap;
140 RtxMap rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000141
142 // RTP header extensions used for the received stream.
143 std::vector<RtpExtension> extensions;
144 } rtp;
145
solenberg4fbae2b2015-08-28 04:07:10 -0700146 // Transport for outgoing packets (RTCP).
147 newapi::Transport* rtcp_send_transport = nullptr;
148
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200149 // VideoRenderer will be called for each decoded frame. 'nullptr' disables
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000150 // rendering of this stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200151 VideoRenderer* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000152
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.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200156 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000157
pbos8fc7fa72015-07-15 08:02:58 -0700158 // Identifier for an A/V synchronization group. Empty string to disable.
159 // TODO(pbos): Synchronize streams in a sync group, not just video streams
160 // to one of the audio streams.
161 std::string sync_group;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000162
163 // Called for each incoming video frame, i.e. in encoded state. E.g. used
164 // when
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200165 // saving the stream to a file. 'nullptr' disables the callback.
166 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000167
168 // Called for each decoded frame. E.g. used when adding effects to the
169 // decoded
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200170 // stream. 'nullptr' disables the callback.
171 I420FrameCallback* pre_render_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000172
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000173 // Target delay in milliseconds. A positive value indicates this stream is
174 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200175 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000176 };
177
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000178 // TODO(pbos): Add info on currently-received codec to Stats.
179 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000180};
181
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000182} // namespace webrtc
183
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000184#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_