We support multiple payload types, and one which matches the audio codec the closest, is picked (or the one with lowest clock rate, if no perfect match is found). The exact clock rate is then ignored and DTMF packets are time stamped with the rate of the current audio codec. This is exactly the way the code has worked up to this point, but until now we have been under the impression that we were in fact sending 8k DTMF. In other words, this is an improvement over the current situation, since we will most likely find a payload type which matches the codec clock rate. This CL also does a little cleaning of the DTMFQueue and RTPSenderAudio classes. BUG=webrtc:2795 Review-Url: https://codereview.webrtc.org/2392883002 Cr-Commit-Position: refs/heads/master@{#15129}
105 lines
3.8 KiB
C++
105 lines
3.8 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
|
|
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
|
|
|
|
#include "webrtc/common_types.h"
|
|
#include "webrtc/base/constructormagic.h"
|
|
#include "webrtc/base/criticalsection.h"
|
|
#include "webrtc/base/onetimeevent.h"
|
|
#include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h"
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
|
#include "webrtc/typedefs.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class RTPSenderAudio {
|
|
public:
|
|
RTPSenderAudio(Clock* clock, RTPSender* rtp_sender);
|
|
~RTPSenderAudio();
|
|
|
|
int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
|
|
int8_t payload_type,
|
|
uint32_t frequency,
|
|
size_t channels,
|
|
uint32_t rate,
|
|
RtpUtility::Payload** payload);
|
|
|
|
bool SendAudio(FrameType frame_type,
|
|
int8_t payload_type,
|
|
uint32_t capture_timestamp,
|
|
const uint8_t* payload_data,
|
|
size_t payload_size,
|
|
const RTPFragmentationHeader* fragmentation);
|
|
|
|
// set audio packet size, used to determine when it's time to send a DTMF
|
|
// packet in silence (CNG)
|
|
int32_t SetAudioPacketSize(uint16_t packet_size_samples);
|
|
|
|
// Store the audio level in dBov for
|
|
// header-extension-for-audio-level-indication.
|
|
// Valid range is [0,100]. Actual value is negative.
|
|
int32_t SetAudioLevel(uint8_t level_dbov);
|
|
|
|
// Send a DTMF tone using RFC 2833 (4733)
|
|
int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
|
|
|
|
protected:
|
|
bool SendTelephoneEventPacket(
|
|
bool ended,
|
|
uint32_t dtmf_timestamp,
|
|
uint16_t duration,
|
|
bool marker_bit); // set on first packet in talk burst
|
|
|
|
bool MarkerBit(FrameType frame_type, int8_t payload_type);
|
|
|
|
private:
|
|
Clock* const clock_ = nullptr;
|
|
RTPSender* const rtp_sender_ = nullptr;
|
|
|
|
rtc::CriticalSection send_audio_critsect_;
|
|
|
|
uint16_t packet_size_samples_ GUARDED_BY(send_audio_critsect_) = 160;
|
|
|
|
// DTMF.
|
|
bool dtmf_event_is_on_ = false;
|
|
bool dtmf_event_first_packet_sent_ = false;
|
|
int8_t dtmf_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
uint32_t dtmf_payload_freq_ GUARDED_BY(send_audio_critsect_) = 8000;
|
|
uint32_t dtmf_timestamp_ = 0;
|
|
uint32_t dtmf_length_samples_ = 0;
|
|
int64_t dtmf_time_last_sent_ = 0;
|
|
uint32_t dtmf_timestamp_last_sent_ = 0;
|
|
DtmfQueue::Event dtmf_current_event_;
|
|
DtmfQueue dtmf_queue_;
|
|
|
|
// VAD detection, used for marker bit.
|
|
bool inband_vad_active_ GUARDED_BY(send_audio_critsect_) = false;
|
|
int8_t cngnb_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
int8_t cngwb_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
int8_t cngswb_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
int8_t cngfb_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
int8_t last_payload_type_ GUARDED_BY(send_audio_critsect_) = -1;
|
|
|
|
// Audio level indication.
|
|
// (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
|
|
uint8_t audio_level_dbov_ GUARDED_BY(send_audio_critsect_) = 0;
|
|
OneTimeEvent first_packet_sent_;
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio);
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
|