Path: blob/master/dep/ffmpeg/include/libavcodec/smpte_436m.h
5196 views
/*1* MXF SMPTE-436M VBI/ANC parsing functions2* Copyright (c) 2025 Jacob Lifshay3*4* This file is part of FFmpeg.5*6* FFmpeg is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public8* License as published by the Free Software Foundation; either9* version 2.1 of the License, or (at your option) any later version.10*11* FFmpeg is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with FFmpeg; if not, write to the Free Software18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19*/2021#ifndef AVCODEC_SMPTE_436M_H22#define AVCODEC_SMPTE_436M_H2324#include <stdint.h>2526/**27* Iterator over the ANC packets in a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data28*/29typedef struct AVSmpte436mAncIterator {30uint16_t anc_packets_left;31int size_left;32const uint8_t *data_left;33} AVSmpte436mAncIterator;3435/**36* Wrapping Type from Table 7 (page 13) of:37* https://pub.smpte.org/latest/st436/s436m-2006.pdf38*/39typedef enum AVSmpte436mWrappingType40{41AV_SMPTE_436M_WRAPPING_TYPE_VANC_FRAME = 1,42AV_SMPTE_436M_WRAPPING_TYPE_VANC_FIELD_1 = 2,43AV_SMPTE_436M_WRAPPING_TYPE_VANC_FIELD_2 = 3,44AV_SMPTE_436M_WRAPPING_TYPE_VANC_PROGRESSIVE_FRAME = 4,45AV_SMPTE_436M_WRAPPING_TYPE_HANC_FRAME = 0x11,46AV_SMPTE_436M_WRAPPING_TYPE_HANC_FIELD_1 = 0x12,47AV_SMPTE_436M_WRAPPING_TYPE_HANC_FIELD_2 = 0x13,48AV_SMPTE_436M_WRAPPING_TYPE_HANC_PROGRESSIVE_FRAME = 0x14,49/** not a real wrapping type, just here to guarantee the enum is big enough */50AV_SMPTE_436M_WRAPPING_TYPE_MAX = 0xFF,51} AVSmpte436mWrappingType;5253/**54* Payload Sample Coding from Table 4 (page 10) and Table 7 (page 13) of:55* https://pub.smpte.org/latest/st436/s436m-2006.pdf56*/57typedef enum AVSmpte436mPayloadSampleCoding58{59/** only used for VBI */60AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_1BIT_LUMA = 1,61/** only used for VBI */62AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_1BIT_COLOR_DIFF = 2,63/** only used for VBI */64AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_1BIT_LUMA_AND_COLOR_DIFF = 3,65/** used for VBI and ANC */66AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_LUMA = 4,67/** used for VBI and ANC */68AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_COLOR_DIFF = 5,69/** used for VBI and ANC */70AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_LUMA_AND_COLOR_DIFF = 6,71/** used for VBI and ANC */72AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_10BIT_LUMA = 7,73/** used for VBI and ANC */74AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_10BIT_COLOR_DIFF = 8,75/** used for VBI and ANC */76AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_10BIT_LUMA_AND_COLOR_DIFF = 9,77/** only used for ANC */78AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_LUMA_WITH_PARITY_ERROR = 10,79/** only used for ANC */80AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_COLOR_DIFF_WITH_PARITY_ERROR = 11,81/** only used for ANC */82AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_8BIT_LUMA_AND_COLOR_DIFF_WITH_PARITY_ERROR = 12,83/** not a real sample coding, just here to guarantee the enum is big enough */84AV_SMPTE_436M_PAYLOAD_SAMPLE_CODING_MAX = 0xFF,85} AVSmpte436mPayloadSampleCoding;8687/** the payload capacity of AVSmpte291mAnc8bit (and of AVSmpte291mAnc10bit when that gets added) */88#define AV_SMPTE_291M_ANC_PAYLOAD_CAPACITY 0xFF8990/**91* An ANC packet with an 8-bit payload.92* This can be decoded from AVSmpte436mCodedAnc::payload.93*94* Note: Some ANC packets need a 10-bit payload, if stored in this struct,95* the most-significant 2 bits of each sample are discarded.96*/97typedef struct AVSmpte291mAnc8bit {98uint8_t did;99uint8_t sdid_or_dbn;100uint8_t data_count;101uint8_t payload[AV_SMPTE_291M_ANC_PAYLOAD_CAPACITY];102uint8_t checksum;103} AVSmpte291mAnc8bit;104105/** max number of samples that can be stored in the payload of AVSmpte436mCodedAnc */106#define AV_SMPTE_436M_CODED_ANC_SAMPLE_CAPACITY \107(AV_SMPTE_291M_ANC_PAYLOAD_CAPACITY + 4) /* 4 for did, sdid_or_dbn, data_count, and checksum */108/** max number of bytes that can be stored in the payload of AVSmpte436mCodedAnc */109#define AV_SMPTE_436M_CODED_ANC_PAYLOAD_CAPACITY (((AV_SMPTE_436M_CODED_ANC_SAMPLE_CAPACITY + 2) / 3) * 4)110111/**112* An encoded ANC packet within a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.113* The repeated section of Table 7 (page 13) of:114* https://pub.smpte.org/latest/st436/s436m-2006.pdf115*/116typedef struct AVSmpte436mCodedAnc {117uint16_t line_number;118AVSmpte436mWrappingType wrapping_type;119AVSmpte436mPayloadSampleCoding payload_sample_coding;120uint16_t payload_sample_count;121uint32_t payload_array_length;122/** the payload, has size payload_array_length.123* can be decoded into AVSmpte291mAnc8bit124*/125uint8_t payload[AV_SMPTE_436M_CODED_ANC_PAYLOAD_CAPACITY];126} AVSmpte436mCodedAnc;127128/**129* Validate a AVSmpte436mCodedAnc structure. Doesn't check if the payload is valid.130* @param[in] anc ANC packet to validate131* @return 0 on success, AVERROR codes otherwise.132*/133int av_smpte_436m_coded_anc_validate(const AVSmpte436mCodedAnc *anc);134135/**136* Encode ANC packets into a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.137* @param[in] anc_packet_count number of ANC packets to encode138* @param[in] anc_packets the ANC packets to encode139* @param[in] size the size of out. ignored if out is NULL.140* @param[out] out Output bytes. Doesn't write anything if out is NULL.141* @return the number of bytes written on success, AVERROR codes otherwise.142* If out is NULL, returns the number of bytes it would have written.143*/144int av_smpte_436m_anc_encode(uint8_t *out, int size, int anc_packet_count, const AVSmpte436mCodedAnc *anc_packets);145146struct AVPacket;147148/**149* Append more ANC packets to a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.150* @param[in] anc_packet_count number of ANC packets to encode151* @param[in] anc_packets the ANC packets to encode152* @param pkt the AVPacket to append to.153* it must either be size 0 or contain valid SMPTE_436M_ANC data.154* @return 0 on success, AVERROR codes otherwise.155*/156int av_smpte_436m_anc_append(struct AVPacket *pkt, int anc_packet_count, const AVSmpte436mCodedAnc *anc_packets);157158/**159* Set up iteration over the ANC packets in a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.160* @param[in] buf Pointer to the data from a AV_CODEC_ID_SMPTE_436M_ANC AVPacket.161* @param[in] buf_size Size of the data from a AV_CODEC_ID_SMPTE_436M_ANC AVPacket.162* @param[out] iter Pointer to the iterator.163* @return 0 on success, AVERROR codes otherwise.164*/165int av_smpte_436m_anc_iter_init(AVSmpte436mAncIterator *iter, const uint8_t *buf, int buf_size);166167/**168* Get the next ANC packet from the iterator, advancing the iterator.169* @param[in,out] iter Pointer to the iterator.170* @param[out] anc The returned ANC packet.171* @return 0 on success, AVERROR_EOF when the iterator has reached the end, AVERROR codes otherwise.172*/173int av_smpte_436m_anc_iter_next(AVSmpte436mAncIterator *iter, AVSmpte436mCodedAnc *anc);174175/**176* Get the minimum number of bytes needed to store a AVSmpte436mCodedAnc payload.177* @param sample_coding the payload sample coding178* @param sample_count the number of samples stored in the payload179* @return returns the minimum number of bytes needed, on error returns < 0.180* always <= SMPTE_436M_CODED_ANC_PAYLOAD_CAPACITY181*/182int av_smpte_436m_coded_anc_payload_size(AVSmpte436mPayloadSampleCoding sample_coding, uint16_t sample_count);183184/**185* Decode a AVSmpte436mCodedAnc payload into AVSmpte291mAnc8bit186* @param[in] sample_coding the payload sample coding187* @param[in] sample_count the number of samples stored in the payload188* @param[in] payload the bytes storing the payload,189* the needed size can be obtained from190avpriv_smpte_436m_coded_anc_payload_size191* @param[in] log_ctx context pointer for av_log192* @param[out] out The decoded ANC packet.193* @return returns 0 on success, otherwise < 0.194*/195int av_smpte_291m_anc_8bit_decode(AVSmpte291mAnc8bit *out,196AVSmpte436mPayloadSampleCoding sample_coding,197uint16_t sample_count,198const uint8_t *payload,199void *log_ctx);200201/**202* Fill in the correct checksum for a AVSmpte291mAnc8bit203* @param[in,out] anc The ANC packet.204*/205void av_smpte_291m_anc_8bit_fill_checksum(AVSmpte291mAnc8bit *anc);206207/**208* Compute the sample count needed to encode a AVSmpte291mAnc8bit into a AVSmpte436mCodedAnc payload209* @param[in] anc The ANC packet.210* @param[in] sample_coding The sample coding.211* @param[in] log_ctx context pointer for av_log212* @return returns the sample count on success, otherwise < 0.213*/214int av_smpte_291m_anc_8bit_get_sample_count(const AVSmpte291mAnc8bit *anc,215AVSmpte436mPayloadSampleCoding sample_coding,216void *log_ctx);217218/**219* Encode a AVSmpte291mAnc8bit into a AVSmpte436mCodedAnc220* @param[in] line_number the line number the ANC packet is on221* @param[in] wrapping_type the wrapping type222* @param[in] sample_coding the payload sample coding223* @param[in] payload the ANC packet to encode.224* @param[in] log_ctx context pointer for av_log225* @param[out] out The encoded ANC packet.226* @return returns 0 on success, otherwise < 0.227*/228int av_smpte_291m_anc_8bit_encode(AVSmpte436mCodedAnc *out,229uint16_t line_number,230AVSmpte436mWrappingType wrapping_type,231AVSmpte436mPayloadSampleCoding sample_coding,232const AVSmpte291mAnc8bit *payload,233void *log_ctx);234235/** AVSmpte291mAnc8bit::did when carrying CTA-708 data (for AV_CODEC_ID_EIA_608) */236#define AV_SMPTE_291M_ANC_DID_CTA_708 0x61237238/** AVSmpte291mAnc8bit::sdid_or_dbn when carrying CTA-708 data (for AV_CODEC_ID_EIA_608) */239#define AV_SMPTE_291M_ANC_SDID_CTA_708 0x1240241/**242* Try to decode an ANC packet into EIA-608/CTA-708 data (AV_CODEC_ID_EIA_608). This243* @param[in] anc The ANC packet.244* @param[in] log_ctx Context pointer for av_log245* @param[out] cc_data the buffer to store the extracted EIA-608/CTA-708 data,246* you can pass NULL to not store the data.247* the required size is 3 * cc_count bytes.248* SMPTE_291M_ANC_PAYLOAD_CAPACITY is always enough size.249* @return returns cc_count (>= 0) on success, AVERROR(EAGAIN) if it wasn't a CTA-708 ANC packet, < 0 on error.250*/251int av_smpte_291m_anc_8bit_extract_cta_708(const AVSmpte291mAnc8bit *anc, uint8_t *cc_data, void *log_ctx);252253#endif /* AVCODEC_SMPTE_436M_H */254255256