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];
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;
251 for (i = 0; i < fh->
Nf; i++) {
252 fh->
C[
i] = components[
i];
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++)
354 huff->
V[i] = values[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);
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,
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",
564 .priv_class = &vaapi_encode_mjpeg_class,
567 .
defaults = vaapi_encode_mjpeg_defaults,
573 .wrapper_name =
"vaapi",
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
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 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.
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
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 int bytestream2_get_bytes_left_p(PutByteContext *p)
#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.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
#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)
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
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).
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
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[]
#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
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
const uint8_t avpriv_mjpeg_val_ac_luminance[]
void * codec_slice_params
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
unsigned int desired_packed_headers
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
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
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]