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);
168 quant = (VAQMatrixBufferJPEG*)data;
169 memset(quant, 0,
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] =
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];
231 int t, i, quant_scale,
len;
236 components = (
uint8_t[3]) {
'R',
'G',
'B' };
238 components = (
uint8_t[3]) { 1, 2, 3 };
247 for (i = 0; i < fh->
Nf; i++) {
248 fh->
C[i] = components[i];
255 fh->
Lf = 8 + 3 * fh->
Nf;
268 bytestream2_put_be16(&pbc, 0x0102);
269 bytestream2_put_byte(&pbc, 0);
272 if (sar_w && sar_h) {
273 bytestream2_put_be16(&pbc, sar_w);
274 bytestream2_put_be16(&pbc, sar_h);
276 bytestream2_put_be16(&pbc, 1);
277 bytestream2_put_be16(&pbc, 1);
280 bytestream2_put_byte(&pbc, 0);
281 bytestream2_put_byte(&pbc, 0);
293 quant_scale = 5000 / priv->
quality;
295 quant_scale = 200 - 2 * priv->
quality;
299 for (t = 0; t < 1 + (fh->
Nf > 1); t++) {
307 for (i = 0; i < 64; i++)
308 quant->
Q[i] = av_clip(data[i] * quant_scale / 100, 1, 255);
319 for (t = 0; t < 2 + 2 * (fh->
Nf > 1); t++) {
321 const uint8_t *lengths, *values;
346 for (i = k = 0; i < 16; i++)
347 k += (huff->
L[i] = lengths[i]);
349 for (i = 0; i < k; i++)
350 huff->
V[i] = values[i];
361 for (i = 0; i < fh->
Nf; i++) {
362 sh->
Cs[i] = fh->
C[i];
372 sh->
Ls = 6 + 2 * sh->
Ns;
375 *vpic = (VAEncPictureParameterBufferJPEG) {
379 .picture_width = fh->
X,
380 .picture_height = fh->
Y,
390 .sample_bit_depth = fh->
P,
392 .num_components = fh->
Nf,
400 for (i = 0; i < fh->
Nf; i++) {
401 vpic->component_id[i] = fh->
C[i];
402 vpic->quantiser_table_selector[i] = fh->
Tq[i];
419 *vslice = (VAEncSliceParameterBufferJPEG) {
420 .restart_interval = 0,
421 .num_components = sh->
Ns,
424 for (i = 0; i < sh->
Ns; i++) {
425 vslice->components[i].component_selector = sh->
Cs[i];
426 vslice->components[i].dc_table_selector = sh->
Td[i];
427 vslice->components[i].ac_table_selector = sh->
Ta[i];
442 "(must be 1-100).\n", priv->
quality);
466 8, 1, 0, 0, VAProfileJPEGBaseline },
468 8, 3, 1, 1, VAProfileJPEGBaseline },
470 8, 3, 1, 0, VAProfileJPEGBaseline },
472 8, 3, 0, 0, VAProfileJPEGBaseline },
483 .picture_params_size =
sizeof(VAEncPictureParameterBufferJPEG),
486 .slice_params_size =
sizeof(VAEncSliceParameterBufferJPEG),
489 .slice_header_type = VAEncPackedHeaderRawData,
503 VA_ENC_PACKED_HEADER_RAW_DATA;
520 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
521 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
525 {
"jfif",
"Include JFIF header",
527 { .i64 = 0 }, 0, 1,
FLAGS },
528 {
"huffman",
"Include huffman tables",
530 { .i64 = 1 }, 0, 1,
FLAGS },
536 {
"global_quality",
"80" },
550 .
name =
"mjpeg_vaapi",
558 .priv_class = &vaapi_encode_mjpeg_class,
561 .
defaults = vaapi_encode_mjpeg_defaults,
566 .wrapper_name =
"vaapi",
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
ptrdiff_t const GLvoid * data
static int FUNC() dqt(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawQuantisationTableSpecification *current)
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
const char * av_default_item_name(void *ptr)
Return the context name.
CodedBitstreamFragment current_fragment
JPEGRawApplicationData jfif_header
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
JPEGRawQuantisationTableSpecification quant_tables
MJPEG encoder and decoder.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64]
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
#define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT
unsigned int va_packed_headers
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
VAAPIEncodeContext common
#define AVERROR_EOF
End of file.
static int FUNC() dht(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawHuffmanTableSpecification *current)
VASurfaceID recon_surface
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
size_t data_size
The number of bytes in the bitstream.
AVHWFramesContext * input_frames
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
CodedBitstreamContext * cbc
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
static const AVCodecDefault defaults[]
void * codec_picture_params
static const unsigned char vaapi_encode_mjpeg_quant_luminance[64]
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
AVCodec ff_mjpeg_vaapi_encoder
uint8_t nb_components
The number of components each pixel has, (1-4)
static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
int width
picture width / height.
#define FF_PROFILE_UNKNOWN
const VAAPIEncodeProfile * profiles
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
JPEGRawHuffmanTableSpecification huffman_tables
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
uint8_t * data
Pointer to the bitstream form of this fragment.
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
static const AVCodecDefault vaapi_encode_mjpeg_defaults[]
static const AVClass vaapi_encode_mjpeg_class
static const VAAPIEncodeProfile vaapi_encode_mjpeg_profiles[]
const struct VAAPIEncodeType * codec
Libavcodec external API header.
JPEGRawQuantisationTable table[4]
Coded bitstream fragment structure, combining one or more units.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
const uint8_t avpriv_mjpeg_val_dc[12]
static const AVOption vaapi_encode_mjpeg_options[]
static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx)
Describe the class of an AVClass context structure.
Context structure for coded bitstream operations.
Rational number (pair of numerator and denominator).
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
static enum AVPixelFormat pix_fmts[]
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
int global_quality
Global quality for codecs which cannot change it per frame.
#define VAAPI_ENCODE_COMMON_OPTIONS
JPEGRawFrameHeader frame_header
static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
common internal api header.
common internal and external API header
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
void * codec_slice_params
unsigned int desired_packed_headers
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
JPEGRawHuffmanTable table[8]
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
static const VAAPIEncodeType vaapi_encode_type_mjpeg