1 /*
2 * Copyright (c) 2012 Derek Buitenhuis
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation;
9 * version 2 of the License.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Known FOURCCs:
24 * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA),
25 * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
26 */
27
28 extern "C" {
32 }
33
36
38 {
41 uint32_t
flags, in_format;
43
46 in_format = UTVF_YV12;
50 else
52 break;
54 in_format = UTVF_YUYV;
58 else
60 break;
65 break;
70 break;
71 default:
73 }
74
75 /* Check before we alloc anything */
79 }
80
82
85
86 /* Alloc extradata buffer */
88
89 if (!info) {
92 }
93
94 /*
95 * We use this buffer to hold the data that Ut Video returns,
96 * since we cannot decode planes separately with it.
97 */
102 }
104
106
111 }
112
113 /*
114 * Create a Ut Video instance. Since the function wants
115 * an "interface name" string, pass it the name of the lib.
116 */
117 utv->
codec = CCodec::CreateInstance(UNFCC(avctx->
codec_tag),
"libavcodec");
118
119 /* Initialize encoder */
121 CBGROSSWIDTH_WINDOWS);
122
123 /* Get extradata from encoder */
127 CBGROSSWIDTH_WINDOWS);
129
130 /* Set flags */
131 utv->
codec->SetState(&flags,
sizeof(flags));
132
133 return 0;
134 }
135
137 const AVFrame *pic,
int *got_packet)
138 {
141 int ret, rgb_size, i;
142 bool keyframe;
145
146 /* Alloc buffer */
148 return ret;
149
151
152 /* Move input if needed data into Ut Video friendly buffer */
158 for (i = 0; i <
h; i++) {
160 y += w;
161 }
162 for (i = 0; i < h / 2; i++) {
167 }
168 break;
170 for (i = 0; i <
h; i++)
171 memcpy(utv->
buffer + i * (w << 1),
173 break;
176 /* Ut Video takes bottom-up BGR */
178 for (i = 0; i <
h; i++)
179 memcpy(utv->
buffer + (h - i - 1) * w * rgb_size,
181 w * rgb_size);
182 break;
183 default:
185 }
186
187 /* Encode frame */
189
193 }
194
195 /*
196 * Ut Video is intra-only and every frame is a keyframe,
197 * and the API always returns true. In case something
198 * durastic changes in the future, such as inter support,
199 * assert that this is true.
200 */
204
206 *got_packet = 1;
207 return 0;
208 }
209
211 {
213
217
218 utv->
codec->EncodeEnd();
219 CCodec::DeleteInstance(utv->
codec);
220
221 return 0;
222 }
223
225 "libutvideo",
230 NULL,
/* supported_framerates */
234 },
235 NULL,
/* supported_samplerates */
236 NULL,
/* sample_fmts */
237 NULL,
/* channel_layouts */
238 0, /* max_lowres */
239 NULL,
/* priv_class */
242 NULL, /* next */
243 NULL, /* init_thread_copy */
244 NULL, /* update_thread_context */
245 NULL, /* defaults */
246 NULL, /* init_static_data */
248 NULL, /* encode */
250 NULL, /* decode */
252 NULL, /* flush */
253 };
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
AVFrame * coded_frame
the picture in the bitstream
#define CODEC_CAP_LOSSLESS
Codec is lossless.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_cold int utvideo_encode_init(AVCodecContext *avctx)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
simple assert() macros that are a bit more flexible than ISO C assert().
Libavcodec external API header.
int flags
A combination of AV_PKT_FLAG values.
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Known FOURCCs: 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA), 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
packed RGB 8:8:8, 24bpp, BGRBGR...
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
enum AVColorSpace colorspace
YUV colorspace type.
static av_cold int utvideo_encode_close(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
int prediction_method
prediction method (needed for huffyuv)
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
int key_frame
1 -> keyframe, 0-> not
#define MKTAG(a, b, c, d)
AVPixelFormat
Pixel format.
This structure stores compressed data.
AVCodec ff_libutvideo_encoder
#define UTVF_NFCC_BGRA_BU