niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 14 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #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 Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 22 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 25 | |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 26 | class RTPSenderAudio { |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 27 | public: |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 28 | RTPSenderAudio(Clock* clock, RTPSender* rtp_sender); |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 29 | ~RTPSenderAudio(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 31 | int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 32 | int8_t payload_type, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 33 | uint32_t frequency, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 34 | size_t channels, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 35 | uint32_t rate, |
danilchap | 6db6cdc | 2015-12-15 02:54:47 -0800 | [diff] [blame] | 36 | RtpUtility::Payload** payload); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 38 | bool SendAudio(FrameType frame_type, |
| 39 | int8_t payload_type, |
| 40 | uint32_t capture_timestamp, |
| 41 | const uint8_t* payload_data, |
Niels Möller | 90397d9 | 2017-10-27 10:51:20 +0200 | [diff] [blame] | 42 | size_t payload_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 44 | // 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 Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 47 | int32_t SetAudioLevel(uint8_t level_dbov); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 49 | // Send a DTMF tone using RFC 2833 (4733) |
| 50 | int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 52 | protected: |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 53 | bool SendTelephoneEventPacket( |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 54 | bool ended, |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 55 | uint32_t dtmf_timestamp, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 56 | uint16_t duration, |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 57 | bool marker_bit); // set on first packet in talk burst |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 59 | bool MarkerBit(FrameType frame_type, int8_t payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 61 | private: |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 62 | Clock* const clock_ = nullptr; |
| 63 | RTPSender* const rtp_sender_ = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 65 | rtc::CriticalSection send_audio_critsect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 67 | // DTMF. |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 68 | bool dtmf_event_is_on_ = false; |
| 69 | bool dtmf_event_first_packet_sent_ = false; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 70 | 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; |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 72 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 79 | // VAD detection, used for marker bit. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 80 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 87 | // Audio level indication. |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 88 | // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 89 | uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_critsect_) = 0; |
skvlad | 98bb664 | 2016-04-07 15:36:45 -0700 | [diff] [blame] | 90 | OneTimeEvent first_packet_sent_; |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 91 | |
| 92 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | }; |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 94 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 95 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 97 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_ |