static gboolean ensure_quantization_table (GstVaapiEncoderJpeg * encoder, GstVaapiEncPicture * picture) { g_assert (picture); if (!fill_quantization_table (encoder, picture)) return FALSE; return TRUE; }
static gboolean ensure_quantization_table (GstVaapiEncoderVP8 * encoder, GstVaapiEncPicture * picture) { g_assert (picture); picture->q_matrix = GST_VAAPI_ENC_Q_MATRIX_NEW (VP8, encoder); if (!picture->q_matrix) { GST_ERROR ("failed to allocate quantiser table"); return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; } if (!fill_quantization_table (encoder, picture, picture->q_matrix)) return FALSE; return TRUE; }
static GstVaapiDecoderStatus gst_vaapi_decoder_jpeg_start_frame (GstVaapiDecoder * base_decoder, GstVaapiDecoderUnit * base_unit) { GstVaapiDecoderJpeg *const decoder = GST_VAAPI_DECODER_JPEG_CAST (base_decoder); GstVaapiDecoderJpegPrivate *const priv = &decoder->priv; GstVaapiPicture *picture; GstVaapiDecoderStatus status; if (!VALID_STATE (decoder, GOT_SOF)) return GST_VAAPI_DECODER_STATUS_SUCCESS; status = ensure_context (decoder); if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) { GST_ERROR ("failed to reset context"); return status; } picture = GST_VAAPI_PICTURE_NEW (JPEGBaseline, decoder); if (!picture) { GST_ERROR ("failed to allocate picture"); return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; } gst_vaapi_picture_replace (&priv->current_picture, picture); gst_vaapi_picture_unref (picture); if (!fill_picture (decoder, picture, &priv->frame_hdr)) return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; status = fill_quantization_table (decoder, picture); if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) return status; /* Update presentation time */ picture->pts = GST_VAAPI_DECODER_CODEC_FRAME (decoder)->pts; return GST_VAAPI_DECODER_STATUS_SUCCESS; }
static GstVaapiDecoderStatus decode_scan( GstVaapiDecoderJpeg *decoder, guchar *scan_header, guint scan_header_size, guchar *scan_data, guint scan_data_size) { GstVaapiDecoderJpegPrivate * const priv = decoder->priv; GstVaapiPicture *picture = priv->current_picture; VASliceParameterBufferJPEGBaseline *slice_param; GstVaapiSlice *gst_slice; guint total_h_samples, total_v_samples; GstJpegScanHdr scan_hdr; guint i; if (!picture) { GST_ERROR("There is no VAPicture before decoding scan."); return GST_VAAPI_DECODER_STATUS_ERROR_INVALID_SURFACE; } if (!fill_quantization_table(decoder, picture)) { GST_ERROR("failed to fill in quantization table"); return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; } if (!fill_huffman_table(decoder, picture)) { GST_ERROR("failed to fill in huffman table"); return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; } memset(&scan_hdr, 0, sizeof(scan_hdr)); if (!gst_jpeg_parse_scan_hdr(&scan_hdr, scan_header, scan_header_size, 0)) { GST_DEBUG("Jpeg parsed scan failed."); return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; } gst_slice = GST_VAAPI_SLICE_NEW(JPEGBaseline, decoder, scan_data, scan_data_size); gst_vaapi_picture_add_slice(picture, gst_slice); slice_param = gst_slice->param; slice_param->num_components = scan_hdr.num_components; for (i = 0; i < scan_hdr.num_components; i++) { slice_param->components[i].component_selector = scan_hdr.components[i].component_selector; slice_param->components[i].dc_table_selector = scan_hdr.components[i].dc_selector; slice_param->components[i].ac_table_selector = scan_hdr.components[i].ac_selector; } slice_param->restart_interval = priv->mcu_restart; if (scan_hdr.num_components == 1) { /*non-interleaved*/ slice_param->slice_horizontal_position = 0; slice_param->slice_vertical_position = 0; /* Y mcu numbers*/ if (slice_param->components[0].component_selector == priv->frame_hdr.components[0].identifier) { slice_param->num_mcus = (priv->frame_hdr.width/8)*(priv->frame_hdr.height/8); } else { /*Cr, Cb mcu numbers*/ slice_param->num_mcus = (priv->frame_hdr.width/16)*(priv->frame_hdr.height/16); } } else { /* interleaved */ slice_param->slice_horizontal_position = 0; slice_param->slice_vertical_position = 0; total_v_samples = get_max_vertical_samples(&priv->frame_hdr); total_h_samples = get_max_horizontal_samples(&priv->frame_hdr); slice_param->num_mcus = ((priv->frame_hdr.width + total_h_samples*8 - 1)/(total_h_samples*8)) * ((priv->frame_hdr.height + total_v_samples*8 -1)/(total_v_samples*8)); } if (picture->slices && picture->slices->len) return GST_VAAPI_DECODER_STATUS_SUCCESS; return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA; }