blob: fc94ee05b326adac5d309c72eb49a3b3f67c6977 [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_RECEIVER_AUDIO_H_
12#define MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pwestin@webrtc.orgaf6f15c2012-01-19 15:53:59 +000014#include <set>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/rtp_rtcp/include/rtp_receiver.h"
17#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
18#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
19#include "modules/rtp_rtcp/source/rtp_utility.h"
20#include "rtc_base/onetimeevent.h"
21#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000024
phoglund@webrtc.org92bb4172012-12-13 10:48:24 +000025// Handles audio RTP packets. This class is thread-safe.
danilchap799a9d02016-09-22 03:36:27 -070026class RTPReceiverAudio : public RTPReceiverStrategy,
27 public TelephoneEventHandler {
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000028 public:
solenberg1d031392016-03-30 02:42:32 -070029 explicit RTPReceiverAudio(RtpData* data_callback);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000030 virtual ~RTPReceiverAudio() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000031
danilchap799a9d02016-09-22 03:36:27 -070032 // The following three methods implement the TelephoneEventHandler interface.
33 // Forward DTMFs to decoder for playout.
34 void SetTelephoneEventForwardToDecoder(bool forward_to_decoder) override;
35
36 // Is forwarding of outband telephone events turned on/off?
37 bool TelephoneEventForwardToDecoder() const override;
38
ossu425a6cc2016-10-05 08:44:22 -070039 // Is TelephoneEvent configured with |payload_type|.
danilchap799a9d02016-09-22 03:36:27 -070040 bool TelephoneEventPayloadType(const int8_t payload_type) const override;
41
42 TelephoneEventHandler* GetTelephoneEventHandler() override { return this; }
wu@webrtc.org822fbd82013-08-15 23:38:54 +000043
ossu425a6cc2016-10-05 08:44:22 -070044 // Returns true if CNG is configured with |payload_type|.
45 bool CNGPayloadType(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000046
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000047 int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
48 const PayloadUnion& specific_payload,
49 bool is_red,
50 const uint8_t* packet,
51 size_t payload_length,
52 int64_t timestamp_ms,
53 bool is_first_packet) override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000054
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000055 RTPAliveType ProcessDeadOrAlive(uint16_t last_payload_length) const override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000056
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 bool ShouldReportCsrcChanges(uint8_t payload_type) const override;
phoglund@webrtc.org5accd372013-01-22 12:31:01 +000058
magjed56124bd2016-11-24 09:34:46 -080059 int32_t OnNewPayloadTypeCreated(const CodecInst& audio_codec) override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000060
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000061 int32_t InvokeOnInitializeDecoder(
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000062 RtpFeedback* callback,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000063 int8_t payload_type,
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000064 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 const PayloadUnion& specific_payload) const override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000066
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000067 // We need to look out for special payload types here and sometimes reset
68 // statistics. In addition we sometimes need to tweak the frequency.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000069 void CheckPayloadChanged(int8_t payload_type,
70 PayloadUnion* specific_payload,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000071 bool* should_discard_changes) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000073 int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000074
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000075 private:
danilchap162abd32015-12-10 02:39:40 -080076 int32_t ParseAudioCodecSpecific(WebRtcRTPHeader* rtp_header,
77 const uint8_t* payload_data,
78 size_t payload_length,
79 const AudioPayload& audio_specific,
80 bool is_red);
phoglund@webrtc.org92bb4172012-12-13 10:48:24 +000081
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000082 bool telephone_event_forward_to_decoder_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000083 int8_t telephone_event_payload_type_;
84 std::set<uint8_t> telephone_event_reported_;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
pbos@webrtc.org2f446732013-04-08 11:08:41 +000086 int8_t cng_nb_payload_type_;
87 int8_t cng_wb_payload_type_;
88 int8_t cng_swb_payload_type_;
89 int8_t cng_fb_payload_type_;
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000090
wu@webrtc.org822fbd82013-08-15 23:38:54 +000091 uint8_t num_energy_;
92 uint8_t current_remote_energy_[kRtpCsrcSize];
skvlad98bb6642016-04-07 15:36:45 -070093
94 ThreadUnsafeOneTimeEvent first_packet_received_;
niklase@google.com470e71d2011-07-07 08:21:25 +000095};
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000096} // namespace webrtc
97
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020098#endif // MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_