blob: 0d80631b37bf121009284cd1213ee7c69ba623ed [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
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +000018#include "modules/audio_coding/test/Channel.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/test/PCMFile.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000021#define PCMA_AND_PCMU
22
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000023namespace webrtc {
24
Yves Gerey665174f2018-06-19 15:03:05 +020025enum StereoMonoMode { kNotSet, kMono, kStereo };
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000026
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000027class TestPackStereo : public AudioPacketizationCallback {
28 public:
29 TestPackStereo();
30 ~TestPackStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000031
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000032 void RegisterReceiverACM(AudioCodingModule* acm);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000034 int32_t SendData(const FrameType frame_type,
35 const uint8_t payload_type,
36 const uint32_t timestamp,
37 const uint8_t* payload_data,
38 const size_t payload_size,
39 const RTPFragmentationHeader* fragmentation) override;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000040
pbos@webrtc.org0946a562013-04-09 00:28:06 +000041 uint16_t payload_size();
42 uint32_t timestamp_diff();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000043 void reset_payload_size();
44 void set_codec_mode(StereoMonoMode mode);
45 void set_lost_packet(bool lost);
46
47 private:
48 AudioCodingModule* receiver_acm_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000049 int16_t seq_no_;
50 uint32_t timestamp_diff_;
51 uint32_t last_in_timestamp_;
52 uint64_t total_bytes_;
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000053 int payload_size_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000054 StereoMonoMode codec_mode_;
55 // Simulate packet losses
56 bool lost_packet_;
niklase@google.com470e71d2011-07-07 08:21:25 +000057};
58
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020059class TestStereo {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000060 public:
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +000061 explicit TestStereo(int test_mode);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000062 ~TestStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020064 void Perform();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 private:
67 // The default value of '-1' indicates that the registration is based only on
68 // codec name and a sampling frequncy matching is not required. This is useful
69 // for codecs which support several sampling frequency.
Yves Gerey665174f2018-06-19 15:03:05 +020070 void RegisterSendCodec(char side,
71 char* codec_name,
72 int32_t samp_freq_hz,
73 int rate,
74 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +020075 int channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
Yves Gerey665174f2018-06-19 15:03:05 +020077 void Run(TestPackStereo* channel,
78 int in_channels,
79 int out_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000080 int percent_loss = 0);
pbos@webrtc.org0946a562013-04-09 00:28:06 +000081 void OpenOutFile(int16_t test_number);
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +000082 void DisplaySendReceiveCodec();
83
84 int test_mode_;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
kwiberg37478382016-02-14 20:40:57 -080086 std::unique_ptr<AudioCodingModule> acm_a_;
87 std::unique_ptr<AudioCodingModule> acm_b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000089 TestPackStereo* channel_a2b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000091 PCMFile* in_file_stereo_;
92 PCMFile* in_file_mono_;
93 PCMFile out_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094 int16_t test_cntr_;
95 uint16_t pack_size_samp_;
96 uint16_t pack_size_bytes_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000097 int counter_;
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +000098 char* send_codec_name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000099};
100
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000101} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200103#endif // MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_