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