• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/stream.h"
22 #include "webrtc/transport.h"
23 #include "webrtc/video_renderer.h"
24 
25 namespace webrtc {
26 
27 class VideoDecoder;
28 
29 class VideoReceiveStream : public ReceiveStream {
30  public:
31   // TODO(mflodman) Move all these settings to VideoDecoder and move the
32   // declaration to common_types.h.
33   struct Decoder {
34     std::string ToString() const;
35 
36     // The actual decoder instance.
37     VideoDecoder* decoder = nullptr;
38 
39     // Received RTP packets with this payload type will be sent to this decoder
40     // instance.
41     int payload_type = 0;
42 
43     // Name of the decoded payload (such as VP8). Maps back to the depacketizer
44     // used to unpack incoming packets.
45     std::string payload_name;
46   };
47 
48   struct Stats {
49     int network_frame_rate = 0;
50     int decode_frame_rate = 0;
51     int render_frame_rate = 0;
52 
53     // Decoder stats.
54     std::string decoder_implementation_name = "unknown";
55     FrameCounts frame_counts;
56     int decode_ms = 0;
57     int max_decode_ms = 0;
58     int current_delay_ms = 0;
59     int target_delay_ms = 0;
60     int jitter_buffer_ms = 0;
61     int min_playout_delay_ms = 0;
62     int render_delay_ms = 10;
63 
64     int current_payload_type = -1;
65 
66     int total_bitrate_bps = 0;
67     int discarded_packets = 0;
68 
69     uint32_t ssrc = 0;
70     std::string c_name;
71     StreamDataCounters rtp_stats;
72     RtcpPacketTypeCounter rtcp_packet_type_counts;
73     RtcpStatistics rtcp_stats;
74   };
75 
76   struct Config {
77     Config() = delete;
ConfigConfig78     explicit Config(Transport* rtcp_send_transport)
79         : rtcp_send_transport(rtcp_send_transport) {}
80 
81     std::string ToString() const;
82 
83     // Decoders for every payload that we can receive.
84     std::vector<Decoder> decoders;
85 
86     // Receive-stream specific RTP settings.
87     struct Rtp {
88       std::string ToString() const;
89 
90       // Synchronization source (stream identifier) to be received.
91       uint32_t remote_ssrc = 0;
92       // Sender SSRC used for sending RTCP (such as receiver reports).
93       uint32_t local_ssrc = 0;
94 
95       // See RtcpMode for description.
96       RtcpMode rtcp_mode = RtcpMode::kCompound;
97 
98       // Extended RTCP settings.
99       struct RtcpXr {
100         // True if RTCP Receiver Reference Time Report Block extension
101         // (RFC 3611) should be enabled.
102         bool receiver_reference_time_report = false;
103       } rtcp_xr;
104 
105       // See draft-alvestrand-rmcat-remb for information.
106       bool remb = false;
107 
108       // See draft-holmer-rmcat-transport-wide-cc-extensions for details.
109       bool transport_cc = false;
110 
111       // See NackConfig for description.
112       NackConfig nack;
113 
114       // See FecConfig for description.
115       FecConfig fec;
116 
117       // RTX settings for incoming video payloads that may be received. RTX is
118       // disabled if there's no config present.
119       struct Rtx {
120         // SSRCs to use for the RTX streams.
121         uint32_t ssrc = 0;
122 
123         // Payload type to use for the RTX stream.
124         int payload_type = 0;
125       };
126 
127       // Map from video RTP payload type -> RTX config.
128       typedef std::map<int, Rtx> RtxMap;
129       RtxMap rtx;
130 
131       // If set to true, the RTX payload type mapping supplied in |rtx| will be
132       // used when restoring RTX packets. Without it, RTX packets will always be
133       // restored to the last non-RTX packet payload type received.
134       bool use_rtx_payload_mapping_on_restore = false;
135 
136       // RTP header extensions used for the received stream.
137       std::vector<RtpExtension> extensions;
138     } rtp;
139 
140     // Transport for outgoing packets (RTCP).
141     Transport* rtcp_send_transport = nullptr;
142 
143     // VideoRenderer will be called for each decoded frame. 'nullptr' disables
144     // rendering of this stream.
145     VideoRenderer* renderer = nullptr;
146 
147     // Expected delay needed by the renderer, i.e. the frame will be delivered
148     // this many milliseconds, if possible, earlier than the ideal render time.
149     // Only valid if 'renderer' is set.
150     int render_delay_ms = 10;
151 
152     // Identifier for an A/V synchronization group. Empty string to disable.
153     // TODO(pbos): Synchronize streams in a sync group, not just video streams
154     // to one of the audio streams.
155     std::string sync_group;
156 
157     // Called for each incoming video frame, i.e. in encoded state. E.g. used
158     // when
159     // saving the stream to a file. 'nullptr' disables the callback.
160     EncodedFrameObserver* pre_decode_callback = nullptr;
161 
162     // Called for each decoded frame. E.g. used when adding effects to the
163     // decoded
164     // stream. 'nullptr' disables the callback.
165     I420FrameCallback* pre_render_callback = nullptr;
166 
167     // Target delay in milliseconds. A positive value indicates this stream is
168     // used for streaming instead of a real-time call.
169     int target_delay_ms = 0;
170   };
171 
172   // TODO(pbos): Add info on currently-received codec to Stats.
173   virtual Stats GetStats() const = 0;
174 };
175 
176 }  // namespace webrtc
177 
178 #endif  // WEBRTC_VIDEO_RECEIVE_STREAM_H_
179