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