Home | History | Annotate | Download | only in source
      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 
     21 namespace webrtc {
     22 class RTPSenderAudio: public DTMFqueue
     23 {
     24 public:
     25     RTPSenderAudio(const int32_t id, Clock* clock,
     26                    RTPSender* rtpSender);
     27     virtual ~RTPSenderAudio();
     28 
     29     int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE],
     30                                  const int8_t payloadType,
     31                                  const uint32_t frequency,
     32                                  const uint8_t channels,
     33                                  const uint32_t rate,
     34                                  RtpUtility::Payload*& payload);
     35 
     36     int32_t SendAudio(const FrameType frameType,
     37                       const int8_t payloadType,
     38                       const uint32_t captureTimeStamp,
     39                       const uint8_t* payloadData,
     40                       const uint32_t payloadSize,
     41                       const RTPFragmentationHeader* fragmentation);
     42 
     43     // set audio packet size, used to determine when it's time to send a DTMF packet in silence (CNG)
     44     int32_t SetAudioPacketSize(const uint16_t packetSizeSamples);
     45 
     46     // Store the audio level in dBov for header-extension-for-audio-level-indication.
     47     // Valid range is [0,100]. Actual value is negative.
     48     int32_t SetAudioLevel(const uint8_t level_dBov);
     49 
     50     // Send a DTMF tone using RFC 2833 (4733)
     51       int32_t SendTelephoneEvent(const uint8_t key,
     52                                  const uint16_t time_ms,
     53                                  const uint8_t level);
     54 
     55     bool SendTelephoneEventActive(int8_t& telephoneEvent) const;
     56 
     57     void SetAudioFrequency(const uint32_t f);
     58 
     59     int AudioFrequency() const;
     60 
     61     // Set payload type for Redundant Audio Data RFC 2198
     62     int32_t SetRED(const int8_t payloadType);
     63 
     64     // Get payload type for Redundant Audio Data RFC 2198
     65     int32_t RED(int8_t& payloadType) const;
     66 
     67     int32_t RegisterAudioCallback(RtpAudioFeedback* messagesCallback);
     68 
     69 protected:
     70     int32_t SendTelephoneEventPacket(const bool ended,
     71                                      const uint32_t dtmfTimeStamp,
     72                                      const uint16_t duration,
     73                                      const bool markerBit); // set on first packet in talk burst
     74 
     75     bool MarkerBit(const FrameType frameType,
     76                    const int8_t payloadType);
     77 
     78 private:
     79     int32_t             _id;
     80     Clock*                    _clock;
     81     RTPSender*       _rtpSender;
     82     CriticalSectionWrapper*   _audioFeedbackCritsect;
     83     RtpAudioFeedback*         _audioFeedback;
     84 
     85     CriticalSectionWrapper*   _sendAudioCritsect;
     86 
     87     uint32_t            _frequency;
     88     uint16_t            _packetSizeSamples;
     89 
     90     // DTMF
     91     bool              _dtmfEventIsOn;
     92     bool              _dtmfEventFirstPacketSent;
     93     int8_t      _dtmfPayloadType;
     94     uint32_t    _dtmfTimestamp;
     95     uint8_t     _dtmfKey;
     96     uint32_t    _dtmfLengthSamples;
     97     uint8_t     _dtmfLevel;
     98     int64_t     _dtmfTimeLastSent;
     99     uint32_t    _dtmfTimestampLastSent;
    100 
    101     int8_t      _REDPayloadType;
    102 
    103     // VAD detection, used for markerbit
    104     bool              _inbandVADactive;
    105     int8_t      _cngNBPayloadType;
    106     int8_t      _cngWBPayloadType;
    107     int8_t      _cngSWBPayloadType;
    108     int8_t      _cngFBPayloadType;
    109     int8_t      _lastPayloadType;
    110 
    111     // Audio level indication (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
    112     uint8_t     _audioLevel_dBov;
    113 };
    114 }  // namespace webrtc
    115 
    116 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
    117