blob: 4526be6960398a64a0690d537ae48af1a57b7c1b [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
kjellander3e6db232015-11-26 04:44:54 -080011#ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
12#define WEBRTC_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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000016#include "webrtc/base/scoped_ptr.h"
kjellander3e6db232015-11-26 04:44:54 -080017#include "webrtc/modules/audio_coding/test/ACMTest.h"
18#include "webrtc/modules/audio_coding/test/Channel.h"
19#include "webrtc/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
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000025enum StereoMonoMode {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000026 kNotSet,
27 kMono,
28 kStereo
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000029};
30
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000031class TestPackStereo : public AudioPacketizationCallback {
32 public:
33 TestPackStereo();
34 ~TestPackStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000035
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000036 void RegisterReceiverACM(AudioCodingModule* acm);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 int32_t SendData(const FrameType frame_type,
39 const uint8_t payload_type,
40 const uint32_t timestamp,
41 const uint8_t* payload_data,
42 const size_t payload_size,
43 const RTPFragmentationHeader* fragmentation) override;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000044
pbos@webrtc.org0946a562013-04-09 00:28:06 +000045 uint16_t payload_size();
46 uint32_t timestamp_diff();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000047 void reset_payload_size();
48 void set_codec_mode(StereoMonoMode mode);
49 void set_lost_packet(bool lost);
50
51 private:
52 AudioCodingModule* receiver_acm_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000053 int16_t seq_no_;
54 uint32_t timestamp_diff_;
55 uint32_t last_in_timestamp_;
56 uint64_t total_bytes_;
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000057 int payload_size_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000058 StereoMonoMode codec_mode_;
59 // Simulate packet losses
60 bool lost_packet_;
niklase@google.com470e71d2011-07-07 08:21:25 +000061};
62
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000063class TestStereo : public ACMTest {
64 public:
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +000065 explicit TestStereo(int test_mode);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 ~TestStereo();
niklase@google.com470e71d2011-07-07 08:21:25 +000067
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000068 void Perform() override;
69
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000070 private:
71 // The default value of '-1' indicates that the registration is based only on
72 // codec name and a sampling frequncy matching is not required. This is useful
73 // for codecs which support several sampling frequency.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000074 void RegisterSendCodec(char side, char* codec_name, int32_t samp_freq_hz,
75 int rate, int pack_size, int channels,
76 int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000078 void Run(TestPackStereo* channel, int in_channels, int out_channels,
79 int percent_loss = 0);
pbos@webrtc.org0946a562013-04-09 00:28:06 +000080 void OpenOutFile(int16_t test_number);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000081 void DisplaySendReceiveCodec();
niklase@google.com470e71d2011-07-07 08:21:25 +000082
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 int test_mode_;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000085 rtc::scoped_ptr<AudioCodingModule> acm_a_;
86 rtc::scoped_ptr<AudioCodingModule> acm_b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000088 TestPackStereo* channel_a2b_;
niklase@google.com470e71d2011-07-07 08:21:25 +000089
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000090 PCMFile* in_file_stereo_;
91 PCMFile* in_file_mono_;
92 PCMFile out_file_;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000093 int16_t test_cntr_;
94 uint16_t pack_size_samp_;
95 uint16_t pack_size_bytes_;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 int counter_;
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +000097 char* send_codec_name_;
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +000098
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099 // Payload types for stereo codecs and CNG
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000100#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000101 int g722_pltype_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000102#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 int l16_8khz_pltype_;
104 int l16_16khz_pltype_;
105 int l16_32khz_pltype_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000106#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 int pcma_pltype_;
108 int pcmu_pltype_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000109#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000110#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000111 int opus_pltype_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000112#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000113};
114
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000115} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
kjellander3e6db232015-11-26 04:44:54 -0800117#endif // WEBRTC_MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_