blob: a215c90ec1a0743dd01f1e15667bff9f3b65da22 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +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_TESTSTEREO_H_
12#define MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000014#include <math.h>
15
kwiberg37478382016-02-14 20:40:57 -080016#include <memory>
17
Henrik Lundin84f75692023-02-01 12:07:10 +000018#include "modules/audio_coding/acm2/acm_receiver.h"
Fredrik Solenberg657b2962018-12-05 10:30:25 +010019#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_coding/test/PCMFile.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000022#define PCMA_AND_PCMU
23
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000024namespace webrtc {
25
Yves Gerey665174f2018-06-19 15:03:05 +020026enum StereoMonoMode { kNotSet, kMono, kStereo };
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000027
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028class TestPackStereo : public AudioPacketizationCallback {
29 public:
30 TestPackStereo();
31 ~TestPackStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000032
Henrik Lundin84f75692023-02-01 12:07:10 +000033 void RegisterReceiverACM(acm2::AcmReceiver* acm_receiver);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
Ali Tofigh62238092022-01-25 13:27:19 +010035 int32_t SendData(AudioFrameType frame_type,
36 uint8_t payload_type,
37 uint32_t timestamp,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 const uint8_t* payload_data,
Ali Tofigh62238092022-01-25 13:27:19 +010039 size_t payload_size,
Minyue Liff0e4db2020-01-23 13:45:50 +010040 int64_t absolute_capture_timestamp_ms) override;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000041
pbos@webrtc.org0946a562013-04-09 00:28:06 +000042 uint16_t payload_size();
43 uint32_t timestamp_diff();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000044 void reset_payload_size();
45 void set_codec_mode(StereoMonoMode mode);
46 void set_lost_packet(bool lost);
47
48 private:
Henrik Lundin84f75692023-02-01 12:07:10 +000049 acm2::AcmReceiver* receiver_acm_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000050 int16_t seq_no_;
51 uint32_t timestamp_diff_;
52 uint32_t last_in_timestamp_;
53 uint64_t total_bytes_;
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000054 int payload_size_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000055 StereoMonoMode codec_mode_;
56 // Simulate packet losses
57 bool lost_packet_;
niklase@google.com470e71d2011-07-07 08:21:25 +000058};
59
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020060class TestStereo {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000061 public:
Fredrik Solenberg657b2962018-12-05 10:30:25 +010062 TestStereo();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000063 ~TestStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020065 void Perform();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000067 private:
68 // The default value of '-1' indicates that the registration is based only on
69 // codec name and a sampling frequncy matching is not required. This is useful
70 // for codecs which support several sampling frequency.
Yves Gerey665174f2018-06-19 15:03:05 +020071 void RegisterSendCodec(char side,
72 char* codec_name,
73 int32_t samp_freq_hz,
74 int rate,
75 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +020076 int channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
Yves Gerey665174f2018-06-19 15:03:05 +020078 void Run(TestPackStereo* channel,
79 int in_channels,
80 int out_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000081 int percent_loss = 0);
pbos@webrtc.org0946a562013-04-09 00:28:06 +000082 void OpenOutFile(int16_t test_number);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
kwiberg37478382016-02-14 20:40:57 -080084 std::unique_ptr<AudioCodingModule> acm_a_;
Henrik Lundin84f75692023-02-01 12:07:10 +000085 std::unique_ptr<acm2::AcmReceiver> acm_b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000087 TestPackStereo* channel_a2b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000089 PCMFile* in_file_stereo_;
90 PCMFile* in_file_mono_;
91 PCMFile out_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000092 int16_t test_cntr_;
93 uint16_t pack_size_samp_;
94 uint16_t pack_size_bytes_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 int counter_;
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +000096 char* send_codec_name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097};
98
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200101#endif // MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_