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 | |
| 11 | #ifndef CHANNEL_H |
| 12 | #define CHANNEL_H |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | |
| 16 | #include "audio_coding_module.h" |
| 17 | #include "critical_section_wrapper.h" |
| 18 | #include "rw_lock_wrapper.h" |
turaj@webrtc.org | c454fab | 2012-12-13 22:46:43 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/interface/module_common_types.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 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 26 | struct ACMTestFrameSizeStats { |
| 27 | uint16_t frameSizeSample; |
| 28 | int16_t maxPayloadLen; |
| 29 | uint32_t numPackets; |
| 30 | uint64_t totalPayloadLenByte; |
| 31 | uint64_t totalEncodedSamples; |
| 32 | double rateBitPerSec; |
| 33 | double usageLenSec; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 36 | struct ACMTestPayloadStats { |
| 37 | bool newPacket; |
| 38 | int16_t payloadType; |
| 39 | int16_t lastPayloadLenByte; |
| 40 | uint32_t lastTimestamp; |
| 41 | ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 44 | class Channel : public AudioPacketizationCallback { |
| 45 | public: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 47 | Channel(int16_t chID = -1); |
| 48 | ~Channel(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | int32_t SendData(const FrameType frameType, const uint8_t payloadType, |
| 51 | const uint32_t timeStamp, const uint8_t* payloadData, |
| 52 | const uint16_t payloadSize, |
| 53 | const RTPFragmentationHeader* fragmentation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 55 | void RegisterReceiverACM(AudioCodingModule *acm); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 56 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 57 | void ResetStats(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 58 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 59 | int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats); |
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 Stats(uint32_t* numPackets); |
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 | void Stats(uint8_t* payloadLenByte, uint32_t* payloadType); |
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 PrintStats(CodecInst& codecInst); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 66 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 67 | void SetIsStereo(bool isStereo) { |
| 68 | _isStereo = isStereo; |
| 69 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 71 | uint32_t LastInTimestamp(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 72 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 73 | void SetFECTestWithPacketLoss(bool usePacketLoss) { |
| 74 | _useFECTestWithPacketLoss = usePacketLoss; |
| 75 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | double BitRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 79 | private: |
| 80 | void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 82 | AudioCodingModule* _receiverACM; |
| 83 | uint16_t _seqNo; |
| 84 | // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample |
| 85 | uint8_t _payloadData[60 * 32 * 2 * 2]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 87 | CriticalSectionWrapper* _channelCritSect; |
| 88 | FILE* _bitStreamFile; |
| 89 | bool _saveBitStream; |
| 90 | int16_t _lastPayloadType; |
| 91 | ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS]; |
| 92 | bool _isStereo; |
| 93 | WebRtcRTPHeader _rtpInfo; |
| 94 | bool _leftChannel; |
| 95 | uint32_t _lastInTimestamp; |
| 96 | // FEC Test variables |
| 97 | int16_t _packetLoss; |
| 98 | bool _useFECTestWithPacketLoss; |
| 99 | uint64_t _beginTime; |
| 100 | uint64_t _totalBytes; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 103 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
| 105 | #endif |