Skip to content

Commit f2ba6c3

Browse files
committed
DeckLink disp sync: handle excessive aud. underflw
using audio codec with relatively long delay may cause underflows, eg.: ``` uv -t testcard:mode=Hi59 -s embedded -d decklink:sync=4 -r embedded \ -c libavcodec:encoder=libx264 -A mp3:bitrate=64k ``` refers to GH-362
1 parent cdf4140 commit f2ba6c3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/video_display/decklink.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class PlaybackDelegate : public IDeckLinkVideoOutputCallback // , public IDeckLi
177177

178178
bool EnqueueFrame(DeckLinkFrame *deckLinkFrame);
179179
void ScheduleNextFrame();
180-
void ScheduleAudio(const struct audio_frame *frame, uint32_t *samples);
180+
void ScheduleAudio(const struct audio_frame *frame, uint32_t *samples,
181+
bool underflow);
181182

182183
HRESULT STDMETHODCALLTYPE
183184
ScheduledFrameCompleted(IDeckLinkVideoFrame *completedFrame,
@@ -1612,7 +1613,7 @@ static bool display_decklink_get_property(void *state, int property, void *val,
16121613
* AUDIO
16131614
*/
16141615
void PlaybackDelegate::ScheduleAudio(const struct audio_frame *frame,
1615-
uint32_t *const samples) {
1616+
uint32_t *const samples, bool underflow) {
16161617
if (m_adata.saved_sync_ts == INT64_MIN &&
16171618
m_audio_sync_ts == audio_sync_val::deinit) {
16181619
return;
@@ -1642,6 +1643,15 @@ void PlaybackDelegate::ScheduleAudio(const struct audio_frame *frame,
16421643
LOG(LOG_LEVEL_ERROR) << MOD_NAME << "ScheduleAudioSamples: "
16431644
<< bmd_hresult_to_string(res) << "\n";
16441645
}
1646+
1647+
if (underflow) {
1648+
static unsigned count;
1649+
if (count++ == 50) {
1650+
MSG(WARNING, "Excessive underflow in sync mode! Try to "
1651+
"increase sync frames (:sync=%d or so).\n",
1652+
m_min_sched_frames + 2);
1653+
}
1654+
}
16451655
}
16461656

16471657
static void display_decklink_put_audio_frame(void *state, const struct audio_frame *frame)
@@ -1669,7 +1679,8 @@ static void display_decklink_put_audio_frame(void *state, const struct audio_fra
16691679
return;
16701680
}
16711681
} else {
1672-
s->delegate.ScheduleAudio(frame, &sampleFramesWritten);
1682+
s->delegate.ScheduleAudio(frame, &sampleFramesWritten,
1683+
buffered == 0);
16731684
}
16741685
const bool overflow = sampleFramesWritten != sampleFrameCount;
16751686
if (overflow || log_level >= LOG_LEVEL_DEBUG) {

0 commit comments

Comments
 (0)