2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/test/fake_audio_capture_module.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <string.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2020-07-07 19:08:53 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
class FakeAdmTest : public ::testing::Test, public webrtc::AudioTransport {
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
|
|
|
|
static const int kMsInSecond = 1000;
|
|
|
|
|
|
|
|
|
|
FakeAdmTest()
|
|
|
|
|
: push_iterations_(0), pull_iterations_(0), rec_buffer_bytes_(0) {
|
|
|
|
|
memset(rec_buffer_, 0, sizeof(rec_buffer_));
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
void SetUp() override {
|
2015-08-13 14:27:18 -07:00
|
|
|
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(fake_audio_capture_module_.get() != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Callbacks inherited from webrtc::AudioTransport.
|
|
|
|
|
// ADM is pushing data.
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
int32_t RecordedDataIsAvailable(const void* audioSamples,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t nSamples,
|
|
|
|
|
const size_t nBytesPerSample,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t nChannels,
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
const uint32_t samplesPerSec,
|
|
|
|
|
const uint32_t totalDelayMS,
|
|
|
|
|
const int32_t clockDrift,
|
|
|
|
|
const uint32_t currentMicLevel,
|
|
|
|
|
const bool keyPressed,
|
|
|
|
|
uint32_t& newMicLevel) override {
|
2020-07-07 19:08:53 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
rec_buffer_bytes_ = nSamples * nBytesPerSample;
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
if ((rec_buffer_bytes_ == 0) ||
|
2013-07-10 00:45:36 +00:00
|
|
|
(rec_buffer_bytes_ >
|
|
|
|
|
FakeAudioCaptureModule::kNumberSamples *
|
|
|
|
|
FakeAudioCaptureModule::kNumberBytesPerSample)) {
|
|
|
|
|
ADD_FAILURE();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
memcpy(rec_buffer_, audioSamples, rec_buffer_bytes_);
|
|
|
|
|
++push_iterations_;
|
|
|
|
|
newMicLevel = currentMicLevel;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 11:46:19 -07:00
|
|
|
void PullRenderData(int bits_per_sample,
|
|
|
|
|
int sample_rate,
|
|
|
|
|
size_t number_of_channels,
|
|
|
|
|
size_t number_of_frames,
|
|
|
|
|
void* audio_data,
|
|
|
|
|
int64_t* elapsed_time_ms,
|
|
|
|
|
int64_t* ntp_time_ms) override {}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
// ADM is pulling data.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
int32_t NeedMorePlayData(const size_t nSamples,
|
|
|
|
|
const size_t nBytesPerSample,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t nChannels,
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
const uint32_t samplesPerSec,
|
|
|
|
|
void* audioSamples,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t& nSamplesOut,
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
int64_t* elapsed_time_ms,
|
|
|
|
|
int64_t* ntp_time_ms) override {
|
2020-07-07 19:08:53 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2013-07-10 00:45:36 +00:00
|
|
|
++pull_iterations_;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t audio_buffer_size = nSamples * nBytesPerSample;
|
|
|
|
|
const size_t bytes_out =
|
|
|
|
|
RecordedDataReceived()
|
2013-07-10 00:45:36 +00:00
|
|
|
? CopyFromRecBuffer(audioSamples, audio_buffer_size)
|
|
|
|
|
: GenerateZeroBuffer(audioSamples, audio_buffer_size);
|
|
|
|
|
nSamplesOut = bytes_out / nBytesPerSample;
|
2014-06-05 20:34:08 +00:00
|
|
|
*elapsed_time_ms = 0;
|
2014-07-14 20:05:09 +00:00
|
|
|
*ntp_time_ms = 0;
|
2013-07-10 00:45:36 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 14:27:18 -07:00
|
|
|
int push_iterations() const {
|
2020-07-07 19:08:53 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2015-08-13 14:27:18 -07:00
|
|
|
return push_iterations_;
|
|
|
|
|
}
|
|
|
|
|
int pull_iterations() const {
|
2020-07-07 19:08:53 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2015-08-13 14:27:18 -07:00
|
|
|
return pull_iterations_;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool RecordedDataReceived() const { return rec_buffer_bytes_ != 0; }
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t GenerateZeroBuffer(void* audio_buffer, size_t audio_buffer_size) {
|
2013-07-10 00:45:36 +00:00
|
|
|
memset(audio_buffer, 0, audio_buffer_size);
|
|
|
|
|
return audio_buffer_size;
|
|
|
|
|
}
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t CopyFromRecBuffer(void* audio_buffer, size_t audio_buffer_size) {
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_EQ(audio_buffer_size, rec_buffer_bytes_);
|
2019-01-28 17:25:26 -08:00
|
|
|
const size_t min_buffer_size =
|
|
|
|
|
std::min(audio_buffer_size, rec_buffer_bytes_);
|
2013-07-10 00:45:36 +00:00
|
|
|
memcpy(audio_buffer, rec_buffer_, min_buffer_size);
|
|
|
|
|
return min_buffer_size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 19:08:53 +02:00
|
|
|
mutable webrtc::Mutex mutex_;
|
2015-08-13 14:27:18 -07:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
int push_iterations_;
|
|
|
|
|
int pull_iterations_;
|
|
|
|
|
|
|
|
|
|
char rec_buffer_[FakeAudioCaptureModule::kNumberSamples *
|
|
|
|
|
FakeAudioCaptureModule::kNumberBytesPerSample];
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t rec_buffer_bytes_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(FakeAdmTest, PlayoutTest) {
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->RegisterAudioCallback(this));
|
|
|
|
|
|
|
|
|
|
bool stereo_available = false;
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StereoPlayoutIsAvailable(
|
|
|
|
|
&stereo_available));
|
|
|
|
|
EXPECT_TRUE(stereo_available);
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(0, fake_audio_capture_module_->StartPlayout());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->PlayoutIsInitialized());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->Playing());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->InitPlayout());
|
|
|
|
|
EXPECT_TRUE(fake_audio_capture_module_->PlayoutIsInitialized());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->Playing());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StartPlayout());
|
|
|
|
|
EXPECT_TRUE(fake_audio_capture_module_->Playing());
|
|
|
|
|
|
|
|
|
|
uint16_t delay_ms = 10;
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->PlayoutDelay(&delay_ms));
|
|
|
|
|
EXPECT_EQ(0, delay_ms);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond);
|
|
|
|
|
EXPECT_GE(0, push_iterations());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->Playing());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FakeAdmTest, RecordTest) {
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->RegisterAudioCallback(this));
|
|
|
|
|
|
|
|
|
|
bool stereo_available = false;
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StereoRecordingIsAvailable(
|
|
|
|
|
&stereo_available));
|
|
|
|
|
EXPECT_FALSE(stereo_available);
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(0, fake_audio_capture_module_->StartRecording());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->Recording());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->InitRecording());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StartRecording());
|
|
|
|
|
EXPECT_TRUE(fake_audio_capture_module_->Recording());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond);
|
|
|
|
|
EXPECT_GE(0, pull_iterations());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());
|
|
|
|
|
EXPECT_FALSE(fake_audio_capture_module_->Recording());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FakeAdmTest, DuplexTest) {
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->RegisterAudioCallback(this));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->InitPlayout());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StartPlayout());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->InitRecording());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StartRecording());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond);
|
|
|
|
|
EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
|
|
|
|
|
EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());
|
|
|
|
|
}
|