FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
60 fail:
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 
141 fail:
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 };
ff_vaapi_get_surface_id
static VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
Definition: vaapi_decode.h:30
VAAPIDecodeContext
Definition: vaapi_decode.h:47
vaapi_decode.h
av_unused
#define av_unused
Definition: attributes.h:131
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
mjpegdec.h
VAAPIDecodePicture
Definition: vaapi_decode.h:35
ff_vaapi_decode_make_param_buffer
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, int type, const void *data, size_t size)
Definition: vaapi_decode.c:34
FFHWAccel
Definition: hwaccel_internal.h:34
fail
#define fail()
Definition: checkasm.h:193
VAAPIDecodePicture::output_surface
VASurfaceID output_surface
Definition: vaapi_decode.h:36
quant
static const uint8_t quant[64]
Definition: vmixdec.c:71
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_vaapi_decode_init
int ff_vaapi_decode_init(AVCodecContext *avctx)
Definition: vaapi_decode.c:692
ff_vaapi_common_frame_params
int ff_vaapi_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vaapi_decode.c:668
ff_vaapi_decode_uninit
int ff_vaapi_decode_uninit(AVCodecContext *avctx)
Definition: vaapi_decode.c:738
ff_vaapi_decode_issue
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:166
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
hwaccel_internal.h
MJpegDecodeContext
Definition: mjpegdec.h:54
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
size
int size
Definition: twinvq_data.h:10344
ff_vaapi_decode_cancel
int ff_vaapi_decode_cancel(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:247
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2124
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
vaapi_mjpeg_end_frame
static int vaapi_mjpeg_end_frame(AVCodecContext *avctx)
Definition: vaapi_mjpeg.c:65
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
vaapi_mjpeg_decode_slice
static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vaapi_mjpeg.c:73
vaapi_mjpeg_start_frame
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
AVCodecContext::height
int height
Definition: avcodec.h:632
AVCodecContext
main external API structure.
Definition: avcodec.h:451
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
ff_vaapi_decode_make_slice_buffer
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)
Definition: vaapi_decode.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_mjpeg_vaapi_hwaccel
const FFHWAccel ff_mjpeg_vaapi_hwaccel
Definition: vaapi_mjpeg.c:146
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:632