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 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 17 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/rtp_rtcp/source/dtmf_queue.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/rtp_rtcp/source/rtp_sender.h" |
| 20 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 21 | #include "rtc_base/constructormagic.h" |
| 22 | #include "rtc_base/criticalsection.h" |
| 23 | #include "rtc_base/onetimeevent.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 24 | #include "rtc_base/thread_annotations.h" |
| 25 | #include "system_wrappers/include/clock.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 28 | |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 29 | class RTPSenderAudio { |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 30 | public: |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 31 | RTPSenderAudio(Clock* clock, RTPSender* rtp_sender); |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 32 | ~RTPSenderAudio(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 34 | int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 35 | int8_t payload_type, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 36 | uint32_t frequency, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 37 | size_t channels, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 38 | uint32_t rate, |
danilchap | 6db6cdc | 2015-12-15 02:54:47 -0800 | [diff] [blame] | 39 | RtpUtility::Payload** payload); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 41 | bool SendAudio(FrameType frame_type, |
| 42 | int8_t payload_type, |
| 43 | uint32_t capture_timestamp, |
| 44 | const uint8_t* payload_data, |
Niels Möller | 90397d9 | 2017-10-27 10:51:20 +0200 | [diff] [blame] | 45 | size_t payload_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 47 | // Store the audio level in dBov for |
| 48 | // header-extension-for-audio-level-indication. |
| 49 | // Valid range is [0,100]. Actual value is negative. |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 50 | int32_t SetAudioLevel(uint8_t level_dbov); |
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 | // Send a DTMF tone using RFC 2833 (4733) |
| 53 | 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] | 54 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 55 | protected: |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 56 | bool SendTelephoneEventPacket( |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 57 | bool ended, |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 58 | uint32_t dtmf_timestamp, |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 59 | uint16_t duration, |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 60 | bool marker_bit); // set on first packet in talk burst |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 62 | bool MarkerBit(FrameType frame_type, int8_t payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 64 | private: |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 65 | Clock* const clock_ = nullptr; |
| 66 | RTPSender* const rtp_sender_ = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 68 | rtc::CriticalSection send_audio_critsect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 70 | // DTMF. |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 71 | bool dtmf_event_is_on_ = false; |
| 72 | bool dtmf_event_first_packet_sent_ = false; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 73 | int8_t dtmf_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1; |
| 74 | uint32_t dtmf_payload_freq_ RTC_GUARDED_BY(send_audio_critsect_) = 8000; |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 75 | uint32_t dtmf_timestamp_ = 0; |
| 76 | uint32_t dtmf_length_samples_ = 0; |
| 77 | int64_t dtmf_time_last_sent_ = 0; |
| 78 | uint32_t dtmf_timestamp_last_sent_ = 0; |
| 79 | DtmfQueue::Event dtmf_current_event_; |
| 80 | DtmfQueue dtmf_queue_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 82 | // VAD detection, used for marker bit. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 83 | bool inband_vad_active_ RTC_GUARDED_BY(send_audio_critsect_) = false; |
| 84 | int8_t cngnb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1; |
| 85 | int8_t cngwb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1; |
| 86 | int8_t cngswb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1; |
| 87 | int8_t cngfb_payload_type_ RTC_GUARDED_BY(send_audio_critsect_) = -1; |
| 88 | 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] | 89 | |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 90 | // Audio level indication. |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 91 | // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 92 | uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_critsect_) = 0; |
skvlad | 98bb664 | 2016-04-07 15:36:45 -0700 | [diff] [blame] | 93 | OneTimeEvent first_packet_sent_; |
solenberg | d3d230f | 2016-09-23 13:10:46 -0700 | [diff] [blame] | 94 | |
| 95 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | }; |
Sergey Ulanov | ec4f068 | 2016-07-28 15:19:10 -0700 | [diff] [blame] | 97 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 98 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 100 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_ |