Path: blob/21.2-virgl/src/gallium/frontends/omx/vid_dec_common.c
4561 views
/**************************************************************************1*2* Copyright 2013 Advanced Micro Devices, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#if ENABLE_ST_OMX_TIZONIA28#include <tizkernel.h>29#endif3031#include "util/u_memory.h"32#include "vl/vl_winsys.h"33#include "vl/vl_video_buffer.h"34#include "util/u_surface.h"3536#include "vid_dec_common.h"37#include "vid_dec_h264_common.h"3839void vid_dec_NeedTarget(vid_dec_PrivateType *priv)40{41struct pipe_video_buffer templat = {};42struct vl_screen *omx_screen;43struct pipe_screen *pscreen;4445omx_screen = priv->screen;46assert(omx_screen);4748pscreen = omx_screen->pscreen;49assert(pscreen);5051if (!priv->target) {52memset(&templat, 0, sizeof(templat));5354templat.width = priv->codec->width;55templat.height = priv->codec->height;56templat.buffer_format = pscreen->get_video_param(57pscreen,58priv->profile,59PIPE_VIDEO_ENTRYPOINT_BITSTREAM,60PIPE_VIDEO_CAP_PREFERED_FORMAT61);62templat.interlaced = pscreen->get_video_param(63pscreen,64priv->profile,65PIPE_VIDEO_ENTRYPOINT_BITSTREAM,66PIPE_VIDEO_CAP_PREFERS_INTERLACED67);6869priv->target = priv->pipe->create_video_buffer(priv->pipe, &templat);70}71}7273void vid_dec_FillOutput(vid_dec_PrivateType *priv, struct pipe_video_buffer *buf,74OMX_BUFFERHEADERTYPE* output)75{76#if ENABLE_ST_OMX_TIZONIA77tiz_port_t *out_port = tiz_krn_get_port(tiz_get_krn(handleOf(priv)),78OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX);79OMX_VIDEO_PORTDEFINITIONTYPE *def = &out_port->portdef_.format.video;80#else81omx_base_PortType *port = priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];82OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video;83#endif8485struct pipe_sampler_view **views;86unsigned i, j;87unsigned width, height;8889views = buf->get_sampler_view_planes(buf);9091#if ENABLE_ST_OMX_TIZONIA92if (!output->pBuffer) {93struct pipe_video_buffer *dst_buf = NULL;94struct pipe_surface **dst_surface = NULL;95struct u_rect src_rect;96struct u_rect dst_rect;97struct vl_compositor *compositor = &priv->compositor;98struct vl_compositor_state *s = &priv->cstate;99enum vl_compositor_deinterlace deinterlace = VL_COMPOSITOR_WEAVE;100101dst_buf = util_hash_table_get(priv->video_buffer_map, output);102assert(dst_buf);103104dst_surface = dst_buf->get_surfaces(dst_buf);105assert(views);106107src_rect.x0 = 0;108src_rect.y0 = 0;109src_rect.x1 = def->nFrameWidth;110src_rect.y1 = def->nFrameHeight;111112dst_rect.x0 = 0;113dst_rect.y0 = 0;114dst_rect.x1 = def->nFrameWidth;115dst_rect.y1 = def->nFrameHeight;116117vl_compositor_clear_layers(s);118vl_compositor_set_buffer_layer(s, compositor, 0, buf,119&src_rect, NULL, deinterlace);120vl_compositor_set_layer_dst_area(s, 0, &dst_rect);121vl_compositor_render(s, compositor, dst_surface[0], NULL, false);122123priv->pipe->flush(priv->pipe, NULL, 0);124125return;126}127#endif128129for (i = 0; i < 2 /* NV12 */; i++) {130if (!views[i]) continue;131width = def->nFrameWidth;132height = def->nFrameHeight;133vl_video_buffer_adjust_size(&width, &height, i,134pipe_format_to_chroma_format(buf->buffer_format),135buf->interlaced);136for (j = 0; j < views[i]->texture->array_size; ++j) {137struct pipe_box box = {0, 0, j, width, height, 1};138struct pipe_transfer *transfer;139uint8_t *map, *dst;140map = priv->pipe->texture_map(priv->pipe, views[i]->texture, 0,141PIPE_MAP_READ, &box, &transfer);142if (!map)143return;144145dst = ((uint8_t*)output->pBuffer + output->nOffset) + j * def->nStride +146i * def->nFrameWidth * def->nFrameHeight;147util_copy_rect(dst,148views[i]->texture->format,149def->nStride * views[i]->texture->array_size, 0, 0,150box.width, box.height, map, transfer->stride, 0, 0);151152pipe_texture_unmap(priv->pipe, transfer);153}154}155}156157158