FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/bsf/smpte436m_to_eia608.c
Date: 2025-08-19 23:55:23
Exec Total Coverage
Lines: 25 39 64.1%
Functions: 2 2 100.0%
Branches: 9 20 45.0%

Line Branch Exec Source
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
28 1 static av_cold int ff_smpte436m_to_eia608_init(AVBSFContext *ctx)
29 {
30 1 ctx->par_out->codec_type = AVMEDIA_TYPE_SUBTITLE;
31 1 ctx->par_out->codec_id = AV_CODEC_ID_EIA_608;
32 1 return 0;
33 }
34
35 65 static int ff_smpte436m_to_eia608_filter(AVBSFContext *ctx, AVPacket *out)
36 {
37 AVPacket *in;
38 65 int ret = ff_bsf_get_packet(ctx, &in);
39
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 32 times.
65 if (ret < 0)
40 33 return ret;
41
42 AVSmpte436mAncIterator iter;
43 32 ret = av_smpte_436m_anc_iter_init(&iter, in->data, in->size);
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
45 goto fail;
46 AVSmpte436mCodedAnc coded_anc;
47
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 while ((ret = av_smpte_436m_anc_iter_next(&iter, &coded_anc)) >= 0) {
48 AVSmpte291mAnc8bit anc;
49 32 ret = av_smpte_291m_anc_8bit_decode(
50 32 &anc, coded_anc.payload_sample_coding, coded_anc.payload_sample_count, coded_anc.payload, ctx);
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
52 goto fail;
53 32 ret = av_smpte_291m_anc_8bit_extract_cta_708(&anc, NULL, ctx);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret == AVERROR(EAGAIN))
55 continue;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
57 goto fail;
58 32 int cc_count = ret;
59
60 32 ret = av_new_packet(out, 3 * cc_count);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
62 goto fail;
63
64 32 ret = av_packet_copy_props(out, in);
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
66 goto fail;
67
68 // verified it won't fail by running it above
69 32 av_smpte_291m_anc_8bit_extract_cta_708(&anc, out->data, ctx);
70
71 32 av_packet_free(&in);
72
73 32 return 0;
74 }
75 if (ret != AVERROR_EOF)
76 return ret;
77 ret = AVERROR(EAGAIN);
78
79 fail:
80 if (ret < 0)
81 av_packet_unref(out);
82 av_packet_free(&in);
83 return ret;
84 }
85
86 const FFBitStreamFilter ff_smpte436m_to_eia608_bsf = {
87 .p.name = "smpte436m_to_eia608",
88 .p.codec_ids = (const enum AVCodecID[]){ AV_CODEC_ID_SMPTE_436M_ANC, AV_CODEC_ID_NONE },
89 .init = ff_smpte436m_to_eia608_init,
90 .filter = ff_smpte436m_to_eia608_filter,
91 };
92