| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2016-05-08 22:46:52 +01:00
										 |  |  |  * This file is part of FFmpeg. | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-05-08 22:46:52 +01:00
										 |  |  |  * FFmpeg is free software; you can redistribute it and/or | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-05-08 22:46:52 +01:00
										 |  |  |  * FFmpeg is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							| 
									
										
										
										
											2016-05-08 22:46:52 +01:00
										 |  |  |  * License along with FFmpeg; if not, write to the Free Software | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <va/va.h>
 | 
					
						
							|  |  |  | #include <va/va_enc_jpeg.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "libavutil/avassert.h"
 | 
					
						
							|  |  |  | #include "libavutil/common.h"
 | 
					
						
							|  |  |  | #include "libavutil/internal.h"
 | 
					
						
							|  |  |  | #include "libavutil/opt.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  | #include "libavutil/pixdesc.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "avcodec.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  | #include "bytestream.h"
 | 
					
						
							|  |  |  | #include "cbs.h"
 | 
					
						
							|  |  |  | #include "cbs_jpeg.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | #include "internal.h"
 | 
					
						
							|  |  |  | #include "jpegtables.h"
 | 
					
						
							|  |  |  | #include "mjpeg.h"
 | 
					
						
							|  |  |  | #include "put_bits.h"
 | 
					
						
							|  |  |  | #include "vaapi_encode.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Standard JPEG quantisation tables, in zigzag order.
 | 
					
						
							|  |  |  | static const unsigned char vaapi_encode_mjpeg_quant_luminance[64] = { | 
					
						
							|  |  |  |     16,  11,  12,  14,  12,  10,  16,  14, | 
					
						
							|  |  |  |     13,  14,  18,  17,  16,  19,  24,  40, | 
					
						
							|  |  |  |     26,  24,  22,  22,  24,  49,  35,  37, | 
					
						
							|  |  |  |     29,  40,  58,  51,  61,  60,  57,  51, | 
					
						
							|  |  |  |     56,  55,  64,  72,  92,  78,  64,  68, | 
					
						
							|  |  |  |     87,  69,  55,  56,  80, 109,  81,  87, | 
					
						
							|  |  |  |     95,  98, 103, 104, 103,  62,  77, 113, | 
					
						
							|  |  |  |    121, 112, 100, 120,  92, 101, 103,  99, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64] = { | 
					
						
							|  |  |  |     17,  18,  18,  24,  21,  24,  47,  26, | 
					
						
							|  |  |  |     26,  47,  99,  66,  56,  66,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  |     99,  99,  99,  99,  99,  99,  99,  99, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct VAAPIEncodeMJPEGContext { | 
					
						
							| 
									
										
										
										
											2018-08-23 00:44:36 +01:00
										 |  |  |     VAAPIEncodeContext common; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     // User options.
 | 
					
						
							|  |  |  |     int jfif; | 
					
						
							|  |  |  |     int huffman; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Derived settings.
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     int quality; | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     uint8_t jfif_data[14]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Writer structures.
 | 
					
						
							|  |  |  |     JPEGRawFrameHeader     frame_header; | 
					
						
							|  |  |  |     JPEGRawScan            scan; | 
					
						
							|  |  |  |     JPEGRawApplicationData jfif_header; | 
					
						
							|  |  |  |     JPEGRawQuantisationTableSpecification quant_tables; | 
					
						
							|  |  |  |     JPEGRawHuffmanTableSpecification      huffman_tables; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     CodedBitstreamContext *cbc; | 
					
						
							|  |  |  |     CodedBitstreamFragment current_fragment; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | } VAAPIEncodeMJPEGContext; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  | static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx, | 
					
						
							|  |  |  |                                                  VAAPIEncodePicture *pic, | 
					
						
							|  |  |  |                                                  VAAPIEncodeSlice *slice, | 
					
						
							|  |  |  |                                                  char *data, size_t *data_len) | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     VAAPIEncodeMJPEGContext *priv = avctx->priv_data; | 
					
						
							|  |  |  |     CodedBitstreamFragment  *frag = &priv->current_fragment; | 
					
						
							|  |  |  |     int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (priv->jfif) { | 
					
						
							|  |  |  |         err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, | 
					
						
							|  |  |  |                                          JPEG_MARKER_APPN + 0, | 
					
						
							|  |  |  |                                          &priv->jfif_header, NULL); | 
					
						
							|  |  |  |         if (err < 0) | 
					
						
							|  |  |  |             goto fail; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, | 
					
						
							|  |  |  |                                      JPEG_MARKER_DQT, | 
					
						
							|  |  |  |                                      &priv->quant_tables, NULL); | 
					
						
							|  |  |  |     if (err < 0) | 
					
						
							|  |  |  |         goto fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, | 
					
						
							|  |  |  |                                      JPEG_MARKER_SOF0, | 
					
						
							|  |  |  |                                      &priv->frame_header, NULL); | 
					
						
							|  |  |  |     if (err < 0) | 
					
						
							|  |  |  |         goto fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (priv->huffman) { | 
					
						
							|  |  |  |         err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, | 
					
						
							|  |  |  |                                          JPEG_MARKER_DHT, | 
					
						
							|  |  |  |                                          &priv->huffman_tables, NULL); | 
					
						
							|  |  |  |         if (err < 0) | 
					
						
							|  |  |  |             goto fail; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, | 
					
						
							|  |  |  |                                      JPEG_MARKER_SOS, | 
					
						
							|  |  |  |                                      &priv->scan, NULL); | 
					
						
							|  |  |  |     if (err < 0) | 
					
						
							|  |  |  |         goto fail; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     err = ff_cbs_write_fragment_data(priv->cbc, frag); | 
					
						
							|  |  |  |     if (err < 0) { | 
					
						
							|  |  |  |         av_log(avctx, AV_LOG_ERROR, "Failed to write image header.\n"); | 
					
						
							|  |  |  |         goto fail; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     if (*data_len < 8 * frag->data_size) { | 
					
						
							|  |  |  |         av_log(avctx, AV_LOG_ERROR, "Image header too large: " | 
					
						
							|  |  |  |                "%zu < %zu.\n", *data_len, 8 * frag->data_size); | 
					
						
							|  |  |  |         err = AVERROR(ENOSPC); | 
					
						
							|  |  |  |         goto fail; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     // Remove the EOI at the end of the fragment.
 | 
					
						
							|  |  |  |     memcpy(data, frag->data, frag->data_size - 2); | 
					
						
							|  |  |  |     *data_len = 8 * (frag->data_size - 2); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     err = 0; | 
					
						
							|  |  |  | fail: | 
					
						
							|  |  |  |     ff_cbs_fragment_uninit(priv->cbc, frag); | 
					
						
							|  |  |  |     return err; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  | static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |                                                  VAAPIEncodePicture *pic, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |                                                  int index, int *type, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |                                                  char *data, size_t *data_len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     VAAPIEncodeMJPEGContext *priv = avctx->priv_data; | 
					
						
							|  |  |  |     int t, i, k; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     if (index == 0) { | 
					
						
							|  |  |  |         // Write quantisation tables.
 | 
					
						
							|  |  |  |         JPEGRawFrameHeader                     *fh = &priv->frame_header; | 
					
						
							|  |  |  |         JPEGRawQuantisationTableSpecification *dqt = &priv->quant_tables; | 
					
						
							|  |  |  |         VAQMatrixBufferJPEG *quant; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (*data_len < sizeof(*quant)) | 
					
						
							|  |  |  |             return AVERROR(ENOSPC); | 
					
						
							|  |  |  |         *type     = VAQMatrixBufferType; | 
					
						
							|  |  |  |         *data_len = sizeof(*quant); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         quant = (VAQMatrixBufferJPEG*)data; | 
					
						
							|  |  |  |         memset(quant, 0, sizeof(*quant)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         quant->load_lum_quantiser_matrix = 1; | 
					
						
							|  |  |  |         for (i = 0; i < 64; i++) | 
					
						
							|  |  |  |             quant->lum_quantiser_matrix[i] = dqt->table[fh->Tq[0]].Q[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (fh->Nf > 1) { | 
					
						
							|  |  |  |             quant->load_chroma_quantiser_matrix = 1; | 
					
						
							|  |  |  |             for (i = 0; i < 64; i++) | 
					
						
							|  |  |  |                 quant->chroma_quantiser_matrix[i] = | 
					
						
							|  |  |  |                     dqt->table[fh->Tq[1]].Q[i]; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     } else if (index == 1) { | 
					
						
							|  |  |  |         // Write huffman tables.
 | 
					
						
							|  |  |  |         JPEGRawScanHeader                 *sh = &priv->scan.header; | 
					
						
							|  |  |  |         JPEGRawHuffmanTableSpecification *dht = &priv->huffman_tables; | 
					
						
							|  |  |  |         VAHuffmanTableBufferJPEGBaseline *huff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (*data_len < sizeof(*huff)) | 
					
						
							|  |  |  |             return AVERROR(ENOSPC); | 
					
						
							|  |  |  |         *type     = VAHuffmanTableBufferType; | 
					
						
							|  |  |  |         *data_len = sizeof(*huff); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         huff = (VAHuffmanTableBufferJPEGBaseline*)data; | 
					
						
							|  |  |  |         memset(huff, 0, sizeof(*huff)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (t = 0; t < 1 + (sh->Ns > 1); t++) { | 
					
						
							|  |  |  |             const JPEGRawHuffmanTable *ht; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             huff->load_huffman_table[t] = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ht = &dht->table[2 * t]; | 
					
						
							|  |  |  |             for (i = k = 0; i < 16; i++) | 
					
						
							|  |  |  |                 k += (huff->huffman_table[t].num_dc_codes[i] = ht->L[i]); | 
					
						
							|  |  |  |             av_assert0(k <= sizeof(huff->huffman_table[t].dc_values)); | 
					
						
							|  |  |  |             for (i = 0; i < k; i++) | 
					
						
							|  |  |  |                 huff->huffman_table[t].dc_values[i] = ht->V[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ht = &dht->table[2 * t + 1]; | 
					
						
							|  |  |  |             for (i = k = 0; i < 16; i++) | 
					
						
							|  |  |  |                 k += (huff->huffman_table[t].num_ac_codes[i] = ht->L[i]); | 
					
						
							|  |  |  |             av_assert0(k <= sizeof(huff->huffman_table[t].ac_values)); | 
					
						
							|  |  |  |             for (i = 0; i < k; i++) | 
					
						
							|  |  |  |                 huff->huffman_table[t].ac_values[i] = ht->V[i]; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         return AVERROR_EOF; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, | 
					
						
							|  |  |  |                                                   VAAPIEncodePicture *pic) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VAAPIEncodeMJPEGContext         *priv = avctx->priv_data; | 
					
						
							|  |  |  |     JPEGRawFrameHeader                *fh = &priv->frame_header; | 
					
						
							|  |  |  |     JPEGRawScanHeader                 *sh = &priv->scan.header; | 
					
						
							|  |  |  |     VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params; | 
					
						
							|  |  |  |     const AVPixFmtDescriptor *desc; | 
					
						
							|  |  |  |     const uint8_t *components; | 
					
						
							|  |  |  |     int t, i, quant_scale, len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); | 
					
						
							|  |  |  |     av_assert0(desc); | 
					
						
							|  |  |  |     if (desc->flags & AV_PIX_FMT_FLAG_RGB) | 
					
						
							|  |  |  |         components = (uint8_t[3]) { 'R', 'G', 'B' }; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         components = (uint8_t[3]) {  1,   2,   3  }; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     // Frame header.
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     fh->P  = 8; | 
					
						
							|  |  |  |     fh->Y  = avctx->height; | 
					
						
							|  |  |  |     fh->X  = avctx->width; | 
					
						
							|  |  |  |     fh->Nf = desc->nb_components; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     for (i = 0; i < fh->Nf; i++) { | 
					
						
							|  |  |  |         fh->C[i] = components[i]; | 
					
						
							|  |  |  |         fh->H[i] = 1 + (i == 0 ? desc->log2_chroma_w : 0); | 
					
						
							|  |  |  |         fh->V[i] = 1 + (i == 0 ? desc->log2_chroma_h : 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         fh->Tq[i] = !!i; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     fh->Lf = 8 + 3 * fh->Nf; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     // JFIF header.
 | 
					
						
							|  |  |  |     if (priv->jfif) { | 
					
						
							|  |  |  |         JPEGRawApplicationData *app = &priv->jfif_header; | 
					
						
							|  |  |  |         AVRational sar = pic->input_image->sample_aspect_ratio; | 
					
						
							|  |  |  |         int sar_w, sar_h; | 
					
						
							|  |  |  |         PutByteContext pbc; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         bytestream2_init_writer(&pbc, priv->jfif_data, | 
					
						
							|  |  |  |                                 sizeof(priv->jfif_data)); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         bytestream2_put_buffer(&pbc, "JFIF", 5); | 
					
						
							|  |  |  |         bytestream2_put_be16(&pbc, 0x0102); | 
					
						
							|  |  |  |         bytestream2_put_byte(&pbc, 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         av_reduce(&sar_w, &sar_h, sar.num, sar.den, 65535); | 
					
						
							|  |  |  |         if (sar_w && sar_h) { | 
					
						
							|  |  |  |             bytestream2_put_be16(&pbc, sar_w); | 
					
						
							|  |  |  |             bytestream2_put_be16(&pbc, sar_h); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |             bytestream2_put_be16(&pbc, 1); | 
					
						
							|  |  |  |             bytestream2_put_be16(&pbc, 1); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         bytestream2_put_byte(&pbc, 0); | 
					
						
							|  |  |  |         bytestream2_put_byte(&pbc, 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         av_assert0(bytestream2_get_bytes_left_p(&pbc) == 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         app->Lp     = 2 + sizeof(priv->jfif_data); | 
					
						
							|  |  |  |         app->Ap     = priv->jfif_data; | 
					
						
							|  |  |  |         app->Ap_ref = NULL; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     // Quantisation tables.
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     if (priv->quality < 50) | 
					
						
							|  |  |  |         quant_scale = 5000 / priv->quality; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         quant_scale = 200 - 2 * priv->quality; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     len = 2; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     for (t = 0; t < 1 + (fh->Nf > 1); t++) { | 
					
						
							|  |  |  |         JPEGRawQuantisationTable *quant = &priv->quant_tables.table[t]; | 
					
						
							|  |  |  |         const uint8_t *data = t == 0 ? | 
					
						
							|  |  |  |             vaapi_encode_mjpeg_quant_luminance : | 
					
						
							|  |  |  |             vaapi_encode_mjpeg_quant_chrominance; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         quant->Pq = 0; | 
					
						
							|  |  |  |         quant->Tq = t; | 
					
						
							|  |  |  |         for (i = 0; i < 64; i++) | 
					
						
							|  |  |  |             quant->Q[i] = av_clip(data[i] * quant_scale / 100, 1, 255); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         len += 65; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     priv->quant_tables.Lq = len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Huffman tables.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     len = 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (t = 0; t < 2 + 2 * (fh->Nf > 1); t++) { | 
					
						
							|  |  |  |         JPEGRawHuffmanTable *huff = &priv->huffman_tables.table[t]; | 
					
						
							|  |  |  |         const uint8_t *lengths, *values; | 
					
						
							|  |  |  |         int k; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch (t) { | 
					
						
							|  |  |  |         case 0: | 
					
						
							|  |  |  |             lengths = avpriv_mjpeg_bits_dc_luminance + 1; | 
					
						
							|  |  |  |             values  = avpriv_mjpeg_val_dc; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 1: | 
					
						
							|  |  |  |             lengths = avpriv_mjpeg_bits_ac_luminance + 1; | 
					
						
							|  |  |  |             values  = avpriv_mjpeg_val_ac_luminance; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 2: | 
					
						
							|  |  |  |             lengths = avpriv_mjpeg_bits_dc_chrominance + 1; | 
					
						
							|  |  |  |             values  = avpriv_mjpeg_val_dc; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 3: | 
					
						
							|  |  |  |             lengths = avpriv_mjpeg_bits_ac_chrominance + 1; | 
					
						
							|  |  |  |             values  = avpriv_mjpeg_val_ac_chrominance; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         huff->Tc = t % 2; | 
					
						
							|  |  |  |         huff->Th = t / 2; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         for (i = k = 0; i < 16; i++) | 
					
						
							|  |  |  |             k += (huff->L[i] = lengths[i]); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         for (i = 0; i < k; i++) | 
					
						
							|  |  |  |             huff->V[i] = values[i]; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         len += 17 + k; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     priv->huffman_tables.Lh = len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Scan header.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sh->Ns = fh->Nf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < fh->Nf; i++) { | 
					
						
							|  |  |  |         sh->Cs[i] = fh->C[i]; | 
					
						
							|  |  |  |         sh->Td[i] = i > 0; | 
					
						
							|  |  |  |         sh->Ta[i] = i > 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     sh->Ss = 0; | 
					
						
							|  |  |  |     sh->Se = 63; | 
					
						
							|  |  |  |     sh->Ah = 0; | 
					
						
							|  |  |  |     sh->Al = 0; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     sh->Ls = 6 + 2 * sh->Ns; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     *vpic = (VAEncPictureParameterBufferJPEG) { | 
					
						
							|  |  |  |         .reconstructed_picture = pic->recon_surface, | 
					
						
							|  |  |  |         .coded_buf             = pic->output_buffer, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         .picture_width  = fh->X, | 
					
						
							|  |  |  |         .picture_height = fh->Y, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         .pic_flags.bits = { | 
					
						
							|  |  |  |             .profile      = 0, | 
					
						
							|  |  |  |             .progressive  = 0, | 
					
						
							|  |  |  |             .huffman      = 1, | 
					
						
							|  |  |  |             .interleaved  = 0, | 
					
						
							|  |  |  |             .differential = 0, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         .sample_bit_depth = fh->P, | 
					
						
							|  |  |  |         .num_scan         = 1, | 
					
						
							|  |  |  |         .num_components   = fh->Nf, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |         // The driver modifies the provided quantisation tables according
 | 
					
						
							|  |  |  |         // to this quality value; the middle value of 50 makes that the
 | 
					
						
							|  |  |  |         // identity so that they are used unchanged.
 | 
					
						
							|  |  |  |         .quality = 50, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     for (i = 0; i < fh->Nf; i++) { | 
					
						
							|  |  |  |         vpic->component_id[i]             = fh->C[i]; | 
					
						
							|  |  |  |         vpic->quantiser_table_selector[i] = fh->Tq[i]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pic->nb_slices = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, | 
					
						
							|  |  |  |                                                 VAAPIEncodePicture *pic, | 
					
						
							|  |  |  |                                                 VAAPIEncodeSlice *slice) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     VAAPIEncodeMJPEGContext         *priv = avctx->priv_data; | 
					
						
							|  |  |  |     JPEGRawScanHeader                 *sh = &priv->scan.header; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     VAEncSliceParameterBufferJPEG *vslice = slice->codec_slice_params; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     *vslice = (VAEncSliceParameterBufferJPEG) { | 
					
						
							|  |  |  |         .restart_interval = 0, | 
					
						
							|  |  |  |         .num_components   = sh->Ns, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     for (i = 0; i < sh->Ns; i++) { | 
					
						
							|  |  |  |         vslice->components[i].component_selector = sh->Cs[i]; | 
					
						
							|  |  |  |         vslice->components[i].dc_table_selector  = sh->Td[i]; | 
					
						
							|  |  |  |         vslice->components[i].ac_table_selector  = sh->Ta[i]; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:55:26 +01:00
										 |  |  | static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx) | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     VAAPIEncodeContext       *ctx = avctx->priv_data; | 
					
						
							| 
									
										
										
										
											2018-08-23 00:44:36 +01:00
										 |  |  |     VAAPIEncodeMJPEGContext *priv = avctx->priv_data; | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     int err; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     priv->quality = avctx->global_quality; | 
					
						
							|  |  |  |     if (priv->quality < 1 || priv->quality > 100) { | 
					
						
							|  |  |  |         av_log(avctx, AV_LOG_ERROR, "Invalid quality value %d " | 
					
						
							|  |  |  |                "(must be 1-100).\n", priv->quality); | 
					
						
							|  |  |  |         return AVERROR(EINVAL); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:59:59 +01:00
										 |  |  |     // Hack: the implementation calls the JPEG image header (which we
 | 
					
						
							|  |  |  |     // will use in the same way as a slice header) generic "raw data".
 | 
					
						
							|  |  |  |     // Therefore, if after the packed header capability check we have
 | 
					
						
							|  |  |  |     // PACKED_HEADER_RAW_DATA available, rewrite it as
 | 
					
						
							|  |  |  |     // PACKED_HEADER_SLICE so that the header-writing code can do the
 | 
					
						
							|  |  |  |     // right thing.
 | 
					
						
							|  |  |  |     if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) { | 
					
						
							|  |  |  |         ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA; | 
					
						
							|  |  |  |         ctx->va_packed_headers |=  VA_ENC_PACKED_HEADER_SLICE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MJPEG, avctx); | 
					
						
							|  |  |  |     if (err < 0) | 
					
						
							|  |  |  |         return err; | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:40 +01:00
										 |  |  | static const VAAPIEncodeProfile vaapi_encode_mjpeg_profiles[] = { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     { FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT, | 
					
						
							|  |  |  |             8, 1, 0, 0, VAProfileJPEGBaseline }, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:40 +01:00
										 |  |  |     { FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT, | 
					
						
							|  |  |  |             8, 3, 1, 1, VAProfileJPEGBaseline }, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     { FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT, | 
					
						
							|  |  |  |             8, 3, 1, 0, VAProfileJPEGBaseline }, | 
					
						
							|  |  |  |     { FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT, | 
					
						
							|  |  |  |             8, 3, 0, 0, VAProfileJPEGBaseline }, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:40 +01:00
										 |  |  |     { FF_PROFILE_UNKNOWN } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 10:09:36 +02:00
										 |  |  | static const VAAPIEncodeType vaapi_encode_type_mjpeg = { | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:40 +01:00
										 |  |  |     .profiles              = vaapi_encode_mjpeg_profiles, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:55:26 +01:00
										 |  |  |     .configure             = &vaapi_encode_mjpeg_configure, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     .picture_params_size   = sizeof(VAEncPictureParameterBufferJPEG), | 
					
						
							|  |  |  |     .init_picture_params   = &vaapi_encode_mjpeg_init_picture_params, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     .slice_params_size     = sizeof(VAEncSliceParameterBufferJPEG), | 
					
						
							|  |  |  |     .init_slice_params     = &vaapi_encode_mjpeg_init_slice_params, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     .slice_header_type     = VAEncPackedHeaderRawData, | 
					
						
							|  |  |  |     .write_slice_header    = &vaapi_encode_mjpeg_write_image_header, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     .write_extra_buffer    = &vaapi_encode_mjpeg_write_extra_buffer, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-09-18 14:55:26 +01:00
										 |  |  |     VAAPIEncodeContext *ctx = avctx->priv_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx->codec = &vaapi_encode_type_mjpeg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:59:59 +01:00
										 |  |  |     // The JPEG image header - see note above.
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:48 +01:00
										 |  |  |     ctx->desired_packed_headers = | 
					
						
							| 
									
										
										
										
											2016-09-18 14:59:59 +01:00
										 |  |  |         VA_ENC_PACKED_HEADER_RAW_DATA; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:55:26 +01:00
										 |  |  |     ctx->surface_width  = FFALIGN(avctx->width,  8); | 
					
						
							|  |  |  |     ctx->surface_height = FFALIGN(avctx->height, 8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ff_vaapi_encode_init(avctx); | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  | static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VAAPIEncodeMJPEGContext *priv = avctx->priv_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ff_cbs_close(&priv->cbc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ff_vaapi_encode_close(avctx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
 | 
					
						
							|  |  |  | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 | 
					
						
							|  |  |  | static const AVOption vaapi_encode_mjpeg_options[] = { | 
					
						
							|  |  |  |     VAAPI_ENCODE_COMMON_OPTIONS, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "jfif", "Include JFIF header", | 
					
						
							|  |  |  |       OFFSET(jfif), AV_OPT_TYPE_BOOL, | 
					
						
							|  |  |  |       { .i64 = 0 }, 0, 1, FLAGS }, | 
					
						
							|  |  |  |     { "huffman", "Include huffman tables", | 
					
						
							|  |  |  |       OFFSET(huffman), AV_OPT_TYPE_BOOL, | 
					
						
							|  |  |  |       { .i64 = 1 }, 0, 1, FLAGS }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { NULL }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | static const AVCodecDefault vaapi_encode_mjpeg_defaults[] = { | 
					
						
							|  |  |  |     { "global_quality", "80" }, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:45 +01:00
										 |  |  |     { "b",              "0"  }, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:47 +01:00
										 |  |  |     { "g",              "1"  }, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     { NULL }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const AVClass vaapi_encode_mjpeg_class = { | 
					
						
							|  |  |  |     .class_name = "mjpeg_vaapi", | 
					
						
							|  |  |  |     .item_name  = av_default_item_name, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     .option     = vaapi_encode_mjpeg_options, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     .version    = LIBAVUTIL_VERSION_INT, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AVCodec ff_mjpeg_vaapi_encoder = { | 
					
						
							|  |  |  |     .name           = "mjpeg_vaapi", | 
					
						
							|  |  |  |     .long_name      = NULL_IF_CONFIG_SMALL("MJPEG (VAAPI)"), | 
					
						
							|  |  |  |     .type           = AVMEDIA_TYPE_VIDEO, | 
					
						
							|  |  |  |     .id             = AV_CODEC_ID_MJPEG, | 
					
						
							| 
									
										
										
										
											2018-08-23 00:44:36 +01:00
										 |  |  |     .priv_data_size = sizeof(VAAPIEncodeMJPEGContext), | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     .init           = &vaapi_encode_mjpeg_init, | 
					
						
							|  |  |  |     .encode2        = &ff_vaapi_encode2, | 
					
						
							| 
									
										
										
										
											2018-09-18 23:30:54 +01:00
										 |  |  |     .close          = &vaapi_encode_mjpeg_close, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     .priv_class     = &vaapi_encode_mjpeg_class, | 
					
						
							| 
									
										
										
										
											2017-12-11 16:18:44 +01:00
										 |  |  |     .capabilities   = AV_CODEC_CAP_HARDWARE, | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  |     .defaults       = vaapi_encode_mjpeg_defaults, | 
					
						
							|  |  |  |     .pix_fmts = (const enum AVPixelFormat[]) { | 
					
						
							|  |  |  |         AV_PIX_FMT_VAAPI, | 
					
						
							|  |  |  |         AV_PIX_FMT_NONE, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-12-11 16:18:44 +01:00
										 |  |  |     .wrapper_name   = "vaapi", | 
					
						
							| 
									
										
										
										
											2016-03-23 23:50:47 +00:00
										 |  |  | }; |