blob: 14026d07d456f666260ed1b512ae5ea3477b8d89 [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"
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "typedefs.h" // NOLINT(build/include)
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,
Niels Möllerbbf389c2017-09-26 14:05:05 +020052 int64_t timestamp_ms) override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000053
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000054 RTPAliveType ProcessDeadOrAlive(uint16_t last_payload_length) const override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000055
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 bool ShouldReportCsrcChanges(uint8_t payload_type) const override;
phoglund@webrtc.org5accd372013-01-22 12:31:01 +000057
magjed56124bd2016-11-24 09:34:46 -080058 int32_t OnNewPayloadTypeCreated(const CodecInst& audio_codec) override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000059
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000060 int32_t InvokeOnInitializeDecoder(
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000061 RtpFeedback* callback,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062 int8_t payload_type,
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000063 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000064 const PayloadUnion& specific_payload) const override;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000065
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000066 // We need to look out for special payload types here and sometimes reset
67 // statistics. In addition we sometimes need to tweak the frequency.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000068 void CheckPayloadChanged(int8_t payload_type,
69 PayloadUnion* specific_payload,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000070 bool* should_discard_changes) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000072 int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000073
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000074 private:
danilchap162abd32015-12-10 02:39:40 -080075 int32_t ParseAudioCodecSpecific(WebRtcRTPHeader* rtp_header,
76 const uint8_t* payload_data,
77 size_t payload_length,
78 const AudioPayload& audio_specific,
79 bool is_red);
phoglund@webrtc.org92bb4172012-12-13 10:48:24 +000080
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000081 bool telephone_event_forward_to_decoder_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000082 int8_t telephone_event_payload_type_;
83 std::set<uint8_t> telephone_event_reported_;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.org2f446732013-04-08 11:08:41 +000085 int8_t cng_nb_payload_type_;
86 int8_t cng_wb_payload_type_;
87 int8_t cng_swb_payload_type_;
88 int8_t cng_fb_payload_type_;
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000089
wu@webrtc.org822fbd82013-08-15 23:38:54 +000090 uint8_t num_energy_;
91 uint8_t current_remote_energy_[kRtpCsrcSize];
skvlad98bb6642016-04-07 15:36:45 -070092
93 ThreadUnsafeOneTimeEvent first_packet_received_;
niklase@google.com470e71d2011-07-07 08:21:25 +000094};
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000095} // namespace webrtc
96
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_AUDIO_H_