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 | |
| 26 | |
| 27 | struct ACMTestFrameSizeStats |
| 28 | { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 29 | uint16_t frameSizeSample; |
| 30 | int16_t maxPayloadLen; |
| 31 | uint32_t numPackets; |
| 32 | uint64_t totalPayloadLenByte; |
| 33 | uint64_t totalEncodedSamples; |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 34 | double rateBitPerSec; |
| 35 | double usageLenSec; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 36 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct ACMTestPayloadStats |
| 40 | { |
| 41 | bool newPacket; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 42 | int16_t payloadType; |
| 43 | int16_t lastPayloadLenByte; |
| 44 | uint32_t lastTimestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES]; |
| 46 | }; |
| 47 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | class Channel: public AudioPacketizationCallback |
| 49 | { |
| 50 | public: |
| 51 | |
| 52 | Channel( |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 53 | int16_t chID = -1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | ~Channel(); |
| 55 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 56 | int32_t SendData( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | const FrameType frameType, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 58 | const uint8_t payloadType, |
| 59 | const uint32_t timeStamp, |
| 60 | const uint8_t* payloadData, |
| 61 | const uint16_t payloadSize, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | const RTPFragmentationHeader* fragmentation); |
| 63 | |
| 64 | void RegisterReceiverACM( |
| 65 | AudioCodingModule *acm); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 66 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | void ResetStats(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 68 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 69 | int16_t Stats( |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 70 | CodecInst& codecInst, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | ACMTestPayloadStats& payloadStats); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 72 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | void Stats( |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 74 | uint32_t* numPackets); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 75 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | void Stats( |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 77 | uint8_t* payloadLenByte, |
| 78 | uint32_t* payloadType); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 79 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | void PrintStats( |
| 81 | CodecInst& codecInst); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 82 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | void SetIsStereo(bool isStereo) |
| 84 | { |
| 85 | _isStereo = isStereo; |
| 86 | } |
| 87 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 88 | uint32_t LastInTimestamp(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 89 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | void SetFECTestWithPacketLoss(bool usePacketLoss) |
| 91 | { |
| 92 | _useFECTestWithPacketLoss = usePacketLoss; |
| 93 | } |
| 94 | |
| 95 | double BitRate(); |
| 96 | |
| 97 | private: |
| 98 | void CalcStatistics( |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 99 | WebRtcRTPHeader& rtpInfo, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 100 | uint16_t payloadSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 102 | AudioCodingModule* _receiverACM; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 103 | uint16_t _seqNo; |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 104 | // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 105 | uint8_t _payloadData[60 * 32 * 2 * 2]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
| 107 | CriticalSectionWrapper* _channelCritSect; |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 108 | FILE* _bitStreamFile; |
| 109 | bool _saveBitStream; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 110 | int16_t _lastPayloadType; |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 111 | ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS]; |
| 112 | bool _isStereo; |
| 113 | WebRtcRTPHeader _rtpInfo; |
| 114 | bool _leftChannel; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 115 | uint32_t _lastInTimestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | // FEC Test variables |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 117 | int16_t _packetLoss; |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 118 | bool _useFECTestWithPacketLoss; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 119 | uint64_t _beginTime; |
| 120 | uint64_t _totalBytes; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 123 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | |
| 125 | #endif |