MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / vaapi_encode_mjpeg_init_picture_params

Function vaapi_encode_mjpeg_init_picture_params

libavcodec/vaapi_encode_mjpeg.c:222–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
223 FFHWBaseEncodePicture *pic)
224{
225 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
226 VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
227 VAAPIEncodePicture *vaapi_pic = pic->priv;
228 JPEGRawFrameHeader *fh = &priv->frame_header;
229 JPEGRawScanHeader *sh = &priv->scan.header;
230 VAEncPictureParameterBufferJPEG *vpic = vaapi_pic->codec_picture_params;
231 const AVPixFmtDescriptor *desc;
232 const uint8_t components_rgb[3] = { 'R', 'G', 'B' };
233 const uint8_t components_yuv[3] = { 1, 2, 3 };
234 const uint8_t *components;
235 int t, i, quant_scale, len;
236
237 av_assert0(pic->type == FF_HW_PICTURE_TYPE_IDR);
238
239 desc = av_pix_fmt_desc_get(base_ctx->input_frames->sw_format);
240 av_assert0(desc);
241 if (desc->flags & AV_PIX_FMT_FLAG_RGB)
242 components = components_rgb;
243 else
244 components = components_yuv;
245
246 // Frame header.
247
248 fh->P = 8;
249 fh->Y = avctx->height;
250 fh->X = avctx->width;
251 fh->Nf = desc->nb_components;
252
253 for (i = 0; i < fh->Nf; i++) {
254 fh->C[i] = components[i];
255 fh->H[i] = 1 + (i == 0 ? desc->log2_chroma_w : 0);
256 fh->V[i] = 1 + (i == 0 ? desc->log2_chroma_h : 0);
257
258 fh->Tq[i] = !!i;
259 }
260
261 fh->Lf = 8 + 3 * fh->Nf;
262
263 // JFIF header.
264 if (priv->jfif) {
265 JPEGRawApplicationData *app = &priv->jfif_header;
266 AVRational sar = pic->input_image->sample_aspect_ratio;
267 int sar_w, sar_h;
268 PutByteContext pbc;
269
270 bytestream2_init_writer(&pbc, priv->jfif_data,
271 sizeof(priv->jfif_data));
272
273 bytestream2_put_buffer(&pbc, "JFIF", 5);
274 bytestream2_put_be16(&pbc, 0x0102);
275 bytestream2_put_byte(&pbc, 0);
276
277 av_reduce(&sar_w, &sar_h, sar.num, sar.den, 65535);
278 if (sar_w && sar_h) {
279 bytestream2_put_be16(&pbc, sar_w);

Callers

nothing calls this directly

Calls 5

av_pix_fmt_desc_getFunction · 0.85
bytestream2_init_writerFunction · 0.85
bytestream2_put_bufferFunction · 0.85
av_reduceFunction · 0.85

Tested by

no test coverage detected