1 /**************************************************************************
3 * Copyright 2013 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include <tizplatform.h>
33 #include <tizkernel.h>
35 #include "vl/vl_winsys.h"
38 #include "h264einport.h"
39 #include "h264einport_decls.h"
40 #include "vid_enc_common.h"
42 static OMX_ERRORTYPE
enc_AllocateBackTexture(OMX_HANDLETYPE ap_hdl
,
44 struct pipe_resource
**resource
,
45 struct pipe_transfer
**transfer
,
48 vid_enc_PrivateType
* priv
= tiz_get_prc(ap_hdl
);
49 tiz_port_t
* port
= tiz_krn_get_port(tiz_get_krn(ap_hdl
), idx
);
50 struct pipe_resource buf_templ
;
51 struct pipe_box box
= {};
54 memset(&buf_templ
, 0, sizeof buf_templ
);
55 buf_templ
.target
= PIPE_TEXTURE_2D
;
56 buf_templ
.format
= PIPE_FORMAT_I8_UNORM
;
57 buf_templ
.bind
= PIPE_BIND_LINEAR
;
58 buf_templ
.usage
= PIPE_USAGE_STAGING
;
60 buf_templ
.width0
= port
->portdef_
.format
.video
.nFrameWidth
;
61 buf_templ
.height0
= port
->portdef_
.format
.video
.nFrameHeight
* 3 / 2;
63 buf_templ
.array_size
= 1;
65 *resource
= priv
->s_pipe
->screen
->resource_create(priv
->s_pipe
->screen
, &buf_templ
);
67 return OMX_ErrorInsufficientResources
;
69 box
.width
= (*resource
)->width0
;
70 box
.height
= (*resource
)->height0
;
71 box
.depth
= (*resource
)->depth0
;
72 ptr
= priv
->s_pipe
->transfer_map(priv
->s_pipe
, *resource
, 0, PIPE_TRANSFER_WRITE
, &box
, transfer
);
83 static void * h264e_inport_ctor(void * ap_obj
, va_list * app
)
85 return super_ctor(typeOf(ap_obj
, "h264einport"), ap_obj
, app
);
88 static void * h264e_inport_dtor(void * ap_obj
)
90 return super_dtor(typeOf(ap_obj
, "h264einport"), ap_obj
);
97 static OMX_ERRORTYPE
h264e_inport_AllocateBuffer(const void * ap_obj
, OMX_HANDLETYPE ap_hdl
,
98 OMX_BUFFERHEADERTYPE
** buf
, OMX_U32 idx
,
99 OMX_PTR
private, OMX_U32 size
)
101 struct input_buf_private
*inp
;
104 r
= super_UseBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
,
105 buf
, idx
, private, size
, NULL
);
109 inp
= (*buf
)->pInputPortPrivate
= CALLOC_STRUCT(input_buf_private
);
111 super_FreeBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
, idx
, *buf
);
112 return OMX_ErrorInsufficientResources
;
115 list_inithead(&inp
->tasks
);
117 r
= enc_AllocateBackTexture(ap_hdl
, idx
, &inp
->resource
, &inp
->transfer
, &(*buf
)->pBuffer
);
121 super_FreeBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
, idx
, *buf
);
125 return OMX_ErrorNone
;
128 static OMX_ERRORTYPE
h264e_inport_UseBuffer(const void * ap_obj
, OMX_HANDLETYPE ap_hdl
,
129 OMX_BUFFERHEADERTYPE
**buf
, OMX_U32 idx
,
130 OMX_PTR
private, OMX_U32 size
, OMX_U8
*mem
)
132 struct input_buf_private
*inp
;
135 r
= super_UseBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
,
136 buf
, idx
, private, size
, mem
);
140 inp
= (*buf
)->pInputPortPrivate
= CALLOC_STRUCT(input_buf_private
);
142 super_FreeBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
, idx
, *buf
);
143 return OMX_ErrorInsufficientResources
;
146 list_inithead(&inp
->tasks
);
148 return OMX_ErrorNone
;
151 static OMX_ERRORTYPE
h264e_inport_FreeBuffer(const void * ap_obj
, OMX_HANDLETYPE ap_hdl
,
152 OMX_U32 idx
, OMX_BUFFERHEADERTYPE
*buf
)
154 vid_enc_PrivateType
*priv
= tiz_get_prc(ap_hdl
);
155 struct input_buf_private
*inp
= buf
->pInputPortPrivate
;
158 enc_ReleaseTasks(&inp
->tasks
);
160 pipe_transfer_unmap(priv
->s_pipe
, inp
->transfer
);
161 pipe_resource_reference(&inp
->resource
, NULL
);
165 return super_FreeBuffer(typeOf(ap_obj
, "h264einport"), ap_obj
, ap_hdl
, idx
, buf
);
172 static void * h264e_inport_class_ctor(void * ap_obj
, va_list * app
)
174 /* NOTE: Class methods might be added in the future. None for now. */
175 return super_ctor (typeOf (ap_obj
, "h264einport_class"), ap_obj
, app
);
182 void * h264e_inport_class_init(void * ap_tos
, void * ap_hdl
)
184 void * tizvideoport
= tiz_get_type(ap_hdl
, "tizvideoport");
185 void * h264einport_class
186 = factory_new(classOf(tizvideoport
), "h264einport_class",
187 classOf(tizvideoport
), sizeof(h264e_inport_class_t
),
188 ap_tos
, ap_hdl
, ctor
, h264e_inport_class_ctor
, 0);
189 return h264einport_class
;
192 void * h264e_inport_init(void * ap_tos
, void * ap_hdl
)
194 void * tizvideoport
= tiz_get_type (ap_hdl
, "tizvideoport");
195 void * h264einport_class
= tiz_get_type (ap_hdl
, "h264einport_class");
196 void * h264einport
= factory_new
197 /* TIZ_CLASS_COMMENT: class type, class name, parent, size */
198 (h264einport_class
, "h264einport", tizvideoport
,
199 sizeof (h264e_inport_t
),
200 /* TIZ_CLASS_COMMENT: class constructor */
202 /* TIZ_CLASS_COMMENT: class constructor */
203 ctor
, h264e_inport_ctor
,
204 /* TIZ_CLASS_COMMENT: class destructor */
205 dtor
, h264e_inport_dtor
,
206 /* TIZ_CLASS_COMMENT: */
207 tiz_api_AllocateBuffer
, h264e_inport_AllocateBuffer
,
208 /* TIZ_CLASS_COMMENT: */
209 tiz_api_UseBuffer
, h264e_inport_UseBuffer
,
210 /* TIZ_CLASS_COMMENT: */
211 tiz_api_FreeBuffer
, h264e_inport_FreeBuffer
,
212 /* TIZ_CLASS_COMMENT: stop value*/