mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 1 | /* |
| 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.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_ |
| 12 | #define WEBRTC_VIDEO_RECEIVE_STREAM_H_ |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | e02d475 | 2014-01-20 14:43:55 +0000 | [diff] [blame] | 14 | #include <map> |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "webrtc/common_types.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 19 | #include "webrtc/config.h" |
| 20 | #include "webrtc/frame_callback.h" |
| 21 | #include "webrtc/transport.h" |
| 22 | #include "webrtc/video_renderer.h" |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 26 | namespace 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.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 29 | enum RtcpMode { kRtcpCompound, kRtcpReducedSize }; |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 30 | } // namespace newapi |
| 31 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 32 | class VideoDecoder; |
| 33 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 34 | class VideoReceiveStream { |
| 35 | public: |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 36 | // 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.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 42 | is_renderer(false), |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 43 | expected_delay_ms(0) {} |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 44 | std::string ToString() const; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 45 | |
| 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.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 58 | bool is_renderer; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 59 | |
| 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.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame^] | 67 | struct Stats { |
| 68 | int network_frame_rate = 0; |
| 69 | int decode_frame_rate = 0; |
| 70 | int render_frame_rate = 0; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 71 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame^] | 72 | // 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.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 86 | std::string c_name; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame^] | 87 | StreamDataCounters rtp_stats; |
| 88 | RtcpPacketTypeCounter rtcp_packet_type_counts; |
| 89 | RtcpStatistics rtcp_stats; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct Config { |
| 93 | Config() |
| 94 | : renderer(NULL), |
| 95 | render_delay_ms(0), |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 96 | audio_channel_id(-1), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 97 | pre_decode_callback(NULL), |
pbos@webrtc.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 98 | pre_render_callback(NULL), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 99 | target_delay_ms(0) {} |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 100 | std::string ToString() const; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 101 | |
| 102 | // Decoders for every payload that we can receive. |
| 103 | std::vector<Decoder> decoders; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 104 | |
| 105 | // Receive-stream specific RTP settings. |
| 106 | struct Rtp { |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 107 | Rtp() |
| 108 | : remote_ssrc(0), |
| 109 | local_ssrc(0), |
mflodman@webrtc.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 110 | rtcp_mode(newapi::kRtcpReducedSize), |
pbos@webrtc.org | bd249bc | 2014-07-07 04:45:15 +0000 | [diff] [blame] | 111 | remb(true) {} |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 +0000 | [diff] [blame] | 112 | std::string ToString() const; |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 113 | |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 114 | // 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.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 118 | |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 119 | // See RtcpMode for description. |
| 120 | newapi::RtcpMode rtcp_mode; |
| 121 | |
asapersson@webrtc.org | efaeda0 | 2014-01-20 08:34:49 +0000 | [diff] [blame] | 122 | // 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.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 131 | // See draft-alvestrand-rmcat-remb for information. |
| 132 | bool remb; |
| 133 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 134 | // See NackConfig for description. |
| 135 | NackConfig nack; |
| 136 | |
| 137 | // See FecConfig for description. |
| 138 | FecConfig fec; |
| 139 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 140 | // 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.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 155 | |
| 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.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 182 | I420FrameCallback* pre_render_callback; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 183 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 184 | // 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.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 189 | virtual void Start() = 0; |
| 190 | virtual void Stop() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 191 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 192 | // TODO(pbos): Add info on currently-received codec to Stats. |
| 193 | virtual Stats GetStats() const = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 194 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 195 | protected: |
| 196 | virtual ~VideoReceiveStream() {} |
| 197 | }; |
| 198 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 199 | } // namespace webrtc |
| 200 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 201 | #endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_ |