| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 26 | ✗ | static int vaapi_mjpeg_start_frame(AVCodecContext *avctx, | |
| 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 | |||
| 65 | ✗ | static int vaapi_mjpeg_end_frame(AVCodecContext *avctx) | |
| 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 | |||
| 73 | ✗ | static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx, | |
| 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 | |||
| 146 | const FFHWAccel ff_mjpeg_vaapi_hwaccel = { | ||
| 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), | ||
| 155 | .init = &ff_vaapi_decode_init, | ||
| 156 | .uninit = &ff_vaapi_decode_uninit, | ||
| 157 | .frame_params = &ff_vaapi_common_frame_params, | ||
| 158 | .priv_data_size = sizeof(VAAPIDecodeContext), | ||
| 159 | .caps_internal = HWACCEL_CAP_ASYNC_SAFE, | ||
| 160 | }; | ||
| 161 |