-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hold output buffer at
ResamplerBase
.
- `ResamplerBase`: - Fed at most one frame at a time. We can calculate at initialization the maximum output frames. - Ala cl/703469056 we can pre allocated the buffer. - Add some tests now that it is not pure abstract. - `ResamplerQWrapper`: - Update to new interface. Use `ResamblerBase` buffer instead of being passed in. - Switch to a factory function, so we can seed `ResamplerBase` with an accurate maximum output frames. - Add a factory function argument, which represents the number of samples per frame in the input codec. - Use `audio_dsp::MaxOutputFrames` based on the new argument to determine the maximum number of frames in the output codec (to seed the new held buffer). - `codec_transcoder_test`: - Some tests were testing both the mock receiving the argument, and the transcoder using it. Split these into a mock test to receive, and a simple implementation to check the output works. PiperOrigin-RevId: 704802974
- Loading branch information
Showing
5 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
#include "iamf/cli/resampler_base.h" | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/status_matchers.h" | ||
#include "absl/types/span.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "iamf/cli/tests/cli_test_utils.h" | ||
|
||
namespace iamf_tools { | ||
namespace { | ||
|
||
using ::absl_testing::IsOk; | ||
|
||
constexpr uint32_t kMaxNumSamplesPerFrame = 4; | ||
constexpr size_t kNumChannels = 2; | ||
|
||
class MockResampler : public ResamplerBase { | ||
public: | ||
MockResampler(uint32_t max_num_samples_per_frame, size_t num_channels) | ||
: ResamplerBase(max_num_samples_per_frame, num_channels) {} | ||
|
||
MOCK_METHOD(absl::Status, PushFrame, | ||
(absl::Span<const std::vector<int32_t>> time_channel_samples), | ||
(override)); | ||
|
||
MOCK_METHOD(absl::Status, Flush, (), (override)); | ||
}; | ||
|
||
TEST(GetOutputSamplesAsSpan, ReturnsEmptyAfterConstruction) { | ||
MockResampler mock_resampler(kMaxNumSamplesPerFrame, kNumChannels); | ||
EXPECT_TRUE(mock_resampler.GetOutputSamplesAsSpan().empty()); | ||
} | ||
|
||
TEST(GetOutputSamplesAsSpan, SizeMatchesNumValidTicks) { | ||
EverySecondTickResampler every_second_tick_resampler(kMaxNumSamplesPerFrame, | ||
kNumChannels); | ||
EXPECT_THAT( | ||
every_second_tick_resampler.PushFrame({{1, 2}, {3, 4}, {5, 6}, {7, 8}}), | ||
IsOk()); | ||
EXPECT_EQ(every_second_tick_resampler.GetOutputSamplesAsSpan().size(), 2); | ||
|
||
EXPECT_THAT(every_second_tick_resampler.PushFrame({{9, 10}, {11, 12}}), | ||
IsOk()); | ||
EXPECT_EQ(every_second_tick_resampler.GetOutputSamplesAsSpan().size(), 1); | ||
|
||
EXPECT_THAT(every_second_tick_resampler.Flush(), IsOk()); | ||
EXPECT_TRUE(every_second_tick_resampler.GetOutputSamplesAsSpan().empty()); | ||
} | ||
|
||
} // namespace | ||
} // namespace iamf_tools |