Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / video_receive_stream.h
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
11 #ifndef WEBRTC_VIDEO_RECEIVE_STREAM_H_
12 #define WEBRTC_VIDEO_RECEIVE_STREAM_H_
13
14 #include <map>
15 #include <string>
16 #include <vector>
17
18 #include "webrtc/common_types.h"
19 #include "webrtc/config.h"
20 #include "webrtc/frame_callback.h"
21 #include "webrtc/transport.h"
22 #include "webrtc/video_renderer.h"
23
24 namespace webrtc {
25
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.
29 enum RtcpMode {
30   kRtcpCompound,
31   kRtcpReducedSize
32 };
33 }  // namespace newapi
34
35 class VideoDecoder;
36
37 // TODO(mflodman) Move all these settings to VideoDecoder and move the
38 // declaration to common_types.h.
39 struct ExternalVideoDecoder {
40   ExternalVideoDecoder()
41       : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
42   // The actual decoder.
43   VideoDecoder* decoder;
44
45   // Received RTP packets with this payload type will be sent to this decoder
46   // instance.
47   int payload_type;
48
49   // 'true' if the decoder handles rendering as well.
50   bool renderer;
51
52   // The expected delay for decoding and rendering, i.e. the frame will be
53   // delivered this many milliseconds, if possible, earlier than the ideal
54   // render time.
55   // Note: Ignored if 'renderer' is false.
56   int expected_delay_ms;
57 };
58
59 class VideoReceiveStream {
60  public:
61   struct Stats {
62     Stats()
63         : network_frame_rate(0),
64           decode_frame_rate(0),
65           render_frame_rate(0),
66           key_frames(0),
67           delta_frames(0),
68           video_packets(0),
69           retransmitted_packets(0),
70           fec_packets(0),
71           padding_packets(0),
72           discarded_packets(0),
73           received_bitrate_bps(0),
74           receive_side_delay_ms(0) {}
75     RtpStatistics rtp_stats;
76     int network_frame_rate;
77     int decode_frame_rate;
78     int render_frame_rate;
79     uint32_t key_frames;
80     uint32_t delta_frames;
81     uint32_t video_packets;
82     uint32_t retransmitted_packets;
83     uint32_t fec_packets;
84     uint32_t padding_packets;
85     uint32_t discarded_packets;
86     int32_t received_bitrate_bps;
87     int receive_side_delay_ms;
88   };
89
90   class StatsCallback {
91    public:
92     virtual ~StatsCallback() {}
93     virtual void ReceiveStats(const Stats& stats) = 0;
94   };
95
96   struct Config {
97     Config()
98         : renderer(NULL),
99           render_delay_ms(0),
100           audio_channel_id(0),
101           pre_decode_callback(NULL),
102           pre_render_callback(NULL),
103           target_delay_ms(0) {}
104     // Codecs the receive stream can receive.
105     std::vector<VideoCodec> codecs;
106
107     // Receive-stream specific RTP settings.
108     struct Rtp {
109       Rtp()
110           : remote_ssrc(0),
111             local_ssrc(0),
112             rtcp_mode(newapi::kRtcpReducedSize),
113             remb(false) {}
114
115       // Synchronization source (stream identifier) to be received.
116       uint32_t remote_ssrc;
117       // Sender SSRC used for sending RTCP (such as receiver reports).
118       uint32_t local_ssrc;
119
120       // See RtcpMode for description.
121       newapi::RtcpMode rtcp_mode;
122
123       // Extended RTCP settings.
124       struct RtcpXr {
125         RtcpXr() : receiver_reference_time_report(false) {}
126
127         // True if RTCP Receiver Reference Time Report Block extension
128         // (RFC 3611) should be enabled.
129         bool receiver_reference_time_report;
130       } rtcp_xr;
131
132       // See draft-alvestrand-rmcat-remb for information.
133       bool remb;
134
135       // See NackConfig for description.
136       NackConfig nack;
137
138       // See FecConfig for description.
139       FecConfig fec;
140
141       // RTX settings for video payloads that may be received. RTX is disabled
142       // if there's no config present.
143       std::map<int, RtxConfig> rtx;
144
145       // RTP header extensions used for the received stream.
146       std::vector<RtpExtension> extensions;
147     } rtp;
148
149     // VideoRenderer will be called for each decoded frame. 'NULL' disables
150     // rendering of this stream.
151     VideoRenderer* renderer;
152
153     // Expected delay needed by the renderer, i.e. the frame will be delivered
154     // this many milliseconds, if possible, earlier than the ideal render time.
155     // Only valid if 'renderer' is set.
156     int render_delay_ms;
157
158     // Audio channel corresponding to this video stream, used for audio/video
159     // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
160     // when creating the VideoEngine instance. '-1' disables a/v sync.
161     int audio_channel_id;
162
163     // Called for each incoming video frame, i.e. in encoded state. E.g. used
164     // when
165     // saving the stream to a file. 'NULL' disables the callback.
166     EncodedFrameObserver* pre_decode_callback;
167
168     // Called for each decoded frame. E.g. used when adding effects to the
169     // decoded
170     // stream. 'NULL' disables the callback.
171     I420FrameCallback* pre_render_callback;
172
173     // External video decoders to be used if incoming payload type matches the
174     // registered type for an external decoder.
175     std::vector<ExternalVideoDecoder> external_decoders;
176
177     // Target delay in milliseconds. A positive value indicates this stream is
178     // used for streaming instead of a real-time call.
179     int target_delay_ms;
180
181     // Callback for periodically receiving receiver stats.
182     StatsCallback* stats_callback;
183   };
184
185   virtual void StartReceiving() = 0;
186   virtual void StopReceiving() = 0;
187
188   // TODO(mflodman) Replace this with callback.
189   virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
190
191  protected:
192   virtual ~VideoReceiveStream() {}
193 };
194
195 }  // namespace webrtc
196
197 #endif  // WEBRTC_VIDEO_RECEIVE_STREAM_H_