FFmpeg
ccfifo.h
Go to the documentation of this file.
1 /*
2  * CEA-708 Closed Captioning FIFO
3  * Copyright (c) 2023 LTN Global Communications
4  *
5  * Author: Devin Heitmueller <dheitmueller@ltnglobal.com>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * CC FIFO Buffer
27  */
28 
29 #ifndef AVFILTER_CCFIFO_H
30 #define AVFILTER_CCFIFO_H
31 
32 #include "libavutil/avutil.h"
33 #include "libavutil/frame.h"
34 #include "libavutil/fifo.h"
35 
36 typedef struct CCFifo {
45  void *log_ctx;
46 } CCFifo;
47 
48 /**
49  * Initialize a CCFifo.
50  *
51  * @param framerate output framerate
52  * @param log_ctx used for any av_log() calls
53  * @return Zero on success, or negative AVERROR code on failure.
54  */
55 int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx);
56 
57 /**
58  * Free all memory allocated in a CCFifo and clear the context.
59  *
60  * @param ccf Pointer to the CCFifo which should be uninitialized
61  */
62 void ff_ccfifo_uninit(CCFifo *ccf);
63 
64 /**
65  * Extract CC data from an AVFrame
66  *
67  * Extract CC bytes from the AVFrame, insert them into our queue, and
68  * remove the side data from the AVFrame. The side data is removed
69  * as it will be re-inserted at the appropriate rate later in the
70  * filter.
71  *
72  * @param af CCFifo to write to
73  * @param frame AVFrame with the video frame to operate on
74  * @return Zero on success, or negative AVERROR
75  * code on failure.
76  */
78 
79 /**
80  *Just like ff_ccfifo_extract(), but takes the raw bytes instead of an AVFrame
81  */
82 int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *data, size_t len);
83 
84 /**
85  * Provide the size in bytes of an output buffer to allocate
86  *
87  * Ask for how many bytes the output will contain, so the caller can allocate
88  * an appropriately sized buffer and pass it to ff_ccfifo_injectbytes()
89  *
90  */
91 int ff_ccfifo_getoutputsize(const CCFifo *ccf);
92 
93 /**
94  * Insert CC data from the FIFO into an AVFrame (as side data)
95  *
96  * Dequeue the appropriate number of CC tuples based on the
97  * frame rate, and insert them into the AVFrame
98  *
99  * @param af CCFifo to read from
100  * @param frame AVFrame with the video frame to operate on
101  * @return Zero on success, or negative AVERROR
102  * code on failure.
103  */
105 
106 /**
107  * Just like ff_ccfifo_inject(), but takes the raw bytes to insert the CC data
108  * int rather than an AVFrame
109  */
110 int ff_ccfifo_injectbytes(CCFifo *ccf, uint8_t *data, size_t len);
111 
112 /**
113  * Returns 1 if captions have been found as a prior call
114  * to ff_ccfifo_extract() or ff_ccfifo_extractbytes()
115  */
116 int ff_ccfifo_ccdetected(const CCFifo *ccf);
117 
118 #endif /* AVFILTER_CCFIFO_H */
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
CCFifo::framerate
AVRational framerate
Definition: ccfifo.h:39
ff_ccfifo_getoutputsize
int ff_ccfifo_getoutputsize(const CCFifo *ccf)
Provide the size in bytes of an output buffer to allocate.
Definition: ccfifo.c:92
data
const char data[16]
Definition: mxf.c:148
fifo.h
ff_ccfifo_uninit
void ff_ccfifo_uninit(CCFifo *ccf)
Free all memory allocated in a CCFifo and clear the context.
Definition: ccfifo.c:46
ff_ccfifo_inject
int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame)
Insert CC data from the FIFO into an AVFrame (as side data)
Definition: ccfifo.c:143
CCFifo::expected_608
int expected_608
Definition: ccfifo.h:41
CCFifo::cc_detected
int cc_detected
Definition: ccfifo.h:42
ff_ccfifo_injectbytes
int ff_ccfifo_injectbytes(CCFifo *ccf, uint8_t *data, size_t len)
Just like ff_ccfifo_inject(), but takes the raw bytes to insert the CC data int rather than an AVFram...
Definition: ccfifo.c:102
ff_ccfifo_ccdetected
int ff_ccfifo_ccdetected(const CCFifo *ccf)
Returns 1 if captions have been found as a prior call to ff_ccfifo_extract() or ff_ccfifo_extractbyte...
Definition: ccfifo.c:97
CCFifo::passthrough
int passthrough
Definition: ccfifo.h:43
framerate
float framerate
Definition: av1_levels.c:29
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
CCFifo
Definition: ccfifo.h:36
AVFifo
Definition: fifo.c:35
frame.h
ff_ccfifo_extractbytes
int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *data, size_t len)
Just like ff_ccfifo_extract(), but takes the raw bytes instead of an AVFrame.
Definition: ccfifo.c:164
len
int len
Definition: vorbis_enc_data.h:426
ff_ccfifo_init
int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx)
Initialize a CCFifo.
Definition: ccfifo.c:53
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
CCFifo::expected_cc_count
int expected_cc_count
Definition: ccfifo.h:40
CCFifo::log_ctx
void * log_ctx
Definition: ccfifo.h:45
ff_ccfifo_extract
int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame)
Extract CC data from an AVFrame.
Definition: ccfifo.c:193
CCFifo::cc_608_fifo
AVFifo * cc_608_fifo
Definition: ccfifo.h:37
avutil.h
CCFifo::passthrough_warning
int passthrough_warning
Definition: ccfifo.h:44
CCFifo::cc_708_fifo
AVFifo * cc_708_fifo
Definition: ccfifo.h:38