39#ifndef SRC_VIDEO_DISPLAY_DECKLINK_DRIFT_FIX_HPP_69DBC8A9_974D_46C5_833D_5A77CF35E034
40#define SRC_VIDEO_DISPLAY_DECKLINK_DRIFT_FIX_HPP_69DBC8A9_974D_46C5_833D_5A77CF35E034
54#define MAX_RESAMPLE_DELTA_DEFAULT 30
55#define MIN_RESAMPLE_DELTA_DEFAULT 1
56#define TARGET_BUFFER_DEFAULT 2700
115 if (this->
size() >= (ptrdiff_t) this->
period ){
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) {
149 <<
" - Total Audio Frames Played: "
151 <<
" / Missing Audio Frames: "
153 <<
" / Buffer Underflows: "
155 <<
" / Buffer Overflows: "
157 <<
" / Resample (Higher Hz): "
159 <<
" / Resample (Lower Hz): "
161 <<
" / Average Buffer: "
163 <<
" / Average Added Frames: "
165 <<
" / Max time diff audio (ms): "
167 <<
" / Min time diff audio (ms): "
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);
259 long long duration_diff = time_diff.count();
264 this->audio_time_diff_min = duration_diff;
298 std::chrono::steady_clock::time_point
last_summary = std::chrono::steady_clock::now();
382 else if ((uint32_t)delta < this->
min_buffer) {
389 void update(uint32_t buffered_count, uint32_t sample_frame_count, uint32_t sampleFramesWritten) {
396 if (buffered_count == 0) {
404 this->previous_buffer = buffered_count;
406 long long dst_frame_rate = 0;
410 int resample_hz = dst_frame_rate = (bmdAudioSampleRate48kHz) *
BASE;
429 dst_frame_rate = (bmdAudioSampleRate48kHz - resample_hz) *
BASE;
431 }
else if(average_buffer_depth < target_buffer_fill - this->
neg_jitter) {
434 dst_frame_rate = (bmdAudioSampleRate48kHz + resample_hz) *
BASE;
437 dst_frame_rate = (bmdAudioSampleRate48kHz) *
BASE;
443 if (dst_frame_rate != 0 &&
447 <<
MOD_NAME "Sending resample request "
448 << dst_frame_rate <<
"/" <<
BASE <<
"\n";
449 assert(
m_root !=
nullptr);
460 if (sampleFramesWritten != sample_frame_count) {
472 static constexpr unsigned long BASE = (1U<<8U);
#define ADEC_CH_RATE_SHIFT
#define MSG_UNIVERSAL_TAG_AUDIO_DECODER
double get_buffer_avg()
Get the average sample count per channel.
void set_target_buffer(uint32_t target_buffer)
Set the target buffer object.
static const uint32_t NEG_JITTER_DEFAULT
static const uint32_t POS_JITTER_DEFAULT
long long dst_frame_rate_set
void set_max_hz(uint32_t max_hz)
Set the max hz object.
uint32_t target_buffer_fill
static constexpr unsigned long BASE
MovingAverage average_buffer_samples
DecklinkAudioSummary audio_summary
void update(uint32_t buffered_count, uint32_t sample_frame_count, uint32_t sampleFramesWritten)
double scale_buffer_delta(int delta)
This function will check the buffer delta and will return a delta in the sample rate that is required...
void set_min_hz(uint32_t min_hz)
Set the min hz object.
void set_root(module *root)
Set the root object.
MovingAverage average_delta
void report()
This will detail out the longer running stats of the Decklink. It should be called on every audio fra...
void mark_audio_time_end()
Mark the end of the put audio function.
void increment_buffer_underflow()
This should be called when an underflow has occured.
long long audio_time_diff_min
void set_buffer_average(double buffer_average)
Set the buffer average object.
void increment_buffer_overflow()
This should be called when an overflow has occured.
void record_audio_time_diff()
This function should be called at the beginning of put audio to record the difference between calls.
void increment_resample_low()
This should be called when a resample is requested that is lower than the original sample rate.
std::chrono::steady_clock::time_point last_summary
MovingAverage avg_added_frames
long long audio_time_diff_max
void increment_resample_high()
This should be called when a resample is requested that is higher than the original sample rate.
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 k...
int32_t prev_buffer_samples
std::chrono::high_resolution_clock::time_point prev_audio_end
uint32_t buffer_underflow
void increment_audio_frames_played()
This should be called when an call to audio put has been called.
MovingAverage(unsigned int period)
static __device__ vec2 abs(const vec2 &v)
static __device__ vec3 round(const vec3 &v)
#define LOG_LEVEL_INFO
normal reporting
#define LOG_LEVEL_WARNING
less severe errors
#define MAX_RESAMPLE_DELTA_DEFAULT
#define TARGET_BUFFER_DEFAULT
#define MIN_RESAMPLE_DELTA_DEFAULT
std::unordered_map< std::string, std::string > commandline_params
struct response * send_message_sync(struct module *root, const char *const_path, struct message *msg, int timeout_ms, int flags)
Sends message without waiting for response.
int response_get_status(struct response *r)
void free_response(struct response *r)
const char * response_get_text(struct response *r)
#define RESPONSE_SUCCESSFUL(code)
#define SEND_MESSAGE_FLAG_NO_STORE
if receiver doesn't exist, doesn't store it and retur 404 instead