blob: 7611c9d6e30a464852b3ad849c09b6ba0c378a19 [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;
30 int16_t maxPayloadLen;
31 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;
42 int16_t lastPayloadLenByte;
43 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
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000053 int32_t SendData(const FrameType frameType, const uint8_t payloadType,
54 const uint32_t timeStamp, const uint8_t* payloadData,
55 const uint16_t payloadSize,
56 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 void RegisterReceiverACM(AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000059
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000060 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000061
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000062 int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000063
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000064 void Stats(uint32_t* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000065
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000066 void Stats(uint8_t* payloadLenByte, uint32_t* payloadType);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000067
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 void PrintStats(CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000069
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000070 void SetIsStereo(bool isStereo) {
71 _isStereo = isStereo;
72 }
niklase@google.com470e71d2011-07-07 08:21:25 +000073
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000074 uint32_t LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000075
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000076 void SetFECTestWithPacketLoss(bool usePacketLoss) {
77 _useFECTestWithPacketLoss = usePacketLoss;
78 }
niklase@google.com470e71d2011-07-07 08:21:25 +000079
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000080 double BitRate();
niklase@google.com470e71d2011-07-07 08:21:25 +000081
turaj@webrtc.orga305e962013-06-06 19:00:09 +000082 void set_send_timestamp(uint32_t new_send_ts) {
83 external_send_timestamp_ = new_send_ts;
84 }
85
86 void set_sequence_number(uint16_t new_sequence_number) {
87 external_sequence_number_ = new_sequence_number;
88 }
89
90 void set_num_packets_to_drop(int new_num_packets_to_drop) {
91 num_packets_to_drop_ = new_num_packets_to_drop;
92 }
93
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000094 private:
95 void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 AudioCodingModule* _receiverACM;
98 uint16_t _seqNo;
99 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
100 uint8_t _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102 CriticalSectionWrapper* _channelCritSect;
103 FILE* _bitStreamFile;
104 bool _saveBitStream;
105 int16_t _lastPayloadType;
106 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
107 bool _isStereo;
108 WebRtcRTPHeader _rtpInfo;
109 bool _leftChannel;
110 uint32_t _lastInTimestamp;
111 // FEC Test variables
112 int16_t _packetLoss;
113 bool _useFECTestWithPacketLoss;
114 uint64_t _beginTime;
115 uint64_t _totalBytes;
turaj@webrtc.orga305e962013-06-06 19:00:09 +0000116
117 // External timing info, defaulted to -1. Only used if they are
118 // non-negative.
119 int64_t external_send_timestamp_;
120 int32_t external_sequence_number_;
121 int num_packets_to_drop_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122};
123
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000124} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000126#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_