Adding DTX logic to FakeDecodeFromFile (used be NetEqTest).
Bug: b/129521878 Change-Id: Ifcf868048a39ef1d2cc736988479f921e668167b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132799 Commit-Queue: Minyue Li <minyue@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Reviewed-by: Ivo Creusen <ivoc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27626}
This commit is contained in:
@ -17,6 +17,53 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeEncodedFrame : public AudioDecoder::EncodedAudioFrame {
|
||||
public:
|
||||
FakeEncodedFrame(AudioDecoder* decoder, rtc::Buffer&& payload)
|
||||
: decoder_(decoder), payload_(std::move(payload)) {}
|
||||
|
||||
size_t Duration() const override {
|
||||
const int ret = decoder_->PacketDuration(payload_.data(), payload_.size());
|
||||
return ret < 0 ? 0 : static_cast<size_t>(ret);
|
||||
}
|
||||
|
||||
absl::optional<DecodeResult> Decode(
|
||||
rtc::ArrayView<int16_t> decoded) const override {
|
||||
auto speech_type = AudioDecoder::kSpeech;
|
||||
const int ret = decoder_->Decode(
|
||||
payload_.data(), payload_.size(), decoder_->SampleRateHz(),
|
||||
decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
|
||||
return ret < 0 ? absl::nullopt
|
||||
: absl::optional<DecodeResult>(
|
||||
{static_cast<size_t>(ret), speech_type});
|
||||
}
|
||||
|
||||
// This is to mimic OpusFrame.
|
||||
bool IsDtxPacket() const override {
|
||||
uint32_t original_payload_size_bytes =
|
||||
ByteReader<uint32_t>::ReadLittleEndian(&payload_.data()[8]);
|
||||
return original_payload_size_bytes <= 2;
|
||||
}
|
||||
|
||||
private:
|
||||
AudioDecoder* const decoder_;
|
||||
const rtc::Buffer payload_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<AudioDecoder::ParseResult> FakeDecodeFromFile::ParsePayload(
|
||||
rtc::Buffer&& payload,
|
||||
uint32_t timestamp) {
|
||||
std::vector<ParseResult> results;
|
||||
std::unique_ptr<EncodedAudioFrame> frame(
|
||||
new FakeEncodedFrame(this, std::move(payload)));
|
||||
results.emplace_back(timestamp, 0, std::move(frame));
|
||||
return results;
|
||||
}
|
||||
|
||||
int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// Provides an AudioDecoder implementation that delivers audio data from a file.
|
||||
// The "encoded" input should contain information about what RTP timestamp the
|
||||
// encoding represents, and how many samples the decoder should produce for that
|
||||
@ -38,6 +37,9 @@ class FakeDecodeFromFile : public AudioDecoder {
|
||||
|
||||
~FakeDecodeFromFile() = default;
|
||||
|
||||
std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
|
||||
uint32_t timestamp) override;
|
||||
|
||||
void Reset() override {}
|
||||
|
||||
int SampleRateHz() const override { return sample_rate_hz_; }
|
||||
|
||||
Reference in New Issue
Block a user