blob: b4b51cf612c20b0e37f70ae0e941b662e10e5601 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orgc454fab2012-12-13 22:46:43 +000019#include "webrtc/modules/interface/module_common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23#define MAX_NUM_PAYLOADS 50
24#define MAX_NUM_FRAMESIZES 6
25
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000026struct 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.com470e71d2011-07-07 08:21:25 +000034};
35
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036struct ACMTestPayloadStats {
37 bool newPacket;
38 int16_t payloadType;
39 int16_t lastPayloadLenByte;
40 uint32_t lastTimestamp;
41 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
niklase@google.com470e71d2011-07-07 08:21:25 +000042};
43
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000044class Channel : public AudioPacketizationCallback {
45 public:
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047 Channel(int16_t chID = -1);
48 ~Channel();
niklase@google.com470e71d2011-07-07 08:21:25 +000049
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 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.com470e71d2011-07-07 08:21:25 +000054
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000055 void RegisterReceiverACM(AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000056
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000057 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000058
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000060
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061 void Stats(uint32_t* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063 void Stats(uint8_t* payloadLenByte, uint32_t* payloadType);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000064
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000065 void PrintStats(CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000066
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000067 void SetIsStereo(bool isStereo) {
68 _isStereo = isStereo;
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071 uint32_t LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000072
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000073 void SetFECTestWithPacketLoss(bool usePacketLoss) {
74 _useFECTestWithPacketLoss = usePacketLoss;
75 }
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 double BitRate();
niklase@google.com470e71d2011-07-07 08:21:25 +000078
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000079 private:
80 void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000081
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000082 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.com470e71d2011-07-07 08:21:25 +000086
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000087 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.com470e71d2011-07-07 08:21:25 +0000101};
102
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
105#endif