2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_
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"
25 class CriticalSectionWrapper;
27 // Handles audio RTP packets. This class is thread-safe.
28 class RTPReceiverAudio : public RTPReceiverStrategy,
29 public TelephoneEventHandler {
31 RTPReceiverAudio(const int32_t id,
32 RtpData* data_callback,
33 RtpAudioFeedback* incoming_messages_callback);
34 virtual ~RTPReceiverAudio() {}
36 // The following three methods implement the TelephoneEventHandler interface.
37 // Forward DTMFs to decoder for playout.
38 void SetTelephoneEventForwardToDecoder(bool forward_to_decoder);
40 // Is forwarding of outband telephone events turned on/off?
41 bool TelephoneEventForwardToDecoder() const;
43 // Is TelephoneEvent configured with payload type payload_type
44 bool TelephoneEventPayloadType(const int8_t payload_type) const;
46 TelephoneEventHandler* GetTelephoneEventHandler() {
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,
54 bool* cng_payload_type_has_changed);
56 int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
57 const PayloadUnion& specific_payload,
59 const uint8_t* packet,
60 uint16_t packet_length,
62 bool is_first_packet);
64 int GetPayloadTypeFrequency() const OVERRIDE;
66 virtual RTPAliveType ProcessDeadOrAlive(uint16_t last_payload_length) const
69 virtual bool ShouldReportCsrcChanges(uint8_t payload_type) const OVERRIDE;
71 virtual int32_t OnNewPayloadTypeCreated(
72 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
74 uint32_t frequency) OVERRIDE;
76 virtual int32_t InvokeOnInitializeDecoder(
77 RtpFeedback* callback,
80 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
81 const PayloadUnion& specific_payload) const OVERRIDE;
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 RtpUtility::PayloadTypeMap* payload_type_map,
87 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
88 size_t payload_name_length,
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;
100 int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const OVERRIDE;
104 int32_t ParseAudioCodecSpecific(
105 WebRtcRTPHeader* rtp_header,
106 const uint8_t* payload_data,
107 uint16_t payload_length,
108 const AudioPayload& audio_specific,
113 uint32_t last_received_frequency_;
115 bool telephone_event_forward_to_decoder_;
116 int8_t telephone_event_payload_type_;
117 std::set<uint8_t> telephone_event_reported_;
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_;
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_;
131 uint8_t current_remote_energy_[kRtpCsrcSize];
133 RtpAudioFeedback* cb_audio_feedback_;
135 } // namespace webrtc
137 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_