diff --git a/meson.build b/meson.build index 1f6edd153d6..f8e84f3c09b 100644 --- a/meson.build +++ b/meson.build @@ -642,85 +642,6 @@ if prog_glslang.found() endif endif -dep_xv = null_dep -_omx = get_option('gallium-omx') -if not system_has_kms_drm - if ['auto', 'disabled'].contains(_omx) - _omx = 'disabled' - else - error('OMX state tracker can only be built on unix-like OSes.') - endif -elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau) - if ['auto', 'disabled'].contains(_omx) - _omx = 'disabled' - else - error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.') - endif -endif -with_gallium_omx = _omx -dep_omx = null_dep -dep_omx_other = [] -if ['auto', 'bellagio'].contains(_omx) - dep_omx = dependency( - 'libomxil-bellagio', required : _omx == 'bellagio' - ) - if dep_omx.found() - with_gallium_omx = 'bellagio' - endif -endif -if ['auto', 'tizonia'].contains(_omx) - if with_dri and with_egl - dep_omx = dependency( - 'libtizonia', version : '>= 0.10.0', - required : _omx == 'tizonia', - ) - dep_omx_other = [ - dependency('libtizplatform', required : _omx == 'tizonia'), - dependency('tizilheaders', required : _omx == 'tizonia'), - ] - if dep_omx.found() and dep_omx_other[0].found() and dep_omx_other[1].found() - with_gallium_omx = 'tizonia' - endif - elif _omx == 'tizonia' - error('OMX-Tizonia state tracker requires dri and egl') - endif -endif -if _omx == 'auto' - with_gallium_omx = 'disabled' -else - with_gallium_omx = _omx -endif - -pre_args += '-DENABLE_ST_OMX_BELLAGIO=@0@'.format((with_gallium_omx == 'bellagio').to_int()) -pre_args += '-DENABLE_ST_OMX_TIZONIA=@0@'.format((with_gallium_omx == 'tizonia').to_int()) - - -omx_drivers_path = get_option('omx-libs-path') - -if with_gallium_omx != 'disabled' - # Figure out where to put the omx driver. - # FIXME: this could all be vastly simplified by adding a 'defined_variable' - # argument to meson's get_variable method. - if omx_drivers_path == '' - _omx_libdir = dep_omx.get_variable(pkgconfig : 'libdir') - _omx_drivers_dir = dep_omx.get_variable(pkgconfig : 'pluginsdir') - if _omx_libdir == get_option('libdir') - omx_drivers_path = _omx_drivers_dir - else - _omx_base_dir = [] - # This will fail on windows. Does OMX run on windows? - _omx_libdir = _omx_libdir.split('/') - _omx_drivers_dir = _omx_drivers_dir.split('/') - foreach o : _omx_drivers_dir - if not _omx_libdir.contains(o) - _omx_base_dir += o - endif - endforeach - omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir) - endif - endif -endif - _va_drivers = [ with_gallium_d3d12_video, with_gallium_nouveau, @@ -2164,8 +2085,7 @@ if with_platform_x11 dep_x11 = dependency('x11') endif if (with_any_vk or with_glx == 'dri' or with_egl or - (with_gallium_vdpau or with_gallium_va or - with_gallium_omx != 'disabled')) + (with_gallium_vdpau or with_gallium_va)) dep_xcb = dependency('xcb') dep_xcb_keysyms = dependency('xcb-keysyms', required : false) with_xcb_keysyms = dep_xcb_keysyms.found() @@ -2205,8 +2125,7 @@ if with_platform_x11 endif if (with_egl or with_any_vk or - with_gallium_vdpau or with_gallium_xa or - with_gallium_omx != 'disabled') + with_gallium_vdpau or with_gallium_xa) dep_xcb_xfixes = dependency('xcb-xfixes') endif if with_xlib_lease or with_any_vk @@ -2437,9 +2356,6 @@ endif if with_gallium_xa video_apis += 'xa' endif -if with_gallium_omx != 'disabled' - video_apis += 'omx' -endif video_summary += {'APIs': video_apis.length() != 0 ? video_apis : false} summary(video_summary, section: 'Video', bool_yn: true, list_sep: ' ') @@ -2461,9 +2377,6 @@ if with_gallium if with_gallium_vdpau gallium_frontends += 'vdpau' endif - if with_gallium_omx != 'disabled' - gallium_frontends += 'omx' + with_gallium_omx - endif if with_gallium_va gallium_frontends += 'va' endif diff --git a/meson_options.txt b/meson_options.txt index ac8a3114cfb..5ff42b8df2d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -118,22 +118,6 @@ option( description : 'path to put vdpau libraries. defaults to $libdir/vdpau.' ) -option( - 'gallium-omx', - type : 'combo', - value : 'auto', - choices : ['auto', 'disabled', 'bellagio', 'tizonia'], - description : 'enable gallium omx frontend.', -) - -option( - 'omx-libs-path', - type : 'string', - value : '', - description : 'path to put omx libraries. defaults to omx-bellagio ' + - 'pkg-config pluginsdir.' -) - option( 'gallium-va', type : 'feature', diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 7284ade7e25..032b6a5a38a 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -562,8 +562,7 @@ libgalliumvl = static_library( # some drivers export their screen creation function globally, so all frontends have to contain the # full libgalliumvl. So we'll handle this here globally for everybody. -if (with_gallium_va or with_gallium_vdpau or with_gallium_omx != 'disabled' or - with_dri or with_gallium_radeonsi) +if (with_gallium_va or with_gallium_vdpau or with_dri or with_gallium_radeonsi) libgalliumvl_stub = libgalliumvl else libgalliumvl_stub = _libgalliumvl_stub diff --git a/src/gallium/frontends/omx/bellagio/entrypoint.c b/src/gallium/frontends/omx/bellagio/entrypoint.c deleted file mode 100644 index 5c75e8dadaa..00000000000 --- a/src/gallium/frontends/omx/bellagio/entrypoint.c +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#include "entrypoint.h" -#include "vid_dec.h" -#include "vid_enc.h" - -int omx_component_library_Setup(stLoaderComponentType **stComponents) -{ - OMX_ERRORTYPE r; - - if (stComponents == NULL) - return 2; - - /* component 0 - video decoder */ - r = vid_dec_LoaderComponent(stComponents[0]); - if (r != OMX_ErrorNone) - return OMX_ErrorInsufficientResources; - - /* component 1 - video encoder */ - r = vid_enc_LoaderComponent(stComponents[1]); - if (r != OMX_ErrorNone) - return OMX_ErrorInsufficientResources; - - return 2; -} - -OMX_ERRORTYPE omx_workaround_Destructor(OMX_COMPONENTTYPE *comp) -{ - omx_base_component_PrivateType* priv = (omx_base_component_PrivateType*)comp->pComponentPrivate; - - priv->state = OMX_StateInvalid; - tsem_up(priv->messageSem); - - /* wait for thread to exit */ - pthread_join(priv->messageHandlerThread, NULL); - - return omx_base_component_Destructor(comp); -} diff --git a/src/gallium/frontends/omx/bellagio/entrypoint.h b/src/gallium/frontends/omx/bellagio/entrypoint.h deleted file mode 100644 index d566d1eb5a3..00000000000 --- a/src/gallium/frontends/omx/bellagio/entrypoint.h +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#ifndef OMX_ENTRYPOINT_H -#define OMX_ENTRYPOINT_H - -#include - -#include "vl/vl_winsys.h" - -PUBLIC extern int omx_component_library_Setup(stLoaderComponentType **stComponents); - -OMX_ERRORTYPE omx_workaround_Destructor(OMX_COMPONENTTYPE *comp); - -#endif diff --git a/src/gallium/frontends/omx/bellagio/vid_dec.c b/src/gallium/frontends/omx/bellagio/vid_dec.c deleted file mode 100644 index a093fea85a9..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec.c +++ /dev/null @@ -1,550 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - - -#include - -#include - -#include - -#include "pipe/p_screen.h" -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" -#include "util/u_surface.h" -#include "vl/vl_video_buffer.h" -#include "util/vl_vlc.h" - -#include "vl/vl_codec.h" - -#include "entrypoint.h" -#include "vid_dec.h" -#include "vid_omx_common.h" -#include "vid_dec_h264_common.h" - -static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name); -static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp); -static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param); -static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param); -static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE *comp, internalRequestMessageType *msg); -static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf); -static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf); -static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output); - -OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp) -{ - comp->componentVersion.s.nVersionMajor = 0; - comp->componentVersion.s.nVersionMinor = 0; - comp->componentVersion.s.nRevision = 0; - comp->componentVersion.s.nStep = 1; - comp->name_specific_length = 4; - - comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name == NULL) - goto error; - - comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *)); - if (comp->name_specific == NULL) - goto error; - - comp->role_specific = CALLOC(comp->name_specific_length, sizeof(char *)); - if (comp->role_specific == NULL) - goto error; - - comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name_specific[0] == NULL) - goto error_specific; - - comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name_specific[1] == NULL) - goto error_specific; - - comp->name_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name_specific[2] == NULL) - goto error_specific; - - comp->name_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name_specific[3] == NULL) - goto error_specific; - - comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->role_specific[0] == NULL) - goto error_specific; - - comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->role_specific[1] == NULL) - goto error_specific; - - comp->role_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->role_specific[2] == NULL) - goto error_specific; - - comp->role_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->role_specific[3] == NULL) - goto error_specific; - - strcpy(comp->name, OMX_VID_DEC_BASE_NAME); - strcpy(comp->name_specific[0], OMX_VID_DEC_MPEG2_NAME); - strcpy(comp->name_specific[1], OMX_VID_DEC_AVC_NAME); - strcpy(comp->name_specific[2], OMX_VID_DEC_HEVC_NAME); - strcpy(comp->name_specific[3], OMX_VID_DEC_AV1_NAME); - - strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE); - strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE); - strcpy(comp->role_specific[2], OMX_VID_DEC_HEVC_ROLE); - strcpy(comp->role_specific[3], OMX_VID_DEC_AV1_ROLE); - - comp->constructor = vid_dec_Constructor; - - return OMX_ErrorNone; - -error_specific: - FREE(comp->role_specific[3]); - FREE(comp->role_specific[2]); - FREE(comp->role_specific[1]); - FREE(comp->role_specific[0]); - FREE(comp->name_specific[3]); - FREE(comp->name_specific[2]); - FREE(comp->name_specific[1]); - FREE(comp->name_specific[0]); - -error: - FREE(comp->role_specific); - FREE(comp->name_specific); - - FREE(comp->name); - - return OMX_ErrorInsufficientResources; -} - -static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name) -{ - vid_dec_PrivateType *priv; - omx_base_video_PortType *port; - struct pipe_screen *screen; - OMX_ERRORTYPE r; - int i; - - assert(!comp->pComponentPrivate); - - priv = comp->pComponentPrivate = CALLOC(1, sizeof(vid_dec_PrivateType)); - if (!priv) - return OMX_ErrorInsufficientResources; - - r = omx_base_filter_Constructor(comp, name); - if (r) - return r; - - priv->profile = PIPE_VIDEO_PROFILE_UNKNOWN; - - if (!strcmp(name, OMX_VID_DEC_MPEG2_NAME)) - priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN; - - if (!strcmp(name, OMX_VID_DEC_AVC_NAME)) - priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - - if (!strcmp(name, OMX_VID_DEC_HEVC_NAME)) - priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN; - - if (!strcmp(name, OMX_VID_DEC_AV1_NAME)) - priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN; - - if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) - priv->BufferMgmtCallback = vid_dec_av1_FrameDecoded; - else - priv->BufferMgmtCallback = vid_dec_FrameDecoded; - priv->messageHandler = vid_dec_MessageHandler; - priv->destructor = vid_dec_Destructor; - - comp->SetParameter = vid_dec_SetParameter; - comp->GetParameter = vid_dec_GetParameter; - - priv->screen = omx_get_screen(); - if (!priv->screen) - return OMX_ErrorInsufficientResources; - - screen = priv->screen->pscreen; - - if (!vl_codec_supported(screen, priv->profile, false)) - return OMX_ErrorInsufficientResources; - - priv->pipe = pipe_create_multimedia_context(screen); - if (!priv->pipe) - return OMX_ErrorInsufficientResources; - - if (!vl_compositor_init(&priv->compositor, priv->pipe)) { - priv->pipe->destroy(priv->pipe); - priv->pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - if (!vl_compositor_init_state(&priv->cstate, priv->pipe)) { - vl_compositor_cleanup(&priv->compositor); - priv->pipe->destroy(priv->pipe); - priv->pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - priv->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0; - priv->sPortTypesParam[OMX_PortDomainVideo].nPorts = 2; - priv->ports = CALLOC(2, sizeof(omx_base_PortType *)); - if (!priv->ports) - return OMX_ErrorInsufficientResources; - - for (i = 0; i < 2; ++i) { - priv->ports[i] = CALLOC(1, sizeof(omx_base_video_PortType)); - if (!priv->ports[i]) - return OMX_ErrorInsufficientResources; - - base_video_port_Constructor(comp, &priv->ports[i], i, i == 0); - } - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - strcpy(port->sPortParam.format.video.cMIMEType,"video/MPEG2"); - port->sPortParam.nBufferCountMin = 8; - port->sPortParam.nBufferCountActual = 8; - port->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE; - port->sPortParam.format.video.nFrameWidth = 176; - port->sPortParam.format.video.nFrameHeight = 144; - port->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2; - port->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingMPEG2; - port->Port_SendBufferFunction = vid_dec_DecodeBuffer; - if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) { - port->Port_AllocateBuffer = vid_dec_av1_AllocateInBuffer; - port->Port_UseBuffer = vid_dec_av1_UseInBuffer; - } - - port->Port_FreeBuffer = vid_dec_FreeDecBuffer; - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]; - port->sPortParam.nBufferCountActual = 8; - port->sPortParam.nBufferCountMin = 4; - port->sPortParam.format.video.nFrameWidth = 176; - port->sPortParam.format.video.nFrameHeight = 144; - port->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - port->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp) -{ - vid_dec_PrivateType* priv = comp->pComponentPrivate; - int i; - - if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) - vid_dec_av1_ReleaseTasks(priv); - - if (priv->ports) { - for (i = 0; i < priv->sPortTypesParam[OMX_PortDomainVideo].nPorts; ++i) { - if(priv->ports[i]) - priv->ports[i]->PortDestructor(priv->ports[i]); - } - FREE(priv->ports); - priv->ports=NULL; - } - - if (priv->pipe) { - vl_compositor_cleanup_state(&priv->cstate); - vl_compositor_cleanup(&priv->compositor); - priv->pipe->destroy(priv->pipe); - } - - if (priv->screen) - omx_put_screen(); - - return omx_workaround_Destructor(comp); -} - -static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_dec_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - - if (!param) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexParamPortDefinition: { - OMX_PARAM_PORTDEFINITIONTYPE *def = param; - - r = omx_base_component_SetParameter(handle, idx, param); - if (r) - return r; - - if (def->nPortIndex == OMX_BASE_FILTER_INPUTPORT_INDEX) { - omx_base_video_PortType *port; - unsigned framesize = def->format.video.nFrameWidth * def->format.video.nFrameHeight; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - port->sPortParam.nBufferSize = framesize * 512 / (16*16); - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]; - port->sPortParam.format.video.nFrameWidth = def->format.video.nFrameWidth; - port->sPortParam.format.video.nFrameHeight = def->format.video.nFrameHeight; - port->sPortParam.format.video.nStride = def->format.video.nFrameWidth; - port->sPortParam.format.video.nSliceHeight = def->format.video.nFrameHeight; - port->sPortParam.nBufferSize = framesize*3/2; - - priv->callbacks->EventHandler(comp, priv->callbackData, OMX_EventPortSettingsChanged, - OMX_BASE_FILTER_OUTPUTPORT_INDEX, 0, NULL); - } - break; - } - case OMX_IndexParamStandardComponentRole: { - OMX_PARAM_COMPONENTROLETYPE *role = param; - - r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE)); - if (r) - return r; - - if (!strcmp((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE)) { - priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN; - } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AVC_ROLE)) { - priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE)) { - priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN; - } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AV1_ROLE)) { - priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN; - } else { - return OMX_ErrorBadParameter; - } - - break; - } - case OMX_IndexParamVideoPortFormat: { - OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param; - omx_base_video_PortType *port; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - if (r) - return r; - - if (format->nPortIndex > 1) - return OMX_ErrorBadPortIndex; - - port = (omx_base_video_PortType *)priv->ports[format->nPortIndex]; - memcpy(&port->sVideoParam, format, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - break; - } - default: - return omx_base_component_SetParameter(handle, idx, param); - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_dec_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - - if (!param) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexParamStandardComponentRole: { - OMX_PARAM_COMPONENTROLETYPE *role = param; - - r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE)); - if (r) - return r; - - if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN) - strcpy((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE); - else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH) - strcpy((char *)role->cRole, OMX_VID_DEC_AVC_ROLE); - else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN) - strcpy((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE); - else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) - strcpy((char *)role->cRole, OMX_VID_DEC_AV1_ROLE); - - break; - } - - case OMX_IndexParamVideoInit: - r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE)); - if (r) - return r; - - memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE)); - break; - - case OMX_IndexParamVideoPortFormat: { - OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param; - omx_base_video_PortType *port; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - if (r) - return r; - - if (format->nPortIndex > 1) - return OMX_ErrorBadPortIndex; - - port = (omx_base_video_PortType *)priv->ports[format->nPortIndex]; - memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - break; - } - - default: - return omx_base_component_GetParameter(handle, idx, param); - - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE* comp, internalRequestMessageType *msg) -{ - vid_dec_PrivateType* priv = comp->pComponentPrivate; - - if (msg->messageType == OMX_CommandStateSet) { - if ((msg->messageParam == OMX_StateIdle ) && (priv->state == OMX_StateLoaded)) { - if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN) - vid_dec_mpeg12_Init(priv); - else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH) - vid_dec_h264_Init(priv); - else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN) - vid_dec_h265_Init(priv); - else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) { - vid_dec_av1_Init(priv); - } - - } else if ((msg->messageParam == OMX_StateLoaded) && (priv->state == OMX_StateIdle)) { - if (priv->shadow) { - priv->shadow->destroy(priv->shadow); - priv->shadow = NULL; - } - if (priv->codec) { - priv->codec->destroy(priv->codec); - priv->codec = NULL; - } - } - } - - return omx_base_component_MessageHandler(comp, msg); -} - -static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_dec_PrivateType *priv = comp->pComponentPrivate; - unsigned i = priv->num_in_buffers++; - OMX_ERRORTYPE r; - - priv->in_buffers[i] = buf; - priv->sizes[i] = buf->nFilledLen; - priv->inputs[i] = buf->pBuffer; - priv->timestamps[i] = buf->nTimeStamp; - - while (priv->num_in_buffers > (!!(buf->nFlags & OMX_BUFFERFLAG_EOS) ? 0 : 1)) { - bool eos = !!(priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS); - unsigned min_bits_left = eos ? 32 : MAX2(buf->nFilledLen * 8, 32); - struct vl_vlc vlc; - - vl_vlc_init(&vlc, priv->num_in_buffers, priv->inputs, priv->sizes); - - if (priv->slice) - priv->bytes_left = vl_vlc_bits_left(&vlc) / 8; - - while (vl_vlc_bits_left(&vlc) > min_bits_left) { - priv->Decode(priv, &vlc, min_bits_left); - vl_vlc_fillbits(&vlc); - } - - if (priv->slice) { - unsigned bytes = priv->bytes_left - vl_vlc_bits_left(&vlc) / 8; - - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &priv->slice, &bytes); - - if (priv->num_in_buffers) - priv->slice = priv->inputs[1]; - else - priv->slice = NULL; - } - - if (eos && priv->frame_started) - priv->EndFrame(priv); - - if (priv->frame_finished) { - priv->frame_finished = false; - priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen; - r = base_port_SendBufferFunction(port, priv->in_buffers[0]); - } else if (eos) { - if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) - vid_dec_av1_FreeInputPortPrivate(priv, priv->in_buffers[0]); - else - vid_dec_FreeInputPortPrivate(priv->in_buffers[0]); - priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen; - r = base_port_SendBufferFunction(port, priv->in_buffers[0]); - } else { - priv->in_buffers[0]->nFilledLen = 0; - r = port->ReturnBufferFunction(port, priv->in_buffers[0]); - } - - if (--priv->num_in_buffers) { - unsigned delta = MIN2((min_bits_left - vl_vlc_bits_left(&vlc)) / 8, priv->sizes[1]); - - priv->in_buffers[0] = priv->in_buffers[1]; - priv->sizes[0] = priv->sizes[1] - delta; - priv->inputs[0] = priv->inputs[1] + delta; - priv->timestamps[0] = priv->timestamps[1]; - } - - if (r) - return r; - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_dec_PrivateType *priv = comp->pComponentPrivate; - - if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) - vid_dec_av1_FreeInputPortPrivate(priv, buf); - else - vid_dec_FreeInputPortPrivate(buf); - - return base_port_FreeBuffer(port, idx, buf); -} - -static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output) -{ - vid_dec_PrivateType *priv = comp->pComponentPrivate; - - vid_dec_FrameDecoded_common(priv, input, output); -} diff --git a/src/gallium/frontends/omx/bellagio/vid_dec.h b/src/gallium/frontends/omx/bellagio/vid_dec.h deleted file mode 100644 index dc8db3deaa4..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec.h +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#ifndef OMX_VID_DEC_H -#define OMX_VID_DEC_H - -#include - -#include -#include - -#include "util/u_thread.h" - -#include "vid_dec_common.h" - -#define OMX_VID_DEC_BASE_NAME "OMX.mesa.video_decoder" - -#define OMX_VID_DEC_MPEG2_NAME "OMX.mesa.video_decoder.mpeg2" -#define OMX_VID_DEC_MPEG2_ROLE "video_decoder.mpeg2" - -#define OMX_VID_DEC_AVC_NAME "OMX.mesa.video_decoder.avc" -#define OMX_VID_DEC_AVC_ROLE "video_decoder.avc" - -#define OMX_VID_DEC_HEVC_NAME "OMX.mesa.video_decoder.hevc" -#define OMX_VID_DEC_HEVC_ROLE "video_decoder.hevc" - -#define OMX_VID_DEC_AV1_NAME "OMX.mesa.video_decoder.av1" -#define OMX_VID_DEC_AV1_ROLE "video_decoder.av1" - -#define OMX_VID_DEC_TIMESTAMP_INVALID ((OMX_TICKS) -1) - -OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp); - -/* vid_dec_mpeg12.c */ -void vid_dec_mpeg12_Init(vid_dec_PrivateType *priv); - -/* vid_dec_h264.c */ -void vid_dec_h264_Init(vid_dec_PrivateType *priv); - -/* vid_dec_h265.c */ -void vid_dec_h265_Init(vid_dec_PrivateType *priv); - -/* vid_dec_av1.c */ -void vid_dec_av1_Init(vid_dec_PrivateType *priv); - -OMX_ERRORTYPE vid_dec_av1_AllocateInBuffer(omx_base_PortType *port, - OMX_INOUT OMX_BUFFERHEADERTYPE **buf, - OMX_IN OMX_U32 idx, OMX_IN OMX_PTR private, - OMX_IN OMX_U32 size); - -OMX_ERRORTYPE vid_dec_av1_UseInBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE **buf, - OMX_U32 idx, OMX_PTR private, OMX_U32 size, OMX_U8 *mem); - -void vid_dec_av1_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output); - -void vid_dec_av1_ReleaseTasks(vid_dec_PrivateType *priv); - -void vid_dec_av1_FreeInputPortPrivate(vid_dec_PrivateType *priv, OMX_BUFFERHEADERTYPE *buf); - -#endif diff --git a/src/gallium/frontends/omx/bellagio/vid_dec_av1.c b/src/gallium/frontends/omx/bellagio/vid_dec_av1.c deleted file mode 100644 index 7aab6069712..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec_av1.c +++ /dev/null @@ -1,2471 +0,0 @@ -/************************************************************************** - * - * Copyright 2020 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" -#include "util/u_video.h" -#include "vl/vl_video_buffer.h" - -#include "vl/vl_codec.h" - -#include "entrypoint.h" -#include "vid_dec.h" -#include "vid_dec_av1.h" - -static unsigned av1_f(struct vl_vlc *vlc, unsigned n) -{ - unsigned valid = vl_vlc_valid_bits(vlc); - - if (n == 0) - return 0; - - if (valid < 32) - vl_vlc_fillbits(vlc); - - return vl_vlc_get_uimsbf(vlc, n); -} - -static unsigned av1_uvlc(struct vl_vlc *vlc) -{ - unsigned value; - unsigned leadingZeros = 0; - - while (1) { - bool done = av1_f(vlc, 1); - if (done) - break; - leadingZeros++; - } - - if (leadingZeros >= 32) - return 0xffffffff; - - value = av1_f(vlc, leadingZeros); - - return value + (1 << leadingZeros) - 1; -} - -static int av1_le(struct vl_vlc *vlc, const unsigned n) -{ - unsigned byte, t = 0; - unsigned i; - - for (i = 0; i < n; ++i) { - byte = av1_f(vlc, 8); - t += (byte << (i * 8)); - } - - return t; -} - -static unsigned av1_uleb128(struct vl_vlc *vlc) -{ - unsigned value = 0; - unsigned leb128Bytes = 0; - unsigned i; - - for (i = 0; i < 8; ++i) { - leb128Bytes = av1_f(vlc, 8); - value |= ((leb128Bytes & 0x7f) << (i * 7)); - if (!(leb128Bytes & 0x80)) - break; - } - - return value; -} - -static int av1_su(struct vl_vlc *vlc, const unsigned n) -{ - unsigned value = av1_f(vlc, n); - unsigned signMask = 1 << (n - 1); - - if (value && signMask) - value = value - 2 * signMask; - - return value; -} - -static unsigned FloorLog2(unsigned x) -{ - unsigned s = 0; - unsigned x1 = x; - - while (x1 != 0) { - x1 = x1 >> 1; - s++; - } - - return s - 1; -} - -static unsigned av1_ns(struct vl_vlc *vlc, unsigned n) -{ - unsigned w = FloorLog2(n) + 1; - unsigned m = (1 << w) - n; - unsigned v = av1_f(vlc, w - 1); - - if (v < m) - return v; - - bool extra_bit = av1_f(vlc, 1); - - return (v << 1) - m + extra_bit; -} - -static void av1_byte_alignment(struct vl_vlc *vlc) -{ - vl_vlc_eatbits(vlc, vl_vlc_valid_bits(vlc) % 8); -} - -static void sequence_header_obu(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - bool timing_info_present_flag; - bool initial_display_delay_present_flag; - uint8_t seq_level_idx; - bool initial_display_delay_present_for_this_op; - bool high_bitdepth; - bool twelve_bit; - bool color_description_present_flag; - uint8_t color_primaries; - uint8_t transfer_characteristics; - uint8_t matrix_coefficients; - int i; - - seq->seq_profile = av1_f(vlc, 3); - assert(seq->seq_profile < 3); - - av1_f(vlc, 1); /* still_picture */ - seq->reduced_still_picture_header = av1_f(vlc, 1); - if (seq->reduced_still_picture_header) { - timing_info_present_flag = 0; - seq->decoder_model_info_present_flag = 0; - initial_display_delay_present_flag = 0; - seq->operating_points_cnt_minus_1 = 0; - seq->operating_point_idc[0] = 0; - seq_level_idx = av1_f(vlc, 5); - seq->decoder_model_present_for_this_op[0] = 0; - initial_display_delay_present_for_this_op = 0; - } else { - uint8_t buffer_delay_length_minus_1 = 0; - - timing_info_present_flag = av1_f(vlc, 1); - if (timing_info_present_flag) { - av1_f(vlc, 32); /* num_units_in_display_tick */ - av1_f(vlc, 32); /* time_scale */ - seq->timing_info.equal_picture_interval = av1_f(vlc, 1); - if (seq->timing_info.equal_picture_interval) - av1_uvlc(vlc); /* num_ticks_per_picture_minus_1 */ - - seq->decoder_model_info_present_flag = av1_f(vlc, 1); - if (seq->decoder_model_info_present_flag) { - /* decoder_model_info */ - buffer_delay_length_minus_1 = av1_f(vlc, 5); - seq->decoder_model_info.num_units_in_decoding_tick = av1_f(vlc, 32); - seq->decoder_model_info.buffer_removal_time_length_minus_1 = av1_f(vlc, 5); - seq->decoder_model_info.frame_presentation_time_length_minus_1 = av1_f(vlc, 5); - } - } else { - seq->decoder_model_info_present_flag = 0; - } - - initial_display_delay_present_flag = av1_f(vlc, 1); - seq->operating_points_cnt_minus_1 = av1_f(vlc, 5); - for (i = 0; i < seq->operating_points_cnt_minus_1 + 1; ++i) { - seq->operating_point_idc[i] = av1_f(vlc, 12); - seq_level_idx = av1_f(vlc, 5); - if (seq_level_idx > 7) - av1_f(vlc, 1); /* seq_tier */ - - if (seq->decoder_model_info_present_flag) { - seq->decoder_model_present_for_this_op[i] = av1_f(vlc, 1); - if (seq->decoder_model_present_for_this_op[i]) { - uint8_t n = buffer_delay_length_minus_1 + 1; - av1_f(vlc, n); /* decoder_buffer_delay */ - av1_f(vlc, n); /* encoder_buffer_delay */ - av1_f(vlc, 1); /* low_delay_mode_flag */ - } - } else { - seq->decoder_model_present_for_this_op[i] = 0; - } - - if (initial_display_delay_present_flag) { - initial_display_delay_present_for_this_op = av1_f(vlc, 1); - if (initial_display_delay_present_for_this_op) - av1_f(vlc, 4); /* initial_display_delay_minus_1 */ - } - } - } - - seq->frame_width_bits_minus_1 = av1_f(vlc, 4); - seq->frame_height_bits_minus_1 = av1_f(vlc, 4); - seq->max_frame_width_minus_1 = av1_f(vlc, seq->frame_width_bits_minus_1 + 1); - seq->max_frame_height_minus_1 = av1_f(vlc, seq->frame_height_bits_minus_1 + 1); - - if (seq->reduced_still_picture_header) - seq->frame_id_numbers_present_flag = 0; - else - seq->frame_id_numbers_present_flag = av1_f(vlc, 1); - if (seq->frame_id_numbers_present_flag) { - seq->delta_frame_id_length_minus_2 = av1_f(vlc, 4); - seq->additional_frame_id_length_minus_1 = av1_f(vlc, 3); - } - - seq->use_128x128_superblock = av1_f(vlc, 1); - seq->enable_filter_intra = av1_f(vlc, 1); - seq->enable_intra_edge_filter = av1_f(vlc, 1); - if (seq->reduced_still_picture_header) { - seq->enable_interintra_compound = 0; - seq->enable_masked_compound = 0; - seq->enable_warped_motion = 0; - seq->enable_dual_filter = 0; - seq->enable_order_hint = 0; - seq->enable_jnt_comp = 0; - seq->enable_ref_frame_mvs = 0; - seq->seq_force_screen_content_tools = AV1_SELECT_SCREEN_CONTENT_TOOLS; - seq->seq_force_integer_mv = AV1_SELECT_INTEGER_MV; - seq->OrderHintBits = 0; - } else { - bool seq_choose_screen_content_tools; - seq->enable_interintra_compound = av1_f(vlc, 1); - seq->enable_masked_compound = av1_f(vlc, 1); - seq->enable_warped_motion = av1_f(vlc, 1); - seq->enable_dual_filter = av1_f(vlc, 1); - seq->enable_order_hint = av1_f(vlc, 1); - if (seq->enable_order_hint) { - seq->enable_jnt_comp = av1_f(vlc, 1); - seq->enable_ref_frame_mvs = av1_f(vlc, 1); - } else { - seq->enable_jnt_comp = 0; - seq->enable_ref_frame_mvs = 0; - } - - seq_choose_screen_content_tools = av1_f(vlc, 1); - seq->seq_force_screen_content_tools = - seq_choose_screen_content_tools ? AV1_SELECT_SCREEN_CONTENT_TOOLS : av1_f(vlc, 1); - - if (seq->seq_force_screen_content_tools > 0) { - bool seq_choose_integer_mv = av1_f(vlc, 1); - seq->seq_force_integer_mv = - seq_choose_integer_mv ? AV1_SELECT_INTEGER_MV : av1_f(vlc, 1); - } else { - seq->seq_force_integer_mv = AV1_SELECT_INTEGER_MV; - } - - if (seq->enable_order_hint) { - seq->order_hint_bits_minus_1 = av1_f(vlc, 3); - seq->OrderHintBits = seq->order_hint_bits_minus_1 + 1; - } else { - seq->OrderHintBits = 0; - } - } - - seq->enable_superres = av1_f(vlc, 1); - seq->enable_cdef = av1_f(vlc, 1); - seq->enable_restoration = av1_f(vlc, 1); - - high_bitdepth = av1_f(vlc, 1); - if (seq->seq_profile == 2 && high_bitdepth) { - twelve_bit = av1_f(vlc, 1); - seq->color_config.BitDepth = twelve_bit ? 12 : 10; - } else if (seq->seq_profile <= 2) { - seq->color_config.BitDepth = high_bitdepth ? 10 : 8; - } - - seq->color_config.mono_chrome = (seq->seq_profile == 1) ? 0 : av1_f(vlc, 1); - seq->color_config.NumPlanes = seq->color_config.mono_chrome ? 1 : 3; - - color_description_present_flag = av1_f(vlc, 1); - if (color_description_present_flag) { - color_primaries = av1_f(vlc, 8); - transfer_characteristics = av1_f(vlc, 8); - matrix_coefficients = av1_f(vlc, 8); - } else { - color_primaries = AV1_CP_UNSPECIFIED; - transfer_characteristics = AV1_TC_UNSPECIFIED; - matrix_coefficients = AV1_MC_UNSPECIFIED; - } - - if (seq->color_config.mono_chrome) { - av1_f(vlc, 1); /* color_range */ - seq->color_config.subsampling_x = 1; - seq->color_config.subsampling_y = 1; - seq->color_config.separate_uv_delta_q = 0; - } else if (color_primaries == AV1_CP_BT_709 && - transfer_characteristics == AV1_TC_SRGB && - matrix_coefficients == AV1_MC_IDENTITY) { - seq->color_config.subsampling_x = 0; - seq->color_config.subsampling_y = 0; - } else { - av1_f(vlc, 1); /* color_range */ - if (seq->seq_profile == 0) { - seq->color_config.subsampling_x = 1; - seq->color_config.subsampling_y = 1; - } else if (seq->seq_profile == 1 ) { - seq->color_config.subsampling_x = 0; - seq->color_config.subsampling_y = 0; - } else { - if (seq->color_config.BitDepth == 12) { - seq->color_config.subsampling_x = av1_f(vlc, 1); - if (seq->color_config.subsampling_x) - seq->color_config.subsampling_y = av1_f(vlc, 1); - else - seq->color_config.subsampling_y = 0; - } else { - seq->color_config.subsampling_x = 1; - seq->color_config.subsampling_y = 0; - } - } - if (seq->color_config.subsampling_x && seq->color_config.subsampling_y) - av1_f(vlc, 2); /* chroma_sample_position */ - } - if (!seq->color_config.mono_chrome) - seq->color_config.separate_uv_delta_q = av1_f(vlc, 1); - - seq->film_grain_params_present = av1_f(vlc, 1); - - priv->picture.av1.picture_parameter.profile = seq->seq_profile; - priv->picture.av1.picture_parameter.seq_info_fields.use_128x128_superblock = - seq->use_128x128_superblock; - priv->picture.av1.picture_parameter.seq_info_fields.enable_filter_intra = - seq->enable_filter_intra; - priv->picture.av1.picture_parameter.seq_info_fields.enable_intra_edge_filter = - seq->enable_intra_edge_filter; - priv->picture.av1.picture_parameter.order_hint_bits_minus_1 = - seq->order_hint_bits_minus_1; - priv->picture.av1.picture_parameter.max_width = seq->max_frame_width_minus_1 + 1; - priv->picture.av1.picture_parameter.max_height = seq->max_frame_height_minus_1 + 1; - priv->picture.av1.picture_parameter.seq_info_fields.enable_interintra_compound = - seq->enable_interintra_compound; - priv->picture.av1.picture_parameter.seq_info_fields.enable_masked_compound = - seq->enable_masked_compound; - priv->picture.av1.picture_parameter.seq_info_fields.enable_dual_filter = - seq->enable_dual_filter; - priv->picture.av1.picture_parameter.seq_info_fields.enable_order_hint = - seq->enable_order_hint; - priv->picture.av1.picture_parameter.seq_info_fields.enable_jnt_comp = - seq->enable_jnt_comp; - priv->picture.av1.picture_parameter.seq_info_fields.ref_frame_mvs = - seq->enable_ref_frame_mvs; - priv->picture.av1.picture_parameter.bit_depth_idx = - (seq->color_config.BitDepth - 8) >> 1; - priv->picture.av1.picture_parameter.seq_info_fields.mono_chrome = - seq->color_config.mono_chrome; -} - -static void superres_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - unsigned coded_denom; - - if (seq->enable_superres) - hdr->use_superres = av1_f(vlc, 1); - else - hdr->use_superres = 0; - - if (hdr->use_superres) { - coded_denom = av1_f(vlc, 3 /* SUPERRES_DENOM_BITS */); - hdr->SuperresDenom = coded_denom + 9 /* SUPERRES_DENOM_MIN */; - } else { - hdr->SuperresDenom = 8 /* SUPERRES_NUM */; - } - - hdr->UpscaledWidth = hdr->FrameWidth; - hdr->FrameWidth = (hdr->UpscaledWidth * 8 + (hdr->SuperresDenom / 2)) / - hdr->SuperresDenom; -} - -static void compute_image_size(vid_dec_PrivateType *priv) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - - hdr->MiCols = 2 * ((hdr->FrameWidth + 7) >> 3); - hdr->MiRows = 2 * ((hdr->FrameHeight + 7) >> 3); -} - -static void frame_size(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - unsigned frame_width_minus_1; - unsigned frame_height_minus_1; - - if (hdr->frame_size_override_flag) { - frame_width_minus_1 = av1_f(vlc, seq->frame_width_bits_minus_1 + 1); - frame_height_minus_1 = av1_f(vlc, seq->frame_height_bits_minus_1 + 1); - hdr->FrameWidth = frame_width_minus_1 + 1; - hdr->FrameHeight = frame_height_minus_1 + 1; - } else { - hdr->FrameWidth = seq->max_frame_width_minus_1 + 1; - hdr->FrameHeight = seq->max_frame_height_minus_1 + 1; - } - - superres_params(priv, vlc); - compute_image_size(priv); -} - -static void render_size(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - bool render_and_frame_size_different; - unsigned render_width_minus_1; - unsigned render_height_minus_1; - - render_and_frame_size_different = av1_f(vlc, 1); - if (render_and_frame_size_different) { - render_width_minus_1 = av1_f(vlc, 16); - render_height_minus_1 = av1_f(vlc, 16); - hdr->RenderWidth = render_width_minus_1 + 1; - hdr->RenderHeight = render_height_minus_1 + 1; - } else { - hdr->RenderWidth = hdr->UpscaledWidth; - hdr->RenderHeight = hdr->FrameHeight; - } -} - -static int get_relative_dist(vid_dec_PrivateType *priv, int a, int b) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - int diff; - unsigned m; - - if (!seq->enable_order_hint) - return 0; - - diff = a - b; - m = 1 << (seq->OrderHintBits - 1); - diff = (diff & (m - 1)) - (diff & m); - - return diff; -} - -static uint8_t find_latest_backward(vid_dec_PrivateType *priv) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - uint8_t ref = 0xff; - unsigned latestOrderHint = 0; - int i; - - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - unsigned hint = hdr->shiftedOrderHints[i]; - if (!hdr->usedFrame[i] && - hint >= hdr->curFrameHint && - (ref == 0xff || hint >= latestOrderHint)) { - ref = i; - latestOrderHint = hint; - } - } - - return ref; -} - -static uint8_t find_earliest_backward(vid_dec_PrivateType *priv) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - uint8_t ref = 0xff; - unsigned earliestOrderHint = 0; - int i; - - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - unsigned hint = hdr->shiftedOrderHints[i]; - if (!hdr->usedFrame[i] && - hint >= hdr->curFrameHint && - (ref == 0xff || hint < earliestOrderHint)) { - ref = i; - earliestOrderHint = hint; - } - } - - return ref; -} - -static uint8_t find_latest_forward(vid_dec_PrivateType *priv) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - uint8_t ref = 0xff; - unsigned latestOrderHint = 0; - int i; - - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - unsigned hint = hdr->shiftedOrderHints[i]; - if (!hdr->usedFrame[i] && - hint < hdr->curFrameHint && - (ref == 0xff || hint >= latestOrderHint)) { - ref = i; - latestOrderHint = hint; - } - } - - return ref; -} - -static void set_frame_refs(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - uint8_t Ref_Frame_List[5] = { AV1_LAST2_FRAME , AV1_LAST3_FRAME, AV1_BWDREF_FRAME, - AV1_ALTREF2_FRAME, AV1_ALTREF_FRAME }; - unsigned earliestOrderHint = 0; - uint8_t ref; - int i; - - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) - hdr->ref_frame_idx[i] = 0xff; - - hdr->ref_frame_idx[0] = hdr->last_frame_idx; - hdr->ref_frame_idx[AV1_GOLDEN_FRAME - AV1_LAST_FRAME] = hdr->gold_frame_idx; - - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) - hdr->usedFrame[i] = 0; - - hdr->usedFrame[hdr->last_frame_idx] = 1; - hdr->usedFrame[hdr->gold_frame_idx] = 1; - - hdr->curFrameHint = 1 << (seq->OrderHintBits - 1); - - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) - hdr->shiftedOrderHints[i] = - hdr->curFrameHint + - get_relative_dist(priv, hdr->RefOrderHint[i], hdr->OrderHint); - - ref = find_latest_backward(priv); - if (ref != 0xff) { - hdr->ref_frame_idx[AV1_ALTREF_FRAME - AV1_LAST_FRAME] = ref; - hdr->usedFrame[ref] = 1; - } - - ref = find_earliest_backward(priv); - if (ref != 0xff) { - hdr->ref_frame_idx[AV1_BWDREF_FRAME - AV1_LAST_FRAME] = ref; - hdr->usedFrame[ref] = 1; - } - - ref = find_earliest_backward(priv); - if (ref != 0xff) { - hdr->ref_frame_idx[AV1_ALTREF2_FRAME - AV1_LAST_FRAME] = ref; - hdr->usedFrame[ref] = 1; - } - - for (i = 0; i < AV1_REFS_PER_FRAME - 2; ++i) { - uint8_t refFrame = Ref_Frame_List[i]; - if (hdr->ref_frame_idx[refFrame - AV1_LAST_FRAME] == 0xff) { - ref = find_latest_forward(priv); - if (ref != 0xff) { - hdr->ref_frame_idx[refFrame - AV1_LAST_FRAME] = ref; - hdr->usedFrame[ref] = 1; - } - } - } - - ref = 0xff; - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - unsigned hint = hdr->shiftedOrderHints[i]; - if (ref == 0xff || hint < earliestOrderHint) { - ref = i; - earliestOrderHint = hint; - } - } - - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) { - if (hdr->ref_frame_idx[i] == 0xff) - hdr->ref_frame_idx[i] = ref; - } -} - -static void frame_size_with_refs(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - bool found_ref; - int i; - - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) { - found_ref = av1_f(vlc, 1); - if (found_ref) { - hdr->UpscaledWidth = - priv->codec_data.av1.RefFrames[hdr->ref_frame_idx[i]].RefUpscaledWidth; - hdr->FrameWidth = hdr->UpscaledWidth; - hdr->FrameHeight = - priv->codec_data.av1.RefFrames[hdr->ref_frame_idx[i]].RefFrameHeight; - hdr->RenderWidth = - priv->codec_data.av1.RefFrames[hdr->ref_frame_idx[i]].RefRenderWidth; - hdr->RenderHeight = - priv->codec_data.av1.RefFrames[hdr->ref_frame_idx[i]].RefRenderHeight; - break; - } - } - - if (!found_ref) { - frame_size(priv, vlc); - render_size(priv, vlc); - } else { - superres_params(priv, vlc); - compute_image_size(priv); - } -} - -static unsigned tile_log2(unsigned blkSize, unsigned target) -{ - unsigned k = 0; - - for (k = 0; (blkSize << k) < target; k++); - - return k; -} - -static void tile_info(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct tile_info *ti = &(priv->codec_data.av1.uncompressed_header.ti); - unsigned sbCols; - unsigned sbRows; - int width_sb; - int height_sb; - unsigned sbSize; - unsigned maxTileWidthSb; - unsigned minLog2TileCols; - unsigned maxLog2TileCols; - unsigned maxLog2TileRows; - unsigned minLog2Tiles; - bool uniform_tile_spacing_flag; - unsigned maxTileAreaSb; - unsigned startSb, i; - - sbCols = (seq->use_128x128_superblock) ? - ((hdr->MiCols + 31) >> 5) : ((hdr->MiCols + 15) >> 4); - sbRows = (seq->use_128x128_superblock) ? - ((hdr->MiRows + 31) >> 5) : ((hdr->MiRows + 15) >> 4); - width_sb = sbCols; - height_sb = sbRows; - sbSize = (seq->use_128x128_superblock ? 5 : 4) + 2; - maxTileWidthSb = AV1_MAX_TILE_WIDTH >> sbSize; - maxTileAreaSb = AV1_MAX_TILE_AREA >> (2 * sbSize); - minLog2TileCols = tile_log2(maxTileWidthSb, sbCols); - maxLog2TileCols = tile_log2(1, MIN2(sbCols, AV1_MAX_TILE_COLS)); - maxLog2TileRows = tile_log2(1, MIN2(sbRows, AV1_MAX_TILE_ROWS)); - minLog2Tiles = MAX2(minLog2TileCols, tile_log2(maxTileAreaSb, sbRows * sbCols)); - - uniform_tile_spacing_flag = av1_f(vlc, 1); - if (uniform_tile_spacing_flag) { - unsigned tileWidthSb, tileHeightSb; - unsigned minLog2TileRows; - - ti->TileColsLog2 = minLog2TileCols; - while (ti->TileColsLog2 < maxLog2TileCols) { - bool increment_tile_cols_log2 = av1_f(vlc, 1); - if (increment_tile_cols_log2) - ti->TileColsLog2++; - else - break; - } - tileWidthSb = (sbCols + (1 << ti->TileColsLog2) - 1) >> ti->TileColsLog2; - i = 0; - for (startSb = 0; startSb < sbCols; startSb += tileWidthSb) { - ti->tile_col_start_sb[i] = startSb; - i++; - } - ti->tile_col_start_sb[i] = sbCols; - ti->TileCols = i; - - minLog2TileRows = (minLog2Tiles > ti->TileColsLog2)? - (minLog2Tiles - ti->TileColsLog2) : 0; - ti->TileRowsLog2 = minLog2TileRows; - while (ti->TileRowsLog2 < maxLog2TileRows) { - bool increment_tile_rows_log2 = av1_f(vlc, 1); - if (increment_tile_rows_log2) - ti->TileRowsLog2++; - else - break; - } - tileHeightSb = (sbRows + (1 << ti->TileRowsLog2) - 1) >> ti->TileRowsLog2; - i = 0; - for (startSb = 0; startSb < sbRows; startSb += tileHeightSb) { - ti->tile_row_start_sb[i] = startSb; - i++; - } - ti->tile_row_start_sb[i] = sbRows; - ti->TileRows = i; - } else { - unsigned widestTileSb = 0; - unsigned maxTileHeightSb; - - startSb = 0; - for (i = 0; startSb < sbCols; ++i) { - uint8_t maxWidth; - unsigned sizeSb; - unsigned width_in_sbs_minus_1; - - ti->tile_col_start_sb[i] = startSb; - maxWidth = MIN2(sbCols - startSb, maxTileWidthSb); - width_in_sbs_minus_1 = av1_ns(vlc, maxWidth); - sizeSb = width_in_sbs_minus_1 + 1; - widestTileSb = MAX2(sizeSb, widestTileSb); - startSb += sizeSb; - width_sb -= sizeSb; - } - ti->TileCols = i; - - ti->tile_col_start_sb[i] = startSb + width_sb; - ti->TileColsLog2 = tile_log2(1, ti->TileCols); - - if (minLog2Tiles > 0) - maxTileAreaSb = (sbRows * sbCols) >> (minLog2Tiles + 1); - else - maxTileAreaSb = (sbRows * sbCols); - maxTileHeightSb = MAX2(maxTileAreaSb / widestTileSb, 1); - - startSb = 0; - for (i = 0; startSb < sbRows; ++i) { - uint8_t maxHeight; - unsigned height_in_sbs_minus_1; - - maxHeight = MIN2(sbRows - startSb, maxTileHeightSb); - height_in_sbs_minus_1 = av1_ns(vlc, maxHeight); - ti->tile_row_start_sb[i] = startSb; - startSb += height_in_sbs_minus_1 + 1; - height_sb -= height_in_sbs_minus_1 + 1; - } - ti->TileRows = i; - ti->tile_row_start_sb[i] = startSb + height_sb; - ti->TileRowsLog2 = tile_log2(1, ti->TileRows); - } - - if (ti->TileColsLog2 > 0 || ti->TileRowsLog2 > 0) { - ti->context_update_tile_id = - av1_f(vlc, ti->TileRowsLog2 + ti->TileColsLog2); - uint8_t tile_size_bytes_minus_1 = av1_f(vlc, 2); - ti->TileSizeBytes = tile_size_bytes_minus_1 + 1; - } else { - ti->context_update_tile_id = 0; - } -} - -static int read_delta_q(struct vl_vlc *vlc) -{ - bool delta_coded = av1_f(vlc, 1); - int delta_q = 0; - - if (delta_coded) - delta_q = av1_su(vlc, 7); - - return delta_q; -} - -static void quantization_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct quantization_params* qp = &(priv->codec_data.av1.uncompressed_header.qp); - bool using_qmatrix; - - qp->base_q_idx = av1_f(vlc, 8); - qp->DeltaQYDc = read_delta_q(vlc); - if (seq->color_config.NumPlanes > 1) { - bool diff_uv_delta = - (seq->color_config.separate_uv_delta_q) ? av1_f(vlc, 1) : 0; - - qp->DeltaQUDc = read_delta_q(vlc); - qp->DeltaQUAc = read_delta_q(vlc); - if (diff_uv_delta) { - qp->DeltaQVDc = read_delta_q(vlc); - qp->DeltaQVAc = read_delta_q(vlc); - } else { - qp->DeltaQVDc = qp->DeltaQUDc; - qp->DeltaQVAc = qp->DeltaQUAc; - } - } else { - qp->DeltaQVDc = 0; - qp->DeltaQVAc = 0; - qp->DeltaQUDc = 0; - qp->DeltaQUAc = 0; - } - - using_qmatrix = av1_f(vlc, 1); - if (using_qmatrix) { - qp->qm_y = av1_f(vlc, 4); - qp->qm_u = av1_f(vlc, 4); - if (!seq->color_config.separate_uv_delta_q) - qp->qm_v = qp->qm_u; - else - qp->qm_v = av1_f(vlc, 4); - } else { - qp->qm_y = 0xf; - qp->qm_u = 0xf; - qp->qm_v = 0xf; - } -} - -static void segmentation_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct segmentation_params* sp = &(priv->codec_data.av1.uncompressed_header.sp); - int i, j; - - sp->segmentation_enabled = av1_f(vlc, 1); - if (sp->segmentation_enabled) { - bool segmentation_update_data; - - if (hdr->primary_ref_frame == AV1_PRIMARY_REF_NONE) { - sp->segmentation_update_map = 1; - sp->segmentation_temporal_update = 0; - segmentation_update_data = 1; - } else { - sp->segmentation_update_map = av1_f(vlc, 1); - if (sp->segmentation_update_map) - sp->segmentation_temporal_update = av1_f(vlc, 1); - else - sp->segmentation_temporal_update = 0; - segmentation_update_data = av1_f(vlc, 1); - } - - if (segmentation_update_data) { - uint8_t Segmentation_Feature_Bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 }; - bool Segmentation_Feature_Signed[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 }; - unsigned Segmentation_Feature_Max[AV1_SEG_LVL_MAX] = { 255, 63, 63, 63, 63, 7, 0, 0 }; - - memset(sp->FeatureData, 0, sizeof(sp->FeatureData)); - memset(sp->FeatureMask, 0, sizeof(sp->FeatureMask)); - for (i = 0; i < AV1_MAX_SEGMENTS; ++i) { - for (j = 0; j < AV1_SEG_LVL_MAX; ++j) { - int feature_value = 0; - bool feature_enabled = av1_f(vlc, 1); - - sp->FeatureEnabled[i][j] = feature_enabled; - int clippedValue = 0; - if (feature_enabled) { - uint8_t bitsToRead = Segmentation_Feature_Bits[j]; - int limit = Segmentation_Feature_Max[j]; - if (Segmentation_Feature_Signed[j]) { - feature_value = av1_su(vlc, 1 + bitsToRead); - clippedValue = CLAMP(feature_value, -limit, limit); - sp->FeatureMask[i] |= 1 << j; - } else { - feature_value = av1_f(vlc, bitsToRead); - clippedValue = CLAMP(feature_value, 0, limit); - sp->FeatureMask[i] |= 1 << j; - } - } - sp->FeatureData[i][j] = clippedValue; - } - } - } else { - int r = hdr->ref_frame_idx[hdr->primary_ref_frame]; - memcpy(sp, &(priv->codec_data.av1.refs[r].sp), sizeof(*sp)); - } - } else { - memset(sp, 0, sizeof(*sp)); - } -} - -static void delta_q_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct quantization_params* qp = &(priv->codec_data.av1.uncompressed_header.qp); - struct delta_q_params * dqp = &(priv->codec_data.av1.uncompressed_header.dqp); - - dqp->delta_q_present = 0; - dqp->delta_q_res = 0; - if (qp->base_q_idx > 0) - dqp->delta_q_present = av1_f(vlc, 1); - if (dqp->delta_q_present) - dqp->delta_q_res = av1_f(vlc, 2); -} - -static void delta_lf_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct delta_q_params * dqp = &(priv->codec_data.av1.uncompressed_header.dqp); - struct delta_lf_params* dlfp = &(priv->codec_data.av1.uncompressed_header.dlfp); - - dlfp->delta_lf_present = 0; - dlfp->delta_lf_res = 0; - dlfp->delta_lf_multi = 0; - if (dqp->delta_q_present) { - if (!hdr->allow_intrabc) - dlfp->delta_lf_present = av1_f(vlc, 1); - - if (dlfp->delta_lf_present) { - dlfp->delta_lf_res = av1_f(vlc, 2); - dlfp->delta_lf_multi = av1_f(vlc, 1); - } - } -} - -static unsigned get_qindex(vid_dec_PrivateType * priv, bool ignoreDeltaQ, unsigned segmentId) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct segmentation_params* sp = &(priv->codec_data.av1.uncompressed_header.sp); - struct quantization_params* qp = &(priv->codec_data.av1.uncompressed_header.qp); - unsigned qindex = 0; - - if (sp->segmentation_enabled && sp->FeatureEnabled[segmentId][AV1_SEG_LVL_ALT_Q]) { - unsigned data = sp->FeatureData[segmentId][AV1_SEG_LVL_ALT_Q]; - qindex = qp->base_q_idx + data; - if (!ignoreDeltaQ && hdr->dqp.delta_q_present) - qindex = data; - - return CLAMP(qindex, 0, 255); - } - - if (!ignoreDeltaQ && hdr->dqp.delta_q_present) - return 0; - - return qp->base_q_idx; -} - -static void loop_filter_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct loop_filter_params *lfp = &(priv->codec_data.av1.uncompressed_header.lfp); - int i; - - if (hdr->CodedLossless || hdr->allow_intrabc) { - lfp->loop_filter_level[0] = 0; - lfp->loop_filter_level[1] = 0; - lfp->loop_filter_ref_deltas[AV1_INTRA_FRAME] = 1; - lfp->loop_filter_ref_deltas[AV1_LAST_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_LAST2_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_LAST3_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_BWDREF_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_GOLDEN_FRAME] = -1; - lfp->loop_filter_ref_deltas[AV1_ALTREF2_FRAME] = -1; - lfp->loop_filter_ref_deltas[AV1_ALTREF_FRAME] = -1; - lfp->loop_filter_mode_deltas[0] = 0; - lfp->loop_filter_mode_deltas[1] = 0; - return; - } - - if (hdr->primary_ref_frame == AV1_PRIMARY_REF_NONE) { - lfp->loop_filter_ref_deltas[AV1_INTRA_FRAME] = 1; - lfp->loop_filter_ref_deltas[AV1_LAST_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_LAST2_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_LAST3_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_BWDREF_FRAME] = 0; - lfp->loop_filter_ref_deltas[AV1_GOLDEN_FRAME] = -1; - lfp->loop_filter_ref_deltas[AV1_ALTREF2_FRAME] = -1; - lfp->loop_filter_ref_deltas[AV1_ALTREF_FRAME] = -1; - lfp->loop_filter_mode_deltas[0] = 0; - lfp->loop_filter_mode_deltas[1] = 0; - } else { - int r = hdr->ref_frame_idx[hdr->primary_ref_frame]; - memcpy(lfp->loop_filter_ref_deltas, - priv->codec_data.av1.refs[r].lfp.loop_filter_ref_deltas, 8); - memcpy(lfp->loop_filter_mode_deltas, - priv->codec_data.av1.refs[r].lfp.loop_filter_mode_deltas, 2); - } - - lfp->loop_filter_level[0] = av1_f(vlc, 6); - lfp->loop_filter_level[1] = av1_f(vlc, 6); - if (seq->color_config.NumPlanes > 1) { - if (lfp->loop_filter_level[0] || lfp->loop_filter_level[1]) { - lfp->loop_filter_level[2] = av1_f(vlc, 6); - lfp->loop_filter_level[3] = av1_f(vlc, 6); - } - } - - lfp->loop_filter_sharpness = av1_f(vlc, 3); - lfp->loop_filter_delta_enabled = av1_f(vlc, 1); - if (lfp->loop_filter_delta_enabled) { - lfp->loop_filter_delta_update = av1_f(vlc, 1); - if (lfp->loop_filter_delta_update) { - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - int8_t update_ref_delta = av1_f(vlc, 1); - if (update_ref_delta) - lfp->loop_filter_ref_deltas[i] = av1_su(vlc, 7); - } - - for (i = 0; i < 2; ++i) { - int8_t update_mode_delta = av1_f(vlc, 1); - if (update_mode_delta) - lfp->loop_filter_mode_deltas[i] = av1_su(vlc, 7); - } - } - } -} - -static void cdef_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct cdef_params *cdefp = &(priv->codec_data.av1.uncompressed_header.cdefp);; - int i; - - if (hdr->CodedLossless || hdr->allow_intrabc || !seq->enable_cdef) { - cdefp->cdef_bits = 0; - cdefp->cdef_y_strengths[0] = 0; - cdefp->cdef_uv_strengths[0] = 0; - return; - } - - cdefp->cdef_damping_minus_3 = av1_f(vlc, 2); - cdefp->cdef_bits = av1_f(vlc, 2); - for (i = 0; i < (1 << cdefp->cdef_bits); ++i) { - cdefp->cdef_y_strengths[i] = av1_f(vlc, 6); - if (seq->color_config.NumPlanes > 1) - cdefp->cdef_uv_strengths[i] = av1_f(vlc, 6); - } -} - -static void lr_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct loop_restoration_params *lrp = &(priv->codec_data.av1.uncompressed_header.lrp); - uint8_t Remap_Lr_Type[4] = - { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ }; - bool UsesLr = false; - bool UsesChromaLr = false; - uint8_t lr_unit_shift, lr_uv_shift; - int i; - - if (hdr->AllLossless || hdr->allow_intrabc || !seq->enable_restoration) { - lrp->FrameRestorationType[0] = AV1_RESTORE_NONE; - lrp->FrameRestorationType[1] = AV1_RESTORE_NONE; - lrp->FrameRestorationType[2] = AV1_RESTORE_NONE; - return; - } - - for (i = 0; i < seq->color_config.NumPlanes; ++i) { - uint8_t lr_type = av1_f(vlc, 2); - lrp->FrameRestorationType[i] = Remap_Lr_Type[lr_type]; - if (lrp->FrameRestorationType[i] != AV1_RESTORE_NONE) { - UsesLr = true; - if (i > 0) - UsesChromaLr = true; - } - } - - if (UsesLr) { - if (seq->use_128x128_superblock) { - lr_unit_shift = av1_f(vlc, 1) + 1; - } else { - lr_unit_shift = av1_f(vlc, 1); - if (lr_unit_shift) { - uint8_t lr_unit_extra_shift = av1_f(vlc, 1); - lr_unit_shift += lr_unit_extra_shift; - } - } - - lrp->LoopRestorationSize[0] = AV1_RESTORATION_TILESIZE >> (2 - lr_unit_shift); - lr_uv_shift = - (seq->color_config.subsampling_x && seq->color_config.subsampling_y && UsesChromaLr) ? - av1_f(vlc, 1) : 0; - - lrp->LoopRestorationSize[1] = lrp->LoopRestorationSize[0] >> lr_uv_shift; - lrp->LoopRestorationSize[2] = lrp->LoopRestorationSize[0] >> lr_uv_shift; - } else { - lrp->LoopRestorationSize[0] = lrp->LoopRestorationSize[1] = - lrp->LoopRestorationSize[2] = (1 << 8); - } -} - -static void tx_mode(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct tx_mode_params *tm = &(priv->codec_data.av1.uncompressed_header.tm); - - if (hdr->CodedLossless) { - tm->TxMode = AV1_ONLY_4X4; - } else { - bool tx_mode_select = av1_f(vlc, 1); - tm->TxMode = (tx_mode_select) ? AV1_TX_MODE_SELECT : AV1_TX_MODE_LARGEST; - } -} - -static void frame_reference_mode(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - - if (hdr->FrameIsIntra) - hdr->reference_select = SINGLE_REFERENCE; - else - hdr->reference_select = av1_f(vlc, 1) ? REFERENCE_MODE_SELECT : SINGLE_REFERENCE; -} - -static void skip_mode_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct skip_mode_params *smp = &(priv->codec_data.av1.uncompressed_header.smp);; - bool skipModeAllowed; - int i; - - if (hdr->FrameIsIntra || hdr->reference_select == SINGLE_REFERENCE || - !seq->enable_order_hint) { - skipModeAllowed = 0; - } else { - int ref_frame_offset[2] = { -1, INT_MAX }; - int ref_idx[2] = { -1, -1 }; - - skipModeAllowed = 0; - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) { - unsigned ref_offset = priv->codec_data.av1.refs[hdr->ref_frame_idx[i]].OrderHint; - if (get_relative_dist(priv, ref_offset, hdr->OrderHint) < 0) { - if (ref_frame_offset[0] == -1 || - get_relative_dist(priv, ref_offset, ref_frame_offset[0]) > 0) { - ref_frame_offset[0] = ref_offset; - ref_idx[0] = i; - } - } else if (get_relative_dist(priv, ref_offset, hdr->OrderHint) > 0) { - if (ref_frame_offset[1] == INT_MAX || - get_relative_dist(priv, ref_offset, ref_frame_offset[1]) < 0) { - ref_frame_offset[1] = ref_offset; - ref_idx[1] = i; - } - } - } - - if (ref_idx[0] != -1 && ref_idx[1] != -1) { - skipModeAllowed = 1; - } else if (ref_idx[0] != -1 && ref_idx[1] == -1) { - ref_frame_offset[1] = -1; - for (i = 0; i < AV1_ALTREF_FRAME - AV1_LAST_FRAME + 1; ++i) { - unsigned ref_offset = priv->codec_data.av1.refs[hdr->ref_frame_idx[i]].OrderHint; - if ((ref_frame_offset[0] != -1 && - get_relative_dist(priv, ref_offset, ref_frame_offset[0]) < 0) && - (ref_frame_offset[1] == -1 || - get_relative_dist(priv, ref_offset, ref_frame_offset[1]) > 0)) { - ref_frame_offset[1] = ref_offset; - ref_idx[1] = i; - } - } - if (ref_frame_offset[1] != -1) - skipModeAllowed = 1; - } - } - - smp->skip_mode_present = skipModeAllowed ? av1_f(vlc, 1) : 0; -} - -static unsigned inverse_recenter(unsigned r, unsigned v) -{ - if (v > (2 * r)) - return v; - else if (v & 1) - return (r - ((v + 1) >> 1)); - else - return (r + (v >> 1)); -} - -static unsigned decode_subexp(struct vl_vlc *vlc, unsigned numSyms) -{ - unsigned i = 0; - unsigned mk = 0; - unsigned k = 3; - - while (1) { - unsigned b2 = (i) ? (k + i - 1) : k; - unsigned a = 1 << b2; - if (numSyms <= (mk + 3 * a)) { - unsigned subexp_final_bits = av1_ns(vlc, (numSyms - mk)); - return (subexp_final_bits + mk); - } else { - bool subexp_more_bits = av1_f(vlc, 1); - if (subexp_more_bits) { - i++; - mk += a; - } else { - unsigned subexp_bits = av1_f(vlc, b2); - return (subexp_bits + mk); - } - } - } -} - -static unsigned decode_unsigned_subexp_with_ref(struct vl_vlc *vlc, - unsigned mx, unsigned r) -{ - unsigned smart; - unsigned v = decode_subexp(vlc, mx); - - if ((r << 1) <= mx) { - smart = inverse_recenter(r, v); - return smart; - } else { - smart = inverse_recenter(mx - 1 - r, v); - return (mx - 1 - smart); - } -} - -static int decode_signed_subexp_with_ref(struct vl_vlc *vlc, int low, int high, int r) -{ - int x = decode_unsigned_subexp_with_ref(vlc, high - low, r - low); - - return (x + low); -} - -static void read_global_param(struct global_motion_params* global_params, - struct global_motion_params* ref_params, - vid_dec_PrivateType *priv, struct vl_vlc *vlc, - uint8_t type, uint8_t ref, uint8_t idx) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - uint8_t absBits = 12; /* GM_ABS_ALPHA_BITS */ - uint8_t precBits = 15; /* GM_ALPHA_PREC_BITS */ - int precDiff, round, sub, mx, r = 0; - - if (idx < 2) { - if (type == AV1_TRANSLATION) { - absBits = 9 /* GM_ABS_TRANS_ONLY_BITS */ - !hdr->allow_high_precision_mv; - precBits = 3 /* GM_TRANS_ONLY_PREC_BITS */ - !hdr->allow_high_precision_mv; - } else { - absBits = 12; /* GM_ABS_TRANS_BITS */ - precBits = 6; /* GM_TRANS_PREC_BITS */; - } - } - - precDiff = AV1_WARPEDMODEL_PREC_BITS - precBits; - round = ((idx % 3) == 2) ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0; - sub = ((idx % 3) == 2) ? (1 << precBits) : 0; - mx = (int)(1 << absBits); - if (ref_params) - r = (ref_params->gm_params[ref][idx] >> precDiff) - sub; - - global_params->gm_params[ref][idx] = - (decode_signed_subexp_with_ref(vlc, -mx, mx + 1, r) << precDiff) + round; -} - -static void global_motion_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct global_motion_params *gmp = &(priv->codec_data.av1.uncompressed_header.gmp); - struct global_motion_params *ref_gmp = NULL; - unsigned ref, i; - - if (hdr->primary_ref_frame == AV1_PRIMARY_REF_NONE) { - for (ref = 0; ref < AV1_NUM_REF_FRAMES; ++ref) { - gmp->GmType[ref] = AV1_IDENTITY; - for (i = 0; i < 6; ++i) - gmp->gm_params[ref][i] = (((i % 3) == 2) ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0); - } - } else { - const int r = hdr->ref_frame_idx[hdr->primary_ref_frame]; - ref_gmp = &(priv->codec_data.av1.refs[r].gmp); - } - - for (ref = AV1_LAST_FRAME; ref <= AV1_ALTREF_FRAME; ++ref) { - gmp->GmType[ref] = AV1_IDENTITY; - for (i = 0; i < 6; ++i) - gmp->gm_params[ref][i] = (((i % 3) == 2) ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0); - } - - if (hdr->FrameIsIntra) - return; - - for (ref = AV1_LAST_FRAME; ref <= AV1_ALTREF_FRAME; ++ref) { - uint8_t type = AV1_IDENTITY; - bool is_global; - - gmp->GmType[ref] = AV1_IDENTITY; - for (i = 0; i < 6; ++i) - gmp->gm_params[ref][i] = (((i % 3) == 2) ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0); - - is_global = av1_f(vlc, 1); - if (is_global) { - bool is_rot_zoom = av1_f(vlc, 1); - if (is_rot_zoom) { - type = AV1_ROTZOOM; - } else { - bool is_translation = av1_f(vlc, 1); - type = is_translation ? AV1_TRANSLATION : AV1_AFFINE; - } - } - - gmp->GmType[ref] = type; - - if (type >= AV1_ROTZOOM) { - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 2); - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 3); - if (type == AV1_AFFINE) { - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 4); - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 5); - } else { - gmp->gm_params[ref][4] = -gmp->gm_params[ref][3]; - gmp->gm_params[ref][5] = gmp->gm_params[ref][2]; - } - } - - if (type >= AV1_TRANSLATION) { - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 0); - read_global_param(gmp, ref_gmp, priv, vlc, type, ref, 1); - } - } -} - -static void film_grain_params(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - struct film_grain_params *fgp = &(priv->codec_data.av1.uncompressed_header.fgp); - - bool update_grain; - uint8_t numPosLuma; - uint8_t numPosChroma; - unsigned i; - - if (!seq->film_grain_params_present || - (!hdr->show_frame && !hdr->showable_frame)) { - memset(fgp, 0, sizeof(*fgp)); - return; - } - - fgp->apply_grain = av1_f(vlc, 1); - if (!fgp->apply_grain) { - memset(fgp, 0, sizeof(*fgp)); - return; - } - - fgp->grain_seed = av1_f(vlc, 16); - update_grain = - (hdr->frame_type == AV1_INTER_FRAME) ? av1_f(vlc, 1) : 1; - - if (!update_grain) { - uint8_t film_grain_params_ref_idx = av1_f(vlc, 3); - uint16_t tempGrainSeed = fgp->grain_seed; - memcpy(fgp, &(priv->codec_data.av1.refs[film_grain_params_ref_idx].fgp), - sizeof(*fgp)); - fgp->grain_seed = tempGrainSeed; - return; - } - - fgp->num_y_points = av1_f(vlc, 4); - for (i = 0; i < fgp->num_y_points; ++i) { - fgp->point_y_value[i] = av1_f(vlc, 8); - fgp->point_y_scaling[i] = av1_f(vlc, 8); - } - - fgp->chroma_scaling_from_luma = - (seq->color_config.mono_chrome) ? 0 : av1_f(vlc, 1); - if (seq->color_config.mono_chrome || fgp->chroma_scaling_from_luma || - (seq->color_config.subsampling_x && seq->color_config.subsampling_y && - (fgp->num_y_points == 0))) { - fgp->num_cb_points = 0; - fgp->num_cr_points = 0; - } else { - fgp->num_cb_points = av1_f(vlc, 4); - for (i = 0; i < fgp->num_cb_points; ++i) { - fgp->point_cb_value[i] = av1_f(vlc, 8); - fgp->point_cb_scaling[i] = av1_f(vlc, 8); - } - fgp->num_cr_points = av1_f(vlc, 4); - for (i = 0; i < fgp->num_cr_points; ++i) { - fgp->point_cr_value[i] = av1_f(vlc, 8); - fgp->point_cr_scaling[i] = av1_f(vlc, 8); - } - } - - fgp->grain_scaling_minus_8 = av1_f(vlc, 2); - fgp->ar_coeff_lag = av1_f(vlc, 2); - numPosLuma = 2 * fgp->ar_coeff_lag * (fgp->ar_coeff_lag + 1); - if (fgp->num_y_points) { - numPosChroma = numPosLuma + 1; - for (i = 0; i < numPosLuma; ++i) { - uint8_t ar_coeffs_y_plus_128 = av1_f(vlc, 8); - fgp->ar_coeffs_y[i] = ar_coeffs_y_plus_128 - 128; - } - } else { - numPosChroma = numPosLuma; - } - - if (fgp->chroma_scaling_from_luma || fgp->num_cb_points) { - for (i = 0; i < numPosChroma; ++i) { - uint8_t ar_coeffs_cb_plus_128 = av1_f(vlc, 8); - fgp->ar_coeffs_cb[i] = ar_coeffs_cb_plus_128 - 128; - } - } - - if (fgp->chroma_scaling_from_luma || fgp->num_cr_points) { - for (i = 0; i < numPosChroma; ++i) { - uint8_t ar_coeffs_cr_plus_128 = av1_f(vlc, 8); - fgp->ar_coeffs_cr[i] = ar_coeffs_cr_plus_128 - 128; - } - } - - fgp->ar_coeff_shift_minus_6 = av1_f(vlc, 2); - fgp->grain_scale_shift = av1_f(vlc, 2); - if (fgp->num_cb_points) { - fgp->cb_mult = av1_f(vlc, 8); - fgp->cb_luma_mult = av1_f(vlc, 8); - fgp->cb_offset = av1_f(vlc, 9); - } - - if (fgp->num_cr_points) { - fgp->cr_mult = av1_f(vlc, 8); - fgp->cr_luma_mult = av1_f(vlc, 8); - fgp->cr_offset = av1_f(vlc, 9); - } - - fgp->overlap_flag = av1_f(vlc, 1); - fgp->clip_to_restricted_range = av1_f(vlc, 1); -} - -static void frame_header_obu(vid_dec_PrivateType *priv, struct vl_vlc *vlc) -{ - struct av1_sequence_header_obu *seq = &(priv->codec_data.av1.seq); - struct av1_uncompressed_header_obu *hdr = &(priv->codec_data.av1.uncompressed_header); - unsigned idLen = 0; - unsigned allFrames; - int i, j; - - memset(hdr, 0, sizeof(*hdr)); - - if (seq->frame_id_numbers_present_flag) - idLen = seq->additional_frame_id_length_minus_1 + - seq->delta_frame_id_length_minus_2 + 3; - - allFrames = (1 << AV1_NUM_REF_FRAMES) - 1; - if (seq->reduced_still_picture_header) { - hdr->show_existing_frame = 0; - hdr->frame_type = AV1_KEY_FRAME; - hdr->FrameIsIntra = 1; - hdr->show_frame = 1; - hdr->showable_frame = 0; - } else { - hdr->show_existing_frame = av1_f(vlc, 1); - if (hdr->show_existing_frame) { - hdr->frame_to_show_map_idx = av1_f(vlc, 3); - if (seq->decoder_model_info_present_flag && - !seq->timing_info.equal_picture_interval) - av1_f(vlc, seq->decoder_model_info. - frame_presentation_time_length_minus_1 + 1); - hdr->refresh_frame_flags = 0; - if (seq->frame_id_numbers_present_flag) - av1_f(vlc, idLen); /* display_frame_id */ - - hdr->frame_type = - priv->codec_data.av1.RefFrames[priv->codec_data.av1.uncompressed_header. - frame_to_show_map_idx].RefFrameType; - - return; - } - - hdr->frame_type = av1_f(vlc, 2); - hdr->FrameIsIntra = (hdr->frame_type == AV1_INTRA_ONLY_FRAME || - hdr->frame_type == AV1_KEY_FRAME); - hdr->show_frame = av1_f(vlc, 1); - - if (hdr->show_frame && seq->decoder_model_info_present_flag && - !seq->timing_info.equal_picture_interval) - av1_f(vlc, seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1); - - hdr->showable_frame = - hdr->show_frame ? (hdr->frame_type != AV1_KEY_FRAME) : av1_f(vlc, 1); - - hdr->error_resilient_mode = (hdr->frame_type == AV1_SWITCH_FRAME || - (hdr->frame_type == AV1_KEY_FRAME && hdr->show_frame)) ? 1 : av1_f(vlc, 1); - } - - if (hdr->frame_type == AV1_KEY_FRAME && hdr->show_frame) { - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) - hdr->RefOrderHint[i] = 0; - } - - hdr->disable_cdf_update = av1_f(vlc, 1); - - hdr->allow_screen_content_tools = - (seq->seq_force_screen_content_tools == AV1_SELECT_SCREEN_CONTENT_TOOLS) ? - av1_f(vlc, 1) : seq->seq_force_screen_content_tools; - - if (hdr->allow_screen_content_tools) { - if (seq->seq_force_integer_mv == AV1_SELECT_INTEGER_MV) - hdr->force_integer_mv = av1_f(vlc, 1); - else - hdr->force_integer_mv = seq->seq_force_integer_mv; - } else { - hdr->force_integer_mv = 0; - } - - if (hdr->FrameIsIntra) - hdr->force_integer_mv = 1; - - hdr->current_frame_id = - seq->frame_id_numbers_present_flag ? av1_f(vlc, idLen) : 0; - - if (hdr->frame_type == AV1_SWITCH_FRAME) - hdr->frame_size_override_flag = 1; - else if (seq->reduced_still_picture_header) - hdr->frame_size_override_flag = 0; - else - hdr->frame_size_override_flag = av1_f(vlc, 1); - - hdr->OrderHint = av1_f(vlc, seq->OrderHintBits); - - if (hdr->FrameIsIntra || hdr->error_resilient_mode) - hdr->primary_ref_frame = AV1_PRIMARY_REF_NONE; - else - hdr->primary_ref_frame = av1_f(vlc, 3); - - if (seq->decoder_model_info_present_flag) { - bool buffer_removal_time_present_flag = av1_f(vlc, 1); - if (buffer_removal_time_present_flag) { - for (i = 0; i <= seq->operating_points_cnt_minus_1; ++i) { - if (seq->decoder_model_present_for_this_op[i]) { - unsigned opPtIdc; - bool inTemporalLayer; - bool inSpatialLayer; - opPtIdc = seq->operating_point_idc[i]; - inTemporalLayer = - (opPtIdc >> priv->codec_data.av1.ext.temporal_id) & 1; - inSpatialLayer = - (opPtIdc >> (priv->codec_data.av1.ext.spatial_id + 8)) & 1; - if ((opPtIdc == 0) || (inTemporalLayer && inSpatialLayer)) - av1_f(vlc, seq->decoder_model_info. - buffer_removal_time_length_minus_1 + 1); - } - } - } - } - - hdr->allow_high_precision_mv = 0; - hdr->use_ref_frame_mvs = 0; - hdr->allow_intrabc = 0; - - hdr->refresh_frame_flags = allFrames = (hdr->frame_type == AV1_SWITCH_FRAME || - (hdr->frame_type == AV1_KEY_FRAME && hdr->show_frame)) ? - allFrames : av1_f(vlc, AV1_NUM_REF_FRAMES); - - if (!hdr->FrameIsIntra || hdr->refresh_frame_flags != allFrames) { - if (hdr->error_resilient_mode && seq->enable_order_hint) { - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) - av1_f(vlc, seq->OrderHintBits); - } - } - - if (hdr->FrameIsIntra) { - frame_size(priv, vlc); - render_size(priv, vlc); - if (hdr->allow_screen_content_tools && (hdr->UpscaledWidth == hdr->FrameWidth)) - hdr->allow_intrabc = av1_f(vlc, 1); - } else { - bool is_filter_switchable; - bool frame_refs_short_signaling; - - if (!seq->enable_order_hint) { - frame_refs_short_signaling = 0; - } else { - frame_refs_short_signaling = av1_f(vlc, 1); - if (frame_refs_short_signaling) { - hdr->last_frame_idx = av1_f(vlc, 3); - hdr->gold_frame_idx = av1_f(vlc, 3); - set_frame_refs(priv, vlc); - } - } - - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) { - if (!frame_refs_short_signaling) - hdr->ref_frame_idx[i] = av1_f(vlc, 3); - if (seq->frame_id_numbers_present_flag) - av1_f(vlc, seq->delta_frame_id_length_minus_2 + 2); - } - - if (hdr->frame_size_override_flag && !hdr->error_resilient_mode) { - frame_size_with_refs(priv, vlc); - } else { - frame_size(priv, vlc); - render_size(priv, vlc); - } - - hdr->allow_high_precision_mv = hdr->force_integer_mv ? 0 : av1_f(vlc, 1); - - is_filter_switchable = av1_f(vlc, 1); - hdr->interpolation_filter = is_filter_switchable ? 4 /* SWITCHABLE */ : av1_f(vlc, 2); - - hdr->is_motion_mode_switchable = av1_f(vlc, 1); - hdr->use_ref_frame_mvs = - (hdr->error_resilient_mode || !seq->enable_ref_frame_mvs) ? 0 : av1_f(vlc, 1); - } - - hdr->disable_frame_end_update_cdf = - (seq->reduced_still_picture_header || hdr->disable_cdf_update) ? 1 : av1_f(vlc, 1); - - tile_info(priv, vlc); - quantization_params(priv, vlc); - segmentation_params(priv, vlc); - delta_q_params(priv, vlc); - delta_lf_params(priv, vlc); - - hdr->CodedLossless = 1; - for (i = 0; i < AV1_MAX_SEGMENTS; ++i) { - unsigned qindex = get_qindex(priv, 1, i); - bool LosslessArray = - (qindex == 0) && (hdr->qp.DeltaQYDc == 0) && - (hdr->qp.DeltaQUAc == 0) && (hdr->qp.DeltaQUDc == 0) && - (hdr->qp.DeltaQVAc == 0) && (hdr->qp.DeltaQVDc == 0); - - if (!LosslessArray) - hdr->CodedLossless = 0; - } - hdr->AllLossless = hdr->CodedLossless && (hdr->FrameWidth == hdr->UpscaledWidth); - - loop_filter_params(priv, vlc); - cdef_params(priv, vlc); - lr_params(priv, vlc); - tx_mode(priv, vlc); - frame_reference_mode(priv, vlc); - skip_mode_params(priv, vlc); - - if (hdr->FrameIsIntra || hdr->error_resilient_mode || !seq->enable_warped_motion) - hdr->allow_warped_motion = 0; - else - hdr->allow_warped_motion = av1_f(vlc, 1); - hdr->reduced_tx_set = av1_f(vlc, 1); - - global_motion_params(priv, vlc); - - film_grain_params(priv, vlc); - - priv->picture.av1.film_grain_target = NULL; - priv->picture.av1.picture_parameter.pic_info_fields.frame_type = hdr->frame_type; - priv->picture.av1.picture_parameter.pic_info_fields.show_frame = hdr->show_frame; - priv->picture.av1.picture_parameter.pic_info_fields.error_resilient_mode = - hdr->error_resilient_mode; - priv->picture.av1.picture_parameter.pic_info_fields.disable_cdf_update = - hdr->disable_cdf_update; - priv->picture.av1.picture_parameter.pic_info_fields.allow_screen_content_tools = - hdr->allow_screen_content_tools; - priv->picture.av1.picture_parameter.pic_info_fields.force_integer_mv = - hdr->force_integer_mv; - priv->picture.av1.picture_parameter.current_frame_id = hdr->current_frame_id; - priv->picture.av1.picture_parameter.order_hint = hdr->OrderHint; - priv->picture.av1.picture_parameter.primary_ref_frame = hdr->primary_ref_frame; - priv->picture.av1.picture_parameter.frame_width = hdr->FrameWidth; - priv->picture.av1.picture_parameter.frame_height = hdr->FrameHeight; - priv->picture.av1.picture_parameter.pic_info_fields.use_superres = - hdr->use_superres; - priv->picture.av1.picture_parameter.superres_scale_denominator = - hdr->SuperresDenom; - - for (i = 0; i < AV1_REFS_PER_FRAME; ++i) - priv->picture.av1.picture_parameter.ref_frame_idx[i] = hdr->ref_frame_idx[i]; - - priv->picture.av1.picture_parameter.pic_info_fields.allow_high_precision_mv = - hdr->allow_high_precision_mv; - priv->picture.av1.picture_parameter.pic_info_fields.allow_intrabc = hdr->allow_intrabc; - priv->picture.av1.picture_parameter.pic_info_fields.use_ref_frame_mvs = - hdr->use_ref_frame_mvs; - priv->picture.av1.picture_parameter.interp_filter = hdr->interpolation_filter; - priv->picture.av1.picture_parameter.pic_info_fields.is_motion_mode_switchable = - hdr->is_motion_mode_switchable; - priv->picture.av1.picture_parameter.refresh_frame_flags = - hdr->refresh_frame_flags; - priv->picture.av1.picture_parameter.pic_info_fields.disable_frame_end_update_cdf = - hdr->disable_frame_end_update_cdf; - - /* Tile Info */ - priv->picture.av1.picture_parameter.tile_rows = hdr->ti.TileRows; - priv->picture.av1.picture_parameter.tile_cols = hdr->ti.TileCols; - priv->picture.av1.picture_parameter.context_update_tile_id = - hdr->ti.context_update_tile_id; - for (i = 0; i picture.av1.picture_parameter.tile_row_start_sb[i] = - hdr->ti.tile_row_start_sb[i]; - for (i = 0; i picture.av1.picture_parameter.tile_col_start_sb[i] = - hdr->ti.tile_col_start_sb[i]; - - /* Quantization Params */ - priv->picture.av1.picture_parameter.base_qindex = hdr->qp.base_q_idx; - priv->picture.av1.picture_parameter.y_dc_delta_q = hdr->qp.DeltaQYDc; - priv->picture.av1.picture_parameter.u_dc_delta_q = hdr->qp.DeltaQUDc; - priv->picture.av1.picture_parameter.u_ac_delta_q = hdr->qp.DeltaQUAc; - priv->picture.av1.picture_parameter.v_dc_delta_q = hdr->qp.DeltaQVDc; - priv->picture.av1.picture_parameter.v_ac_delta_q = hdr->qp.DeltaQVAc; - priv->picture.av1.picture_parameter.qmatrix_fields.qm_y = hdr->qp.qm_y; - priv->picture.av1.picture_parameter.qmatrix_fields.qm_u = hdr->qp.qm_u; - priv->picture.av1.picture_parameter.qmatrix_fields.qm_v = hdr->qp.qm_v; - - /* Segmentation Params */ - priv->picture.av1.picture_parameter.seg_info.segment_info_fields.enabled = - hdr->sp.segmentation_enabled; - priv->picture.av1.picture_parameter.seg_info.segment_info_fields.update_map = - hdr->sp.segmentation_update_map; - priv->picture.av1.picture_parameter.seg_info.segment_info_fields.temporal_update = - hdr->sp.segmentation_temporal_update; - for (i = 0; i < AV1_MAX_SEGMENTS; ++i) { - for (j = 0; j < AV1_SEG_LVL_MAX; ++j) - priv->picture.av1.picture_parameter.seg_info.feature_data[i][j] = - hdr->sp.FeatureData[i][j]; - priv->picture.av1.picture_parameter.seg_info.feature_mask[i] = - hdr->sp.FeatureMask[i]; - } - - /* Delta Q Params */ - priv->picture.av1.picture_parameter.mode_control_fields.delta_q_present_flag = - hdr->dqp.delta_q_present; - priv->picture.av1.picture_parameter.mode_control_fields.log2_delta_q_res = - hdr->dqp.delta_q_res; - - /* Delta LF Params */ - priv->picture.av1.picture_parameter.mode_control_fields.delta_lf_present_flag = - hdr->dlfp.delta_lf_present; - priv->picture.av1.picture_parameter.mode_control_fields.log2_delta_lf_res = - hdr->dlfp.delta_lf_res; - priv->picture.av1.picture_parameter.mode_control_fields.delta_lf_multi = - hdr->dlfp.delta_lf_multi; - - /* Loop Filter Params */ - for (i = 0; i < 2; ++i) - priv->picture.av1.picture_parameter.filter_level[i] = hdr->lfp.loop_filter_level[i]; - priv->picture.av1.picture_parameter.filter_level_u = hdr->lfp.loop_filter_level[2]; - priv->picture.av1.picture_parameter.filter_level_v = hdr->lfp.loop_filter_level[3]; - priv->picture.av1.picture_parameter.loop_filter_info_fields.sharpness_level = - hdr->lfp.loop_filter_sharpness; - priv->picture.av1.picture_parameter.loop_filter_info_fields.mode_ref_delta_enabled = - hdr->lfp.loop_filter_delta_enabled; - priv->picture.av1.picture_parameter.loop_filter_info_fields.mode_ref_delta_update = - hdr->lfp.loop_filter_delta_update; - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) - priv->picture.av1.picture_parameter.ref_deltas[i] = - hdr->lfp.loop_filter_ref_deltas[i]; - for (i = 0; i < 2; ++i) - priv->picture.av1.picture_parameter.mode_deltas[i] = - hdr->lfp.loop_filter_mode_deltas[i]; - - /* CDEF Params */ - priv->picture.av1.picture_parameter.cdef_damping_minus_3 = - hdr->cdefp.cdef_damping_minus_3; - priv->picture.av1.picture_parameter.cdef_bits = hdr->cdefp.cdef_bits; - for (i = 0; i < AV1_MAX_CDEF_BITS_ARRAY; ++i) { - priv->picture.av1.picture_parameter.cdef_y_strengths[i] = - hdr->cdefp.cdef_y_strengths[i]; - priv->picture.av1.picture_parameter.cdef_uv_strengths[i] = - hdr->cdefp.cdef_uv_strengths[i]; - } - - /* Loop Restoration Params */ - priv->picture.av1.picture_parameter.loop_restoration_fields.yframe_restoration_type = - hdr->lrp.FrameRestorationType[0]; - priv->picture.av1.picture_parameter.loop_restoration_fields.cbframe_restoration_type = - hdr->lrp.FrameRestorationType[1]; - priv->picture.av1.picture_parameter.loop_restoration_fields.crframe_restoration_type = - hdr->lrp.FrameRestorationType[2]; - for (i = 0; i < 3; ++i) - priv->picture.av1.picture_parameter.lr_unit_size[i] = hdr->lrp.LoopRestorationSize[i]; - - priv->picture.av1.picture_parameter.mode_control_fields.tx_mode = hdr->tm.TxMode; - priv->picture.av1.picture_parameter.mode_control_fields.reference_select = - (hdr->reference_select == REFERENCE_MODE_SELECT) ? COMPOUND_REFERENCE : SINGLE_REFERENCE; - priv->picture.av1.picture_parameter.mode_control_fields.skip_mode_present = - hdr->smp.skip_mode_present; - priv->picture.av1.picture_parameter.pic_info_fields.allow_warped_motion = - hdr->allow_warped_motion; - priv->picture.av1.picture_parameter.mode_control_fields.reduced_tx_set_used = - hdr->reduced_tx_set; - - /* Global Motion Params */ - for (i = 0; i < 7; ++i) { - priv->picture.av1.picture_parameter.wm[i].wmtype = hdr->gmp.GmType[i + 1]; - for (j = 0; j < 6; ++j) - priv->picture.av1.picture_parameter.wm[i].wmmat[j] = hdr->gmp.gm_params[i + 1][j]; - } - - /* Film Grain Params */ - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields.apply_grain = - hdr->fgp.apply_grain; - priv->picture.av1.picture_parameter.film_grain_info.grain_seed = - hdr->fgp.grain_seed; - priv->picture.av1.picture_parameter.film_grain_info.num_y_points = - hdr->fgp.num_y_points; - for (i = 0; i < AV1_FG_MAX_NUM_Y_POINTS; ++i) { - priv->picture.av1.picture_parameter.film_grain_info.point_y_value[i] = - hdr->fgp.point_y_value[i]; - priv->picture.av1.picture_parameter.film_grain_info.point_y_scaling[i] = - hdr->fgp.point_y_scaling[i]; - } - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - chroma_scaling_from_luma = hdr->fgp.chroma_scaling_from_luma; - priv->picture.av1.picture_parameter.film_grain_info.num_cb_points = - hdr->fgp.num_cb_points; - priv->picture.av1.picture_parameter.film_grain_info.num_cr_points = - hdr->fgp.num_cr_points; - for (i = 0; i < AV1_FG_MAX_NUM_CBR_POINTS; ++i) { - priv->picture.av1.picture_parameter.film_grain_info.point_cb_value[i] = - hdr->fgp.point_cb_value[i]; - priv->picture.av1.picture_parameter.film_grain_info.point_cb_scaling[i] = - hdr->fgp.point_cb_scaling[i]; - priv->picture.av1.picture_parameter.film_grain_info.point_cr_value[i] = - hdr->fgp.point_cr_value[i]; - priv->picture.av1.picture_parameter.film_grain_info.point_cr_scaling[i] = - hdr->fgp.point_cr_scaling[i]; - } - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - grain_scaling_minus_8 = hdr->fgp.grain_scaling_minus_8; - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - ar_coeff_lag = hdr->fgp.ar_coeff_lag; - for (i = 0; i < AV1_FG_MAX_NUM_POS_LUMA; ++i) - priv->picture.av1.picture_parameter.film_grain_info.ar_coeffs_y[i] = - hdr->fgp.ar_coeffs_y[i]; - for (i = 0; i < AV1_FG_MAX_NUM_POS_CHROMA; ++i) { - priv->picture.av1.picture_parameter.film_grain_info.ar_coeffs_cb[i] = - hdr->fgp.ar_coeffs_cb[i]; - priv->picture.av1.picture_parameter.film_grain_info.ar_coeffs_cr[i] = - hdr->fgp.ar_coeffs_cr[i]; - } - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - ar_coeff_shift_minus_6 = hdr->fgp.ar_coeff_shift_minus_6; - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - grain_scale_shift = hdr->fgp.grain_scale_shift; - priv->picture.av1.picture_parameter.film_grain_info.cb_mult = hdr->fgp.cb_mult; - priv->picture.av1.picture_parameter.film_grain_info.cb_luma_mult = hdr->fgp.cb_luma_mult; - priv->picture.av1.picture_parameter.film_grain_info.cb_offset = hdr->fgp.cb_offset; - priv->picture.av1.picture_parameter.film_grain_info.cr_mult = hdr->fgp.cr_mult; - priv->picture.av1.picture_parameter.film_grain_info.cr_luma_mult = hdr->fgp.cr_luma_mult; - priv->picture.av1.picture_parameter.film_grain_info.cr_offset = hdr->fgp.cr_offset; - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - overlap_flag = hdr->fgp.overlap_flag; - priv->picture.av1.picture_parameter.film_grain_info.film_grain_info_fields. - clip_to_restricted_range = hdr->fgp.clip_to_restricted_range; -} - -static void parse_tile_hdr(vid_dec_PrivateType *priv, struct vl_vlc *vlc, - unsigned start_bits_pos, unsigned total_obu_len) -{ - struct tile_info *ti = &(priv->codec_data.av1.uncompressed_header.ti); - unsigned tg_start, tg_end; - unsigned NumTiles, tileBits; - bool tile_start_and_end_present_flag; - unsigned size[AV1_MAX_NUM_TILES] = { 0 }; - unsigned offset[AV1_MAX_NUM_TILES] = { 0 }; - unsigned frame_header_size, left_size; - unsigned i, j; - - NumTiles = ti->TileCols * ti->TileRows; - tile_start_and_end_present_flag = 0; - if (NumTiles > 1) - tile_start_and_end_present_flag = av1_f(vlc, 1); - - if (NumTiles == 1 || !tile_start_and_end_present_flag) { - tg_start = 0; - tg_end = NumTiles - 1; - } else { - tileBits = ti->TileColsLog2 + ti->TileRowsLog2; - tg_start = av1_f(vlc, tileBits); - tg_end = av1_f(vlc, tileBits); - } - - av1_byte_alignment(vlc); - - frame_header_size = (start_bits_pos - vl_vlc_bits_left(vlc)) / 8; - left_size = total_obu_len - frame_header_size; - for (i = tg_start; i <= tg_end; ++i) { - if (i == tg_start) { - offset[i] = priv->codec_data.av1.bs_obu_td_sz + - priv->codec_data.av1.bs_obu_seq_sz + frame_header_size + - ti->TileSizeBytes; - if (tg_start == tg_end) { - size[i] = left_size; - for (j = 0; j < size[i]; ++j) { - vl_vlc_fillbits(vlc); - vl_vlc_eatbits(vlc, 8); - } - break; - } - } else { - offset[i] = offset[i - 1] + ti->TileSizeBytes + size[i - 1]; - left_size -= ti->TileSizeBytes + size[i - 1]; - } - - if (i != tg_end) { - size[i] = av1_le(vlc, ti->TileSizeBytes) + 1; - } else { - offset[i] = offset[i - 1] + size[i - 1]; - size[i] = left_size; - } - - for (j = 0; j < size[i]; ++j) { - vl_vlc_fillbits(vlc); - vl_vlc_eatbits(vlc, 8); - } - } - - for (i = tg_start; i <= tg_end; ++i) { - priv->picture.av1.slice_parameter.slice_data_offset[i] = offset[i]; - priv->picture.av1.slice_parameter.slice_data_size[i] = size[i]; - } -} - -static struct dec_av1_task *dec_av1_NeedTask(vid_dec_PrivateType *priv) -{ - struct pipe_video_buffer templat = {}; - struct dec_av1_task *task; - struct vl_screen *omx_screen; - struct pipe_screen *pscreen; - - omx_screen = priv->screen; - assert(omx_screen); - - pscreen = omx_screen->pscreen; - assert(pscreen); - - if (!list_is_empty(&priv->codec_data.av1.free_tasks)) { - task = list_entry(priv->codec_data.av1.free_tasks.next, - struct dec_av1_task, list); - task->buf_ref_count = 1; - list_del(&task->list); - return task; - } - - task = CALLOC_STRUCT(dec_av1_task); - if (!task) - return NULL; - - memset(&templat, 0, sizeof(templat)); - templat.width = priv->codec->width; - templat.height = priv->codec->height; - templat.buffer_format = pscreen->get_video_param( - pscreen, - PIPE_VIDEO_PROFILE_UNKNOWN, - PIPE_VIDEO_ENTRYPOINT_BITSTREAM, - PIPE_VIDEO_CAP_PREFERED_FORMAT - ); - templat.interlaced = false; - - task->buf = priv->pipe->create_video_buffer(priv->pipe, &templat); - if (!task->buf) { - FREE(task); - return NULL; - } - task->buf_ref_count = 1; - task->is_sef_task = false; - - return task; -} - -static void dec_av1_ReleaseTask(vid_dec_PrivateType *priv, - struct list_head *head) -{ - if (!head || !head->next) - return; - - list_for_each_entry_safe(struct dec_av1_task, task, head, list) { - task->buf->destroy(task->buf); - FREE(task); - } -} - -static void dec_av1_MoveTask(struct list_head *from, - struct list_head *to) -{ - to->prev->next = from->next; - from->next->prev = to->prev; - from->prev->next = to; - to->prev = from->prev; - list_inithead(from); -} - -static void dec_av1_SortTask(vid_dec_PrivateType *priv) -{ - int i; - - list_for_each_entry_safe(struct dec_av1_task, t, - &priv->codec_data.av1.finished_tasks, list) { - bool found = false; - for (i = 0; i < 8; ++i) { - if (t->buf == priv->picture.av1.ref[i]) { - found = true; - break; - } - } - if (!found && t->buf_ref_count == 0) { - list_del(&t->list); - list_addtail(&t->list, &priv->codec_data.av1.free_tasks); - } - } -} - -static struct dec_av1_task *dec_av1_SearchTask(vid_dec_PrivateType *priv, - struct list_head *tasks) -{ - unsigned idx = - priv->codec_data.av1.uncompressed_header.frame_to_show_map_idx; - - list_for_each_entry_safe(struct dec_av1_task, t, tasks, list) { - if (t->buf == priv->picture.av1.ref[idx]) - return t; - } - - return NULL; -} - -static bool dec_av1_GetStartedTask(vid_dec_PrivateType *priv, - struct dec_av1_task *task, struct list_head *tasks) -{ - struct dec_av1_task *started_task; - - ++priv->codec_data.av1.que_num; - list_addtail(&task->list, &priv->codec_data.av1.started_tasks); - if (priv->codec_data.av1.que_num <= 16) - return false; - - started_task = list_entry(priv->codec_data.av1.started_tasks.next, - struct dec_av1_task, list); - list_del(&started_task->list); - list_addtail(&started_task->list, tasks); - --priv->codec_data.av1.que_num; - - return true; -} - -static void dec_av1_ShowExistingframe(vid_dec_PrivateType *priv) -{ - struct input_buf_private *inp = priv->in_buffers[0]->pInputPortPrivate; - struct dec_av1_task *task, *existing_task; - bool fnd; - - task = CALLOC_STRUCT(dec_av1_task); - if (!task) - return; - - task->is_sef_task = true; - - mtx_lock(&priv->codec_data.av1.mutex); - dec_av1_MoveTask(&inp->tasks, &priv->codec_data.av1.finished_tasks); - dec_av1_SortTask(priv); - existing_task = dec_av1_SearchTask(priv, &priv->codec_data.av1.started_tasks); - if (existing_task) { - ++existing_task->buf_ref_count; - task->buf = existing_task->buf; - task->buf_ref = &existing_task->buf; - task->buf_ref_count = 0; - } else { - existing_task = dec_av1_SearchTask(priv, &priv->codec_data.av1.finished_tasks); - if (existing_task) { - struct vl_screen *omx_screen; - struct pipe_screen *pscreen; - struct pipe_video_buffer templat = {}; - struct pipe_video_buffer *buf; - struct pipe_box box={}; - - omx_screen = priv->screen; - assert(omx_screen); - - pscreen = omx_screen->pscreen; - assert(pscreen); - - memset(&templat, 0, sizeof(templat)); - templat.width = priv->codec->width; - templat.height = priv->codec->height; - templat.buffer_format = pscreen->get_video_param( - pscreen, - PIPE_VIDEO_PROFILE_UNKNOWN, - PIPE_VIDEO_ENTRYPOINT_BITSTREAM, - PIPE_VIDEO_CAP_PREFERED_FORMAT - ); - templat.interlaced = false; - buf = priv->pipe->create_video_buffer(priv->pipe, &templat); - if (!buf) { - FREE(task); - mtx_unlock(&priv->codec_data.av1.mutex); - return; - } - - box.width = priv->codec->width; - box.height = priv->codec->height; - box.depth = 1; - priv->pipe->resource_copy_region(priv->pipe, - ((struct vl_video_buffer *)buf)->resources[0], - 0, 0, 0, 0, - ((struct vl_video_buffer *)(existing_task->buf))->resources[0], - 0, &box); - box.width /= 2; - box.height/= 2; - priv->pipe->resource_copy_region(priv->pipe, - ((struct vl_video_buffer *)buf)->resources[1], - 0, 0, 0, 0, - ((struct vl_video_buffer *)(existing_task->buf))->resources[1], - 0, &box); - priv->pipe->flush(priv->pipe, NULL, 0); - existing_task->buf_ref_count = 0; - task->buf = buf; - task->buf_ref_count = 1; - } else { - FREE(task); - mtx_unlock(&priv->codec_data.av1.mutex); - return; - } - } - dec_av1_SortTask(priv); - - fnd = dec_av1_GetStartedTask(priv, task, &inp->tasks); - mtx_unlock(&priv->codec_data.av1.mutex); - if (fnd) - priv->frame_finished = 1; -} - -static struct dec_av1_task *dec_av1_BeginFrame(vid_dec_PrivateType *priv) -{ - struct input_buf_private *inp = priv->in_buffers[0]->pInputPortPrivate; - struct dec_av1_task *task; - - if (priv->frame_started) - return NULL; - - if (!priv->codec) { - struct vl_screen *omx_screen; - struct pipe_screen *pscreen; - struct pipe_video_codec templat = {}; - bool supported; - - omx_screen = priv->screen; - assert(omx_screen); - - pscreen = omx_screen->pscreen; - assert(pscreen); - - supported = vl_codec_supported(pscreen, priv->profile, false); - assert(supported && "AV1 is not supported"); - - templat.profile = priv->profile; - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.max_references = AV1_NUM_REF_FRAMES; - templat.expect_chunked_decode = true; - omx_base_video_PortType *port; - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - templat.width = port->sPortParam.format.video.nFrameWidth; - templat.height = port->sPortParam.format.video.nFrameHeight; - - priv->codec = priv->pipe->create_video_codec(priv->pipe, &templat); - } - - mtx_lock(&priv->codec_data.av1.mutex); - dec_av1_MoveTask(&inp->tasks, &priv->codec_data.av1.finished_tasks); - dec_av1_SortTask(priv); - mtx_unlock(&priv->codec_data.av1.mutex); - - task = dec_av1_NeedTask(priv); - if (!task) - return NULL; - - priv->codec->begin_frame(priv->codec, task->buf, &priv->picture.base); - priv->frame_started = true; - - return task; -} - -static void dec_av1_EndFrame(vid_dec_PrivateType *priv, struct dec_av1_task *task) -{ - struct input_buf_private *inp = priv->in_buffers[0]->pInputPortPrivate; - unsigned refresh_frame_flags; - bool fnd; - unsigned i; - - if (!priv->frame_started || ! task) - return; - - priv->codec->end_frame(priv->codec, task->buf, &priv->picture.base); - priv->frame_started = false; - - refresh_frame_flags = priv->codec_data.av1.uncompressed_header.refresh_frame_flags; - for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { - if (refresh_frame_flags & (1 << i)) { - memcpy(&priv->codec_data.av1.refs[i], &priv->codec_data.av1.uncompressed_header, - sizeof(struct av1_uncompressed_header_obu)); - priv->picture.av1.ref[i] = task->buf; - priv->codec_data.av1.RefFrames[i].RefFrameType = - priv->codec_data.av1.uncompressed_header.frame_type; - priv->codec_data.av1.RefFrames[i].RefFrameId = - priv->codec_data.av1.uncompressed_header.current_frame_id; - priv->codec_data.av1.RefFrames[i].RefUpscaledWidth = - priv->codec_data.av1.uncompressed_header.UpscaledWidth; - priv->codec_data.av1.RefFrames[i].RefFrameWidth = - priv->codec_data.av1.uncompressed_header.FrameWidth; - priv->codec_data.av1.RefFrames[i].RefFrameHeight = - priv->codec_data.av1.uncompressed_header.FrameHeight; - priv->codec_data.av1.RefFrames[i].RefRenderWidth = - priv->codec_data.av1.uncompressed_header.RenderWidth; - priv->codec_data.av1.RefFrames[i].RefRenderHeight = - priv->codec_data.av1.uncompressed_header.RenderHeight; - } - } - if (!priv->picture.av1.picture_parameter.pic_info_fields.show_frame) - task->no_show_frame = true; - - mtx_lock(&priv->codec_data.av1.mutex); - fnd = dec_av1_GetStartedTask(priv, task, &priv->codec_data.av1.decode_tasks); - if (!fnd) { - mtx_unlock(&priv->codec_data.av1.mutex); - return; - } - if (!priv->codec_data.av1.stacked_frame) - dec_av1_MoveTask(&priv->codec_data.av1.decode_tasks, &inp->tasks); - mtx_unlock(&priv->codec_data.av1.mutex); - priv->frame_finished = 1; -} - -static void dec_av1_Decode(vid_dec_PrivateType *priv, struct vl_vlc *vlc, - unsigned min_bits_left) -{ - unsigned start_bits_pos = vl_vlc_bits_left(vlc); - unsigned start_bits = vl_vlc_valid_bits(vlc); - unsigned start_bytes = start_bits / 8; - const void *obu_data = vlc->data; - uint8_t start_buf[8]; - unsigned num_buffers = 0; - void * const * buffers[4]; - unsigned sizes[4]; - unsigned obu_size = 0; - unsigned total_obu_len; - enum av1_obu_type type; - bool obu_extension_flag; - bool obu_has_size_field; - unsigned i; - - for (i = 0; i < start_bytes; ++i) - start_buf[i] = - vl_vlc_peekbits(vlc, start_bits) >> ((start_bytes - i - 1) * 8); - - /* obu header */ - av1_f(vlc, 1); /* obu_forbidden_bit */ - type = av1_f(vlc, 4); - obu_extension_flag = av1_f(vlc, 1); - obu_has_size_field = av1_f(vlc, 1); - av1_f(vlc, 1); /* obu_reserved_1bit */ - if (obu_extension_flag) { - priv->codec_data.av1.ext.temporal_id = av1_f(vlc, 3); - priv->codec_data.av1.ext.spatial_id = av1_f(vlc, 2); - av1_f(vlc, 3); /* extension_header_reserved_3bits */ - } - - obu_size = (obu_has_size_field) ? av1_uleb128(vlc) : - (priv->sizes[0] - (unsigned)obu_extension_flag - 1); - total_obu_len = (start_bits_pos - vl_vlc_bits_left(vlc)) / 8 + obu_size; - - switch (type) { - case AV1_OBU_SEQUENCE_HEADER: { - sequence_header_obu(priv, vlc); - av1_byte_alignment(vlc); - priv->codec_data.av1.bs_obu_seq_sz = total_obu_len; - memcpy(priv->codec_data.av1.bs_obu_seq_buf, start_buf, start_bytes); - memcpy(priv->codec_data.av1.bs_obu_seq_buf + start_bytes, obu_data, - total_obu_len - start_bytes); - break; - } - case AV1_OBU_TEMPORAL_DELIMITER: - av1_byte_alignment(vlc); - priv->codec_data.av1.bs_obu_td_sz = total_obu_len; - memcpy(priv->codec_data.av1.bs_obu_td_buf, start_buf, total_obu_len); - break; - case AV1_OBU_FRAME_HEADER: - frame_header_obu(priv, vlc); - if (priv->codec_data.av1.uncompressed_header.show_existing_frame) - dec_av1_ShowExistingframe(priv); - av1_byte_alignment(vlc); - break; - case AV1_OBU_FRAME: { - struct dec_av1_task *task; - - frame_header_obu(priv, vlc); - av1_byte_alignment(vlc); - - parse_tile_hdr(priv, vlc, start_bits_pos, total_obu_len); - av1_byte_alignment(vlc); - - task = dec_av1_BeginFrame(priv); - if (!task) - return; - - if (priv->codec_data.av1.bs_obu_td_sz) { - buffers[num_buffers] = (void *)priv->codec_data.av1.bs_obu_td_buf; - sizes[num_buffers++] = priv->codec_data.av1.bs_obu_td_sz; - priv->codec_data.av1.bs_obu_td_sz = 0; - } - if (priv->codec_data.av1.bs_obu_seq_sz) { - buffers[num_buffers] = (void *)priv->codec_data.av1.bs_obu_seq_buf; - sizes[num_buffers++] = priv->codec_data.av1.bs_obu_seq_sz; - priv->codec_data.av1.bs_obu_seq_sz = 0; - } - buffers[num_buffers] = (void *)start_buf; - sizes[num_buffers++] = start_bytes; - buffers[num_buffers] = (void *)obu_data; - sizes[num_buffers++] = total_obu_len - start_bytes; - - priv->codec->decode_bitstream(priv->codec, priv->target, - &priv->picture.base, num_buffers, (const void * const*)buffers, sizes); - - priv->codec_data.av1.stacked_frame = - (vl_vlc_bits_left(vlc) > min_bits_left) ? true : false; - - dec_av1_EndFrame(priv, task); - break; - } - default: - av1_byte_alignment(vlc); - break; - } - - return; -} - -OMX_ERRORTYPE vid_dec_av1_AllocateInBuffer(omx_base_PortType *port, - OMX_INOUT OMX_BUFFERHEADERTYPE **buf, OMX_IN OMX_U32 idx, - OMX_IN OMX_PTR private, OMX_IN OMX_U32 size) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = base_port_AllocateBuffer(port, buf, idx, private, size); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - base_port_FreeBuffer(port, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - return OMX_ErrorNone; -} - -OMX_ERRORTYPE vid_dec_av1_UseInBuffer(omx_base_PortType *port, - OMX_BUFFERHEADERTYPE **buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size, OMX_U8 *mem) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = base_port_UseBuffer(port, buf, idx, private, size, mem); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - base_port_FreeBuffer(port, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - return OMX_ErrorNone; -} - -void vid_dec_av1_FreeInputPortPrivate(vid_dec_PrivateType *priv, - OMX_BUFFERHEADERTYPE *buf) -{ - struct input_buf_private *inp = buf->pInputPortPrivate; - - if (!inp || !inp->tasks.next) - return; - - list_for_each_entry_safe(struct dec_av1_task, task, &inp->tasks, list) { - task->buf->destroy(task->buf); - FREE(task); - } -} - -void vid_dec_av1_ReleaseTasks(vid_dec_PrivateType *priv) -{ - dec_av1_ReleaseTask(priv, &priv->codec_data.av1.free_tasks); - dec_av1_ReleaseTask(priv, &priv->codec_data.av1.started_tasks); - dec_av1_ReleaseTask(priv, &priv->codec_data.av1.decode_tasks); - dec_av1_ReleaseTask(priv, &priv->codec_data.av1.finished_tasks); - mtx_destroy(&priv->codec_data.av1.mutex); -} - -void vid_dec_av1_FrameDecoded(OMX_COMPONENTTYPE *comp, - OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output) -{ - vid_dec_PrivateType *priv = comp->pComponentPrivate; - bool eos = !!(input->nFlags & OMX_BUFFERFLAG_EOS); - struct input_buf_private *inp = input->pInputPortPrivate; - struct dec_av1_task *task; - bool stacked = false; - - mtx_lock(&priv->codec_data.av1.mutex); - if (list_length(&inp->tasks) > 1) - stacked = true; - - if (list_is_empty(&inp->tasks)) { - task = list_entry(priv->codec_data.av1.started_tasks.next, - struct dec_av1_task, list); - list_del(&task->list); - list_addtail(&task->list, &inp->tasks); - --priv->codec_data.av1.que_num; - } - - task = list_entry(inp->tasks.next, struct dec_av1_task, list); - - if (!task->no_show_frame) { - vid_dec_FillOutput(priv, task->buf, output); - output->nFilledLen = output->nAllocLen; - output->nTimeStamp = input->nTimeStamp; - } else { - task->no_show_frame = false; - output->nFilledLen = 0; - } - - if (task->is_sef_task) { - if (task->buf_ref_count == 0) { - struct dec_av1_task *t = container_of(task->buf_ref, struct dec_av1_task, buf); - list_del(&task->list); - t->buf_ref_count--; - list_del(&t->list); - list_addtail(&t->list, &priv->codec_data.av1.finished_tasks); - } else if (task->buf_ref_count == 1) { - list_del(&task->list); - task->buf->destroy(task->buf); - task->buf_ref_count--; - } - FREE(task); - } else { - if (task->buf_ref_count == 1) { - list_del(&task->list); - list_addtail(&task->list, &priv->codec_data.av1.finished_tasks); - task->buf_ref_count--; - } else if (task->buf_ref_count == 2) { - list_del(&task->list); - task->buf_ref_count--; - list_addtail(&task->list, &priv->codec_data.av1.finished_tasks); - } - } - - if (eos && input->pInputPortPrivate) { - if (!priv->codec_data.av1.que_num) - input->nFilledLen = 0; - else - vid_dec_av1_FreeInputPortPrivate(priv, input); - } - else { - if (!stacked) - input->nFilledLen = 0; - } - mtx_unlock(&priv->codec_data.av1.mutex); -} - -void vid_dec_av1_Init(vid_dec_PrivateType *priv) -{ - priv->picture.base.profile = PIPE_VIDEO_PROFILE_AV1_MAIN; - priv->Decode = dec_av1_Decode; - list_inithead(&priv->codec_data.av1.free_tasks); - list_inithead(&priv->codec_data.av1.started_tasks); - list_inithead(&priv->codec_data.av1.decode_tasks); - list_inithead(&priv->codec_data.av1.finished_tasks); - (void)mtx_init(&priv->codec_data.av1.mutex, mtx_plain); -} diff --git a/src/gallium/frontends/omx/bellagio/vid_dec_av1.h b/src/gallium/frontends/omx/bellagio/vid_dec_av1.h deleted file mode 100644 index 817d2db1948..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec_av1.h +++ /dev/null @@ -1,459 +0,0 @@ -/************************************************************************** - * - * Copyright 2020 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef VID_DEC_AV1_H -#define VID_DEC_AV1_H - -#include "util/u_thread.h" - -enum av1_obu_type { - AV1_OBU_SEQUENCE_HEADER = 1, - AV1_OBU_TEMPORAL_DELIMITER, - AV1_OBU_FRAME_HEADER, - AV1_OBU_TILE_GROUP, - AV1_OBU_METADATA, - AV1_OBU_FRAME, - AV1_OBU_REDUNDANT_FRAME_HEADER, - AV1_OBU_TILE_LIST, - AV1_OBU_PADDING = 15 -}; - -enum av1_obu_frame_type { - AV1_KEY_FRAME = 0, - AV1_INTER_FRAME, - AV1_INTRA_ONLY_FRAME, - AV1_SWITCH_FRAME -}; - -enum av1_obu_color_primary { - AV1_CP_BT_709 = 1, - AV1_CP_UNSPECIFIED, - AV1_CP_BT_470_M = 4, - AV1_CP_BT_470_B_G, - AV1_CP_BT_601, - AV1_CP_SMPTE_240, - AV1_CP_GENERIC_FILM, - AV1_CP_BT_2020, - AV1_CP_XYZ, - AV1_CP_SMPTE_431, - AV1_CP_SMPTE_432, - AV1_CP_EBU_3213 = 22 -}; - -enum av1_obu_transfer_characteristic { - AV1_TC_RESERVED_0 = 0, - AV1_TC_BT_709, - AV1_TC_UNSPECIFIED, - AV1_TC_RESERVED_3, - AV1_TC_BT_470_M, - AV1_TC_BT_470_B_G, - AV1_TC_BT_601, - AV1_TC_SMPTE_240, - AV1_TC_LINEAR, - AV1_TC_LOG_100, - AV1_TC_LOG_100_SQRT10, - AV1_TC_IEC_61966, - AV1_TC_BT_1361, - AV1_TC_SRGB, - AV1_TC_BT_2020_10_BIT, - AV1_TC_BT_2020_12_BIT, - AV1_TC_SMPTE_2084, - AV1_TC_SMPTE_428, - AV1_TC_HLG -}; - -enum av1_obu_matrix_coefficient { - AV1_MC_IDENTITY = 0, - AV1_MC_BT_709, - AV1_MC_UNSPECIFIED, - AV1_MC_RESERVED_3, - AV1_MC_FCC, - AV1_MC_BT_470_B_G, - AV1_MC_BT_601, - AV1_MC_SMPTE_240, - AV1_MC_SMPTE_YCGCO, - AV1_MC_BT_2020_NCL, - AV1_MC_BT_2020_CL, - AV1_MC_SMPTE_2085, - AV1_MC_CHROMAT_NCL, - AV1_MC_CHROMAT_CL, - AV1_MC_ICTCP -}; - -enum av1_obu_seg_lvl { - AV1_SEG_LVL_ALT_Q = 0, - AV1_SEG_LVL_ALT_LF_Y_V, - AV1_SEG_LVL_REF_FRAME = 5, - AV1_SEG_LVL_SKIP, - AV1_SEG_LVL_GLOBALMV, - AV1_SEG_LVL_MAX -}; - -enum av1_obu_lrtype { - AV1_RESTORE_NONE = 0, - AV1_RESTORE_WIENER, - AV1_RESTORE_SGRPROJ, - AV1_RESTORE_SWITCHABLE -}; - -enum av1_obu_txmode { - AV1_ONLY_4X4 = 0, - AV1_TX_MODE_LARGEST, - AV1_TX_MODE_SELECT -}; - -enum av1_obu_gmtype { - AV1_IDENTITY = 0, - AV1_TRANSLATION, - AV1_ROTZOOM, - AV1_AFFINE -}; - -enum av1_frame_refs { - AV1_NONE = -1, - AV1_INTRA_FRAME = 0, - AV1_LAST_FRAME, - AV1_LAST2_FRAME, - AV1_LAST3_FRAME, - AV1_GOLDEN_FRAME, - AV1_BWDREF_FRAME, - AV1_ALTREF2_FRAME, - AV1_ALTREF_FRAME -}; - -#define AV1_SELECT_SCREEN_CONTENT_TOOLS 2 -#define AV1_SELECT_INTEGER_MV 2 - -#define AV1_PRIMARY_REF_NONE 7 -#define AV1_REFS_PER_FRAME 7 -#define AV1_NUM_REF_FRAMES 8 - -#define AV1_MAX_TILE_WIDTH 4096 -#define AV1_MAX_TILE_AREA (4096 * 2304) -#define AV1_MAX_TILE_ROWS 64 -#define AV1_MAX_TILE_COLS 64 -#define AV1_MAX_NUM_TILES AV1_MAX_TILE_ROWS * AV1_MAX_TILE_COLS - -#define AV1_MAX_SEGMENTS 8 -#define AV1_MAX_CDEF_BITS_ARRAY 8 -#define AV1_RESTORATION_TILESIZE 256 -#define AV1_WARPEDMODEL_PREC_BITS 16 -#define AV1_FG_MAX_NUM_Y_POINTS 14 -#define AV1_FG_MAX_NUM_CBR_POINTS 10 -#define AV1_FG_MAX_NUM_POS_LUMA 24 -#define AV1_FG_MAX_NUM_POS_CHROMA 25 - -struct av1_obu_extension_header_obu -{ - unsigned temporal_id; - unsigned spatial_id; -}; - -struct av1_sequence_header_obu { - uint8_t seq_profile; - bool reduced_still_picture_header; - - struct { - bool equal_picture_interval; - } timing_info; - - bool decoder_model_info_present_flag; - struct { - unsigned num_units_in_decoding_tick; - uint8_t buffer_removal_time_length_minus_1; - uint8_t frame_presentation_time_length_minus_1; - } decoder_model_info; - - uint8_t operating_points_cnt_minus_1; - uint16_t operating_point_idc[32]; - bool decoder_model_present_for_this_op[32]; - - uint8_t frame_width_bits_minus_1; - uint8_t frame_height_bits_minus_1; - unsigned max_frame_width_minus_1; - unsigned max_frame_height_minus_1; - bool frame_id_numbers_present_flag; - uint8_t delta_frame_id_length_minus_2; - uint8_t additional_frame_id_length_minus_1; - - bool use_128x128_superblock; - bool enable_filter_intra; - bool enable_intra_edge_filter; - bool enable_interintra_compound; - bool enable_masked_compound; - bool enable_warped_motion; - bool enable_dual_filter; - bool enable_order_hint; - bool enable_jnt_comp; - bool enable_ref_frame_mvs; - uint8_t seq_force_screen_content_tools; - uint8_t seq_force_integer_mv; - - uint8_t order_hint_bits_minus_1; - uint8_t OrderHintBits; - bool enable_superres; - bool enable_cdef; - bool enable_restoration; - struct { - uint8_t BitDepth; - bool mono_chrome; - uint8_t NumPlanes; - bool subsampling_x; - bool subsampling_y; - bool separate_uv_delta_q; - } color_config; - bool film_grain_params_present; -}; - -struct ref_frame { - uint8_t RefFrameType; - unsigned RefFrameId; - unsigned RefUpscaledWidth; - unsigned RefFrameWidth; - unsigned RefFrameHeight; - unsigned RefRenderWidth; - unsigned RefRenderHeight; -}; - -struct tile_info { - unsigned TileColsLog2; - unsigned TileRowsLog2; - int tile_col_start_sb[AV1_MAX_TILE_COLS + 1]; - int tile_row_start_sb[AV1_MAX_TILE_ROWS + 1]; - unsigned TileCols; - unsigned TileRows; - unsigned context_update_tile_id; - uint8_t TileSizeBytes; -}; - -struct quantization_params { - uint8_t base_q_idx; - int DeltaQYDc; - int DeltaQUDc; - int DeltaQUAc; - int DeltaQVDc; - int DeltaQVAc; - uint8_t qm_y; - uint8_t qm_u; - uint8_t qm_v; -}; - -struct segmentation_params { - bool segmentation_enabled; - bool segmentation_update_map; - bool segmentation_temporal_update; - bool FeatureEnabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; - int FeatureData[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; - int FeatureMask[AV1_MAX_SEGMENTS]; -}; - -struct delta_q_params { - bool delta_q_present; - uint8_t delta_q_res; -}; - -struct delta_lf_params { - bool delta_lf_present; - uint8_t delta_lf_res; - bool delta_lf_multi; -}; - -struct loop_filter_params { - uint8_t loop_filter_level[4]; - uint8_t loop_filter_sharpness; - bool loop_filter_delta_enabled; - bool loop_filter_delta_update; - int8_t loop_filter_ref_deltas[AV1_NUM_REF_FRAMES]; - int8_t loop_filter_mode_deltas[2]; -}; - -struct cdef_params { - uint8_t cdef_damping_minus_3; - uint8_t cdef_bits; - uint16_t cdef_y_strengths[AV1_MAX_CDEF_BITS_ARRAY]; - uint16_t cdef_uv_strengths[AV1_MAX_CDEF_BITS_ARRAY]; -}; - -struct loop_restoration_params { - uint8_t FrameRestorationType[3]; - uint16_t LoopRestorationSize[3]; -}; - -struct tx_mode_params { - uint8_t TxMode; -}; - -enum reference_mode { - SINGLE_REFERENCE = 0, - COMPOUND_REFERENCE = 1, - REFERENCE_MODE_SELECT = 2, - REFERENCE_MODES = 3, -}; - -struct skip_mode_params { - bool skip_mode_present; -}; - -struct global_motion_params { - uint8_t GmType[AV1_NUM_REF_FRAMES]; - int gm_params[AV1_NUM_REF_FRAMES][6]; -}; - -struct film_grain_params { - bool apply_grain; - uint16_t grain_seed; - uint8_t num_y_points; - uint8_t point_y_value[AV1_FG_MAX_NUM_Y_POINTS]; - uint8_t point_y_scaling[AV1_FG_MAX_NUM_Y_POINTS]; - bool chroma_scaling_from_luma; - uint8_t num_cb_points; - uint8_t num_cr_points; - uint8_t point_cb_value[AV1_FG_MAX_NUM_CBR_POINTS]; - uint8_t point_cb_scaling[AV1_FG_MAX_NUM_CBR_POINTS]; - uint8_t point_cr_value[AV1_FG_MAX_NUM_CBR_POINTS]; - uint8_t point_cr_scaling[AV1_FG_MAX_NUM_CBR_POINTS]; - uint8_t grain_scaling_minus_8; - uint8_t ar_coeff_lag; - int ar_coeffs_y[AV1_FG_MAX_NUM_POS_LUMA]; - int ar_coeffs_cb[AV1_FG_MAX_NUM_POS_CHROMA]; - int ar_coeffs_cr[AV1_FG_MAX_NUM_POS_CHROMA]; - uint8_t ar_coeff_shift_minus_6; - int ar_coeff_shift; - uint8_t grain_scale_shift; - uint8_t cb_mult; - uint8_t cb_luma_mult; - uint16_t cb_offset; - uint8_t cr_mult; - uint8_t cr_luma_mult; - uint16_t cr_offset; - bool overlap_flag; - bool clip_to_restricted_range; -}; - -struct av1_uncompressed_header_obu -{ - uint8_t frame_type; - bool FrameIsIntra; - bool show_frame; - bool showable_frame; - bool show_existing_frame; - uint8_t frame_to_show_map_idx; - - unsigned RefOrderHint[AV1_NUM_REF_FRAMES]; - bool error_resilient_mode; - bool disable_cdf_update; - bool allow_screen_content_tools; - bool force_integer_mv; - - unsigned current_frame_id; - bool frame_size_override_flag; - unsigned OrderHint; - uint8_t primary_ref_frame; - - uint8_t refresh_frame_flags; - unsigned FrameWidth; - unsigned FrameHeight; - bool use_superres; - unsigned SuperresDenom; - unsigned UpscaledWidth; - unsigned MiCols; - unsigned MiRows; - - unsigned RenderWidth; - unsigned RenderHeight; - - uint8_t last_frame_idx; - uint8_t gold_frame_idx; - uint8_t ref_frame_idx[AV1_REFS_PER_FRAME]; - uint8_t usedFrame[AV1_NUM_REF_FRAMES]; - unsigned curFrameHint; - unsigned shiftedOrderHints[AV1_NUM_REF_FRAMES]; - - bool allow_high_precision_mv; - bool use_ref_frame_mvs; - bool allow_intrabc; - uint8_t interpolation_filter; - bool is_motion_mode_switchable; - - bool disable_frame_end_update_cdf; - struct tile_info ti; - struct quantization_params qp; - struct segmentation_params sp; - struct delta_q_params dqp; - struct delta_lf_params dlfp; - - bool CodedLossless; - bool AllLossless; - struct loop_filter_params lfp; - struct cdef_params cdefp; - struct loop_restoration_params lrp; - struct tx_mode_params tm; - enum reference_mode reference_select; - struct skip_mode_params smp; - bool allow_warped_motion; - bool reduced_tx_set; - struct global_motion_params gmp; - struct film_grain_params fgp; -}; - -struct dec_av1_task { - struct list_head list; - - struct pipe_video_buffer *buf; - bool no_show_frame; - unsigned buf_ref_count; - struct pipe_video_buffer **buf_ref; - bool is_sef_task; -}; - -struct input_buf_private { - struct list_head tasks; - struct list_head inps; -}; - -struct dec_av1 { - struct av1_obu_extension_header_obu ext; - struct av1_sequence_header_obu seq; - struct av1_uncompressed_header_obu uncompressed_header; - struct av1_uncompressed_header_obu refs[AV1_NUM_REF_FRAMES]; - struct ref_frame RefFrames[AV1_NUM_REF_FRAMES]; - - uint8_t bs_obu_td_buf[8]; - unsigned bs_obu_td_sz; - uint8_t bs_obu_seq_buf[128]; - unsigned bs_obu_seq_sz; - struct pipe_video_buffer *frame_refs[AV1_NUM_REF_FRAMES]; - struct list_head free_tasks; - struct list_head started_tasks; - struct list_head finished_tasks; - struct list_head decode_tasks; - unsigned que_num; - bool stacked_frame; - mtx_t mutex; -}; - -#endif diff --git a/src/gallium/frontends/omx/bellagio/vid_dec_h264.c b/src/gallium/frontends/omx/bellagio/vid_dec_h264.c deleted file mode 100644 index 24a9925e070..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec_h264.c +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" -#include "util/u_video.h" -#include "util/vl_rbsp.h" -#include "vl/vl_zscan.h" - -#include "entrypoint.h" -#include "vid_dec.h" -#include "vid_dec_h264_common.h" - -void vid_dec_h264_Init(vid_dec_PrivateType *priv) -{ - priv->picture.base.profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - - priv->Decode = vid_dec_h264_Decode; - priv->EndFrame = vid_dec_h264_EndFrame; - priv->Flush = vid_dec_h264_Flush; - - list_inithead(&priv->codec_data.h264.dpb_list); - priv->picture.h264.field_order_cnt[0] = priv->picture.h264.field_order_cnt[1] = INT_MAX; - priv->first_buf_in_frame = true; -} diff --git a/src/gallium/frontends/omx/bellagio/vid_dec_h265.c b/src/gallium/frontends/omx/bellagio/vid_dec_h265.c deleted file mode 100644 index 322c1aaafa2..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec_h265.c +++ /dev/null @@ -1,1015 +0,0 @@ -/************************************************************************** - * - * Copyright 2016 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" -#include "util/u_video.h" -#include "util/vl_rbsp.h" - -#include "entrypoint.h" -#include "vid_dec.h" - -#define DPB_MAX_SIZE 32 -#define MAX_NUM_REF_PICS 16 - -enum { - NAL_UNIT_TYPE_TRAIL_N = 0, - NAL_UNIT_TYPE_TRAIL_R = 1, - NAL_UNIT_TYPE_TSA_N = 2, - NAL_UNIT_TYPE_TSA_R = 3, - NAL_UNIT_TYPE_STSA_N = 4, - NAL_UNIT_TYPE_STSA_R = 5, - NAL_UNIT_TYPE_RADL_N = 6, - NAL_UNIT_TYPE_RADL_R = 7, - NAL_UNIT_TYPE_RASL_N = 8, - NAL_UNIT_TYPE_RASL_R = 9, - NAL_UNIT_TYPE_BLA_W_LP = 16, - NAL_UNIT_TYPE_BLA_W_RADL = 17, - NAL_UNIT_TYPE_BLA_N_LP = 18, - NAL_UNIT_TYPE_IDR_W_RADL = 19, - NAL_UNIT_TYPE_IDR_N_LP = 20, - NAL_UNIT_TYPE_CRA = 21, - NAL_UNIT_TYPE_SPS = 33, - NAL_UNIT_TYPE_PPS = 34, -}; - -static const uint8_t Default_8x8_Intra[64] = { - 16, 16, 16, 16, 17, 18, 21, 24, - 16, 16, 16, 16, 17, 19, 22, 25, - 16, 16, 17, 18, 20, 22, 25, 29, - 16, 16, 18, 21, 24, 27, 31, 36, - 17, 17, 20, 24, 30, 35, 41, 47, - 18, 19, 22, 27, 35, 44, 54, 65, - 21, 22, 25, 31, 41, 54, 70, 88, - 24, 25, 29, 36, 47, 65, 88, 115 -}; - -static const uint8_t Default_8x8_Inter[64] = { - 16, 16, 16, 16, 17, 18, 20, 24, - 16, 16, 16, 17, 18, 20, 24, 25, - 16, 16, 17, 18, 20, 24, 25, 28, - 16, 17, 18, 20, 24, 25, 28, 33, - 17, 18, 20, 24, 25, 28, 33, 41, - 18, 20, 24, 25, 28, 33, 41, 54, - 20, 24, 25, 28, 33, 41, 54, 71, - 24, 25, 28, 33, 41, 54, 71, 91 -}; - -struct dpb_list { - struct list_head list; - struct pipe_video_buffer *buffer; - OMX_TICKS timestamp; - unsigned poc; -}; - -struct ref_pic_set { - unsigned num_pics; - unsigned num_neg_pics; - unsigned num_pos_pics; - unsigned num_delta_poc; - int delta_poc[MAX_NUM_REF_PICS]; - bool used[MAX_NUM_REF_PICS]; -}; - -static bool is_idr_picture(unsigned nal_unit_type) -{ - return (nal_unit_type == NAL_UNIT_TYPE_IDR_W_RADL || - nal_unit_type == NAL_UNIT_TYPE_IDR_N_LP); -} - -/* broken link access picture */ -static bool is_bla_picture(unsigned nal_unit_type) -{ - return (nal_unit_type == NAL_UNIT_TYPE_BLA_W_LP || - nal_unit_type == NAL_UNIT_TYPE_BLA_W_RADL || - nal_unit_type == NAL_UNIT_TYPE_BLA_N_LP); -} - -/* random access point picture */ -static bool is_rap_picture(unsigned nal_unit_type) -{ - return (nal_unit_type >= NAL_UNIT_TYPE_BLA_W_LP && - nal_unit_type <= NAL_UNIT_TYPE_CRA); -} - -static bool is_slice_picture(unsigned nal_unit_type) -{ - return (nal_unit_type <= NAL_UNIT_TYPE_RASL_R || - is_rap_picture(nal_unit_type)); -} - -static void set_poc(vid_dec_PrivateType *priv, - unsigned nal_unit_type, int i) -{ - priv->picture.h265.CurrPicOrderCntVal = i; - - if (priv->codec_data.h265.temporal_id == 0 && - (nal_unit_type == NAL_UNIT_TYPE_TRAIL_R || - nal_unit_type == NAL_UNIT_TYPE_TSA_R || - nal_unit_type == NAL_UNIT_TYPE_STSA_R || - is_rap_picture(nal_unit_type))) - priv->codec_data.h265.slice_prev_poc = i; -} - -static unsigned get_poc(vid_dec_PrivateType *priv) -{ - return priv->picture.h265.CurrPicOrderCntVal; -} - -static void profile_tier(struct vl_rbsp *rbsp) -{ - int i; - - /* general_profile_space */ - vl_rbsp_u(rbsp, 2); - - /* general_tier_flag */ - vl_rbsp_u(rbsp, 1); - - /* general_profile_idc */ - vl_rbsp_u(rbsp, 5); - - /* general_profile_compatibility_flag */ - for(i = 0; i < 32; ++i) - vl_rbsp_u(rbsp, 1); - - /* general_progressive_source_flag */ - vl_rbsp_u(rbsp, 1); - - /* general_interlaced_source_flag */ - vl_rbsp_u(rbsp, 1); - - /* general_non_packed_constraint_flag */ - vl_rbsp_u(rbsp, 1); - - /* general_frame_only_constraint_flag */ - vl_rbsp_u(rbsp, 1); - - /* general_reserved_zero_44bits */ - vl_rbsp_u(rbsp, 16); - vl_rbsp_u(rbsp, 16); - vl_rbsp_u(rbsp, 12); -} - -static unsigned profile_tier_level(struct vl_rbsp *rbsp, - int max_sublayers_minus1) -{ - bool sub_layer_profile_present_flag[6]; - bool sub_layer_level_present_flag[6]; - unsigned level_idc; - int i; - - profile_tier(rbsp); - - /* general_level_idc */ - level_idc = vl_rbsp_u(rbsp, 8); - - for (i = 0; i < max_sublayers_minus1; ++i) { - sub_layer_profile_present_flag[i] = vl_rbsp_u(rbsp, 1); - sub_layer_level_present_flag[i] = vl_rbsp_u(rbsp, 1); - } - - if (max_sublayers_minus1 > 0) - for (i = max_sublayers_minus1; i < 8; ++i) - /* reserved_zero_2bits */ - vl_rbsp_u(rbsp, 2); - - for (i = 0; i < max_sublayers_minus1; ++i) { - if (sub_layer_profile_present_flag[i]) - profile_tier(rbsp); - - if (sub_layer_level_present_flag[i]) - /* sub_layer_level_idc */ - vl_rbsp_u(rbsp, 8); - } - - return level_idc; -} - -static void scaling_list_data(vid_dec_PrivateType *priv, - struct vl_rbsp *rbsp, struct pipe_h265_sps *sps) -{ - unsigned size_id, matrix_id; - unsigned scaling_list_len[4] = { 16, 64, 64, 64 }; - uint8_t scaling_list4x4[6][64] = { }; - int i; - - uint8_t (*scaling_list_data[4])[6][64] = { - (uint8_t (*)[6][64])scaling_list4x4, - (uint8_t (*)[6][64])sps->ScalingList8x8, - (uint8_t (*)[6][64])sps->ScalingList16x16, - (uint8_t (*)[6][64])sps->ScalingList32x32 - }; - uint8_t (*scaling_list_dc_coeff[2])[6] = { - (uint8_t (*)[6])sps->ScalingListDCCoeff16x16, - (uint8_t (*)[6])sps->ScalingListDCCoeff32x32 - }; - - for (size_id = 0; size_id < 4; ++size_id) { - - for (matrix_id = 0; matrix_id < ((size_id == 3) ? 2 : 6); ++matrix_id) { - bool scaling_list_pred_mode_flag = vl_rbsp_u(rbsp, 1); - - if (!scaling_list_pred_mode_flag) { - /* scaling_list_pred_matrix_id_delta */; - unsigned matrix_id_with_delta = matrix_id - vl_rbsp_ue(rbsp); - - if (matrix_id != matrix_id_with_delta) { - memcpy((*scaling_list_data[size_id])[matrix_id], - (*scaling_list_data[size_id])[matrix_id_with_delta], - scaling_list_len[size_id]); - if (size_id > 1) - (*scaling_list_dc_coeff[size_id - 2])[matrix_id] = - (*scaling_list_dc_coeff[size_id - 2])[matrix_id_with_delta]; - } else { - const uint8_t *d; - - if (size_id == 0) - memset((*scaling_list_data[0])[matrix_id], 16, 16); - else { - if (size_id < 3) - d = (matrix_id < 3) ? Default_8x8_Intra : Default_8x8_Inter; - else - d = (matrix_id < 1) ? Default_8x8_Intra : Default_8x8_Inter; - memcpy((*scaling_list_data[size_id])[matrix_id], d, - scaling_list_len[size_id]); - } - if (size_id > 1) - (*scaling_list_dc_coeff[size_id - 2])[matrix_id] = 16; - } - } else { - int next_coef = 8; - int coef_num = MIN2(64, (1 << (4 + (size_id << 1)))); - - if (size_id > 1) { - /* scaling_list_dc_coef_minus8 */ - next_coef = vl_rbsp_se(rbsp) + 8; - (*scaling_list_dc_coeff[size_id - 2])[matrix_id] = next_coef; - } - - for (i = 0; i < coef_num; ++i) { - /* scaling_list_delta_coef */ - next_coef = (next_coef + vl_rbsp_se(rbsp) + 256) % 256; - (*scaling_list_data[size_id])[matrix_id][i] = next_coef; - } - } - } - } - - for (i = 0; i < 6; ++i) - memcpy(sps->ScalingList4x4[i], scaling_list4x4[i], 16); - - return; -} - -static void st_ref_pic_set(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - struct ref_pic_set *rps, struct pipe_h265_sps *sps, - unsigned idx) -{ - bool inter_rps_pred_flag; - unsigned delta_idx_minus1; - int delta_poc; - int i; - - inter_rps_pred_flag = (idx != 0) ? (vl_rbsp_u(rbsp, 1)) : false; - - if (inter_rps_pred_flag) { - struct ref_pic_set *ref_rps; - unsigned sign, abs; - int delta_rps; - bool used; - int j; - - if (idx == sps->num_short_term_ref_pic_sets) - delta_idx_minus1 = vl_rbsp_ue(rbsp); - else - delta_idx_minus1 = 0; - - ref_rps = (struct ref_pic_set *) - priv->codec_data.h265.ref_pic_set_list + idx - (delta_idx_minus1 + 1); - - /* delta_rps_sign */ - sign = vl_rbsp_u(rbsp, 1); - /* abs_delta_rps_minus1 */ - abs = vl_rbsp_ue(rbsp); - delta_rps = (1 - 2 * sign) * (abs + 1); - - rps->num_neg_pics = 0; - rps->num_pos_pics = 0; - rps->num_pics = 0; - - for(i = 0 ; i <= ref_rps->num_pics; ++i) { - /* used_by_curr_pic_flag */ - if (!vl_rbsp_u(rbsp, 1)) - /* use_delta_flag */ - vl_rbsp_u(rbsp, 1); - else { - delta_poc = delta_rps + - ((i < ref_rps->num_pics)? ref_rps->delta_poc[i] : 0); - rps->delta_poc[rps->num_pics] = delta_poc; - rps->used[rps->num_pics] = true; - if (delta_poc < 0) - rps->num_neg_pics++; - else - rps->num_pos_pics++; - rps->num_pics++; - } - } - - rps->num_delta_poc = ref_rps->num_pics; - - /* sort delta poc */ - for (i = 1; i < rps->num_pics; ++i) { - delta_poc = rps->delta_poc[i]; - used = rps->used[i]; - for (j = i - 1; j >= 0; j--) { - if (delta_poc < rps->delta_poc[j]) { - rps->delta_poc[j + 1] = rps->delta_poc[j]; - rps->used[j + 1] = rps->used[j]; - rps->delta_poc[j] = delta_poc; - rps->used[j] = used; - } - } - } - - for (i = 0 , j = rps->num_neg_pics - 1; - i < rps->num_neg_pics >> 1; i++, j--) { - delta_poc = rps->delta_poc[i]; - used = rps->used[i]; - rps->delta_poc[i] = rps->delta_poc[j]; - rps->used[i] = rps->used[j]; - rps->delta_poc[j] = delta_poc; - rps->used[j] = used; - } - } else { - /* num_negative_pics */ - rps->num_neg_pics = vl_rbsp_ue(rbsp); - /* num_positive_pics */ - rps->num_pos_pics = vl_rbsp_ue(rbsp); - rps->num_pics = rps->num_neg_pics + rps->num_pos_pics; - - delta_poc = 0; - for(i = 0 ; i < rps->num_neg_pics; ++i) { - /* delta_poc_s0_minus1 */ - delta_poc -= (vl_rbsp_ue(rbsp) + 1); - rps->delta_poc[i] = delta_poc; - /* used_by_curr_pic_s0_flag */ - rps->used[i] = vl_rbsp_u(rbsp, 1); - } - - delta_poc = 0; - for(i = rps->num_neg_pics; i < rps->num_pics; ++i) { - /* delta_poc_s1_minus1 */ - delta_poc += (vl_rbsp_ue(rbsp) + 1); - rps->delta_poc[i] = delta_poc; - /* used_by_curr_pic_s1_flag */ - rps->used[i] = vl_rbsp_u(rbsp, 1); - } - } -} - -static struct pipe_h265_sps *seq_parameter_set_id(vid_dec_PrivateType *priv, - struct vl_rbsp *rbsp) -{ - unsigned id = vl_rbsp_ue(rbsp); - - if (id >= ARRAY_SIZE(priv->codec_data.h265.sps)) - return NULL; - - return &priv->codec_data.h265.sps[id]; -} - -static void seq_parameter_set(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - struct pipe_h265_sps *sps; - int sps_max_sub_layers_minus1; - unsigned i; - - /* sps_video_parameter_set_id */ - vl_rbsp_u(rbsp, 4); - - /* sps_max_sub_layers_minus1 */ - sps_max_sub_layers_minus1 = vl_rbsp_u(rbsp, 3); - - assert(sps_max_sub_layers_minus1 <= 6); - - /* sps_temporal_id_nesting_flag */ - vl_rbsp_u(rbsp, 1); - - priv->codec_data.h265.level_idc = - profile_tier_level(rbsp, sps_max_sub_layers_minus1); - - sps = seq_parameter_set_id(priv, rbsp); - if (!sps) - return; - - memset(sps, 0, sizeof(*sps)); - - sps->chroma_format_idc = vl_rbsp_ue(rbsp); - - if (sps->chroma_format_idc == 3) - sps->separate_colour_plane_flag = vl_rbsp_u(rbsp, 1); - - priv->codec_data.h265.pic_width_in_luma_samples = - sps->pic_width_in_luma_samples = vl_rbsp_ue(rbsp); - - priv->codec_data.h265.pic_height_in_luma_samples = - sps->pic_height_in_luma_samples = vl_rbsp_ue(rbsp); - - /* conformance_window_flag */ - if (vl_rbsp_u(rbsp, 1)) { - /* conf_win_left_offset */ - vl_rbsp_ue(rbsp); - /* conf_win_right_offset */ - vl_rbsp_ue(rbsp); - /* conf_win_top_offset */ - vl_rbsp_ue(rbsp); - /* conf_win_bottom_offset */ - vl_rbsp_ue(rbsp); - } - - sps->bit_depth_luma_minus8 = vl_rbsp_ue(rbsp); - sps->bit_depth_chroma_minus8 = vl_rbsp_ue(rbsp); - sps->log2_max_pic_order_cnt_lsb_minus4 = vl_rbsp_ue(rbsp); - - /* sps_sub_layer_ordering_info_present_flag */ - i = vl_rbsp_u(rbsp, 1) ? 0 : sps_max_sub_layers_minus1; - for (; i <= sps_max_sub_layers_minus1; ++i) { - sps->sps_max_dec_pic_buffering_minus1 = vl_rbsp_ue(rbsp); - /* sps_max_num_reorder_pics */ - vl_rbsp_ue(rbsp); - /* sps_max_latency_increase_plus */ - vl_rbsp_ue(rbsp); - } - - sps->log2_min_luma_coding_block_size_minus3 = vl_rbsp_ue(rbsp); - sps->log2_diff_max_min_luma_coding_block_size = vl_rbsp_ue(rbsp); - sps->log2_min_transform_block_size_minus2 = vl_rbsp_ue(rbsp); - sps->log2_diff_max_min_transform_block_size = vl_rbsp_ue(rbsp); - sps->max_transform_hierarchy_depth_inter = vl_rbsp_ue(rbsp); - sps->max_transform_hierarchy_depth_intra = vl_rbsp_ue(rbsp); - - sps->scaling_list_enabled_flag = vl_rbsp_u(rbsp, 1); - if (sps->scaling_list_enabled_flag) - /* sps_scaling_list_data_present_flag */ - if (vl_rbsp_u(rbsp, 1)) - scaling_list_data(priv, rbsp, sps); - - sps->amp_enabled_flag = vl_rbsp_u(rbsp, 1); - sps->sample_adaptive_offset_enabled_flag = vl_rbsp_u(rbsp, 1); - sps->pcm_enabled_flag = vl_rbsp_u(rbsp, 1); - if (sps->pcm_enabled_flag) { - sps->pcm_sample_bit_depth_luma_minus1 = vl_rbsp_u(rbsp, 4); - sps->pcm_sample_bit_depth_chroma_minus1 = vl_rbsp_u(rbsp, 4); - sps->log2_min_pcm_luma_coding_block_size_minus3 = vl_rbsp_ue(rbsp); - sps->log2_diff_max_min_pcm_luma_coding_block_size = vl_rbsp_ue(rbsp); - sps->pcm_loop_filter_disabled_flag = vl_rbsp_u(rbsp, 1); - } - - sps->num_short_term_ref_pic_sets = vl_rbsp_ue(rbsp); - - for (i = 0; i < sps->num_short_term_ref_pic_sets; ++i) { - struct ref_pic_set *rps; - - rps = (struct ref_pic_set *) - priv->codec_data.h265.ref_pic_set_list + i; - st_ref_pic_set(priv, rbsp, rps, sps, i); - } - - sps->long_term_ref_pics_present_flag = vl_rbsp_u(rbsp, 1); - if (sps->long_term_ref_pics_present_flag) { - sps->num_long_term_ref_pics_sps = vl_rbsp_ue(rbsp); - for (i = 0; i < sps->num_long_term_ref_pics_sps; ++i) { - /* lt_ref_pic_poc_lsb_sps */ - vl_rbsp_u(rbsp, sps->log2_max_pic_order_cnt_lsb_minus4 + 4); - /* used_by_curr_pic_lt_sps_flag */ - vl_rbsp_u(rbsp, 1); - } - } - - sps->sps_temporal_mvp_enabled_flag = vl_rbsp_u(rbsp, 1); - sps->strong_intra_smoothing_enabled_flag = vl_rbsp_u(rbsp, 1); -} - -static struct pipe_h265_pps *pic_parameter_set_id(vid_dec_PrivateType *priv, - struct vl_rbsp *rbsp) -{ - unsigned id = vl_rbsp_ue(rbsp); - - if (id >= ARRAY_SIZE(priv->codec_data.h265.pps)) - return NULL; - - return &priv->codec_data.h265.pps[id]; -} - -static void picture_parameter_set(vid_dec_PrivateType *priv, - struct vl_rbsp *rbsp) -{ - struct pipe_h265_sps *sps; - struct pipe_h265_pps *pps; - int i; - - pps = pic_parameter_set_id(priv, rbsp); - if (!pps) - return; - - memset(pps, 0, sizeof(*pps)); - sps = pps->sps = seq_parameter_set_id(priv, rbsp); - if (!sps) - return; - - pps->dependent_slice_segments_enabled_flag = vl_rbsp_u(rbsp, 1); - pps->output_flag_present_flag = vl_rbsp_u(rbsp, 1); - pps->num_extra_slice_header_bits = vl_rbsp_u(rbsp, 3); - pps->sign_data_hiding_enabled_flag = vl_rbsp_u(rbsp, 1); - pps->cabac_init_present_flag = vl_rbsp_u(rbsp, 1); - - pps->num_ref_idx_l0_default_active_minus1 = vl_rbsp_ue(rbsp); - pps->num_ref_idx_l1_default_active_minus1 = vl_rbsp_ue(rbsp); - pps->init_qp_minus26 = vl_rbsp_se(rbsp); - pps->constrained_intra_pred_flag = vl_rbsp_u(rbsp, 1); - pps->transform_skip_enabled_flag = vl_rbsp_u(rbsp, 1); - - pps->cu_qp_delta_enabled_flag = vl_rbsp_u(rbsp, 1); - if (pps->cu_qp_delta_enabled_flag) - pps->diff_cu_qp_delta_depth = vl_rbsp_ue(rbsp); - - pps->pps_cb_qp_offset = vl_rbsp_se(rbsp); - pps->pps_cr_qp_offset = vl_rbsp_se(rbsp); - pps->pps_slice_chroma_qp_offsets_present_flag = vl_rbsp_u(rbsp, 1); - - pps->weighted_pred_flag = vl_rbsp_u(rbsp, 1); - pps->weighted_bipred_flag = vl_rbsp_u(rbsp, 1); - - pps->transquant_bypass_enabled_flag = vl_rbsp_u(rbsp, 1); - pps->tiles_enabled_flag = vl_rbsp_u(rbsp, 1); - pps->entropy_coding_sync_enabled_flag = vl_rbsp_u(rbsp, 1); - - if (pps->tiles_enabled_flag) { - pps->num_tile_columns_minus1 = vl_rbsp_ue(rbsp); - pps->num_tile_rows_minus1 = vl_rbsp_ue(rbsp); - - pps->uniform_spacing_flag = vl_rbsp_u(rbsp, 1); - if (!pps->uniform_spacing_flag) { - for (i = 0; i < pps->num_tile_columns_minus1; ++i) - pps->column_width_minus1[i] = vl_rbsp_ue(rbsp); - - for (i = 0; i < pps->num_tile_rows_minus1; ++i) - pps->row_height_minus1[i] = vl_rbsp_ue(rbsp); - } - - if (!pps->num_tile_columns_minus1 || !pps->num_tile_rows_minus1) - pps->loop_filter_across_tiles_enabled_flag = vl_rbsp_u(rbsp, 1); - } - - pps->pps_loop_filter_across_slices_enabled_flag = vl_rbsp_u(rbsp, 1); - - pps->deblocking_filter_control_present_flag = vl_rbsp_u(rbsp, 1); - if (pps->deblocking_filter_control_present_flag) { - pps->deblocking_filter_override_enabled_flag = vl_rbsp_u(rbsp, 1); - pps->pps_deblocking_filter_disabled_flag = vl_rbsp_u(rbsp, 1); - if (!pps->pps_deblocking_filter_disabled_flag) { - pps->pps_beta_offset_div2 = vl_rbsp_se(rbsp); - pps->pps_tc_offset_div2 = vl_rbsp_se(rbsp); - } - } - - if (vl_vlc_bits_left(&rbsp->nal) == 0) - return; - - /* pps_scaling_list_data_present_flag */ - if (vl_rbsp_u(rbsp, 1)) - scaling_list_data(priv, rbsp, sps); - - pps->lists_modification_present_flag = vl_rbsp_u(rbsp, 1); - pps->log2_parallel_merge_level_minus2 = vl_rbsp_ue(rbsp); - pps->slice_segment_header_extension_present_flag = vl_rbsp_u(rbsp, 1); -} - -static void vid_dec_h265_BeginFrame(vid_dec_PrivateType *priv) -{ - if (priv->frame_started) - return; - - if (!priv->codec) { - struct pipe_video_codec templat = {}; - omx_base_video_PortType *port = (omx_base_video_PortType *) - priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - - templat.profile = priv->profile; - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.expect_chunked_decode = false; - templat.width = priv->codec_data.h265.pic_width_in_luma_samples; - templat.height = priv->codec_data.h265.pic_height_in_luma_samples; - templat.level = priv->codec_data.h265.level_idc; - priv->codec = priv->pipe->create_video_codec(priv->pipe, &templat); - - /* disable transcode tunnel if video size is different from coded size */ - if (priv->codec_data.h265.pic_width_in_luma_samples != - port->sPortParam.format.video.nFrameWidth || - priv->codec_data.h265.pic_height_in_luma_samples != - port->sPortParam.format.video.nFrameHeight) - priv->disable_tunnel = true; - } - - vid_dec_NeedTarget(priv); - - if (priv->first_buf_in_frame) - priv->timestamp = priv->timestamps[0]; - priv->first_buf_in_frame = false; - - priv->codec->begin_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = true; -} - -static struct pipe_video_buffer *vid_dec_h265_Flush(vid_dec_PrivateType *priv, - OMX_TICKS *timestamp) -{ - struct dpb_list *entry, *result = NULL; - struct pipe_video_buffer *buf; - - /* search for the lowest poc and break on zeros */ - LIST_FOR_EACH_ENTRY(entry, &priv->codec_data.h265.dpb_list, list) { - - if (result && entry->poc == 0) - break; - - if (!result || entry->poc < result->poc) - result = entry; - } - - if (!result) - return NULL; - - buf = result->buffer; - if (timestamp) - *timestamp = result->timestamp; - - --priv->codec_data.h265.dpb_num; - list_del(&result->list); - FREE(result); - - return buf; -} - -static void vid_dec_h265_EndFrame(vid_dec_PrivateType *priv) -{ - struct dpb_list *entry = NULL; - struct pipe_video_buffer *tmp; - struct ref_pic_set *rps; - int i; - OMX_TICKS timestamp; - - if (!priv->frame_started) - return; - - priv->picture.h265.NumPocStCurrBefore = 0; - priv->picture.h265.NumPocStCurrAfter = 0; - memset(priv->picture.h265.RefPicSetStCurrBefore, 0, 8); - memset(priv->picture.h265.RefPicSetStCurrAfter, 0, 8); - for (i = 0; i < MAX_NUM_REF_PICS; ++i) { - priv->picture.h265.ref[i] = NULL; - priv->picture.h265.PicOrderCntVal[i] = 0; - } - - rps = priv->codec_data.h265.rps; - - if (rps) { - unsigned bf = 0, af = 0; - - priv->picture.h265.NumDeltaPocsOfRefRpsIdx = rps->num_delta_poc; - for (i = 0; i < rps->num_pics; ++i) { - priv->picture.h265.PicOrderCntVal[i] = - rps->delta_poc[i] + get_poc(priv); - - LIST_FOR_EACH_ENTRY(entry, &priv->codec_data.h265.dpb_list, list) { - if (entry->poc == priv->picture.h265.PicOrderCntVal[i]) { - priv->picture.h265.ref[i] = entry->buffer; - } - } - - if (rps->used[i]) { - if (i < rps->num_neg_pics) { - priv->picture.h265.NumPocStCurrBefore++; - priv->picture.h265.RefPicSetStCurrBefore[bf++] = i; - } else { - priv->picture.h265.NumPocStCurrAfter++; - priv->picture.h265.RefPicSetStCurrAfter[af++] = i; - } - } - } - } - - priv->codec->end_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = false; - - /* add the decoded picture to the dpb list */ - entry = CALLOC_STRUCT(dpb_list); - if (!entry) - return; - - priv->first_buf_in_frame = true; - entry->buffer = priv->target; - entry->timestamp = priv->timestamp; - entry->poc = get_poc(priv); - - list_addtail(&entry->list, &priv->codec_data.h265.dpb_list); - ++priv->codec_data.h265.dpb_num; - priv->target = NULL; - - if (priv->codec_data.h265.dpb_num <= DPB_MAX_SIZE) - return; - - tmp = priv->in_buffers[0]->pInputPortPrivate; - priv->in_buffers[0]->pInputPortPrivate = vid_dec_h265_Flush(priv, ×tamp); - priv->in_buffers[0]->nTimeStamp = timestamp; - priv->target = tmp; - priv->frame_finished = priv->in_buffers[0]->pInputPortPrivate != NULL; - if (priv->frame_finished && - (priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS)) - FREE(priv->codec_data.h265.ref_pic_set_list); -} - -static void slice_header(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - unsigned nal_unit_type) -{ - struct pipe_h265_pps *pps; - struct pipe_h265_sps *sps; - bool first_slice_segment_in_pic_flag; - bool dependent_slice_segment_flag = false; - struct ref_pic_set *rps; - unsigned poc_lsb, poc_msb, slice_prev_poc; - unsigned max_poc_lsb, prev_poc_lsb, prev_poc_msb; - unsigned num_st_rps; - int i; - - if (priv->picture.h265.IDRPicFlag != is_idr_picture(nal_unit_type)) - vid_dec_h265_EndFrame(priv); - - priv->picture.h265.IDRPicFlag = is_idr_picture(nal_unit_type); - - first_slice_segment_in_pic_flag = vl_rbsp_u(rbsp, 1); - - if (is_rap_picture(nal_unit_type)) - /* no_output_of_prior_pics_flag */ - vl_rbsp_u(rbsp, 1); - - pps = pic_parameter_set_id(priv, rbsp); - if (!pps) - return; - - sps = pps->sps; - if (!sps) - return; - - if (pps != priv->picture.h265.pps) - vid_dec_h265_EndFrame(priv); - - priv->picture.h265.pps = pps; - - if (priv->picture.h265.RAPPicFlag != is_rap_picture(nal_unit_type)) - vid_dec_h265_EndFrame(priv); - priv->picture.h265.RAPPicFlag = is_rap_picture(nal_unit_type); - priv->picture.h265.IntraPicFlag = is_rap_picture(nal_unit_type); - num_st_rps = sps->num_short_term_ref_pic_sets; - - if (priv->picture.h265.CurrRpsIdx != num_st_rps) - vid_dec_h265_EndFrame(priv); - priv->picture.h265.CurrRpsIdx = num_st_rps; - - if (!first_slice_segment_in_pic_flag) { - int size, num; - int bits_slice_segment_address = 0; - - if (pps->dependent_slice_segments_enabled_flag) - dependent_slice_segment_flag = vl_rbsp_u(rbsp, 1); - - size = 1 << (sps->log2_min_luma_coding_block_size_minus3 + 3 + - sps->log2_diff_max_min_luma_coding_block_size); - - num = ((sps->pic_width_in_luma_samples + size - 1) / size) * - ((sps->pic_height_in_luma_samples + size - 1) / size); - - while (num > (1 << bits_slice_segment_address)) - bits_slice_segment_address++; - - /* slice_segment_address */ - vl_rbsp_u(rbsp, bits_slice_segment_address); - } - - if (dependent_slice_segment_flag) - return; - - for (i = 0; i < pps->num_extra_slice_header_bits; ++i) - /* slice_reserved_flag */ - vl_rbsp_u(rbsp, 1); - - /* slice_type */ - vl_rbsp_ue(rbsp); - - if (pps->output_flag_present_flag) - /* pic output flag */ - vl_rbsp_u(rbsp, 1); - - if (sps->separate_colour_plane_flag) - /* colour_plane_id */ - vl_rbsp_u(rbsp, 2); - - if (is_idr_picture(nal_unit_type)) { - set_poc(priv, nal_unit_type, 0); - return; - } - - /* slice_pic_order_cnt_lsb */ - poc_lsb = - vl_rbsp_u(rbsp, sps->log2_max_pic_order_cnt_lsb_minus4 + 4); - - slice_prev_poc = (int)priv->codec_data.h265.slice_prev_poc; - max_poc_lsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4); - - prev_poc_lsb = slice_prev_poc & (max_poc_lsb - 1); - prev_poc_msb = slice_prev_poc - prev_poc_lsb; - - if ((poc_lsb < prev_poc_lsb) && - ((prev_poc_lsb - poc_lsb ) >= (max_poc_lsb / 2))) - poc_msb = prev_poc_msb + max_poc_lsb; - - else if ((poc_lsb > prev_poc_lsb ) && - ((poc_lsb - prev_poc_lsb) > (max_poc_lsb / 2))) - poc_msb = prev_poc_msb - max_poc_lsb; - - else - poc_msb = prev_poc_msb; - - if (is_bla_picture(nal_unit_type)) - poc_msb = 0; - - if (get_poc(priv) != poc_msb + poc_lsb) - vid_dec_h265_EndFrame(priv); - - set_poc(priv, nal_unit_type, (poc_msb + poc_lsb)); - - /* short_term_ref_pic_set_sps_flag */ - if (!vl_rbsp_u(rbsp, 1)) { - rps = (struct ref_pic_set *) - priv->codec_data.h265.ref_pic_set_list + num_st_rps; - st_ref_pic_set(priv, rbsp, rps, sps, num_st_rps); - - } else if (num_st_rps > 1) { - int num_bits = 0; - unsigned idx; - - while ((1 << num_bits) < num_st_rps) - num_bits++; - - if (num_bits > 0) - /* short_term_ref_pic_set_idx */ - idx = vl_rbsp_u(rbsp, num_bits); - else - idx = 0; - - rps = (struct ref_pic_set *) - priv->codec_data.h265.ref_pic_set_list + idx; - } else - rps = (struct ref_pic_set *) - priv->codec_data.h265.ref_pic_set_list; - - if (is_bla_picture(nal_unit_type)) { - rps->num_neg_pics = 0; - rps->num_pos_pics = 0; - rps->num_pics = 0; - } - - priv->codec_data.h265.rps = rps; - - return; -} - -static void vid_dec_h265_Decode(vid_dec_PrivateType *priv, - struct vl_vlc *vlc, - unsigned min_bits_left) -{ - unsigned nal_unit_type; - unsigned nuh_layer_id; - unsigned nuh_temporal_id_plus1; - - if (!vl_vlc_search_byte(vlc, vl_vlc_bits_left(vlc) - min_bits_left, 0x00)) - return; - - if (vl_vlc_peekbits(vlc, 24) != 0x000001) { - vl_vlc_eatbits(vlc, 8); - return; - } - - if (priv->slice) { - unsigned bytes = priv->bytes_left - (vl_vlc_bits_left(vlc) / 8); - - priv->codec->decode_bitstream(priv->codec, priv->target, - &priv->picture.base, 1, - &priv->slice, &bytes); - priv->slice = NULL; - } - - vl_vlc_eatbits(vlc, 24); - - /* forbidden_zero_bit */ - vl_vlc_eatbits(vlc, 1); - - if (vl_vlc_valid_bits(vlc) < 15) - vl_vlc_fillbits(vlc); - - nal_unit_type = vl_vlc_get_uimsbf(vlc, 6); - - /* nuh_layer_id */ - nuh_layer_id = vl_vlc_get_uimsbf(vlc, 6); - - /* nuh_temporal_id_plus1 */ - nuh_temporal_id_plus1 = vl_vlc_get_uimsbf(vlc, 3); - priv->codec_data.h265.temporal_id = nuh_temporal_id_plus1 - 1; - - if (!is_slice_picture(nal_unit_type)) - vid_dec_h265_EndFrame(priv); - - if (nal_unit_type == NAL_UNIT_TYPE_SPS) { - struct vl_rbsp rbsp; - - vl_rbsp_init(&rbsp, vlc, ~0, /* emulation_bytes */ true); - seq_parameter_set(priv, &rbsp); - - } else if (nal_unit_type == NAL_UNIT_TYPE_PPS) { - struct vl_rbsp rbsp; - - vl_rbsp_init(&rbsp, vlc, ~0, /* emulation_bytes */ true); - picture_parameter_set(priv, &rbsp); - - } else if (is_slice_picture(nal_unit_type)) { - unsigned bits = vl_vlc_valid_bits(vlc); - unsigned bytes = bits / 8 + 5; - struct vl_rbsp rbsp; - uint8_t buf[9]; - const void *ptr = buf; - unsigned i; - - buf[0] = 0x0; - buf[1] = 0x0; - buf[2] = 0x1; - buf[3] = nal_unit_type << 1 | nuh_layer_id >> 5; - buf[4] = nuh_layer_id << 3 | nuh_temporal_id_plus1; - for (i = 5; i < bytes; ++i) - buf[i] = vl_vlc_peekbits(vlc, bits) >> ((bytes - i - 1) * 8); - - priv->bytes_left = (vl_vlc_bits_left(vlc) - bits) / 8; - priv->slice = vlc->data; - - vl_rbsp_init(&rbsp, vlc, 128, /* emulation_bytes */ true); - slice_header(priv, &rbsp, nal_unit_type); - - vid_dec_h265_BeginFrame(priv); - - priv->codec->decode_bitstream(priv->codec, priv->target, - &priv->picture.base, 1, - &ptr, &bytes); - } - - /* resync to byte boundary */ - vl_vlc_eatbits(vlc, vl_vlc_valid_bits(vlc) % 8); -} - -void vid_dec_h265_Init(vid_dec_PrivateType *priv) -{ - priv->picture.base.profile = PIPE_VIDEO_PROFILE_HEVC_MAIN; - - list_inithead(&priv->codec_data.h265.dpb_list); - priv->codec_data.h265.ref_pic_set_list = (struct ref_pic_set *) - CALLOC(MAX_NUM_REF_PICS, sizeof(struct ref_pic_set)); - - priv->Decode = vid_dec_h265_Decode; - priv->EndFrame = vid_dec_h265_EndFrame; - priv->Flush = vid_dec_h265_Flush; - priv->first_buf_in_frame = true; -} diff --git a/src/gallium/frontends/omx/bellagio/vid_dec_mpeg12.c b/src/gallium/frontends/omx/bellagio/vid_dec_mpeg12.c deleted file mode 100644 index f77d2812d3e..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_dec_mpeg12.c +++ /dev/null @@ -1,383 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#include "pipe/p_video_codec.h" -#include "util/vl_vlc.h" -#include "vl/vl_zscan.h" - -#include "vid_dec.h" - -static uint8_t default_intra_matrix[64] = { - 8, 16, 19, 22, 26, 27, 29, 34, - 16, 16, 22, 24, 27, 29, 34, 37, - 19, 22, 26, 27, 29, 34, 34, 38, - 22, 22, 26, 27, 29, 34, 37, 40, - 22, 26, 27, 29, 32, 35, 40, 48, - 26, 27, 29, 32, 35, 40, 48, 58, - 26, 27, 29, 34, 38, 46, 56, 69, - 27, 29, 35, 38, 46, 56, 69, 83 -}; - -static uint8_t default_non_intra_matrix[64] = { - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16 -}; - -static void vid_dec_mpeg12_Decode(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left); -static void vid_dec_mpeg12_EndFrame(vid_dec_PrivateType *priv); -static struct pipe_video_buffer *vid_dec_mpeg12_Flush(vid_dec_PrivateType *priv, OMX_TICKS *timestamp); - -void vid_dec_mpeg12_Init(vid_dec_PrivateType *priv) -{ - struct pipe_video_codec templat = {}; - omx_base_video_PortType *port; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - templat.profile = priv->profile; - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.max_references = 2; - templat.expect_chunked_decode = true; - templat.width = port->sPortParam.format.video.nFrameWidth; - templat.height = port->sPortParam.format.video.nFrameHeight; - - priv->codec = priv->pipe->create_video_codec(priv->pipe, &templat); - - priv->picture.base.profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN; - priv->picture.mpeg12.intra_matrix = default_intra_matrix; - priv->picture.mpeg12.non_intra_matrix = default_non_intra_matrix; - - priv->Decode = vid_dec_mpeg12_Decode; - priv->EndFrame = vid_dec_mpeg12_EndFrame; - priv->Flush = vid_dec_mpeg12_Flush; -} - -static void BeginFrame(vid_dec_PrivateType *priv) -{ - if (priv->picture.mpeg12.picture_coding_type != PIPE_MPEG12_PICTURE_CODING_TYPE_B) { - priv->picture.mpeg12.ref[0] = priv->picture.mpeg12.ref[1]; - priv->picture.mpeg12.ref[1] = NULL; - } - - if (priv->target == priv->picture.mpeg12.ref[0]) { - struct pipe_video_buffer *tmp = priv->target; - priv->target = priv->shadow; - priv->shadow = tmp; - } - - vid_dec_NeedTarget(priv); - - priv->codec->begin_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = true; -} - -static void vid_dec_mpeg12_EndFrame(vid_dec_PrivateType *priv) -{ - struct pipe_video_buffer *done; - - priv->codec->end_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = false; - - if (priv->picture.mpeg12.picture_coding_type != PIPE_MPEG12_PICTURE_CODING_TYPE_B) { - - priv->picture.mpeg12.ref[1] = priv->target; - done = priv->picture.mpeg12.ref[0]; - if (!done) { - priv->target = NULL; - return; - } - - } else - done = priv->target; - - priv->frame_finished = true; - priv->target = priv->in_buffers[0]->pInputPortPrivate; - priv->in_buffers[0]->pInputPortPrivate = done; -} - -static struct pipe_video_buffer *vid_dec_mpeg12_Flush(vid_dec_PrivateType *priv, OMX_TICKS *timestamp) -{ - struct pipe_video_buffer *result = priv->picture.mpeg12.ref[1]; - priv->picture.mpeg12.ref[1] = NULL; - if (timestamp) - *timestamp = OMX_VID_DEC_TIMESTAMP_INVALID; - return result; -} - -static void vid_dec_mpeg12_Decode(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left) -{ - uint8_t code; - unsigned i; - - if (!vl_vlc_search_byte(vlc, vl_vlc_bits_left(vlc) - min_bits_left, 0x00)) - return; - - if (vl_vlc_peekbits(vlc, 24) != 0x000001) { - vl_vlc_eatbits(vlc, 8); - return; - } - - if (priv->slice) { - unsigned bytes = priv->bytes_left - (vl_vlc_bits_left(vlc) / 8); - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &priv->slice, &bytes); - priv->slice = NULL; - } - - vl_vlc_eatbits(vlc, 24); - code = vl_vlc_get_uimsbf(vlc, 8); - - if (priv->frame_started && (code == 0x00 || code > 0xAF)) - vid_dec_mpeg12_EndFrame(priv); - - if (code == 0xB3) { - /* sequence header code */ - vl_vlc_fillbits(vlc); - - /* horizontal_size_value */ - vl_vlc_get_uimsbf(vlc, 12); - - /* vertical_size_value */ - vl_vlc_get_uimsbf(vlc, 12); - - /* aspect_ratio_information */ - vl_vlc_get_uimsbf(vlc, 4); - - /* frame_rate_code */ - vl_vlc_get_uimsbf(vlc, 4); - - vl_vlc_fillbits(vlc); - - /* bit_rate_value */ - vl_vlc_get_uimsbf(vlc, 18); - - /* marker_bit */ - vl_vlc_get_uimsbf(vlc, 1); - - /* vbv_buffer_size_value */ - vl_vlc_get_uimsbf(vlc, 10); - - /* constrained_parameters_flag */ - vl_vlc_get_uimsbf(vlc, 1); - - vl_vlc_fillbits(vlc); - - /* load_intra_quantiser_matrix */ - if (vl_vlc_get_uimsbf(vlc, 1)) { - /* intra_quantiser_matrix */ - priv->picture.mpeg12.intra_matrix = priv->codec_data.mpeg12.intra_matrix; - for (i = 0; i < 64; ++i) { - priv->codec_data.mpeg12.intra_matrix[vl_zscan_normal[i]] = vl_vlc_get_uimsbf(vlc, 8); - vl_vlc_fillbits(vlc); - } - } else - priv->picture.mpeg12.intra_matrix = default_intra_matrix; - - /* load_non_intra_quantiser_matrix */ - if (vl_vlc_get_uimsbf(vlc, 1)) { - /* non_intra_quantiser_matrix */ - priv->picture.mpeg12.non_intra_matrix = priv->codec_data.mpeg12.non_intra_matrix; - for (i = 0; i < 64; ++i) { - priv->codec_data.mpeg12.non_intra_matrix[i] = vl_vlc_get_uimsbf(vlc, 8); - vl_vlc_fillbits(vlc); - } - } else - priv->picture.mpeg12.non_intra_matrix = default_non_intra_matrix; - - } else if (code == 0x00) { - /* picture start code */ - vl_vlc_fillbits(vlc); - - /* temporal_reference */ - vl_vlc_get_uimsbf(vlc, 10); - - priv->picture.mpeg12.picture_coding_type = vl_vlc_get_uimsbf(vlc, 3); - - /* vbv_delay */ - vl_vlc_get_uimsbf(vlc, 16); - - vl_vlc_fillbits(vlc); - if (priv->picture.mpeg12.picture_coding_type == 2 || - priv->picture.mpeg12.picture_coding_type == 3) { - priv->picture.mpeg12.full_pel_forward_vector = vl_vlc_get_uimsbf(vlc, 1); - /* forward_f_code */ - priv->picture.mpeg12.f_code[0][0] = vl_vlc_get_uimsbf(vlc, 3) - 1; - priv->picture.mpeg12.f_code[0][1] = priv->picture.mpeg12.f_code[0][0]; - } else { - priv->picture.mpeg12.full_pel_forward_vector = 0; - priv->picture.mpeg12.f_code[0][1] = priv->picture.mpeg12.f_code[0][0] = 14; - } - - if (priv->picture.mpeg12.picture_coding_type == 3) { - priv->picture.mpeg12.full_pel_backward_vector = vl_vlc_get_uimsbf(vlc, 1); - /* backward_f_code */ - priv->picture.mpeg12.f_code[1][0] = vl_vlc_get_uimsbf(vlc, 3) - 1; - priv->picture.mpeg12.f_code[1][1] = priv->picture.mpeg12.f_code[1][0]; - } else { - priv->picture.mpeg12.full_pel_backward_vector = 0; - priv->picture.mpeg12.f_code[0][1] = priv->picture.mpeg12.f_code[0][0] = 14; - } - - /* extra_bit_picture */ - while (vl_vlc_get_uimsbf(vlc, 1)) { - /* extra_information_picture */ - vl_vlc_get_uimsbf(vlc, 8); - vl_vlc_fillbits(vlc); - } - - } else if (code == 0xB5) { - /* extension start code */ - vl_vlc_fillbits(vlc); - - /* extension_start_code_identifier */ - switch (vl_vlc_get_uimsbf(vlc, 4)) { - case 0x3: /* quant matrix extension */ - - /* load_intra_quantiser_matrix */ - if (vl_vlc_get_uimsbf(vlc, 1)) { - /* intra_quantiser_matrix */ - priv->picture.mpeg12.intra_matrix = priv->codec_data.mpeg12.intra_matrix; - for (i = 0; i < 64; ++i) { - priv->codec_data.mpeg12.intra_matrix[vl_zscan_normal[i]] = vl_vlc_get_uimsbf(vlc, 8); - vl_vlc_fillbits(vlc); - } - } else - priv->picture.mpeg12.intra_matrix = default_intra_matrix; - - /* load_non_intra_quantiser_matrix */ - if (vl_vlc_get_uimsbf(vlc, 1)) { - /* non_intra_quantiser_matrix */ - priv->picture.mpeg12.non_intra_matrix = priv->codec_data.mpeg12.non_intra_matrix; - for (i = 0; i < 64; ++i) { - priv->codec_data.mpeg12.non_intra_matrix[i] = vl_vlc_get_uimsbf(vlc, 8); - vl_vlc_fillbits(vlc); - } - } else - priv->picture.mpeg12.intra_matrix = default_non_intra_matrix; - - break; - - case 0x8: /* picture coding extension */ - - priv->picture.mpeg12.f_code[0][0] = vl_vlc_get_uimsbf(vlc, 4) - 1; - priv->picture.mpeg12.f_code[0][1] = vl_vlc_get_uimsbf(vlc, 4) - 1; - priv->picture.mpeg12.f_code[1][0] = vl_vlc_get_uimsbf(vlc, 4) - 1; - priv->picture.mpeg12.f_code[1][1] = vl_vlc_get_uimsbf(vlc, 4) - 1; - priv->picture.mpeg12.intra_dc_precision = vl_vlc_get_uimsbf(vlc, 2); - priv->picture.mpeg12.picture_structure = vl_vlc_get_uimsbf(vlc, 2); - priv->picture.mpeg12.top_field_first = vl_vlc_get_uimsbf(vlc, 1); - priv->picture.mpeg12.frame_pred_frame_dct = vl_vlc_get_uimsbf(vlc, 1); - priv->picture.mpeg12.concealment_motion_vectors = vl_vlc_get_uimsbf(vlc, 1); - priv->picture.mpeg12.q_scale_type = vl_vlc_get_uimsbf(vlc, 1); - priv->picture.mpeg12.intra_vlc_format = vl_vlc_get_uimsbf(vlc, 1); - priv->picture.mpeg12.alternate_scan = vl_vlc_get_uimsbf(vlc, 1); - - /* repeat_first_field */ - vl_vlc_get_uimsbf(vlc, 1); - - /* chroma_420_type */ - vl_vlc_get_uimsbf(vlc, 1); - - vl_vlc_fillbits(vlc); - - /* progressive_frame */ - vl_vlc_get_uimsbf(vlc, 1); - - /* composite_display_flag */ - if (vl_vlc_get_uimsbf(vlc, 1)) { - - /* v_axis */ - vl_vlc_get_uimsbf(vlc, 1); - - /* field_sequence */ - vl_vlc_get_uimsbf(vlc, 3); - - /* sub_carrier */ - vl_vlc_get_uimsbf(vlc, 1); - - /* burst_amplitude */ - vl_vlc_get_uimsbf(vlc, 7); - - /* sub_carrier_phase */ - vl_vlc_get_uimsbf(vlc, 8); - } - break; - } - - } else if (code <= 0xAF) { - /* slice start */ - unsigned bytes = (vl_vlc_valid_bits(vlc) / 8) + 4; - uint8_t buf[12]; - const void *ptr = buf; - unsigned i; - - if (!priv->frame_started) - BeginFrame(priv); - - buf[0] = 0x00; - buf[1] = 0x00; - buf[2] = 0x01; - buf[3] = code; - for (i = 4; i < bytes; ++i) - buf[i] = vl_vlc_get_uimsbf(vlc, 8); - - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &ptr, &bytes); - - priv->bytes_left = vl_vlc_bits_left(vlc) / 8; - priv->slice = vlc->data; - - } else if (code == 0xB2) { - /* user data start */ - - } else if (code == 0xB4) { - /* sequence error */ - } else if (code == 0xB7) { - /* sequence end */ - } else if (code == 0xB8) { - /* group start */ - } else if (code >= 0xB9) { - /* system start */ - } else { - /* reserved */ - } - - /* resync to byte boundary */ - vl_vlc_eatbits(vlc, vl_vlc_valid_bits(vlc) % 8); -} diff --git a/src/gallium/frontends/omx/bellagio/vid_enc.c b/src/gallium/frontends/omx/bellagio/vid_enc.c deleted file mode 100644 index ceaa2876a8e..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_enc.c +++ /dev/null @@ -1,935 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - - -#include - -#include - -#include -#include - -#include "pipe/p_screen.h" -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" - -#include "vl/vl_codec.h" - -#include "entrypoint.h" -#include "vid_enc.h" -#include "vid_omx_common.h" -#include "vid_enc_common.h" - -static OMX_ERRORTYPE vid_enc_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name); -static OMX_ERRORTYPE vid_enc_Destructor(OMX_COMPONENTTYPE *comp); -static OMX_ERRORTYPE vid_enc_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param); -static OMX_ERRORTYPE vid_enc_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param); -static OMX_ERRORTYPE vid_enc_SetConfig(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR config); -static OMX_ERRORTYPE vid_enc_GetConfig(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR config); -static OMX_ERRORTYPE vid_enc_MessageHandler(OMX_COMPONENTTYPE *comp, internalRequestMessageType *msg); -static OMX_ERRORTYPE vid_enc_AllocateInBuffer(omx_base_PortType *port, OMX_INOUT OMX_BUFFERHEADERTYPE **buf, - OMX_IN OMX_U32 idx, OMX_IN OMX_PTR private, OMX_IN OMX_U32 size); -static OMX_ERRORTYPE vid_enc_UseInBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE **buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size, OMX_U8 *mem); -static OMX_ERRORTYPE vid_enc_FreeInBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf); -static OMX_ERRORTYPE vid_enc_EncodeFrame(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf); -static OMX_ERRORTYPE vid_enc_AllocateOutBuffer(omx_base_PortType *comp, OMX_INOUT OMX_BUFFERHEADERTYPE **buf, - OMX_IN OMX_U32 idx, OMX_IN OMX_PTR private, OMX_IN OMX_U32 size); -static OMX_ERRORTYPE vid_enc_FreeOutBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf); -static void vid_enc_BufferEncoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output); - -OMX_ERRORTYPE vid_enc_LoaderComponent(stLoaderComponentType *comp) -{ - comp->componentVersion.s.nVersionMajor = 0; - comp->componentVersion.s.nVersionMinor = 0; - comp->componentVersion.s.nRevision = 0; - comp->componentVersion.s.nStep = 1; - comp->name_specific_length = 1; - comp->constructor = vid_enc_Constructor; - - comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (!comp->name) - return OMX_ErrorInsufficientResources; - - comp->name_specific = CALLOC(1, sizeof(char *)); - if (!comp->name_specific) - goto error_arrays; - - comp->role_specific = CALLOC(1, sizeof(char *)); - if (!comp->role_specific) - goto error_arrays; - - comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->name_specific[0] == NULL) - goto error_specific; - - comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE); - if (comp->role_specific[0] == NULL) - goto error_specific; - - strcpy(comp->name, OMX_VID_ENC_BASE_NAME); - strcpy(comp->name_specific[0], OMX_VID_ENC_AVC_NAME); - strcpy(comp->role_specific[0], OMX_VID_ENC_AVC_ROLE); - - return OMX_ErrorNone; - -error_specific: - FREE(comp->role_specific[0]); - FREE(comp->name_specific[0]); - -error_arrays: - FREE(comp->role_specific); - FREE(comp->name_specific); - - FREE(comp->name); - - return OMX_ErrorInsufficientResources; -} - -static OMX_ERRORTYPE vid_enc_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name) -{ - vid_enc_PrivateType *priv; - omx_base_video_PortType *port; - struct pipe_screen *screen; - OMX_ERRORTYPE r; - int i; - - assert(!comp->pComponentPrivate); - - priv = comp->pComponentPrivate = CALLOC(1, sizeof(vid_enc_PrivateType)); - if (!priv) - return OMX_ErrorInsufficientResources; - - r = omx_base_filter_Constructor(comp, name); - if (r) - return r; - - priv->BufferMgmtCallback = vid_enc_BufferEncoded; - priv->messageHandler = vid_enc_MessageHandler; - priv->destructor = vid_enc_Destructor; - - comp->SetParameter = vid_enc_SetParameter; - comp->GetParameter = vid_enc_GetParameter; - comp->GetConfig = vid_enc_GetConfig; - comp->SetConfig = vid_enc_SetConfig; - - priv->screen = omx_get_screen(); - if (!priv->screen) - return OMX_ErrorInsufficientResources; - - screen = priv->screen->pscreen; - if (!vl_codec_supported(screen, PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH, true)) - return OMX_ErrorBadParameter; - - priv->s_pipe = pipe_create_multimedia_context(screen); - if (!priv->s_pipe) - return OMX_ErrorInsufficientResources; - - enc_InitCompute_common(priv); - - if (!vl_compositor_init(&priv->compositor, priv->s_pipe)) { - priv->s_pipe->destroy(priv->s_pipe); - priv->s_pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - if (!vl_compositor_init_state(&priv->cstate, priv->s_pipe)) { - vl_compositor_cleanup(&priv->compositor); - priv->s_pipe->destroy(priv->s_pipe); - priv->s_pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - priv->t_pipe = pipe_create_multimedia_context(screen); - if (!priv->t_pipe) - return OMX_ErrorInsufficientResources; - - priv->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0; - priv->sPortTypesParam[OMX_PortDomainVideo].nPorts = 2; - priv->ports = CALLOC(2, sizeof(omx_base_PortType *)); - if (!priv->ports) - return OMX_ErrorInsufficientResources; - - for (i = 0; i < 2; ++i) { - priv->ports[i] = CALLOC(1, sizeof(omx_base_video_PortType)); - if (!priv->ports[i]) - return OMX_ErrorInsufficientResources; - - base_video_port_Constructor(comp, &priv->ports[i], i, i == 0); - } - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - port->sPortParam.format.video.nFrameWidth = 176; - port->sPortParam.format.video.nFrameHeight = 144; - port->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - port->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - port->sPortParam.nBufferCountActual = 8; - port->sPortParam.nBufferCountMin = 4; - - port->Port_SendBufferFunction = vid_enc_EncodeFrame; - port->Port_AllocateBuffer = vid_enc_AllocateInBuffer; - port->Port_UseBuffer = vid_enc_UseInBuffer; - port->Port_FreeBuffer = vid_enc_FreeInBuffer; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]; - strcpy(port->sPortParam.format.video.cMIMEType,"video/H264"); - port->sPortParam.format.video.nFrameWidth = 176; - port->sPortParam.format.video.nFrameHeight = 144; - port->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; - port->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingAVC; - - port->Port_AllocateBuffer = vid_enc_AllocateOutBuffer; - port->Port_FreeBuffer = vid_enc_FreeOutBuffer; - - priv->bitrate.eControlRate = OMX_Video_ControlRateDisable; - priv->bitrate.nTargetBitrate = 0; - - priv->quant.nQpI = OMX_VID_ENC_QUANT_I_FRAMES_DEFAULT; - priv->quant.nQpP = OMX_VID_ENC_QUANT_P_FRAMES_DEFAULT; - priv->quant.nQpB = OMX_VID_ENC_QUANT_B_FRAMES_DEFAULT; - - priv->profile_level.eProfile = OMX_VIDEO_AVCProfileBaseline; - priv->profile_level.eLevel = OMX_VIDEO_AVCLevel51; - - priv->force_pic_type.IntraRefreshVOP = OMX_FALSE; - priv->frame_num = 0; - priv->pic_order_cnt = 0; - priv->restricted_b_frames = debug_get_bool_option("OMX_USE_RESTRICTED_B_FRAMES", false); - - priv->scale.xWidth = OMX_VID_ENC_SCALING_WIDTH_DEFAULT; - priv->scale.xHeight = OMX_VID_ENC_SCALING_WIDTH_DEFAULT; - - list_inithead(&priv->free_tasks); - list_inithead(&priv->used_tasks); - list_inithead(&priv->b_frames); - list_inithead(&priv->stacked_tasks); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_Destructor(OMX_COMPONENTTYPE *comp) -{ - vid_enc_PrivateType* priv = comp->pComponentPrivate; - int i; - - enc_ReleaseTasks(&priv->free_tasks); - enc_ReleaseTasks(&priv->used_tasks); - enc_ReleaseTasks(&priv->b_frames); - enc_ReleaseTasks(&priv->stacked_tasks); - - if (priv->ports) { - for (i = 0; i < priv->sPortTypesParam[OMX_PortDomainVideo].nPorts; ++i) { - if(priv->ports[i]) - priv->ports[i]->PortDestructor(priv->ports[i]); - } - FREE(priv->ports); - priv->ports=NULL; - } - - for (i = 0; i < OMX_VID_ENC_NUM_SCALING_BUFFERS; ++i) - if (priv->scale_buffer[i]) - priv->scale_buffer[i]->destroy(priv->scale_buffer[i]); - - if (priv->s_pipe) { - vl_compositor_cleanup_state(&priv->cstate); - vl_compositor_cleanup(&priv->compositor); - enc_ReleaseCompute_common(priv); - priv->s_pipe->destroy(priv->s_pipe); - } - - if (priv->t_pipe) - priv->t_pipe->destroy(priv->t_pipe); - - if (priv->screen) - omx_put_screen(); - - return omx_workaround_Destructor(comp); -} - -static OMX_ERRORTYPE enc_AllocateBackTexture(omx_base_PortType *port, - struct pipe_resource **resource, - struct pipe_transfer **transfer, - OMX_U8 **map) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - struct pipe_resource buf_templ; - struct pipe_box box = {}; - OMX_U8 *ptr; - - memset(&buf_templ, 0, sizeof buf_templ); - buf_templ.target = PIPE_TEXTURE_2D; - buf_templ.format = PIPE_FORMAT_I8_UNORM; - buf_templ.bind = PIPE_BIND_LINEAR; - buf_templ.usage = PIPE_USAGE_STAGING; - buf_templ.flags = 0; - buf_templ.width0 = port->sPortParam.format.video.nFrameWidth; - buf_templ.height0 = port->sPortParam.format.video.nFrameHeight * 3 / 2; - buf_templ.depth0 = 1; - buf_templ.array_size = 1; - - *resource = priv->s_pipe->screen->resource_create(priv->s_pipe->screen, &buf_templ); - if (!*resource) - return OMX_ErrorInsufficientResources; - - box.width = (*resource)->width0; - box.height = (*resource)->height0; - box.depth = (*resource)->depth0; - ptr = priv->s_pipe->texture_map(priv->s_pipe, *resource, 0, PIPE_MAP_WRITE, &box, transfer); - if (map) - *map = ptr; - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - - if (!param) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexParamPortDefinition: { - OMX_PARAM_PORTDEFINITIONTYPE *def = param; - - r = omx_base_component_SetParameter(handle, idx, param); - if (r) - return r; - - if (def->nPortIndex == OMX_BASE_FILTER_INPUTPORT_INDEX) { - omx_base_video_PortType *port; - unsigned framesize; - struct pipe_resource *resource; - struct pipe_transfer *transfer; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - enc_AllocateBackTexture(priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX], - &resource, &transfer, NULL); - port->sPortParam.format.video.nStride = transfer->stride; - pipe_texture_unmap(priv->s_pipe, transfer); - pipe_resource_reference(&resource, NULL); - - framesize = port->sPortParam.format.video.nStride * - port->sPortParam.format.video.nFrameHeight; - port->sPortParam.format.video.nSliceHeight = port->sPortParam.format.video.nFrameHeight; - port->sPortParam.nBufferSize = framesize * 3 / 2; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]; - port->sPortParam.nBufferSize = framesize * 512 / (16*16); - - priv->frame_rate = def->format.video.xFramerate; - - priv->callbacks->EventHandler(comp, priv->callbackData, OMX_EventPortSettingsChanged, - OMX_BASE_FILTER_OUTPUTPORT_INDEX, 0, NULL); - } - break; - } - case OMX_IndexParamStandardComponentRole: { - OMX_PARAM_COMPONENTROLETYPE *role = param; - - r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE)); - if (r) - return r; - - if (strcmp((char *)role->cRole, OMX_VID_ENC_AVC_ROLE)) { - return OMX_ErrorBadParameter; - } - - break; - } - case OMX_IndexParamVideoBitrate: { - OMX_VIDEO_PARAM_BITRATETYPE *bitrate = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_BITRATETYPE)); - if (r) - return r; - - priv->bitrate = *bitrate; - - break; - } - case OMX_IndexParamVideoQuantization: { - OMX_VIDEO_PARAM_QUANTIZATIONTYPE *quant = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE)); - if (r) - return r; - - priv->quant = *quant; - - break; - } - case OMX_IndexParamVideoProfileLevelCurrent: { - OMX_VIDEO_PARAM_PROFILELEVELTYPE *profile_level = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); - if (r) - return r; - - priv->profile_level = *profile_level; - - break; - } - default: - return omx_base_component_SetParameter(handle, idx, param); - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - - if (!param) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexParamStandardComponentRole: { - OMX_PARAM_COMPONENTROLETYPE *role = param; - - r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE)); - if (r) - return r; - - strcpy((char *)role->cRole, OMX_VID_ENC_AVC_ROLE); - break; - } - case OMX_IndexParamVideoInit: - r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE)); - if (r) - return r; - - memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE)); - break; - - case OMX_IndexParamVideoPortFormat: { - OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param; - omx_base_video_PortType *port; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - if (r) - return r; - - if (format->nPortIndex > 1) - return OMX_ErrorBadPortIndex; - if (format->nIndex >= 1) - return OMX_ErrorNoMore; - - port = (omx_base_video_PortType *)priv->ports[format->nPortIndex]; - memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); - break; - } - case OMX_IndexParamVideoBitrate: { - OMX_VIDEO_PARAM_BITRATETYPE *bitrate = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_BITRATETYPE)); - if (r) - return r; - - bitrate->eControlRate = priv->bitrate.eControlRate; - bitrate->nTargetBitrate = priv->bitrate.nTargetBitrate; - - break; - } - case OMX_IndexParamVideoQuantization: { - OMX_VIDEO_PARAM_QUANTIZATIONTYPE *quant = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE)); - if (r) - return r; - - quant->nQpI = priv->quant.nQpI; - quant->nQpP = priv->quant.nQpP; - quant->nQpB = priv->quant.nQpB; - - break; - } - case OMX_IndexParamVideoProfileLevelCurrent: { - OMX_VIDEO_PARAM_PROFILELEVELTYPE *profile_level = param; - - r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); - if (r) - return r; - - profile_level->eProfile = priv->profile_level.eProfile; - profile_level->eLevel = priv->profile_level.eLevel; - - break; - } - default: - return omx_base_component_GetParameter(handle, idx, param); - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_SetConfig(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR config) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - int i; - - if (!config) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexConfigVideoIntraVOPRefresh: { - OMX_CONFIG_INTRAREFRESHVOPTYPE *type = config; - - r = checkHeader(config, sizeof(OMX_CONFIG_INTRAREFRESHVOPTYPE)); - if (r) - return r; - - priv->force_pic_type = *type; - - break; - } - case OMX_IndexConfigCommonScale: { - OMX_CONFIG_SCALEFACTORTYPE *scale = config; - - r = checkHeader(config, sizeof(OMX_CONFIG_SCALEFACTORTYPE)); - if (r) - return r; - - if (scale->xWidth < 176 || scale->xHeight < 144) - return OMX_ErrorBadParameter; - - for (i = 0; i < OMX_VID_ENC_NUM_SCALING_BUFFERS; ++i) { - if (priv->scale_buffer[i]) { - priv->scale_buffer[i]->destroy(priv->scale_buffer[i]); - priv->scale_buffer[i] = NULL; - } - } - - priv->scale = *scale; - if (priv->scale.xWidth != 0xffffffff && priv->scale.xHeight != 0xffffffff) { - struct pipe_video_buffer templat = {}; - - templat.buffer_format = PIPE_FORMAT_NV12; - templat.width = priv->scale.xWidth; - templat.height = priv->scale.xHeight; - templat.interlaced = false; - for (i = 0; i < OMX_VID_ENC_NUM_SCALING_BUFFERS; ++i) { - priv->scale_buffer[i] = priv->s_pipe->create_video_buffer(priv->s_pipe, &templat); - if (!priv->scale_buffer[i]) - return OMX_ErrorInsufficientResources; - } - } - - break; - } - default: - return omx_base_component_SetConfig(handle, idx, config); - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_GetConfig(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR config) -{ - OMX_COMPONENTTYPE *comp = handle; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_ERRORTYPE r; - - if (!config) - return OMX_ErrorBadParameter; - - switch(idx) { - case OMX_IndexConfigCommonScale: { - OMX_CONFIG_SCALEFACTORTYPE *scale = config; - - r = checkHeader(config, sizeof(OMX_CONFIG_SCALEFACTORTYPE)); - if (r) - return r; - - scale->xWidth = priv->scale.xWidth; - scale->xHeight = priv->scale.xHeight; - - break; - } - default: - return omx_base_component_GetConfig(handle, idx, config); - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_MessageHandler(OMX_COMPONENTTYPE* comp, internalRequestMessageType *msg) -{ - vid_enc_PrivateType* priv = comp->pComponentPrivate; - - if (msg->messageType == OMX_CommandStateSet) { - if ((msg->messageParam == OMX_StateIdle ) && (priv->state == OMX_StateLoaded)) { - - struct pipe_video_codec templat = {}; - omx_base_video_PortType *port; - - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - - templat.profile = enc_TranslateOMXProfileToPipe(priv->profile_level.eProfile); - templat.level = enc_TranslateOMXLevelToPipe(priv->profile_level.eLevel); - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.width = priv->scale_buffer[priv->current_scale_buffer] ? - priv->scale.xWidth : port->sPortParam.format.video.nFrameWidth; - templat.height = priv->scale_buffer[priv->current_scale_buffer] ? - priv->scale.xHeight : port->sPortParam.format.video.nFrameHeight; - - if (templat.profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE) { - struct pipe_screen *screen = priv->screen->pscreen; - templat.max_references = 1; - priv->stacked_frames_num = - screen->get_video_param(screen, - PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH, - PIPE_VIDEO_ENTRYPOINT_ENCODE, - PIPE_VIDEO_CAP_STACKED_FRAMES); - } else { - templat.max_references = OMX_VID_ENC_P_PERIOD_DEFAULT; - priv->stacked_frames_num = 1; - } - priv->codec = priv->s_pipe->create_video_codec(priv->s_pipe, &templat); - - } else if ((msg->messageParam == OMX_StateLoaded) && (priv->state == OMX_StateIdle)) { - if (priv->codec) { - priv->codec->destroy(priv->codec); - priv->codec = NULL; - } - } - } - - return omx_base_component_MessageHandler(comp, msg); -} - -static OMX_ERRORTYPE vid_enc_AllocateInBuffer(omx_base_PortType *port, OMX_INOUT OMX_BUFFERHEADERTYPE **buf, - OMX_IN OMX_U32 idx, OMX_IN OMX_PTR private, OMX_IN OMX_U32 size) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = base_port_AllocateBuffer(port, buf, idx, private, size); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - base_port_FreeBuffer(port, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - FREE((*buf)->pBuffer); - r = enc_AllocateBackTexture(port, &inp->resource, &inp->transfer, &(*buf)->pBuffer); - if (r) { - FREE(inp); - base_port_FreeBuffer(port, idx, *buf); - return r; - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_UseInBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE **buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size, OMX_U8 *mem) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = base_port_UseBuffer(port, buf, idx, private, size, mem); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - base_port_FreeBuffer(port, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_FreeInBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - struct input_buf_private *inp = buf->pInputPortPrivate; - - if (inp) { - enc_ReleaseTasks(&inp->tasks); - if (inp->transfer) - pipe_texture_unmap(priv->s_pipe, inp->transfer); - pipe_resource_reference(&inp->resource, NULL); - FREE(inp); - } - buf->pBuffer = NULL; - - return base_port_FreeBuffer(port, idx, buf); -} - -static OMX_ERRORTYPE vid_enc_AllocateOutBuffer(omx_base_PortType *port, OMX_INOUT OMX_BUFFERHEADERTYPE **buf, - OMX_IN OMX_U32 idx, OMX_IN OMX_PTR private, OMX_IN OMX_U32 size) -{ - OMX_ERRORTYPE r; - - r = base_port_AllocateBuffer(port, buf, idx, private, size); - if (r) - return r; - - FREE((*buf)->pBuffer); - (*buf)->pBuffer = NULL; - (*buf)->pOutputPortPrivate = CALLOC(1, sizeof(struct output_buf_private)); - if (!(*buf)->pOutputPortPrivate) { - base_port_FreeBuffer(port, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE vid_enc_FreeOutBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - - if (buf->pOutputPortPrivate) { - struct output_buf_private *outp = buf->pOutputPortPrivate; - if (outp->transfer) - pipe_buffer_unmap(priv->t_pipe, outp->transfer); - pipe_resource_reference(&outp->bitstream, NULL); - FREE(outp); - buf->pOutputPortPrivate = NULL; - } - buf->pBuffer = NULL; - - return base_port_FreeBuffer(port, idx, buf); -} - -static struct encode_task *enc_NeedTask(omx_base_PortType *port) -{ - OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video; - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - - return enc_NeedTask_common(priv, def); -} - -static OMX_ERRORTYPE enc_LoadImage(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf, - struct pipe_video_buffer *vbuf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video; - return enc_LoadImage_common(priv, def, buf, vbuf); -} - -static void enc_ScaleInput(omx_base_PortType *port, struct pipe_video_buffer **vbuf, unsigned *size) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video; - enc_ScaleInput_common(priv, def, vbuf, size); -} - -static void enc_ControlPicture(omx_base_PortType *port, struct pipe_h264_enc_picture_desc *picture) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - enc_ControlPicture_common(priv, picture); -} - -static void enc_HandleTask(omx_base_PortType *port, struct encode_task *task, - enum pipe_h2645_enc_picture_type picture_type) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - unsigned size = priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.nBufferSize; - struct pipe_video_buffer *vbuf = task->buf; - struct pipe_h264_enc_picture_desc picture = {}; - - /* -------------- scale input image --------- */ - enc_ScaleInput(port, &vbuf, &size); - priv->s_pipe->flush(priv->s_pipe, NULL, 0); - - /* -------------- allocate output buffer --------- */ - task->bitstream = pipe_buffer_create(priv->s_pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STAGING, /* map for read */ - size); - - picture.picture_type = picture_type; - picture.pic_order_cnt = task->pic_order_cnt; - picture.base.profile = enc_TranslateOMXProfileToPipe(priv->profile_level.eProfile); - picture.base.entry_point = PIPE_VIDEO_ENTRYPOINT_ENCODE; - if (priv->restricted_b_frames && picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) - picture.not_referenced = true; - enc_ControlPicture(port, &picture); - - /* -------------- encode frame --------- */ - priv->codec->begin_frame(priv->codec, vbuf, &picture.base); - priv->codec->encode_bitstream(priv->codec, vbuf, task->bitstream, &task->feedback); - priv->codec->end_frame(priv->codec, vbuf, &picture.base); -} - -static void enc_ClearBframes(omx_base_PortType *port, struct input_buf_private *inp) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - struct encode_task *task; - - if (list_is_empty(&priv->b_frames)) - return; - - task = list_entry(priv->b_frames.prev, struct encode_task, list); - list_del(&task->list); - - /* promote last from to P frame */ - priv->ref_idx_l0 = priv->ref_idx_l1; - enc_HandleTask(port, task, PIPE_H2645_ENC_PICTURE_TYPE_P); - list_addtail(&task->list, &inp->tasks); - priv->ref_idx_l1 = priv->frame_num++; - - /* handle B frames */ - LIST_FOR_EACH_ENTRY(task, &priv->b_frames, list) { - enc_HandleTask(port, task, PIPE_H2645_ENC_PICTURE_TYPE_B); - if (!priv->restricted_b_frames) - priv->ref_idx_l0 = priv->frame_num; - priv->frame_num++; - } - - enc_MoveTasks(&priv->b_frames, &inp->tasks); -} - -static OMX_ERRORTYPE vid_enc_EncodeFrame(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf) -{ - OMX_COMPONENTTYPE* comp = port->standCompContainer; - vid_enc_PrivateType *priv = comp->pComponentPrivate; - struct input_buf_private *inp = buf->pInputPortPrivate; - enum pipe_h2645_enc_picture_type picture_type; - struct encode_task *task; - unsigned stacked_num = 0; - OMX_ERRORTYPE err; - - enc_MoveTasks(&inp->tasks, &priv->free_tasks); - task = enc_NeedTask(port); - if (!task) - return OMX_ErrorInsufficientResources; - - if (buf->nFilledLen == 0) { - if (buf->nFlags & OMX_BUFFERFLAG_EOS) { - buf->nFilledLen = buf->nAllocLen; - enc_ClearBframes(port, inp); - enc_MoveTasks(&priv->stacked_tasks, &inp->tasks); - priv->codec->flush(priv->codec); - } - return base_port_SendBufferFunction(port, buf); - } - - if (buf->pOutputPortPrivate) { - struct pipe_video_buffer *vbuf = buf->pOutputPortPrivate; - buf->pOutputPortPrivate = task->buf; - task->buf = vbuf; - } else { - /* ------- load input image into video buffer ---- */ - err = enc_LoadImage(port, buf, task->buf); - if (err != OMX_ErrorNone) { - FREE(task); - return err; - } - } - - /* -------------- determine picture type --------- */ - if (!(priv->pic_order_cnt % OMX_VID_ENC_IDR_PERIOD_DEFAULT) || - priv->force_pic_type.IntraRefreshVOP) { - enc_ClearBframes(port, inp); - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_IDR; - priv->force_pic_type.IntraRefreshVOP = OMX_FALSE; - priv->frame_num = 0; - priv->pic_order_cnt = 0; - } else if (priv->codec->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE || - !(priv->pic_order_cnt % OMX_VID_ENC_P_PERIOD_DEFAULT) || - (buf->nFlags & OMX_BUFFERFLAG_EOS)) { - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_P; - } else { - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_B; - } - - task->pic_order_cnt = priv->pic_order_cnt++; - - if (picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) { - /* put frame at the tail of the queue */ - list_addtail(&task->list, &priv->b_frames); - } else { - /* handle I or P frame */ - priv->ref_idx_l0 = priv->ref_idx_l1; - enc_HandleTask(port, task, picture_type); - list_addtail(&task->list, &priv->stacked_tasks); - LIST_FOR_EACH_ENTRY(task, &priv->stacked_tasks, list) { - ++stacked_num; - } - if (stacked_num == priv->stacked_frames_num) { - struct encode_task *t; - t = list_entry(priv->stacked_tasks.next, struct encode_task, list); - list_del(&t->list); - list_addtail(&t->list, &inp->tasks); - } - priv->ref_idx_l1 = priv->frame_num++; - - /* handle B frames */ - LIST_FOR_EACH_ENTRY(task, &priv->b_frames, list) { - enc_HandleTask(port, task, PIPE_H2645_ENC_PICTURE_TYPE_B); - if (!priv->restricted_b_frames) - priv->ref_idx_l0 = priv->frame_num; - priv->frame_num++; - } - - enc_MoveTasks(&priv->b_frames, &inp->tasks); - } - - if (list_is_empty(&inp->tasks)) - return port->ReturnBufferFunction(port, buf); - else - return base_port_SendBufferFunction(port, buf); -} - -static void vid_enc_BufferEncoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output) -{ - vid_enc_PrivateType *priv = comp->pComponentPrivate; - vid_enc_BufferEncoded_common(priv, input, output); -} diff --git a/src/gallium/frontends/omx/bellagio/vid_enc.h b/src/gallium/frontends/omx/bellagio/vid_enc.h deleted file mode 100644 index 4d2b867261b..00000000000 --- a/src/gallium/frontends/omx/bellagio/vid_enc.h +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -/* - * Authors: - * Christian König - * - */ - -#ifndef OMX_VID_ENC_H -#define OMX_VID_ENC_H - -#include -#include - -#include - -#define OMX_VID_ENC_BASE_NAME "OMX.mesa.video_encoder" -#define OMX_VID_ENC_AVC_NAME "OMX.mesa.video_encoder.avc" -#define OMX_VID_ENC_AVC_ROLE "video_encoder.avc" - -OMX_ERRORTYPE vid_enc_LoaderComponent(stLoaderComponentType *comp); - -#endif diff --git a/src/gallium/frontends/omx/meson.build b/src/gallium/frontends/omx/meson.build deleted file mode 100644 index f212a1d940b..00000000000 --- a/src/gallium/frontends/omx/meson.build +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright © 2017, 2019 Intel Corporation -# SPDX-License-Identifier: MIT - -inc_st_omx = [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux] -dep_st_omx = [ - dep_omx, dep_x11_xcb, dep_xcb, dep_xcb_dri2, dep_xcb_dri3, dep_libdrm, -] - -files_omx = files( - 'vid_dec_common.c', - 'vid_dec_h264_common.c', - 'vid_enc_common.c', - 'vid_omx_common.c' -) - -if with_gallium_omx == 'bellagio' - files_omx += files( - 'bellagio/entrypoint.c', - 'bellagio/vid_dec.c', - 'bellagio/vid_dec_mpeg12.c', - 'bellagio/vid_dec_h264.c', - 'bellagio/vid_dec_h265.c', - 'bellagio/vid_dec_av1.c', - 'bellagio/vid_enc.c' - ) -elif with_gallium_omx == 'tizonia' - files_omx += files( - 'tizonia/entrypoint.c', - 'tizonia/h264d.c', - 'tizonia/h264dprc.c', - 'tizonia/h264dinport.c', - 'tizonia/h264e.c', - 'tizonia/h264eprc.c', - 'tizonia/h264einport.c', - 'tizonia/h264eoutport.c' - ) - inc_st_omx = [ - inc_st_omx, - inc_loader, - inc_gbm, - inc_st_dri, - inc_egl, - inc_egl_dri2, - ] - dep_st_omx = [dep_st_omx, dep_omx_other] -endif - -libomx_st = static_library( - 'omx_st', - files_omx, - c_args : ['-fcommon'], - gnu_symbol_visibility : 'hidden', - include_directories : inc_st_omx, - dependencies : [dep_st_omx, idep_mesautil], -) diff --git a/src/gallium/frontends/omx/tizonia/entrypoint.c b/src/gallium/frontends/omx/tizonia/entrypoint.c deleted file mode 100644 index a6c2c45b39e..00000000000 --- a/src/gallium/frontends/omx/tizonia/entrypoint.c +++ /dev/null @@ -1,158 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include "vid_dec_h264_common.h" -#include "entrypoint.h" -#include "h264d.h" -#include "h264dprc.h" -#include "h264dinport.h" -#include "h264e.h" -#include "h264eprc.h" -#include "h264einport.h" -#include "h264eoutport.h" -#include "names.h" - -#include "util/u_debug.h" - -DEBUG_GET_ONCE_BOOL_OPTION(mesa_enable_omx_eglimage, - "MESA_ENABLE_OMX_EGLIMAGE", - false) - -static OMX_BOOL egl_image_validation_hook(const OMX_HANDLETYPE ap_hdl, - OMX_U32 pid, OMX_PTR ap_eglimage, - void *ap_args) -{ - const void * p_krn = NULL; - const tiz_port_t * p_port = NULL; - - assert(ap_hdl); - assert(ap_eglimage); - assert(!ap_args); - - if (!debug_get_option_mesa_enable_omx_eglimage()) { - return OMX_FALSE; - } - - p_krn = tiz_get_krn(ap_hdl); - p_port = tiz_krn_get_port(p_krn, pid); - - const OMX_VIDEO_PORTDEFINITIONTYPE * p_video_portdef - = &(p_port->portdef_.format.video); - - if (!p_video_portdef->pNativeWindow) { - return OMX_FALSE; - } - - return OMX_TRUE; -} - -OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE ap_hdl) -{ - tiz_role_factory_t h264d_role; - tiz_role_factory_t h264e_role; - const tiz_role_factory_t * rf_list[] = {&h264d_role, &h264e_role}; - tiz_type_factory_t h264dprc_type; - tiz_type_factory_t h264d_inport_type; - tiz_type_factory_t h264eprc_type; - tiz_type_factory_t h264e_inport_type; - tiz_type_factory_t h264e_outport_type; - const tiz_type_factory_t * tf_list[] = {&h264dprc_type, - &h264d_inport_type, - &h264eprc_type, - &h264e_inport_type, - &h264e_outport_type}; - const tiz_eglimage_hook_t egl_validation_hook = { - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - egl_image_validation_hook, - NULL - }; - - /* Settings for roles */ - strcpy ((OMX_STRING) h264d_role.role, OMX_VID_DEC_AVC_ROLE); - h264d_role.pf_cport = instantiate_h264d_config_port; - h264d_role.pf_port[0] = instantiate_h264d_input_port; - h264d_role.pf_port[1] = instantiate_h264d_output_port; - h264d_role.nports = 2; - h264d_role.pf_proc = instantiate_h264d_processor; - - strcpy ((OMX_STRING) h264e_role.role, OMX_VID_ENC_AVC_ROLE); - h264e_role.pf_cport = instantiate_h264e_config_port; - h264e_role.pf_port[0] = instantiate_h264e_input_port; - h264e_role.pf_port[1] = instantiate_h264e_output_port; - h264e_role.nports = 2; - h264e_role.pf_proc = instantiate_h264e_processor; - - /* Settings for classes */ - strcpy ((OMX_STRING) h264dprc_type.class_name, "h264dprc_class"); - h264dprc_type.pf_class_init = h264d_prc_class_init; - strcpy ((OMX_STRING) h264dprc_type.object_name, "h264dprc"); - h264dprc_type.pf_object_init = h264d_prc_init; - - strcpy ((OMX_STRING) h264d_inport_type.class_name, "h264dinport_class"); - h264d_inport_type.pf_class_init = h264d_inport_class_init; - strcpy ((OMX_STRING) h264d_inport_type.object_name, "h264dinport"); - h264d_inport_type.pf_object_init = h264d_inport_init; - - strcpy ((OMX_STRING) h264eprc_type.class_name, "h264eprc_class"); - h264eprc_type.pf_class_init = h264e_prc_class_init; - strcpy ((OMX_STRING) h264eprc_type.object_name, "h264eprc"); - h264eprc_type.pf_object_init = h264e_prc_init; - - strcpy ((OMX_STRING) h264e_inport_type.class_name, "h264einport_class"); - h264e_inport_type.pf_class_init = h264e_inport_class_init; - strcpy ((OMX_STRING) h264e_inport_type.object_name, "h264einport"); - h264e_inport_type.pf_object_init = h264e_inport_init; - - strcpy ((OMX_STRING) h264e_outport_type.class_name, "h264eoutport_class"); - h264e_outport_type.pf_class_init = h264e_outport_class_init; - strcpy ((OMX_STRING) h264e_outport_type.object_name, "h264eoutport"); - h264e_outport_type.pf_object_init = h264e_outport_init; - - /* Initialize the component infrastructure */ - tiz_comp_init (ap_hdl, OMX_VID_COMP_NAME); - - /* Classes need to be registered first */ - tiz_comp_register_types (ap_hdl, tf_list, 5); - - /* Register the component roles */ - tiz_comp_register_roles (ap_hdl, rf_list, 2); - - /* Register egl image validation hook for the decoder */ - tiz_check_omx (tiz_comp_register_role_eglimage_hook - (ap_hdl, (const OMX_U8 *) OMX_VID_DEC_AVC_ROLE, - &egl_validation_hook)); - - return OMX_ErrorNone; -} diff --git a/src/gallium/frontends/omx/tizonia/entrypoint.h b/src/gallium/frontends/omx/tizonia/entrypoint.h deleted file mode 100644 index 740a89dbffc..00000000000 --- a/src/gallium/frontends/omx/tizonia/entrypoint.h +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef OMX_TIZ_ENTRYPOINT_H -#define OMX_TIZ_ENTRYPOINT_H - -#include "vl/vl_winsys.h" - -PUBLIC OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE ap_hdl); - -#endif diff --git a/src/gallium/frontends/omx/tizonia/h264d.c b/src/gallium/frontends/omx/tizonia/h264d.c deleted file mode 100644 index 92019a7a4bd..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264d.c +++ /dev/null @@ -1,176 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include - -#include "vid_dec_h264_common.h" - -#include "h264dprc.h" -#include "h264d.h" -#include "names.h" - -static OMX_VERSIONTYPE h264_decoder_version = {{0, 0, 0, 1}}; - -OMX_PTR instantiate_h264d_input_port(OMX_HANDLETYPE ap_hdl) -{ - OMX_VIDEO_PORTDEFINITIONTYPE portdef; - OMX_VIDEO_PARAM_AVCTYPE avctype; - OMX_VIDEO_CODINGTYPE encodings[] = { - OMX_VIDEO_CodingAVC, - OMX_VIDEO_CodingMax - }; - OMX_COLOR_FORMATTYPE formats[] = { - OMX_COLOR_FormatUnused, - OMX_COLOR_FormatMax - }; - tiz_port_options_t avc_port_opts = { - OMX_PortDomainVideo, - OMX_DirInput, - OMX_VID_DEC_AVC_INPUT_PORT_MIN_BUF_COUNT, - OMX_VID_DEC_AVC_PORT_MIN_INPUT_BUF_SIZE, - OMX_VID_DEC_AVC_PORT_NONCONTIGUOUS, - OMX_VID_DEC_AVC_PORT_ALIGNMENT, - OMX_VID_DEC_AVC_PORT_SUPPLIERPREF, - {OMX_VID_DEC_AVC_INPUT_PORT_INDEX, NULL, NULL, NULL}, - 1 /* slave port */ - }; - OMX_VIDEO_AVCLEVELTYPE levels[] = { - OMX_VIDEO_AVCLevel1, - OMX_VIDEO_AVCLevel1b, - OMX_VIDEO_AVCLevel11, - OMX_VIDEO_AVCLevel12, - OMX_VIDEO_AVCLevel13, - OMX_VIDEO_AVCLevel2, - OMX_VIDEO_AVCLevel21, - OMX_VIDEO_AVCLevel22, - OMX_VIDEO_AVCLevel3, - OMX_VIDEO_AVCLevel31, - OMX_VIDEO_AVCLevel32, - OMX_VIDEO_AVCLevel4, - OMX_VIDEO_AVCLevel41, - OMX_VIDEO_AVCLevel42, - OMX_VIDEO_AVCLevel5, - OMX_VIDEO_AVCLevel51, - OMX_VIDEO_AVCLevelMax - }; - - portdef.pNativeRender = NULL; - portdef.nFrameWidth = OMX_VID_DEC_AVC_DEFAULT_FRAME_WIDTH; - portdef.nFrameHeight = OMX_VID_DEC_AVC_DEFAULT_FRAME_HEIGHT; - portdef.nStride = 0; - portdef.nSliceHeight = 0; - portdef.nBitrate = 64000; - portdef.xFramerate = OMX_VID_DEC_AVC_DEFAULT_FRAME_RATE; - portdef.bFlagErrorConcealment = OMX_FALSE; - portdef.eCompressionFormat = OMX_VIDEO_CodingAVC; - portdef.eColorFormat = OMX_COLOR_FormatUnused; - portdef.pNativeWindow = NULL; - - avctype.nSize = sizeof (OMX_VIDEO_PARAM_AVCTYPE); - avctype.nVersion.nVersion = OMX_VERSION; - avctype.nPortIndex = OMX_VID_DEC_AVC_INPUT_PORT_INDEX; - avctype.eProfile = OMX_VIDEO_AVCProfileHigh; - /* Encoder related, decide if need to initialise these */ - avctype.nSliceHeaderSpacing = 0; - avctype.nPFrames = 0; - avctype.nBFrames = 0; - avctype.bUseHadamard = OMX_FALSE; - avctype.nRefFrames = 1; - avctype.nRefIdx10ActiveMinus1 = 1; - avctype.nRefIdx11ActiveMinus1 = 0; - avctype.bEnableUEP = OMX_FALSE; - avctype.bEnableFMO = OMX_FALSE; - avctype.bEnableASO = OMX_FALSE; - avctype.bEnableRS = OMX_FALSE; - avctype.eLevel = OMX_VIDEO_AVCLevel51; - avctype.nAllowedPictureTypes = 2; - avctype.bFrameMBsOnly = OMX_FALSE; - avctype.bMBAFF = OMX_FALSE; - avctype.bEntropyCodingCABAC = OMX_FALSE; - avctype.bWeightedPPrediction = OMX_FALSE; - avctype.nWeightedBipredicitonMode = 0; - avctype.bconstIpred = OMX_FALSE; - avctype.bDirect8x8Inference = OMX_FALSE; - avctype.bDirectSpatialTemporal = OMX_FALSE; - avctype.nCabacInitIdc = 0; - avctype.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; - - return factory_new (tiz_get_type(ap_hdl, "h264dinport"), - &avc_port_opts, &portdef, - &encodings, &formats, &avctype, &levels, - NULL /* OMX_VIDEO_PARAM_BITRATETYPE */, - NULL /* OMX_VIDEO_PARAM_QUANTIZATIONTYPE */); -} - -OMX_PTR instantiate_h264d_output_port(OMX_HANDLETYPE ap_hdl) -{ - OMX_VIDEO_PORTDEFINITIONTYPE portdef; - OMX_VIDEO_CODINGTYPE encodings[] = { - OMX_VIDEO_CodingUnused, - OMX_VIDEO_CodingMax - }; - OMX_COLOR_FORMATTYPE formats[] = { - OMX_COLOR_FormatYUV420SemiPlanar, - OMX_COLOR_FormatMax - }; - tiz_port_options_t rawvideo_port_opts = { - OMX_PortDomainVideo, - OMX_DirOutput, - OMX_VID_DEC_AVC_OUTPUT_PORT_MIN_BUF_COUNT, - OMX_VID_DEC_AVC_PORT_MIN_OUTPUT_BUF_SIZE, - OMX_VID_DEC_AVC_PORT_NONCONTIGUOUS, - OMX_VID_DEC_AVC_PORT_ALIGNMENT, - OMX_VID_DEC_AVC_PORT_SUPPLIERPREF, - {OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, NULL, NULL, NULL}, - 0 /* Master port */ - }; - - portdef.pNativeRender = NULL; - portdef.nFrameWidth = OMX_VID_DEC_AVC_DEFAULT_FRAME_WIDTH; - portdef.nFrameHeight = OMX_VID_DEC_AVC_DEFAULT_FRAME_HEIGHT; - portdef.nStride = 0; - portdef.nSliceHeight = 0; - portdef.nBitrate = 64000; - portdef.xFramerate = OMX_VID_DEC_AVC_DEFAULT_FRAME_RATE; - portdef.bFlagErrorConcealment = OMX_FALSE; - portdef.eCompressionFormat = OMX_VIDEO_CodingUnused; - portdef.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - portdef.pNativeWindow = NULL; - - return factory_new(tiz_get_type(ap_hdl, "tizvideoport"), - &rawvideo_port_opts, &portdef, - &encodings, &formats); -} - -OMX_PTR instantiate_h264d_config_port(OMX_HANDLETYPE ap_hdl) -{ - return factory_new(tiz_get_type(ap_hdl, "tizconfigport"), - NULL, /* this port does not take options */ - OMX_VID_COMP_NAME, h264_decoder_version); -} - -OMX_PTR instantiate_h264d_processor(OMX_HANDLETYPE ap_hdl) -{ - return factory_new(tiz_get_type(ap_hdl, "h264dprc")); -} diff --git a/src/gallium/frontends/omx/tizonia/h264d.h b/src/gallium/frontends/omx/tizonia/h264d.h deleted file mode 100644 index 1733425d45c..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264d.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264D_H -#define H264D_H - -#include -#include -#include - -OMX_PTR instantiate_h264d_config_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264d_input_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264d_output_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264d_processor(OMX_HANDLETYPE ap_hdl); - -#endif /* H264D_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264dinport.c b/src/gallium/frontends/omx/tizonia/h264dinport.c deleted file mode 100644 index 858ae761560..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264dinport.c +++ /dev/null @@ -1,147 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#include -#include - -#include "vl/vl_winsys.h" - -#include "h264d.h" -#include "h264dinport.h" -#include "h264dinport_decls.h" -#include "vid_dec_common.h" - -/* - * h264dinport class - */ - -static void * h264d_inport_ctor(void * ap_obj, va_list * app) -{ - return super_ctor(typeOf(ap_obj, "h264dinport"), ap_obj, app); -} - -static void * h264d_inport_dtor(void * ap_obj) -{ - return super_dtor(typeOf(ap_obj, "h264dinport"), ap_obj); -} - -/* - * from tiz_api - */ - -static OMX_ERRORTYPE h264d_inport_SetParameter(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_INDEXTYPE a_index, OMX_PTR ap_struct) -{ - OMX_ERRORTYPE err = OMX_ErrorNone; - - assert(ap_obj); - assert(ap_hdl); - assert(ap_struct); - - if (a_index == OMX_IndexParamPortDefinition) { - vid_dec_PrivateType * p_prc = tiz_get_prc(ap_hdl); - OMX_VIDEO_PORTDEFINITIONTYPE * p_def = &(p_prc->out_port_def_.format.video); - OMX_PARAM_PORTDEFINITIONTYPE * i_def = (OMX_PARAM_PORTDEFINITIONTYPE *) ap_struct; - - /* Make changes only if there is a resolution change */ - if ((p_def->nFrameWidth == i_def->format.video.nFrameWidth) && - (p_def->nFrameHeight == i_def->format.video.nFrameHeight) && - (p_def->eCompressionFormat == i_def->format.video.eCompressionFormat)) - return err; - - /* Set some default values if not set */ - if (i_def->format.video.nStride == 0) - i_def->format.video.nStride = i_def->format.video.nFrameWidth; - if (i_def->format.video.nSliceHeight == 0) - i_def->format.video.nSliceHeight = i_def->format.video.nFrameHeight; - - err = super_SetParameter(typeOf (ap_obj, "h264dinport"), ap_obj, - ap_hdl, a_index, ap_struct); - if (err == OMX_ErrorNone) { - tiz_port_t * p_obj = (tiz_port_t *) ap_obj; - - /* Set desired buffer size that will be used when allocating input buffers */ - p_obj->portdef_.nBufferSize = i_def->format.video.nFrameWidth * i_def->format.video.nFrameHeight * 512 / (16*16); - - /* Get a locally copy of port def. Useful for the early return above */ - tiz_check_omx(tiz_api_GetParameter(tiz_get_krn(handleOf(p_prc)), handleOf(p_prc), - OMX_IndexParamPortDefinition, &(p_prc->out_port_def_))); - } - } - - return err; -} - -/* - * h264dinport_class - */ - -static void * h264d_inport_class_ctor(void * ap_obj, va_list * app) -{ - /* NOTE: Class methods might be added in the future. None for now. */ - return super_ctor (typeOf (ap_obj, "h264dinport_class"), ap_obj, app); -} - -/* - * initialization - */ - -void * h264d_inport_class_init(void * ap_tos, void * ap_hdl) -{ - void * tizavcport = tiz_get_type(ap_hdl, "tizavcport"); - void * h264dinport_class - = factory_new(classOf(tizavcport), "h264dinport_class", - classOf(tizavcport), sizeof(h264d_inport_class_t), - ap_tos, ap_hdl, ctor, h264d_inport_class_ctor, 0); - return h264dinport_class; -} - -void * h264d_inport_init(void * ap_tos, void * ap_hdl) -{ - void * tizavcport = tiz_get_type (ap_hdl, "tizavcport"); - void * h264dinport_class = tiz_get_type (ap_hdl, "h264dinport_class"); - void * h264dinport = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (h264dinport_class, "h264dinport", tizavcport, - sizeof (h264d_inport_t), - /* TIZ_CLASS_COMMENT: class constructor */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264d_inport_ctor, - /* TIZ_CLASS_COMMENT: class destructor */ - dtor, h264d_inport_dtor, - /* TIZ_CLASS_COMMENT: */ - tiz_api_SetParameter, h264d_inport_SetParameter, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - - return h264dinport; -} diff --git a/src/gallium/frontends/omx/tizonia/h264dinport.h b/src/gallium/frontends/omx/tizonia/h264dinport.h deleted file mode 100644 index f158e4e1038..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264dinport.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264DINPORT_H -#define H264DINPORT_H - -void * h264d_inport_class_init(void * ap_tos, void * ap_hdl); -void * h264d_inport_init(void * ap_tos, void * ap_hdl); - -#endif /* H264DINPORT_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264dinport_decls.h b/src/gallium/frontends/omx/tizonia/h264dinport_decls.h deleted file mode 100644 index 0194f6e3d09..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264dinport_decls.h +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264DINPORT_DECLS_H -#define H264DINPORT_DECLS_H - -#include -#include - -#include - -typedef struct h264d_inport h264d_inport_t; -struct h264d_inport -{ - /* Object */ - const tiz_avcport_t _; -}; - -typedef struct h264d_inport_class h264d_inport_class_t; -struct h264d_inport_class -{ - /* Class */ - const tiz_avcport_class_t _; - /* NOTE: Class methods might be added in the future */ -}; - -#endif /* H264DINPORT_DECLS_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264dprc.c b/src/gallium/frontends/omx/tizonia/h264dprc.c deleted file mode 100644 index e8ad22c8da4..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264dprc.c +++ /dev/null @@ -1,616 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#include "entrypoint.h" -#include "h264d.h" -#include "h264dprc.h" -#include "vid_omx_common.h" -#include "vid_dec_common.h" -#include "vid_dec_h264_common.h" - -#include "vl/vl_video_buffer.h" -#include "vl/vl_compositor.h" -#include "util/u_hash_table.h" -#include "util/u_surface.h" - -#include "dri_screen.h" -#include "egl_dri2.h" - -unsigned dec_frame_delta; - -static enum pipe_error hash_table_clear_item_callback(void *key, void *value, void *data) -{ - struct pipe_video_buffer *video_buffer = (struct pipe_video_buffer *)value; - video_buffer->destroy(video_buffer); - return PIPE_OK; -} - -static void release_input_headers(vid_dec_PrivateType* priv) { - int i; - for (i = 0; i < priv->num_in_buffers; i++) { - assert(!priv->in_port_disabled_); - if (priv->in_buffers[i]->pInputPortPrivate) { - vid_dec_FreeInputPortPrivate(priv->in_buffers[i]); - } - (void) tiz_krn_release_buffer (tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_INPUT_PORT_INDEX, - priv->in_buffers[i]); - priv->in_buffers[i] = NULL; - } - priv->p_inhdr_ = NULL; - priv->num_in_buffers = 0; -} - -static void release_output_header(vid_dec_PrivateType* priv) { - if (priv->p_outhdr_) { - assert(!priv->out_port_disabled_); - (void) tiz_krn_release_buffer (tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - priv->p_outhdr_); - priv->p_outhdr_ = NULL; - } -} - -static OMX_ERRORTYPE h264d_release_all_headers(vid_dec_PrivateType* priv) -{ - assert(priv); - release_input_headers(priv); - release_output_header(priv); - - return OMX_ErrorNone; -} - -static void h264d_buffer_emptied(vid_dec_PrivateType* priv, OMX_BUFFERHEADERTYPE * p_hdr) -{ - assert(priv); - assert(priv->in_buffers[0] == p_hdr); - - if (!priv->out_port_disabled_) { - assert (p_hdr->nFilledLen == 0); - p_hdr->nOffset = 0; - - if ((p_hdr->nFlags & OMX_BUFFERFLAG_EOS) != 0) { - priv->eos_ = true; - } - - (void) tiz_krn_release_buffer (tiz_get_krn (handleOf (priv)), 0, p_hdr); - priv->p_inhdr_ = NULL; - priv->in_buffers[0] = NULL; - } -} - -static void h264d_buffer_filled(vid_dec_PrivateType* priv, OMX_BUFFERHEADERTYPE * p_hdr) -{ - assert(priv); - assert(p_hdr); - assert(priv->p_outhdr_ == p_hdr); - - if (!priv->in_port_disabled_) { - p_hdr->nOffset = 0; - - if (priv->eos_) { - /* EOS has been received and all the input data has been consumed - * already, so its time to propagate the EOS flag */ - priv->p_outhdr_->nFlags |= OMX_BUFFERFLAG_EOS; - priv->eos_ = false; - } - - (void) tiz_krn_release_buffer(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - p_hdr); - priv->p_outhdr_ = NULL; - } -} - -static bool h264d_shift_buffers_left(vid_dec_PrivateType* priv) { - if (--priv->num_in_buffers) { - priv->in_buffers[0] = priv->in_buffers[1]; - priv->sizes[0] = priv->sizes[1] - dec_frame_delta; - priv->inputs[0] = priv->inputs[1] + dec_frame_delta; - priv->timestamps[0] = priv->timestamps[1]; - - return true; - } - return false; -} - -static OMX_BUFFERHEADERTYPE * get_input_buffer(vid_dec_PrivateType* priv) { - assert(priv); - - if (priv->in_port_disabled_) { - return NULL; - } - - if (priv->num_in_buffers > 1) { - /* The input buffer wasn't cleared last time. */ - h264d_buffer_emptied(priv, priv->in_buffers[0]); - if (priv->in_buffers[0]) { - /* Failed to release buffer */ - return NULL; - } - h264d_shift_buffers_left(priv); - } - - /* Decode_frame expects new buffers each time */ - assert(priv->p_inhdr_ || priv->first_buf_in_frame); - tiz_krn_claim_buffer(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_INPUT_PORT_INDEX, 0, - &priv->p_inhdr_); - return priv->p_inhdr_; -} - -static struct pipe_resource * st_omx_pipe_texture_from_eglimage(EGLDisplay egldisplay, - EGLImage eglimage) -{ - _EGLDisplay *disp = egldisplay; - struct dri2_egl_display *dri2_egl_dpy = disp->DriverData; - __DRIscreen *_dri_screen = dri2_egl_dpy->dri_screen; - struct dri_screen *st_dri_screen = dri_screen(_dri_screen); - if (!st_dri_screen->validate_egl_image(st_dri_screen, eglimage)) - return NULL; - __DRIimage *_dri_image = st_dri_screen->lookup_egl_image_validated(st_dri_screen, eglimage); - - return _dri_image->texture; -} - -static void get_eglimage(vid_dec_PrivateType* priv) { - OMX_PTR p_eglimage = NULL; - OMX_NATIVE_WINDOWTYPE * p_egldisplay = NULL; - const tiz_port_t * p_port = NULL; - struct pipe_video_buffer templat = {}; - struct pipe_video_buffer *video_buffer = NULL; - struct pipe_resource * p_res = NULL; - struct pipe_resource *resources[VL_NUM_COMPONENTS]; - - if (OMX_ErrorNone == - tiz_krn_claim_eglimage(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - priv->p_outhdr_, &p_eglimage)) { - priv->use_eglimage = true; - p_port = tiz_krn_get_port(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX); - p_egldisplay = p_port->portdef_.format.video.pNativeWindow; - - if (!util_hash_table_get(priv->video_buffer_map, priv->p_outhdr_)) { - p_res = st_omx_pipe_texture_from_eglimage(p_egldisplay, p_eglimage); - - assert(p_res); - - memset(&templat, 0, sizeof(templat)); - templat.buffer_format = p_res->format; - templat.width = p_res->width0; - templat.height = p_res->height0; - templat.interlaced = 0; - - memset(resources, 0, sizeof(resources)); - pipe_resource_reference(&resources[0], p_res); - - video_buffer = vl_video_buffer_create_ex2(priv->pipe, &templat, resources); - - assert(video_buffer); - assert(video_buffer->buffer_format == p_res->format); - - _mesa_hash_table_insert(priv->video_buffer_map, priv->p_outhdr_, video_buffer); - } - } else { - (void) tiz_krn_release_buffer(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - priv->p_outhdr_); - priv->p_outhdr_ = NULL; - } -} - -static OMX_BUFFERHEADERTYPE * get_output_buffer(vid_dec_PrivateType* priv) { - assert (priv); - - if (priv->out_port_disabled_) { - return NULL; - } - - if (!priv->p_outhdr_) { - if (OMX_ErrorNone - == tiz_krn_claim_buffer(tiz_get_krn (handleOf (priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, 0, - &priv->p_outhdr_)) { - if (priv->p_outhdr_) { - /* Check pBuffer nullity to know if an eglimage has been registered. */ - if (!priv->p_outhdr_->pBuffer) { - get_eglimage(priv); - } - } - } - } - return priv->p_outhdr_; -} - -static void reset_stream_parameters(vid_dec_PrivateType* apriv) -{ - assert(apriv); - TIZ_INIT_OMX_PORT_STRUCT(apriv->out_port_def_, - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX); - - tiz_api_GetParameter (tiz_get_krn (handleOf (apriv)), handleOf (apriv), - OMX_IndexParamPortDefinition, &(apriv->out_port_def_)); - - apriv->p_inhdr_ = 0; - apriv->num_in_buffers = 0; - apriv->first_buf_in_frame = true; - apriv->eos_ = false; - apriv->frame_finished = false; - apriv->frame_started = false; - apriv->picture.h264.field_order_cnt[0] = apriv->picture.h264.field_order_cnt[1] = INT_MAX; - apriv->slice = NULL; -} - -/* Replacement for bellagio's omx_base_filter_BufferMgmtFunction */ -static void h264d_manage_buffers(vid_dec_PrivateType* priv) { - bool next_is_eos = priv->num_in_buffers == 2 ? !!(priv->in_buffers[1]->nFlags & OMX_BUFFERFLAG_EOS) : false; - vid_dec_FrameDecoded_common(priv, priv->in_buffers[0], priv->p_outhdr_); - - priv->p_outhdr_->nTimeStamp = priv->in_buffers[0]->nTimeStamp; - - /* Realase output buffer if filled or eos - Keep if two input buffers are being decoded */ - if ((!next_is_eos) && ((priv->p_outhdr_->nFilledLen > 0) || priv->use_eglimage || priv->eos_)) { - h264d_buffer_filled(priv, priv->p_outhdr_); - } - - /* Release input buffer if possible */ - if (priv->in_buffers[0]->nFilledLen == 0) { - h264d_buffer_emptied(priv, priv->in_buffers[0]); - } -} - -static OMX_ERRORTYPE decode_frame(vid_dec_PrivateType*priv, - OMX_BUFFERHEADERTYPE *in_buf) -{ - unsigned i = priv->num_in_buffers++; - priv->in_buffers[i] = in_buf; - priv->sizes[i] = in_buf->nFilledLen; - priv->inputs[i] = in_buf->pBuffer; - priv->timestamps[i] = in_buf->nTimeStamp; - - while (priv->num_in_buffers > (!!(in_buf->nFlags & OMX_BUFFERFLAG_EOS) ? 0 : 1)) { - priv->eos_ = !!(priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS); - unsigned min_bits_left = priv->eos_ ? 32 : MAX2(in_buf->nFilledLen * 8, 32); - struct vl_vlc vlc; - - vl_vlc_init(&vlc, priv->num_in_buffers, priv->inputs, priv->sizes); - - if (priv->slice) - priv->bytes_left = vl_vlc_bits_left(&vlc) / 8; - - while (vl_vlc_bits_left (&vlc) > min_bits_left) { - vid_dec_h264_Decode(priv, &vlc, min_bits_left); - vl_vlc_fillbits(&vlc); - } - - if (priv->slice) { - unsigned bytes = priv->bytes_left - vl_vlc_bits_left(&vlc) / 8; - - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &priv->slice, &bytes); - - if (priv->num_in_buffers) - priv->slice = priv->inputs[1]; - else - priv->slice = NULL; - } - - if (priv->eos_ && priv->frame_started) - vid_dec_h264_EndFrame(priv); - - if (priv->frame_finished) { - priv->frame_finished = false; - h264d_manage_buffers(priv); - } else if (priv->eos_) { - vid_dec_FreeInputPortPrivate(priv->in_buffers[0]); - h264d_manage_buffers(priv); - } else { - priv->in_buffers[0]->nFilledLen = 0; - h264d_buffer_emptied(priv, priv->in_buffers[0]); - } - - if (priv->out_port_disabled_) { - /* In case out port is disabled, h264d_buffer_emptied will fail to release input port. - * We need to wait before shifting the buffers in that case and check in - * get_input_buffer when out port is enabled to release and shift the buffers. - * Infinite looping occurs if buffer is not released */ - if (priv->num_in_buffers == 2) { - /* Set the delta value for use in get_input_buffer before exiting */ - dec_frame_delta = MIN2((min_bits_left - vl_vlc_bits_left(&vlc)) / 8, priv->sizes[1]); - } - break; - } - - h264d_shift_buffers_left(priv); - } - - return OMX_ErrorNone; -} - -/* - * h264dprc - */ - -static void * h264d_prc_ctor(void *ap_obj, va_list * app) -{ - vid_dec_PrivateType*priv = super_ctor(typeOf (ap_obj, "h264dprc"), ap_obj, app); - assert(priv); - priv->p_inhdr_ = 0; - priv->p_outhdr_ = 0; - priv->first_buf_in_frame = true; - priv->eos_ = false; - priv->in_port_disabled_ = false; - priv->out_port_disabled_ = false; - priv->picture.base.profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - reset_stream_parameters(priv); - - return priv; -} - -static void * h264d_prc_dtor(void *ap_obj) -{ - return super_dtor(typeOf(ap_obj, "h264dprc"), ap_obj); -} - -static OMX_ERRORTYPE h264d_prc_allocate_resources(void *ap_obj, OMX_U32 a_pid) -{ - vid_dec_PrivateType*priv = ap_obj; - struct pipe_screen *screen; - vl_csc_matrix csc; - - assert (priv); - - priv->screen = omx_get_screen(); - if (!priv->screen) - return OMX_ErrorInsufficientResources; - - screen = priv->screen->pscreen; - priv->pipe = pipe_create_multimedia_context(screen); - if (!priv->pipe) - return OMX_ErrorInsufficientResources; - - if (!vl_compositor_init(&priv->compositor, priv->pipe)) { - priv->pipe->destroy(priv->pipe); - priv->pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - if (!vl_compositor_init_state(&priv->cstate, priv->pipe)) { - vl_compositor_cleanup(&priv->compositor); - priv->pipe->destroy(priv->pipe); - priv->pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601, NULL, true, &csc); - if (!vl_compositor_set_csc_matrix(&priv->cstate, (const vl_csc_matrix *)&csc, 1.0f, 0.0f)) { - vl_compositor_cleanup(&priv->compositor); - priv->pipe->destroy(priv->pipe); - priv->pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - list_inithead(&priv->codec_data.h264.dpb_list); - - priv->video_buffer_map = util_hash_table_create_ptr_keys(); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_deallocate_resources(void *ap_obj) -{ - vid_dec_PrivateType*priv = ap_obj; - assert(priv); - - /* Clear hash table */ - util_hash_table_foreach(priv->video_buffer_map, - &hash_table_clear_item_callback, - NULL); - _mesa_hash_table_destroy(priv->video_buffer_map, NULL); - - if (priv->pipe) { - vl_compositor_cleanup_state(&priv->cstate); - vl_compositor_cleanup(&priv->compositor); - priv->pipe->destroy(priv->pipe); - } - - if (priv->screen) - omx_put_screen(); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_prepare_to_transfer(void *ap_obj, OMX_U32 a_pid) -{ - vid_dec_PrivateType*priv = ap_obj; - assert(priv); - - TIZ_INIT_OMX_PORT_STRUCT(priv->out_port_def_, - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX); - tiz_check_omx( - tiz_api_GetParameter(tiz_get_krn(handleOf(priv)), handleOf(priv), - OMX_IndexParamPortDefinition, &(priv->out_port_def_))); - - priv->first_buf_in_frame = true; - priv->eos_ = false; - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_transfer_and_process(void *ap_obj, OMX_U32 a_pid) -{ - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_stop_and_return(void *ap_obj) -{ - vid_dec_PrivateType*priv = (vid_dec_PrivateType*) ap_obj; - return h264d_release_all_headers (priv); -} - -static OMX_ERRORTYPE h264d_prc_buffers_ready(const void *ap_obj) -{ - vid_dec_PrivateType*priv = (vid_dec_PrivateType*) ap_obj; - OMX_BUFFERHEADERTYPE *in_buf = NULL; - OMX_BUFFERHEADERTYPE *out_buf = NULL; - - assert(priv); - - /* Set parameters if start of stream */ - if (!priv->eos_ && priv->first_buf_in_frame && (in_buf = get_input_buffer(priv))) { - decode_frame(priv, in_buf); - } - - /* Don't get input buffer if output buffer not found */ - while (!priv->eos_ && (out_buf = get_output_buffer(priv)) && (in_buf = get_input_buffer(priv))) { - if (!priv->out_port_disabled_) { - decode_frame(priv, in_buf); - } - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_port_flush(const void *ap_obj, OMX_U32 a_pid) -{ - vid_dec_PrivateType*priv = (vid_dec_PrivateType*) ap_obj; - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_INPUT_PORT_INDEX == a_pid) { - release_input_headers(priv); - reset_stream_parameters(priv); - } - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX == a_pid) { - release_output_header(priv); - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_port_disable(const void *ap_obj, OMX_U32 a_pid) -{ - vid_dec_PrivateType*priv = (vid_dec_PrivateType*) ap_obj; - assert(priv); - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_INPUT_PORT_INDEX == a_pid) { - /* Release all buffers */ - h264d_release_all_headers(priv); - reset_stream_parameters(priv); - priv->in_port_disabled_ = true; - } - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX == a_pid) { - release_output_header(priv); - priv->out_port_disabled_ = true; - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264d_prc_port_enable(const void *ap_obj, OMX_U32 a_pid) -{ - vid_dec_PrivateType* priv = (vid_dec_PrivateType*) ap_obj; - assert(priv); - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_INPUT_PORT_INDEX == a_pid) { - if (priv->in_port_disabled_) { - reset_stream_parameters(priv); - priv->in_port_disabled_ = false; - } - } - if (OMX_ALL == a_pid || OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX == a_pid) { - priv->out_port_disabled_ = false; - } - return OMX_ErrorNone; -} - -/* - * h264d_prc_class - */ - -static void * h264d_prc_class_ctor(void *ap_obj, va_list * app) -{ - /* NOTE: Class methods might be added in the future. None for now. */ - return super_ctor(typeOf(ap_obj, "h264dprc_class"), ap_obj, app); -} - -/* - * initialization - */ - -void * h264d_prc_class_init(void * ap_tos, void * ap_hdl) -{ - void * tizprc = tiz_get_type(ap_hdl, "tizprc"); - void * h264dprc_class = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (classOf(tizprc), "h264dprc_class", classOf(tizprc), - sizeof(h264d_prc_class_t), - /* TIZ_CLASS_COMMENT: */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264d_prc_class_ctor, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - return h264dprc_class; -} - -void * h264d_prc_init(void * ap_tos, void * ap_hdl) -{ - void * tizprc = tiz_get_type(ap_hdl, "tizprc"); - void * h264dprc_class = tiz_get_type(ap_hdl, "h264dprc_class"); - TIZ_LOG_CLASS (h264dprc_class); - void * h264dprc = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (h264dprc_class, "h264dprc", tizprc, sizeof(vid_dec_PrivateType), - /* TIZ_CLASS_COMMENT: */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264d_prc_ctor, - /* TIZ_CLASS_COMMENT: class destructor */ - dtor, h264d_prc_dtor, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_allocate_resources, h264d_prc_allocate_resources, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_deallocate_resources, h264d_prc_deallocate_resources, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_prepare_to_transfer, h264d_prc_prepare_to_transfer, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_transfer_and_process, h264d_prc_transfer_and_process, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_stop_and_return, h264d_prc_stop_and_return, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_buffers_ready, h264d_prc_buffers_ready, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_flush, h264d_prc_port_flush, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_disable, h264d_prc_port_disable, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_enable, h264d_prc_port_enable, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - - return h264dprc; -} diff --git a/src/gallium/frontends/omx/tizonia/h264dprc.h b/src/gallium/frontends/omx/tizonia/h264dprc.h deleted file mode 100644 index 08af5491a3e..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264dprc.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264DPRC_H -#define H264DPRC_H - -void * h264d_prc_class_init(void * ap_tos, void * ap_hdl); -void * h264d_prc_init(void * ap_tos, void * ap_hdl); - -#endif /* H264DPRC_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264e.c b/src/gallium/frontends/omx/tizonia/h264e.c deleted file mode 100644 index 8ff4b14c53c..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264e.c +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include - -#include "h264eprc.h" -#include "h264e.h" -#include "names.h" -#include "vid_enc_common.h" - -static OMX_VERSIONTYPE h264e_encoder_version = {{0, 0, 0, 1}}; - -OMX_PTR instantiate_h264e_input_port(OMX_HANDLETYPE ap_hdl) -{ - OMX_VIDEO_PORTDEFINITIONTYPE portdef; - OMX_VIDEO_CODINGTYPE encodings[] = { - OMX_VIDEO_CodingUnused, - OMX_VIDEO_CodingMax - }; - OMX_COLOR_FORMATTYPE formats[] = { - OMX_COLOR_FormatYUV420SemiPlanar, - OMX_COLOR_FormatMax - }; - tiz_port_options_t rawvideo_port_opts = { - OMX_PortDomainVideo, - OMX_DirInput, - OMX_VID_ENC_AVC_INPUT_PORT_MIN_BUF_COUNT, - OMX_VID_ENC_AVC_PORT_MIN_INPUT_BUF_SIZE, - OMX_VID_ENC_AVC_PORT_NONCONTIGUOUS, - OMX_VID_ENC_AVC_PORT_ALIGNMENT, - OMX_VID_ENC_AVC_PORT_SUPPLIERPREF, - {OMX_VID_ENC_AVC_INPUT_PORT_INDEX, NULL, NULL, NULL}, - 1 /* Slave port */ - }; - - portdef.pNativeRender = NULL; - portdef.nFrameWidth = OMX_VID_ENC_AVC_DEFAULT_FRAME_WIDTH; - portdef.nFrameHeight = OMX_VID_ENC_AVC_DEFAULT_FRAME_HEIGHT; - portdef.nStride = 0; - portdef.nSliceHeight = 0; - portdef.nBitrate = 64000; - portdef.xFramerate = 15; - portdef.bFlagErrorConcealment = OMX_FALSE; - portdef.eCompressionFormat = OMX_VIDEO_CodingUnused; - portdef.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; - portdef.pNativeWindow = NULL; - - return factory_new(tiz_get_type(ap_hdl, "h264einport"), - &rawvideo_port_opts, &portdef, - &encodings, &formats); -} - -OMX_PTR instantiate_h264e_output_port(OMX_HANDLETYPE ap_hdl) -{ - OMX_VIDEO_PORTDEFINITIONTYPE portdef; - OMX_VIDEO_PARAM_AVCTYPE avctype; - OMX_VIDEO_PARAM_BITRATETYPE bitrate; - OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant; - - OMX_VIDEO_CODINGTYPE encodings[] = { - OMX_VIDEO_CodingAVC, - OMX_VIDEO_CodingMax - }; - OMX_COLOR_FORMATTYPE formats[] = { - OMX_COLOR_FormatUnused, - OMX_COLOR_FormatMax - }; - tiz_port_options_t avc_port_opts = { - OMX_PortDomainVideo, - OMX_DirOutput, - OMX_VID_ENC_AVC_OUTPUT_PORT_MIN_BUF_COUNT, - OMX_VID_ENC_AVC_PORT_MIN_OUTPUT_BUF_SIZE, - OMX_VID_ENC_AVC_PORT_NONCONTIGUOUS, - OMX_VID_ENC_AVC_PORT_ALIGNMENT, - OMX_VID_ENC_AVC_PORT_SUPPLIERPREF, - {OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX, NULL, NULL, NULL}, - 0 /* Master port */ - }; - OMX_VIDEO_AVCLEVELTYPE levels[] = { - OMX_VIDEO_AVCLevel51, - OMX_VIDEO_AVCLevel1, - OMX_VIDEO_AVCLevel1b, - OMX_VIDEO_AVCLevel11, - OMX_VIDEO_AVCLevel12, - OMX_VIDEO_AVCLevel13, - OMX_VIDEO_AVCLevel2, - OMX_VIDEO_AVCLevel21, - OMX_VIDEO_AVCLevel22, - OMX_VIDEO_AVCLevel3, - OMX_VIDEO_AVCLevel31, - OMX_VIDEO_AVCLevel32, - OMX_VIDEO_AVCLevel4, - OMX_VIDEO_AVCLevel41, - OMX_VIDEO_AVCLevel42, - OMX_VIDEO_AVCLevel5, - OMX_VIDEO_AVCLevelMax - }; - - /* Values set from as given in specification */ - portdef.pNativeRender = NULL; - portdef.nFrameWidth = OMX_VID_ENC_AVC_DEFAULT_FRAME_WIDTH; - portdef.nFrameHeight = OMX_VID_ENC_AVC_DEFAULT_FRAME_HEIGHT; - portdef.nStride = 0; - portdef.nSliceHeight = 0; - portdef.nBitrate = 64000; - portdef.xFramerate = 15; - portdef.bFlagErrorConcealment = OMX_FALSE; - portdef.eCompressionFormat = OMX_VIDEO_CodingAVC; - portdef.eColorFormat = OMX_COLOR_FormatUnused; - portdef.pNativeWindow = NULL; - - bitrate.eControlRate = OMX_Video_ControlRateDisable; - bitrate.nTargetBitrate = 0; - - quant.nQpI = OMX_VID_ENC_QUANT_I_FRAMES_DEFAULT; - quant.nQpP = OMX_VID_ENC_QUANT_P_FRAMES_DEFAULT; - quant.nQpB = OMX_VID_ENC_QUANT_B_FRAMES_DEFAULT; - - avctype.nSize = sizeof (OMX_VIDEO_PARAM_AVCTYPE); - avctype.nVersion.nVersion = OMX_VERSION; - avctype.nPortIndex = OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX; - avctype.eProfile = OMX_VIDEO_AVCProfileBaseline; - avctype.nSliceHeaderSpacing = 0; - avctype.nPFrames = 0; - avctype.nBFrames = 0; - avctype.bUseHadamard = OMX_TRUE; - avctype.nRefFrames = 1; - avctype.nRefIdx10ActiveMinus1 = 1; - avctype.nRefIdx11ActiveMinus1 = 0; - avctype.bEnableUEP = OMX_FALSE; - avctype.bEnableFMO = OMX_FALSE; - avctype.bEnableASO = OMX_FALSE; - avctype.bEnableRS = OMX_FALSE; - avctype.eLevel = OMX_VIDEO_AVCLevel51; - avctype.nAllowedPictureTypes = 2; - avctype.bFrameMBsOnly = OMX_FALSE; - avctype.bMBAFF = OMX_FALSE; - avctype.bEntropyCodingCABAC = OMX_FALSE; - avctype.bWeightedPPrediction = OMX_FALSE; - avctype.nWeightedBipredicitonMode = 0; - avctype.bconstIpred = OMX_FALSE; - avctype.bDirect8x8Inference = OMX_FALSE; - avctype.bDirectSpatialTemporal = OMX_FALSE; - avctype.nCabacInitIdc = 0; - avctype.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; - - return factory_new(tiz_get_type(ap_hdl, "h264eoutport"), - &avc_port_opts, &portdef, - &encodings, &formats, &avctype, &levels, - &bitrate, &quant); -} - -OMX_PTR instantiate_h264e_config_port(OMX_HANDLETYPE ap_hdl) -{ - return factory_new(tiz_get_type(ap_hdl, "tizconfigport"), - NULL, /* this port does not take options */ - OMX_VID_COMP_NAME, h264e_encoder_version); -} - -OMX_PTR instantiate_h264e_processor(OMX_HANDLETYPE ap_hdl) -{ - return factory_new(tiz_get_type(ap_hdl, "h264eprc")); -} diff --git a/src/gallium/frontends/omx/tizonia/h264e.h b/src/gallium/frontends/omx/tizonia/h264e.h deleted file mode 100644 index de8316c726d..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264e.h +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264E_H -#define H264E_H - -#include -#include -#include - -#define OMX_VID_ENC_AVC_ROLE "video_encoder.avc" - -/* With libtizonia, port indexes must start at index 0 */ -#define OMX_VID_ENC_AVC_INPUT_PORT_INDEX 0 -#define OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX 1 -#define OMX_VID_ENC_AVC_DEFAULT_FRAME_WIDTH 176 -#define OMX_VID_ENC_AVC_DEFAULT_FRAME_HEIGHT 144 -#define OMX_VID_ENC_AVC_INPUT_PORT_MIN_BUF_COUNT 8 -#define OMX_VID_ENC_AVC_OUTPUT_PORT_MIN_BUF_COUNT 2 -#define OMX_VID_ENC_AVC_PORT_MIN_INPUT_BUF_SIZE 4 * 1024 -#define OMX_VID_ENC_AVC_PORT_MIN_OUTPUT_BUF_SIZE 345600 -#define OMX_VID_ENC_AVC_PORT_NONCONTIGUOUS OMX_FALSE -#define OMX_VID_ENC_AVC_PORT_ALIGNMENT 0 -#define OMX_VID_ENC_AVC_PORT_SUPPLIERPREF OMX_BufferSupplyInput - -OMX_PTR instantiate_h264e_config_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264e_input_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264e_output_port(OMX_HANDLETYPE ap_hdl); -OMX_PTR instantiate_h264e_processor(OMX_HANDLETYPE ap_hdl); - -#endif /* H264E_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264einport.c b/src/gallium/frontends/omx/tizonia/h264einport.c deleted file mode 100644 index faf4609fedc..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264einport.c +++ /dev/null @@ -1,216 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#include -#include - -#include "vl/vl_winsys.h" - -#include "h264e.h" -#include "h264einport.h" -#include "h264einport_decls.h" -#include "vid_enc_common.h" - -static OMX_ERRORTYPE enc_AllocateBackTexture(OMX_HANDLETYPE ap_hdl, - OMX_U32 idx, - struct pipe_resource **resource, - struct pipe_transfer **transfer, - OMX_U8 **map) -{ - vid_enc_PrivateType * priv = tiz_get_prc(ap_hdl); - tiz_port_t * port = tiz_krn_get_port(tiz_get_krn(ap_hdl), idx); - struct pipe_resource buf_templ; - struct pipe_box box = {}; - OMX_U8 *ptr; - - memset(&buf_templ, 0, sizeof buf_templ); - buf_templ.target = PIPE_TEXTURE_2D; - buf_templ.format = PIPE_FORMAT_I8_UNORM; - buf_templ.bind = PIPE_BIND_LINEAR; - buf_templ.usage = PIPE_USAGE_STAGING; - buf_templ.flags = 0; - buf_templ.width0 = port->portdef_.format.video.nFrameWidth; - buf_templ.height0 = port->portdef_.format.video.nFrameHeight * 3 / 2; - buf_templ.depth0 = 1; - buf_templ.array_size = 1; - - *resource = priv->s_pipe->screen->resource_create(priv->s_pipe->screen, &buf_templ); - if (!*resource) - return OMX_ErrorInsufficientResources; - - box.width = (*resource)->width0; - box.height = (*resource)->height0; - box.depth = (*resource)->depth0; - ptr = priv->s_pipe->texture_map(priv->s_pipe, *resource, 0, PIPE_MAP_WRITE, &box, transfer); - if (map) - *map = ptr; - - return OMX_ErrorNone; -} - -/* - * h264einport class - */ - -static void * h264e_inport_ctor(void * ap_obj, va_list * app) -{ - return super_ctor(typeOf(ap_obj, "h264einport"), ap_obj, app); -} - -static void * h264e_inport_dtor(void * ap_obj) -{ - return super_dtor(typeOf(ap_obj, "h264einport"), ap_obj); -} - -/* - * from tiz_api - */ - -static OMX_ERRORTYPE h264e_inport_AllocateBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_BUFFERHEADERTYPE ** buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = super_UseBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, - buf, idx, private, size, NULL); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - r = enc_AllocateBackTexture(ap_hdl, idx, &inp->resource, &inp->transfer, &(*buf)->pBuffer); - - if (r) { - FREE(inp); - super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf); - return r; - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_inport_UseBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_BUFFERHEADERTYPE **buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size, OMX_U8 *mem) -{ - struct input_buf_private *inp; - OMX_ERRORTYPE r; - - r = super_UseBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, - buf, idx, private, size, mem); - if (r) - return r; - - inp = (*buf)->pInputPortPrivate = CALLOC_STRUCT(input_buf_private); - if (!inp) { - super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - list_inithead(&inp->tasks); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_inport_FreeBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf) -{ - vid_enc_PrivateType *priv = tiz_get_prc(ap_hdl); - struct input_buf_private *inp = buf->pInputPortPrivate; - - if (inp) { - enc_ReleaseTasks(&inp->tasks); - if (inp->transfer) - pipe_texture_unmap(priv->s_pipe, inp->transfer); - pipe_resource_reference(&inp->resource, NULL); - FREE(inp); - } - - return super_FreeBuffer(typeOf(ap_obj, "h264einport"), ap_obj, ap_hdl, idx, buf); -} - -/* - * h264einport_class - */ - -static void * h264e_inport_class_ctor(void * ap_obj, va_list * app) -{ - /* NOTE: Class methods might be added in the future. None for now. */ - return super_ctor (typeOf (ap_obj, "h264einport_class"), ap_obj, app); -} - -/* - * initialization - */ - -void * h264e_inport_class_init(void * ap_tos, void * ap_hdl) -{ - void * tizvideoport = tiz_get_type(ap_hdl, "tizvideoport"); - void * h264einport_class - = factory_new(classOf(tizvideoport), "h264einport_class", - classOf(tizvideoport), sizeof(h264e_inport_class_t), - ap_tos, ap_hdl, ctor, h264e_inport_class_ctor, 0); - return h264einport_class; -} - -void * h264e_inport_init(void * ap_tos, void * ap_hdl) -{ - void * tizvideoport = tiz_get_type (ap_hdl, "tizvideoport"); - void * h264einport_class = tiz_get_type (ap_hdl, "h264einport_class"); - void * h264einport = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (h264einport_class, "h264einport", tizvideoport, - sizeof (h264e_inport_t), - /* TIZ_CLASS_COMMENT: class constructor */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264e_inport_ctor, - /* TIZ_CLASS_COMMENT: class destructor */ - dtor, h264e_inport_dtor, - /* TIZ_CLASS_COMMENT: */ - tiz_api_AllocateBuffer, h264e_inport_AllocateBuffer, - /* TIZ_CLASS_COMMENT: */ - tiz_api_UseBuffer, h264e_inport_UseBuffer, - /* TIZ_CLASS_COMMENT: */ - tiz_api_FreeBuffer, h264e_inport_FreeBuffer, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - - return h264einport; -} diff --git a/src/gallium/frontends/omx/tizonia/h264einport.h b/src/gallium/frontends/omx/tizonia/h264einport.h deleted file mode 100644 index 3dd89061970..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264einport.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264EINPORT_H -#define H264EINPORT_H - -void * h264e_inport_class_init(void * ap_tos, void * ap_hdl); -void * h264e_inport_init(void * ap_tos, void * ap_hdl); - -#endif /* H264EINPORT_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264einport_decls.h b/src/gallium/frontends/omx/tizonia/h264einport_decls.h deleted file mode 100644 index 9efaf742b84..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264einport_decls.h +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264EINPORT_DECLS_H -#define H264EINPORT_DECLS_H - -#include -#include - -#include - -typedef struct h264e_inport h264e_inport_t; -struct h264e_inport -{ - /* Object */ - const tiz_videoport_t _; -}; - -typedef struct h264e_inport_class h264e_inport_class_t; -struct h264e_inport_class -{ - /* Class */ - const tiz_videoport_class_t _; - /* NOTE: Class methods might be added in the future */ -}; - -#endif /* H264EINPORT_DECLS_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264eoutport.c b/src/gallium/frontends/omx/tizonia/h264eoutport.c deleted file mode 100644 index 88bdace0768..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264eoutport.c +++ /dev/null @@ -1,143 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#include - -#include "vl/vl_winsys.h" - -#include "h264eoutport.h" -#include "h264eoutport_decls.h" -#include "vid_enc_common.h" - -/* - * h264eoutport class - */ - -static void * h264e_outport_ctor(void * ap_obj, va_list * app) -{ - return super_ctor(typeOf(ap_obj, "h264eoutport"), ap_obj, app); -} - -static void * h264e_outport_dtor(void * ap_obj) -{ - return super_dtor(typeOf(ap_obj, "h264eoutport"), ap_obj); -} - -/* - * from tiz_api - */ - -static OMX_ERRORTYPE h264e_outport_AllocateBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_BUFFERHEADERTYPE ** buf, OMX_U32 idx, - OMX_PTR private, OMX_U32 size) -{ - OMX_ERRORTYPE r; - - r = super_UseBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl, - buf, idx, private, size, NULL); - if (r) - return r; - - (*buf)->pBuffer = NULL; - (*buf)->pOutputPortPrivate = CALLOC(1, sizeof(struct output_buf_private)); - if (!(*buf)->pOutputPortPrivate) { - super_FreeBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl, idx, *buf); - return OMX_ErrorInsufficientResources; - } - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_outport_FreeBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl, - OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf) -{ - vid_enc_PrivateType *priv = tiz_get_prc(ap_hdl); - struct output_buf_private *outp = buf->pOutputPortPrivate; - - if (outp) { - if (outp->transfer) - pipe_buffer_unmap(priv->t_pipe, outp->transfer); - pipe_resource_reference(&outp->bitstream, NULL); - FREE(outp); - buf->pOutputPortPrivate = NULL; - } - buf->pBuffer = NULL; - - return super_FreeBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl, idx, buf); -} - -/* - * h264e_outport_class - */ - -static void * h264e_outport_class_ctor(void * ap_obj, va_list * app) -{ - /* NOTE: Class methods might be added in the future. None for now. */ - return super_ctor(typeOf(ap_obj, "h264eoutport_class"), ap_obj, app); -} - -/* - * initialization - */ - -void * h264e_outport_class_init(void * ap_tos, void * ap_hdl) -{ - void * tizavcport = tiz_get_type(ap_hdl, "tizavcport"); - void * h264eoutport_class - = factory_new (classOf(tizavcport), "h264eoutport_class", - classOf(tizavcport), sizeof(h264e_outport_class_t), - ap_tos, ap_hdl, ctor, h264e_outport_class_ctor, 0); - return h264eoutport_class; -} - -void * h264e_outport_init(void * ap_tos, void * ap_hdl) -{ - void * tizavcport = tiz_get_type(ap_hdl, "tizavcport"); - void * h264eoutport_class = tiz_get_type(ap_hdl, "h264eoutport_class"); - void * h264eoutport = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (h264eoutport_class, "h264eoutport", tizavcport, - sizeof(h264e_outport_t), - /* TIZ_CLASS_COMMENT: class constructor */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264e_outport_ctor, - /* TIZ_CLASS_COMMENT: class destructor */ - dtor, h264e_outport_dtor, - /* TIZ_CLASS_COMMENT: */ - tiz_api_AllocateBuffer, h264e_outport_AllocateBuffer, - /* TIZ_CLASS_COMMENT: */ - tiz_api_FreeBuffer, h264e_outport_FreeBuffer, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - - return h264eoutport; -} diff --git a/src/gallium/frontends/omx/tizonia/h264eoutport.h b/src/gallium/frontends/omx/tizonia/h264eoutport.h deleted file mode 100644 index afbf9fed3f7..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264eoutport.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264EOUTPORT_H -#define H264EOUTPORT_H - -void * h264e_outport_class_init(void * ap_tos, void * ap_hdl); -void * h264e_outport_init(void * ap_tos, void * ap_hdl); - -#endif /* H264EOUTPORT_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264eoutport_decls.h b/src/gallium/frontends/omx/tizonia/h264eoutport_decls.h deleted file mode 100644 index 28c9e06a0f7..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264eoutport_decls.h +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264EOUTPORT_DECLS_H -#define H264EOUTPORT_DECLS_H - -#include -#include - -#include - -typedef struct h264e_outport h264e_outport_t; -struct h264e_outport -{ - /* Object */ - const tiz_avcport_t _; -}; - -typedef struct h264e_outport_class h264e_outport_class_t; -struct h264e_outport_class -{ - /* Class */ - const tiz_avcport_class_t _; - /* NOTE: Class methods might be added in the future */ -}; - -#endif /* H264EOUTPORT_DECLS_H */ diff --git a/src/gallium/frontends/omx/tizonia/h264eprc.c b/src/gallium/frontends/omx/tizonia/h264eprc.c deleted file mode 100644 index 9ff4b71a266..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264eprc.c +++ /dev/null @@ -1,699 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#include "pipe/p_screen.h" -#include "pipe/p_video_codec.h" -#include "util/u_memory.h" - -#include "vl/vl_codec.h" - -#include "entrypoint.h" -#include "h264e.h" -#include "h264eprc.h" -#include "vid_omx_common.h" -#include "vid_enc_common.h" - -static OMX_ERRORTYPE init_port_structs(vid_enc_PrivateType * priv) { - const void * p_krn = NULL; - - assert(priv); - - /* Initialisation */ - TIZ_INIT_OMX_PORT_STRUCT(priv->in_port_def_, - OMX_VID_ENC_AVC_INPUT_PORT_INDEX); - TIZ_INIT_OMX_PORT_STRUCT(priv->out_port_def_, - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX); - TIZ_INIT_OMX_PORT_STRUCT(priv->bitrate, - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX); - TIZ_INIT_OMX_PORT_STRUCT(priv->quant, - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX); - TIZ_INIT_OMX_PORT_STRUCT(priv->profile_level, - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX); - - /* Get values */ - p_krn = tiz_get_krn(handleOf(priv)); - - tiz_check_omx( - tiz_api_GetParameter(p_krn, handleOf(priv), - OMX_IndexParamPortDefinition, &(priv->in_port_def_))); - tiz_check_omx( - tiz_api_GetParameter(p_krn, handleOf(priv), - OMX_IndexParamPortDefinition, &(priv->out_port_def_))); - tiz_check_omx( - tiz_api_GetParameter(p_krn, handleOf(priv), - OMX_IndexParamVideoBitrate, &(priv->bitrate))); - tiz_check_omx( - tiz_api_GetParameter(p_krn, handleOf(priv), - OMX_IndexParamVideoQuantization, &(priv->quant))); - tiz_check_omx( - tiz_api_GetParameter(p_krn, handleOf(priv), - OMX_IndexParamVideoProfileLevelCurrent, &(priv->profile_level))); - - return OMX_ErrorNone; -} - -static OMX_BUFFERHEADERTYPE * get_input_buffer(vid_enc_PrivateType * priv) { - assert(priv); - - if (priv->in_port_disabled_) { - return NULL; - } - - assert(!priv->p_inhdr_); /* encode_frame expects new buffers every time */ - - tiz_krn_claim_buffer(tiz_get_krn(handleOf(priv)), - OMX_VID_ENC_AVC_INPUT_PORT_INDEX, 0, - &priv->p_inhdr_); - return priv->p_inhdr_; -} - -static OMX_BUFFERHEADERTYPE * get_output_buffer(vid_enc_PrivateType * priv) { - assert(priv); - - if (priv->out_port_disabled_) { - return NULL; - } - - if (!priv->p_outhdr_) { - tiz_krn_claim_buffer(tiz_get_krn(handleOf(priv)), - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX, 0, - &priv->p_outhdr_); - } - return priv->p_outhdr_; -} - -static OMX_ERRORTYPE h264e_buffer_emptied(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE * p_hdr) -{ - OMX_ERRORTYPE r = OMX_ErrorNone; - - assert(priv); - assert(priv->p_inhdr_ == p_hdr); - - if (!priv->out_port_disabled_) { - p_hdr->nOffset = 0; - - if ((p_hdr->nFlags & OMX_BUFFERFLAG_EOS) != 0) { - priv->eos_ = true; - } - - r = tiz_krn_release_buffer(tiz_get_krn(handleOf(priv)), 0, p_hdr); - priv->p_inhdr_ = NULL; - } - - return r; -} - -static OMX_ERRORTYPE h264e_buffer_filled(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE * p_hdr) -{ - OMX_ERRORTYPE r = OMX_ErrorNone; - - assert(priv); - assert(priv->p_outhdr_ == p_hdr); - assert(p_hdr); - - if (!priv->in_port_disabled_) { - p_hdr->nOffset = 0; - - if (priv->eos_) { - /* EOS has been received and all the input data has been consumed - * already, so its time to propagate the EOS flag */ - priv->p_outhdr_->nFlags |= OMX_BUFFERFLAG_EOS; - } - - r = tiz_krn_release_buffer(tiz_get_krn(handleOf(priv)), - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX, - p_hdr); - priv->p_outhdr_ = NULL; - } - - return r; -} - - -static void release_input_header(vid_enc_PrivateType * priv) { - assert(!priv->in_port_disabled_); - if (priv->p_inhdr_) { - (void) tiz_krn_release_buffer(tiz_get_krn(handleOf(priv)), - OMX_VID_ENC_AVC_INPUT_PORT_INDEX, - priv->p_inhdr_); - } - priv->p_inhdr_ = NULL; -} - -static void release_output_header(vid_enc_PrivateType * priv) { - if (priv->p_outhdr_) { - assert(!priv->out_port_disabled_); - (void) tiz_krn_release_buffer(tiz_get_krn(handleOf(priv)), - OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX, - priv->p_outhdr_); - priv->p_outhdr_ = NULL; - } -} - -static OMX_ERRORTYPE h264e_release_all_headers(vid_enc_PrivateType * priv) -{ - assert(priv); - - release_input_header(priv); - release_output_header(priv); - - return OMX_ErrorNone; -} - -static void reset_stream_parameters(vid_enc_PrivateType * priv) -{ - assert(priv); - init_port_structs(priv); - priv->p_inhdr_ = 0; - priv->p_outhdr_ = 0; - priv->eos_ = false; -} - -/* Replacement for bellagio's omx_base_filter_BufferMgmtFunction */ -static OMX_ERRORTYPE h264e_manage_buffers(vid_enc_PrivateType* priv) { - OMX_BUFFERHEADERTYPE * in_buf = priv->p_inhdr_; - OMX_BUFFERHEADERTYPE * out_buf = priv->p_outhdr_; - OMX_ERRORTYPE r = OMX_ErrorNone; - - if (in_buf->nFilledLen > 0) { - vid_enc_BufferEncoded_common(priv, in_buf, out_buf); - } else { - in_buf->nFilledLen = 0; - } - - out_buf->nTimeStamp = in_buf->nTimeStamp; - - /* Release input buffer if possible */ - if (in_buf->nFilledLen == 0) { - r = h264e_buffer_emptied(priv, in_buf); - } - - /* Realase output buffer if filled or eos */ - if ((out_buf->nFilledLen != 0) || priv->eos_) { - r = h264e_buffer_filled(priv, out_buf); - } - - return r; -} - -static struct encode_task *enc_NeedTask(vid_enc_PrivateType * priv) -{ - OMX_VIDEO_PORTDEFINITIONTYPE *def = &priv->in_port_def_.format.video; - - return enc_NeedTask_common(priv, def); -} - -static void enc_ScaleInput(vid_enc_PrivateType * priv, struct pipe_video_buffer **vbuf, unsigned *size) -{ - OMX_VIDEO_PORTDEFINITIONTYPE *def = &priv->in_port_def_.format.video; - enc_ScaleInput_common(priv, def, vbuf, size); -} - -static void enc_HandleTask(vid_enc_PrivateType * priv, struct encode_task *task, - enum pipe_h2645_enc_picture_type picture_type) -{ - unsigned size = priv->out_port_def_.nBufferSize; - struct pipe_video_buffer *vbuf = task->buf; - struct pipe_h264_enc_picture_desc picture = {}; - - /* -------------- scale input image --------- */ - enc_ScaleInput(priv, &vbuf, &size); - priv->s_pipe->flush(priv->s_pipe, NULL, 0); - - /* -------------- allocate output buffer --------- */ - task->bitstream = pipe_buffer_create(priv->s_pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STAGING, /* map for read */ - size); - - picture.picture_type = picture_type; - picture.pic_order_cnt = task->pic_order_cnt; - if (priv->restricted_b_frames && picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) - picture.not_referenced = true; - enc_ControlPicture_common(priv, &picture); - - /* -------------- encode frame --------- */ - priv->codec->begin_frame(priv->codec, vbuf, &picture.base); - priv->codec->encode_bitstream(priv->codec, vbuf, task->bitstream, &task->feedback); - priv->codec->end_frame(priv->codec, vbuf, &picture.base); -} - -static void enc_ClearBframes(vid_enc_PrivateType * priv, struct input_buf_private *inp) -{ - struct encode_task *task; - - if (list_is_empty(&priv->b_frames)) - return; - - task = list_entry(priv->b_frames.prev, struct encode_task, list); - list_del(&task->list); - - /* promote last from to P frame */ - priv->ref_idx_l0 = priv->ref_idx_l1; - enc_HandleTask(priv, task, PIPE_H2645_ENC_PICTURE_TYPE_P); - list_addtail(&task->list, &inp->tasks); - priv->ref_idx_l1 = priv->frame_num++; - - /* handle B frames */ - LIST_FOR_EACH_ENTRY(task, &priv->b_frames, list) { - enc_HandleTask(priv, task, PIPE_H2645_ENC_PICTURE_TYPE_B); - if (!priv->restricted_b_frames) - priv->ref_idx_l0 = priv->frame_num; - priv->frame_num++; - } - - enc_MoveTasks(&priv->b_frames, &inp->tasks); -} - -static OMX_ERRORTYPE enc_LoadImage(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE *buf, - struct pipe_video_buffer *vbuf) -{ - OMX_VIDEO_PORTDEFINITIONTYPE *def = &priv->in_port_def_.format.video; - return enc_LoadImage_common(priv, def, buf, vbuf); -} - -static OMX_ERRORTYPE encode_frame(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE * in_buf) -{ - struct input_buf_private *inp = in_buf->pInputPortPrivate; - enum pipe_h2645_enc_picture_type picture_type; - struct encode_task *task; - unsigned stacked_num = 0; - OMX_ERRORTYPE err; - - enc_MoveTasks(&inp->tasks, &priv->free_tasks); - task = enc_NeedTask(priv); - if (!task) - return OMX_ErrorInsufficientResources; - - /* EOS */ - if (in_buf->nFilledLen == 0) { - if (in_buf->nFlags & OMX_BUFFERFLAG_EOS) { - in_buf->nFilledLen = in_buf->nAllocLen; - enc_ClearBframes(priv, inp); - enc_MoveTasks(&priv->stacked_tasks, &inp->tasks); - priv->codec->flush(priv->codec); - } - return h264e_manage_buffers(priv); - } - - if (in_buf->pOutputPortPrivate) { - struct pipe_video_buffer *vbuf = in_buf->pOutputPortPrivate; - in_buf->pOutputPortPrivate = task->buf; - task->buf = vbuf; - } else { - /* ------- load input image into video buffer ---- */ - err = enc_LoadImage(priv, in_buf, task->buf); - if (err != OMX_ErrorNone) { - FREE(task); - return err; - } - } - - /* -------------- determine picture type --------- */ - if (!(priv->pic_order_cnt % OMX_VID_ENC_IDR_PERIOD_DEFAULT) || - priv->force_pic_type.IntraRefreshVOP) { - enc_ClearBframes(priv, inp); - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_IDR; - priv->force_pic_type.IntraRefreshVOP = OMX_FALSE; - priv->frame_num = 0; - } else if (priv->codec->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE || - !(priv->pic_order_cnt % OMX_VID_ENC_P_PERIOD_DEFAULT) || - (in_buf->nFlags & OMX_BUFFERFLAG_EOS)) { - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_P; - } else { - picture_type = PIPE_H2645_ENC_PICTURE_TYPE_B; - } - - task->pic_order_cnt = priv->pic_order_cnt++; - - if (picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) { - /* put frame at the tail of the queue */ - list_addtail(&task->list, &priv->b_frames); - } else { - /* handle I or P frame */ - priv->ref_idx_l0 = priv->ref_idx_l1; - enc_HandleTask(priv, task, picture_type); - list_addtail(&task->list, &priv->stacked_tasks); - LIST_FOR_EACH_ENTRY(task, &priv->stacked_tasks, list) { - ++stacked_num; - } - if (stacked_num == priv->stacked_frames_num) { - struct encode_task *t; - t = list_entry(priv->stacked_tasks.next, struct encode_task, list); - list_del(&t->list); - list_addtail(&t->list, &inp->tasks); - } - priv->ref_idx_l1 = priv->frame_num++; - - /* handle B frames */ - LIST_FOR_EACH_ENTRY(task, &priv->b_frames, list) { - enc_HandleTask(priv, task, PIPE_H2645_ENC_PICTURE_TYPE_B); - if (!priv->restricted_b_frames) - priv->ref_idx_l0 = priv->frame_num; - priv->frame_num++; - } - - enc_MoveTasks(&priv->b_frames, &inp->tasks); - } - - if (list_is_empty(&inp->tasks)) { - return h264e_buffer_emptied(priv, in_buf); - } else { - return h264e_manage_buffers(priv); - } -} - -static OMX_ERRORTYPE h264e_prc_create_encoder(void *ap_obj) -{ - vid_enc_PrivateType *priv = ap_obj; - struct pipe_screen *screen; - - priv->screen = omx_get_screen(); - if (!priv->screen) - return OMX_ErrorInsufficientResources; - - screen = priv->screen->pscreen; - if (!vl_codec_supported(screen, PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH, true)) - return OMX_ErrorBadParameter; - - priv->s_pipe = pipe_create_multimedia_context(screen); - if (!priv->s_pipe) - return OMX_ErrorInsufficientResources; - - enc_InitCompute_common(priv); - - if (!vl_compositor_init(&priv->compositor, priv->s_pipe)) { - priv->s_pipe->destroy(priv->s_pipe); - priv->s_pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - if (!vl_compositor_init_state(&priv->cstate, priv->s_pipe)) { - vl_compositor_cleanup(&priv->compositor); - priv->s_pipe->destroy(priv->s_pipe); - priv->s_pipe = NULL; - return OMX_ErrorInsufficientResources; - } - - priv->t_pipe = pipe_create_multimedia_context(screen); - if (!priv->t_pipe) - return OMX_ErrorInsufficientResources; - - list_inithead(&priv->free_tasks); - list_inithead(&priv->used_tasks); - list_inithead(&priv->b_frames); - list_inithead(&priv->stacked_tasks); - - return OMX_ErrorNone; -} - -static void h264e_prc_destroy_encoder(void *ap_obj) -{ - vid_enc_PrivateType *priv = ap_obj; - int i; - - assert (priv); - - enc_ReleaseTasks(&priv->free_tasks); - enc_ReleaseTasks(&priv->used_tasks); - enc_ReleaseTasks(&priv->b_frames); - enc_ReleaseTasks(&priv->stacked_tasks); - - for (i = 0; i < OMX_VID_ENC_NUM_SCALING_BUFFERS; ++i) - if (priv->scale_buffer[i]) - priv->scale_buffer[i]->destroy(priv->scale_buffer[i]); - - if (priv->s_pipe) { - vl_compositor_cleanup_state(&priv->cstate); - vl_compositor_cleanup(&priv->compositor); - enc_ReleaseCompute_common(priv); - priv->s_pipe->destroy(priv->s_pipe); - } - - if (priv->t_pipe) - priv->t_pipe->destroy(priv->t_pipe); - - if (priv->screen) - omx_put_screen(); -} - -/* - * h264eprc - */ - -static void * h264e_prc_ctor(void *ap_obj, va_list * app) -{ - vid_enc_PrivateType *priv = super_ctor(typeOf(ap_obj, "h264eprc"), ap_obj, app); - assert (priv); - - if (h264e_prc_create_encoder(ap_obj) != OMX_ErrorNone) - return priv; - - priv->p_inhdr_ = 0; - priv->p_outhdr_ = 0; - priv->profile_level.eProfile = OMX_VIDEO_AVCProfileBaseline; - priv->profile_level.eLevel = OMX_VIDEO_AVCLevel51; - priv->force_pic_type.IntraRefreshVOP = OMX_FALSE; - priv->frame_num = 0; - priv->pic_order_cnt = 0; - priv->restricted_b_frames = debug_get_bool_option("OMX_USE_RESTRICTED_B_FRAMES", false); - priv->scale.xWidth = OMX_VID_ENC_SCALING_WIDTH_DEFAULT; - priv->scale.xHeight = OMX_VID_ENC_SCALING_WIDTH_DEFAULT; - priv->in_port_disabled_ = false; - priv->out_port_disabled_ = false; - reset_stream_parameters(priv); - - return priv; -} - -static void * h264e_prc_dtor(void *ap_obj) -{ - h264e_prc_destroy_encoder(ap_obj); - return super_dtor(typeOf(ap_obj, "h264eprc"), ap_obj); -} - -static OMX_ERRORTYPE h264e_prc_allocate_resources(void *ap_obj, OMX_U32 a_pid) -{ - vid_enc_PrivateType *priv = ap_obj; - - assert(priv); - if (!priv->screen) - return OMX_ErrorInsufficientResources; - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_deallocate_resources(void *ap_obj) -{ - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_prepare_to_transfer(void *ap_obj, OMX_U32 a_pid) -{ - vid_enc_PrivateType *priv = ap_obj; - - assert(priv); - - init_port_structs(priv); - - priv->eos_ = false; - - struct pipe_video_codec templat = {}; - - templat.profile = enc_TranslateOMXProfileToPipe(priv->profile_level.eProfile); - templat.level = enc_TranslateOMXLevelToPipe(priv->profile_level.eLevel); - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.width = priv->scale_buffer[priv->current_scale_buffer] ? - priv->scale.xWidth : priv->in_port_def_.format.video.nFrameWidth; - templat.height = priv->scale_buffer[priv->current_scale_buffer] ? - priv->scale.xHeight : priv->in_port_def_.format.video.nFrameHeight; - - if (templat.profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE) { - struct pipe_screen *screen = priv->screen->pscreen; - templat.max_references = 1; - priv->stacked_frames_num = - screen->get_video_param(screen, - PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH, - PIPE_VIDEO_ENTRYPOINT_ENCODE, - PIPE_VIDEO_CAP_STACKED_FRAMES); - } else { - templat.max_references = OMX_VID_ENC_P_PERIOD_DEFAULT; - priv->stacked_frames_num = 1; - } - priv->codec = priv->s_pipe->create_video_codec(priv->s_pipe, &templat); - - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_transfer_and_process(void *ap_obj, OMX_U32 a_pid) -{ - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_stop_and_return(void *ap_obj) -{ - vid_enc_PrivateType *priv = (vid_enc_PrivateType *) ap_obj; - return h264e_release_all_headers(priv); -} - -static OMX_ERRORTYPE h264e_prc_buffers_ready(const void *ap_obj) -{ - vid_enc_PrivateType *priv = (vid_enc_PrivateType *) ap_obj; - OMX_BUFFERHEADERTYPE *in_buf = NULL; - OMX_BUFFERHEADERTYPE *out_buf = NULL; - OMX_ERRORTYPE r = OMX_ErrorNone; - - assert(priv); - - /* Don't get input buffer if output buffer not found */ - while (!priv->eos_ && (out_buf = get_output_buffer(priv)) && (in_buf = get_input_buffer(priv))) { - if (!priv->out_port_disabled_) { - r = encode_frame(priv, in_buf); - } - } - - return r; -} - -static OMX_ERRORTYPE h264e_prc_port_flush(const void *ap_obj, OMX_U32 a_pid) -{ - vid_enc_PrivateType *priv = (vid_enc_PrivateType *) ap_obj; - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_INPUT_PORT_INDEX == a_pid) { - release_input_header(priv); - reset_stream_parameters(priv); - } - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX == a_pid) { - release_output_header(priv); - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_port_disable(const void *ap_obj, OMX_U32 a_pid) -{ - vid_enc_PrivateType *priv = (vid_enc_PrivateType *) ap_obj; - assert(priv); - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_INPUT_PORT_INDEX == a_pid) { - /* Release all buffers */ - h264e_release_all_headers(priv); - reset_stream_parameters(priv); - priv->in_port_disabled_ = true; - } - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX == a_pid) { - release_output_header(priv); - priv->out_port_disabled_ = true; - } - return OMX_ErrorNone; -} - -static OMX_ERRORTYPE h264e_prc_port_enable(const void *ap_obj, OMX_U32 a_pid) -{ - vid_enc_PrivateType * priv = (vid_enc_PrivateType *) ap_obj; - assert(priv); - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_INPUT_PORT_INDEX == a_pid) { - if (priv->in_port_disabled_) { - reset_stream_parameters(priv); - priv->in_port_disabled_ = false; - } - } - if (OMX_ALL == a_pid || OMX_VID_ENC_AVC_OUTPUT_PORT_INDEX == a_pid) { - priv->out_port_disabled_ = false; - } - return OMX_ErrorNone; -} - -/* - * h264e_prc_class - */ - -static void * h264e_prc_class_ctor(void *ap_obj, va_list * app) -{ - /* NOTE: Class methods might be added in the future. None for now. */ - return super_ctor(typeOf(ap_obj, "h264eprc_class"), ap_obj, app); -} - -/* - * initialization - */ - -void * h264e_prc_class_init(void * ap_tos, void * ap_hdl) -{ - void * tizprc = tiz_get_type(ap_hdl, "tizprc"); - void * h264eprc_class = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (classOf(tizprc), "h264eprc_class", classOf(tizprc), - sizeof(h264e_prc_class_t), - /* TIZ_CLASS_COMMENT: */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264e_prc_class_ctor, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - return h264eprc_class; -} - -void * h264e_prc_init(void * ap_tos, void * ap_hdl) -{ - void * tizprc = tiz_get_type(ap_hdl, "tizprc"); - void * h264eprc_class = tiz_get_type(ap_hdl, "h264eprc_class"); - TIZ_LOG_CLASS (h264eprc_class); - void * h264eprc = factory_new - /* TIZ_CLASS_COMMENT: class type, class name, parent, size */ - (h264eprc_class, "h264eprc", tizprc, sizeof(vid_enc_PrivateType), - /* TIZ_CLASS_COMMENT: */ - ap_tos, ap_hdl, - /* TIZ_CLASS_COMMENT: class constructor */ - ctor, h264e_prc_ctor, - /* TIZ_CLASS_COMMENT: class destructor */ - dtor, h264e_prc_dtor, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_allocate_resources, h264e_prc_allocate_resources, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_deallocate_resources, h264e_prc_deallocate_resources, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_prepare_to_transfer, h264e_prc_prepare_to_transfer, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_transfer_and_process, h264e_prc_transfer_and_process, - /* TIZ_CLASS_COMMENT: */ - tiz_srv_stop_and_return, h264e_prc_stop_and_return, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_buffers_ready, h264e_prc_buffers_ready, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_flush, h264e_prc_port_flush, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_disable, h264e_prc_port_disable, - /* TIZ_CLASS_COMMENT: */ - tiz_prc_port_enable, h264e_prc_port_enable, - /* TIZ_CLASS_COMMENT: stop value*/ - 0); - - return h264eprc; -} diff --git a/src/gallium/frontends/omx/tizonia/h264eprc.h b/src/gallium/frontends/omx/tizonia/h264eprc.h deleted file mode 100644 index c5bc151a825..00000000000 --- a/src/gallium/frontends/omx/tizonia/h264eprc.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef H264EPRC_H -#define H264EPRC_H - -void * h264e_prc_class_init(void * ap_tos, void * ap_hdl); -void * h264e_prc_init(void * ap_tos, void * ap_hdl); - -#endif /* H264EPRC_H */ diff --git a/src/gallium/frontends/omx/tizonia/names.h b/src/gallium/frontends/omx/tizonia/names.h deleted file mode 100644 index edde7df396a..00000000000 --- a/src/gallium/frontends/omx/tizonia/names.h +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************** - * - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef OMX_TIZ_NAMES_H -#define OMX_TIZ_NAMES_H - -#define OMX_VID_COMP_NAME "OMX.mesa.video.all" - -#endif diff --git a/src/gallium/frontends/omx/vid_dec_common.c b/src/gallium/frontends/omx/vid_dec_common.c deleted file mode 100644 index de5a8fd7f37..00000000000 --- a/src/gallium/frontends/omx/vid_dec_common.c +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#if ENABLE_ST_OMX_TIZONIA -#include -#endif - -#include "util/u_memory.h" -#include "vl/vl_winsys.h" -#include "vl/vl_video_buffer.h" -#include "util/u_surface.h" - -#include "vid_dec_common.h" -#include "vid_dec_h264_common.h" - -void vid_dec_NeedTarget(vid_dec_PrivateType *priv) -{ - struct pipe_video_buffer templat = {}; - struct vl_screen *omx_screen; - struct pipe_screen *pscreen; - - omx_screen = priv->screen; - assert(omx_screen); - - pscreen = omx_screen->pscreen; - assert(pscreen); - - if (!priv->target) { - memset(&templat, 0, sizeof(templat)); - - templat.width = priv->codec->width; - templat.height = priv->codec->height; - templat.buffer_format = pscreen->get_video_param( - pscreen, - priv->profile, - PIPE_VIDEO_ENTRYPOINT_BITSTREAM, - PIPE_VIDEO_CAP_PREFERED_FORMAT - ); - templat.interlaced = pscreen->get_video_param( - pscreen, - priv->profile, - PIPE_VIDEO_ENTRYPOINT_BITSTREAM, - PIPE_VIDEO_CAP_PREFERS_INTERLACED - ); - - priv->target = priv->pipe->create_video_buffer(priv->pipe, &templat); - } -} - -void vid_dec_FillOutput(vid_dec_PrivateType *priv, struct pipe_video_buffer *buf, - OMX_BUFFERHEADERTYPE* output) -{ -#if ENABLE_ST_OMX_TIZONIA - tiz_port_t *out_port = tiz_krn_get_port(tiz_get_krn(handleOf(priv)), - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX); - OMX_VIDEO_PORTDEFINITIONTYPE *def = &out_port->portdef_.format.video; -#else - omx_base_PortType *port = priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]; - OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video; -#endif - - struct pipe_sampler_view **views; - unsigned i, j; - unsigned width, height; - - views = buf->get_sampler_view_planes(buf); - -#if ENABLE_ST_OMX_TIZONIA - if (!output->pBuffer) { - struct pipe_video_buffer *dst_buf = NULL; - struct pipe_surface **dst_surface = NULL; - struct u_rect src_rect; - struct u_rect dst_rect; - struct vl_compositor *compositor = &priv->compositor; - struct vl_compositor_state *s = &priv->cstate; - enum vl_compositor_deinterlace deinterlace = VL_COMPOSITOR_WEAVE; - - dst_buf = util_hash_table_get(priv->video_buffer_map, output); - assert(dst_buf); - - dst_surface = dst_buf->get_surfaces(dst_buf); - assert(views); - - src_rect.x0 = 0; - src_rect.y0 = 0; - src_rect.x1 = def->nFrameWidth; - src_rect.y1 = def->nFrameHeight; - - dst_rect.x0 = 0; - dst_rect.y0 = 0; - dst_rect.x1 = def->nFrameWidth; - dst_rect.y1 = def->nFrameHeight; - - vl_compositor_clear_layers(s); - vl_compositor_set_buffer_layer(s, compositor, 0, buf, - &src_rect, NULL, deinterlace); - vl_compositor_set_layer_dst_area(s, 0, &dst_rect); - vl_compositor_render(s, compositor, dst_surface[0], NULL, false); - - priv->pipe->flush(priv->pipe, NULL, 0); - - return; - } -#endif - - for (i = 0; i < 2 /* NV12 */; i++) { - if (!views[i]) continue; - width = def->nFrameWidth; - height = def->nFrameHeight; - vl_video_buffer_adjust_size(&width, &height, i, - pipe_format_to_chroma_format(buf->buffer_format), - buf->interlaced); - for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box; - u_box_3d(0, 0, j, width, height, 1, &box); - struct pipe_transfer *transfer; - uint8_t *map, *dst; - map = priv->pipe->texture_map(priv->pipe, views[i]->texture, 0, - PIPE_MAP_READ, &box, &transfer); - if (!map) - return; - - dst = ((uint8_t*)output->pBuffer + output->nOffset) + j * def->nStride + - i * def->nFrameWidth * def->nFrameHeight; - util_copy_rect(dst, - views[i]->texture->format, - def->nStride * views[i]->texture->array_size, 0, 0, - box.width, box.height, map, transfer->stride, 0, 0); - - pipe_texture_unmap(priv->pipe, transfer); - } - } -} diff --git a/src/gallium/frontends/omx/vid_dec_common.h b/src/gallium/frontends/omx/vid_dec_common.h deleted file mode 100644 index 8077a2c9e97..00000000000 --- a/src/gallium/frontends/omx/vid_dec_common.h +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef VID_DEC_COMMON_H -#define VID_DEC_COMMON_H - -#include "util/list.h" -#include "util/vl_rbsp.h" - -#include "vl/vl_compositor.h" -#include "vl/vl_zscan.h" - -#include "bellagio/vid_dec_av1.h" - -#include -#include - -#if ENABLE_ST_OMX_BELLAGIO - -#include -#include -#include - -DERIVEDCLASS(vid_dec_PrivateType, omx_base_filter_PrivateType) -#define vid_dec_PrivateType_FIELDS omx_base_filter_PrivateType_FIELDS \ - enum pipe_video_profile profile; \ - struct vl_screen *screen; \ - struct pipe_context *pipe; \ - struct pipe_video_codec *codec; \ - void (*Decode)(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left); \ - void (*EndFrame)(vid_dec_PrivateType *priv); \ - struct pipe_video_buffer *(*Flush)(vid_dec_PrivateType *priv, OMX_TICKS *timestamp); \ - struct pipe_video_buffer *target, *shadow; \ - union { \ - struct { \ - uint8_t intra_matrix[64]; \ - uint8_t non_intra_matrix[64]; \ - } mpeg12; \ - struct { \ - unsigned nal_ref_idc; \ - bool IdrPicFlag; \ - unsigned idr_pic_id; \ - unsigned pic_order_cnt_lsb; \ - unsigned pic_order_cnt_msb; \ - unsigned delta_pic_order_cnt_bottom; \ - unsigned delta_pic_order_cnt[2]; \ - unsigned prevFrameNumOffset; \ - struct pipe_h264_sps sps[32]; \ - struct pipe_h264_pps pps[256]; \ - struct list_head dpb_list; \ - unsigned dpb_num; \ - } h264; \ - struct { \ - unsigned temporal_id; \ - unsigned level_idc; \ - unsigned pic_width_in_luma_samples; \ - unsigned pic_height_in_luma_samples; \ - bool IdrPicFlag; \ - int slice_prev_poc; \ - void *ref_pic_set_list; \ - void *rps; \ - struct pipe_h265_sps sps[16]; \ - struct pipe_h265_pps pps[64]; \ - struct list_head dpb_list; \ - unsigned dpb_num; \ - } h265; \ - struct dec_av1 av1; \ - } codec_data; \ - union { \ - struct pipe_picture_desc base; \ - struct pipe_mpeg12_picture_desc mpeg12; \ - struct pipe_h264_picture_desc h264; \ - struct pipe_h265_picture_desc h265; \ - struct pipe_av1_picture_desc av1; \ - } picture; \ - unsigned num_in_buffers; \ - OMX_BUFFERHEADERTYPE *in_buffers[2]; \ - const void *inputs[2]; \ - unsigned sizes[2]; \ - OMX_TICKS timestamps[2]; \ - OMX_TICKS timestamp; \ - bool first_buf_in_frame; \ - bool frame_finished; \ - bool frame_started; \ - unsigned bytes_left; \ - const void *slice; \ - bool disable_tunnel; \ - struct vl_compositor compositor; \ - struct vl_compositor_state cstate; -ENDCLASS(vid_dec_PrivateType) - -#else - -#include -#include - -#include "util/list.h" -#include "util/u_hash_table.h" - -#include "pipe/p_video_state.h" - -typedef struct h264d_prc_class h264d_prc_class_t; -struct h264d_prc_class -{ - /* Class */ - const tiz_prc_class_t _; - /* NOTE: Class methods might be added in the future */ -}; - -typedef struct h264d_stream_info h264d_stream_info_t; -struct h264d_stream_info -{ - unsigned int width; - unsigned int height; -}; - -typedef struct h264d_prc vid_dec_PrivateType; -struct h264d_prc -{ - /* Object */ - const tiz_prc_t _; - OMX_BUFFERHEADERTYPE *in_buffers[2]; - OMX_BUFFERHEADERTYPE *p_inhdr_; - OMX_BUFFERHEADERTYPE *p_outhdr_; - OMX_PARAM_PORTDEFINITIONTYPE out_port_def_; - const void *inputs[2]; - unsigned sizes[2]; - OMX_TICKS timestamps[2]; - OMX_TICKS timestamp; - bool eos_; - bool in_port_disabled_; - bool out_port_disabled_; - struct vl_screen *screen; - struct pipe_context *pipe; - struct pipe_video_codec *codec; - struct pipe_video_buffer *target; - enum pipe_video_profile profile; - struct hash_table *video_buffer_map; - union { - struct { - unsigned nal_ref_idc; - bool IdrPicFlag; - unsigned idr_pic_id; - unsigned pic_order_cnt_lsb; - unsigned pic_order_cnt_msb; - unsigned delta_pic_order_cnt_bottom; - unsigned delta_pic_order_cnt[2]; - unsigned prevFrameNumOffset; - struct pipe_h264_sps sps[32]; - struct pipe_h264_pps pps[256]; - struct list_head dpb_list; - unsigned dpb_num; - } h264; - } codec_data; - union { - struct pipe_picture_desc base; - struct pipe_h264_picture_desc h264; - } picture; - h264d_stream_info_t stream_info; - unsigned num_in_buffers; - bool first_buf_in_frame; - bool frame_finished; - bool frame_started; - unsigned bytes_left; - const void *slice; - bool disable_tunnel; - struct vl_compositor compositor; - struct vl_compositor_state cstate; - bool use_eglimage; -}; - -#endif - -void vid_dec_NeedTarget(vid_dec_PrivateType* priv); -void vid_dec_FillOutput(vid_dec_PrivateType* priv, struct pipe_video_buffer* buf, - OMX_BUFFERHEADERTYPE* output); -#endif diff --git a/src/gallium/frontends/omx/vid_dec_h264_common.c b/src/gallium/frontends/omx/vid_dec_h264_common.c deleted file mode 100644 index fcf5c99d644..00000000000 --- a/src/gallium/frontends/omx/vid_dec_h264_common.c +++ /dev/null @@ -1,1137 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#if ENABLE_ST_OMX_TIZONIA -#include -#endif - -#include "util/u_memory.h" - -#include "vid_dec_h264_common.h" - -static void vid_dec_h264_BeginFrame(vid_dec_PrivateType *priv) -{ - //TODO: sane buffer handling - - if (priv->frame_started) - return; - - if (!priv->codec) { - struct pipe_video_codec templat = {}; - templat.profile = priv->profile; - templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; - templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420; - templat.max_references = priv->picture.h264.num_ref_frames; - templat.expect_chunked_decode = false; -#if ENABLE_ST_OMX_BELLAGIO - omx_base_video_PortType *port; - port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; - templat.width = port->sPortParam.format.video.nFrameWidth; - templat.height = port->sPortParam.format.video.nFrameHeight; -#else - templat.width = priv->out_port_def_.format.video.nFrameWidth; - templat.height = priv->out_port_def_.format.video.nFrameHeight; -#endif - templat.level = priv->picture.h264.pps->sps->level_idc; - - priv->codec = priv->pipe->create_video_codec(priv->pipe, &templat); - } - - vid_dec_NeedTarget(priv); - - if (priv->first_buf_in_frame) - priv->timestamp = priv->timestamps[0]; - priv->first_buf_in_frame = false; - - priv->picture.h264.num_ref_frames = priv->picture.h264.pps->sps->max_num_ref_frames; - - priv->picture.h264.slice_count = 0; - priv->codec->begin_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = true; -} - -struct pipe_video_buffer *vid_dec_h264_Flush(vid_dec_PrivateType *priv, - OMX_TICKS *timestamp) -{ - struct dpb_list *entry, *result = NULL; - struct pipe_video_buffer *buf; - - /* search for the lowest poc and break on zeros */ - LIST_FOR_EACH_ENTRY(entry, &priv->codec_data.h264.dpb_list, list) { - - if (result && entry->poc == 0) - break; - - if (!result || entry->poc < result->poc) - result = entry; - } - - if (!result) - return NULL; - - buf = result->buffer; - if (timestamp) - *timestamp = result->timestamp; - - --priv->codec_data.h264.dpb_num; - list_del(&result->list); - FREE(result); - - return buf; -} - -void vid_dec_h264_EndFrame(vid_dec_PrivateType *priv) -{ - struct dpb_list *entry; - struct pipe_video_buffer *tmp; - bool top_field_first; - OMX_TICKS timestamp = 0; - - if (!priv->frame_started) - return; - - priv->codec->end_frame(priv->codec, priv->target, &priv->picture.base); - priv->frame_started = false; - - // TODO: implement frame number handling - priv->picture.h264.frame_num_list[0] = priv->picture.h264.frame_num; - priv->picture.h264.field_order_cnt_list[0][0] = priv->picture.h264.frame_num; - priv->picture.h264.field_order_cnt_list[0][1] = priv->picture.h264.frame_num; - - top_field_first = priv->picture.h264.field_order_cnt[0] < priv->picture.h264.field_order_cnt[1]; - - if (priv->picture.h264.field_pic_flag && priv->picture.h264.bottom_field_flag != top_field_first) - return; - - /* add the decoded picture to the dpb list */ - entry = CALLOC_STRUCT(dpb_list); - if (!entry) - return; - - priv->first_buf_in_frame = true; - entry->buffer = priv->target; - entry->timestamp = priv->timestamp; - entry->poc = MIN2(priv->picture.h264.field_order_cnt[0], priv->picture.h264.field_order_cnt[1]); - list_addtail(&entry->list, &priv->codec_data.h264.dpb_list); - ++priv->codec_data.h264.dpb_num; - priv->target = NULL; - priv->picture.h264.field_order_cnt[0] = priv->picture.h264.field_order_cnt[1] = INT_MAX; - - if (priv->codec_data.h264.dpb_num <= DPB_MAX_SIZE) - return; - - tmp = priv->in_buffers[0]->pInputPortPrivate; - priv->in_buffers[0]->pInputPortPrivate = vid_dec_h264_Flush(priv, ×tamp); - priv->in_buffers[0]->nTimeStamp = timestamp; - priv->target = tmp; - priv->frame_finished = priv->in_buffers[0]->pInputPortPrivate != NULL; -} - -static void vui_parameters(struct vl_rbsp *rbsp) -{ - // TODO -} - -static void scaling_list(struct vl_rbsp *rbsp, uint8_t *scalingList, unsigned sizeOfScalingList, - const uint8_t *defaultList, const uint8_t *fallbackList) -{ - unsigned lastScale = 8, nextScale = 8; - const int *list; - unsigned i; - - /* (pic|seq)_scaling_list_present_flag[i] */ - if (!vl_rbsp_u(rbsp, 1)) { - if (fallbackList) - memcpy(scalingList, fallbackList, sizeOfScalingList); - return; - } - - list = (sizeOfScalingList == 16) ? vl_zscan_normal_16 : vl_zscan_normal; - for (i = 0; i < sizeOfScalingList; ++i ) { - - if (nextScale != 0) { - signed delta_scale = vl_rbsp_se(rbsp); - nextScale = (lastScale + delta_scale + 256) % 256; - if (i == 0 && nextScale == 0) { - memcpy(scalingList, defaultList, sizeOfScalingList); - return; - } - } - scalingList[list[i]] = nextScale == 0 ? lastScale : nextScale; - lastScale = scalingList[list[i]]; - } -} - -static struct pipe_h264_sps *seq_parameter_set_id(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - unsigned id = vl_rbsp_ue(rbsp); - if (id >= ARRAY_SIZE(priv->codec_data.h264.sps)) - return NULL; /* invalid seq_parameter_set_id */ - - return &priv->codec_data.h264.sps[id]; -} - -static void seq_parameter_set(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - struct pipe_h264_sps *sps; - unsigned profile_idc, level_idc; - unsigned i; - - /* Sequence parameter set */ - profile_idc = vl_rbsp_u(rbsp, 8); - - /* constraint_set0_flag */ - vl_rbsp_u(rbsp, 1); - - /* constraint_set1_flag */ - vl_rbsp_u(rbsp, 1); - - /* constraint_set2_flag */ - vl_rbsp_u(rbsp, 1); - - /* constraint_set3_flag */ - vl_rbsp_u(rbsp, 1); - - /* constraint_set4_flag */ - vl_rbsp_u(rbsp, 1); - - /* constraint_set5_flag */ - vl_rbsp_u(rbsp, 1); - - /* reserved_zero_2bits */ - vl_rbsp_u(rbsp, 2); - - /* level_idc */ - level_idc = vl_rbsp_u(rbsp, 8); - - sps = seq_parameter_set_id(priv, rbsp); - if (!sps) - return; - - memset(sps, 0, sizeof(*sps)); - memset(sps->ScalingList4x4, 16, sizeof(sps->ScalingList4x4)); - memset(sps->ScalingList8x8, 16, sizeof(sps->ScalingList8x8)); - - sps->level_idc = level_idc; - - if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || - profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || - profile_idc == 128 || profile_idc == 138) { - - sps->chroma_format_idc = vl_rbsp_ue(rbsp); - - if (sps->chroma_format_idc == 3) - sps->separate_colour_plane_flag = vl_rbsp_u(rbsp, 1); - - sps->bit_depth_luma_minus8 = vl_rbsp_ue(rbsp); - - sps->bit_depth_chroma_minus8 = vl_rbsp_ue(rbsp); - - /* qpprime_y_zero_transform_bypass_flag */ - vl_rbsp_u(rbsp, 1); - - sps->seq_scaling_matrix_present_flag = vl_rbsp_u(rbsp, 1); - if (sps->seq_scaling_matrix_present_flag) { - - scaling_list(rbsp, sps->ScalingList4x4[0], 16, Default_4x4_Intra, Default_4x4_Intra); - scaling_list(rbsp, sps->ScalingList4x4[1], 16, Default_4x4_Intra, sps->ScalingList4x4[0]); - scaling_list(rbsp, sps->ScalingList4x4[2], 16, Default_4x4_Intra, sps->ScalingList4x4[1]); - scaling_list(rbsp, sps->ScalingList4x4[3], 16, Default_4x4_Inter, Default_4x4_Inter); - scaling_list(rbsp, sps->ScalingList4x4[4], 16, Default_4x4_Inter, sps->ScalingList4x4[3]); - scaling_list(rbsp, sps->ScalingList4x4[5], 16, Default_4x4_Inter, sps->ScalingList4x4[4]); - - scaling_list(rbsp, sps->ScalingList8x8[0], 64, Default_8x8_Intra, Default_8x8_Intra); - scaling_list(rbsp, sps->ScalingList8x8[1], 64, Default_8x8_Inter, Default_8x8_Inter); - if (sps->chroma_format_idc == 3) { - scaling_list(rbsp, sps->ScalingList8x8[2], 64, Default_8x8_Intra, sps->ScalingList8x8[0]); - scaling_list(rbsp, sps->ScalingList8x8[3], 64, Default_8x8_Inter, sps->ScalingList8x8[1]); - scaling_list(rbsp, sps->ScalingList8x8[4], 64, Default_8x8_Intra, sps->ScalingList8x8[2]); - scaling_list(rbsp, sps->ScalingList8x8[5], 64, Default_8x8_Inter, sps->ScalingList8x8[3]); - } - } - } else if (profile_idc == 183) - sps->chroma_format_idc = 0; - else - sps->chroma_format_idc = 1; - - sps->log2_max_frame_num_minus4 = vl_rbsp_ue(rbsp); - - sps->pic_order_cnt_type = vl_rbsp_ue(rbsp); - - if (sps->pic_order_cnt_type == 0) - sps->log2_max_pic_order_cnt_lsb_minus4 = vl_rbsp_ue(rbsp); - else if (sps->pic_order_cnt_type == 1) { - sps->delta_pic_order_always_zero_flag = vl_rbsp_u(rbsp, 1); - - sps->offset_for_non_ref_pic = vl_rbsp_se(rbsp); - - sps->offset_for_top_to_bottom_field = vl_rbsp_se(rbsp); - - sps->num_ref_frames_in_pic_order_cnt_cycle = vl_rbsp_ue(rbsp); - - for (i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) - sps->offset_for_ref_frame[i] = vl_rbsp_se(rbsp); - } - - sps->max_num_ref_frames = vl_rbsp_ue(rbsp); - - /* gaps_in_frame_num_value_allowed_flag */ - vl_rbsp_u(rbsp, 1); - - /* pic_width_in_mbs_minus1 */ - ASSERTED int pic_width_in_samplesl = (vl_rbsp_ue(rbsp) + 1) * 16; - assert(pic_width_in_samplesl); - - /* pic_height_in_map_units_minus1 */ - ASSERTED int pic_height_in_map_units = vl_rbsp_ue(rbsp) + 1; - assert(pic_height_in_map_units); - - sps->frame_mbs_only_flag = vl_rbsp_u(rbsp, 1); - if (!sps->frame_mbs_only_flag) - sps->mb_adaptive_frame_field_flag = vl_rbsp_u(rbsp, 1); - - sps->direct_8x8_inference_flag = vl_rbsp_u(rbsp, 1); - - sps->MinLumaBiPredSize8x8 = (sps->level_idc >= 31); /* See section A.3.3.2 of H264 spec */; -#if ENABLE_ST_OMX_TIZONIA - priv->stream_info.width = pic_width_in_samplesl; - - int frame_height_in_mbs = (2 - sps->frame_mbs_only_flag) * pic_height_in_map_units; - int pic_height_in_mbs = frame_height_in_mbs / ( 1 + priv->picture.h264.field_pic_flag ); - int pic_height_in_samplesl = pic_height_in_mbs * 16; - priv->stream_info.height = pic_height_in_samplesl; - - - /* frame_cropping_flag */ - if (vl_rbsp_u(rbsp, 1)) { - unsigned frame_crop_left_offset = vl_rbsp_ue(rbsp); - unsigned frame_crop_right_offset = vl_rbsp_ue(rbsp); - unsigned frame_crop_top_offset = vl_rbsp_ue(rbsp); - unsigned frame_crop_bottom_offset = vl_rbsp_ue(rbsp); - - priv->stream_info.width -= (frame_crop_left_offset + frame_crop_right_offset) * 2; - priv->stream_info.height -= (frame_crop_top_offset + frame_crop_bottom_offset) * 2; - } -#else - /* frame_cropping_flag */ - if (vl_rbsp_u(rbsp, 1)) { - /* frame_crop_left_offset */ - vl_rbsp_ue(rbsp); - - /* frame_crop_right_offset */ - vl_rbsp_ue(rbsp); - - /* frame_crop_top_offset */ - vl_rbsp_ue(rbsp); - - /* frame_crop_bottom_offset */ - vl_rbsp_ue(rbsp); - } -#endif - - /* vui_parameters_present_flag */ - if (vl_rbsp_u(rbsp, 1)) - vui_parameters(rbsp); -} - -static struct pipe_h264_pps *pic_parameter_set_id(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - unsigned id = vl_rbsp_ue(rbsp); - if (id >= ARRAY_SIZE(priv->codec_data.h264.pps)) - return NULL; /* invalid pic_parameter_set_id */ - - return &priv->codec_data.h264.pps[id]; -} - -static void picture_parameter_set(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - struct pipe_h264_sps *sps; - struct pipe_h264_pps *pps; - unsigned i; - - pps = pic_parameter_set_id(priv, rbsp); - if (!pps) - return; - - memset(pps, 0, sizeof(*pps)); - - sps = pps->sps = seq_parameter_set_id(priv, rbsp); - if (!sps) - return; - - memcpy(pps->ScalingList4x4, sps->ScalingList4x4, sizeof(pps->ScalingList4x4)); - memcpy(pps->ScalingList8x8, sps->ScalingList8x8, sizeof(pps->ScalingList8x8)); - - pps->entropy_coding_mode_flag = vl_rbsp_u(rbsp, 1); - - pps->bottom_field_pic_order_in_frame_present_flag = vl_rbsp_u(rbsp, 1); - - pps->num_slice_groups_minus1 = vl_rbsp_ue(rbsp); - if (pps->num_slice_groups_minus1 > 0) { - pps->slice_group_map_type = vl_rbsp_ue(rbsp); - - if (pps->slice_group_map_type == 0) { - - for (i = 0; i <= pps->num_slice_groups_minus1; ++i) - /* run_length_minus1[i] */ - vl_rbsp_ue(rbsp); - - } else if (pps->slice_group_map_type == 2) { - - for (i = 0; i <= pps->num_slice_groups_minus1; ++i) { - /* top_left[i] */ - vl_rbsp_ue(rbsp); - - /* bottom_right[i] */ - vl_rbsp_ue(rbsp); - } - - } else if (pps->slice_group_map_type >= 3 && pps->slice_group_map_type <= 5) { - - /* slice_group_change_direction_flag */ - vl_rbsp_u(rbsp, 1); - - pps->slice_group_change_rate_minus1 = vl_rbsp_ue(rbsp); - - } else if (pps->slice_group_map_type == 6) { - - unsigned pic_size_in_map_units_minus1; - - pic_size_in_map_units_minus1 = vl_rbsp_ue(rbsp); - - for (i = 0; i <= pic_size_in_map_units_minus1; ++i) - /* slice_group_id[i] */ - vl_rbsp_u(rbsp, log2(pps->num_slice_groups_minus1 + 1)); - } - } - - pps->num_ref_idx_l0_default_active_minus1 = vl_rbsp_ue(rbsp); - - pps->num_ref_idx_l1_default_active_minus1 = vl_rbsp_ue(rbsp); - - pps->weighted_pred_flag = vl_rbsp_u(rbsp, 1); - - pps->weighted_bipred_idc = vl_rbsp_u(rbsp, 2); - - pps->pic_init_qp_minus26 = vl_rbsp_se(rbsp); - - pps->pic_init_qs_minus26 = vl_rbsp_se(rbsp); - - pps->chroma_qp_index_offset = vl_rbsp_se(rbsp); - - pps->deblocking_filter_control_present_flag = vl_rbsp_u(rbsp, 1); - - pps->constrained_intra_pred_flag = vl_rbsp_u(rbsp, 1); - - pps->redundant_pic_cnt_present_flag = vl_rbsp_u(rbsp, 1); - - if (vl_rbsp_more_data(rbsp)) { - pps->transform_8x8_mode_flag = vl_rbsp_u(rbsp, 1); - - /* pic_scaling_matrix_present_flag */ - if (vl_rbsp_u(rbsp, 1)) { - - scaling_list(rbsp, pps->ScalingList4x4[0], 16, Default_4x4_Intra, - sps->seq_scaling_matrix_present_flag ? NULL : Default_4x4_Intra); - scaling_list(rbsp, pps->ScalingList4x4[1], 16, Default_4x4_Intra, pps->ScalingList4x4[0]); - scaling_list(rbsp, pps->ScalingList4x4[2], 16, Default_4x4_Intra, pps->ScalingList4x4[1]); - scaling_list(rbsp, pps->ScalingList4x4[3], 16, Default_4x4_Inter, - sps->seq_scaling_matrix_present_flag ? NULL : Default_4x4_Inter); - scaling_list(rbsp, pps->ScalingList4x4[4], 16, Default_4x4_Inter, pps->ScalingList4x4[3]); - scaling_list(rbsp, pps->ScalingList4x4[5], 16, Default_4x4_Inter, pps->ScalingList4x4[4]); - - if (pps->transform_8x8_mode_flag) { - scaling_list(rbsp, pps->ScalingList8x8[0], 64, Default_8x8_Intra, - sps->seq_scaling_matrix_present_flag ? NULL : Default_8x8_Intra); - scaling_list(rbsp, pps->ScalingList8x8[1], 64, Default_8x8_Inter, - sps->seq_scaling_matrix_present_flag ? NULL : Default_8x8_Inter); - if (sps->chroma_format_idc == 3) { - scaling_list(rbsp, pps->ScalingList8x8[2], 64, Default_8x8_Intra, pps->ScalingList8x8[0]); - scaling_list(rbsp, pps->ScalingList8x8[3], 64, Default_8x8_Inter, pps->ScalingList8x8[1]); - scaling_list(rbsp, pps->ScalingList8x8[4], 64, Default_8x8_Intra, pps->ScalingList8x8[2]); - scaling_list(rbsp, pps->ScalingList8x8[5], 64, Default_8x8_Inter, pps->ScalingList8x8[3]); - } - } - } - - pps->second_chroma_qp_index_offset = vl_rbsp_se(rbsp); - } -} - -static void ref_pic_list_mvc_modification(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp) -{ - // TODO - assert(0); -} - -static void ref_pic_list_modification(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - enum pipe_h264_slice_type slice_type) -{ - unsigned modification_of_pic_nums_idc; - - if (slice_type != 2 && slice_type != 4) { - /* ref_pic_list_modification_flag_l0 */ - if (vl_rbsp_u(rbsp, 1)) { - do { - modification_of_pic_nums_idc = vl_rbsp_ue(rbsp); - if (modification_of_pic_nums_idc == 0 || - modification_of_pic_nums_idc == 1) - /* abs_diff_pic_num_minus1 */ - vl_rbsp_ue(rbsp); - else if (modification_of_pic_nums_idc == 2) - /* long_term_pic_num */ - vl_rbsp_ue(rbsp); - } while (modification_of_pic_nums_idc != 3); - } - } - - if (slice_type == 1) { - /* ref_pic_list_modification_flag_l1 */ - if (vl_rbsp_u(rbsp, 1)) { - do { - modification_of_pic_nums_idc = vl_rbsp_ue(rbsp); - if (modification_of_pic_nums_idc == 0 || - modification_of_pic_nums_idc == 1) - /* abs_diff_pic_num_minus1 */ - vl_rbsp_ue(rbsp); - else if (modification_of_pic_nums_idc == 2) - /* long_term_pic_num */ - vl_rbsp_ue(rbsp); - } while (modification_of_pic_nums_idc != 3); - } - } -} - -static void pred_weight_table(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - struct pipe_h264_sps *sps, enum pipe_h264_slice_type slice_type) -{ - unsigned ChromaArrayType = sps->separate_colour_plane_flag ? 0 : sps->chroma_format_idc; - unsigned i, j; - - /* luma_log2_weight_denom */ - vl_rbsp_ue(rbsp); - - if (ChromaArrayType != 0) - /* chroma_log2_weight_denom */ - vl_rbsp_ue(rbsp); - - for (i = 0; i <= priv->picture.h264.num_ref_idx_l0_active_minus1; ++i) { - /* luma_weight_l0_flag */ - if (vl_rbsp_u(rbsp, 1)) { - /* luma_weight_l0[i] */ - vl_rbsp_se(rbsp); - /* luma_offset_l0[i] */ - vl_rbsp_se(rbsp); - } - if (ChromaArrayType != 0) { - /* chroma_weight_l0_flag */ - if (vl_rbsp_u(rbsp, 1)) { - for (j = 0; j < 2; ++j) { - /* chroma_weight_l0[i][j] */ - vl_rbsp_se(rbsp); - /* chroma_offset_l0[i][j] */ - vl_rbsp_se(rbsp); - } - } - } - } - - if (slice_type == 1) { - for (i = 0; i <= priv->picture.h264.num_ref_idx_l1_active_minus1; ++i) { - /* luma_weight_l1_flag */ - if (vl_rbsp_u(rbsp, 1)) { - /* luma_weight_l1[i] */ - vl_rbsp_se(rbsp); - /* luma_offset_l1[i] */ - vl_rbsp_se(rbsp); - } - if (ChromaArrayType != 0) { - /* chroma_weight_l1_flag */ - if (vl_rbsp_u(rbsp, 1)) { - for (j = 0; j < 2; ++j) { - /* chroma_weight_l1[i][j] */ - vl_rbsp_se(rbsp); - /* chroma_offset_l1[i][j] */ - vl_rbsp_se(rbsp); - } - } - } - } - } -} - -static void dec_ref_pic_marking(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - bool IdrPicFlag) -{ - unsigned memory_management_control_operation; - - if (IdrPicFlag) { - /* no_output_of_prior_pics_flag */ - vl_rbsp_u(rbsp, 1); - /* long_term_reference_flag */ - vl_rbsp_u(rbsp, 1); - } else { - /* adaptive_ref_pic_marking_mode_flag */ - if (vl_rbsp_u(rbsp, 1)) { - do { - memory_management_control_operation = vl_rbsp_ue(rbsp); - - if (memory_management_control_operation == 1 || - memory_management_control_operation == 3) - /* difference_of_pic_nums_minus1 */ - vl_rbsp_ue(rbsp); - - if (memory_management_control_operation == 2) - /* long_term_pic_num */ - vl_rbsp_ue(rbsp); - - if (memory_management_control_operation == 3 || - memory_management_control_operation == 6) - /* long_term_frame_idx */ - vl_rbsp_ue(rbsp); - - if (memory_management_control_operation == 4) - /* max_long_term_frame_idx_plus1 */ - vl_rbsp_ue(rbsp); - } while (memory_management_control_operation != 0); - } - } -} - -static void slice_header(vid_dec_PrivateType *priv, struct vl_rbsp *rbsp, - unsigned nal_ref_idc, unsigned nal_unit_type) -{ - enum pipe_h264_slice_type slice_type; - struct pipe_h264_pps *pps; - struct pipe_h264_sps *sps; - unsigned frame_num, prevFrameNum; - bool IdrPicFlag = nal_unit_type == 5; - - if (IdrPicFlag != priv->codec_data.h264.IdrPicFlag) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.IdrPicFlag = IdrPicFlag; - - /* first_mb_in_slice */ - vl_rbsp_ue(rbsp); - - slice_type = vl_rbsp_ue(rbsp) % 5; - - /* get picture parameter set */ - pps = pic_parameter_set_id(priv, rbsp); - if (!pps) - return; - - /* get sequence parameter set */ - sps = pps->sps; - if (!sps) - return; - - if (pps != priv->picture.h264.pps) - vid_dec_h264_EndFrame(priv); - - priv->picture.h264.pps = pps; - - if (sps->separate_colour_plane_flag == 1 ) - /* colour_plane_id */ - vl_rbsp_u(rbsp, 2); - - /* frame number handling */ - frame_num = vl_rbsp_u(rbsp, sps->log2_max_frame_num_minus4 + 4); - - if (frame_num != priv->picture.h264.frame_num) - vid_dec_h264_EndFrame(priv); - - prevFrameNum = priv->picture.h264.frame_num; - priv->picture.h264.frame_num = frame_num; - - priv->picture.h264.field_pic_flag = 0; - priv->picture.h264.bottom_field_flag = 0; - - if (!sps->frame_mbs_only_flag) { - unsigned field_pic_flag = vl_rbsp_u(rbsp, 1); - - if (!field_pic_flag && field_pic_flag != priv->picture.h264.field_pic_flag) - vid_dec_h264_EndFrame(priv); - - priv->picture.h264.field_pic_flag = field_pic_flag; - - if (priv->picture.h264.field_pic_flag) { - unsigned bottom_field_flag = vl_rbsp_u(rbsp, 1); - - if (bottom_field_flag != priv->picture.h264.bottom_field_flag) - vid_dec_h264_EndFrame(priv); - - priv->picture.h264.bottom_field_flag = bottom_field_flag; - } - } - - if (IdrPicFlag) { - /* set idr_pic_id */ - unsigned idr_pic_id = vl_rbsp_ue(rbsp); - - if (idr_pic_id != priv->codec_data.h264.idr_pic_id) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.idr_pic_id = idr_pic_id; - } - - if (sps->pic_order_cnt_type == 0) { - /* pic_order_cnt_lsb */ - unsigned log2_max_pic_order_cnt_lsb = sps->log2_max_pic_order_cnt_lsb_minus4 + 4; - unsigned max_pic_order_cnt_lsb = 1 << log2_max_pic_order_cnt_lsb; - int pic_order_cnt_lsb = vl_rbsp_u(rbsp, log2_max_pic_order_cnt_lsb); - int pic_order_cnt_msb; - - if (pic_order_cnt_lsb != priv->codec_data.h264.pic_order_cnt_lsb) - vid_dec_h264_EndFrame(priv); - - if (IdrPicFlag) { - priv->codec_data.h264.pic_order_cnt_msb = 0; - priv->codec_data.h264.pic_order_cnt_lsb = 0; - } - - if ((pic_order_cnt_lsb < priv->codec_data.h264.pic_order_cnt_lsb) && - (priv->codec_data.h264.pic_order_cnt_lsb - pic_order_cnt_lsb) >= (max_pic_order_cnt_lsb / 2)) - pic_order_cnt_msb = priv->codec_data.h264.pic_order_cnt_msb + max_pic_order_cnt_lsb; - - else if ((pic_order_cnt_lsb > priv->codec_data.h264.pic_order_cnt_lsb) && - (pic_order_cnt_lsb - priv->codec_data.h264.pic_order_cnt_lsb) > (max_pic_order_cnt_lsb / 2)) - pic_order_cnt_msb = priv->codec_data.h264.pic_order_cnt_msb - max_pic_order_cnt_lsb; - - else - pic_order_cnt_msb = priv->codec_data.h264.pic_order_cnt_msb; - - priv->codec_data.h264.pic_order_cnt_msb = pic_order_cnt_msb; - priv->codec_data.h264.pic_order_cnt_lsb = pic_order_cnt_lsb; - - if (pps->bottom_field_pic_order_in_frame_present_flag && !priv->picture.h264.field_pic_flag) { - /* delta_pic_oreder_cnt_bottom */ - unsigned delta_pic_order_cnt_bottom = vl_rbsp_se(rbsp); - - if (delta_pic_order_cnt_bottom != priv->codec_data.h264.delta_pic_order_cnt_bottom) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.delta_pic_order_cnt_bottom = delta_pic_order_cnt_bottom; - } - - if (!priv->picture.h264.field_pic_flag) { - priv->picture.h264.field_order_cnt[0] = pic_order_cnt_msb + pic_order_cnt_lsb; - priv->picture.h264.field_order_cnt[1] = priv->picture.h264.field_order_cnt [0] + - priv->codec_data.h264.delta_pic_order_cnt_bottom; - } else if (!priv->picture.h264.bottom_field_flag) - priv->picture.h264.field_order_cnt[0] = pic_order_cnt_msb + pic_order_cnt_lsb; - else - priv->picture.h264.field_order_cnt[1] = pic_order_cnt_msb + pic_order_cnt_lsb; - - } else if (sps->pic_order_cnt_type == 1) { - /* delta_pic_order_cnt[0] */ - unsigned MaxFrameNum = 1 << (sps->log2_max_frame_num_minus4 + 4); - unsigned FrameNumOffset, absFrameNum, expectedPicOrderCnt; - - if (!sps->delta_pic_order_always_zero_flag) { - unsigned delta_pic_order_cnt[2]; - - delta_pic_order_cnt[0] = vl_rbsp_se(rbsp); - - if (delta_pic_order_cnt[0] != priv->codec_data.h264.delta_pic_order_cnt[0]) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.delta_pic_order_cnt[0] = delta_pic_order_cnt[0]; - - if (pps->bottom_field_pic_order_in_frame_present_flag && !priv->picture.h264.field_pic_flag) { - /* delta_pic_order_cnt[1] */ - delta_pic_order_cnt[1] = vl_rbsp_se(rbsp); - - if (delta_pic_order_cnt[1] != priv->codec_data.h264.delta_pic_order_cnt[1]) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.delta_pic_order_cnt[1] = delta_pic_order_cnt[1]; - } - } - - if (IdrPicFlag) - FrameNumOffset = 0; - else if (prevFrameNum > frame_num) - FrameNumOffset = priv->codec_data.h264.prevFrameNumOffset + MaxFrameNum; - else - FrameNumOffset = priv->codec_data.h264.prevFrameNumOffset; - - priv->codec_data.h264.prevFrameNumOffset = FrameNumOffset; - - if (sps->num_ref_frames_in_pic_order_cnt_cycle != 0) - absFrameNum = FrameNumOffset + frame_num; - else - absFrameNum = 0; - - if (nal_ref_idc == 0 && absFrameNum > 0) - absFrameNum = absFrameNum - 1; - - if (absFrameNum > 0) { - unsigned picOrderCntCycleCnt = (absFrameNum - 1) / sps->num_ref_frames_in_pic_order_cnt_cycle; - unsigned frameNumInPicOrderCntCycle = (absFrameNum - 1) % sps->num_ref_frames_in_pic_order_cnt_cycle; - signed ExpectedDeltaPerPicOrderCntCycle = 0; - unsigned i; - - for (i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) - ExpectedDeltaPerPicOrderCntCycle += sps->offset_for_ref_frame[i]; - - expectedPicOrderCnt = picOrderCntCycleCnt * ExpectedDeltaPerPicOrderCntCycle; - for (i = 0; i <= frameNumInPicOrderCntCycle; ++i) - expectedPicOrderCnt += sps->offset_for_ref_frame[i]; - - } else - expectedPicOrderCnt = 0; - - if (nal_ref_idc == 0) - expectedPicOrderCnt += sps->offset_for_non_ref_pic; - - if (!priv->picture.h264.field_pic_flag) { - priv->picture.h264.field_order_cnt[0] = expectedPicOrderCnt + priv->codec_data.h264.delta_pic_order_cnt[0]; - priv->picture.h264.field_order_cnt[1] = priv->picture.h264.field_order_cnt[0] + - sps->offset_for_top_to_bottom_field + priv->codec_data.h264.delta_pic_order_cnt[1]; - - } else if (!priv->picture.h264.bottom_field_flag) - priv->picture.h264.field_order_cnt[0] = expectedPicOrderCnt + priv->codec_data.h264.delta_pic_order_cnt[0]; - else - priv->picture.h264.field_order_cnt[1] = expectedPicOrderCnt + sps->offset_for_top_to_bottom_field + - priv->codec_data.h264.delta_pic_order_cnt[0]; - - } else if (sps->pic_order_cnt_type == 2) { - unsigned MaxFrameNum = 1 << (sps->log2_max_frame_num_minus4 + 4); - unsigned FrameNumOffset, tempPicOrderCnt; - - if (IdrPicFlag) - FrameNumOffset = 0; - else if (prevFrameNum > frame_num) - FrameNumOffset = priv->codec_data.h264.prevFrameNumOffset + MaxFrameNum; - else - FrameNumOffset = priv->codec_data.h264.prevFrameNumOffset; - - priv->codec_data.h264.prevFrameNumOffset = FrameNumOffset; - - if (IdrPicFlag) - tempPicOrderCnt = 0; - else if (nal_ref_idc == 0) - tempPicOrderCnt = 2 * (FrameNumOffset + frame_num) - 1; - else - tempPicOrderCnt = 2 * (FrameNumOffset + frame_num); - - if (!priv->picture.h264.field_pic_flag) { - priv->picture.h264.field_order_cnt[0] = tempPicOrderCnt; - priv->picture.h264.field_order_cnt[1] = tempPicOrderCnt; - - } else if (!priv->picture.h264.bottom_field_flag) - priv->picture.h264.field_order_cnt[0] = tempPicOrderCnt; - else - priv->picture.h264.field_order_cnt[1] = tempPicOrderCnt; - } - - if (pps->redundant_pic_cnt_present_flag) - /* redundant_pic_cnt */ - vl_rbsp_ue(rbsp); - - if (slice_type == PIPE_H264_SLICE_TYPE_B) - /* direct_spatial_mv_pred_flag */ - vl_rbsp_u(rbsp, 1); - - priv->picture.h264.num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1; - priv->picture.h264.num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1; - - if (slice_type == PIPE_H264_SLICE_TYPE_P || - slice_type == PIPE_H264_SLICE_TYPE_SP || - slice_type == PIPE_H264_SLICE_TYPE_B) { - - /* num_ref_idx_active_override_flag */ - if (vl_rbsp_u(rbsp, 1)) { - priv->picture.h264.num_ref_idx_l0_active_minus1 = vl_rbsp_ue(rbsp); - - if (slice_type == PIPE_H264_SLICE_TYPE_B) - priv->picture.h264.num_ref_idx_l1_active_minus1 = vl_rbsp_ue(rbsp); - } - } - - if (nal_unit_type == 20 || nal_unit_type == 21) - ref_pic_list_mvc_modification(priv, rbsp); - else - ref_pic_list_modification(priv, rbsp, slice_type); - - if ((pps->weighted_pred_flag && (slice_type == PIPE_H264_SLICE_TYPE_P || slice_type == PIPE_H264_SLICE_TYPE_SP)) || - (pps->weighted_bipred_idc == 1 && slice_type == PIPE_H264_SLICE_TYPE_B)) - pred_weight_table(priv, rbsp, sps, slice_type); - - if (nal_ref_idc != 0) - dec_ref_pic_marking(priv, rbsp, IdrPicFlag); - - if (pps->entropy_coding_mode_flag && slice_type != PIPE_H264_SLICE_TYPE_I && slice_type != PIPE_H264_SLICE_TYPE_SI) - /* cabac_init_idc */ - vl_rbsp_ue(rbsp); - - /* slice_qp_delta */ - vl_rbsp_se(rbsp); - - if (slice_type == PIPE_H264_SLICE_TYPE_SP || slice_type == PIPE_H264_SLICE_TYPE_SI) { - if (slice_type == PIPE_H264_SLICE_TYPE_SP) - /* sp_for_switch_flag */ - vl_rbsp_u(rbsp, 1); - - /*slice_qs_delta */ - vl_rbsp_se(rbsp); - } - - if (pps->deblocking_filter_control_present_flag) { - unsigned disable_deblocking_filter_idc = vl_rbsp_ue(rbsp); - - if (disable_deblocking_filter_idc != 1) { - /* slice_alpha_c0_offset_div2 */ - vl_rbsp_se(rbsp); - - /* slice_beta_offset_div2 */ - vl_rbsp_se(rbsp); - } - } - - if (pps->num_slice_groups_minus1 > 0 && pps->slice_group_map_type >= 3 && pps->slice_group_map_type <= 5) - /* slice_group_change_cycle */ - vl_rbsp_u(rbsp, 2); -} - -#if ENABLE_ST_OMX_TIZONIA -static OMX_ERRORTYPE update_port_parameters(vid_dec_PrivateType* priv) { - OMX_VIDEO_PORTDEFINITIONTYPE * p_def = NULL; /* Output port info */ - h264d_stream_info_t * i_def = NULL; /* Info read from stream */ - OMX_ERRORTYPE err = OMX_ErrorNone; - - assert(priv); - - p_def = &(priv->out_port_def_.format.video); - i_def = &(priv->stream_info); - - /* Handle dynamic resolution change */ - if ((p_def->nFrameWidth == i_def->width) && p_def->nFrameHeight == i_def->height) - return err; - - p_def->nFrameWidth = i_def->width; - p_def->nFrameHeight = i_def->height; - p_def->nStride = i_def->width; - p_def->nSliceHeight = i_def->height; - - err = tiz_krn_SetParameter_internal(tiz_get_krn(handleOf(priv)), handleOf(priv), - OMX_IndexParamPortDefinition, &(priv->out_port_def_)); - if (err == OMX_ErrorNone) { - tiz_port_t * p_obj = tiz_krn_get_port(tiz_get_krn(handleOf(priv)), OMX_VID_DEC_AVC_INPUT_PORT_INDEX); - - /* Set desired buffer size that will be used when allocating input buffers */ - p_obj->portdef_.nBufferSize = p_def->nFrameWidth * p_def->nFrameHeight * 512 / (16*16); - - /* Get a locally copy of port def. Useful for the early return above */ - tiz_check_omx(tiz_api_GetParameter(tiz_get_krn(handleOf(priv)), handleOf(priv), - OMX_IndexParamPortDefinition, &(priv->out_port_def_))); - - tiz_srv_issue_event((OMX_PTR) priv, OMX_EventPortSettingsChanged, - OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX, - OMX_IndexParamPortDefinition, - NULL); - } - - return err; -} -#endif - -void vid_dec_h264_Decode(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left) -{ - unsigned nal_ref_idc, nal_unit_type; - - if (!vl_vlc_search_byte(vlc, vl_vlc_bits_left(vlc) - min_bits_left, 0x00)) - return; - - if (vl_vlc_peekbits(vlc, 24) != 0x000001) { - vl_vlc_eatbits(vlc, 8); - return; - } - - if (priv->slice) { - unsigned bytes = priv->bytes_left - (vl_vlc_bits_left(vlc) / 8); - ++priv->picture.h264.slice_count; - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &priv->slice, &bytes); - priv->slice = NULL; - } - - vl_vlc_eatbits(vlc, 24); - - /* forbidden_zero_bit */ - vl_vlc_eatbits(vlc, 1); - - nal_ref_idc = vl_vlc_get_uimsbf(vlc, 2); - - if (nal_ref_idc != priv->codec_data.h264.nal_ref_idc && - (nal_ref_idc * priv->codec_data.h264.nal_ref_idc) == 0) - vid_dec_h264_EndFrame(priv); - - priv->codec_data.h264.nal_ref_idc = nal_ref_idc; - - nal_unit_type = vl_vlc_get_uimsbf(vlc, 5); - - if (nal_unit_type != 1 && nal_unit_type != 5) - vid_dec_h264_EndFrame(priv); - - if (nal_unit_type == 7) { - struct vl_rbsp rbsp; - vl_rbsp_init(&rbsp, vlc, ~0, /* emulation_bytes */ true); - seq_parameter_set(priv, &rbsp); -#if ENABLE_ST_OMX_TIZONIA - update_port_parameters(priv); -#endif - - } else if (nal_unit_type == 8) { - struct vl_rbsp rbsp; - vl_rbsp_init(&rbsp, vlc, ~0, /* emulation_bytes */ true); - picture_parameter_set(priv, &rbsp); - - } else if (nal_unit_type == 1 || nal_unit_type == 5) { - /* Coded slice of a non-IDR or IDR picture */ - unsigned bits = vl_vlc_valid_bits(vlc); - unsigned bytes = bits / 8 + 4; - struct vl_rbsp rbsp; - uint8_t buf[8]; - const void *ptr = buf; - unsigned i; - - buf[0] = 0x0; - buf[1] = 0x0; - buf[2] = 0x1; - buf[3] = (nal_ref_idc << 5) | nal_unit_type; - for (i = 4; i < bytes; ++i) - buf[i] = vl_vlc_peekbits(vlc, bits) >> ((bytes - i - 1) * 8); - - priv->bytes_left = (vl_vlc_bits_left(vlc) - bits) / 8; - priv->slice = vlc->data; - - vl_rbsp_init(&rbsp, vlc, 128, /* emulation_bytes */ true); - slice_header(priv, &rbsp, nal_ref_idc, nal_unit_type); - - vid_dec_h264_BeginFrame(priv); - - ++priv->picture.h264.slice_count; - priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base, - 1, &ptr, &bytes); - } - - /* resync to byte boundary */ - vl_vlc_eatbits(vlc, vl_vlc_valid_bits(vlc) % 8); -} - -void vid_dec_FreeInputPortPrivate(OMX_BUFFERHEADERTYPE *buf) -{ - struct pipe_video_buffer *vbuf = buf->pInputPortPrivate; - if (!vbuf) - return; - - vbuf->destroy(vbuf); - buf->pInputPortPrivate = NULL; -} - -void vid_dec_FrameDecoded_common(vid_dec_PrivateType* priv, OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output) -{ -#if ENABLE_ST_OMX_BELLAGIO - bool eos = !!(input->nFlags & OMX_BUFFERFLAG_EOS); -#else - bool eos = priv->eos_; -#endif - OMX_TICKS timestamp; - - if (!input->pInputPortPrivate) { -#if ENABLE_ST_OMX_BELLAGIO - input->pInputPortPrivate = priv->Flush(priv, ×tamp); -#else - input->pInputPortPrivate = vid_dec_h264_Flush(priv, ×tamp); -#endif - if (timestamp != OMX_VID_DEC_AVC_TIMESTAMP_INVALID) - input->nTimeStamp = timestamp; - } - - if (input->pInputPortPrivate) { - if (output->pInputPortPrivate && !priv->disable_tunnel) { - struct pipe_video_buffer *tmp, *vbuf, *new_vbuf; - - tmp = output->pOutputPortPrivate; - vbuf = input->pInputPortPrivate; - if (vbuf->interlaced) { - /* re-allocate the progressive buffer */ - struct pipe_video_buffer templat = {}; - struct u_rect src_rect, dst_rect; - -#if ENABLE_ST_OMX_BELLAGIO - omx_base_video_PortType *port; - port = (omx_base_video_PortType *) - priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]; -#else - tiz_port_t *port; - port = tiz_krn_get_port(tiz_get_krn(handleOf (priv)), OMX_VID_DEC_AVC_INPUT_PORT_INDEX); -#endif - memset(&templat, 0, sizeof(templat)); -#if ENABLE_ST_OMX_BELLAGIO - templat.width = port->sPortParam.format.video.nFrameWidth; - templat.height = port->sPortParam.format.video.nFrameHeight; -#else - templat.width = port->portdef_.format.video.nFrameWidth; - templat.height = port->portdef_.format.video.nFrameHeight; -#endif - templat.buffer_format = PIPE_FORMAT_NV12; - templat.interlaced = false; - new_vbuf = priv->pipe->create_video_buffer(priv->pipe, &templat); - - /* convert the interlaced to the progressive */ - src_rect.x0 = dst_rect.x0 = 0; - src_rect.x1 = dst_rect.x1 = templat.width; - src_rect.y0 = dst_rect.y0 = 0; - src_rect.y1 = dst_rect.y1 = templat.height; - - vl_compositor_yuv_deint_full(&priv->cstate, &priv->compositor, - input->pInputPortPrivate, new_vbuf, - &src_rect, &dst_rect, VL_COMPOSITOR_WEAVE); - - /* set the progrssive buffer for next round */ - vbuf->destroy(vbuf); - input->pInputPortPrivate = new_vbuf; - } - output->pOutputPortPrivate = input->pInputPortPrivate; - input->pInputPortPrivate = tmp; - } else { - vid_dec_FillOutput(priv, input->pInputPortPrivate, output); - } - output->nFilledLen = output->nAllocLen; - output->nTimeStamp = input->nTimeStamp; - } - - if (eos && input->pInputPortPrivate) - vid_dec_FreeInputPortPrivate(input); - else - input->nFilledLen = 0; -} diff --git a/src/gallium/frontends/omx/vid_dec_h264_common.h b/src/gallium/frontends/omx/vid_dec_h264_common.h deleted file mode 100644 index abde53beef9..00000000000 --- a/src/gallium/frontends/omx/vid_dec_h264_common.h +++ /dev/null @@ -1,99 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef VID_DEC_H264_COMMON_H -#define VID_DEC_H264_COMMON_H - -#include "vid_dec_common.h" - -#define OMX_VID_DEC_AVC_DEFAULT_FRAME_WIDTH 176 -#define OMX_VID_DEC_AVC_DEFAULT_FRAME_HEIGHT 144 -#define OMX_VID_DEC_AVC_DEFAULT_FRAME_RATE 15<<16 -#define OMX_VID_DEC_AVC_ROLE "video_decoder.avc" -/* With libtizonia, port indexes must start at index 0 */ -#define OMX_VID_DEC_AVC_INPUT_PORT_INDEX 0 -#define OMX_VID_DEC_AVC_OUTPUT_PORT_INDEX 1 -#define OMX_VID_DEC_AVC_INPUT_PORT_MIN_BUF_COUNT 8 -#define OMX_VID_DEC_AVC_OUTPUT_PORT_MIN_BUF_COUNT 4 -/* 38016 = (width * height) + ((width * height)/2) */ -#define OMX_VID_DEC_AVC_PORT_MIN_INPUT_BUF_SIZE 38016 -#define OMX_VID_DEC_AVC_PORT_MIN_OUTPUT_BUF_SIZE 345600 -#define OMX_VID_DEC_AVC_PORT_NONCONTIGUOUS OMX_FALSE -#define OMX_VID_DEC_AVC_PORT_ALIGNMENT 0 -#define OMX_VID_DEC_AVC_PORT_SUPPLIERPREF OMX_BufferSupplyInput -#define OMX_VID_DEC_AVC_TIMESTAMP_INVALID ((OMX_TICKS) -1) - -#define DPB_MAX_SIZE 5 - -struct dpb_list { - struct list_head list; - struct pipe_video_buffer *buffer; - OMX_TICKS timestamp; - int poc; -}; - -static const uint8_t Default_4x4_Intra[16] = { - 6, 13, 20, 28, 13, 20, 28, 32, - 20, 28, 32, 37, 28, 32, 37, 42 -}; - -static const uint8_t Default_4x4_Inter[16] = { - 10, 14, 20, 24, 14, 20, 24, 27, - 20, 24, 27, 30, 24, 27, 30, 34 -}; - -static const uint8_t Default_8x8_Intra[64] = { - 6, 10, 13, 16, 18, 23, 25, 27, - 10, 11, 16, 18, 23, 25, 27, 29, - 13, 16, 18, 23, 25, 27, 29, 31, - 16, 18, 23, 25, 27, 29, 31, 33, - 18, 23, 25, 27, 29, 31, 33, 36, - 23, 25, 27, 29, 31, 33, 36, 38, - 25, 27, 29, 31, 33, 36, 38, 40, - 27, 29, 31, 33, 36, 38, 40, 42 -}; - -static const uint8_t Default_8x8_Inter[64] = { - 9, 13, 15, 17, 19, 21, 22, 24, - 13, 13, 17, 19, 21, 22, 24, 25, - 15, 17, 19, 21, 22, 24, 25, 27, - 17, 19, 21, 22, 24, 25, 27, 28, - 19, 21, 22, 24, 25, 27, 28, 30, - 21, 22, 24, 25, 27, 28, 30, 32, - 22, 24, 25, 27, 28, 30, 32, 33, - 24, 25, 27, 28, 30, 32, 33, 35 -}; - -struct pipe_video_buffer *vid_dec_h264_Flush(vid_dec_PrivateType *priv, - OMX_TICKS *timestamp); -void vid_dec_h264_EndFrame(vid_dec_PrivateType *priv); -void vid_dec_h264_Decode(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left); -void vid_dec_FreeInputPortPrivate(OMX_BUFFERHEADERTYPE *buf); -void vid_dec_FrameDecoded_common(vid_dec_PrivateType*priv, OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output); - -#endif diff --git a/src/gallium/frontends/omx/vid_enc_common.c b/src/gallium/frontends/omx/vid_enc_common.c deleted file mode 100644 index 5014bedbeb8..00000000000 --- a/src/gallium/frontends/omx/vid_enc_common.c +++ /dev/null @@ -1,573 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include "vid_enc_common.h" - -#include "vl/vl_video_buffer.h" -#include "tgsi/tgsi_text.h" - -void enc_ReleaseTasks(struct list_head *head) -{ - struct encode_task *i, *next; - - if (!head || !list_is_linked(head)) - return; - - LIST_FOR_EACH_ENTRY_SAFE(i, next, head, list) { - pipe_resource_reference(&i->bitstream, NULL); - i->buf->destroy(i->buf); - FREE(i); - } -} - -void enc_MoveTasks(struct list_head *from, struct list_head *to) -{ - to->prev->next = from->next; - from->next->prev = to->prev; - from->prev->next = to; - to->prev = from->prev; - list_inithead(from); -} - -static void enc_GetPictureParamPreset(struct pipe_h264_enc_picture_desc *picture) -{ - picture->motion_est.enc_disable_sub_mode = 0x000000fe; - picture->motion_est.enc_ime2_search_range_x = 0x00000001; - picture->motion_est.enc_ime2_search_range_y = 0x00000001; - picture->seq.enc_constraint_set_flags = 0x00000040; -} - -enum pipe_video_profile enc_TranslateOMXProfileToPipe(unsigned omx_profile) -{ - switch (omx_profile) { - case OMX_VIDEO_AVCProfileBaseline: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE; - case OMX_VIDEO_AVCProfileMain: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN; - case OMX_VIDEO_AVCProfileExtended: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED; - case OMX_VIDEO_AVCProfileHigh: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; - case OMX_VIDEO_AVCProfileHigh10: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10; - case OMX_VIDEO_AVCProfileHigh422: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422; - case OMX_VIDEO_AVCProfileHigh444: - return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444; - default: - return PIPE_VIDEO_PROFILE_UNKNOWN; - } -} - -unsigned enc_TranslateOMXLevelToPipe(unsigned omx_level) -{ - switch (omx_level) { - case OMX_VIDEO_AVCLevel1: - case OMX_VIDEO_AVCLevel1b: - return 10; - case OMX_VIDEO_AVCLevel11: - return 11; - case OMX_VIDEO_AVCLevel12: - return 12; - case OMX_VIDEO_AVCLevel13: - return 13; - case OMX_VIDEO_AVCLevel2: - return 20; - case OMX_VIDEO_AVCLevel21: - return 21; - case OMX_VIDEO_AVCLevel22: - return 22; - case OMX_VIDEO_AVCLevel3: - return 30; - case OMX_VIDEO_AVCLevel31: - return 31; - case OMX_VIDEO_AVCLevel32: - return 32; - case OMX_VIDEO_AVCLevel4: - return 40; - case OMX_VIDEO_AVCLevel41: - return 41; - default: - case OMX_VIDEO_AVCLevel42: - return 42; - case OMX_VIDEO_AVCLevel5: - return 50; - case OMX_VIDEO_AVCLevel51: - return 51; - } -} - -void vid_enc_BufferEncoded_common(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output) -{ - struct output_buf_private *outp = output->pOutputPortPrivate; - struct input_buf_private *inp = input->pInputPortPrivate; - struct encode_task *task; - struct pipe_box box = {}; - unsigned size; - -#if ENABLE_ST_OMX_BELLAGIO - if (!inp || list_is_empty(&inp->tasks)) { - input->nFilledLen = 0; /* mark buffer as empty */ - enc_MoveTasks(&priv->used_tasks, &inp->tasks); - return; - } -#endif - - task = list_entry(inp->tasks.next, struct encode_task, list); - list_del(&task->list); - list_addtail(&task->list, &priv->used_tasks); - - if (!task->bitstream) - return; - - /* ------------- map result buffer ----------------- */ - - if (outp->transfer) - pipe_buffer_unmap(priv->t_pipe, outp->transfer); - - pipe_resource_reference(&outp->bitstream, task->bitstream); - pipe_resource_reference(&task->bitstream, NULL); - - box.width = outp->bitstream->width0; - box.height = outp->bitstream->height0; - box.depth = outp->bitstream->depth0; - - output->pBuffer = priv->t_pipe->buffer_map(priv->t_pipe, outp->bitstream, 0, - PIPE_MAP_READ_WRITE, - &box, &outp->transfer); - - /* ------------- get size of result ----------------- */ - - priv->codec->get_feedback(priv->codec, task->feedback, &size, NULL); - - output->nOffset = 0; - output->nFilledLen = size; /* mark buffer as full */ - - /* all output buffers contain exactly one frame */ - output->nFlags = OMX_BUFFERFLAG_ENDOFFRAME; - -#if ENABLE_ST_OMX_TIZONIA - input->nFilledLen = 0; /* mark buffer as empty */ - enc_MoveTasks(&priv->used_tasks, &inp->tasks); -#endif -} - - -struct encode_task *enc_NeedTask_common(vid_enc_PrivateType * priv, OMX_VIDEO_PORTDEFINITIONTYPE *def) -{ - struct pipe_video_buffer templat = {}; - struct encode_task *task; - - if (!list_is_empty(&priv->free_tasks)) { - task = list_entry(priv->free_tasks.next, struct encode_task, list); - list_del(&task->list); - return task; - } - - /* allocate a new one */ - task = CALLOC_STRUCT(encode_task); - if (!task) - return NULL; - - templat.buffer_format = PIPE_FORMAT_NV12; - templat.width = def->nFrameWidth; - templat.height = def->nFrameHeight; - templat.interlaced = false; - - task->buf = priv->s_pipe->create_video_buffer(priv->s_pipe, &templat); - if (!task->buf) { - FREE(task); - return NULL; - } - - return task; -} - -void enc_ScaleInput_common(vid_enc_PrivateType * priv, OMX_VIDEO_PORTDEFINITIONTYPE *def, - struct pipe_video_buffer **vbuf, unsigned *size) -{ - struct pipe_video_buffer *src_buf = *vbuf; - struct vl_compositor *compositor = &priv->compositor; - struct vl_compositor_state *s = &priv->cstate; - struct pipe_sampler_view **views; - struct pipe_surface **dst_surface; - unsigned i; - - if (!priv->scale_buffer[priv->current_scale_buffer]) - return; - - views = src_buf->get_sampler_view_planes(src_buf); - dst_surface = priv->scale_buffer[priv->current_scale_buffer]->get_surfaces - (priv->scale_buffer[priv->current_scale_buffer]); - vl_compositor_clear_layers(s); - - for (i = 0; i < VL_MAX_SURFACES; ++i) { - struct u_rect src_rect; - if (!views[i] || !dst_surface[i]) - continue; - src_rect.x0 = 0; - src_rect.y0 = 0; - src_rect.x1 = def->nFrameWidth; - src_rect.y1 = def->nFrameHeight; - if (i > 0) { - src_rect.x1 /= 2; - src_rect.y1 /= 2; - } - vl_compositor_set_rgba_layer(s, compositor, 0, views[i], &src_rect, NULL, NULL); - vl_compositor_render(s, compositor, dst_surface[i], NULL, false); - } - *size = priv->scale.xWidth * priv->scale.xHeight * 2; - *vbuf = priv->scale_buffer[priv->current_scale_buffer++]; - priv->current_scale_buffer %= OMX_VID_ENC_NUM_SCALING_BUFFERS; -} - -void enc_ControlPicture_common(vid_enc_PrivateType * priv, struct pipe_h264_enc_picture_desc *picture) -{ - struct pipe_h264_enc_rate_control *rate_ctrl = &picture->rate_ctrl[0]; - - /* Get bitrate from port */ - switch (priv->bitrate.eControlRate) { - case OMX_Video_ControlRateVariable: - rate_ctrl->rate_ctrl_method = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE; - break; - case OMX_Video_ControlRateConstant: - rate_ctrl->rate_ctrl_method = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT; - break; - case OMX_Video_ControlRateVariableSkipFrames: - rate_ctrl->rate_ctrl_method = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE_SKIP; - break; - case OMX_Video_ControlRateConstantSkipFrames: - rate_ctrl->rate_ctrl_method = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP; - break; - default: - rate_ctrl->rate_ctrl_method = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE; - break; - } - - rate_ctrl->frame_rate_den = OMX_VID_ENC_CONTROL_FRAME_RATE_DEN_DEFAULT; - rate_ctrl->frame_rate_num = ((priv->frame_rate) >> 16) * rate_ctrl->frame_rate_den; - - if (rate_ctrl->rate_ctrl_method != PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE) { - if (priv->bitrate.nTargetBitrate < OMX_VID_ENC_BITRATE_MIN) - rate_ctrl->target_bitrate = OMX_VID_ENC_BITRATE_MIN; - else if (priv->bitrate.nTargetBitrate < OMX_VID_ENC_BITRATE_MAX) - rate_ctrl->target_bitrate = priv->bitrate.nTargetBitrate; - else - rate_ctrl->target_bitrate = OMX_VID_ENC_BITRATE_MAX; - rate_ctrl->peak_bitrate = rate_ctrl->target_bitrate; - if (rate_ctrl->target_bitrate < OMX_VID_ENC_BITRATE_MEDIAN) - rate_ctrl->vbv_buffer_size = MIN2((rate_ctrl->target_bitrate * 2.75), OMX_VID_ENC_BITRATE_MEDIAN); - else - rate_ctrl->vbv_buffer_size = rate_ctrl->target_bitrate; - - if (rate_ctrl->frame_rate_num) { - unsigned long long t = rate_ctrl->target_bitrate; - t *= rate_ctrl->frame_rate_den; - rate_ctrl->target_bits_picture = t / rate_ctrl->frame_rate_num; - } else { - rate_ctrl->target_bits_picture = rate_ctrl->target_bitrate; - } - rate_ctrl->peak_bits_picture_integer = rate_ctrl->target_bits_picture; - rate_ctrl->peak_bits_picture_fraction = 0; - } - - picture->quant_i_frames = priv->quant.nQpI; - picture->quant_p_frames = priv->quant.nQpP; - picture->quant_b_frames = priv->quant.nQpB; - - picture->frame_num = priv->frame_num; - picture->num_ref_idx_l0_active_minus1 = 0; - picture->ref_idx_l0_list[0] = priv->ref_idx_l0; - picture->num_ref_idx_l1_active_minus1 = 0; - picture->ref_idx_l1_list[0] = priv->ref_idx_l1; - picture->enable_vui = (picture->rate_ctrl[0].frame_rate_num != 0); - enc_GetPictureParamPreset(picture); - - uint8_t ref_idx = (priv->frame_num + 1) % 2; - picture->header_flags.value = 0; - if (picture->picture_type == PIPE_H2645_ENC_PICTURE_TYPE_IDR) { - picture->header_flags.sps = 1; - picture->header_flags.pps = 1; - picture->ref_list0[0] = PIPE_H2645_LIST_REF_INVALID_ENTRY; - } else { - picture->ref_list0[0] = ref_idx; - } - picture->header_flags.aud = 1; - picture->slice.frame_num = priv->frame_num; - picture->slice.pic_order_cnt_lsb = priv->pic_order_cnt % 16; - picture->dpb_size = 2; - picture->dpb_curr_pic = priv->frame_num % 2; - picture->dpb[picture->dpb_curr_pic].frame_idx = priv->frame_num; - picture->dpb[ref_idx].frame_idx = priv->ref_idx_l0; -} - -static void *create_compute_state(struct pipe_context *pipe, - const char *source) -{ - struct tgsi_token tokens[1024]; - struct pipe_compute_state state = {0}; - - if (!tgsi_text_translate(source, tokens, ARRAY_SIZE(tokens))) { - assert(false); - return NULL; - } - - state.ir_type = PIPE_SHADER_IR_TGSI; - state.prog = tokens; - - return pipe->create_compute_state(pipe, &state); -} - -void enc_InitCompute_common(vid_enc_PrivateType *priv) -{ - struct pipe_context *pipe = priv->s_pipe; - struct pipe_screen *screen = pipe->screen; - - /* We need the partial last block support. */ - if (!screen->get_param(screen, PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK)) - return; - - static const char *copy_y = - "COMP\n" - "PROPERTY CS_FIXED_BLOCK_WIDTH 64\n" - "PROPERTY CS_FIXED_BLOCK_HEIGHT 1\n" - "PROPERTY CS_FIXED_BLOCK_DEPTH 1\n" - "DCL SV[0], THREAD_ID\n" - "DCL SV[1], BLOCK_ID\n" - "DCL IMAGE[0], 2D, PIPE_FORMAT_R8_UINT\n" - "DCL IMAGE[1], 2D, PIPE_FORMAT_R8_UINT, WR\n" - "DCL TEMP[0..1]\n" - "IMM[0] UINT32 {64, 0, 0, 0}\n" - - "UMAD TEMP[0].x, SV[1], IMM[0], SV[0]\n" - "MOV TEMP[0].y, SV[1]\n" - "LOAD TEMP[1].x, IMAGE[0], TEMP[0], 2D, PIPE_FORMAT_R8_UINT\n" - "STORE IMAGE[1].x, TEMP[0], TEMP[1], 2D, PIPE_FORMAT_R8_UINT\n" - "END\n"; - - static const char *copy_uv = - "COMP\n" - "PROPERTY CS_FIXED_BLOCK_WIDTH 64\n" - "PROPERTY CS_FIXED_BLOCK_HEIGHT 1\n" - "PROPERTY CS_FIXED_BLOCK_DEPTH 1\n" - "DCL SV[0], THREAD_ID\n" - "DCL SV[1], BLOCK_ID\n" - "DCL IMAGE[0], 2D, PIPE_FORMAT_R8_UINT\n" - "DCL IMAGE[2], 2D, PIPE_FORMAT_R8G8_UINT, WR\n" - "DCL CONST[0][0]\n" /* .x = offset of the UV portion in the y direction */ - "DCL TEMP[0..4]\n" - "IMM[0] UINT32 {64, 0, 2, 1}\n" - /* Destination R8G8 coordinates */ - "UMAD TEMP[0].x, SV[1], IMM[0], SV[0]\n" - "MOV TEMP[0].y, SV[1]\n" - /* Source R8 coordinates of U */ - "UMUL TEMP[1].x, TEMP[0], IMM[0].zzzz\n" - "UADD TEMP[1].y, TEMP[0], CONST[0].xxxx\n" - /* Source R8 coordinates of V */ - "UADD TEMP[2].x, TEMP[1], IMM[0].wwww\n" - "MOV TEMP[2].y, TEMP[1]\n" - - "LOAD TEMP[3].x, IMAGE[0], TEMP[1], 2D, PIPE_FORMAT_R8_UINT\n" - "LOAD TEMP[4].x, IMAGE[0], TEMP[2], 2D, PIPE_FORMAT_R8_UINT\n" - "MOV TEMP[3].y, TEMP[4].xxxx\n" - "STORE IMAGE[2], TEMP[0], TEMP[3], 2D, PIPE_FORMAT_R8G8_UINT\n" - "END\n"; - - priv->copy_y_shader = create_compute_state(pipe, copy_y); - priv->copy_uv_shader = create_compute_state(pipe, copy_uv); -} - -void enc_ReleaseCompute_common(vid_enc_PrivateType *priv) -{ - struct pipe_context *pipe = priv->s_pipe; - - if (priv->copy_y_shader) - pipe->delete_compute_state(pipe, priv->copy_y_shader); - if (priv->copy_uv_shader) - pipe->delete_compute_state(pipe, priv->copy_uv_shader); -} - -OMX_ERRORTYPE enc_LoadImage_common(vid_enc_PrivateType * priv, OMX_VIDEO_PORTDEFINITIONTYPE *def, - OMX_BUFFERHEADERTYPE *buf, - struct pipe_video_buffer *vbuf) -{ - struct pipe_context *pipe = priv->s_pipe; - struct pipe_box box = {}; - struct input_buf_private *inp = buf->pInputPortPrivate; - - if (!inp->resource) { - struct pipe_sampler_view **views; - void *ptr; - - views = vbuf->get_sampler_view_planes(vbuf); - if (!views) - return OMX_ErrorInsufficientResources; - - ptr = buf->pBuffer; - box.width = def->nFrameWidth; - box.height = def->nFrameHeight; - box.depth = 1; - pipe->texture_subdata(pipe, views[0]->texture, 0, - PIPE_MAP_WRITE, &box, - ptr, def->nStride, 0); - ptr = ((uint8_t*)buf->pBuffer) + (def->nStride * box.height); - box.width = def->nFrameWidth / 2; - box.height = def->nFrameHeight / 2; - box.depth = 1; - pipe->texture_subdata(pipe, views[1]->texture, 0, - PIPE_MAP_WRITE, &box, - ptr, def->nStride, 0); - } else { - struct vl_video_buffer *dst_buf = (struct vl_video_buffer *)vbuf; - - pipe_texture_unmap(pipe, inp->transfer); - - /* inp->resource uses PIPE_FORMAT_I8 and the layout looks like this: - * - * def->nFrameWidth = 4, def->nFrameHeight = 4: - * |----| - * |YYYY| - * |YYYY| - * |YYYY| - * |YYYY| - * |UVUV| - * |UVUV| - * |----| - * - * The copy has 2 steps: - * - Copy Y to dst_buf->resources[0] as R8. - * - Copy UV to dst_buf->resources[1] as R8G8. - */ - if (priv->copy_y_shader && priv->copy_uv_shader) { - /* Compute path */ - /* Set shader images for both copies. */ - struct pipe_image_view image[3] = {0}; - image[0].resource = inp->resource; - image[0].shader_access = image[0].access = PIPE_IMAGE_ACCESS_READ; - image[0].format = PIPE_FORMAT_R8_UINT; - - image[1].resource = dst_buf->resources[0]; - image[1].shader_access = image[1].access = PIPE_IMAGE_ACCESS_WRITE; - image[1].format = PIPE_FORMAT_R8_UINT; - - image[2].resource = dst_buf->resources[1]; - image[2].shader_access = image[1].access = PIPE_IMAGE_ACCESS_WRITE; - image[2].format = PIPE_FORMAT_R8G8_UINT; - - pipe->set_shader_images(pipe, PIPE_SHADER_COMPUTE, 0, 3, 0, image); - - /* Set the constant buffer. */ - uint32_t constants[4] = {def->nFrameHeight}; - struct pipe_constant_buffer cb = {}; - - cb.buffer_size = sizeof(constants); - cb.user_buffer = constants; - pipe->set_constant_buffer(pipe, PIPE_SHADER_COMPUTE, 0, false, &cb); - - /* Use the optimal block size for the linear image layout. */ - struct pipe_grid_info info = {}; - info.block[0] = 64; - info.block[1] = 1; - info.block[2] = 1; - info.grid[2] = 1; - - /* Copy Y */ - pipe->bind_compute_state(pipe, priv->copy_y_shader); - - info.grid[0] = DIV_ROUND_UP(def->nFrameWidth, 64); - info.grid[1] = def->nFrameHeight; - info.last_block[0] = def->nFrameWidth % 64; - pipe->launch_grid(pipe, &info); - - /* Copy UV */ - pipe->bind_compute_state(pipe, priv->copy_uv_shader); - - info.grid[0] = DIV_ROUND_UP(def->nFrameWidth / 2, 64); - info.grid[1] = def->nFrameHeight / 2; - info.last_block[0] = (def->nFrameWidth / 2) % 64; - pipe->launch_grid(pipe, &info); - - /* Make the result visible to all clients. */ - pipe->memory_barrier(pipe, PIPE_BARRIER_ALL); - - /* Unbind. */ - pipe->set_shader_images(pipe, PIPE_SHADER_COMPUTE, 0, 0, 3, NULL); - pipe->set_constant_buffer(pipe, PIPE_SHADER_COMPUTE, 0, false, NULL); - pipe->bind_compute_state(pipe, NULL); - } else { - /* Graphics path */ - struct pipe_blit_info blit; - - box.width = def->nFrameWidth; - box.height = def->nFrameHeight; - box.depth = 1; - - /* Copy Y */ - pipe->resource_copy_region(pipe, - dst_buf->resources[0], - 0, 0, 0, 0, inp->resource, 0, &box); - - /* Copy U */ - memset(&blit, 0, sizeof(blit)); - blit.src.resource = inp->resource; - blit.src.format = inp->resource->format; - - blit.src.box.x = -1; - blit.src.box.y = def->nFrameHeight; - blit.src.box.width = def->nFrameWidth; - blit.src.box.height = def->nFrameHeight / 2 ; - blit.src.box.depth = 1; - - blit.dst.resource = dst_buf->resources[1]; - blit.dst.format = blit.dst.resource->format; - - blit.dst.box.width = def->nFrameWidth / 2; - blit.dst.box.height = def->nFrameHeight / 2; - blit.dst.box.depth = 1; - blit.filter = PIPE_TEX_FILTER_NEAREST; - - blit.mask = PIPE_MASK_R; - pipe->blit(pipe, &blit); - - /* Copy V */ - blit.src.box.x = 0; - blit.mask = PIPE_MASK_G; - pipe->blit(pipe, &blit); - } - - pipe->flush(pipe, NULL, 0); - - box.width = inp->resource->width0; - box.height = inp->resource->height0; - box.depth = inp->resource->depth0; - buf->pBuffer = pipe->texture_map(pipe, inp->resource, 0, - PIPE_MAP_WRITE, &box, - &inp->transfer); - } - - return OMX_ErrorNone; -} diff --git a/src/gallium/frontends/omx/vid_enc_common.h b/src/gallium/frontends/omx/vid_enc_common.h deleted file mode 100644 index 8c8830dfcc6..00000000000 --- a/src/gallium/frontends/omx/vid_enc_common.h +++ /dev/null @@ -1,179 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef VID_ENC_COMMON_H -#define VID_ENC_COMMON_H - -#include "util/list.h" -#include "util/u_memory.h" - -#include "vl/vl_defines.h" -#include "vl/vl_compositor.h" -#include "vl/vl_winsys.h" - -#include - -#define OMX_VID_ENC_BITRATE_MIN 64000 -#define OMX_VID_ENC_BITRATE_MEDIAN 2000000 -#define OMX_VID_ENC_BITRATE_MAX 240000000 -#define OMX_VID_ENC_CONTROL_FRAME_RATE_DEN_DEFAULT 1001 -#define OMX_VID_ENC_QUANT_I_FRAMES_DEFAULT 0x1c -#define OMX_VID_ENC_QUANT_P_FRAMES_DEFAULT 0x1c -#define OMX_VID_ENC_QUANT_B_FRAMES_DEFAULT 0x1c -#define OMX_VID_ENC_SCALING_WIDTH_DEFAULT 0xffffffff -#define OMX_VID_ENC_SCALING_HEIGHT_DEFAULT 0xffffffff -#define OMX_VID_ENC_IDR_PERIOD_DEFAULT 1000 -#define OMX_VID_ENC_P_PERIOD_DEFAULT 3 - -#define OMX_VID_ENC_NUM_SCALING_BUFFERS 4 - -struct encode_task { - struct list_head list; - - struct pipe_video_buffer *buf; - unsigned pic_order_cnt; - struct pipe_resource *bitstream; - void *feedback; -}; - -struct input_buf_private { - struct list_head tasks; - - struct pipe_resource *resource; - struct pipe_transfer *transfer; -}; - -struct output_buf_private { - struct pipe_resource *bitstream; - struct pipe_transfer *transfer; -}; - -#if ENABLE_ST_OMX_BELLAGIO - -#include - -DERIVEDCLASS(vid_enc_PrivateType, omx_base_filter_PrivateType) -#define vid_enc_PrivateType_FIELDS omx_base_filter_PrivateType_FIELDS \ - struct vl_screen *screen; \ - struct pipe_context *s_pipe; \ - struct pipe_context *t_pipe; \ - struct pipe_video_codec *codec; \ - struct list_head free_tasks; \ - struct list_head used_tasks; \ - struct list_head b_frames; \ - struct list_head stacked_tasks; \ - OMX_U32 frame_rate; \ - OMX_U32 frame_num; \ - OMX_U32 pic_order_cnt; \ - OMX_U32 ref_idx_l0, ref_idx_l1; \ - OMX_BOOL restricted_b_frames; \ - OMX_VIDEO_PARAM_BITRATETYPE bitrate; \ - OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant; \ - OMX_VIDEO_PARAM_PROFILELEVELTYPE profile_level; \ - OMX_CONFIG_INTRAREFRESHVOPTYPE force_pic_type; \ - struct vl_compositor compositor; \ - struct vl_compositor_state cstate; \ - struct pipe_video_buffer *scale_buffer[OMX_VID_ENC_NUM_SCALING_BUFFERS]; \ - OMX_CONFIG_SCALEFACTORTYPE scale; \ - OMX_U32 current_scale_buffer; \ - OMX_U32 stacked_frames_num; \ - void *copy_y_shader; \ - void *copy_uv_shader; -ENDCLASS(vid_enc_PrivateType) - -#else - -#include -#include - -typedef struct h264e_prc_class h264e_prc_class_t; -struct h264e_prc_class -{ - /* Class */ - const tiz_prc_class_t _; - /* NOTE: Class methods might be added in the future */ -}; - -typedef struct h264e_prc vid_enc_PrivateType; -struct h264e_prc -{ - /* Object */ - const tiz_prc_t _; - OMX_BUFFERHEADERTYPE *p_inhdr_; - OMX_BUFFERHEADERTYPE *p_outhdr_; - OMX_PARAM_PORTDEFINITIONTYPE in_port_def_; - OMX_PARAM_PORTDEFINITIONTYPE out_port_def_; - struct vl_screen *screen; - struct pipe_context *s_pipe; - struct pipe_context *t_pipe; - struct pipe_video_codec *codec; - struct list_head free_tasks; - struct list_head used_tasks; - struct list_head b_frames; - struct list_head stacked_tasks; - OMX_U32 frame_rate; - OMX_U32 frame_num; - OMX_U32 pic_order_cnt; - OMX_U32 ref_idx_l0, ref_idx_l1; - OMX_BOOL restricted_b_frames; - OMX_VIDEO_PARAM_BITRATETYPE bitrate; - OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant; - OMX_VIDEO_PARAM_PROFILELEVELTYPE profile_level; - OMX_CONFIG_INTRAREFRESHVOPTYPE force_pic_type; - struct vl_compositor compositor; - struct vl_compositor_state cstate; - struct pipe_video_buffer *scale_buffer[OMX_VID_ENC_NUM_SCALING_BUFFERS]; - OMX_CONFIG_SCALEFACTORTYPE scale; - OMX_U32 current_scale_buffer; - OMX_U32 stacked_frames_num; - bool eos_; - bool in_port_disabled_; - bool out_port_disabled_; - void *copy_y_shader; - void *copy_uv_shader; -}; -#endif - -void enc_ReleaseTasks(struct list_head *head); -void enc_MoveTasks(struct list_head *from, struct list_head *to); -enum pipe_video_profile enc_TranslateOMXProfileToPipe(unsigned omx_profile); -unsigned enc_TranslateOMXLevelToPipe(unsigned omx_level); -void vid_enc_BufferEncoded_common(vid_enc_PrivateType * priv, OMX_BUFFERHEADERTYPE* input, - OMX_BUFFERHEADERTYPE* output); -struct encode_task *enc_NeedTask_common(vid_enc_PrivateType * priv, - OMX_VIDEO_PORTDEFINITIONTYPE *def); -void enc_ScaleInput_common(vid_enc_PrivateType * priv, - OMX_VIDEO_PORTDEFINITIONTYPE *def, - struct pipe_video_buffer **vbuf, unsigned *size); -void enc_ControlPicture_common(vid_enc_PrivateType * priv, - struct pipe_h264_enc_picture_desc *picture); -void enc_InitCompute_common(vid_enc_PrivateType *priv); -void enc_ReleaseCompute_common(vid_enc_PrivateType *priv); -OMX_ERRORTYPE enc_LoadImage_common(vid_enc_PrivateType * priv, OMX_VIDEO_PORTDEFINITIONTYPE *def, - OMX_BUFFERHEADERTYPE *buf, - struct pipe_video_buffer *vbuf); -#endif diff --git a/src/gallium/frontends/omx/vid_omx_common.c b/src/gallium/frontends/omx/vid_omx_common.c deleted file mode 100644 index b931c28599b..00000000000 --- a/src/gallium/frontends/omx/vid_omx_common.c +++ /dev/null @@ -1,114 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#include -#include -#include - -#if defined(HAVE_X11_PLATFORM) -#include -#else -#define XOpenDisplay(x) NULL -#define XCloseDisplay(x) -#define Display void -#endif - -#include "util/simple_mtx.h" -#include "util/u_thread.h" -#include "util/u_memory.h" -#include "loader/loader.h" - -#include "vid_omx_common.h" - -static simple_mtx_t omx_lock = SIMPLE_MTX_INITIALIZER; -static Display *omx_display = NULL; -static struct vl_screen *omx_screen = NULL; -static unsigned omx_usecount = 0; -static const char *omx_render_node = NULL; -static int drm_fd; - -struct vl_screen *omx_get_screen(void) -{ - static bool first_time = true; - simple_mtx_lock(&omx_lock); - - if (!omx_screen) { - if (first_time) { - omx_render_node = debug_get_option("OMX_RENDER_NODE", NULL); - first_time = false; - } - if (omx_render_node) { - drm_fd = loader_open_device(omx_render_node); - if (drm_fd < 0) - goto error; - - omx_screen = vl_drm_screen_create(drm_fd); - if (!omx_screen) { - close(drm_fd); - goto error; - } - } else { - omx_display = XOpenDisplay(NULL); - if (!omx_display) - goto error; - - omx_screen = vl_dri3_screen_create(omx_display, 0); -#ifdef HAVE_X11_DRI2 - if (!omx_screen) - omx_screen = vl_dri2_screen_create(omx_display, 0); -#endif - if (!omx_screen) { - XCloseDisplay(omx_display); - goto error; - } - } - } - - ++omx_usecount; - - simple_mtx_unlock(&omx_lock); - return omx_screen; - -error: - simple_mtx_unlock(&omx_lock); - return NULL; -} - -void omx_put_screen(void) -{ - simple_mtx_lock(&omx_lock); - if ((--omx_usecount) == 0) { - omx_screen->destroy(omx_screen); - omx_screen = NULL; - - if (omx_render_node) - close(drm_fd); - else - XCloseDisplay(omx_display); - } - simple_mtx_unlock(&omx_lock); -} diff --git a/src/gallium/frontends/omx/vid_omx_common.h b/src/gallium/frontends/omx/vid_omx_common.h deleted file mode 100644 index e27013d1746..00000000000 --- a/src/gallium/frontends/omx/vid_omx_common.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************** - * - * Copyright 2013 Advanced Micro Devices, Inc. - * 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 THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. - * - **************************************************************************/ - -#ifndef VID_OMX_COMMON_H -#define VID_OMX_COMMON_H - -#include "vl/vl_winsys.h" - -struct vl_screen *omx_get_screen(void); -void omx_put_screen(void); - -#endif diff --git a/src/gallium/meson.build b/src/gallium/meson.build index 63298fb5f20..e1bcad455f8 100644 --- a/src/gallium/meson.build +++ b/src/gallium/meson.build @@ -218,10 +218,6 @@ if with_gallium_vdpau subdir('frontends/vdpau') subdir('targets/vdpau') endif -if with_gallium_omx != 'disabled' - subdir('frontends/omx') - subdir('targets/omx') -endif if with_gallium_va subdir('frontends/va') subdir('targets/va') diff --git a/src/gallium/targets/omx/meson.build b/src/gallium/targets/omx/meson.build deleted file mode 100644 index 5bfa7fdcf92..00000000000 --- a/src/gallium/targets/omx/meson.build +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright © 2017-2018 Intel Corporation -# SPDX-License-Identifier: MIT - -# TODO: support non-static targets -# Static targets are always enabled in autotools (unless you modify -# configure.ac) - -omx_link_args = [] -omx_link_depends = [] - -omx_sym = configure_file(input : 'omx.sym.in', output : 'omx.sym', configuration : sym_config) - -if with_ld_version_script - omx_link_args += ['-Wl,--version-script', join_paths(meson.current_build_dir(), 'omx.sym')] - omx_link_depends += omx_sym -endif - -libomx_gallium = shared_library( - 'omx_mesa', - 'omx_target.c', - gnu_symbol_visibility : 'hidden', - link_args : [omx_link_args, ld_args_gc_sections], - include_directories : [ - inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_util, inc_gallium_winsys, inc_gallium_drivers, - ], - link_whole : [libomx_st], - link_with : [ - libgalliumvlwinsys, libgalliumvl, libgallium, - libpipe_loader_static, libws_null, libwsw, libswdri, libswkmsdri, - ], - link_depends : omx_link_depends, - dependencies : [idep_mesautil, driver_r600, driver_radeonsi, driver_nouveau], - install : true, - install_dir : omx_drivers_path, -) diff --git a/src/gallium/targets/omx/omx.sym.in b/src/gallium/targets/omx/omx.sym.in deleted file mode 100644 index 726a8c2b92a..00000000000 --- a/src/gallium/targets/omx/omx.sym.in +++ /dev/null @@ -1,13 +0,0 @@ -{ - global: - OMX_ComponentInit; - omx_component_library_Setup; - - # Workaround for an LLVM warning with -simplifycfg-sink-common - # due to LLVM being initialized multiple times. - @radeon_drm_winsys_create@ - @amdgpu_winsys_create@ - @ac_init_shared_llvm_once@ - local: - *; -}; diff --git a/src/gallium/targets/omx/omx_target.c b/src/gallium/targets/omx/omx_target.c deleted file mode 100644 index 308e23bb4a0..00000000000 --- a/src/gallium/targets/omx/omx_target.c +++ /dev/null @@ -1,2 +0,0 @@ -#include "target-helpers/drm_helper.h" -#include "target-helpers/sw_helper.h" diff --git a/src/gallium/targets/pipe-loader/meson.build b/src/gallium/targets/pipe-loader/meson.build index c7cbcb31eda..368f3c1146a 100644 --- a/src/gallium/targets/pipe-loader/meson.build +++ b/src/gallium/targets/pipe-loader/meson.build @@ -10,7 +10,7 @@ pipe_loader_incs = [ inc_gallium_winsys, inc_gallium_aux, ] -if (with_gallium_va or with_gallium_vdpau or with_gallium_omx != 'disabled') +if (with_gallium_va or with_gallium_vdpau) pipe_loader_link_with += libgalliumvlwinsys endif