UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
DecklinkAudioSummary Class Reference

#include <decklink_drift_fix.hpp>

Collaboration diagram for DecklinkAudioSummary:
Collaboration graph

Public Member Functions

void calculate_missing (uint32_t buffer_samples, uint32_t samples)
 A quick way of roughly calculating if the buffer has emptied by the size of a single audio frame to keep track of missing audio frames. This doesn't mean that the audio frame was not played, just that the length of time between audio put calls caused the buffer to empty by half of the average size of a frame.
 
void increment_audio_frames_played ()
 This should be called when an call to audio put has been called.
 
void increment_buffer_overflow ()
 This should be called when an overflow has occured.
 
void increment_buffer_underflow ()
 This should be called when an underflow has occured.
 
void increment_resample_high ()
 This should be called when a resample is requested that is higher than the original sample rate.
 
void increment_resample_low ()
 This should be called when a resample is requested that is lower than the original sample rate.
 
void mark_audio_time_end ()
 Mark the end of the put audio function.
 
void record_audio_time_diff ()
 This function should be called at the beginning of put audio to record the difference between calls.
 
void report ()
 This will detail out the longer running stats of the Decklink. It should be called on every audio frame but will only print out the report once every 30 seconds.
 
void set_buffer_average (double buffer_average)
 Set the buffer average object.
 

Private Attributes

long long audio_time_diff_max = 0
 
long long audio_time_diff_min = std::numeric_limits<long long>().max()
 
MovingAverage avg_added_frames {250}
 
uint32_t buffer_average = 0
 
uint32_t buffer_overflow = 0
 
uint32_t buffer_underflow = 0
 
uint32_t frames_missed = 0
 
uint32_t frames_played = 0
 
std::chrono::steady_clock::time_point last_summary = std::chrono::steady_clock::now()
 
std::chrono::high_resolution_clock::time_point prev_audio_end {}
 
int32_t prev_buffer_samples = -1
 
uint32_t resample_high = 0
 
uint32_t resample_low = 0
 

Detailed Description

Definition at line 139 of file decklink_drift_fix.hpp.

Member Function Documentation

◆ calculate_missing()

void DecklinkAudioSummary::calculate_missing ( uint32_t buffer_samples,
uint32_t samples )
inline

A quick way of roughly calculating if the buffer has emptied by the size of a single audio frame to keep track of missing audio frames. This doesn't mean that the audio frame was not played, just that the length of time between audio put calls caused the buffer to empty by half of the average size of a frame.

Parameters
buffer_samplesThe amount of audio samples in the buffer.
samplesThe amount of samples that will be written to the buffer.

Definition at line 233 of file decklink_drift_fix.hpp.

233 {
234 this->avg_added_frames.add(samples);
235 if(this->avg_added_frames.filled()) {
236 samples = (uint32_t)this->avg_added_frames.avg();
237 }
238 // Check to see if the amount in the buffer has dropped by over half the average
239 // number of samples being written. If so, we likely dropped a frame.
240 if(prev_buffer_samples >= 0 && (uint32_t)this->prev_buffer_samples > buffer_samples + (samples / 2)) {
241 this->frames_missed++;
242 }
243 this->prev_buffer_samples = buffer_samples;
244 }
void add(double val)
double avg() const

References MovingAverage::add(), MovingAverage::avg(), avg_added_frames, MovingAverage::filled(), frames_missed, and prev_buffer_samples.

Referenced by AudioDriftFixer::update().

Here is the call graph for this function:

◆ increment_audio_frames_played()

void DecklinkAudioSummary::increment_audio_frames_played ( )
inline

This should be called when an call to audio put has been called.

Definition at line 211 of file decklink_drift_fix.hpp.

211 {
212 this->frames_played++;
213 }

References frames_played.

Referenced by AudioDriftFixer::update().

◆ increment_buffer_overflow()

void DecklinkAudioSummary::increment_buffer_overflow ( )
inline

This should be called when an overflow has occured.

Definition at line 197 of file decklink_drift_fix.hpp.

197 {
198 this->buffer_overflow++;
199 }

References buffer_overflow.

Referenced by AudioDriftFixer::update().

