blob: c45864acbbb7cece19a2b34e550e0ba7877d5fe7 [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
kjellander3e6db232015-11-26 04:44:54 -080011#ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_
12#define WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <stdio.h>
15
Tommi9090e0b2016-01-20 13:39:36 +010016#include "webrtc/base/criticalsection.h"
kjellander3e6db232015-11-26 04:44:54 -080017#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010018#include "webrtc/modules/include/module_common_types.h"
turaj@webrtc.orga305e962013-06-06 19:00:09 +000019#include "webrtc/typedefs.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
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000026// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000027struct ACMTestFrameSizeStats {
28 uint16_t frameSizeSample;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000029 size_t maxPayloadLen;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000030 uint32_t numPackets;
31 uint64_t totalPayloadLenByte;
32 uint64_t totalEncodedSamples;
33 double rateBitPerSec;
34 double usageLenSec;
niklase@google.com470e71d2011-07-07 08:21:25 +000035};
36
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000037// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000038struct ACMTestPayloadStats {
39 bool newPacket;
40 int16_t payloadType;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000041 size_t lastPayloadLenByte;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000042 uint32_t lastTimestamp;
43 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
niklase@google.com470e71d2011-07-07 08:21:25 +000044};
45
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046class Channel : public AudioPacketizationCallback {
47 public:
niklase@google.com470e71d2011-07-07 08:21:25 +000048
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000049 Channel(int16_t chID = -1);
kwiberg65fc8b92016-08-29 10:05:24 -070050 ~Channel() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000052 int32_t SendData(FrameType frameType,
53 uint8_t payloadType,
54 uint32_t timeStamp,
55 const uint8_t* payloadData,
56 size_t payloadSize,
57 const RTPFragmentationHeader* fragmentation) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 void RegisterReceiverACM(AudioCodingModule *acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000060
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063 int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000064
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000065 void Stats(uint32_t* numPackets);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000066
pkasting@chromium.orgd3245462015-02-23 21:28:22 +000067 void Stats(uint8_t* payloadType, uint32_t* payloadLenByte);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000068
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000069 void PrintStats(CodecInst& codecInst);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000070
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071 void SetIsStereo(bool isStereo) {
72 _isStereo = isStereo;
73 }
niklase@google.com470e71d2011-07-07 08:21:25 +000074
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000075 uint32_t LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000076
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 void SetFECTestWithPacketLoss(bool usePacketLoss) {
78 _useFECTestWithPacketLoss = usePacketLoss;
79 }
niklase@google.com470e71d2011-07-07 08:21:25 +000080
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000081 double BitRate();
niklase@google.com470e71d2011-07-07 08:21:25 +000082
turaj@webrtc.orga305e962013-06-06 19:00:09 +000083 void set_send_timestamp(uint32_t new_send_ts) {
84 external_send_timestamp_ = new_send_ts;
85 }
86
87 void set_sequence_number(uint16_t new_sequence_number) {
88 external_sequence_number_ = new_sequence_number;
89 }
90
91 void set_num_packets_to_drop(int new_num_packets_to_drop) {
92 num_packets_to_drop_ = new_num_packets_to_drop;
93 }
94
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000095 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000096 void CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000098 AudioCodingModule* _receiverACM;
99 uint16_t _seqNo;
100 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
101 uint8_t _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
pbos5ad935c2016-01-25 03:52:44 -0800103 rtc::CriticalSection _channelCritSect;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000104 FILE* _bitStreamFile;
105 bool _saveBitStream;
106 int16_t _lastPayloadType;
107 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
108 bool _isStereo;
109 WebRtcRTPHeader _rtpInfo;
110 bool _leftChannel;
111 uint32_t _lastInTimestamp;
minyue@webrtc.org05617162015-03-03 12:02:30 +0000112 bool _useLastFrameSize;
113 uint32_t _lastFrameSizeSample;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000114 // FEC Test variables
115 int16_t _packetLoss;
116 bool _useFECTestWithPacketLoss;
117 uint64_t _beginTime;
118 uint64_t _totalBytes;
turaj@webrtc.orga305e962013-06-06 19:00:09 +0000119
120 // External timing info, defaulted to -1. Only used if they are
121 // non-negative.
122 int64_t external_send_timestamp_;
123 int32_t external_sequence_number_;
124 int num_packets_to_drop_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125};
126
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000127} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
kjellander3e6db232015-11-26 04:44:54 -0800129#endif // WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_