niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [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 06:47:31 +0200 | [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 +0000 | [diff] [blame] | 13 | |
| 14 | #include <stdio.h> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 16 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 17 | #include "modules/include/module_common_types.h" |
| 18 | #include "rtc_base/criticalsection.h" |
| 19 | #include "typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | #define MAX_NUM_PAYLOADS 50 |
| 24 | #define MAX_NUM_FRAMESIZES 6 |
| 25 | |
turaj@webrtc.org | c2d69d3 | 2014-02-19 20:31:17 +0000 | [diff] [blame] | 26 | // TODO(turajs): Write constructor for this structure. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 27 | struct ACMTestFrameSizeStats { |
| 28 | uint16_t frameSizeSample; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 29 | size_t maxPayloadLen; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
turaj@webrtc.org | c2d69d3 | 2014-02-19 20:31:17 +0000 | [diff] [blame] | 37 | // TODO(turajs): Write constructor for this structure. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 38 | struct ACMTestPayloadStats { |
| 39 | bool newPacket; |
| 40 | int16_t payloadType; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 41 | size_t lastPayloadLenByte; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 42 | uint32_t lastTimestamp; |
| 43 | ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 46 | class Channel : public AudioPacketizationCallback { |
| 47 | public: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 49 | Channel(int16_t chID = -1); |
kwiberg | 65fc8b9 | 2016-08-29 10:05:24 -0700 | [diff] [blame] | 50 | ~Channel() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 52 | int32_t SendData(FrameType frameType, |
| 53 | uint8_t payloadType, |
| 54 | uint32_t timeStamp, |
| 55 | const uint8_t* payloadData, |
| 56 | size_t payloadSize, |
| 57 | const RTPFragmentationHeader* fragmentation) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 59 | void RegisterReceiverACM(AudioCodingModule *acm); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 60 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 61 | void ResetStats(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 62 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 63 | int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 64 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 65 | void Stats(uint32_t* numPackets); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 66 | |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 67 | void Stats(uint8_t* payloadType, uint32_t* payloadLenByte); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 68 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 69 | void PrintStats(CodecInst& codecInst); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 70 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 71 | void SetIsStereo(bool isStereo) { |
| 72 | _isStereo = isStereo; |
| 73 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 75 | uint32_t LastInTimestamp(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 76 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | void SetFECTestWithPacketLoss(bool usePacketLoss) { |
| 78 | _useFECTestWithPacketLoss = usePacketLoss; |
| 79 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 81 | double BitRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
turaj@webrtc.org | a305e96 | 2013-06-06 19:00:09 +0000 | [diff] [blame] | 83 | void set_send_timestamp(uint32_t new_send_ts) { |
| 84 | external_send_timestamp_ = new_send_ts; |
| 85 | } |
| 86 | |
| 87 | void set_sequence_number(uint16_t new_sequence_number) { |
| 88 | external_sequence_number_ = new_sequence_number; |
| 89 | } |
| 90 | |
| 91 | void set_num_packets_to_drop(int new_num_packets_to_drop) { |
| 92 | num_packets_to_drop_ = new_num_packets_to_drop; |
| 93 | } |
| 94 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 95 | private: |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 96 | void CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 98 | AudioCodingModule* _receiverACM; |
| 99 | uint16_t _seqNo; |
| 100 | // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample |
| 101 | uint8_t _payloadData[60 * 32 * 2 * 2]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 103 | rtc::CriticalSection _channelCritSect; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 104 | FILE* _bitStreamFile; |
| 105 | bool _saveBitStream; |
| 106 | int16_t _lastPayloadType; |
| 107 | ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS]; |
| 108 | bool _isStereo; |
| 109 | WebRtcRTPHeader _rtpInfo; |
| 110 | bool _leftChannel; |
| 111 | uint32_t _lastInTimestamp; |
minyue@webrtc.org | 0561716 | 2015-03-03 12:02:30 +0000 | [diff] [blame] | 112 | bool _useLastFrameSize; |
| 113 | uint32_t _lastFrameSizeSample; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 114 | // FEC Test variables |
| 115 | int16_t _packetLoss; |
| 116 | bool _useFECTestWithPacketLoss; |
| 117 | uint64_t _beginTime; |
| 118 | uint64_t _totalBytes; |
turaj@webrtc.org | a305e96 | 2013-06-06 19:00:09 +0000 | [diff] [blame] | 119 | |
| 120 | // External timing info, defaulted to -1. Only used if they are |
| 121 | // non-negative. |
| 122 | int64_t external_send_timestamp_; |
| 123 | int32_t external_sequence_number_; |
| 124 | int num_packets_to_drop_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 127 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 129 | #endif // MODULES_AUDIO_CODING_TEST_CHANNEL_H_ |