◆ increment_buffer_underflow()

void DecklinkAudioSummary::increment_buffer_underflow ( )
inline

This should be called when an underflow has occured.

Definition at line 204 of file decklink_drift_fix.hpp.

204 {
205 this->buffer_underflow++;
206 }

References buffer_underflow.

Referenced by AudioDriftFixer::update().

◆ increment_resample_high()

void DecklinkAudioSummary::increment_resample_high ( )
inline

This should be called when a resample is requested that is higher than the original sample rate.

Definition at line 190 of file decklink_drift_fix.hpp.

190 {
191 this->resample_high++;
192 }

References resample_high.

Referenced by AudioDriftFixer::update().

◆ increment_resample_low()

void DecklinkAudioSummary::increment_resample_low ( )
inline

This should be called when a resample is requested that is lower than the original sample rate.

Definition at line 182 of file decklink_drift_fix.hpp.

182 {
183 this->resample_low++;
184 }

References resample_low.

Referenced by AudioDriftFixer::update().

◆ mark_audio_time_end()

void DecklinkAudioSummary::mark_audio_time_end ( )
inline

Mark the end of the put audio function.

Definition at line 273 of file decklink_drift_fix.hpp.

273 {
274 this->prev_audio_end = std::chrono::high_resolution_clock::now();
275 }

References prev_audio_end.

Referenced by AudioDriftFixer::update().

◆ record_audio_time_diff()

void DecklinkAudioSummary::record_audio_time_diff ( )
inline

This function should be called at the beginning of put audio to record the difference between calls.

Definition at line 251 of file decklink_drift_fix.hpp.

251 {
252 // CHeck the previous time has been initialised
253 if(this->prev_audio_end.time_since_epoch().count() != 0) {
254 // Collect the time now and do a comparison to the time when we ended the previous function call
255 std::chrono::high_resolution_clock::time_point audio_begin = std::chrono::high_resolution_clock::now();
256 std::chrono::milliseconds time_diff = std::chrono::duration_cast<std::chrono::milliseconds>(audio_begin - this->prev_audio_end);
257
258 // Set a max or min if the timing is outside of whats already been collected
259 long long duration_diff = time_diff.count();
260 if(duration_diff > this->audio_time_diff_max) {
261 this->audio_time_diff_max = duration_diff;
262 }
263 else if(duration_diff < this->audio_time_diff_min) {
264 this->audio_time_diff_min = duration_diff;
265 }
266 }
267 }

References audio_time_diff_max, audio_time_diff_min, and prev_audio_end.

Referenced by AudioDriftFixer::update().

◆ report()

void DecklinkAudioSummary::report ( )
inline

This will detail out the longer running stats of the Decklink. It should be called on every audio frame but will only print out the report once every 30 seconds.

Definition at line 145 of file decklink_drift_fix.hpp.

145 {
146 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
147 if(std::chrono::duration_cast<std::chrono::seconds>(now - this->last_summary).count() > 10) {
148 LOG(LOG_LEVEL_INFO) << SUNDERLINE("Decklink stats (cumulative)")
149 << " - Total Audio Frames Played: "
150 << SBOLD(this->frames_played)
151 << " / Missing Audio Frames: "
152 << SBOLD(this->frames_missed)
153 << " / Buffer Underflows: "
154 << SBOLD(this->buffer_underflow)
155 << " / Buffer Overflows: "
156 << SBOLD(this->buffer_overflow)
157 << " / Resample (Higher Hz): "
158 << SBOLD(this->resample_high)
159 << " / Resample (Lower Hz): "
160 << SBOLD(this->resample_low)
161 << " / Average Buffer: "
162 << SBOLD(this->buffer_average)
163 << " / Average Added Frames: "
164 << SBOLD(this->avg_added_frames.avg())
165 << " / Max time diff audio (ms): "
166 << SBOLD(this->audio_time_diff_max)
167 << " / Min time diff audio (ms): "
168 << SBOLD(this->audio_time_diff_min)
169 << "\n";
170 // Reset some of the variables
171 this->audio_time_diff_max = 0;
172 this->audio_time_diff_min = std::numeric_limits<long long>().max();
173 // Ensure that the summary gets called 30 seconds from now
174 this->last_summary = now;
175 }
176 }
#define SBOLD(x)
Definition color_out.h:80
#define SUNDERLINE(x)
Definition color_out.h:81
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
#define LOG(level)
Definition debug.h:313
int count
Definition hd-rum.c:44

