FFmpeg
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.h"
23 #include "vaapi_decode.h"
24 #include "mjpegdec.h"
25 
27  av_unused const uint8_t *buffer,
28  av_unused uint32_t size)
29 {
30  const MJpegDecodeContext *s = avctx->priv_data;
32  VAPictureParameterBufferJPEGBaseline pp;
33  int err, i;
34 
36 
37  pp = (VAPictureParameterBufferJPEGBaseline) {
38  .picture_width = avctx->width,
39  .picture_height = avctx->height,
40 
41  .num_components = s->nb_components,
42  };
43 
44  for (i = 0; i < s->nb_components; i++) {
45  pp.components[i].component_id = s->component_id[i];
46  pp.components[i].h_sampling_factor = s->h_count[i];
47  pp.components[i].v_sampling_factor = s->v_count[i];
48  pp.components[i].quantiser_table_selector = s->quant_index[i];
49  }
50 
51  err = ff_vaapi_decode_make_param_buffer(avctx, pic,
52  VAPictureParameterBufferType,
53  &pp, sizeof(pp));
54  if (err < 0)
55  goto fail;
56 
57  return 0;
58 
59 fail:
60  ff_vaapi_decode_cancel(avctx, pic);
61  return err;
62 }
63 
65 {
66  const MJpegDecodeContext *s = avctx->priv_data;
68 
69  return ff_vaapi_decode_issue(avctx, pic);
70 }
71 
73  const uint8_t *buffer,
74  uint32_t size)
75 {
76  const MJpegDecodeContext *s = avctx->priv_data;
78  VAHuffmanTableBufferJPEGBaseline huff;
79  VAIQMatrixBufferJPEGBaseline quant;
80  VASliceParameterBufferJPEGBaseline sp;
81  int err, i, j;
82 
83  memset(&huff, 0, sizeof(huff));
84  for (i = 0; i < 2; i++) {
85  huff.load_huffman_table[i] = 1;
86  for (j = 0; j < 16; j++)
87  huff.huffman_table[i].num_dc_codes[j] = s->raw_huffman_lengths[0][i][j];
88  for (j = 0; j < 12; j++)
89  huff.huffman_table[i].dc_values[j] = s->raw_huffman_values[0][i][j];
90  for (j = 0; j < 16; j++)
91  huff.huffman_table[i].num_ac_codes[j] = s->raw_huffman_lengths[1][i][j];
92  for (j = 0; j < 162; j++)
93  huff.huffman_table[i].ac_values[j] = s->raw_huffman_values[1][i][j];
94  }
95 
96  err = ff_vaapi_decode_make_param_buffer(avctx, pic,
97  VAHuffmanTableBufferType,
98  &huff, sizeof(huff));
99  if (err < 0)
100  goto fail;
101 
102  memset(&quant, 0, sizeof(quant));
103  for (i = 0; i < 4; i++) {
104  quant.load_quantiser_table[i] = 1;
105  for (j = 0; j < 64; j++)
106  quant.quantiser_table[i][j] = s->quant_matrixes[i][j];
107  }
108 
109  err = ff_vaapi_decode_make_param_buffer(avctx, pic,
110  VAIQMatrixBufferType,
111  &quant, sizeof(quant));
112  if (err < 0)
113  goto fail;
114 
115  sp = (VASliceParameterBufferJPEGBaseline) {
116  .slice_data_size = size,
117  .slice_data_offset = 0,
118  .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
119 
120  .slice_horizontal_position = 0,
121  .slice_vertical_position = 0,
122 
123  .restart_interval = s->restart_interval,
124  .num_mcus = s->mb_width * s->mb_height,
125  };
126 
127  sp.num_components = s->nb_components;
128  for (i = 0; i < s->nb_components; i++) {
129  sp.components[i].component_selector = s->component_id[s->comp_index[i]];
130  sp.components[i].dc_table_selector = s->dc_index[i];
131  sp.components[i].ac_table_selector = s->ac_index[i];
132  }
133 
134  err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), buffer, size);
135  if (err)
136  goto fail;
137 
138  return 0;
139 
140 fail:
141  ff_vaapi_decode_cancel(avctx, pic);
142  return err;
143 }
144 
146  .name = "mjpeg_vaapi",
147  .type = AVMEDIA_TYPE_VIDEO,
148  .id = AV_CODEC_ID_MJPEG,
149  .pix_fmt = AV_PIX_FMT_VAAPI,
150  .start_frame = &vaapi_mjpeg_start_frame,
151  .end_frame = &vaapi_mjpeg_end_frame,
152  .decode_slice = &vaapi_mjpeg_decode_slice,
153  .frame_priv_data_size = sizeof(VAAPIDecodePicture),
156  .frame_params = &ff_vaapi_common_frame_params,
157  .priv_data_size = sizeof(VAAPIDecodeContext),
158  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
159 };
int v_count[MAX_COMPONENTS]
Definition: mjpegdec.h:88
static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vaapi_mjpeg.c:72
static int vaapi_mjpeg_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vaapi_mjpeg.c:26
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, int type, const void *data, size_t size)
Definition: vaapi_decode.c:29
static VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
Definition: vaapi_decode.h:35
int dc_index[MAX_COMPONENTS]
Definition: mjpegdec.h:90
int comp_index[MAX_COMPONENTS]
Definition: mjpegdec.h:89
int ff_vaapi_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vaapi_decode.c:586
int ff_vaapi_decode_uninit(AVCodecContext *avctx)
Definition: vaapi_decode.c:699
uint8_t
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:150
AVFrame * picture_ptr
Definition: mjpegdec.h:100
int h_count[MAX_COMPONENTS]
Definition: mjpegdec.h:87
#define sp
Definition: regdef.h:63
ptrdiff_t size
Definition: opengl_enc.c:100
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#define fail()
Definition: checkasm.h:120
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3655
int ff_vaapi_decode_init(AVCodecContext *avctx)
Definition: vaapi_decode.c:610
int component_id[MAX_COMPONENTS]
Definition: mjpegdec.h:86
int width
picture width / height.
Definition: avcodec.h:1738
uint8_t raw_huffman_lengths[2][4][16]
Definition: mjpegdec.h:148
#define s(width, name)
Definition: cbs_vp9.c:257
int quant_index[4]
Definition: mjpegdec.h:97
VASurfaceID output_surface
Definition: vaapi_decode.h:45
main external API structure.
Definition: avcodec.h:1565
const AVHWAccel ff_mjpeg_vaapi_hwaccel
Definition: vaapi_mjpeg.c:145
int ac_index[MAX_COMPONENTS]
Definition: mjpegdec.h:91
int ff_vaapi_decode_cancel(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:224
uint8_t raw_huffman_values[2][4][256]
Definition: mjpegdec.h:149
const uint8_t * quant
static int vaapi_mjpeg_end_frame(AVCodecContext *avctx)
Definition: vaapi_mjpeg.c:64
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwaccel.h:26
void * priv_data
Definition: avcodec.h:1592
void * hwaccel_picture_private
Definition: mjpegdec.h:153
MJPEG decoder.
uint16_t quant_matrixes[4][64]
Definition: mjpegdec.h:56
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, size_t params_size, const void *slice_data, size_t slice_size)
Definition: vaapi_decode.c:58
for(j=16;j >0;--j)
GLuint buffer
Definition: opengl_enc.c:101
#define av_unused
Definition: attributes.h:125