2011-04-05 23:06:20 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2009 Younes Manton.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
#include <util/u_memory.h>
|
|
|
|
#include <util/u_rect.h>
|
|
|
|
#include <util/u_video.h>
|
|
|
|
|
|
|
|
#include "vl_mpeg12_decoder.h"
|
|
|
|
#include "vl_defines.h"
|
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
#define SCALE_FACTOR_SNORM (32768.0f / 256.0f)
|
|
|
|
#define SCALE_FACTOR_SSCALED (1.0f / 256.0f)
|
2011-04-07 19:10:55 +01:00
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
static const enum pipe_format const_zscan_source_formats[] = {
|
|
|
|
PIPE_FORMAT_R16_SNORM,
|
|
|
|
PIPE_FORMAT_R16_SSCALED
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_zscan_source_formats =
|
|
|
|
sizeof(const_zscan_source_formats) / sizeof(enum pipe_format);
|
|
|
|
|
2011-04-10 21:32:56 +01:00
|
|
|
static const enum pipe_format const_idct_source_formats[] = {
|
2011-04-11 22:55:36 +01:00
|
|
|
PIPE_FORMAT_R16G16B16A16_SNORM,
|
|
|
|
PIPE_FORMAT_R16G16B16A16_SSCALED
|
2011-04-10 21:32:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_idct_source_formats =
|
|
|
|
sizeof(const_idct_source_formats) / sizeof(enum pipe_format);
|
|
|
|
|
|
|
|
static const enum pipe_format const_idct_intermediate_formats[] = {
|
|
|
|
PIPE_FORMAT_R16G16B16A16_FLOAT,
|
2011-04-11 22:55:36 +01:00
|
|
|
PIPE_FORMAT_R16G16B16A16_SNORM,
|
|
|
|
PIPE_FORMAT_R16G16B16A16_SSCALED,
|
|
|
|
PIPE_FORMAT_R32G32B32A32_FLOAT
|
2011-04-10 21:32:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_idct_intermediate_formats =
|
|
|
|
sizeof(const_idct_intermediate_formats) / sizeof(enum pipe_format);
|
|
|
|
|
|
|
|
static const enum pipe_format const_mc_source_formats[] = {
|
2011-04-11 22:55:36 +01:00
|
|
|
PIPE_FORMAT_R16_SNORM,
|
|
|
|
PIPE_FORMAT_R16_SSCALED
|
2011-04-10 21:32:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_mc_source_formats =
|
|
|
|
sizeof(const_mc_source_formats) / sizeof(enum pipe_format);
|
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
static bool
|
|
|
|
init_zscan_buffer(struct vl_mpeg12_buffer *buffer)
|
|
|
|
{
|
|
|
|
enum pipe_format formats[3];
|
|
|
|
|
|
|
|
struct pipe_sampler_view **source;
|
|
|
|
struct pipe_surface **destination;
|
|
|
|
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(buffer);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder*)buffer->base.decoder;
|
|
|
|
|
|
|
|
formats[0] = formats[1] = formats[2] = dec->zscan_source_format;
|
|
|
|
buffer->zscan_source = vl_video_buffer_init(dec->base.context, dec->pipe,
|
|
|
|
dec->blocks_per_line * BLOCK_WIDTH * BLOCK_HEIGHT,
|
|
|
|
dec->max_blocks / dec->blocks_per_line,
|
|
|
|
1, PIPE_VIDEO_CHROMA_FORMAT_444,
|
|
|
|
formats, PIPE_USAGE_STATIC);
|
|
|
|
if (!buffer->zscan_source)
|
|
|
|
goto error_source;
|
|
|
|
|
|
|
|
source = buffer->zscan_source->get_sampler_views(buffer->zscan_source);
|
|
|
|
if (!source)
|
|
|
|
goto error_sampler;
|
|
|
|
|
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
|
|
|
|
destination = buffer->idct_source->get_surfaces(buffer->idct_source);
|
|
|
|
else
|
|
|
|
destination = buffer->mc_source->get_surfaces(buffer->mc_source);
|
|
|
|
|
|
|
|
if (!destination)
|
|
|
|
goto error_surface;
|
|
|
|
|
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i)
|
|
|
|
if (!vl_zscan_init_buffer(i == 0 ? &dec->zscan_y : &dec->zscan_c,
|
|
|
|
&buffer->zscan[i], source[i], destination[i]))
|
|
|
|
goto error_plane;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error_plane:
|
|
|
|
for (; i > 0; --i)
|
|
|
|
vl_zscan_cleanup_buffer(&buffer->zscan[i - 1]);
|
|
|
|
|
|
|
|
error_surface:
|
|
|
|
error_sampler:
|
|
|
|
buffer->zscan_source->destroy(buffer->zscan_source);
|
|
|
|
|
|
|
|
error_source:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup_zscan_buffer(struct vl_mpeg12_buffer *buffer)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(buffer);
|
|
|
|
|
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i)
|
|
|
|
vl_zscan_cleanup_buffer(&buffer->zscan[i]);
|
|
|
|
buffer->zscan_source->destroy(buffer->zscan_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
init_idct_buffer(struct vl_mpeg12_buffer *buffer)
|
|
|
|
{
|
|
|
|
enum pipe_format formats[3];
|
|
|
|
|
|
|
|
struct pipe_sampler_view **idct_source_sv, **idct_intermediate_sv;
|
|
|
|
struct pipe_surface **idct_surfaces;
|
|
|
|
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(buffer);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder*)buffer->base.decoder;
|
|
|
|
|
|
|
|
formats[0] = formats[1] = formats[2] = dec->idct_source_format;
|
|
|
|
buffer->idct_source = vl_video_buffer_init(dec->base.context, dec->pipe,
|
|
|
|
dec->base.width / 4, dec->base.height, 1,
|
|
|
|
dec->base.chroma_format,
|
|
|
|
formats, PIPE_USAGE_STATIC);
|
|
|
|
if (!buffer->idct_source)
|
|
|
|
goto error_source;
|
|
|
|
|
|
|
|
formats[0] = formats[1] = formats[2] = dec->idct_intermediate_format;
|
|
|
|
buffer->idct_intermediate = vl_video_buffer_init(dec->base.context, dec->pipe,
|
|
|
|
dec->base.width / dec->nr_of_idct_render_targets,
|
|
|
|
dec->base.height / 4, dec->nr_of_idct_render_targets,
|
|
|
|
dec->base.chroma_format,
|
|
|
|
formats, PIPE_USAGE_STATIC);
|
|
|
|
|
|
|
|
if (!buffer->idct_intermediate)
|
|
|
|
goto error_intermediate;
|
|
|
|
|
|
|
|
idct_source_sv = buffer->idct_source->get_sampler_views(buffer->idct_source);
|
|
|
|
if (!idct_source_sv)
|
|
|
|
goto error_source_sv;
|
|
|
|
|
|
|
|
idct_intermediate_sv = buffer->idct_intermediate->get_sampler_views(buffer->idct_intermediate);
|
|
|
|
if (!idct_intermediate_sv)
|
|
|
|
goto error_intermediate_sv;
|
|
|
|
|
|
|
|
idct_surfaces = buffer->mc_source->get_surfaces(buffer->mc_source);
|
|
|
|
if (!idct_surfaces)
|
|
|
|
goto error_surfaces;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; ++i)
|
|
|
|
if (!vl_idct_init_buffer(i == 0 ? &dec->idct_y : &dec->idct_c,
|
|
|
|
&buffer->idct[i], idct_source_sv[i],
|
|
|
|
idct_intermediate_sv[i], idct_surfaces[i]))
|
|
|
|
goto error_plane;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error_plane:
|
|
|
|
for (; i > 0; --i)
|
|
|
|
vl_idct_cleanup_buffer(i == 1 ? &dec->idct_c : &dec->idct_y, &buffer->idct[i - 1]);
|
|
|
|
|
|
|
|
error_surfaces:
|
|
|
|
error_intermediate_sv:
|
|
|
|
error_source_sv:
|
|
|
|
buffer->idct_intermediate->destroy(buffer->idct_intermediate);
|
|
|
|
|
|
|
|
error_intermediate:
|
|
|
|
buffer->idct_source->destroy(buffer->idct_source);
|
|
|
|
|
|
|
|
error_source:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
static void
|
|
|
|
cleanup_idct_buffer(struct vl_mpeg12_buffer *buf)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder*)buf->base.decoder;
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
vl_idct_cleanup_buffer(&dec->idct_y, &buf->idct[0]);
|
|
|
|
vl_idct_cleanup_buffer(&dec->idct_c, &buf->idct[1]);
|
|
|
|
vl_idct_cleanup_buffer(&dec->idct_c, &buf->idct[2]);
|
2011-04-23 02:37:05 +01:00
|
|
|
buf->idct_source->destroy(buf->idct_source);
|
|
|
|
buf->idct_intermediate->destroy(buf->idct_intermediate);
|
2011-04-10 19:30:27 +01:00
|
|
|
}
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
static void
|
|
|
|
vl_mpeg12_buffer_destroy(struct pipe_video_decode_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
2011-04-10 19:30:27 +01:00
|
|
|
struct vl_mpeg12_decoder *dec;
|
2011-04-14 21:31:40 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder*)buf->base.decoder;
|
|
|
|
assert(dec);
|
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
cleanup_zscan_buffer(buf);
|
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
|
|
|
|
cleanup_idct_buffer(buf);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
buf->mc_source->destroy(buf->mc_source);
|
2011-04-05 23:06:20 +01:00
|
|
|
vl_vb_cleanup(&buf->vertex_stream);
|
2011-04-14 21:31:40 +01:00
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i)
|
|
|
|
vl_mc_cleanup_buffer(&buf->mc[i]);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
FREE(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vl_mpeg12_buffer_map(struct pipe_video_decode_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
2011-04-23 12:24:35 +01:00
|
|
|
|
|
|
|
struct pipe_sampler_view **sampler_views;
|
|
|
|
unsigned i;
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder *)buf->base.decoder;
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
vl_vb_map(&buf->vertex_stream, dec->pipe);
|
2011-04-23 12:24:35 +01:00
|
|
|
|
|
|
|
sampler_views = buf->zscan_source->get_sampler_views(buf->zscan_source);
|
|
|
|
|
|
|
|
assert(sampler_views);
|
|
|
|
|
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i) {
|
|
|
|
struct pipe_resource *tex = sampler_views[i]->texture;
|
|
|
|
struct pipe_box rect =
|
|
|
|
{
|
|
|
|
0, 0, 0,
|
|
|
|
tex->width0,
|
|
|
|
tex->height0,
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
|
|
|
buf->tex_transfer[i] = dec->pipe->get_transfer
|
|
|
|
(
|
|
|
|
dec->pipe, tex,
|
|
|
|
0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
|
|
|
|
&rect
|
|
|
|
);
|
|
|
|
|
|
|
|
buf->texels[i] = dec->pipe->transfer_map(dec->pipe, buf->tex_transfer[i]);
|
|
|
|
}
|
2011-04-05 23:06:20 +01:00
|
|
|
}
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
static struct pipe_ycbcr_block *
|
|
|
|
vl_mpeg12_buffer_get_ycbcr_stream(struct pipe_video_decode_buffer *buffer, int component)
|
2011-04-20 12:44:26 +01:00
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
|
|
|
|
|
|
|
assert(buf);
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
return vl_vb_get_ycbcr_stream(&buf->vertex_stream, component);
|
2011-04-20 12:44:26 +01:00
|
|
|
}
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
static short *
|
|
|
|
vl_mpeg12_buffer_get_ycbcr_buffer(struct pipe_video_decode_buffer *buffer, int component)
|
2011-04-20 12:44:26 +01:00
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
|
|
|
|
|
|
|
assert(buf);
|
2011-04-23 12:24:35 +01:00
|
|
|
assert(component < VL_MAX_PLANES);
|
2011-04-20 12:44:26 +01:00
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
return buf->texels[component];
|
2011-04-20 12:44:26 +01:00
|
|
|
}
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
static unsigned
|
|
|
|
vl_mpeg12_buffer_get_mv_stream_stride(struct pipe_video_decode_buffer *buffer)
|
2011-04-05 23:06:20 +01:00
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
|
|
|
|
|
|
|
assert(buf);
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
return vl_vb_get_mv_stream_stride(&buf->vertex_stream);
|
|
|
|
}
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
static struct pipe_motionvector *
|
|
|
|
vl_mpeg12_buffer_get_mv_stream(struct pipe_video_decode_buffer *buffer, int ref_frame)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
return vl_vb_get_mv_stream(&buf->vertex_stream, ref_frame);
|
2011-04-05 23:06:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vl_mpeg12_buffer_unmap(struct pipe_video_decode_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer;
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
2011-04-23 12:24:35 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder *)buf->base.decoder;
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
vl_vb_unmap(&buf->vertex_stream, dec->pipe);
|
2011-04-23 12:24:35 +01:00
|
|
|
|
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i) {
|
|
|
|
dec->pipe->transfer_unmap(dec->pipe, buf->tex_transfer[i]);
|
|
|
|
dec->pipe->transfer_destroy(dec->pipe, buf->tex_transfer[i]);
|
|
|
|
}
|
2011-04-05 23:06:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vl_mpeg12_destroy(struct pipe_video_decoder *decoder)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder*)decoder;
|
|
|
|
|
|
|
|
assert(decoder);
|
|
|
|
|
|
|
|
/* Asserted in softpipe_delete_fs_state() for some reason */
|
|
|
|
dec->pipe->bind_vs_state(dec->pipe, NULL);
|
|
|
|
dec->pipe->bind_fs_state(dec->pipe, NULL);
|
|
|
|
|
|
|
|
dec->pipe->delete_depth_stencil_alpha_state(dec->pipe, dec->dsa);
|
|
|
|
|
2011-04-16 12:04:04 +01:00
|
|
|
vl_mc_cleanup(&dec->mc_y);
|
|
|
|
vl_mc_cleanup(&dec->mc_c);
|
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) {
|
|
|
|
vl_idct_cleanup(&dec->idct_y);
|
|
|
|
vl_idct_cleanup(&dec->idct_c);
|
|
|
|
}
|
2011-04-16 12:04:04 +01:00
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
vl_zscan_cleanup(&dec->zscan_y);
|
|
|
|
vl_zscan_cleanup(&dec->zscan_c);
|
|
|
|
|
2011-04-17 22:21:32 +01:00
|
|
|
dec->pipe->delete_vertex_elements_state(dec->pipe, dec->ves_ycbcr);
|
2011-04-17 20:31:31 +01:00
|
|
|
dec->pipe->delete_vertex_elements_state(dec->pipe, dec->ves_mv);
|
2011-04-14 21:31:40 +01:00
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
pipe_resource_reference(&dec->quads.buffer, NULL);
|
2011-04-17 17:53:22 +01:00
|
|
|
pipe_resource_reference(&dec->pos.buffer, NULL);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
FREE(dec);
|
|
|
|
}
|
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
static struct pipe_video_decode_buffer *
|
|
|
|
vl_mpeg12_create_buffer(struct pipe_video_decoder *decoder)
|
|
|
|
{
|
2011-04-10 21:32:56 +01:00
|
|
|
enum pipe_format formats[3];
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
struct vl_mpeg12_decoder *dec = (struct vl_mpeg12_decoder*)decoder;
|
|
|
|
struct vl_mpeg12_buffer *buffer;
|
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
struct pipe_sampler_view **mc_source_sv;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
buffer = CALLOC_STRUCT(vl_mpeg12_buffer);
|
|
|
|
if (buffer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buffer->base.decoder = decoder;
|
|
|
|
buffer->base.destroy = vl_mpeg12_buffer_destroy;
|
|
|
|
buffer->base.map = vl_mpeg12_buffer_map;
|
2011-04-23 12:24:35 +01:00
|
|
|
buffer->base.get_ycbcr_stream = vl_mpeg12_buffer_get_ycbcr_stream;
|
|
|
|
buffer->base.get_ycbcr_buffer = vl_mpeg12_buffer_get_ycbcr_buffer;
|
2011-04-20 12:44:26 +01:00
|
|
|
buffer->base.get_mv_stream_stride = vl_mpeg12_buffer_get_mv_stream_stride;
|
|
|
|
buffer->base.get_mv_stream = vl_mpeg12_buffer_get_mv_stream;
|
2011-04-05 23:06:20 +01:00
|
|
|
buffer->base.unmap = vl_mpeg12_buffer_unmap;
|
|
|
|
|
2011-04-17 17:53:22 +01:00
|
|
|
vl_vb_init(&buffer->vertex_stream, dec->pipe,
|
|
|
|
dec->base.width / MACROBLOCK_WIDTH,
|
|
|
|
dec->base.height / MACROBLOCK_HEIGHT);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-10 21:32:56 +01:00
|
|
|
formats[0] = formats[1] = formats[2] =dec->mc_source_format;
|
2011-04-07 19:10:55 +01:00
|
|
|
buffer->mc_source = vl_video_buffer_init(dec->base.context, dec->pipe,
|
2011-04-05 23:06:20 +01:00
|
|
|
dec->base.width, dec->base.height, 1,
|
2011-04-12 18:21:07 +01:00
|
|
|
dec->base.chroma_format,
|
2011-04-10 21:32:56 +01:00
|
|
|
formats, PIPE_USAGE_STATIC);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
if (!buffer->mc_source)
|
|
|
|
goto error_mc_source;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-10 17:46:31 +01:00
|
|
|
mc_source_sv = buffer->mc_source->get_sampler_views(buffer->mc_source);
|
|
|
|
if (!mc_source_sv)
|
|
|
|
goto error_mc_source_sv;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-16 12:04:04 +01:00
|
|
|
if(!vl_mc_init_buffer(&dec->mc_y, &buffer->mc[0], mc_source_sv[0]))
|
2011-04-05 23:06:20 +01:00
|
|
|
goto error_mc_y;
|
|
|
|
|
2011-04-16 12:04:04 +01:00
|
|
|
if(!vl_mc_init_buffer(&dec->mc_c, &buffer->mc[1], mc_source_sv[1]))
|
2011-04-05 23:06:20 +01:00
|
|
|
goto error_mc_cb;
|
|
|
|
|
2011-04-16 12:04:04 +01:00
|
|
|
if(!vl_mc_init_buffer(&dec->mc_c, &buffer->mc[2], mc_source_sv[2]))
|
2011-04-05 23:06:20 +01:00
|
|
|
goto error_mc_cr;
|
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
|
|
|
|
if (!init_idct_buffer(buffer))
|
|
|
|
goto error_idct;
|
|
|
|
|
|
|
|
if (!init_zscan_buffer(buffer))
|
|
|
|
goto error_zscan;
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
return &buffer->base;
|
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
error_zscan:
|
|
|
|
// TODO Cleanup error handling
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
error_mc_cr:
|
2011-04-14 21:31:40 +01:00
|
|
|
vl_mc_cleanup_buffer(&buffer->mc[1]);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
error_mc_cb:
|
2011-04-14 21:31:40 +01:00
|
|
|
vl_mc_cleanup_buffer(&buffer->mc[0]);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
error_mc_y:
|
2011-04-10 17:46:31 +01:00
|
|
|
error_mc_source_sv:
|
2011-04-07 19:10:55 +01:00
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
|
2011-04-10 19:30:27 +01:00
|
|
|
cleanup_idct_buffer(buffer);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-10 19:30:27 +01:00
|
|
|
error_idct:
|
2011-04-07 19:10:55 +01:00
|
|
|
buffer->mc_source->destroy(buffer->mc_source);
|
|
|
|
|
|
|
|
error_mc_source:
|
2011-04-05 23:06:20 +01:00
|
|
|
vl_vb_cleanup(&buffer->vertex_stream);
|
|
|
|
|
|
|
|
error_vertex_stream:
|
|
|
|
FREE(buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer *buffer,
|
2011-04-23 12:24:35 +01:00
|
|
|
unsigned num_ycbcr_blocks[3],
|
2011-04-05 23:06:20 +01:00
|
|
|
struct pipe_video_buffer *refs[2],
|
|
|
|
struct pipe_video_buffer *dst,
|
|
|
|
struct pipe_fence_handle **fence)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer *)buffer;
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
|
|
|
|
2011-04-14 21:31:40 +01:00
|
|
|
struct pipe_sampler_view **sv[2];
|
2011-04-05 23:06:20 +01:00
|
|
|
struct pipe_surface **surfaces;
|
|
|
|
|
2011-04-17 17:53:22 +01:00
|
|
|
struct pipe_vertex_buffer vb[3];
|
|
|
|
|
2011-04-14 21:31:40 +01:00
|
|
|
unsigned i, j;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
dec = (struct vl_mpeg12_decoder *)buf->base.decoder;
|
|
|
|
assert(dec);
|
|
|
|
|
2011-04-14 21:31:40 +01:00
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
sv[i] = refs[i] ? refs[i]->get_sampler_views(refs[i]) : NULL;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
surfaces = dst->get_surfaces(dst);
|
|
|
|
|
2011-04-17 17:53:22 +01:00
|
|
|
vb[0] = dec->quads;
|
|
|
|
vb[1] = dec->pos;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-17 20:31:31 +01:00
|
|
|
dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_mv);
|
2011-04-05 23:06:20 +01:00
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i) {
|
2011-04-16 12:40:19 +01:00
|
|
|
vl_mc_set_surface(&buf->mc[i], surfaces[i]);
|
2011-04-14 21:31:40 +01:00
|
|
|
|
|
|
|
for (j = 0; j < 2; ++j) {
|
|
|
|
if (sv[j] == NULL) continue;
|
|
|
|
|
2011-04-17 17:53:22 +01:00
|
|
|
vb[2] = vl_vb_get_mv(&buf->vertex_stream, j);;
|
|
|
|
dec->pipe->set_vertex_buffers(dec->pipe, 3, vb);
|
|
|
|
|
|
|
|
vl_mc_render_ref(&buf->mc[i], sv[j][i]);
|
2011-04-14 21:31:40 +01:00
|
|
|
}
|
2011-04-17 17:53:22 +01:00
|
|
|
}
|
2011-04-13 21:45:54 +01:00
|
|
|
|
2011-04-17 22:21:32 +01:00
|
|
|
dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_ycbcr);
|
2011-04-17 17:53:22 +01:00
|
|
|
for (i = 0; i < VL_MAX_PLANES; ++i) {
|
2011-04-23 12:24:35 +01:00
|
|
|
if (num_ycbcr_blocks[i] == 0) continue;
|
2011-04-17 22:21:32 +01:00
|
|
|
|
|
|
|
vb[1] = vl_vb_get_ycbcr(&buf->vertex_stream, i);
|
|
|
|
dec->pipe->set_vertex_buffers(dec->pipe, 2, vb);
|
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
vl_zscan_render(&buf->zscan[i] , num_ycbcr_blocks[i]);
|
2011-04-23 02:37:05 +01:00
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
|
2011-04-23 12:24:35 +01:00
|
|
|
vl_idct_flush(i == 0 ? &dec->idct_y : &dec->idct_c, &buf->idct[i], num_ycbcr_blocks[i]);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-23 12:24:35 +01:00
|
|
|
vl_mc_render_ycbcr(&buf->mc[i], num_ycbcr_blocks[i]);
|
2011-04-05 23:06:20 +01:00
|
|
|
}
|
2011-04-17 17:53:22 +01:00
|
|
|
|
2011-04-14 21:31:40 +01:00
|
|
|
dec->pipe->flush(dec->pipe, fence);
|
2011-04-05 23:06:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
init_pipe_state(struct vl_mpeg12_decoder *dec)
|
|
|
|
{
|
|
|
|
struct pipe_depth_stencil_alpha_state dsa;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
memset(&dsa, 0, sizeof dsa);
|
|
|
|
dsa.depth.enabled = 0;
|
|
|
|
dsa.depth.writemask = 0;
|
|
|
|
dsa.depth.func = PIPE_FUNC_ALWAYS;
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
dsa.stencil[i].enabled = 0;
|
|
|
|
dsa.stencil[i].func = PIPE_FUNC_ALWAYS;
|
|
|
|
dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP;
|
|
|
|
dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP;
|
|
|
|
dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP;
|
|
|
|
dsa.stencil[i].valuemask = 0;
|
|
|
|
dsa.stencil[i].writemask = 0;
|
|
|
|
}
|
|
|
|
dsa.alpha.enabled = 0;
|
|
|
|
dsa.alpha.func = PIPE_FUNC_ALWAYS;
|
|
|
|
dsa.alpha.ref_value = 0;
|
|
|
|
dec->dsa = dec->pipe->create_depth_stencil_alpha_state(dec->pipe, &dsa);
|
|
|
|
dec->pipe->bind_depth_stencil_alpha_state(dec->pipe, dec->dsa);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-10 21:32:56 +01:00
|
|
|
static enum pipe_format
|
|
|
|
find_first_supported_format(struct vl_mpeg12_decoder *dec,
|
|
|
|
const enum pipe_format formats[],
|
|
|
|
unsigned num_formats,
|
|
|
|
enum pipe_texture_target target)
|
|
|
|
{
|
|
|
|
struct pipe_screen *screen;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
screen = dec->pipe->screen;
|
|
|
|
|
|
|
|
for (i = 0; i < num_formats; ++i)
|
|
|
|
if (screen->is_format_supported(dec->pipe->screen, formats[i], target, 1,
|
|
|
|
PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET))
|
|
|
|
return formats[i];
|
|
|
|
|
|
|
|
return PIPE_FORMAT_NONE;
|
|
|
|
}
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
static bool
|
2011-04-23 02:37:05 +01:00
|
|
|
init_zscan(struct vl_mpeg12_decoder *dec)
|
|
|
|
{
|
|
|
|
struct pipe_sampler_view *layout;
|
|
|
|
|
|
|
|
unsigned num_channels;
|
|
|
|
|
|
|
|
assert(dec);
|
|
|
|
|
|
|
|
dec->blocks_per_line = 4;
|
|
|
|
dec->max_blocks =
|
|
|
|
(dec->base.width * dec->base.height) /
|
|
|
|
(BLOCK_WIDTH * BLOCK_HEIGHT);
|
|
|
|
|
|
|
|
dec->zscan_source_format = find_first_supported_format(dec, const_zscan_source_formats,
|
|
|
|
num_zscan_source_formats, PIPE_TEXTURE_2D);
|
|
|
|
|
|
|
|
if (dec->zscan_source_format == PIPE_FORMAT_NONE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
layout = vl_zscan_linear(dec->pipe, dec->blocks_per_line);
|
|
|
|
|
|
|
|
num_channels = dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT ? 4 : 1;
|
|
|
|
|
|
|
|
if (!vl_zscan_init(&dec->zscan_y, dec->pipe, dec->base.width, dec->base.height,
|
|
|
|
dec->blocks_per_line, dec->max_blocks, num_channels))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vl_zscan_set_layout(&dec->zscan_y, layout);
|
|
|
|
|
|
|
|
if (!vl_zscan_init(&dec->zscan_c, dec->pipe, dec->chroma_width, dec->chroma_height,
|
|
|
|
dec->blocks_per_line, dec->max_blocks, num_channels))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vl_zscan_set_layout(&dec->zscan_c, layout);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
init_idct(struct vl_mpeg12_decoder *dec)
|
2011-04-05 23:06:20 +01:00
|
|
|
{
|
2011-04-11 22:55:36 +01:00
|
|
|
struct pipe_sampler_view *matrix, *transpose;
|
|
|
|
float matrix_scale, transpose_scale;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-10 19:49:18 +01:00
|
|
|
dec->nr_of_idct_render_targets = dec->pipe->screen->get_param(dec->pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS);
|
|
|
|
|
|
|
|
// more than 4 render targets usually doesn't makes any seens
|
|
|
|
dec->nr_of_idct_render_targets = MIN2(dec->nr_of_idct_render_targets, 4);
|
2011-04-10 18:08:11 +01:00
|
|
|
|
2011-04-10 21:32:56 +01:00
|
|
|
dec->idct_source_format = find_first_supported_format(dec, const_idct_source_formats,
|
|
|
|
num_idct_source_formats, PIPE_TEXTURE_2D);
|
|
|
|
|
|
|
|
if (dec->idct_source_format == PIPE_FORMAT_NONE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dec->idct_intermediate_format = find_first_supported_format(dec, const_idct_intermediate_formats,
|
|
|
|
num_idct_intermediate_formats, PIPE_TEXTURE_3D);
|
|
|
|
|
|
|
|
if (dec->idct_intermediate_format == PIPE_FORMAT_NONE)
|
|
|
|
return false;
|
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
switch (dec->idct_source_format) {
|
|
|
|
case PIPE_FORMAT_R16G16B16A16_SSCALED:
|
|
|
|
matrix_scale = SCALE_FACTOR_SSCALED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPE_FORMAT_R16G16B16A16_SNORM:
|
|
|
|
matrix_scale = SCALE_FACTOR_SNORM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dec->idct_intermediate_format == PIPE_FORMAT_R16G16B16A16_FLOAT ||
|
|
|
|
dec->idct_intermediate_format == PIPE_FORMAT_R32G32B32A32_FLOAT)
|
|
|
|
transpose_scale = 1.0f;
|
|
|
|
else
|
|
|
|
transpose_scale = matrix_scale = sqrt(matrix_scale);
|
|
|
|
|
|
|
|
if (dec->mc_source_format == PIPE_FORMAT_R16_SSCALED)
|
|
|
|
transpose_scale /= SCALE_FACTOR_SSCALED;
|
|
|
|
|
|
|
|
if (!(matrix = vl_idct_upload_matrix(dec->pipe, matrix_scale)))
|
|
|
|
goto error_matrix;
|
|
|
|
|
|
|
|
if (matrix_scale != transpose_scale) {
|
|
|
|
if (!(transpose = vl_idct_upload_matrix(dec->pipe, transpose_scale)))
|
|
|
|
goto error_transpose;
|
|
|
|
} else
|
|
|
|
pipe_sampler_view_reference(&transpose, matrix);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
if (!vl_idct_init(&dec->idct_y, dec->pipe, dec->base.width, dec->base.height,
|
2011-04-19 20:06:59 +01:00
|
|
|
dec->nr_of_idct_render_targets, matrix, transpose))
|
2011-04-11 22:55:36 +01:00
|
|
|
goto error_y;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
if(!vl_idct_init(&dec->idct_c, dec->pipe, dec->chroma_width, dec->chroma_height,
|
2011-04-11 22:55:36 +01:00
|
|
|
dec->nr_of_idct_render_targets, matrix, transpose))
|
|
|
|
goto error_c;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
pipe_sampler_view_reference(&matrix, NULL);
|
|
|
|
pipe_sampler_view_reference(&transpose, NULL);
|
2011-04-05 23:06:20 +01:00
|
|
|
return true;
|
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
error_c:
|
2011-04-05 23:06:20 +01:00
|
|
|
vl_idct_cleanup(&dec->idct_y);
|
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
error_y:
|
|
|
|
pipe_sampler_view_reference(&transpose, NULL);
|
|
|
|
|
|
|
|
error_transpose:
|
|
|
|
pipe_sampler_view_reference(&matrix, NULL);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
error_matrix:
|
2011-04-05 23:06:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pipe_video_decoder *
|
|
|
|
vl_create_mpeg12_decoder(struct pipe_video_context *context,
|
|
|
|
struct pipe_context *pipe,
|
|
|
|
enum pipe_video_profile profile,
|
2011-04-07 19:10:55 +01:00
|
|
|
enum pipe_video_entrypoint entrypoint,
|
2011-04-05 23:06:20 +01:00
|
|
|
enum pipe_video_chroma_format chroma_format,
|
|
|
|
unsigned width, unsigned height)
|
|
|
|
{
|
|
|
|
struct vl_mpeg12_decoder *dec;
|
2011-04-11 22:55:36 +01:00
|
|
|
float mc_scale;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
assert(u_reduce_video_profile(profile) == PIPE_VIDEO_CODEC_MPEG12);
|
|
|
|
|
|
|
|
dec = CALLOC_STRUCT(vl_mpeg12_decoder);
|
|
|
|
|
|
|
|
if (!dec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dec->base.context = context;
|
|
|
|
dec->base.profile = profile;
|
2011-04-07 19:10:55 +01:00
|
|
|
dec->base.entrypoint = entrypoint;
|
2011-04-05 23:06:20 +01:00
|
|
|
dec->base.chroma_format = chroma_format;
|
|
|
|
dec->base.width = width;
|
|
|
|
dec->base.height = height;
|
|
|
|
|
|
|
|
dec->base.destroy = vl_mpeg12_destroy;
|
|
|
|
dec->base.create_buffer = vl_mpeg12_create_buffer;
|
|
|
|
dec->base.flush_buffer = vl_mpeg12_decoder_flush_buffer;
|
|
|
|
|
2011-04-17 17:53:22 +01:00
|
|
|
dec->base.width = align(width, MACROBLOCK_WIDTH);
|
|
|
|
dec->base.height = align(height, MACROBLOCK_HEIGHT);
|
|
|
|
|
2011-04-05 23:06:20 +01:00
|
|
|
dec->pipe = pipe;
|
|
|
|
|
2011-04-19 20:06:59 +01:00
|
|
|
dec->quads = vl_vb_upload_quads(dec->pipe);
|
2011-04-17 17:53:22 +01:00
|
|
|
dec->pos = vl_vb_upload_pos(
|
|
|
|
dec->pipe,
|
|
|
|
dec->base.width / MACROBLOCK_WIDTH,
|
|
|
|
dec->base.height / MACROBLOCK_HEIGHT
|
|
|
|
);
|
|
|
|
|
2011-04-17 22:21:32 +01:00
|
|
|
dec->ves_ycbcr = vl_vb_get_ves_ycbcr(dec->pipe);
|
2011-04-17 20:31:31 +01:00
|
|
|
dec->ves_mv = vl_vb_get_ves_mv(dec->pipe);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-07 19:10:55 +01:00
|
|
|
/* TODO: Implement 422, 444 */
|
|
|
|
assert(dec->base.chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-10 21:32:56 +01:00
|
|
|
dec->mc_source_format = find_first_supported_format(dec, const_mc_source_formats,
|
|
|
|
num_mc_source_formats, PIPE_TEXTURE_3D);
|
|
|
|
|
|
|
|
if (dec->mc_source_format == PIPE_FORMAT_NONE)
|
2011-04-11 22:55:36 +01:00
|
|
|
return NULL;
|
|
|
|
|
2011-04-23 02:37:05 +01:00
|
|
|
if (dec->base.chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
|
|
|
|
dec->chroma_width = dec->base.width / 2;
|
|
|
|
dec->chroma_height = dec->base.height / 2;
|
|
|
|
} else if (dec->base.chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
|
|
|
|
dec->chroma_width = dec->base.width;
|
|
|
|
dec->chroma_height = dec->base.height / 2;
|
|
|
|
} else {
|
|
|
|
dec->chroma_width = dec->base.width;
|
|
|
|
dec->chroma_height = dec->base.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!init_zscan(dec))
|
|
|
|
return NULL; // TODO error handling
|
|
|
|
|
2011-04-11 22:55:36 +01:00
|
|
|
if (entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) {
|
2011-04-23 02:37:05 +01:00
|
|
|
if (!init_idct(dec))
|
2011-04-11 22:55:36 +01:00
|
|
|
goto error_idct;
|
|
|
|
if (dec->mc_source_format == PIPE_FORMAT_R16_SSCALED)
|
|
|
|
mc_scale = SCALE_FACTOR_SSCALED;
|
|
|
|
else
|
|
|
|
mc_scale = 1.0f;
|
|
|
|
} else {
|
|
|
|
switch (dec->mc_source_format) {
|
|
|
|
case PIPE_FORMAT_R16_SNORM:
|
|
|
|
mc_scale = SCALE_FACTOR_SNORM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPE_FORMAT_R16_SSCALED:
|
|
|
|
mc_scale = SCALE_FACTOR_SSCALED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-16 15:22:53 +01:00
|
|
|
if (!vl_mc_init(&dec->mc_y, dec->pipe, dec->base.width, dec->base.height, MACROBLOCK_HEIGHT, mc_scale))
|
2011-04-16 12:04:04 +01:00
|
|
|
goto error_mc_y;
|
|
|
|
|
2011-04-16 15:22:53 +01:00
|
|
|
// TODO
|
|
|
|
if (!vl_mc_init(&dec->mc_c, dec->pipe, dec->base.width, dec->base.height, BLOCK_HEIGHT, mc_scale))
|
2011-04-16 12:04:04 +01:00
|
|
|
goto error_mc_c;
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
if (!init_pipe_state(dec))
|
|
|
|
goto error_pipe_state;
|
|
|
|
|
|
|
|
return &dec->base;
|
|
|
|
|
|
|
|
error_pipe_state:
|
2011-04-16 12:04:04 +01:00
|
|
|
vl_mc_cleanup(&dec->mc_c);
|
|
|
|
|
|
|
|
error_mc_c:
|
|
|
|
vl_mc_cleanup(&dec->mc_y);
|
2011-04-05 23:06:20 +01:00
|
|
|
|
2011-04-16 12:04:04 +01:00
|
|
|
error_mc_y:
|
2011-04-07 19:10:55 +01:00
|
|
|
if (entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) {
|
|
|
|
vl_idct_cleanup(&dec->idct_y);
|
|
|
|
vl_idct_cleanup(&dec->idct_c);
|
|
|
|
}
|
2011-04-05 23:06:20 +01:00
|
|
|
|
|
|
|
error_idct:
|
|
|
|
FREE(dec);
|
|
|
|
return NULL;
|
|
|
|
}
|