20 #include <va/va_enc_jpeg.h>
41 16, 11, 12, 14, 12, 10, 16, 14,
42 13, 14, 18, 17, 16, 19, 24, 40,
43 26, 24, 22, 22, 24, 49, 35, 37,
44 29, 40, 58, 51, 61, 60, 57, 51,
45 56, 55, 64, 72, 92, 78, 64, 68,
46 87, 69, 55, 56, 80, 109, 81, 87,
47 95, 98, 103, 104, 103, 62, 77, 113,
48 121, 112, 100, 120, 92, 101, 103, 99,
51 17, 18, 18, 24, 21, 24, 47, 26,
52 26, 47, 99, 66, 56, 66, 99, 99,
53 99, 99, 99, 99, 99, 99, 99, 99,
54 99, 99, 99, 99, 99, 99, 99, 99,
55 99, 99, 99, 99, 99, 99, 99, 99,
56 99, 99, 99, 99, 99, 99, 99, 99,
57 99, 99, 99, 99, 99, 99, 99, 99,
58 99, 99, 99, 99, 99, 99, 99, 99,
86 char *
data,
size_t *data_len)
132 if (*data_len < 8 * frag->data_size) {
134 "%zu < %zu.\n", *data_len, 8 * frag->
data_size);
152 char *
data,
size_t *data_len)
161 VAQMatrixBufferJPEG *
quant;
163 if (*data_len <
sizeof(*
quant))
165 *
type = VAQMatrixBufferType;
166 *data_len =
sizeof(*quant);
171 quant->load_lum_quantiser_matrix = 1;
172 for (
i = 0;
i < 64;
i++)
173 quant->lum_quantiser_matrix[
i] =
dqt->table[fh->
Tq[0]].Q[
i];
176 quant->load_chroma_quantiser_matrix = 1;
177 for (
i = 0;
i < 64;
i++)
178 quant->chroma_quantiser_matrix[
i] =
179 dqt->table[fh->
Tq[1]].Q[
i];
182 }
else if (
index == 1) {
186 VAHuffmanTableBufferJPEGBaseline *huff;
188 if (*data_len <
sizeof(*huff))
190 *
type = VAHuffmanTableBufferType;
191 *data_len =
sizeof(*huff);
193 huff = (VAHuffmanTableBufferJPEGBaseline*)
data;
194 memset(huff, 0,
sizeof(*huff));
196 for (t = 0; t < 1 + (sh->
Ns > 1); t++) {
199 huff->load_huffman_table[t] = 1;
201 ht = &
dht->table[2 * t];
202 for (
i = k = 0;
i < 16;
i++)
203 k += (huff->huffman_table[t].num_dc_codes[
i] = ht->
L[
i]);
204 av_assert0(k <=
sizeof(huff->huffman_table[t].dc_values));
205 for (
i = 0;
i < k;
i++)
206 huff->huffman_table[t].dc_values[
i] = ht->
V[
i];
208 ht = &
dht->table[2 * t + 1];
209 for (
i = k = 0;
i < 16;
i++)
210 k += (huff->huffman_table[t].num_ac_codes[
i] = ht->
L[
i]);
211 av_assert0(k <=
sizeof(huff->huffman_table[t].ac_values));
212 for (
i = 0;
i < k;
i++)
213 huff->huffman_table[t].ac_values[
i] = ht->
V[
i];
232 const uint8_t components_rgb[3] = {
'R',
'G',
'B' };
233 const uint8_t components_yuv[3] = { 1, 2, 3 };
234 const uint8_t *components;
235 int t,
i, quant_scale,
len;
242 components = components_rgb;
244 components = components_yuv;
251 fh->
Nf =
desc->nb_components;
253 for (
i = 0;
i < fh->
Nf;
i++) {
254 fh->
C[
i] = components[
i];
255 fh->
H[
i] = 1 + (
i == 0 ?
desc->log2_chroma_w : 0);
256 fh->
V[
i] = 1 + (
i == 0 ?
desc->log2_chroma_h : 0);
261 fh->
Lf = 8 + 3 * fh->
Nf;
274 bytestream2_put_be16(&pbc, 0x0102);
275 bytestream2_put_byte(&pbc, 0);
278 if (sar_w && sar_h) {
279 bytestream2_put_be16(&pbc, sar_w);
280 bytestream2_put_be16(&pbc, sar_h);
282 bytestream2_put_be16(&pbc, 1);
283 bytestream2_put_be16(&pbc, 1);
286 bytestream2_put_byte(&pbc, 0);
287 bytestream2_put_byte(&pbc, 0);
299 quant_scale = 5000 / priv->
quality;
301 quant_scale = 200 - 2 * priv->
quality;
305 for (t = 0; t < 1 + (fh->
Nf > 1); t++) {
307 const uint8_t *
data = t == 0 ?
313 for (
i = 0;
i < 64;
i++)
325 for (t = 0; t < 2 + 2 * (fh->
Nf > 1); t++) {
327 const uint8_t *lengths, *
values;
352 for (
i = k = 0;
i < 16;
i++)
353 k += (huff->
L[
i] = lengths[
i]);
355 for (
i = 0;
i < k;
i++)
367 for (
i = 0;
i < fh->
Nf;
i++) {
368 sh->
Cs[
i] = fh->
C[
i];
378 sh->
Ls = 6 + 2 * sh->
Ns;
381 *vpic = (VAEncPictureParameterBufferJPEG) {
385 .picture_width = fh->
X,
386 .picture_height = fh->
Y,
396 .sample_bit_depth = fh->
P,
398 .num_components = fh->
Nf,
406 for (
i = 0;
i < fh->
Nf;
i++) {
407 vpic->component_id[
i] = fh->
C[
i];
408 vpic->quantiser_table_selector[
i] = fh->
Tq[
i];
425 *vslice = (VAEncSliceParameterBufferJPEG) {
426 .restart_interval = 0,
427 .num_components = sh->
Ns,
430 for (
i = 0;
i < sh->
Ns;
i++) {
431 vslice->components[
i].component_selector = sh->
Cs[
i];
432 vslice->components[
i].dc_table_selector = sh->
Td[
i];
433 vslice->components[
i].ac_table_selector = sh->
Ta[
i];
462 "(must be 1-100).\n", priv->
quality);
472 if (
ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) {
473 ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA;
474 ctx->va_packed_headers |= VA_ENC_PACKED_HEADER_SLICE;
486 8, 1, 0, 0, VAProfileJPEGBaseline },
488 8, 3, 1, 1, VAProfileJPEGBaseline },
490 8, 3, 1, 0, VAProfileJPEGBaseline },
492 8, 3, 0, 0, VAProfileJPEGBaseline },
505 .default_quality = 80,
507 .picture_params_size =
sizeof(VAEncPictureParameterBufferJPEG),
510 .slice_params_size =
sizeof(VAEncSliceParameterBufferJPEG),
513 .slice_header_type = VAEncPackedHeaderRawData,
526 ctx->desired_packed_headers =
527 VA_ENC_PACKED_HEADER_RAW_DATA;
542 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
543 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
548 {
"jfif",
"Include JFIF header",
550 { .i64 = 0 }, 0, 1,
FLAGS },
551 {
"huffman",
"Include huffman tables",
553 { .i64 = 1 }, 0, 1,
FLAGS },
571 .
p.
name =
"mjpeg_vaapi",
591 .p.wrapper_name =
"vaapi",