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