khronosfws/openmax_al/src/common/xavideopostprocessingitf.c
changeset 12 5a06f39ad45b
child 16 43d09473c595
equal deleted inserted replaced
0:71ca22bcf22a 12:5a06f39ad45b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <assert.h>
       
    21 #include "xavideopostprocessingitf.h"
       
    22 #ifdef _GSTREAMER_BACKEND_  
       
    23 #include "XAVideoPostProsessingItfAdaptation.h"
       
    24 #endif
       
    25 /**
       
    26  * XAVideoPostProcessingItfImpl* GetImpl(XAVideoPostProcessingItf self)
       
    27  * Description: Validated interface pointer and cast it to implementations pointer.
       
    28  **/
       
    29 static XAVideoPostProcessingItfImpl* GetImpl(XAVideoPostProcessingItf self)
       
    30 {
       
    31     if(self)
       
    32     {
       
    33         XAVideoPostProcessingItfImpl* impl = (XAVideoPostProcessingItfImpl*)(*self);
       
    34         if(impl && (impl == impl->self))
       
    35         {
       
    36             return impl;
       
    37         }
       
    38     }
       
    39     return NULL;
       
    40 }
       
    41 
       
    42 /**
       
    43  * Base interface XAVideoPostProcessingItf implementation
       
    44  */
       
    45 
       
    46 /**
       
    47  * XAresult XAVideoPostProcessingItfImpl_SetRotation(XAVideoPostProcessingItf self,
       
    48  *                                                   XAmillidegree rotation)
       
    49  * Description: Sets post-prosessing options for rotation.
       
    50  **/
       
    51 XAresult XAVideoPostProcessingItfImpl_SetRotation(XAVideoPostProcessingItf self,
       
    52                                                   XAmillidegree rotation)
       
    53 {
       
    54     XAresult ret = XA_RESULT_SUCCESS;
       
    55     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
    56     XAboolean isSupported = XA_BOOLEAN_FALSE;
       
    57     DEBUG_API("->XAVideoPostProcessingItfImpl_SetRotation");
       
    58 
       
    59     if(!impl)
       
    60     {
       
    61         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    62         DEBUG_API("<-XAVideoPostProcessingItfImpl_SetRotation");
       
    63         /* invalid parameter */
       
    64         return XA_RESULT_PARAMETER_INVALID;
       
    65     }
       
    66 
       
    67     /* Check is arbitrary rotation supported */
       
    68     ret = XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported( self, &isSupported );
       
    69 
       
    70     if(ret == XA_RESULT_SUCCESS)
       
    71     {
       
    72         if( isSupported == XA_BOOLEAN_FALSE )
       
    73         {
       
    74             /* check that wanted angle is integer multiple of 90 degrees */
       
    75             if( rotation % 90000 != 0 )
       
    76             {
       
    77                 /* feature unsupported */
       
    78                 ret = XA_RESULT_FEATURE_UNSUPPORTED;
       
    79                 return ret;
       
    80             }
       
    81         }
       
    82 
       
    83         impl->rotation = rotation;
       
    84         impl->isRotate = XA_BOOLEAN_TRUE;
       
    85     }
       
    86 
       
    87     DEBUG_API("<-XAVideoPostProcessingItfImpl_SetRotation");
       
    88     return ret;
       
    89 }
       
    90 
       
    91 /**
       
    92  * XAresult XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported(XAVideoPostProcessingItf self,
       
    93  *                                                                    XAboolean *pSupported)
       
    94  * Description: Determines if arbitrary rotation angles are supported by the implementation.
       
    95  */
       
    96 XAresult XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported(XAVideoPostProcessingItf self,
       
    97                                                                    XAboolean *pSupported)
       
    98 {
       
    99     XAresult ret = XA_RESULT_SUCCESS;
       
   100     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   101     DEBUG_API("->XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported");
       
   102     if(!impl || !pSupported)
       
   103     {
       
   104         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   105         DEBUG_API("<-XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported");
       
   106         /* invalid parameter */
       
   107         return XA_RESULT_PARAMETER_INVALID;
       
   108     }
       
   109 #ifdef _GSTREAMER_BACKEND_  
       
   110     ret = XAVideoPostProcessingItfAdapt_ThreadEntry(impl->adapCtx);
       
   111     if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
       
   112     {
       
   113     	DEBUG_API("<-XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported");
       
   114     	return ret;
       
   115     }
       
   116 
       
   117     ret = XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported(impl->adapCtx,
       
   118                                                                      pSupported);
       
   119 
       
   120     if(ret == XA_RESULT_SUCCESS)
       
   121     {
       
   122         impl->supported = *pSupported;
       
   123     }
       
   124 
       
   125     XAVideoPostProcessingItfAdapt_ThreadExit(impl->adapCtx);
       
   126 #endif
       
   127     DEBUG_API("<-XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported");
       
   128     return ret;
       
   129 }
       
   130 
       
   131 /**
       
   132  * XAresult XAVideoPostProcessingItfImpl_SetScaleOptions(XAVideoPostProcessingItf self,
       
   133  *                                                       XAuint32 scaleOptions,
       
   134  *                                                       XAuint32 backgroundColor,
       
   135  *                                                       XAuint32 renderingHints)
       
   136  * Description: Sets the options for scaling
       
   137  */
       
   138 XAresult XAVideoPostProcessingItfImpl_SetScaleOptions(XAVideoPostProcessingItf self,
       
   139                                                       XAuint32 scaleOptions,
       
   140                                                       XAuint32 backgroundColor,
       
   141                                                       XAuint32 renderingHints)
       
   142 {
       
   143     XAresult ret = XA_RESULT_SUCCESS;
       
   144     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   145     DEBUG_API("->XAVideoPostProcessingItfImpl_SetScaleOptions");
       
   146 
       
   147     if(!impl || (scaleOptions != XA_VIDEOSCALE_STRETCH && scaleOptions != XA_VIDEOSCALE_FIT
       
   148         && scaleOptions != XA_VIDEOSCALE_CROP))
       
   149     {
       
   150         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   151         DEBUG_API("<-XAVideoPostProcessingItfImpl_SetScaleOptions");
       
   152         /* invalid parameter */
       
   153         return XA_RESULT_PARAMETER_INVALID;
       
   154     }
       
   155 
       
   156     impl->scaleOptions = scaleOptions;
       
   157     impl->backgroundColor = backgroundColor;
       
   158     impl->renderingHints = renderingHints;
       
   159     impl->isScaleOptions = XA_BOOLEAN_TRUE;
       
   160 
       
   161     DEBUG_API("<-XAVideoPostProcessingItfImpl_SetScaleOptions");
       
   162     return ret;
       
   163 }
       
   164 
       
   165 /**
       
   166  * XAresult XAVideoPostProcessingItfImpl_SetSourceRectangle(XAVideoPostProcessingItf self,
       
   167  *                                                          const XARectangle *pSrcRect)
       
   168  * Description: Defines the rectangle in the original frame that is to be used for further processing
       
   169  */
       
   170 XAresult XAVideoPostProcessingItfImpl_SetSourceRectangle(XAVideoPostProcessingItf self,
       
   171                                                          const XARectangle *pSrcRect)
       
   172 {
       
   173     XAresult ret = XA_RESULT_SUCCESS;
       
   174     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   175     DEBUG_API("->XAVideoPostProcessingItfImpl_SetSourceRectangle");
       
   176 
       
   177     if(!impl || !pSrcRect)
       
   178     {
       
   179         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   180         DEBUG_API("<-XAVideoPostProcessingItfImpl_SetSourceRectangle");
       
   181         /* invalid parameter */
       
   182         return XA_RESULT_PARAMETER_INVALID;
       
   183     }
       
   184 
       
   185     impl->srcRect = *pSrcRect;
       
   186     impl->isSrcRect = XA_BOOLEAN_TRUE;
       
   187 
       
   188     DEBUG_API("<-XAVideoPostProcessingItfImpl_SetSourceRectangle");
       
   189     return ret;
       
   190 }
       
   191 
       
   192 /**
       
   193  * XAresult XAVideoPostProcessingItfImpl_SetDestinationRectangle(XAVideoPostProcessingItf self,
       
   194  *                                                               const XARectangle *pDestRect)
       
   195  *
       
   196  * Description:  Defines the destination rectangle for the processed frame. This rectangle,
       
   197  * in conjunction with the scaling options used  (fit, crop, stretch) determines
       
   198  * the scaling applied to the frame.
       
   199  */
       
   200 XAresult XAVideoPostProcessingItfImpl_SetDestinationRectangle(XAVideoPostProcessingItf self,
       
   201                                                               const XARectangle *pDestRect)
       
   202 {
       
   203     XAresult ret = XA_RESULT_SUCCESS;
       
   204     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   205     DEBUG_API("->XAVideoPostProcessingItfImpl_SetDestinationRectangle");
       
   206 
       
   207     if(!impl || !pDestRect)
       
   208     {
       
   209         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   210         DEBUG_API("<-XAVideoPostProcessingItfImpl_SetDestinationRectangle");
       
   211         /* invalid parameter */
       
   212         return XA_RESULT_PARAMETER_INVALID;
       
   213     }
       
   214 
       
   215     impl->destRect = *pDestRect;
       
   216     impl->isDestRect = XA_BOOLEAN_TRUE;
       
   217 
       
   218     DEBUG_API("<-XAVideoPostProcessingItfImpl_SetDestinationRectangle");
       
   219     return ret;
       
   220 }
       
   221 
       
   222 /**
       
   223  * XAresult XAVideoPostProcessingItfImpl_SetMirror(XAVideoPostProcessingItf self,
       
   224  *                                                 XAuint32 mirror)
       
   225  * Description: Sets post-prosessing options for mirroring.
       
   226  */
       
   227 XAresult XAVideoPostProcessingItfImpl_SetMirror(XAVideoPostProcessingItf self,
       
   228                                                 XAuint32 mirror)
       
   229 {
       
   230     XAresult ret = XA_RESULT_SUCCESS;
       
   231     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   232     DEBUG_API("->XAVideoPostProcessingItfImpl_SetMirror");
       
   233 
       
   234     if(!impl || (mirror != XA_VIDEOMIRROR_NONE && mirror != XA_VIDEOMIRROR_VERTICAL
       
   235        && mirror != XA_VIDEOMIRROR_HORIZONTAL && mirror != XA_VIDEOMIRROR_BOTH ))
       
   236     {
       
   237         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   238         DEBUG_API("<-XAVideoPostProcessingItfImpl_SetMirror");
       
   239         /* invalid parameter */
       
   240         return XA_RESULT_PARAMETER_INVALID;
       
   241     }
       
   242 
       
   243     impl->mirror = mirror;
       
   244     impl->isMirror = XA_BOOLEAN_TRUE;
       
   245 
       
   246     DEBUG_API("<-XAVideoPostProcessingItfImpl_SetMirror");
       
   247     return ret;
       
   248 }
       
   249 
       
   250 /**
       
   251  * XAresult XAVideoPostProcessingItfImpl_Commit(XAVideoPostProcessingItf self)
       
   252  * Description: Commit all video post-processing changes since the last Commit().
       
   253  */
       
   254 XAresult XAVideoPostProcessingItfImpl_Commit(XAVideoPostProcessingItf self)
       
   255 {
       
   256     XAresult ret = XA_RESULT_SUCCESS;
       
   257     XAVideoPostProcessingItfImpl* impl = GetImpl(self);
       
   258     DEBUG_API("->XAVideoPostProcessingItfImpl_Commit");
       
   259     if(!impl)
       
   260     {
       
   261         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   262         DEBUG_API("<-XAVideoPostProcessingItfImpl_Commit");
       
   263         /* invalid parameter */
       
   264         return XA_RESULT_PARAMETER_INVALID;
       
   265     }
       
   266 
       
   267 #ifdef _GSTREAMER_BACKEND_  
       
   268     ret = XAVideoPostProcessingItfAdapt_ThreadEntry(impl->adapCtx);
       
   269     if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
       
   270     {
       
   271     	DEBUG_API("<-XAVideoPostProcessingItfImpl_Commit");
       
   272     	return ret;
       
   273     }
       
   274 
       
   275     ret = XAVideoPostProcessingItfAdapt_Commit(impl->adapCtx,
       
   276                                                impl->rotation,
       
   277                                                impl->scaleOptions,
       
   278                                                impl->backgroundColor,
       
   279                                                impl->renderingHints,
       
   280                                                &impl->srcRect,
       
   281                                                &impl->destRect,
       
   282                                                impl->mirror,
       
   283                                                impl->isMirror,
       
   284                                                impl->isRotate,
       
   285                                                impl->isDestRect,
       
   286 											   impl->isSrcRect,
       
   287 											   impl->isScaleOptions);
       
   288 
       
   289     if( ret == XA_RESULT_SUCCESS )
       
   290     {
       
   291         impl->isMirror = XA_BOOLEAN_FALSE;
       
   292         impl->isRotate = XA_BOOLEAN_FALSE;
       
   293 		impl->isDestRect = XA_BOOLEAN_FALSE;
       
   294 		impl->isSrcRect = XA_BOOLEAN_FALSE;
       
   295 		impl->isScaleOptions = XA_BOOLEAN_FALSE;
       
   296     }
       
   297 
       
   298     XAVideoPostProcessingItfAdapt_ThreadExit(impl->adapCtx);
       
   299 #endif    
       
   300     DEBUG_API("<-XAVideoPostProcessingItfImpl_Commit");
       
   301     return ret;
       
   302 }
       
   303 
       
   304 /**
       
   305  * XAVideoPostProcessingItfImpl -specific methods
       
   306  **/
       
   307 #ifdef _GSTREAMER_BACKEND_  
       
   308 
       
   309 /**
       
   310  * XAVideoPostProcessingItfImpl* XAVideoPostProcessingItfImpl_Create()
       
   311  * @return  XAVideoPostProcessingItfImpl* - Pointer to  VideoPostProcessingItf interface implementation
       
   312  **/
       
   313 XAVideoPostProcessingItfImpl* XAVideoPostProcessingItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
       
   314 {
       
   315     XAVideoPostProcessingItfImpl* self = (XAVideoPostProcessingItfImpl*)
       
   316         calloc(1,sizeof(XAVideoPostProcessingItfImpl));
       
   317     DEBUG_API("->XAVideoPostProcessingItfImpl_Create");
       
   318     if(self)
       
   319     {
       
   320         XARectangle emptyRect = {0,0,0,0};
       
   321         /* init itf default implementation */
       
   322         self->itf.Commit = XAVideoPostProcessingItfImpl_Commit;
       
   323         self->itf.IsArbitraryRotationSupported = XAVideoPostProcessingItfImpl_IsArbitraryRotationSupported;
       
   324         self->itf.SetDestinationRectangle = XAVideoPostProcessingItfImpl_SetDestinationRectangle;
       
   325         self->itf.SetMirror = XAVideoPostProcessingItfImpl_SetMirror;
       
   326         self->itf.SetRotation = XAVideoPostProcessingItfImpl_SetRotation;
       
   327         self->itf.SetScaleOptions = XAVideoPostProcessingItfImpl_SetScaleOptions;
       
   328         self->itf.SetSourceRectangle = XAVideoPostProcessingItfImpl_SetSourceRectangle;
       
   329 
       
   330         /* init variables */
       
   331         self->rotation = 0;
       
   332         self->scaleOptions = XA_VIDEOSCALE_FIT;
       
   333         self->mirror = XA_VIDEOMIRROR_NONE;
       
   334         self->backgroundColor = 0;
       
   335         self->renderingHints = XA_RENDERINGHINT_NONE;
       
   336         self->adapCtx = adapCtx;
       
   337         self->srcRect = emptyRect;
       
   338         self->destRect = emptyRect;
       
   339         self->isMirror = XA_BOOLEAN_FALSE;
       
   340         self->isRotate = XA_BOOLEAN_FALSE;
       
   341         self->isDestRect = XA_BOOLEAN_FALSE;
       
   342         self->isSrcRect = XA_BOOLEAN_FALSE;
       
   343         self->isScaleOptions = XA_BOOLEAN_FALSE;
       
   344 
       
   345         self->self = self;
       
   346     }
       
   347     DEBUG_API("<-XAVideoPostProcessingItfImpl_Create");
       
   348     return self;
       
   349 }
       
   350 #endif
       
   351 /**
       
   352  * void XAVideoPostProcessingItfImpl_Free(XAVideoPostProcessingItfImpl* self);
       
   353  * @param  XAVideoPostProcessingItfImpl* self -
       
   354  **/
       
   355 void XAVideoPostProcessingItfImpl_Free(XAVideoPostProcessingItfImpl* self)
       
   356 {
       
   357     DEBUG_API("->XAVideoPostProcessingItfImpl_Free");
       
   358     assert(self==self->self);
       
   359     free(self);
       
   360     DEBUG_API("<-XAVideoPostProcessingItfImpl_Free");
       
   361 }