blob: 55167d359af5446ad48168ec9754852f9bfdb648 [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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <stdio.h>
15
turaj@webrtc.orga305e962013-06-06 19:00:09 +000016#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
turaj@webrtc.orgc454fab2012-12-13 22:46:43 +000017#include "webrtc/modules/interface/module_common_types.h"
turaj@webrtc.orga305e962013-06-06 19:00:09 +000018#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
turaj@webrtc.orga305e962013-06-06 19:00:09 +000022class CriticalSectionWrapper;
23
niklase@google.com470e71d2011-07-07 08:21:25 +000024#define MAX_NUM_PAYLOADS 50
25#define MAX_NUM_FRAMESIZES 6
26
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000027// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000028struct ACMTestFrameSizeStats {
29 uint16_t frameSizeSample;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000030 size_t maxPayloadLen;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000031 uint32_t numPackets;
32 uint64_t totalPayloadLenByte;
33 uint64_t totalEncodedSamples;
34 double rateBitPerSec;
35 double usageLenSec;
niklase@google.com470e71d2011-07-07 08:21:25 +000036};
37
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000038// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039struct ACMTestPayloadStats {
40 bool newPacket;
41 int16_t payloadType;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000042 size_t lastPayloadLenByte;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000043 uint32_t lastTimestamp;
44 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
46
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047class Channel : public AudioPacketizationCallback {
48 public:
niklase@google.com470e71d2011-07-07 08:21:25 +000049
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 Channel(int16_t chID = -1);
51 ~Channel();
niklase@google.com470e71d2011-07-07 08:21:25 +000052
henrike@webrtc.org47658f12014-09-10 22:14:59 +000053 virtual int32_t SendData(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000054 FrameType frameType,
55 uint8_t payloadType,
56 uint32_t timeStamp,
57 const uint8_t* payloadData,
58 size_t payloadSize,
henrike@webrtc.org47658f12014-09-10 22:14:59 +000059 const RTPFragmentationHeader* fragmentation) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061 void RegisterReceiverACM(AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000064
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000065 int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000066
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000067 void Stats(uint32_t* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000068
pkasting@chromium.orgd3245462015-02-23 21:28:22 +000069 void Stats(uint8_t* payloadType, uint32_t* payloadLenByte);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000070
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071 void PrintStats(CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000072
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000073 void SetIsStereo(bool isStereo) {
74 _isStereo = isStereo;
75 }
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 uint32_t LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000078
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000079 void SetFECTestWithPacketLoss(bool usePacketLoss) {
80 _useFECTestWithPacketLoss = usePacketLoss;
81 }
niklase@google.com470e71d2011-07-07 08:21:25 +000082
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000083 double BitRate();
niklase@google.com470e71d2011-07-07 08:21:25 +000084
turaj@webrtc.orga305e962013-06-06 19:00:09 +000085 void set_send_timestamp(uint32_t new_send_ts) {
86 external_send_timestamp_ = new_send_ts;
87 }
88
89 void set_sequence_number(uint16_t new_sequence_number) {
90 external_sequence_number_ = new_sequence_number;
91 }
92
93 void set_num_packets_to_drop(int new_num_packets_to_drop) {
94 num_packets_to_drop_ = new_num_packets_to_drop;
95 }
96
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000098 void CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100 AudioCodingModule* _receiverACM;
101 uint16_t _seqNo;
102 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
103 uint8_t _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105 CriticalSectionWrapper* _channelCritSect;
106 FILE* _bitStreamFile;
107 bool _saveBitStream;
108 int16_t _lastPayloadType;
109 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
110 bool _isStereo;
111 WebRtcRTPHeader _rtpInfo;
112 bool _leftChannel;
113 uint32_t _lastInTimestamp;
minyue@webrtc.org05617162015-03-03 12:02:30 +0000114 bool _useLastFrameSize;
115 uint32_t _lastFrameSizeSample;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116 // FEC Test variables
117 int16_t _packetLoss;
118 bool _useFECTestWithPacketLoss;
119 uint64_t _beginTime;
120 uint64_t _totalBytes;
turaj@webrtc.orga305e962013-06-06 19:00:09 +0000121
122 // External timing info, defaulted to -1. Only used if they are
123 // non-negative.
124 int64_t external_send_timestamp_;
125 int32_t external_sequence_number_;
126 int num_packets_to_drop_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127};
128
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000129} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000131#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_