blob: e5a6829892563a40e1fe8cd52e82658d49ad23c4 [file] [log] [blame]
mflodman@webrtc.org06e80262013-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
11#ifndef WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
12#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
13
14#include <string>
15#include <vector>
16
17#include "webrtc/common_types.h"
pbos@webrtc.org24e20892013-10-28 16:32:01 +000018#include "webrtc/config.h"
19#include "webrtc/frame_callback.h"
20#include "webrtc/transport.h"
21#include "webrtc/video_renderer.h"
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000022
23namespace webrtc {
24
pbos@webrtc.org51e01012013-10-17 14:14:42 +000025namespace newapi {
26// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
27// RTCP mode is described by RFC 5506.
28enum RtcpMode {
29 kRtcpCompound,
30 kRtcpReducedSize
31};
32} // namespace newapi
33
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000034class VideoDecoder;
35
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000036// TODO(mflodman) Move all these settings to VideoDecoder and move the
37// declaration to common_types.h.
38struct ExternalVideoDecoder {
pbos@webrtc.orgb2d1a402013-05-28 08:04:45 +000039 ExternalVideoDecoder()
40 : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000041 // The actual decoder.
42 VideoDecoder* decoder;
43
44 // Received RTP packets with this payload type will be sent to this decoder
45 // instance.
46 int payload_type;
47
48 // 'true' if the decoder handles rendering as well.
49 bool renderer;
50
51 // The expected delay for decoding and rendering, i.e. the frame will be
52 // delivered this many milliseconds, if possible, earlier than the ideal
53 // render time.
54 // Note: Ignored if 'renderer' is false.
55 int expected_delay_ms;
56};
57
mflodman@webrtc.org06e80262013-04-18 12:02:52 +000058class VideoReceiveStream {
59 public:
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +000060 struct Stats {
61 Stats()
62 : network_frame_rate(0),
63 decode_frame_rate(0),
64 render_frame_rate(0),
65 key_frames(0),
66 delta_frames(0),
67 video_packets(0),
68 retransmitted_packets(0),
69 fec_packets(0),
70 padding_packets(0),
71 discarded_packets(0),
72 received_bitrate_bps(0),
73 receive_side_delay_ms(0) {}
74 RtpStatistics rtp_stats;
75 int network_frame_rate;
76 int decode_frame_rate;
77 int render_frame_rate;
78 uint32_t key_frames;
79 uint32_t delta_frames;
80 uint32_t video_packets;
81 uint32_t retransmitted_packets;
82 uint32_t fec_packets;
83 uint32_t padding_packets;
84 uint32_t discarded_packets;
85 int32_t received_bitrate_bps;
86 int receive_side_delay_ms;
87 };
88
89 class StatsCallback {
90 public:
91 virtual ~StatsCallback() {}
92 virtual void ReceiveStats(const Stats& stats) = 0;
93 };
94
95 struct Config {
96 Config()
97 : renderer(NULL),
98 render_delay_ms(0),
99 audio_channel_id(0),
100 pre_decode_callback(NULL),
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000101 pre_render_callback(NULL),
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000102 target_delay_ms(0) {}
pbos@webrtc.orgce851092013-08-05 12:01:36 +0000103 // Codecs the receive stream can receive.
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000104 std::vector<VideoCodec> codecs;
105
106 // Receive-stream specific RTP settings.
107 struct Rtp {
pbos@webrtc.org4b50db12013-12-03 10:13:04 +0000108 Rtp()
109 : remote_ssrc(0),
110 local_ssrc(0),
111 rtcp_mode(newapi::kRtcpReducedSize) {}
pbos@webrtc.org51e01012013-10-17 14:14:42 +0000112
pbos@webrtc.org4b50db12013-12-03 10:13:04 +0000113 // Synchronization source (stream identifier) to be received.
114 uint32_t remote_ssrc;
115 // Sender SSRC used for sending RTCP (such as receiver reports).
116 uint32_t local_ssrc;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000117
pbos@webrtc.org51e01012013-10-17 14:14:42 +0000118 // See RtcpMode for description.
119 newapi::RtcpMode rtcp_mode;
120
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000121 // See NackConfig for description.
122 NackConfig nack;
123
124 // See FecConfig for description.
125 FecConfig fec;
126
127 // RTX settings for possible payloads. RTX is disabled if the vector is
128 // empty.
129 std::vector<RtxConfig> rtx;
130
131 // RTP header extensions used for the received stream.
132 std::vector<RtpExtension> extensions;
133 } rtp;
134
135 // VideoRenderer will be called for each decoded frame. 'NULL' disables
136 // rendering of this stream.
137 VideoRenderer* renderer;
138
139 // Expected delay needed by the renderer, i.e. the frame will be delivered
140 // this many milliseconds, if possible, earlier than the ideal render time.
141 // Only valid if 'renderer' is set.
142 int render_delay_ms;
143
144 // Audio channel corresponding to this video stream, used for audio/video
145 // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
146 // when creating the VideoEngine instance. '-1' disables a/v sync.
147 int audio_channel_id;
148
149 // Called for each incoming video frame, i.e. in encoded state. E.g. used
150 // when
151 // saving the stream to a file. 'NULL' disables the callback.
152 EncodedFrameObserver* pre_decode_callback;
153
154 // Called for each decoded frame. E.g. used when adding effects to the
155 // decoded
156 // stream. 'NULL' disables the callback.
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000157 I420FrameCallback* pre_render_callback;
pbos@webrtc.org6f1c3ef2013-06-05 11:33:21 +0000158
159 // External video decoders to be used if incoming payload type matches the
160 // registered type for an external decoder.
161 std::vector<ExternalVideoDecoder> external_decoders;
162
163 // Target delay in milliseconds. A positive value indicates this stream is
164 // used for streaming instead of a real-time call.
165 int target_delay_ms;
166
167 // Callback for periodically receiving receiver stats.
168 StatsCallback* stats_callback;
169 };
170
pbos@webrtc.org7f9f8402013-11-20 11:36:47 +0000171 virtual void StartReceiving() = 0;
172 virtual void StopReceiving() = 0;
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000173
174 // TODO(mflodman) Replace this with callback.
175 virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
176
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000177 protected:
178 virtual ~VideoReceiveStream() {}
179};
180
mflodman@webrtc.org06e80262013-04-18 12:02:52 +0000181} // namespace webrtc
182
183#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_