blob: a8003c1aa9c53c49aa1ebd8478617d34c51f5dc9 [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 {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000039 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000040
41 // The actual decoder instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020042 VideoDecoder* decoder = nullptr;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000043
44 // Received RTP packets with this payload type will be sent to this decoder
45 // instance.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020046 int payload_type = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000047
48 // Name of the decoded payload (such as VP8). Maps back to the depacketizer
49 // used to unpack incoming packets.
50 std::string payload_name;
51
52 // 'true' if the decoder handles rendering as well.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020053 bool is_renderer = false;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000054
55 // The expected delay for decoding and rendering, i.e. the frame will be
56 // delivered this many milliseconds, if possible, earlier than the ideal
57 // render time.
58 // Note: Ignored if 'renderer' is false.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020059 int expected_delay_ms = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000060 };
61
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000062 struct Stats {
63 int network_frame_rate = 0;
64 int decode_frame_rate = 0;
65 int render_frame_rate = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000066
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000067 // Decoder stats.
68 FrameCounts frame_counts;
69 int decode_ms = 0;
70 int max_decode_ms = 0;
71 int current_delay_ms = 0;
72 int target_delay_ms = 0;
73 int jitter_buffer_ms = 0;
74 int min_playout_delay_ms = 0;
Peter Boströmc4188fd2015-04-24 15:16:03 +020075 int render_delay_ms = 10;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000076
77 int total_bitrate_bps = 0;
78 int discarded_packets = 0;
79
80 uint32_t ssrc = 0;
sprang@webrtc.org09315702014-02-07 12:06:29 +000081 std::string c_name;
pbos@webrtc.org09c77b92015-02-25 10:42:16 +000082 StreamDataCounters rtp_stats;
83 RtcpPacketTypeCounter rtcp_packet_type_counts;
84 RtcpStatistics rtcp_stats;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000085 };
86
87 struct Config {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000088 std::string ToString() const;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000089
90 // Decoders for every payload that we can receive.
91 std::vector<Decoder> decoders;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +000092
93 // Receive-stream specific RTP settings.
94 struct Rtp {
pbos@webrtc.org32e85282015-01-15 10:09:39 +000095 std::string ToString() const;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +000096
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000097 // Synchronization source (stream identifier) to be received.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020098 uint32_t remote_ssrc = 0;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000099 // Sender SSRC used for sending RTCP (such as receiver reports).
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200100 uint32_t local_ssrc = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000101
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000102 // See RtcpMode for description.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200103 newapi::RtcpMode rtcp_mode = newapi::kRtcpCompound;
pbos@webrtc.orgc11148b2013-10-17 14:14:42 +0000104
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000105 // Extended RTCP settings.
106 struct RtcpXr {
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000107 // True if RTCP Receiver Reference Time Report Block extension
108 // (RFC 3611) should be enabled.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200109 bool receiver_reference_time_report = false;
asapersson@webrtc.orgefaeda02014-01-20 08:34:49 +0000110 } rtcp_xr;
111
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000112 // See draft-alvestrand-rmcat-remb for information.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200113 bool remb = false;
mflodman@webrtc.org92c27932013-12-13 16:36:28 +0000114
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000115 // See NackConfig for description.
116 NackConfig nack;
117
118 // See FecConfig for description.
119 FecConfig fec;
120
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000121 // RTX settings for incoming video payloads that may be received. RTX is
122 // disabled if there's no config present.
123 struct Rtx {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000124 // SSRCs to use for the RTX streams.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200125 uint32_t ssrc = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000126
127 // Payload type to use for the RTX stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200128 int payload_type = 0;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000129 };
130
131 // Map from video RTP payload type -> RTX config.
132 typedef std::map<int, Rtx> RtxMap;
133 RtxMap rtx;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000134
135 // RTP header extensions used for the received stream.
136 std::vector<RtpExtension> extensions;
137 } rtp;
138
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200139 // VideoRenderer will be called for each decoded frame. 'nullptr' disables
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000140 // rendering of this stream.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200141 VideoRenderer* renderer = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000142
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.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200146 int render_delay_ms = 10;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000147
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.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200151 int audio_channel_id = -1;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000152
153 // Called for each incoming video frame, i.e. in encoded state. E.g. used
154 // when
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200155 // saving the stream to a file. 'nullptr' disables the callback.
156 EncodedFrameObserver* pre_decode_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000157
158 // Called for each decoded frame. E.g. used when adding effects to the
159 // decoded
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200160 // stream. 'nullptr' disables the callback.
161 I420FrameCallback* pre_render_callback = nullptr;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000162
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000163 // Target delay in milliseconds. A positive value indicates this stream is
164 // used for streaming instead of a real-time call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200165 int target_delay_ms = 0;
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000166 };
167
pbos@webrtc.orga5c8d2c2014-04-24 11:13:21 +0000168 virtual void Start() = 0;
169 virtual void Stop() = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000170
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000171 // TODO(pbos): Add info on currently-received codec to Stats.
172 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000173
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000174 protected:
175 virtual ~VideoReceiveStream() {}
176};
177
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000178} // namespace webrtc
179
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000180#endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_