CESNET / UltraGrid

UltraGrid low-latency audio and video network transmission system
http://www.ultragrid.cz
Other
485 stars 55 forks source link

[DeckLink] timestamp restart on format change #347

Open MartinPulec opened 8 months ago

MartinPulec commented 8 months ago

When format change occurs, timestamps are reset causing libopus warning:

[lavc libopus @ 0x7f29080066c0] Queue input is backward in time

Steps to reproduce:

$ uv -t decklink -s embedded -A Opus -VVV | grep 'Sending PTS\|libopus\|DeckLink'                                                                                                                                               
[1698061079.328] [lavcd aud.] Using audio encoder: libopus
[1698061079.333] [DeckLink capture] Using codec: UYVY
[1698061079.376] [DeckLink capture] Using device UltraStudio 4K
[1698061079.376] [DeckLink capture] bmdDeckLinkConfigCapturePassThroughMode set to: bmdDeckLinkCapturePassthroughModeDisabled
[1698061079.376] [DeckLink capture] bmdDeckLinkConfigVideoInputConnection set to: SDI
[1698061079.376] [DeckLink capture] 625i50 PAL   720 x 576       25 FPS          40000 AVAREGE TIME BETWEEN FRAMES
[1698061079.376] [DeckLink capture] Enable video input: 625i50 PAL
[1698061079.376] [DeckLink] Trying to autodetect format.
[1698061079.377] [DeckLink capture] Audio input set to: embedded
[1698061079.473] [DeckLink capture] Format change detected (display mode, color space - YCbCr422, 10bit).
[1698061079.473] [DeckLink capture] Detected 10-bit signal, use ":codec=UYVY" to enforce 8-bit capture (old behavior).
[1698061079.473] [DeckLink capture] Using codec: v210
[1698061079.473] [DeckLink capture] IDeckLinkDisplayMode::GetName failed: Failed to allocate necessary memory (0x80000002)
[1698061079.473] [DeckLink capture] (NULL!)      1280 x 720      59.9401 FPS     16683 AVAREGE TIME BETWEEN FRAMES
[1698061079.473] [DeckLink capture] Enable video input: (NULL!)
[1698061079.477] [lavc libopus @ 0x7f29080066c0] No bit rate set. Defaulting to 64000 bps.
[1698061079.477] [lavcd aud.] Setting AV frame: 960 samples, format 3, sample rate 48000[1698061079.477] [lavcd aud.] Sending PTS 0
[1698061079.477] [lavcd aud.] Sending PTS 960   
[1698061079.508] [DeckLink capture] Format change detected (field dominance - YCbCr422, 10bit).
[1698061079.530] [lavcd aud.] Sending PTS 0
[1698061079.531] [lavc libopus @ 0x7f29080066c0] Queue input is backward in time
[1698061079.549] [lavcd aud.] Sending PTS 960
[1698061079.566] [lavcd aud.] Sending PTS 1920
[1698061079.582] [lavcd aud.] Sending PTS 2880
[1698061079.597] [lavcd aud.] Sending PTS 3840
[ OK from now ]

When there is format auto-detection, at least on the beginning this occurs once (if using auto-detection). Not sure if this causes some problems now (but possible with DeckLink sync output).

MartinPulec commented 8 months ago

This issue shouldn't now occur now (since 5e2815c1) when UG starts. It still does when format changes, because DeckLink resets timestaps when IDeckLinkInput::EnableVideoInput() is called (needs to be called with the new format).

Since the timestamp discontinuity doesn't seem to be producing issues (aside the warning), I am considering not solving that. It is perhaps not possible to persuade the BMD API not the reset the timer so it will require to "remember" the offset and adding it to the timestamp from device.

alatteri commented 8 months ago

Agreed. Apart from the warning, doesn't seem to actually be creating any negative behavior.