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), |
| 42 | renderer(false), |
| 43 | expected_delay_ms(0) {} |
| 44 | |
| 45 | // The actual decoder instance. |
| 46 | VideoDecoder* decoder; |
| 47 | |
| 48 | // Received RTP packets with this payload type will be sent to this decoder |
| 49 | // instance. |
| 50 | int payload_type; |
| 51 | |
| 52 | // Name of the decoded payload (such as VP8). Maps back to the depacketizer |
| 53 | // used to unpack incoming packets. |
| 54 | std::string payload_name; |
| 55 | |
| 56 | // 'true' if the decoder handles rendering as well. |
| 57 | bool renderer; |
| 58 | |
| 59 | // The expected delay for decoding and rendering, i.e. the frame will be |
| 60 | // delivered this many milliseconds, if possible, earlier than the ideal |
| 61 | // render time. |
| 62 | // Note: Ignored if 'renderer' is false. |
| 63 | int expected_delay_ms; |
| 64 | }; |
| 65 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 66 | struct Stats : public SsrcStats { |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 67 | Stats() |
| 68 | : network_frame_rate(0), |
| 69 | decode_frame_rate(0), |
| 70 | render_frame_rate(0), |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 71 | avg_delay_ms(0), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 72 | discarded_packets(0), |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 73 | ssrc(0) {} |
| 74 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 75 | int network_frame_rate; |
| 76 | int decode_frame_rate; |
| 77 | int render_frame_rate; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 78 | int avg_delay_ms; |
asapersson@webrtc.org | 9d45393 | 2014-09-04 07:07:44 +0000 | [diff] [blame] | 79 | int discarded_packets; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 80 | uint32_t ssrc; |
| 81 | std::string c_name; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct Config { |
| 85 | Config() |
| 86 | : renderer(NULL), |
| 87 | render_delay_ms(0), |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 88 | audio_channel_id(-1), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 89 | pre_decode_callback(NULL), |
pbos@webrtc.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 90 | pre_render_callback(NULL), |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 91 | target_delay_ms(0) {} |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 92 | |
| 93 | // Decoders for every payload that we can receive. |
| 94 | std::vector<Decoder> decoders; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 95 | |
| 96 | // Receive-stream specific RTP settings. |
| 97 | struct Rtp { |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 98 | Rtp() |
| 99 | : remote_ssrc(0), |
| 100 | local_ssrc(0), |
mflodman@webrtc.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 101 | rtcp_mode(newapi::kRtcpReducedSize), |
pbos@webrtc.org | bd249bc | 2014-07-07 04:45:15 +0000 | [diff] [blame] | 102 | remb(true) {} |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 103 | |
pbos@webrtc.org | b613b5a | 2013-12-03 10:13:04 +0000 | [diff] [blame] | 104 | // Synchronization source (stream identifier) to be received. |
| 105 | uint32_t remote_ssrc; |
| 106 | // Sender SSRC used for sending RTCP (such as receiver reports). |
| 107 | uint32_t local_ssrc; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 108 | |
pbos@webrtc.org | c11148b | 2013-10-17 14:14:42 +0000 | [diff] [blame] | 109 | // See RtcpMode for description. |
| 110 | newapi::RtcpMode rtcp_mode; |
| 111 | |
asapersson@webrtc.org | efaeda0 | 2014-01-20 08:34:49 +0000 | [diff] [blame] | 112 | // Extended RTCP settings. |
| 113 | struct RtcpXr { |
| 114 | RtcpXr() : receiver_reference_time_report(false) {} |
| 115 | |
| 116 | // True if RTCP Receiver Reference Time Report Block extension |
| 117 | // (RFC 3611) should be enabled. |
| 118 | bool receiver_reference_time_report; |
| 119 | } rtcp_xr; |
| 120 | |
mflodman@webrtc.org | 92c2793 | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 121 | // See draft-alvestrand-rmcat-remb for information. |
| 122 | bool remb; |
| 123 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 124 | // See NackConfig for description. |
| 125 | NackConfig nack; |
| 126 | |
| 127 | // See FecConfig for description. |
| 128 | FecConfig fec; |
| 129 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 130 | // RTX settings for incoming video payloads that may be received. RTX is |
| 131 | // disabled if there's no config present. |
| 132 | struct Rtx { |
| 133 | Rtx() : ssrc(0), payload_type(0) {} |
| 134 | |
| 135 | // SSRCs to use for the RTX streams. |
| 136 | uint32_t ssrc; |
| 137 | |
| 138 | // Payload type to use for the RTX stream. |
| 139 | int payload_type; |
| 140 | }; |
| 141 | |
| 142 | // Map from video RTP payload type -> RTX config. |
| 143 | typedef std::map<int, Rtx> RtxMap; |
| 144 | RtxMap rtx; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 145 | |
| 146 | // RTP header extensions used for the received stream. |
| 147 | std::vector<RtpExtension> extensions; |
| 148 | } rtp; |
| 149 | |
| 150 | // VideoRenderer will be called for each decoded frame. 'NULL' disables |
| 151 | // rendering of this stream. |
| 152 | VideoRenderer* renderer; |
| 153 | |
| 154 | // Expected delay needed by the renderer, i.e. the frame will be delivered |
| 155 | // this many milliseconds, if possible, earlier than the ideal render time. |
| 156 | // Only valid if 'renderer' is set. |
| 157 | int render_delay_ms; |
| 158 | |
| 159 | // Audio channel corresponding to this video stream, used for audio/video |
| 160 | // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set |
| 161 | // when creating the VideoEngine instance. '-1' disables a/v sync. |
| 162 | int audio_channel_id; |
| 163 | |
| 164 | // Called for each incoming video frame, i.e. in encoded state. E.g. used |
| 165 | // when |
| 166 | // saving the stream to a file. 'NULL' disables the callback. |
| 167 | EncodedFrameObserver* pre_decode_callback; |
| 168 | |
| 169 | // Called for each decoded frame. E.g. used when adding effects to the |
| 170 | // decoded |
| 171 | // stream. 'NULL' disables the callback. |
pbos@webrtc.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 172 | I420FrameCallback* pre_render_callback; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 173 | |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 174 | // Target delay in milliseconds. A positive value indicates this stream is |
| 175 | // used for streaming instead of a real-time call. |
| 176 | int target_delay_ms; |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 179 | virtual void Start() = 0; |
| 180 | virtual void Stop() = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 181 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 182 | // TODO(pbos): Add info on currently-received codec to Stats. |
| 183 | virtual Stats GetStats() const = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 184 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 185 | protected: |
| 186 | virtual ~VideoReceiveStream() {} |
| 187 | }; |
| 188 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 189 | } // namespace webrtc |
| 190 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 191 | #endif // WEBRTC_VIDEO_RECEIVE_STREAM_H_ |