FFmpeg
smpte436m_to_eia608.c
Go to the documentation of this file.
1 /*
2  * MXF SMPTE-436M ANC to EIA-608 bitstream filter
3  * Copyright (c) 2025 Jacob Lifshay
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "bsf.h"
23 #include "bsf_internal.h"
24 #include "codec_id.h"
25 #include "libavcodec/smpte_436m.h"
26 #include "libavutil/error.h"
27 
29 {
30  ctx->par_out->codec_type = AVMEDIA_TYPE_SUBTITLE;
31  ctx->par_out->codec_id = AV_CODEC_ID_EIA_608;
32  return 0;
33 }
34 
36 {
37  AVPacket *in;
38  int ret = ff_bsf_get_packet(ctx, &in);
39  if (ret < 0)
40  return ret;
41 
43  ret = av_smpte_436m_anc_iter_init(&iter, in->data, in->size);
44  if (ret < 0)
45  goto fail;
46  AVSmpte436mCodedAnc coded_anc;
47  while ((ret = av_smpte_436m_anc_iter_next(&iter, &coded_anc)) >= 0) {
50  &anc, coded_anc.payload_sample_coding, coded_anc.payload_sample_count, coded_anc.payload, ctx);
51  if (ret < 0)
52  goto fail;
54  if (ret == AVERROR(EAGAIN))
55  continue;
56  if (ret < 0)
57  goto fail;
58  int cc_count = ret;
59 
60  ret = av_new_packet(out, 3 * cc_count);
61  if (ret < 0)
62  goto fail;
63 
65  if (ret < 0)
66  goto fail;
67 
68  // verified it won't fail by running it above
70 
71  av_packet_free(&in);
72 
73  return 0;
74  }
75  if (ret != AVERROR_EOF)
76  return ret;
77  ret = AVERROR(EAGAIN);
78 
79 fail:
80  if (ret < 0)
82  av_packet_free(&in);
83  return ret;
84 }
85 
87  .p.name = "smpte436m_to_eia608",
88  .p.codec_ids = (const enum AVCodecID[]){ AV_CODEC_ID_SMPTE_436M_ANC, AV_CODEC_ID_NONE },
91 };
AV_CODEC_ID_EIA_608
@ AV_CODEC_ID_EIA_608
Definition: codec_id.h:572
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
bsf_internal.h
out
FILE * out
Definition: movenc.c:55
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
AVPacket::data
uint8_t * data
Definition: packet.h:552
AVSmpte436mCodedAnc::payload_sample_count
uint16_t payload_sample_count
Definition: smpte_436m.h:121
av_smpte_436m_anc_iter_next
int av_smpte_436m_anc_iter_next(AVSmpte436mAncIterator *iter, AVSmpte436mCodedAnc *anc)
Get the next ANC packet from the iterator, advancing the iterator.
Definition: smpte_436m.c:250
ff_bsf_get_packet
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
Definition: bsf.c:235
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:75
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
bsf.h
fail
#define fail()
Definition: checkasm.h:199
av_cold
#define av_cold
Definition: attributes.h:90
codec_id.h
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: packet.c:99
av_smpte_291m_anc_8bit_decode
int av_smpte_291m_anc_8bit_decode(AVSmpte291mAnc8bit *out, AVSmpte436mPayloadSampleCoding sample_coding, uint16_t sample_count, const uint8_t *payload, void *log_ctx)
Decode a AVSmpte436mCodedAnc payload into AVSmpte291mAnc8bit.
Definition: smpte_436m.c:295
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_smpte_436m_anc_iter_init
int av_smpte_436m_anc_iter_init(AVSmpte436mAncIterator *iter, const uint8_t *buf, int buf_size)
Set up iteration over the ANC packets in a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.
Definition: smpte_436m.c:234
smpte_436m.h
NULL
#define NULL
Definition: coverity.c:32
FFBitStreamFilter
Definition: bsf_internal.h:27
error.h
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
AVPacket::size
int size
Definition: packet.h:553
ff_smpte436m_to_eia608_filter
static int ff_smpte436m_to_eia608_filter(AVBSFContext *ctx, AVPacket *out)
Definition: smpte436m_to_eia608.c:35
AVSmpte436mCodedAnc
An encoded ANC packet within a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.
Definition: smpte_436m.h:117
AVSmpte291mAnc8bit
An ANC packet with an 8-bit payload.
Definition: smpte_436m.h:98
av_packet_copy_props
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: packet.c:395
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
AV_CODEC_ID_SMPTE_436M_ANC
@ AV_CODEC_ID_SMPTE_436M_ANC
Definition: codec_id.h:606
AVSmpte436mCodedAnc::payload
uint8_t payload[AV_SMPTE_436M_CODED_ANC_PAYLOAD_CAPACITY]
the payload, has size payload_array_length.
Definition: smpte_436m.h:126
ret
ret
Definition: filter_design.txt:187
av_smpte_291m_anc_8bit_extract_cta_708
int av_smpte_291m_anc_8bit_extract_cta_708(const AVSmpte291mAnc8bit *anc, uint8_t *cc_data, void *log_ctx)
Try to decode an ANC packet into EIA-608/CTA-708 data (AV_CODEC_ID_EIA_608).
Definition: smpte_436m.c:433
AVSmpte436mAncIterator
Iterator over the ANC packets in a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.
Definition: smpte_436m.h:30
AVPacket
This structure stores compressed data.
Definition: packet.h:529
ff_smpte436m_to_eia608_init
static av_cold int ff_smpte436m_to_eia608_init(AVBSFContext *ctx)
Definition: smpte436m_to_eia608.c:28
AVSmpte436mCodedAnc::payload_sample_coding
AVSmpte436mPayloadSampleCoding payload_sample_coding
Definition: smpte_436m.h:120
ff_smpte436m_to_eia608_bsf
const FFBitStreamFilter ff_smpte436m_to_eia608_bsf
Definition: smpte436m_to_eia608.c:86