FFmpeg
Loading...
Searching...
No Matches
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 "libavcodec/bsf.h"
24#include "libavcodec/codec_id.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
64 ret = av_packet_copy_props(out, in);
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 goto fail;
77 ret = AVERROR(EAGAIN);
78
79fail:
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};
const FFBitStreamFilter ff_smpte436m_to_eia608_bsf
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
Definition bsf.c:233
#define NULL
Definition coverity.c:32
error code definitions
#define fail
Definition test.h:479
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_EIA_608
Definition codec_id.h:576
@ AV_CODEC_ID_SMPTE_436M_ANC
Definition codec_id.h:610
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition packet.c:397
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
#define av_cold
Definition attributes.h:117
static int ff_smpte436m_to_eia608_filter(AVBSFContext *ctx, AVPacket *out)
static av_cold int ff_smpte436m_to_eia608_init(AVBSFContext *ctx)
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
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
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
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
The bitstream filter state.
Definition bsf.h:68
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
An ANC packet with an 8-bit payload.
Definition smpte_436m.h:98
Iterator over the ANC packets in a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.
Definition smpte_436m.h:30
An encoded ANC packet within a single AV_CODEC_ID_SMPTE_436M_ANC AVPacket's data.
Definition smpte_436m.h:117
AVSmpte436mPayloadSampleCoding payload_sample_coding
Definition smpte_436m.h:120
uint16_t payload_sample_count
Definition smpte_436m.h:121
uint8_t payload[AV_SMPTE_436M_CODED_ANC_PAYLOAD_CAPACITY]
the payload, has size payload_array_length.
Definition smpte_436m.h:126
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49