niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_CHANNEL_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_CHANNEL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 13 | |
| 14 | #include <stdio.h> |
| 15 | |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 | [diff] [blame] | 16 | #include "modules/audio_coding/acm2/acm_receiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 18 | #include "modules/include/module_common_types.h" |
Markus Handell | 0df0fae | 2020-07-07 13:53:34 | [diff] [blame] | 19 | #include "rtc_base/synchronization/mutex.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 20 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 22 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 23 | #define MAX_NUM_PAYLOADS 50 |
| 24 | #define MAX_NUM_FRAMESIZES 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 25 | |
turaj@webrtc.org | c2d69d3 | 2014-02-19 20:31:17 | [diff] [blame] | 26 | // TODO(turajs): Write constructor for this structure. |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 27 | struct ACMTestFrameSizeStats { |
| 28 | uint16_t frameSizeSample; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 29 | size_t maxPayloadLen; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 30 | uint32_t numPackets; |
| 31 | uint64_t totalPayloadLenByte; |
| 32 | uint64_t totalEncodedSamples; |
| 33 | double rateBitPerSec; |
| 34 | double usageLenSec; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 35 | }; |
| 36 | |
turaj@webrtc.org | c2d69d3 | 2014-02-19 20:31:17 | [diff] [blame] | 37 | // TODO(turajs): Write constructor for this structure. |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 38 | struct ACMTestPayloadStats { |
| 39 | bool newPacket; |
| 40 | int16_t payloadType; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 41 | size_t lastPayloadLenByte; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 42 | uint32_t lastTimestamp; |
| 43 | ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 44 | }; |
| 45 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 46 | class Channel : public AudioPacketizationCallback { |
| 47 | public: |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 48 | Channel(int16_t chID = -1); |
kwiberg | 65fc8b9 | 2016-08-29 17:05:24 | [diff] [blame] | 49 | ~Channel() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 50 | |
Niels Möller | 87e2d78 | 2019-03-07 09:18:23 | [diff] [blame] | 51 | int32_t SendData(AudioFrameType frameType, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 52 | uint8_t payloadType, |
| 53 | uint32_t timeStamp, |
| 54 | const uint8_t* payloadData, |
Minyue Li | ff0e4db | 2020-01-23 12:45:50 | [diff] [blame] | 55 | size_t payloadSize, |
| 56 | int64_t absolute_capture_timestamp_ms) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 57 | |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 | [diff] [blame] | 58 | void RegisterReceiverACM(acm2::AcmReceiver* acm_receiver); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 | [diff] [blame] | 59 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 60 | void ResetStats(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 | [diff] [blame] | 61 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 62 | void SetIsStereo(bool isStereo) { _isStereo = isStereo; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 63 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 64 | uint32_t LastInTimestamp(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 | [diff] [blame] | 65 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 66 | void SetFECTestWithPacketLoss(bool usePacketLoss) { |
| 67 | _useFECTestWithPacketLoss = usePacketLoss; |
| 68 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 69 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 70 | double BitRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 71 | |
turaj@webrtc.org | a305e96 | 2013-06-06 19:00:09 | [diff] [blame] | 72 | void set_send_timestamp(uint32_t new_send_ts) { |
| 73 | external_send_timestamp_ = new_send_ts; |
| 74 | } |
| 75 | |
| 76 | void set_sequence_number(uint16_t new_sequence_number) { |
| 77 | external_sequence_number_ = new_sequence_number; |
| 78 | } |
| 79 | |
| 80 | void set_num_packets_to_drop(int new_num_packets_to_drop) { |
| 81 | num_packets_to_drop_ = new_num_packets_to_drop; |
| 82 | } |
| 83 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 84 | private: |
Niels Möller | bf47495 | 2019-02-18 11:00:06 | [diff] [blame] | 85 | void CalcStatistics(const RTPHeader& rtp_header, size_t payloadSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 86 | |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 | [diff] [blame] | 87 | acm2::AcmReceiver* _receiverACM; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 88 | uint16_t _seqNo; |
| 89 | // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample |
| 90 | uint8_t _payloadData[60 * 32 * 2 * 2]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 91 | |
Markus Handell | 0df0fae | 2020-07-07 13:53:34 | [diff] [blame] | 92 | Mutex _channelCritSect; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 93 | FILE* _bitStreamFile; |
| 94 | bool _saveBitStream; |
| 95 | int16_t _lastPayloadType; |
| 96 | ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS]; |
| 97 | bool _isStereo; |
Niels Möller | bf47495 | 2019-02-18 11:00:06 | [diff] [blame] | 98 | RTPHeader _rtp_header; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 99 | bool _leftChannel; |
| 100 | uint32_t _lastInTimestamp; |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 | [diff] [blame] | 101 | bool _useLastFrameSize; |
| 102 | uint32_t _lastFrameSizeSample; |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 103 | // FEC Test variables |
| 104 | int16_t _packetLoss; |
| 105 | bool _useFECTestWithPacketLoss; |
| 106 | uint64_t _beginTime; |
| 107 | uint64_t _totalBytes; |
turaj@webrtc.org | a305e96 | 2013-06-06 19:00:09 | [diff] [blame] | 108 | |
| 109 | // External timing info, defaulted to -1. Only used if they are |
| 110 | // non-negative. |
| 111 | int64_t external_send_timestamp_; |
| 112 | int32_t external_sequence_number_; |
| 113 | int num_packets_to_drop_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 114 | }; |
| 115 | |
tina.legrand@webrtc.org | d5726a12 | 2013-05-03 07:34:12 | [diff] [blame] | 116 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 117 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 118 | #endif // MODULES_AUDIO_CODING_TEST_CHANNEL_H_ |