blob: a1e760bfbfb295d7396e2848a37e1f11f6c88414 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
16
Mirko Bonadei71207422017-09-15 13:58:09 +020017#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/rtp_rtcp/source/dtmf_queue.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#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 Gerey988cc082018-10-23 12:03:01 +020024#include "rtc_base/thread_annotations.h"
25#include "system_wrappers/include/clock.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
Sergey Ulanovec4f0682016-07-28 15:19:10 -070028
solenbergd3d230f2016-09-23 13:10:46 -070029class RTPSenderAudio {
danilchap162abd32015-12-10 02:39:40 -080030 public:
Sergey Ulanovec4f0682016-07-28 15:19:10 -070031 RTPSenderAudio(Clock* clock, RTPSender* rtp_sender);
solenbergd3d230f2016-09-23 13:10:46 -070032 ~RTPSenderAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000033
danilchap162abd32015-12-10 02:39:40 -080034 int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
Sergey Ulanovec4f0682016-07-28 15:19:10 -070035 int8_t payload_type,
danilchap162abd32015-12-10 02:39:40 -080036 uint32_t frequency,
Peter Kasting69558702016-01-12 16:26:35 -080037 size_t channels,
danilchap162abd32015-12-10 02:39:40 -080038 uint32_t rate,
danilchap6db6cdc2015-12-15 02:54:47 -080039 RtpUtility::Payload** payload);
niklase@google.com470e71d2011-07-07 08:21:25 +000040
Sergey Ulanov525df3f2016-08-02 17:46:41 -070041 bool SendAudio(FrameType frame_type,
42 int8_t payload_type,
43 uint32_t capture_timestamp,
44 const uint8_t* payload_data,
Niels Möller90397d92017-10-27 10:51:20 +020045 size_t payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000046
danilchap162abd32015-12-10 02:39:40 -080047 // 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 Ulanovec4f0682016-07-28 15:19:10 -070050 int32_t SetAudioLevel(uint8_t level_dbov);
niklase@google.com470e71d2011-07-07 08:21:25 +000051
danilchap162abd32015-12-10 02:39:40 -080052 // Send a DTMF tone using RFC 2833 (4733)
53 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
danilchap162abd32015-12-10 02:39:40 -080055 protected:
Sergey Ulanov525df3f2016-08-02 17:46:41 -070056 bool SendTelephoneEventPacket(
danilchap162abd32015-12-10 02:39:40 -080057 bool ended,
Sergey Ulanovec4f0682016-07-28 15:19:10 -070058 uint32_t dtmf_timestamp,
danilchap162abd32015-12-10 02:39:40 -080059 uint16_t duration,
Sergey Ulanovec4f0682016-07-28 15:19:10 -070060 bool marker_bit); // set on first packet in talk burst
niklase@google.com470e71d2011-07-07 08:21:25 +000061
Sergey Ulanovec4f0682016-07-28 15:19:10 -070062 bool MarkerBit(FrameType frame_type, int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
danilchap162abd32015-12-10 02:39:40 -080064 private:
solenbergffbbcac2016-11-17 05:25:37 -080065 Clock* const clock_ = nullptr;
66 RTPSender* const rtp_sender_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000067
Sergey Ulanovec4f0682016-07-28 15:19:10 -070068 rtc::CriticalSection send_audio_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Sergey Ulanovec4f0682016-07-28 15:19:10 -070070 // DTMF.
solenbergffbbcac2016-11-17 05:25:37 -080071 bool dtmf_event_is_on_ = false;
72 bool dtmf_event_first_packet_sent_ = false;
danilchap56359be2017-09-07 07:53:45 -070073 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;
solenbergffbbcac2016-11-17 05:25:37 -080075 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.com470e71d2011-07-07 08:21:25 +000081
Sergey Ulanovec4f0682016-07-28 15:19:10 -070082 // VAD detection, used for marker bit.
danilchap56359be2017-09-07 07:53:45 -070083 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.com470e71d2011-07-07 08:21:25 +000089
Sergey Ulanovec4f0682016-07-28 15:19:10 -070090 // Audio level indication.
danilchap162abd32015-12-10 02:39:40 -080091 // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
danilchap56359be2017-09-07 07:53:45 -070092 uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_critsect_) = 0;
skvlad98bb6642016-04-07 15:36:45 -070093 OneTimeEvent first_packet_sent_;
solenbergd3d230f2016-09-23 13:10:46 -070094
95 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio);
niklase@google.com470e71d2011-07-07 08:21:25 +000096};
Sergey Ulanovec4f0682016-07-28 15:19:10 -070097
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000098} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000099
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200100#endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_