blob: 0b248c847b491af01535691ddcc3473e7e44a141 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_CHANNEL_H_
12#define MODULES_AUDIO_CODING_TEST_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <stdio.h>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_coding/include/audio_coding_module.h"
17#include "modules/include/module_common_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/critical_section.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
Yves Gerey665174f2018-06-19 15:03:05 +020022#define MAX_NUM_PAYLOADS 50
23#define MAX_NUM_FRAMESIZES 6
niklase@google.com470e71d2011-07-07 08:21:25 +000024
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000025// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000026struct ACMTestFrameSizeStats {
27 uint16_t frameSizeSample;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000028 size_t maxPayloadLen;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000029 uint32_t numPackets;
30 uint64_t totalPayloadLenByte;
31 uint64_t totalEncodedSamples;
32 double rateBitPerSec;
33 double usageLenSec;
niklase@google.com470e71d2011-07-07 08:21:25 +000034};
35
turaj@webrtc.orgc2d69d32014-02-19 20:31:17 +000036// TODO(turajs): Write constructor for this structure.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000037struct ACMTestPayloadStats {
38 bool newPacket;
39 int16_t payloadType;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000040 size_t lastPayloadLenByte;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000041 uint32_t lastTimestamp;
42 ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
niklase@google.com470e71d2011-07-07 08:21:25 +000043};
44
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000045class Channel : public AudioPacketizationCallback {
46 public:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047 Channel(int16_t chID = -1);
kwiberg65fc8b92016-08-29 10:05:24 -070048 ~Channel() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
Niels Möller87e2d782019-03-07 10:18:23 +010050 int32_t SendData(AudioFrameType frameType,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000051 uint8_t payloadType,
52 uint32_t timeStamp,
53 const uint8_t* payloadData,
Niels Möllerc35b6e62019-04-25 16:31:18 +020054 size_t payloadSize) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
Yves Gerey665174f2018-06-19 15:03:05 +020056 void RegisterReceiverACM(AudioCodingModule* acm);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000057
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 void ResetStats();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000059
Yves Gerey665174f2018-06-19 15:03:05 +020060 void SetIsStereo(bool isStereo) { _isStereo = isStereo; }
niklase@google.com470e71d2011-07-07 08:21:25 +000061
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000062 uint32_t LastInTimestamp();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000063
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000064 void SetFECTestWithPacketLoss(bool usePacketLoss) {
65 _useFECTestWithPacketLoss = usePacketLoss;
66 }
niklase@google.com470e71d2011-07-07 08:21:25 +000067
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 double BitRate();
niklase@google.com470e71d2011-07-07 08:21:25 +000069
turaj@webrtc.orga305e962013-06-06 19:00:09 +000070 void set_send_timestamp(uint32_t new_send_ts) {
71 external_send_timestamp_ = new_send_ts;
72 }
73
74 void set_sequence_number(uint16_t new_sequence_number) {
75 external_sequence_number_ = new_sequence_number;
76 }
77
78 void set_num_packets_to_drop(int new_num_packets_to_drop) {
79 num_packets_to_drop_ = new_num_packets_to_drop;
80 }
81
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000082 private:
Niels Möllerbf474952019-02-18 12:00:06 +010083 void CalcStatistics(const RTPHeader& rtp_header, size_t payloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000085 AudioCodingModule* _receiverACM;
86 uint16_t _seqNo;
87 // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
88 uint8_t _payloadData[60 * 32 * 2 * 2];
niklase@google.com470e71d2011-07-07 08:21:25 +000089
pbos5ad935c2016-01-25 03:52:44 -080090 rtc::CriticalSection _channelCritSect;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000091 FILE* _bitStreamFile;
92 bool _saveBitStream;
93 int16_t _lastPayloadType;
94 ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
95 bool _isStereo;
Niels Möllerbf474952019-02-18 12:00:06 +010096 RTPHeader _rtp_header;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 bool _leftChannel;
98 uint32_t _lastInTimestamp;
minyue@webrtc.org05617162015-03-03 12:02:30 +000099 bool _useLastFrameSize;
100 uint32_t _lastFrameSizeSample;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101 // FEC Test variables
102 int16_t _packetLoss;
103 bool _useFECTestWithPacketLoss;
104 uint64_t _beginTime;
105 uint64_t _totalBytes;
turaj@webrtc.orga305e962013-06-06 19:00:09 +0000106
107 // External timing info, defaulted to -1. Only used if they are
108 // non-negative.
109 int64_t external_send_timestamp_;
110 int32_t external_sequence_number_;
111 int num_packets_to_drop_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112};
113
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000114} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // MODULES_AUDIO_CODING_TEST_CHANNEL_H_