blob: 617027e7d0571a76344684ad6ea409121eb6b9fe [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"
19
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22#define MAX_NUM_PAYLOADS 50
23#define MAX_NUM_FRAMESIZES 6
24
25
26struct ACMTestFrameSizeStats
27{
28 WebRtc_UWord16 frameSizeSample;
29 WebRtc_Word16 maxPayloadLen;
30 WebRtc_UWord32 numPackets;
31 WebRtc_UWord64 totalPayloadLenByte;
32 WebRtc_UWord64 totalEncodedSamples;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000033 double rateBitPerSec;
34 double usageLenSec;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000035
niklase@google.com470e71d2011-07-07 08:21:25 +000036};
37
38struct ACMTestPayloadStats
39{
40 bool newPacket;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000041 WebRtc_Word16 payloadType;
42 WebRtc_Word16 lastPayloadLenByte;
43 WebRtc_UWord32 lastTimestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +000044 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
45};
46
niklase@google.com470e71d2011-07-07 08:21:25 +000047class Channel: public AudioPacketizationCallback
48{
49public:
50
51 Channel(
52 WebRtc_Word16 chID = -1);
53 ~Channel();
54
55 WebRtc_Word32 SendData(
56 const FrameType frameType,
57 const WebRtc_UWord8 payloadType,
58 const WebRtc_UWord32 timeStamp,
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000059 const WebRtc_UWord8* payloadData,
niklase@google.com470e71d2011-07-07 08:21:25 +000060 const WebRtc_UWord16 payloadSize,
61 const RTPFragmentationHeader* fragmentation);
62
63 void RegisterReceiverACM(
64 AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000065
niklase@google.com470e71d2011-07-07 08:21:25 +000066 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000067
niklase@google.com470e71d2011-07-07 08:21:25 +000068 WebRtc_Word16 Stats(
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +000069 CodecInst& codecInst,
niklase@google.com470e71d2011-07-07 08:21:25 +000070 ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000071
niklase@google.com470e71d2011-07-07 08:21:25 +000072 void Stats(
73 WebRtc_UWord32* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000074
niklase@google.com470e71d2011-07-07 08:21:25 +000075 void Stats(
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000076 WebRtc_UWord8* payloadLenByte,
niklase@google.com470e71d2011-07-07 08:21:25 +000077 WebRtc_UWord32* payloadType);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000078
niklase@google.com470e71d2011-07-07 08:21:25 +000079 void PrintStats(
80 CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000081
niklase@google.com470e71d2011-07-07 08:21:25 +000082 void SetIsStereo(bool isStereo)
83 {
84 _isStereo = isStereo;
85 }
86
87 WebRtc_UWord32 LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000088
niklase@google.com470e71d2011-07-07 08:21:25 +000089 void SetFECTestWithPacketLoss(bool usePacketLoss)
90 {
91 _useFECTestWithPacketLoss = usePacketLoss;
92 }
93
94 double BitRate();
95
96private:
97 void CalcStatistics(
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000098 WebRtcRTPHeader& rtpInfo,
niklase@google.com470e71d2011-07-07 08:21:25 +000099 WebRtc_UWord16 payloadSize);
100
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000101 AudioCodingModule* _receiverACM;
102 WebRtc_UWord16 _seqNo;
103 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
104 WebRtc_UWord8 _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
106 CriticalSectionWrapper* _channelCritSect;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000107 FILE* _bitStreamFile;
108 bool _saveBitStream;
109 WebRtc_Word16 _lastPayloadType;
110 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
111 bool _isStereo;
112 WebRtcRTPHeader _rtpInfo;
113 bool _leftChannel;
114 WebRtc_UWord32 _lastInTimestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 // FEC Test variables
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000116 WebRtc_Word16 _packetLoss;
117 bool _useFECTestWithPacketLoss;
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000118 WebRtc_UWord64 _beginTime;
119 WebRtc_UWord64 _totalBytes;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120};
121
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000122} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
124#endif