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 MODULES_AUDIO_CODING_TEST_CHANNEL_H_ 12 #define MODULES_AUDIO_CODING_TEST_CHANNEL_H_ 13 14 #include <stdio.h> 15 16 #include "modules/audio_coding/include/audio_coding_module.h" 17 #include "modules/include/module_common_types.h" 18 #include "rtc_base/synchronization/mutex.h" 19 20 namespace webrtc { 21 22 #define MAX_NUM_PAYLOADS 50 23 #define MAX_NUM_FRAMESIZES 6 24 25 // TODO(turajs): Write constructor for this structure. 26 struct ACMTestFrameSizeStats { 27 uint16_t frameSizeSample; 28 size_t maxPayloadLen; 29 uint32_t numPackets; 30 uint64_t totalPayloadLenByte; 31 uint64_t totalEncodedSamples; 32 double rateBitPerSec; 33 double usageLenSec; 34 }; 35 36 // TODO(turajs): Write constructor for this structure. 37 struct ACMTestPayloadStats { 38 bool newPacket; 39 int16_t payloadType; 40 size_t lastPayloadLenByte; 41 uint32_t lastTimestamp; 42 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES]; 43 }; 44 45 class Channel : public AudioPacketizationCallback { 46 public: 47 Channel(int16_t chID = -1); 48 ~Channel() override; 49 50 int32_t SendData(AudioFrameType frameType, 51 uint8_t payloadType, 52 uint32_t timeStamp, 53 const uint8_t* payloadData, 54 size_t payloadSize, 55 int64_t absolute_capture_timestamp_ms) override; 56 57 void RegisterReceiverACM(AudioCodingModule* acm); 58 59 void ResetStats(); 60 SetIsStereo(bool isStereo)61 void SetIsStereo(bool isStereo) { _isStereo = isStereo; } 62 63 uint32_t LastInTimestamp(); 64 SetFECTestWithPacketLoss(bool usePacketLoss)65 void SetFECTestWithPacketLoss(bool usePacketLoss) { 66 _useFECTestWithPacketLoss = usePacketLoss; 67 } 68 69 double BitRate(); 70 set_send_timestamp(uint32_t new_send_ts)71 void set_send_timestamp(uint32_t new_send_ts) { 72 external_send_timestamp_ = new_send_ts; 73 } 74 set_sequence_number(uint16_t new_sequence_number)75 void set_sequence_number(uint16_t new_sequence_number) { 76 external_sequence_number_ = new_sequence_number; 77 } 78 set_num_packets_to_drop(int new_num_packets_to_drop)79 void set_num_packets_to_drop(int new_num_packets_to_drop) { 80 num_packets_to_drop_ = new_num_packets_to_drop; 81 } 82 83 private: 84 void CalcStatistics(const RTPHeader& rtp_header, size_t payloadSize); 85 86 AudioCodingModule* _receiverACM; 87 uint16_t _seqNo; 88 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample 89 uint8_t _payloadData[60 * 32 * 2 * 2]; 90 91 Mutex _channelCritSect; 92 FILE* _bitStreamFile; 93 bool _saveBitStream; 94 int16_t _lastPayloadType; 95 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS]; 96 bool _isStereo; 97 RTPHeader _rtp_header; 98 bool _leftChannel; 99 uint32_t _lastInTimestamp; 100 bool _useLastFrameSize; 101 uint32_t _lastFrameSizeSample; 102 // FEC Test variables 103 int16_t _packetLoss; 104 bool _useFECTestWithPacketLoss; 105 uint64_t _beginTime; 106 uint64_t _totalBytes; 107 108 // External timing info, defaulted to -1. Only used if they are 109 // non-negative. 110 int64_t external_send_timestamp_; 111 int32_t external_sequence_number_; 112 int num_packets_to_drop_; 113 }; 114 115 } // namespace webrtc 116 117 #endif // MODULES_AUDIO_CODING_TEST_CHANNEL_H_ 118