2012-02-09 16:21:04 +00:00
|
|
|
/*
|
|
|
|
* gstvaapidecoder_jpeg.c - JPEG decoder
|
|
|
|
*
|
2013-01-29 13:14:45 +00:00
|
|
|
* Copyright (C) 2011-2013 Intel Corporation
|
2012-02-09 16:21:04 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstvaapidecoder_jpeg
|
|
|
|
* @short_description: JPEG decoder
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <gst/codecparsers/gstjpegparser.h>
|
2012-06-25 15:10:49 +00:00
|
|
|
#include "gstvaapicompat.h"
|
2012-02-09 16:21:04 +00:00
|
|
|
#include "gstvaapidecoder_jpeg.h"
|
|
|
|
#include "gstvaapidecoder_objects.h"
|
|
|
|
#include "gstvaapidecoder_priv.h"
|
|
|
|
#include "gstvaapidisplay_priv.h"
|
|
|
|
#include "gstvaapiobject_priv.h"
|
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(GstVaapiDecoderJpeg,
|
|
|
|
gst_vaapi_decoder_jpeg,
|
2012-09-07 14:14:11 +00:00
|
|
|
GST_VAAPI_TYPE_DECODER)
|
2012-02-09 16:21:04 +00:00
|
|
|
|
|
|
|
#define GST_VAAPI_DECODER_JPEG_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
|
|
|
GST_VAAPI_TYPE_DECODER_JPEG, \
|
|
|
|
GstVaapiDecoderJpegPrivate))
|
|
|
|
|
|
|
|
struct _GstVaapiDecoderJpegPrivate {
|
|
|
|
GstVaapiProfile profile;
|
|
|
|
guint width;
|
|
|
|
guint height;
|
|
|
|
GstVaapiPicture *current_picture;
|
2012-04-19 15:50:14 +00:00
|
|
|
GstJpegFrameHdr frame_hdr;
|
2012-06-04 08:20:13 +00:00
|
|
|
GstJpegHuffmanTables huf_tables;
|
2012-06-21 14:06:47 +00:00
|
|
|
GstJpegQuantTables quant_tables;
|
2012-04-19 15:50:14 +00:00
|
|
|
gboolean has_huf_table;
|
|
|
|
gboolean has_quant_table;
|
|
|
|
guint mcu_restart;
|
2012-02-09 16:21:04 +00:00
|
|
|
guint is_opened : 1;
|
|
|
|
guint profile_changed : 1;
|
|
|
|
guint is_constructed : 1;
|
|
|
|
};
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
typedef struct _GstJpegScanSegment GstJpegScanSegment;
|
|
|
|
struct _GstJpegScanSegment {
|
|
|
|
guint header_offset;
|
|
|
|
guint header_size;
|
|
|
|
guint data_offset;
|
|
|
|
guint data_size;
|
|
|
|
guint is_valid : 1;
|
|
|
|
};
|
2012-02-09 16:21:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_close(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
gst_vaapi_picture_replace(&priv->current_picture, NULL);
|
|
|
|
|
|
|
|
/* Reset all */
|
|
|
|
priv->profile = GST_VAAPI_PROFILE_JPEG_BASELINE;
|
|
|
|
priv->width = 0;
|
|
|
|
priv->height = 0;
|
|
|
|
priv->is_opened = FALSE;
|
|
|
|
priv->profile_changed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-06 13:02:25 +00:00
|
|
|
gst_vaapi_decoder_jpeg_open(GstVaapiDecoderJpeg *decoder)
|
2012-02-09 16:21:04 +00:00
|
|
|
{
|
|
|
|
gst_vaapi_decoder_jpeg_close(decoder);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_destroy(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
gst_vaapi_decoder_jpeg_close(decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vaapi_decoder_jpeg_create(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
if (!GST_VAAPI_DECODER_CODEC(decoder))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
ensure_context(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
GstVaapiProfile profiles[2];
|
|
|
|
GstVaapiEntrypoint entrypoint = GST_VAAPI_ENTRYPOINT_VLD;
|
|
|
|
guint i, n_profiles = 0;
|
|
|
|
gboolean reset_context = FALSE;
|
|
|
|
|
|
|
|
if (priv->profile_changed) {
|
|
|
|
GST_DEBUG("profile changed");
|
|
|
|
priv->profile_changed = FALSE;
|
|
|
|
reset_context = TRUE;
|
|
|
|
|
|
|
|
profiles[n_profiles++] = priv->profile;
|
|
|
|
//if (priv->profile == GST_VAAPI_PROFILE_JPEG_EXTENDED)
|
|
|
|
// profiles[n_profiles++] = GST_VAAPI_PROFILE_JPEG_BASELINE;
|
|
|
|
|
|
|
|
for (i = 0; i < n_profiles; i++) {
|
|
|
|
if (gst_vaapi_display_has_decoder(GST_VAAPI_DECODER_DISPLAY(decoder),
|
|
|
|
profiles[i], entrypoint))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == n_profiles)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
|
|
|
priv->profile = profiles[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reset_context) {
|
2012-09-10 16:26:51 +00:00
|
|
|
GstVaapiContextInfo info;
|
|
|
|
|
|
|
|
info.profile = priv->profile;
|
|
|
|
info.entrypoint = entrypoint;
|
|
|
|
info.width = priv->width;
|
|
|
|
info.height = priv->height;
|
|
|
|
info.ref_frames = 2;
|
|
|
|
reset_context = gst_vaapi_decoder_ensure_context(
|
2012-02-09 16:21:04 +00:00
|
|
|
GST_VAAPI_DECODER(decoder),
|
2012-09-10 16:26:51 +00:00
|
|
|
&info
|
2012-02-09 16:21:04 +00:00
|
|
|
);
|
|
|
|
if (!reset_context)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
static gboolean
|
2012-02-09 16:21:04 +00:00
|
|
|
decode_current_picture(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
GstVaapiPicture * const picture = priv->current_picture;
|
2012-07-17 11:43:32 +00:00
|
|
|
gboolean success = TRUE;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
|
|
|
if (picture) {
|
|
|
|
if (!gst_vaapi_picture_decode(picture))
|
2012-07-17 11:43:32 +00:00
|
|
|
success = FALSE;
|
2012-02-09 16:21:04 +00:00
|
|
|
else if (!gst_vaapi_picture_output(picture))
|
2012-07-17 11:43:32 +00:00
|
|
|
success = FALSE;
|
2012-02-09 16:21:04 +00:00
|
|
|
gst_vaapi_picture_replace(&priv->current_picture, NULL);
|
|
|
|
}
|
2012-07-17 11:43:32 +00:00
|
|
|
return success;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
fill_picture(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
|
|
|
GstVaapiPicture *picture,
|
2012-04-19 15:50:14 +00:00
|
|
|
GstJpegFrameHdr *jpeg_frame_hdr
|
2012-02-09 16:21:04 +00:00
|
|
|
)
|
|
|
|
{
|
2012-07-31 09:51:57 +00:00
|
|
|
VAPictureParameterBufferJPEGBaseline *pic_param = picture->param;
|
2012-02-09 16:21:04 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_assert(pic_param);
|
|
|
|
|
2012-07-31 09:51:57 +00:00
|
|
|
memset(pic_param, 0, sizeof(VAPictureParameterBufferJPEGBaseline));
|
2012-06-25 15:10:49 +00:00
|
|
|
pic_param->picture_width = jpeg_frame_hdr->width;
|
|
|
|
pic_param->picture_height = jpeg_frame_hdr->height;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
pic_param->num_components = jpeg_frame_hdr->num_components;
|
|
|
|
if (jpeg_frame_hdr->num_components > 4)
|
|
|
|
return FALSE;
|
2012-02-09 16:21:04 +00:00
|
|
|
for (i = 0; i < pic_param->num_components; i++) {
|
|
|
|
pic_param->components[i].component_id =
|
2012-04-19 15:50:14 +00:00
|
|
|
jpeg_frame_hdr->components[i].identifier;
|
2012-02-09 16:21:04 +00:00
|
|
|
pic_param->components[i].h_sampling_factor =
|
2012-04-19 15:50:14 +00:00
|
|
|
jpeg_frame_hdr->components[i].horizontal_factor;
|
2012-02-09 16:21:04 +00:00
|
|
|
pic_param->components[i].v_sampling_factor =
|
2012-04-19 15:50:14 +00:00
|
|
|
jpeg_frame_hdr->components[i].vertical_factor;
|
2012-02-09 16:21:04 +00:00
|
|
|
pic_param->components[i].quantiser_table_selector =
|
2012-04-19 15:50:14 +00:00
|
|
|
jpeg_frame_hdr->components[i].quant_table_selector;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
fill_quantization_table(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiPicture *picture
|
2012-02-09 16:21:04 +00:00
|
|
|
)
|
|
|
|
{
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
2012-07-31 09:51:57 +00:00
|
|
|
VAIQMatrixBufferJPEGBaseline *iq_matrix;
|
2012-06-25 15:10:49 +00:00
|
|
|
guint i, j, num_tables;
|
2012-04-19 15:50:14 +00:00
|
|
|
|
|
|
|
if (!priv->has_quant_table)
|
2012-06-21 14:06:47 +00:00
|
|
|
gst_jpeg_get_default_quantization_tables(&priv->quant_tables);
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-07-31 09:51:57 +00:00
|
|
|
picture->iq_matrix = GST_VAAPI_IQ_MATRIX_NEW(JPEGBaseline, decoder);
|
2012-02-09 16:21:04 +00:00
|
|
|
g_assert(picture->iq_matrix);
|
|
|
|
iq_matrix = picture->iq_matrix->param;
|
2012-06-25 15:10:49 +00:00
|
|
|
|
|
|
|
num_tables = MIN(G_N_ELEMENTS(iq_matrix->quantiser_table),
|
|
|
|
GST_JPEG_MAX_QUANT_ELEMENTS);
|
|
|
|
|
|
|
|
for (i = 0; i < num_tables; i++) {
|
2012-06-21 14:06:47 +00:00
|
|
|
GstJpegQuantTable * const quant_table =
|
|
|
|
&priv->quant_tables.quant_tables[i];
|
2012-06-25 15:10:49 +00:00
|
|
|
|
|
|
|
iq_matrix->load_quantiser_table[i] = quant_table->valid;
|
|
|
|
if (!iq_matrix->load_quantiser_table[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_assert(quant_table->quant_precision == 0);
|
|
|
|
for (j = 0; j < GST_JPEG_MAX_QUANT_ELEMENTS; j++)
|
|
|
|
iq_matrix->quantiser_table[i][j] = quant_table->quant_table[j];
|
|
|
|
iq_matrix->load_quantiser_table[i] = 1;
|
|
|
|
quant_table->valid = FALSE;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
fill_huffman_table(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiPicture *picture
|
2012-02-09 16:21:04 +00:00
|
|
|
)
|
|
|
|
{
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
2012-06-25 15:10:49 +00:00
|
|
|
GstJpegHuffmanTables * const huf_tables = &priv->huf_tables;
|
2012-07-31 09:51:57 +00:00
|
|
|
VAHuffmanTableBufferJPEGBaseline *huffman_table;
|
2012-06-25 15:10:49 +00:00
|
|
|
guint i, num_tables;
|
2012-04-19 15:50:14 +00:00
|
|
|
|
|
|
|
if (!priv->has_huf_table)
|
2012-06-21 14:06:47 +00:00
|
|
|
gst_jpeg_get_default_huffman_tables(&priv->huf_tables);
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-07-31 09:51:57 +00:00
|
|
|
picture->huf_table = GST_VAAPI_HUFFMAN_TABLE_NEW(JPEGBaseline, decoder);
|
2012-02-09 16:21:04 +00:00
|
|
|
g_assert(picture->huf_table);
|
|
|
|
huffman_table = picture->huf_table->param;
|
2012-06-25 15:10:49 +00:00
|
|
|
|
|
|
|
num_tables = MIN(G_N_ELEMENTS(huffman_table->huffman_table),
|
|
|
|
GST_JPEG_MAX_SCAN_COMPONENTS);
|
|
|
|
|
|
|
|
for (i = 0; i < num_tables; i++) {
|
|
|
|
huffman_table->load_huffman_table[i] =
|
|
|
|
huf_tables->dc_tables[i].valid && huf_tables->ac_tables[i].valid;
|
|
|
|
if (!huffman_table->load_huffman_table[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memcpy(huffman_table->huffman_table[i].num_dc_codes,
|
|
|
|
huf_tables->dc_tables[i].huf_bits,
|
|
|
|
sizeof(huffman_table->huffman_table[i].num_dc_codes));
|
|
|
|
memcpy(huffman_table->huffman_table[i].dc_values,
|
|
|
|
huf_tables->dc_tables[i].huf_values,
|
|
|
|
sizeof(huffman_table->huffman_table[i].dc_values));
|
|
|
|
memcpy(huffman_table->huffman_table[i].num_ac_codes,
|
|
|
|
huf_tables->ac_tables[i].huf_bits,
|
|
|
|
sizeof(huffman_table->huffman_table[i].num_ac_codes));
|
|
|
|
memcpy(huffman_table->huffman_table[i].ac_values,
|
|
|
|
huf_tables->ac_tables[i].huf_values,
|
|
|
|
sizeof(huffman_table->huffman_table[i].ac_values));
|
2012-07-31 09:51:57 +00:00
|
|
|
memset(huffman_table->huffman_table[i].pad,
|
|
|
|
0,
|
|
|
|
sizeof(huffman_table->huffman_table[i].pad));
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
2012-04-19 15:50:14 +00:00
|
|
|
get_max_horizontal_samples(GstJpegFrameHdr *frame_hdr)
|
2012-02-09 16:21:04 +00:00
|
|
|
{
|
|
|
|
guint i, max_factor = 0;
|
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
for (i = 0; i < frame_hdr->num_components; i++) {
|
|
|
|
if (frame_hdr->components[i].horizontal_factor > max_factor)
|
|
|
|
max_factor = frame_hdr->components[i].horizontal_factor;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
return max_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
2012-04-19 15:50:14 +00:00
|
|
|
get_max_vertical_samples(GstJpegFrameHdr *frame_hdr)
|
2012-02-09 16:21:04 +00:00
|
|
|
{
|
|
|
|
guint i, max_factor = 0;
|
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
for (i = 0; i < frame_hdr->num_components; i++) {
|
|
|
|
if (frame_hdr->components[i].vertical_factor > max_factor)
|
|
|
|
max_factor = frame_hdr->components[i].vertical_factor;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
return max_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_picture(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
2012-04-19 15:50:14 +00:00
|
|
|
guint8 profile,
|
2012-02-09 16:21:04 +00:00
|
|
|
guchar *buf,
|
2012-12-06 13:02:25 +00:00
|
|
|
guint buf_size
|
2012-02-09 16:21:04 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
2012-07-17 11:43:32 +00:00
|
|
|
GstJpegFrameHdr * const frame_hdr = &priv->frame_hdr;
|
|
|
|
GstVaapiPicture *picture;
|
|
|
|
GstVaapiDecoderStatus status;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
switch (profile) {
|
2012-07-17 11:43:32 +00:00
|
|
|
case GST_JPEG_MARKER_SOF_MIN:
|
|
|
|
priv->profile = GST_VAAPI_PROFILE_JPEG_BASELINE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ERROR("unsupported profile %d", profile);
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
memset(frame_hdr, 0, sizeof(*frame_hdr));
|
|
|
|
if (!gst_jpeg_parse_frame_hdr(frame_hdr, buf, buf_size, 0)) {
|
2012-02-09 16:21:04 +00:00
|
|
|
GST_ERROR("failed to parse image");
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
2012-07-17 11:43:32 +00:00
|
|
|
priv->height = frame_hdr->height;
|
|
|
|
priv->width = frame_hdr->width;
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-02-09 16:21:04 +00:00
|
|
|
status = ensure_context(decoder);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR("failed to reset context");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (priv->current_picture && !decode_current_picture(decoder))
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-07-31 09:51:57 +00:00
|
|
|
picture = GST_VAAPI_PICTURE_NEW(JPEGBaseline, decoder);
|
2012-02-09 16:21:04 +00:00
|
|
|
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);
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (!fill_picture(decoder, picture, frame_hdr))
|
2012-02-09 16:21:04 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
/* Update presentation time */
|
2012-12-06 13:02:25 +00:00
|
|
|
picture->pts = GST_VAAPI_DECODER_CODEC_FRAME(decoder)->pts;
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_huffman_table(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
|
|
|
guchar *buf,
|
|
|
|
guint buf_size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (!gst_jpeg_parse_huffman_table(&priv->huf_tables, buf, buf_size, 0)) {
|
2012-04-19 15:50:14 +00:00
|
|
|
GST_DEBUG("failed to parse Huffman table");
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
2012-04-19 15:50:14 +00:00
|
|
|
priv->has_huf_table = TRUE;
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_quant_table(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
|
|
|
guchar *buf,
|
|
|
|
guint buf_size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (!gst_jpeg_parse_quant_table(&priv->quant_tables, buf, buf_size, 0)) {
|
2012-04-19 15:50:14 +00:00
|
|
|
GST_DEBUG("failed to parse quantization table");
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
|
|
|
priv->has_quant_table = TRUE;
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_restart_interval(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
|
|
|
guchar *buf,
|
|
|
|
guint buf_size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (!gst_jpeg_parse_restart_interval(&priv->mcu_restart, buf, buf_size, 0)) {
|
2012-04-19 15:50:14 +00:00
|
|
|
GST_DEBUG("failed to parse restart interval");
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_scan(
|
|
|
|
GstVaapiDecoderJpeg *decoder,
|
2012-06-04 07:52:19 +00:00
|
|
|
guchar *scan_header,
|
2012-04-19 15:50:14 +00:00
|
|
|
guint scan_header_size,
|
2012-06-04 07:52:19 +00:00
|
|
|
guchar *scan_data,
|
|
|
|
guint scan_data_size)
|
2012-04-19 15:50:14 +00:00
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
GstVaapiPicture *picture = priv->current_picture;
|
2012-07-31 09:51:57 +00:00
|
|
|
VASliceParameterBufferJPEGBaseline *slice_param;
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiSlice *gst_slice;
|
|
|
|
guint total_h_samples, total_v_samples;
|
|
|
|
GstJpegScanHdr scan_hdr;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!picture) {
|
2012-07-17 11:43:32 +00:00
|
|
|
GST_ERROR("There is no VAPicture before decoding scan.");
|
2012-04-19 15:50:14 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_INVALID_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fill_quantization_table(decoder, picture)) {
|
2012-07-17 11:43:32 +00:00
|
|
|
GST_ERROR("failed to fill in quantization table");
|
2012-02-09 16:21:04 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-04-19 15:50:14 +00:00
|
|
|
if (!fill_huffman_table(decoder, picture)) {
|
2012-07-17 11:43:32 +00:00
|
|
|
GST_ERROR("failed to fill in huffman table");
|
2012-02-09 16:21:04 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-06-04 07:52:19 +00:00
|
|
|
memset(&scan_hdr, 0, sizeof(scan_hdr));
|
2012-07-17 11:43:32 +00:00
|
|
|
if (!gst_jpeg_parse_scan_hdr(&scan_hdr, scan_header, scan_header_size, 0)) {
|
2012-06-04 07:52:19 +00:00
|
|
|
GST_DEBUG("Jpeg parsed scan failed.");
|
2012-07-17 11:43:32 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-06-04 07:52:19 +00:00
|
|
|
}
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-07-31 09:51:57 +00:00
|
|
|
gst_slice = GST_VAAPI_SLICE_NEW(JPEGBaseline, decoder, scan_data, scan_data_size);
|
2012-06-04 07:52:19 +00:00
|
|
|
gst_vaapi_picture_add_slice(picture, gst_slice);
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-06-04 07:52:19 +00:00
|
|
|
slice_param = gst_slice->param;
|
|
|
|
slice_param->num_components = scan_hdr.num_components;
|
|
|
|
for (i = 0; i < scan_hdr.num_components; i++) {
|
2012-06-25 15:10:49 +00:00
|
|
|
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;
|
2012-06-04 07:52:19 +00:00
|
|
|
}
|
|
|
|
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*/
|
2012-06-25 15:10:49 +00:00
|
|
|
if (slice_param->components[0].component_selector == priv->frame_hdr.components[0].identifier) {
|
2012-06-04 07:52:19 +00:00
|
|
|
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));
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (picture->slices && picture->slices->len)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_buffer(GstVaapiDecoderJpeg *decoder, GstBuffer *buffer)
|
|
|
|
{
|
2012-04-19 15:50:14 +00:00
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
GstVaapiDecoderStatus status = GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
2012-07-17 11:43:32 +00:00
|
|
|
GstJpegMarkerSegment seg;
|
|
|
|
GstJpegScanSegment scan_seg;
|
2012-02-09 16:21:04 +00:00
|
|
|
guchar *buf;
|
2012-07-17 11:43:32 +00:00
|
|
|
guint buf_size, ofs;
|
|
|
|
gboolean append_ecs;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
|
|
|
buf = GST_BUFFER_DATA(buffer);
|
|
|
|
buf_size = GST_BUFFER_SIZE(buffer);
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
memset(&scan_seg, 0, sizeof(scan_seg));
|
|
|
|
|
|
|
|
ofs = 0;
|
|
|
|
while (gst_jpeg_parse(&seg, buf, buf_size, ofs)) {
|
|
|
|
if (seg.size < 0) {
|
|
|
|
GST_DEBUG("buffer to short for parsing");
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
|
|
|
}
|
|
|
|
ofs += seg.size;
|
2012-02-09 16:21:04 +00:00
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
/* Decode scan, if complete */
|
|
|
|
if (seg.marker == GST_JPEG_MARKER_EOI && scan_seg.header_size > 0) {
|
|
|
|
scan_seg.data_size = seg.offset - scan_seg.data_offset;
|
|
|
|
scan_seg.is_valid = TRUE;
|
|
|
|
}
|
|
|
|
if (scan_seg.is_valid) {
|
|
|
|
status = decode_scan(
|
|
|
|
decoder,
|
|
|
|
buf + scan_seg.header_offset,
|
|
|
|
scan_seg.header_size,
|
|
|
|
buf + scan_seg.data_offset,
|
|
|
|
scan_seg.data_size
|
|
|
|
);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
break;
|
|
|
|
memset(&scan_seg, 0, sizeof(scan_seg));
|
|
|
|
}
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
append_ecs = TRUE;
|
|
|
|
switch (seg.marker) {
|
|
|
|
case GST_JPEG_MARKER_SOI:
|
|
|
|
priv->has_quant_table = FALSE;
|
|
|
|
priv->has_huf_table = FALSE;
|
|
|
|
priv->mcu_restart = 0;
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_SUCCESS;
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
2012-07-17 11:43:32 +00:00
|
|
|
case GST_JPEG_MARKER_EOI:
|
2012-08-24 08:36:16 +00:00
|
|
|
if (decode_current_picture(decoder)) {
|
|
|
|
/* Get out of the loop, trailing data is not needed */
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
2012-07-17 11:43:32 +00:00
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_DHT:
|
|
|
|
status = decode_huffman_table(decoder, buf + seg.offset, seg.size);
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_DQT:
|
2012-07-17 11:43:32 +00:00
|
|
|
status = decode_quant_table(decoder, buf + seg.offset, seg.size);
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_DRI:
|
2012-07-17 11:43:32 +00:00
|
|
|
status = decode_restart_interval(decoder, buf + seg.offset, seg.size);
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
2012-07-17 11:43:32 +00:00
|
|
|
case GST_JPEG_MARKER_DAC:
|
|
|
|
GST_ERROR("unsupported arithmetic coding mode");
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_SOS:
|
|
|
|
scan_seg.header_offset = seg.offset;
|
|
|
|
scan_seg.header_size = seg.size;
|
|
|
|
scan_seg.data_offset = seg.offset + seg.size;
|
|
|
|
scan_seg.data_size = 0;
|
|
|
|
append_ecs = FALSE;
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-07-17 11:43:32 +00:00
|
|
|
/* Restart marker */
|
|
|
|
if (seg.marker >= GST_JPEG_MARKER_RST_MIN &&
|
|
|
|
seg.marker <= GST_JPEG_MARKER_RST_MAX) {
|
|
|
|
append_ecs = FALSE;
|
|
|
|
break;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
2012-07-17 11:43:32 +00:00
|
|
|
|
|
|
|
/* Frame header */
|
|
|
|
if (seg.marker >= GST_JPEG_MARKER_SOF_MIN &&
|
|
|
|
seg.marker <= GST_JPEG_MARKER_SOF_MAX) {
|
|
|
|
status = decode_picture(
|
|
|
|
decoder,
|
|
|
|
seg.marker,
|
2012-12-06 13:02:25 +00:00
|
|
|
buf + seg.offset, seg.size
|
2012-07-17 11:43:32 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Application segments */
|
|
|
|
if (seg.marker >= GST_JPEG_MARKER_APP_MIN &&
|
|
|
|
seg.marker <= GST_JPEG_MARKER_APP_MAX) {
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_WARNING("unsupported marker (0x%02x)", seg.marker);
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
|
2012-04-19 15:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
/* Append entropy coded segments */
|
|
|
|
if (append_ecs)
|
|
|
|
scan_seg.data_size = seg.offset - scan_seg.data_offset;
|
2012-04-19 15:50:14 +00:00
|
|
|
|
2012-07-17 11:43:32 +00:00
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
break;
|
2012-04-19 15:50:14 +00:00
|
|
|
}
|
2012-08-24 08:36:16 +00:00
|
|
|
end:
|
2012-04-19 15:50:14 +00:00
|
|
|
return status;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 13:02:25 +00:00
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
ensure_decoder(GstVaapiDecoderJpeg *decoder)
|
2012-02-09 16:21:04 +00:00
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
|
2012-12-06 13:02:25 +00:00
|
|
|
g_return_val_if_fail(priv->is_constructed,
|
|
|
|
GST_VAAPI_DECODER_STATUS_ERROR_INIT_FAILED);
|
|
|
|
|
2012-02-09 16:21:04 +00:00
|
|
|
if (!priv->is_opened) {
|
2012-12-06 13:02:25 +00:00
|
|
|
priv->is_opened = gst_vaapi_decoder_jpeg_open(decoder);
|
2012-02-09 16:21:04 +00:00
|
|
|
if (!priv->is_opened)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CODEC;
|
|
|
|
}
|
2012-12-06 13:02:25 +00:00
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gint
|
|
|
|
scan_for_start_code(GstAdapter *adapter, guint ofs, guint size, guint32 *scp)
|
|
|
|
{
|
|
|
|
return (gint)gst_adapter_masked_scan_uint32_peek(adapter,
|
|
|
|
0xffff0000, 0xffd80000, ofs, size, scp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
gst_vaapi_decoder_jpeg_parse(GstVaapiDecoder *base_decoder,
|
2013-01-07 10:13:07 +00:00
|
|
|
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit *unit)
|
2012-12-06 13:02:25 +00:00
|
|
|
{
|
|
|
|
GstVaapiDecoderJpeg * const decoder = GST_VAAPI_DECODER_JPEG(base_decoder);
|
|
|
|
GstVaapiDecoderStatus status;
|
|
|
|
guint size, buf_size, flags = 0;
|
|
|
|
gint ofs;
|
|
|
|
|
|
|
|
status = ensure_decoder(decoder);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* Expect at least 4 bytes, SOI .. EOI */
|
|
|
|
size = gst_adapter_available(adapter);
|
|
|
|
if (size < 4)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
|
|
|
|
|
|
|
ofs = scan_for_start_code(adapter, 0, size, NULL);
|
|
|
|
if (ofs < 0)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
|
|
|
gst_adapter_flush(adapter, ofs);
|
|
|
|
size -= ofs;
|
|
|
|
|
|
|
|
ofs = G_UNLIKELY(size < 4) ? -1 :
|
|
|
|
scan_for_start_code(adapter, 2, size - 2, NULL);
|
|
|
|
if (ofs < 0) {
|
|
|
|
// Assume the whole packet is present if end-of-stream
|
|
|
|
if (!at_eos)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
|
|
|
ofs = size;
|
|
|
|
}
|
|
|
|
buf_size = ofs;
|
|
|
|
|
2013-01-07 10:13:07 +00:00
|
|
|
unit->size = buf_size;
|
2012-12-06 13:02:25 +00:00
|
|
|
|
|
|
|
flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
|
|
|
|
flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_END;
|
|
|
|
flags |= GST_VAAPI_DECODER_UNIT_FLAG_SLICE;
|
|
|
|
GST_VAAPI_DECODER_UNIT_FLAG_SET(unit, flags);
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
gst_vaapi_decoder_jpeg_decode(GstVaapiDecoder *base_decoder,
|
|
|
|
GstVaapiDecoderUnit *unit)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpeg * const decoder = GST_VAAPI_DECODER_JPEG(base_decoder);
|
|
|
|
GstVaapiDecoderStatus status;
|
|
|
|
|
|
|
|
status = ensure_decoder(decoder);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
unit->buffer = gst_buffer_create_sub(
|
|
|
|
GST_VAAPI_DECODER_CODEC_FRAME(decoder)->input_buffer,
|
|
|
|
unit->offset, unit->size);
|
|
|
|
if (!unit->buffer)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
|
|
|
|
|
|
|
|
status = decode_buffer(decoder, unit->buffer);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_finalize(GObject *object)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpeg * const decoder = GST_VAAPI_DECODER_JPEG(object);
|
|
|
|
|
|
|
|
gst_vaapi_decoder_jpeg_destroy(decoder);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(gst_vaapi_decoder_jpeg_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_constructed(GObject *object)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpeg * const decoder = GST_VAAPI_DECODER_JPEG(object);
|
|
|
|
GstVaapiDecoderJpegPrivate * const priv = decoder->priv;
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
|
|
|
|
parent_class = G_OBJECT_CLASS(gst_vaapi_decoder_jpeg_parent_class);
|
|
|
|
if (parent_class->constructed)
|
|
|
|
parent_class->constructed(object);
|
|
|
|
|
|
|
|
priv->is_constructed = gst_vaapi_decoder_jpeg_create(decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_class_init(GstVaapiDecoderJpegClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
|
|
|
GstVaapiDecoderClass * const decoder_class = GST_VAAPI_DECODER_CLASS(klass);
|
|
|
|
|
|
|
|
g_type_class_add_private(klass, sizeof(GstVaapiDecoderJpegPrivate));
|
|
|
|
|
|
|
|
object_class->finalize = gst_vaapi_decoder_jpeg_finalize;
|
|
|
|
object_class->constructed = gst_vaapi_decoder_jpeg_constructed;
|
|
|
|
|
2012-12-06 13:02:25 +00:00
|
|
|
decoder_class->parse = gst_vaapi_decoder_jpeg_parse;
|
2012-02-09 16:21:04 +00:00
|
|
|
decoder_class->decode = gst_vaapi_decoder_jpeg_decode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_jpeg_init(GstVaapiDecoderJpeg *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpegPrivate *priv;
|
|
|
|
|
|
|
|
priv = GST_VAAPI_DECODER_JPEG_GET_PRIVATE(decoder);
|
|
|
|
decoder->priv = priv;
|
|
|
|
priv->profile = GST_VAAPI_PROFILE_JPEG_BASELINE;
|
|
|
|
priv->width = 0;
|
|
|
|
priv->height = 0;
|
|
|
|
priv->current_picture = NULL;
|
2012-04-19 15:50:14 +00:00
|
|
|
priv->has_huf_table = FALSE;
|
|
|
|
priv->has_quant_table = FALSE;
|
|
|
|
priv->mcu_restart = 0;
|
2012-02-09 16:21:04 +00:00
|
|
|
priv->is_opened = FALSE;
|
|
|
|
priv->profile_changed = TRUE;
|
|
|
|
priv->is_constructed = FALSE;
|
2012-04-19 15:50:14 +00:00
|
|
|
memset(&priv->frame_hdr, 0, sizeof(priv->frame_hdr));
|
2012-06-04 08:20:13 +00:00
|
|
|
memset(&priv->huf_tables, 0, sizeof(priv->huf_tables));
|
2012-06-21 14:06:47 +00:00
|
|
|
memset(&priv->quant_tables, 0, sizeof(priv->quant_tables));
|
2012-02-09 16:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_decoder_jpeg_new:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @caps: a #GstCaps holding codec information
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiDecoder for JPEG decoding. The @caps can
|
|
|
|
* hold extra information like codec-data and pictured coded size.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiDecoder object
|
|
|
|
*/
|
|
|
|
GstVaapiDecoder *
|
|
|
|
gst_vaapi_decoder_jpeg_new(GstVaapiDisplay *display, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderJpeg *decoder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
|
|
|
g_return_val_if_fail(GST_IS_CAPS(caps), NULL);
|
|
|
|
|
|
|
|
decoder = g_object_new(
|
|
|
|
GST_VAAPI_TYPE_DECODER_JPEG,
|
|
|
|
"display", display,
|
|
|
|
"caps", caps,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (!decoder->priv->is_constructed) {
|
|
|
|
g_object_unref(decoder);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return GST_VAAPI_DECODER_CAST(decoder);
|
|
|
|
}
|