References audio_time_diff_max, audio_time_diff_min, MovingAverage::avg(), avg_added_frames, buffer_average, buffer_overflow, buffer_underflow, count, frames_missed, frames_played, last_summary, LOG, LOG_LEVEL_INFO, resample_high, resample_low, SBOLD, and SUNDERLINE.

Referenced by AudioDriftFixer::update().

Here is the call graph for this function:

◆ set_buffer_average()

void DecklinkAudioSummary::set_buffer_average ( double buffer_average)
inline

Set the buffer average object.

Parameters
buffer_averageThe average samples in the buffer per channel

Definition at line 220 of file decklink_drift_fix.hpp.

220 {
221 this->buffer_average = (int32_t)round(buffer_average);
222 }
static __device__ vec3 round(const vec3 &v)
Definition cuda_dxt.cu:122

References buffer_average, and round().

Referenced by AudioDriftFixer::update().

Here is the call graph for this function:

Member Data Documentation

◆ audio_time_diff_max

long long DecklinkAudioSummary::audio_time_diff_max = 0
private

Definition at line 294 of file decklink_drift_fix.hpp.

Referenced by record_audio_time_diff(), and report().

◆ audio_time_diff_min

long long DecklinkAudioSummary::audio_time_diff_min = std::numeric_limits<long long>().max()
private

Definition at line 295 of file decklink_drift_fix.hpp.

Referenced by record_audio_time_diff(), and report().

◆ avg_added_frames

MovingAverage DecklinkAudioSummary::avg_added_frames {250}
private

Definition at line 283 of file decklink_drift_fix.hpp.

283{250};

Referenced by calculate_missing(), and report().

◆ buffer_average

uint32_t DecklinkAudioSummary::buffer_average = 0
private

Definition at line 291 of file decklink_drift_fix.hpp.

Referenced by report(), and set_buffer_average().

◆ buffer_overflow

uint32_t DecklinkAudioSummary::buffer_overflow = 0
private

Definition at line 286 of file decklink_drift_fix.hpp.

Referenced by increment_buffer_overflow(), and report().

◆ buffer_underflow

uint32_t DecklinkAudioSummary::buffer_underflow = 0
private

Definition at line 285 of file decklink_drift_fix.hpp.

Referenced by increment_buffer_underflow(), and report().

◆ frames_missed

uint32_t DecklinkAudioSummary::frames_missed = 0
private

Definition at line 282 of file decklink_drift_fix.hpp.

Referenced by calculate_missing(), and report().

◆ frames_played

uint32_t DecklinkAudioSummary::frames_played = 0
private

Definition at line 280 of file decklink_drift_fix.hpp.

Referenced by increment_audio_frames_played(), and report().

◆ last_summary

std::chrono::steady_clock::time_point DecklinkAudioSummary::last_summary = std::chrono::steady_clock::now()
private

Definition at line 298 of file decklink_drift_fix.hpp.

Referenced by report().

◆ prev_audio_end

std::chrono::high_resolution_clock::time_point DecklinkAudioSummary::prev_audio_end {}
private

Definition at line 293 of file decklink_drift_fix.hpp.

293{};

Referenced by mark_audio_time_end(), and record_audio_time_diff().

◆ prev_buffer_samples

int32_t DecklinkAudioSummary::prev_buffer_samples = -1
private

Definition at line 278 of file decklink_drift_fix.hpp.

Referenced by calculate_missing().

◆ resample_high

uint32_t DecklinkAudioSummary::resample_high = 0
private

Definition at line 288 of file decklink_drift_fix.hpp.

Referenced by increment_resample_high(), and report().

◆ resample_low

uint32_t DecklinkAudioSummary::resample_low = 0
private

Definition at line 289 of file decklink_drift_fix.hpp.

Referenced by increment_resample_low(), and report().


The documentation for this class was generated from the following file: