blob: 16648cd136a7f029d458ddf138a0476c971508c2 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
12#define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirko Bonadei71207422017-09-15 13:58:09 +020014#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/rtp_rtcp/source/dtmf_queue.h"
16#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
17#include "modules/rtp_rtcp/source/rtp_sender.h"
18#include "modules/rtp_rtcp/source/rtp_utility.h"
19#include "rtc_base/constructormagic.h"
20#include "rtc_base/criticalsection.h"
21#include "rtc_base/onetimeevent.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
Sergey Ulanovec4f0682016-07-28 15:19:10 -070025
solenbergd3d230f2016-09-23 13:10:46 -070026class RTPSenderAudio {
danilchap162abd32015-12-10 02:39:40 -080027 public:
Sergey Ulanovec4f0682016-07-28 15:19:10 -070028 RTPSenderAudio(Clock* clock, RTPSender* rtp_sender);
solenbergd3d230f2016-09-23 13:10:46 -070029 ~RTPSenderAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000030
danilchap162abd32015-12-10 02:39:40 -080031 int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
Sergey Ulanovec4f0682016-07-28 15:19:10 -070032 int8_t payload_type,
danilchap162abd32015-12-10 02:39:40 -080033 uint32_t frequency,
Peter Kasting69558702016-01-12 16:26:35 -080034 size_t channels,
danilchap162abd32015-12-10 02:39:40 -080035 uint32_t rate,
danilchap6db6cdc2015-12-15 02:54:47 -080036 RtpUtility::Payload** payload);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
Sergey Ulanov525df3f2016-08-02 17:46:41 -070038 bool SendAudio(FrameType frame_type,
39 int8_t payload_type,
40 uint32_t capture_timestamp,
41 const uint8_t* payload_data,
Niels Möller90397d92017-10-27 10:51:20 +020042 size_t payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
danilchap162abd32015-12-10 02:39:40 -080044 // Store the audio level in dBov for
45 // header-extension-for-audio-level-indication.
46 // Valid range is [0,100]. Actual value is negative.
Sergey Ulanovec4f0682016-07-28 15:19:10 -070047 int32_t SetAudioLevel(uint8_t level_dbov);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
danilchap162abd32015-12-10 02:39:40 -080049 // Send a DTMF tone using RFC 2833 (4733)
50 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +000051
danilchap162abd32015-12-10 02:39:40 -080052 protected:
Sergey Ulanov525df3f2016-08-02 17:46:41 -070053 bool SendTelephoneEventPacket(
danilchap162abd32015-12-10 02:39:40 -080054 bool ended,
Sergey Ulanovec4f0682016-07-28 15:19:10 -070055 uint32_t dtmf_timestamp,
danilchap162abd32015-12-10 02:39:40 -080056 uint16_t duration,
Sergey Ulanovec4f0682016-07-28 15:19:10 -070057 bool marker_bit); // set on first packet in talk burst
niklase@google.com470e71d2011-07-07 08:21:25 +000058
Sergey Ulanovec4f0682016-07-28 15:19:10 -070059 bool MarkerBit(FrameType frame_type, int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
danilchap162abd32015-12-10 02:39:40 -080061 private:
solenbergffbbcac2016-11-17 05:25:37 -080062 Clock* const clock_ = nullptr;
63 RTPSender* const rtp_sender_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Sergey Ulanovec4f0682016-07-28 15:19:10 -070065 rtc::CriticalSection send_audio_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +000066
Sergey Ulanovec4f0682016-07-28 15:19:10 -070067 // DTMF.
solenbergffbbcac2016-11-17 05:25:37 -080068 bool dtmf_event_is_on_ = false;
69 bool dtmf_event_first_packet_sent_ = false;
danilchap56359be2017-09-07 07:53:45 -070070 int8_t dtmf_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
71 uint32_t dtmf_payload_freq_ RTC_GUARDED_BY(send_audio_critsect_) = 8000;
solenbergffbbcac2016-11-17 05:25:37 -080072 uint32_t dtmf_timestamp_ = 0;
73 uint32_t dtmf_length_samples_ = 0;
74 int64_t dtmf_time_last_sent_ = 0;
75 uint32_t dtmf_timestamp_last_sent_ = 0;
76 DtmfQueue::Event dtmf_current_event_;
77 DtmfQueue dtmf_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
Sergey Ulanovec4f0682016-07-28 15:19:10 -070079 // VAD detection, used for marker bit.
danilchap56359be2017-09-07 07:53:45 -070080 bool inband_vad_active_ RTC_GUARDED_BY(send_audio_critsect_) = false;
81 int8_t cngnb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
82 int8_t cngwb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
83 int8_t cngswb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
84 int8_t cngfb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
85 int8_t last_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
Sergey Ulanovec4f0682016-07-28 15:19:10 -070087 // Audio level indication.
danilchap162abd32015-12-10 02:39:40 -080088 // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
danilchap56359be2017-09-07 07:53:45 -070089 uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_critsect_) = 0;
skvlad98bb6642016-04-07 15:36:45 -070090 OneTimeEvent first_packet_sent_;
solenbergd3d230f2016-09-23 13:10:46 -070091
92 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio);
niklase@google.com470e71d2011-07-07 08:21:25 +000093};
Sergey Ulanovec4f0682016-07-28 15:19:10 -070094
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000095} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000096
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_