From dc6d5533e199940d124cad1fb9f7cc6f41357408 Mon Sep 17 00:00:00 2001 From: Ivo Creusen Date: Thu, 27 Sep 2018 11:43:42 +0200 Subject: [PATCH] Add more NetEq information to NetEqState. Some important NetEq information was not available in NetEqState, which meant it was not available on the API. This CL adds additional information. Bug: webrtc:9667 Change-Id: I702707c7d60472f488047d48fb286f839c5608dc Reviewed-on: https://webrtc-review.googlesource.com/c/102300 Reviewed-by: Minyue Li Reviewed-by: Karl Wiberg Commit-Queue: Ivo Creusen Cr-Commit-Position: refs/heads/master@{#24985} --- api/test/neteq_simulator.h | 7 +++++++ modules/audio_coding/neteq/include/neteq.h | 6 ++++++ modules/audio_coding/neteq/neteq_impl.cc | 4 ++++ modules/audio_coding/neteq/packet_buffer.cc | 1 + modules/audio_coding/neteq/statistics_calculator.cc | 4 ++++ modules/audio_coding/neteq/statistics_calculator.h | 3 +++ modules/audio_coding/neteq/tools/neteq_test.cc | 6 ++++++ 7 files changed, 31 insertions(+) diff --git a/api/test/neteq_simulator.h b/api/test/neteq_simulator.h index ab6db9c84c..8ef67313e8 100644 --- a/api/test/neteq_simulator.h +++ b/api/test/neteq_simulator.h @@ -47,9 +47,16 @@ class NetEqSimulator { int current_delay_ms = 0; // An indicator that packet loss occurred since the last GetAudio event. bool packet_loss_occurred = false; + // An indicator that the packet buffer has been flushed since the last + // GetAudio event. + bool packet_buffer_flushed = false; + // Indicates if the next needed packet is available in the buffer. + bool next_packet_available = false; // The inter-arrival times in ms of the packets that have arrived since the // last GetAudio event. std::vector packet_iat_ms; + // The current packet size in ms. + int packet_size_ms = 0; }; // Runs the simulation until we hit the next GetAudio event. If the simulation diff --git a/modules/audio_coding/neteq/include/neteq.h b/modules/audio_coding/neteq/include/neteq.h index 918b006ddf..530975f3b8 100644 --- a/modules/audio_coding/neteq/include/neteq.h +++ b/modules/audio_coding/neteq/include/neteq.h @@ -82,11 +82,17 @@ struct NetEqOperationsAndState { // NetEqLifetimeStatistics::total_samples_received. uint64_t preemptive_samples = 0; uint64_t accelerate_samples = 0; + // Count of the number of buffer flushes. + uint64_t packet_buffer_flushes = 0; // The statistics below are not cumulative. // The waiting time of the last decoded packet. uint64_t last_waiting_time_ms = 0; // The sum of the packet and jitter buffer size in ms. uint64_t current_buffer_size_ms = 0; + // The current frame size in ms. + uint64_t current_frame_size_ms = 0; + // Flag to indicate that the next packet is available. + bool next_packet_available = false; }; // This is the interface class for NetEq. diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc index 857a4d7724..f428be1c3b 100644 --- a/modules/audio_coding/neteq/neteq_impl.cc +++ b/modules/audio_coding/neteq/neteq_impl.cc @@ -378,6 +378,10 @@ NetEqOperationsAndState NetEqImpl::GetOperationsAndState() const { (packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + sync_buffer_->FutureLength()) * 1000 / fs_hz_; + result.current_frame_size_ms = decoder_frame_length_ * 1000 / fs_hz_; + result.next_packet_available = packet_buffer_->PeekNextPacket() && + packet_buffer_->PeekNextPacket()->timestamp == + sync_buffer_->end_timestamp(); return result; } diff --git a/modules/audio_coding/neteq/packet_buffer.cc b/modules/audio_coding/neteq/packet_buffer.cc index c04534eaa6..eba4d3e68b 100644 --- a/modules/audio_coding/neteq/packet_buffer.cc +++ b/modules/audio_coding/neteq/packet_buffer.cc @@ -91,6 +91,7 @@ int PacketBuffer::InsertPacket(Packet&& packet, StatisticsCalculator* stats) { if (buffer_.size() >= max_number_of_packets_) { // Buffer is full. Flush it. Flush(); + stats->FlushedPacketBuffer(); RTC_LOG(LS_WARNING) << "Packet buffer flushed"; return_val = kFlushed; } diff --git a/modules/audio_coding/neteq/statistics_calculator.cc b/modules/audio_coding/neteq/statistics_calculator.cc index 7ce156ef9a..c0e7a402aa 100644 --- a/modules/audio_coding/neteq/statistics_calculator.cc +++ b/modules/audio_coding/neteq/statistics_calculator.cc @@ -248,6 +248,10 @@ void StatisticsCalculator::SecondaryDecodedSamples(int num_samples) { secondary_decoded_samples_ += num_samples; } +void StatisticsCalculator::FlushedPacketBuffer() { + operations_and_state_.packet_buffer_flushes++; +} + void StatisticsCalculator::LogDelayedPacketOutageEvent(int outage_duration_ms) { RTC_HISTOGRAM_COUNTS("WebRTC.Audio.DelayedPacketOutageEventMs", outage_duration_ms, 1 /* min */, 2000 /* max */, diff --git a/modules/audio_coding/neteq/statistics_calculator.h b/modules/audio_coding/neteq/statistics_calculator.h index 37540fdbc5..9e5dacfd92 100644 --- a/modules/audio_coding/neteq/statistics_calculator.h +++ b/modules/audio_coding/neteq/statistics_calculator.h @@ -83,6 +83,9 @@ class StatisticsCalculator { // Reports that |num_samples| samples were decoded from secondary packets. void SecondaryDecodedSamples(int num_samples); + // Rerport that the packet buffer was flushed. + void FlushedPacketBuffer(); + // Logs a delayed packet outage event of |outage_duration_ms|. A delayed // packet outage event is defined as an expand period caused not by an actual // packet loss, but by a delayed packet. diff --git a/modules/audio_coding/neteq/tools/neteq_test.cc b/modules/audio_coding/neteq/tools/neteq_test.cc index fdd1b24bd6..421f380a7a 100644 --- a/modules/audio_coding/neteq/tools/neteq_test.cc +++ b/modules/audio_coding/neteq/tools/neteq_test.cc @@ -155,6 +155,12 @@ NetEqTest::SimulationStepResult NetEqTest::RunToNextGetAudio() { input_->NextEventTime().value_or(time_now_ms) - start_time_ms; const auto operations_state = neteq_->GetOperationsAndState(); current_state_.current_delay_ms = operations_state.current_buffer_size_ms; + current_state_.packet_size_ms = operations_state.current_frame_size_ms; + current_state_.next_packet_available = + operations_state.next_packet_available; + current_state_.packet_buffer_flushed = + operations_state.packet_buffer_flushes > + prev_ops_state_.packet_buffer_flushes; // TODO(ivoc): Add more accurate reporting by tracking the origin of // samples in the sync buffer. result.action_times_ms[Action::kExpand] = 0;