1 /* 2 * Copyright (c) 2012 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_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_ 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_ 13 14 #include <set> 15 16 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" 17 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" 18 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 20 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 21 #include "webrtc/typedefs.h" 22 23 namespace webrtc { 24 25 class CriticalSectionWrapper; 26 27 // Handles audio RTP packets. This class is thread-safe. 28 class RTPReceiverAudio : public RTPReceiverStrategy, 29 public TelephoneEventHandler { 30 public: 31 RTPReceiverAudio(const int32_t id, 32 RtpData* data_callback, 33 RtpAudioFeedback* incoming_messages_callback); 34 virtual ~RTPReceiverAudio() {} 35 36 // The following three methods implement the TelephoneEventHandler interface. 37 // Forward DTMFs to decoder for playout. 38 void SetTelephoneEventForwardToDecoder(bool forward_to_decoder); 39 40 // Is forwarding of outband telephone events turned on/off? 41 bool TelephoneEventForwardToDecoder() const; 42 43 // Is TelephoneEvent configured with payload type payload_type 44 bool TelephoneEventPayloadType(const int8_t payload_type) const; 45 46 TelephoneEventHandler* GetTelephoneEventHandler() { 47 return this; 48 } 49 50 // Returns true if CNG is configured with payload type payload_type. If so, 51 // the frequency and cng_payload_type_has_changed are filled in. 52 bool CNGPayloadType(const int8_t payload_type, 53 uint32_t* frequency, 54 bool* cng_payload_type_has_changed); 55 56 int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header, 57 const PayloadUnion& specific_payload, 58 bool is_red, 59 const uint8_t* packet, 60 uint16_t packet_length, 61 int64_t timestamp_ms, 62 bool is_first_packet); 63 64 int GetPayloadTypeFrequency() const OVERRIDE; 65 66 virtual RTPAliveType ProcessDeadOrAlive(uint16_t last_payload_length) const 67 OVERRIDE; 68 69 virtual bool ShouldReportCsrcChanges(uint8_t payload_type) const OVERRIDE; 70 71 virtual int32_t OnNewPayloadTypeCreated( 72 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 73 int8_t payload_type, 74 uint32_t frequency) OVERRIDE; 75 76 virtual int32_t InvokeOnInitializeDecoder( 77 RtpFeedback* callback, 78 int32_t id, 79 int8_t payload_type, 80 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 81 const PayloadUnion& specific_payload) const OVERRIDE; 82 83 // We do not allow codecs to have multiple payload types for audio, so we 84 // need to override the default behavior (which is to do nothing). 85 void PossiblyRemoveExistingPayloadType( 86 ModuleRTPUtility::PayloadTypeMap* payload_type_map, 87 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 88 size_t payload_name_length, 89 uint32_t frequency, 90 uint8_t channels, 91 uint32_t rate) const; 92 93 // We need to look out for special payload types here and sometimes reset 94 // statistics. In addition we sometimes need to tweak the frequency. 95 void CheckPayloadChanged(int8_t payload_type, 96 PayloadUnion* specific_payload, 97 bool* should_reset_statistics, 98 bool* should_discard_changes) OVERRIDE; 99 100 int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const OVERRIDE; 101 102 private: 103 104 int32_t ParseAudioCodecSpecific( 105 WebRtcRTPHeader* rtp_header, 106 const uint8_t* payload_data, 107 uint16_t payload_length, 108 const AudioPayload& audio_specific, 109 bool is_red); 110 111 int32_t id_; 112 113 uint32_t last_received_frequency_; 114 115 bool telephone_event_forward_to_decoder_; 116 int8_t telephone_event_payload_type_; 117 std::set<uint8_t> telephone_event_reported_; 118 119 int8_t cng_nb_payload_type_; 120 int8_t cng_wb_payload_type_; 121 int8_t cng_swb_payload_type_; 122 int8_t cng_fb_payload_type_; 123 int8_t cng_payload_type_; 124 125 // G722 is special since it use the wrong number of RTP samples in timestamp 126 // VS. number of samples in the frame 127 int8_t g722_payload_type_; 128 bool last_received_g722_; 129 130 uint8_t num_energy_; 131 uint8_t current_remote_energy_[kRtpCsrcSize]; 132 133 RtpAudioFeedback* cb_audio_feedback_; 134 }; 135 } // namespace webrtc 136 137 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_ 138