FFmpeg
Loading...
Searching...
No Matches
vaapi_mjpeg.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <va/va.h>
20#include <va/va_dec_jpeg.h>
21
22#include "hwaccel_internal.h"
23#include "vaapi_decode.h"
24#include "mjpegdec.h"
25
27 av_unused const AVBufferRef *buffer_ref,
28 av_unused const uint8_t *buffer,
29 av_unused uint32_t size)
30{
31 const MJpegDecodeContext *s = avctx->priv_data;
32 VAAPIDecodePicture *pic = s->hwaccel_picture_private;
33 VAPictureParameterBufferJPEGBaseline pp;
34 int err, i;
35
36 pic->output_surface = ff_vaapi_get_surface_id(s->picture_ptr);
37
38 pp = (VAPictureParameterBufferJPEGBaseline) {
39 .picture_width = avctx->width,
40 .picture_height = avctx->height,
41
42 .num_components = s->nb_components,
43 };
44
45 for (i = 0; i < s->nb_components; i++) {
46 pp.components[i].component_id = s->component_id[i];
47 pp.components[i].h_sampling_factor = s->h_count[i];
48 pp.components[i].v_sampling_factor = s->v_count[i];
49 pp.components[i].quantiser_table_selector = s->quant_index[i];
50 }
51
52 err = ff_vaapi_decode_make_param_buffer(avctx, pic,
53 VAPictureParameterBufferType,
54 &pp, sizeof(pp));
55 if (err < 0)
56 goto fail;
57
58 return 0;
59
60fail:
61 ff_vaapi_decode_cancel(avctx, pic);
62 return err;
63}
64
66{
67 const MJpegDecodeContext *s = avctx->priv_data;
68 VAAPIDecodePicture *pic = s->hwaccel_picture_private;
69
70 return ff_vaapi_decode_issue(avctx, pic);
71}
72
74 const uint8_t *buffer,
75 uint32_t size)
76{
77 const MJpegDecodeContext *s = avctx->priv_data;
78 VAAPIDecodePicture *pic = s->hwaccel_picture_private;
79 VAHuffmanTableBufferJPEGBaseline huff;
80 VAIQMatrixBufferJPEGBaseline quant;
81 VASliceParameterBufferJPEGBaseline sp;
82 int err, i, j;
83
84 memset(&huff, 0, sizeof(huff));
85 for (i = 0; i < 2; i++) {
86 huff.load_huffman_table[i] = 1;
87 for (j = 0; j < 16; j++)
88 huff.huffman_table[i].num_dc_codes[j] = s->raw_huffman_lengths[0][i][j];
89 for (j = 0; j < 12; j++)
90 huff.huffman_table[i].dc_values[j] = s->raw_huffman_values[0][i][j];
91 for (j = 0; j < 16; j++)
92 huff.huffman_table[i].num_ac_codes[j] = s->raw_huffman_lengths[1][i][j];
93 for (j = 0; j < 162; j++)
94 huff.huffman_table[i].ac_values[j] = s->raw_huffman_values[1][i][j];
95 }
96
97 err = ff_vaapi_decode_make_param_buffer(avctx, pic,
98 VAHuffmanTableBufferType,
99 &huff, sizeof(huff));
100 if (err < 0)
101 goto fail;
102
103 memset(&quant, 0, sizeof(quant));
104 for (i = 0; i < 4; i++) {
105 quant.load_quantiser_table[i] = 1;
106 for (j = 0; j < 64; j++)
107 quant.quantiser_table[i][j] = s->quant_matrixes[i][j];
108 }
109
110 err = ff_vaapi_decode_make_param_buffer(avctx, pic,
111 VAIQMatrixBufferType,
112 &quant, sizeof(quant));
113 if (err < 0)
114 goto fail;
115
116 sp = (VASliceParameterBufferJPEGBaseline) {
117 .slice_data_size = size,
118 .slice_data_offset = 0,
119 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
120
121 .slice_horizontal_position = 0,
122 .slice_vertical_position = 0,
123
124 .restart_interval = s->restart_interval,
125 .num_mcus = s->mb_width * s->mb_height,
126 };
127
128 sp.num_components = s->nb_components;
129 for (i = 0; i < s->nb_components; i++) {
130 sp.components[i].component_selector = s->component_id[s->comp_index[i]];
131 sp.components[i].dc_table_selector = s->dc_index[i];
132 sp.components[i].ac_table_selector = s->ac_index[i];
133 }
134
135 err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), buffer, size);
136 if (err)
137 goto fail;
138
139 return 0;
140
141fail:
142 ff_vaapi_decode_cancel(avctx, pic);
143 return err;
144}
145
147 .p.name = "mjpeg_vaapi",
148 .p.type = AVMEDIA_TYPE_VIDEO,
149 .p.id = AV_CODEC_ID_MJPEG,
150 .p.pix_fmt = AV_PIX_FMT_VAAPI,
151 .start_frame = &vaapi_mjpeg_start_frame,
152 .end_frame = &vaapi_mjpeg_end_frame,
153 .decode_slice = &vaapi_mjpeg_decode_slice,
154 .frame_priv_data_size = sizeof(VAAPIDecodePicture),
157 .frame_params = &ff_vaapi_common_frame_params,
158 .priv_data_size = sizeof(VAAPIDecodeContext),
159 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
160};
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define fail
Definition test.h:479
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
const struct FFHWAccel ff_mjpeg_vaapi_hwaccel
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define av_unused
Definition attributes.h:164
MJPEG decoder.
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition pixfmt.h:126
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
void * priv_data
Definition avcodec.h:470
VASurfaceID output_surface
static char buffer[20]
Definition seek.c:32
int size
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, int type, const void *data, size_t size)
int ff_vaapi_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
int ff_vaapi_decode_init(AVCodecContext *avctx)
int ff_vaapi_decode_uninit(AVCodecContext *avctx)
int ff_vaapi_decode_cancel(AVCodecContext *avctx, VAAPIDecodePicture *pic)
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, int nb_params, size_t params_size, const void *slice_data, size_t slice_size)
static VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition vaapi_mjpeg.c:73
static int vaapi_mjpeg_start_frame(AVCodecContext *avctx, av_unused const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition vaapi_mjpeg.c:26
static int vaapi_mjpeg_end_frame(AVCodecContext *avctx)
Definition vaapi_mjpeg.c:65
static const uint8_t quant[64]
Definition vmixdec.c:71