From: Devin Heitmueller <devin.heitmueller@ltnglobal.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 0/2] Implement SMPTE 2038 output support over Decklink SDI Date: Mon, 24 Apr 2023 10:11:25 -0400 Message-ID: <CAHGibzFsJOrK4M-OPEgr_EwiC3Ld61Kybi-UgJ3VhYA9pdqMSA@mail.gmail.com> (raw) In-Reply-To: <b5eadd-1f72-df86-d444-94a855d6856b@passwd.hu> Hello Marton, Thanks for reviewing. Comments inline: On Sun, Apr 23, 2023 at 2:43 PM Marton Balint <cus@passwd.hu> wrote: > In general, queueing packets in specific components should be avoided if > possible. Muxed packets are normally ordered by DTS and stream id, generic > code ensures that. If you want something other than that, then I think > the perferred way of doing it is by providing a custom interleave > function. (e.g. to ensure you get data packets before video even if data > stream has a higher stream ID.) To be clear, using a queue was not first choice. It's the result of trying different approaches, and I'm open to constructive suggestions on alternatives. While what you're are saying is correct "in general", there are some really important reasons why it doesn't work in this case. Permit me to explain... By default, the behavior of the mux interleaver is to wait until there is at least one packet available for each stream before writing to the output module (in this case decklink). However data formats such as SMPTE ST2038 are considered to be "sparse" as there isn't necessarily a continuous stream of packets like with video and audio (there may be many seconds between packets, or no packets at all). As a result you can't wait for a packet to be available on all streams since on some streams it will simply wait continuously until hitting the max_interleave_delta, at which point it will burst out everything in the queue. This would cause stalls and/or stuttering playback on the decklink output. To accommodate these sparse streams we added code to mux.c to not wait for 2038 packets. A side-effect of that though is that packets will be sent through as soon as they hit the mux, which in most cases will be significantly ahead of the video (potentially hundreds of milliseconds). This can easily be seen experimentally by adding an av_log() line to ff_decklink_write_packet(), which will show in many cases the PTS values of the data frames being sent 20+ frames before the corresponding video. The queue is there because the data packets and video frames arrive in separate calls to write_packet(), and they need to be combined to ensure they are inserted into the same video frame. Stashing the data packets seemed like a reasonable approach, and a queue seemed like a good choice as a data structure since there can be multiple data packets for a video frame and we might receive data packets for multiple video frames before the corresponding video frames arrived. The notion you mentioned that the data packets might arrive after the video frames is a valid concern hypothetically. In practice it hasn't been an issue, as the data packets tend to arrive long before the video. It was not a motivation for using a queue. If a data packet did arrive after the video (due to the DTS and stream ID ordering you mentioned), the implementation would insert it on the next video frame and it would effectively be one frame late. I was willing to accept this edge case given it doesn't actually happen in practice. > If you are only using the queue to store multiple data packets for a > single frame then one way to avoid it is to parse them as soon as they > arrive via the KLV library. If you insist on queueing them (maybe because > not every packet will be parased by the KLV lib), then I'd rather see you > use avpriv_packet_list_*() functions, and not a custom decklink > implementation. Passing them off to libklvanc doesn't actually change the queueing problem. The libklvanc library doesn't actually output the VANC packets but rather just converts them into the byte sequences that then need to be embedded into the video frames. I guess I could queue the output of libklvanc rather than the original AVPackets, but that doesn't actually solve any of the problems described above, and actually makes things more complicated since the AVPackets contain all the timing data and the VANC byte blobs would need to queue not just the data but also the output timing, VANC line number and horizontal position within the VANC region. Regarding the use of avpriv_packet_list() as opposed to avpacket_queue_*, I used the avpacket_queue functions for consistency with the decklink capture module where it is used today. Also, avpacket_queue is threadsafe while avpriv_packet_list.*() is not. While the threadsafeness is not critical for the VANC case, I have subsequent patches for audio where it is important, and I figured it would more consistent to use the same queue mechanism within decklink for all three (capture, audio output, and vanc output). That said, I wouldn't specifically object to converting to the avpriv_packet_list functions since thread-safeness isn't really a requirement for this particular case. It's probably worth noting though that I extended the avpacket_queue method to allow me to peek at the first packet in the queue (which avpriv_packet_list doesn't support today). Hence converting to avpriv_packet_list would require an equivalent addition to be accepted upstream. Devin -- Devin Heitmueller, Senior Software Engineer LTN Global Communications o: +1 (301) 363-1001 w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-04-24 14:19 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-04-21 21:12 Devin Heitmueller 2023-04-21 21:12 ` [FFmpeg-devel] [PATCH 1/2] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller 2023-04-21 21:12 ` [FFmpeg-devel] [PATCH 2/2] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller 2023-04-23 18:42 ` [FFmpeg-devel] [PATCH 0/2] Implement SMPTE 2038 output support over Decklink SDI Marton Balint 2023-04-24 14:11 ` Devin Heitmueller [this message] 2023-04-25 21:58 ` Marton Balint 2023-04-26 14:45 ` Devin Heitmueller 2023-04-26 7:35 ` Marton Balint 2023-04-26 14:30 ` Devin Heitmueller
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CAHGibzFsJOrK4M-OPEgr_EwiC3Ld61Kybi-UgJ3VhYA9pdqMSA@mail.gmail.com \ --to=devin.heitmueller@ltnglobal.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git