1/*
2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
11#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
13
14#include "webrtc/common_types.h"
15#include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h"
16#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
17#include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
18#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
19#include "webrtc/typedefs.h"
20
21namespace webrtc {
22class RTPSenderAudio : public DTMFqueue {
23 public:
24  RTPSenderAudio(Clock* clock,
25                 RTPSender* rtpSender,
26                 RtpAudioFeedback* audio_feedback);
27  virtual ~RTPSenderAudio();
28
29  int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
30                               int8_t payloadType,
31                               uint32_t frequency,
32                               size_t channels,
33                               uint32_t rate,
34                               RtpUtility::Payload** payload);
35
36  int32_t SendAudio(FrameType frameType,
37                    int8_t payloadType,
38                    uint32_t captureTimeStamp,
39                    const uint8_t* payloadData,
40                    size_t payloadSize,
41                    const RTPFragmentationHeader* fragmentation);
42
43  // set audio packet size, used to determine when it's time to send a DTMF
44  // packet in silence (CNG)
45  int32_t SetAudioPacketSize(uint16_t packetSizeSamples);
46
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.
50  int32_t SetAudioLevel(uint8_t level_dBov);
51
52  // Send a DTMF tone using RFC 2833 (4733)
53  int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
54
55  int AudioFrequency() const;
56
57  // Set payload type for Redundant Audio Data RFC 2198
58  int32_t SetRED(int8_t payloadType);
59
60  // Get payload type for Redundant Audio Data RFC 2198
61  int32_t RED(int8_t* payloadType) const;
62
63 protected:
64  int32_t SendTelephoneEventPacket(
65      bool ended,
66      int8_t dtmf_payload_type,
67      uint32_t dtmfTimeStamp,
68      uint16_t duration,
69      bool markerBit);  // set on first packet in talk burst
70
71  bool MarkerBit(const FrameType frameType, const int8_t payloadType);
72
73 private:
74  Clock* const _clock;
75  RTPSender* const _rtpSender;
76  RtpAudioFeedback* const _audioFeedback;
77
78  rtc::scoped_ptr<CriticalSectionWrapper> _sendAudioCritsect;
79
80  uint16_t _packetSizeSamples GUARDED_BY(_sendAudioCritsect);
81
82  // DTMF
83  bool _dtmfEventIsOn;
84  bool _dtmfEventFirstPacketSent;
85  int8_t _dtmfPayloadType GUARDED_BY(_sendAudioCritsect);
86  uint32_t _dtmfTimestamp;
87  uint8_t _dtmfKey;
88  uint32_t _dtmfLengthSamples;
89  uint8_t _dtmfLevel;
90  int64_t _dtmfTimeLastSent;
91  uint32_t _dtmfTimestampLastSent;
92
93  int8_t _REDPayloadType GUARDED_BY(_sendAudioCritsect);
94
95  // VAD detection, used for markerbit
96  bool _inbandVADactive GUARDED_BY(_sendAudioCritsect);
97  int8_t _cngNBPayloadType GUARDED_BY(_sendAudioCritsect);
98  int8_t _cngWBPayloadType GUARDED_BY(_sendAudioCritsect);
99  int8_t _cngSWBPayloadType GUARDED_BY(_sendAudioCritsect);
100  int8_t _cngFBPayloadType GUARDED_BY(_sendAudioCritsect);
101  int8_t _lastPayloadType GUARDED_BY(_sendAudioCritsect);
102
103  // Audio level indication
104  // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
105  uint8_t _audioLevel_dBov GUARDED_BY(_sendAudioCritsect);
106};
107}  // namespace webrtc
108
109#endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
110