1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_CAST_CAST_CONFIG_H_ 6 #define MEDIA_CAST_CAST_CONFIG_H_ 7 8 #include <list> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/callback.h" 14 #include "base/memory/ref_counted.h" 15 #include "media/cast/cast_defines.h" 16 17 namespace media { 18 namespace cast { 19 20 enum RtcpMode { 21 kRtcpCompound, // Compound RTCP mode is described by RFC 4585. 22 kRtcpReducedSize, // Reduced-size RTCP mode is described by RFC 5506. 23 }; 24 25 enum VideoCodec { 26 kVp8, 27 kH264, 28 kExternalVideo, 29 }; 30 31 enum AudioCodec { 32 kOpus, 33 kPcm16, 34 kExternalAudio, 35 }; 36 37 struct AudioSenderConfig { 38 AudioSenderConfig(); 39 40 uint32 sender_ssrc; 41 uint32 incoming_feedback_ssrc; 42 43 int rtcp_interval; 44 std::string rtcp_c_name; 45 RtcpMode rtcp_mode; 46 47 int rtp_history_ms; // The time RTP packets are stored for retransmissions. 48 int rtp_max_delay_ms; 49 int rtp_payload_type; 50 51 bool use_external_encoder; 52 int frequency; 53 int channels; 54 int bitrate; // Set to <= 0 for "auto variable bitrate" (libopus knows best). 55 AudioCodec codec; 56 57 std::string aes_key; // Binary string of size kAesKeySize. 58 std::string aes_iv_mask; // Binary string of size kAesKeySize. 59 }; 60 61 struct VideoSenderConfig { 62 VideoSenderConfig(); 63 64 uint32 sender_ssrc; 65 uint32 incoming_feedback_ssrc; 66 67 int rtcp_interval; 68 std::string rtcp_c_name; 69 RtcpMode rtcp_mode; 70 71 int rtp_history_ms; // The time RTP packets are stored for retransmissions. 72 int rtp_max_delay_ms; 73 int rtp_payload_type; 74 75 bool use_external_encoder; 76 int width; // Incoming frames will be scaled to this size. 77 int height; 78 79 float congestion_control_back_off; 80 int max_bitrate; 81 int min_bitrate; 82 int start_bitrate; 83 int max_qp; 84 int min_qp; 85 int max_frame_rate; 86 int max_number_of_video_buffers_used; // Max value depend on codec. 87 VideoCodec codec; 88 int number_of_cores; 89 90 std::string aes_key; // Binary string of size kAesKeySize. 91 std::string aes_iv_mask; // Binary string of size kAesKeySize. 92 }; 93 94 struct AudioReceiverConfig { 95 AudioReceiverConfig(); 96 97 uint32 feedback_ssrc; 98 uint32 incoming_ssrc; 99 100 int rtcp_interval; 101 std::string rtcp_c_name; 102 RtcpMode rtcp_mode; 103 104 // The time the receiver is prepared to wait for retransmissions. 105 int rtp_max_delay_ms; 106 int rtp_payload_type; 107 108 bool use_external_decoder; 109 int frequency; 110 int channels; 111 AudioCodec codec; 112 113 std::string aes_key; // Binary string of size kAesKeySize. 114 std::string aes_iv_mask; // Binary string of size kAesKeySize. 115 }; 116 117 struct VideoReceiverConfig { 118 VideoReceiverConfig(); 119 120 uint32 feedback_ssrc; 121 uint32 incoming_ssrc; 122 123 int rtcp_interval; 124 std::string rtcp_c_name; 125 RtcpMode rtcp_mode; 126 127 // The time the receiver is prepared to wait for retransmissions. 128 int rtp_max_delay_ms; 129 int rtp_payload_type; 130 131 bool use_external_decoder; 132 int max_frame_rate; 133 134 // Some HW decoders can not run faster than the frame rate, preventing it 135 // from catching up after a glitch. 136 bool decoder_faster_than_max_frame_rate; 137 VideoCodec codec; 138 139 std::string aes_key; // Binary string of size kAesKeySize. 140 std::string aes_iv_mask; // Binary string of size kAesKeySize. 141 }; 142 143 struct EncodedVideoFrame { 144 EncodedVideoFrame(); 145 ~EncodedVideoFrame(); 146 147 VideoCodec codec; 148 bool key_frame; 149 uint32 frame_id; 150 uint32 last_referenced_frame_id; 151 std::string data; 152 }; 153 154 // DEPRECATED: Do not use in new code. Please migrate existing code to use 155 // media::AudioBus. 156 struct PcmAudioFrame { 157 PcmAudioFrame(); 158 ~PcmAudioFrame(); 159 160 int channels; // Samples in interleaved stereo format. L0, R0, L1 ,R1 ,... 161 int frequency; 162 std::vector<int16> samples; 163 }; 164 165 struct EncodedAudioFrame { 166 EncodedAudioFrame(); 167 ~EncodedAudioFrame(); 168 169 AudioCodec codec; 170 uint32 frame_id; // Needed to release the frame. 171 int samples; // Needed send side to advance the RTP timestamp. 172 // Not used receive side. 173 // Support for max sampling rate of 48KHz, 2 channels, 100 ms duration. 174 static const int kMaxNumberOfSamples = 48 * 2 * 100; 175 std::string data; 176 }; 177 178 typedef std::vector<uint8> Packet; 179 typedef std::vector<Packet> PacketList; 180 181 class PacketSender { 182 public: 183 // All packets to be sent to the network will be delivered via these 184 // functions. 185 virtual bool SendPackets(const PacketList& packets) = 0; 186 187 virtual bool SendPacket(const Packet& packet) = 0; 188 ~PacketSender()189 virtual ~PacketSender() {} 190 }; 191 192 class PacketReceiver : public base::RefCountedThreadSafe<PacketReceiver> { 193 public: 194 // All packets received from the network should be delivered via this 195 // function. 196 virtual void ReceivedPacket(const uint8* packet, size_t length, 197 const base::Closure callback) = 0; 198 199 static void DeletePacket(const uint8* packet); 200 201 protected: ~PacketReceiver()202 virtual ~PacketReceiver() {} 203 204 private: 205 friend class base::RefCountedThreadSafe<PacketReceiver>; 206 }; 207 208 class VideoEncoderController { 209 public: 210 // Inform the encoder about the new target bit rate. 211 virtual void SetBitRate(int new_bit_rate) = 0; 212 213 // Inform the encoder to not encode the next frame. 214 // Note: this setting is sticky and should last until called with false. 215 virtual void SkipNextFrame(bool skip_next_frame) = 0; 216 217 // Inform the encoder to encode the next frame as a key frame. 218 virtual void GenerateKeyFrame() = 0; 219 220 // Inform the encoder to only reference frames older or equal to frame_id; 221 virtual void LatestFrameIdToReference(uint32 frame_id) = 0; 222 223 // Query the codec about how many frames it has skipped due to slow ACK. 224 virtual int NumberOfSkippedFrames() const = 0; 225 226 protected: ~VideoEncoderController()227 virtual ~VideoEncoderController() {} 228 }; 229 230 } // namespace cast 231 } // namespace media 232 233 #endif // MEDIA_CAST_CAST_CONFIG_H_ 234