Path: blob/21.2-virgl/src/gallium/frontends/omx/tizonia/h264einport.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#include <assert.h>28#include <string.h>29#include <limits.h>3031#include <tizplatform.h>32#include <tizkernel.h>3334#include "vl/vl_winsys.h"3536#include "h264e.h"37#include "h264einport.h"38#include "h264einport_decls.h"39#include "vid_enc_common.h"4041static OMX_ERRORTYPE enc_AllocateBackTexture(OMX_HANDLETYPE ap_hdl,42OMX_U32 idx,43struct pipe_resource **resource,44struct pipe_transfer **transfer,45OMX_U8 **map)46{47vid_enc_PrivateType * priv = tiz_get_prc(ap_hdl);48tiz_port_t * port = tiz_krn_get_port(tiz_get_krn(ap_hdl), idx);49struct pipe_resource buf_templ;50struct pipe_box box = {};51OMX_U8 *ptr;5253memset(&buf_templ, 0, sizeof buf_templ);54buf_templ.target = PIPE_TEXTURE_2D;55buf_templ.format = PIPE_FORMAT_I8_UNORM;56buf_templ.bind = PIPE_BIND_LINEAR;57buf_templ.usage = PIPE_USAGE_STAGING;58buf_templ.flags = 0;59buf_templ.width0 = port->portdef_.format.video.nFrameWidth;60buf_templ.height0 = port->portdef_.format.video.nFrameHeight * 3 / 2;61buf_templ.depth0 = 1;62buf_templ.array_size = 1;6364*resource = priv->s_pipe->screen->resource_create(priv->s_pipe->screen, &buf_templ);65if (!*resource)66return OMX_ErrorInsufficientResources;6768box.width = (*resource)->width0;69box.height = (*resource)->height0;70box.depth = (*resource)->depth0;71ptr = priv->s_pipe->texture_map(priv->s_pipe, *resource, 0, PIPE_MAP_WRITE, &box, transfer);72if (map)73*map = ptr;7475return OMX_ErrorNone;76}7778/*79* h264einport class80*/8182static void * h264e_inport_ctor(void * ap_obj, va_list * app)83{84return super_ctor(typeOf(ap_obj, "h264einport"), ap_obj, app);85}8687static void * h264e_inport_dtor(void * ap_obj)88{89return super_dtor(typeOf(ap_obj, "h264einport"), ap_obj);90}9192/*93* from tiz_api94*/9596static OMX_ERRORTYPE h264e_inport_AllocateBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl,97OMX_BUFFERHEADERTYPE ** buf, OMX_U32 idx,98OMX_PTR private, OMX_U32 size)99{100struct input_buf_private *inp;101OMX_ERRORTYPE r;102103r = super_UseBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl,104buf, idx, private, size, NULL);105if (r)106return r;107108inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private);109if (!inp) {110super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf);111return OMX_ErrorInsufficientResources;112}113114list_inithead(&inp->tasks);115116r = enc_AllocateBackTexture(ap_hdl, idx, &inp->resource, &inp->transfer, &(*buf)->pBuffer);117118if (r) {119FREE(inp);120super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf);121return r;122}123124return OMX_ErrorNone;125}126127static OMX_ERRORTYPE h264e_inport_UseBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl,128OMX_BUFFERHEADERTYPE **buf, OMX_U32 idx,129OMX_PTR private, OMX_U32 size, OMX_U8 *mem)130{131struct input_buf_private *inp;132OMX_ERRORTYPE r;133134r = super_UseBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl,135buf, idx, private, size, mem);136if (r)137return r;138139inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private);140if (!inp) {141super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf);142return OMX_ErrorInsufficientResources;143}144145list_inithead(&inp->tasks);146147return OMX_ErrorNone;148}149150static OMX_ERRORTYPE h264e_inport_FreeBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl,151OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf)152{153vid_enc_PrivateType *priv = tiz_get_prc(ap_hdl);154struct input_buf_private *inp = buf->pInputPortPrivate;155156if (inp) {157enc_ReleaseTasks(&inp->tasks);158if (inp->transfer)159pipe_texture_unmap(priv->s_pipe, inp->transfer);160pipe_resource_reference(&inp->resource, NULL);161FREE(inp);162}163164return super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, buf);165}166167/*168* h264einport_class169*/170171static void * h264e_inport_class_ctor(void * ap_obj, va_list * app)172{173/* NOTE: Class methods might be added in the future. None for now. */174return super_ctor (typeOf (ap_obj, "h264einport_class"), ap_obj, app);175}176177/*178* initialization179*/180181void * h264e_inport_class_init(void * ap_tos, void * ap_hdl)182{183void * tizvideoport = tiz_get_type(ap_hdl, "tizvideoport");184void * h264einport_class185= factory_new(classOf(tizvideoport), "h264einport_class",186classOf(tizvideoport), sizeof(h264e_inport_class_t),187ap_tos, ap_hdl, ctor, h264e_inport_class_ctor, 0);188return h264einport_class;189}190191void * h264e_inport_init(void * ap_tos, void * ap_hdl)192{193void * tizvideoport = tiz_get_type (ap_hdl, "tizvideoport");194void * h264einport_class = tiz_get_type (ap_hdl, "h264einport_class");195void * h264einport = factory_new196/* TIZ_CLASS_COMMENT: class type, class name, parent, size */197(h264einport_class, "h264einport", tizvideoport,198sizeof (h264e_inport_t),199/* TIZ_CLASS_COMMENT: class constructor */200ap_tos, ap_hdl,201/* TIZ_CLASS_COMMENT: class constructor */202ctor, h264e_inport_ctor,203/* TIZ_CLASS_COMMENT: class destructor */204dtor, h264e_inport_dtor,205/* TIZ_CLASS_COMMENT: */206tiz_api_AllocateBuffer, h264e_inport_AllocateBuffer,207/* TIZ_CLASS_COMMENT: */208tiz_api_UseBuffer, h264e_inport_UseBuffer,209/* TIZ_CLASS_COMMENT: */210tiz_api_FreeBuffer, h264e_inport_FreeBuffer,211/* TIZ_CLASS_COMMENT: stop value*/2120);213214return h264einport;215}216217218