Line |
Branch |
Exec |
Source |
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 <stddef.h> |
33 |
|
|
#include <stdint.h> |
34 |
|
|
|
35 |
|
|
#include "libavutil/frame.h" |
36 |
|
|
#include "libavutil/rational.h" |
37 |
|
|
|
38 |
|
|
#define CC_BYTES_PER_ENTRY 3 |
39 |
|
|
|
40 |
|
|
typedef struct CCFifo { |
41 |
|
|
struct AVFifo *cc_608_fifo; |
42 |
|
|
struct AVFifo *cc_708_fifo; |
43 |
|
|
AVRational framerate; |
44 |
|
|
int expected_cc_count; |
45 |
|
|
int expected_608; |
46 |
|
|
int cc_detected; |
47 |
|
|
int passthrough; |
48 |
|
|
int passthrough_warning; |
49 |
|
|
void *log_ctx; |
50 |
|
|
} CCFifo; |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Initialize a CCFifo. |
54 |
|
|
* |
55 |
|
|
* @param framerate output framerate |
56 |
|
|
* @param log_ctx used for any av_log() calls |
57 |
|
|
* @return Zero on success, or negative AVERROR code on failure. |
58 |
|
|
*/ |
59 |
|
|
int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx); |
60 |
|
|
|
61 |
|
|
/** |
62 |
|
|
* Free all memory allocated in a CCFifo and clear the context. |
63 |
|
|
* |
64 |
|
|
* @param ccf Pointer to the CCFifo which should be uninitialized |
65 |
|
|
*/ |
66 |
|
|
void ff_ccfifo_uninit(CCFifo *ccf); |
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* Extract CC data from an AVFrame |
70 |
|
|
* |
71 |
|
|
* Extract CC bytes from the AVFrame, insert them into our queue, and |
72 |
|
|
* remove the side data from the AVFrame. The side data is removed |
73 |
|
|
* as it will be re-inserted at the appropriate rate later in the |
74 |
|
|
* filter. |
75 |
|
|
* |
76 |
|
|
* @param af CCFifo to write to |
77 |
|
|
* @param frame AVFrame with the video frame to operate on |
78 |
|
|
* @return Zero on success, or negative AVERROR |
79 |
|
|
* code on failure. |
80 |
|
|
*/ |
81 |
|
|
int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame); |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
*Just like ff_ccfifo_extract(), but takes the raw bytes instead of an AVFrame |
85 |
|
|
*/ |
86 |
|
|
int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *data, size_t len); |
87 |
|
|
|
88 |
|
|
/** |
89 |
|
|
* Provide the size in bytes of an output buffer to allocate |
90 |
|
|
* |
91 |
|
|
* Ask for how many bytes the output will contain, so the caller can allocate |
92 |
|
|
* an appropriately sized buffer and pass it to ff_ccfifo_injectbytes() |
93 |
|
|
* |
94 |
|
|
*/ |
95 |
|
✗ |
static inline int ff_ccfifo_getoutputsize(const CCFifo *ccf) |
96 |
|
|
{ |
97 |
|
✗ |
return ccf->expected_cc_count * CC_BYTES_PER_ENTRY; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* Insert CC data from the FIFO into an AVFrame (as side data) |
103 |
|
|
* |
104 |
|
|
* Dequeue the appropriate number of CC tuples based on the |
105 |
|
|
* frame rate, and insert them into the AVFrame |
106 |
|
|
* |
107 |
|
|
* @param af CCFifo to read from |
108 |
|
|
* @param frame AVFrame with the video frame to operate on |
109 |
|
|
* @return Zero on success, or negative AVERROR |
110 |
|
|
* code on failure. |
111 |
|
|
*/ |
112 |
|
|
int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame); |
113 |
|
|
|
114 |
|
|
/** |
115 |
|
|
* Just like ff_ccfifo_inject(), but takes the raw bytes to insert the CC data |
116 |
|
|
* int rather than an AVFrame |
117 |
|
|
*/ |
118 |
|
|
int ff_ccfifo_injectbytes(CCFifo *ccf, uint8_t *data, size_t len); |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Returns 1 if captions have been found as a prior call |
122 |
|
|
* to ff_ccfifo_extract() or ff_ccfifo_extractbytes() |
123 |
|
|
*/ |
124 |
|
|
static inline int ff_ccfifo_ccdetected(const CCFifo *ccf) |
125 |
|
|
{ |
126 |
|
|
return ccf->cc_detected; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
#endif /* AVFILTER_CCFIFO_H */ |
130 |
|
|
|