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];
230 const uint8_t components_rgb[3] = {
'R',
'G',
'B' };
231 const uint8_t components_yuv[3] = { 1, 2, 3 };
233 int t,
i, quant_scale,
len;
240 components = components_rgb;
242 components = components_yuv;
249 fh->
Nf =
desc->nb_components;
251 for (
i = 0;
i < fh->
Nf;
i++) {
252 fh->
C[
i] = components[
i];
253 fh->
H[
i] = 1 + (
i == 0 ?
desc->log2_chroma_w : 0);
254 fh->
V[
i] = 1 + (
i == 0 ?
desc->log2_chroma_h : 0);
259 fh->
Lf = 8 + 3 * fh->
Nf;
272 bytestream2_put_be16(&pbc, 0x0102);
273 bytestream2_put_byte(&pbc, 0);
276 if (sar_w && sar_h) {
277 bytestream2_put_be16(&pbc, sar_w);
278 bytestream2_put_be16(&pbc, sar_h);
280 bytestream2_put_be16(&pbc, 1);
281 bytestream2_put_be16(&pbc, 1);
284 bytestream2_put_byte(&pbc, 0);
285 bytestream2_put_byte(&pbc, 0);
297 quant_scale = 5000 / priv->
quality;
299 quant_scale = 200 - 2 * priv->
quality;
303 for (t = 0; t < 1 + (fh->
Nf > 1); t++) {
311 for (
i = 0;
i < 64;
i++)
312 quant->Q[
i] = av_clip(
data[
i] * quant_scale / 100, 1, 255);
323 for (t = 0; t < 2 + 2 * (fh->
Nf > 1); t++) {
350 for (
i = k = 0;
i < 16;
i++)
351 k += (huff->
L[
i] = lengths[
i]);
353 for (
i = 0;
i < k;
i++)
365 for (
i = 0;
i < fh->
Nf;
i++) {
366 sh->
Cs[
i] = fh->
C[
i];
376 sh->
Ls = 6 + 2 * sh->
Ns;
379 *vpic = (VAEncPictureParameterBufferJPEG) {
383 .picture_width = fh->
X,
384 .picture_height = fh->
Y,
394 .sample_bit_depth = fh->
P,
396 .num_components = fh->
Nf,
404 for (
i = 0;
i < fh->
Nf;
i++) {
405 vpic->component_id[
i] = fh->
C[
i];
406 vpic->quantiser_table_selector[
i] = fh->
Tq[
i];
423 *vslice = (VAEncSliceParameterBufferJPEG) {
424 .restart_interval = 0,
425 .num_components = sh->
Ns,
428 for (
i = 0;
i < sh->
Ns;
i++) {
429 vslice->components[
i].component_selector = sh->
Cs[
i];
430 vslice->components[
i].dc_table_selector = sh->
Td[
i];
431 vslice->components[
i].ac_table_selector = sh->
Ta[
i];
446 "(must be 1-100).\n", priv->
quality);
456 if (
ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) {
457 ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA;
458 ctx->va_packed_headers |= VA_ENC_PACKED_HEADER_SLICE;
470 8, 1, 0, 0, VAProfileJPEGBaseline },
472 8, 3, 1, 1, VAProfileJPEGBaseline },
474 8, 3, 1, 0, VAProfileJPEGBaseline },
476 8, 3, 0, 0, VAProfileJPEGBaseline },
488 .default_quality = 80,
490 .picture_params_size =
sizeof(VAEncPictureParameterBufferJPEG),
493 .slice_params_size =
sizeof(VAEncSliceParameterBufferJPEG),
496 .slice_header_type = VAEncPackedHeaderRawData,
509 ctx->desired_packed_headers =
510 VA_ENC_PACKED_HEADER_RAW_DATA;
528 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
529 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
533 {
"jfif",
"Include JFIF header",
535 { .i64 = 0 }, 0, 1,
FLAGS },
536 {
"huffman",
"Include huffman tables",
538 { .i64 = 1 }, 0, 1,
FLAGS },
556 .
name =
"mjpeg_vaapi",
573 .wrapper_name =
"vaapi",