void JitterHistory::frame_arrived(steady_clock::time_point now, int64_t frame_duration, size_t dropped_frames)
{
+ if (frame_duration != last_duration) {
+ // If the frame rate changed, the input clock is also going to change,
+ // so our historical data doesn't make much sense anymore.
+ // Also, format changes typically introduce blips that are not representative
+ // of the typical frame stream. (We make the assumption that format changes
+ // don't happen all the time in regular use; if they did, we should probably
+ // rather keep the history so that we take jitter they may introduce into account.)
+ clear();
+ last_duration = frame_duration;
+ }
if (expected_timestamp > steady_clock::time_point::min()) {
expected_timestamp += dropped_frames * nanoseconds(frame_duration * 1000000000 / TIMEBASE);
double jitter_seconds = fabs(duration<double>(expected_timestamp - now).count());
}
void QueueLengthPolicy::update_policy(steady_clock::time_point now,
- steady_clock::time_point expected_next_frame,
+ steady_clock::time_point expected_next_input_frame,
int64_t input_frame_duration,
int64_t master_frame_duration,
double max_input_card_jitter_seconds,
// Figure out when we can expect the next frame for this card, assuming
// worst-case jitter (ie., the frame is maximally late).
- double seconds_until_next_frame = max(duration<double>(expected_next_frame - now).count() + max_input_card_jitter_seconds, 0.0);
+ double seconds_until_next_frame = max(duration<double>(expected_next_input_frame - now).count() + max_input_card_jitter_seconds, 0.0);
// How many times are the master card expected to tick in that time?
// We assume the master clock has worst-case jitter but not any rate
DeckLinkCapture *capture = new DeckLinkCapture(decklink, card_index);
DeckLinkOutput *output = new DeckLinkOutput(resource_pool.get(), decklink_output_surface, global_flags.width, global_flags.height, card_index);
- if (!output->set_device(decklink)) {
+ if (!output->set_device(decklink, capture->get_input())) {
delete output;
output = nullptr;
}
if (global_flags.enable_alsa_output) {
alsa.reset(new ALSAOutput(OUTPUT_FREQUENCY, /*num_channels=*/2));
}
+ output_card_is_master = global_flags.output_card_is_master;
if (global_flags.output_card != -1) {
desired_output_card_index = global_flags.output_card;
set_output_card_internal(global_flags.output_card);
card->jitter_history.clear();
card->capture->start_bm_capture();
desired_output_video_mode = output_video_mode = card->output->pick_video_mode(desired_output_video_mode);
- card->output->start_output(desired_output_video_mode, pts_int);
+ card->output->start_output(desired_output_video_mode, pts_int, /*is_master_card=*/output_card_is_master);
}
output_card_index = card_index;
output_jitter_history.clear();
DeckLinkOutput *output = cards[output_card_index].output.get();
output->end_output();
desired_output_video_mode = output_video_mode = output->pick_video_mode(desired_output_video_mode);
- output->start_output(desired_output_video_mode, pts_int);
+ output->start_output(desired_output_video_mode, pts_int, /*is_master_card=*/output_card_is_master);
}
{
bool master_card_is_output;
unsigned master_card_index;
- if (output_card_index != -1) {
+ if (output_card_index != -1 && output_card_is_master) {
master_card_is_output = true;
master_card_index = output_card_index;
} else {
bool Mixer::input_card_is_master_clock(unsigned card_index, unsigned master_card_index) const
{
- if (output_card_index != -1) {
+ if (output_card_index != -1 && output_card_is_master) {
// The output card (ie., cards[output_card_index].output) is the master clock,
// so no input card (ie., cards[card_index].capture) is.
return false;
void Mixer::start_mode_scanning(unsigned card_index)
{
assert(card_index < MAX_VIDEO_CARDS);
- if (cards[card_index].capture != nullptr) {
+ if (cards[card_index].capture == nullptr) {
// Inactive card. Should never happen.
return;
}