MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / create_s337_payload

Function create_s337_payload

libavdevice/decklink_enc.cpp:323–358  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

321/* Wrap the AC-3 packet into an S337 payload that is in S16LE format which can be easily
322 injected into the PCM stream. Note: despite the function name, only AC-3 is implemented */
323static int create_s337_payload(AVPacket *pkt, uint8_t **outbuf, int *outsize)
324{
325 /* Note: if the packet size is not divisible by four, we need to make the actual
326 payload larger to ensure it ends on an two channel S16LE boundary */
327 int payload_size = FFALIGN(pkt->size, 4) + 8;
328 uint16_t bitcount = pkt->size * 8;
329 uint8_t *s337_payload;
330 PutByteContext pb;
331
332 /* Sanity check: According to SMPTE ST 340:2015 Sec 4.1, the AC-3 sync frame will
333 exactly match the 1536 samples of baseband (PCM) audio that it represents. */
334 if (pkt->size > 1536)
335 return AVERROR(EINVAL);
336
337 /* Encapsulate AC3 syncframe into SMPTE 337 packet */
338 s337_payload = (uint8_t *) av_malloc(payload_size);
339 if (s337_payload == NULL)
340 return AVERROR(ENOMEM);
341 bytestream2_init_writer(&pb, s337_payload, payload_size);
342 bytestream2_put_le16u(&pb, 0xf872); /* Sync word 1 */
343 bytestream2_put_le16u(&pb, 0x4e1f); /* Sync word 1 */
344 bytestream2_put_le16u(&pb, 0x0001); /* Burst Info, including data type (1=ac3) */
345 bytestream2_put_le16u(&pb, bitcount); /* Length code */
346 for (int i = 0; i < (pkt->size - 1); i += 2)
347 bytestream2_put_le16u(&pb, (pkt->data[i] << 8) | pkt->data[i+1]);
348
349 /* Ensure final payload is aligned on 4-byte boundary */
350 if (pkt->size & 1)
351 bytestream2_put_le16u(&pb, pkt->data[pkt->size - 1] << 8);
352 if ((pkt->size & 3) == 1 || (pkt->size & 3) == 2)
353 bytestream2_put_le16u(&pb, 0);
354
355 *outsize = payload_size;
356 *outbuf = s337_payload;
357 return 0;
358}
359
360static int decklink_setup_subtitle(AVFormatContext *avctx, AVStream *st)
361{

Callers 1

Calls 2

bytestream2_init_writerFunction · 0.85
av_mallocFunction · 0.50

Tested by

no test coverage detected