blob: 74845841ba4cb14bfb1020c580d84ec14ec405e9 [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
26
27struct ACMTestFrameSizeStats
28{
29 WebRtc_UWord16 frameSizeSample;
30 WebRtc_Word16 maxPayloadLen;
31 WebRtc_UWord32 numPackets;
32 WebRtc_UWord64 totalPayloadLenByte;
33 WebRtc_UWord64 totalEncodedSamples;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000034 double rateBitPerSec;
35 double usageLenSec;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000036
niklase@google.com470e71d2011-07-07 08:21:25 +000037};
38
39struct ACMTestPayloadStats
40{
41 bool newPacket;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000042 WebRtc_Word16 payloadType;
43 WebRtc_Word16 lastPayloadLenByte;
44 WebRtc_UWord32 lastTimestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +000045 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
46};
47
niklase@google.com470e71d2011-07-07 08:21:25 +000048class Channel: public AudioPacketizationCallback
49{
50public:
51
52 Channel(
53 WebRtc_Word16 chID = -1);
54 ~Channel();
55
56 WebRtc_Word32 SendData(
57 const FrameType frameType,
58 const WebRtc_UWord8 payloadType,
59 const WebRtc_UWord32 timeStamp,
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000060 const WebRtc_UWord8* payloadData,
niklase@google.com470e71d2011-07-07 08:21:25 +000061 const WebRtc_UWord16 payloadSize,
62 const RTPFragmentationHeader* fragmentation);
63
64 void RegisterReceiverACM(
65 AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000066
niklase@google.com470e71d2011-07-07 08:21:25 +000067 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000068
niklase@google.com470e71d2011-07-07 08:21:25 +000069 WebRtc_Word16 Stats(
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000070 CodecInst& codecInst,
niklase@google.com470e71d2011-07-07 08:21:25 +000071 ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000072
niklase@google.com470e71d2011-07-07 08:21:25 +000073 void Stats(
74 WebRtc_UWord32* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000075
niklase@google.com470e71d2011-07-07 08:21:25 +000076 void Stats(
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000077 WebRtc_UWord8* payloadLenByte,
niklase@google.com470e71d2011-07-07 08:21:25 +000078 WebRtc_UWord32* payloadType);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000079
niklase@google.com470e71d2011-07-07 08:21:25 +000080 void PrintStats(
81 CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000082
niklase@google.com470e71d2011-07-07 08:21:25 +000083 void SetIsStereo(bool isStereo)
84 {
85 _isStereo = isStereo;
86 }
87
88 WebRtc_UWord32 LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000089
niklase@google.com470e71d2011-07-07 08:21:25 +000090 void SetFECTestWithPacketLoss(bool usePacketLoss)
91 {
92 _useFECTestWithPacketLoss = usePacketLoss;
93 }
94
95 double BitRate();
96
97private:
98 void CalcStatistics(
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000099 WebRtcRTPHeader& rtpInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 WebRtc_UWord16 payloadSize);
101
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000102 AudioCodingModule* _receiverACM;
103 WebRtc_UWord16 _seqNo;
104 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
105 WebRtc_UWord8 _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107 CriticalSectionWrapper* _channelCritSect;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000108 FILE* _bitStreamFile;
109 bool _saveBitStream;
110 WebRtc_Word16 _lastPayloadType;
111 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
112 bool _isStereo;
113 WebRtcRTPHeader _rtpInfo;
114 bool _leftChannel;
115 WebRtc_UWord32 _lastInTimestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 // FEC Test variables
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000117 WebRtc_Word16 _packetLoss;
118 bool _useFECTestWithPacketLoss;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000119 WebRtc_UWord64 _beginTime;
120 WebRtc_UWord64 _totalBytes;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121};
122
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000123} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
125#endif