webrtc_m130/webrtc/modules/audio_coding/neteq/statistics_calculator.h

114 lines
3.9 KiB
C
Raw Normal View History

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_
#include <vector>
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
#include "webrtc/typedefs.h"
namespace webrtc {
// Forward declarations.
class DecisionLogic;
class DelayManager;
// This class handles various network statistics in NetEq.
class StatisticsCalculator {
public:
StatisticsCalculator();
virtual ~StatisticsCalculator() {}
// Resets most of the counters.
void Reset();
// Resets the counters that are not handled by Reset().
void ResetMcu();
// Resets the waiting time statistics.
void ResetWaitingTimeStatistics();
// Reports that |num_samples| samples were produced through expansion, and
// that the expansion produced other than just noise samples.
void ExpandedVoiceSamples(int num_samples);
// Reports that |num_samples| samples were produced through expansion, and
// that the expansion produced only noise samples.
void ExpandedNoiseSamples(int num_samples);
// Reports that |num_samples| samples were produced through preemptive
// expansion.
void PreemptiveExpandedSamples(int num_samples);
// Reports that |num_samples| samples were removed through accelerate.
void AcceleratedSamples(int num_samples);
// Reports that |num_samples| zeros were inserted into the output.
void AddZeros(int num_samples);
// Reports that |num_packets| packets were discarded.
void PacketsDiscarded(int num_packets);
// Reports that |num_samples| were lost.
void LostSamples(int num_samples);
// Increases the report interval counter with |num_samples| at a sample rate
// of |fs_hz|.
void IncreaseCounter(int num_samples, int fs_hz);
// Stores new packet waiting time in waiting time statistics.
void StoreWaitingTime(int waiting_time_ms);
// Reports that |num_samples| samples were decoded from secondary packets.
void SecondaryDecodedSamples(int num_samples);
// Returns the current network statistics in |stats|. The current sample rate
// is |fs_hz|, the total number of samples in packet buffer and sync buffer
// yet to play out is |num_samples_in_buffers|, and the number of samples per
// packet is |samples_per_packet|.
void GetNetworkStatistics(int fs_hz,
int num_samples_in_buffers,
int samples_per_packet,
const DelayManager& delay_manager,
const DecisionLogic& decision_logic,
NetEqNetworkStatistics *stats);
void WaitingTimes(std::vector<int>* waiting_times);
private:
static const int kMaxReportPeriod = 60; // Seconds before auto-reset.
static const int kLenWaitingTimes = 100;
// Calculates numerator / denominator, and returns the value in Q14.
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
static uint16_t CalculateQ14Ratio(uint32_t numerator, uint32_t denominator);
uint32_t preemptive_samples_;
uint32_t accelerate_samples_;
int added_zero_samples_;
uint32_t expanded_speech_samples_;
uint32_t expanded_noise_samples_;
int discarded_packets_;
uint32_t lost_timestamps_;
uint32_t timestamps_since_last_report_;
int waiting_times_[kLenWaitingTimes]; // Used as a circular buffer.
int len_waiting_times_;
int next_waiting_time_index_;
uint32_t secondary_decoded_samples_;
DISALLOW_COPY_AND_ASSIGN(StatisticsCalculator);
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_