Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v4] decklink: Add support for compressed AC-3 output over SDI
Date: Wed, 5 Apr 2023 23:52:34 +0200 (CEST)
Message-ID: <48b77d7-cc59-21b4-9ab2-202b74a56c9f@passwd.hu> (raw)
In-Reply-To: <20230403212823.890-1-dheitmueller@ltnglobal.com>



On Mon, 3 Apr 2023, Devin Heitmueller wrote:

> Extend the decklink output to include support for compressed AC-3,
> encapsulated using the SMPTE ST 377:2015 standard.
>
> This functionality can be exercised by using the "copy" codec when
> the input audio stream is AC-3.  For example:
>
> ./ffmpeg -i ~/foo.ts -codec:a copy -f decklink 'UltraStudio Mini Monitor'
>
> Note that the default behavior continues to be to do PCM output,
> which means without specifying the copy codec a stream containing
> AC-3 will be decoded and downmixed to stereo audio before output.
>
> Thanks to Marton Balint for providing feedback.
>
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
> ---
> libavdevice/decklink_enc.cpp | 97 ++++++++++++++++++++++++++++++------
> 1 file changed, 82 insertions(+), 15 deletions(-)
>
> diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
> index 8d423f6b6e..9ee1925fd0 100644

[...]

> --- a/libavdevice/decklink_enc.cpp
> +++ b/libavdevice/decklink_enc.cpp
> +/* Wrap the AC-3 packet into an S337 payload that is in S16LE format which can be easily
> +   injected into the PCM stream.  Note: despite the function name, only AC-3 is implemented */
> +static int create_s337_payload(AVPacket *pkt, enum AVCodecID codec_id, uint8_t **outbuf, int *outsize)

Actually you can remove the codec_id parameter as well...

> +{
> +    // Note: if the packet is an odd-number of bytes, we need to make
> +    // the actual payload one byte larger to ensure it ends on an S16LE boundary
> +    int payload_size = pkt->size + (pkt->size % 2) + 8;

FFALIGN(pkt->size, 2). But you'd want FFALIGN(pkt->size, 4) because you 
want the buffer size to be divisable by 4 because later decklink needs a 
sample count...

> +    uint16_t bitcount = pkt->size * 8;

Is this supposed to be aligned too? I see similar code in 
libavformat/spdifenc.c and FFALIGN(pkt->size, 2) << 3 is used there.

> +    uint8_t *s337_payload;
> +    PutByteContext pb;
> +
> +    /* Sanity check:  According to SMPTE ST 340:2015 Sec 4.1, the AC-3 sync frame will
> +       exactly match the 1536 samples of baseband (PCM) audio that it represents.  */
> +    if (pkt->size > 1536)
> +        return AVERROR(EINVAL);
> +
> +    /* Encapsulate AC3 syncframe into SMPTE 337 packet */
> +    s337_payload = (uint8_t *) av_malloc(payload_size);
> +    if (s337_payload == NULL)
> +        return AVERROR(ENOMEM);
> +    bytestream2_init_writer(&pb, s337_payload, payload_size);
> +    bytestream2_put_le16u(&pb, 0xf872); /* Sync word 1 */
> +    bytestream2_put_le16u(&pb, 0x4e1f); /* Sync word 1 */
> +    bytestream2_put_le16u(&pb, 0x0001); /* Burst Info, including data type (1=ac3) */
> +    bytestream2_put_le16u(&pb, bitcount); /* Length code */
> +    for (int i = 0; i < (pkt->size - 1); i += 2)
> +        bytestream2_put_le16u(&pb, (pkt->data[i] << 8) | pkt->data[i+1]);
> +    if (pkt->size % 2)

pkt->size & 1

> +        bytestream2_put_le16u(&pb, pkt->data[pkt->size - 1] << 8);
> +

And you likely want a bytestream2_put_le16(&pb, 0) in the end so even 
the end of the 4-byte aligned buffer is properly zeroed.

Thanks,
Marton
_______________________________________________
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".

  reply	other threads:[~2023-04-05 21:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 21:28 Devin Heitmueller
2023-04-05 21:52 ` Marton Balint [this message]
2023-04-07 19:03   ` 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=48b77d7-cc59-21b4-9ab2-202b74a56c9f@passwd.hu \
    --to=cus@passwd.hu \
    --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