khronosfws/openmax_al/src/adaptation/xavideopostprosessingitfadaptation.c
changeset 16 43d09473c595
parent 14 80975da52420
child 22 128eb6a32b84
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
     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 <gst.h>
       
    19 #include <video.h>
       
    20 #include "XAAdaptation.h"
       
    21 #include "XAMediaPlayerAdaptCtx.h"
       
    22 #include "XAMediaRecorderAdaptCtx.h"
       
    23 #include "XACameraAdaptCtx.h"
       
    24 #include "XAVideoPostProsessingItfAdaptation.h"
       
    25 #include "XAStaticCameraCapsAdaptation.h"
       
    26 
       
    27 /*
       
    28  * XAresult XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported(XAAdaptationBaseCtx *bCtx,
       
    29  *                                                                     XAboolean *pSupported)
       
    30  */
       
    31 XAresult XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported(XAAdaptationBaseCtx *bCtx,
       
    32                                                                     XAboolean *pSupported)
       
    33 {
       
    34     XAresult ret = XA_RESULT_SUCCESS;
       
    35     DEBUG_API("->XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported");
       
    36 
       
    37     if(!bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation
       
    38             && bCtx->ctxId != XACameraAdaptation) || !pSupported)
       
    39     {
       
    40         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    41         DEBUG_API("<-XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported");
       
    42         return XA_RESULT_PARAMETER_INVALID;
       
    43     }
       
    44 
       
    45     /* This feature is not supported, return boolean false */
       
    46     *pSupported = XA_BOOLEAN_FALSE;
       
    47 
       
    48     DEBUG_API("<-XAVideoPostProcessingItfAdapt_IsArbitraryRotationSupported");
       
    49     return ret;
       
    50 }
       
    51 
       
    52 /*
       
    53  * XAresult XAVideoPostProcessingItfAdapt_Commit(XAAdaptationBaseCtx *bCtx)
       
    54  */
       
    55 XAresult XAVideoPostProcessingItfAdapt_Commit(XAAdaptationBaseCtx *bCtx,
       
    56                                               XAmillidegree rotation,
       
    57                                               XAuint32 scaleOptions,
       
    58                                               XAuint32 backgroundColor,
       
    59                                               XAuint32 renderingHints,
       
    60                                               const XARectangle *pSrcRect,
       
    61                                               const XARectangle *pDestRect,
       
    62                                               XAuint32 mirror,
       
    63                                               XAboolean isMirror,
       
    64                                               XAboolean isRotate,
       
    65                                               XAboolean isDestRect,
       
    66                                               XAboolean isSrcRect,
       
    67                                               XAboolean isScaleOptions
       
    68                                               )
       
    69 {
       
    70     XAresult ret = XA_RESULT_SUCCESS;
       
    71     XAmillidegree tempRotation = 0;
       
    72     XAmillidegree newRotation = 0;
       
    73     XAuint32 tempMirror = XA_VIDEOMIRROR_NONE;
       
    74     XAuint32 newMirror = XA_VIDEOMIRROR_NONE;
       
    75     XADataSource *dataSrc = NULL;
       
    76     GstElement *cropElement = NULL;
       
    77     GstElement *rotateElement = NULL;
       
    78     GstElement *mirrorElement = NULL;
       
    79     GstElement *boxElement = NULL;
       
    80     GstElement *balanceElement = NULL;
       
    81     GstElement *gammaElement = NULL;
       
    82     GstElement *sink = NULL;
       
    83     GstElement *col1 = NULL;
       
    84     GstElement *scale = NULL;
       
    85     gdouble     alphaValue = 1;
       
    86     gint        videoBackgroundColor = 0,
       
    87                 cropscaleRight = 0, cropscaleBottom = 0,
       
    88                 cropscaleLeft = 0,
       
    89                 cropscaleTop = 0,
       
    90                 videoscaleHeight = 0;
       
    91     GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS;
       
    92     GstState gstOrigState = GST_STATE_PLAYING;
       
    93     GstState gstTmpState = GST_STATE_PLAYING;
       
    94 
       
    95     DEBUG_API("->XAVideoPostProcessingItfAdapt_Commit");
       
    96 
       
    97     if( !bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation
       
    98         && bCtx->ctxId != XACameraAdaptation))
       
    99     {
       
   100         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   101         DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit");
       
   102         return XA_RESULT_PARAMETER_INVALID;
       
   103     }
       
   104 
       
   105     if( bCtx->ctxId == XAMediaPlayerAdaptation )
       
   106     {
       
   107         XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   108 
       
   109 
       
   110         /* Get video pp elements */
       
   111         GstPad *pad = NULL;
       
   112         GstCaps *caps = NULL;
       
   113         col1 = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_colsp1");
       
   114         cropElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_crop");
       
   115         rotateElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_rotate");
       
   116         mirrorElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_mirror");
       
   117         boxElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_box");
       
   118         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
   119         gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma");
       
   120         sink = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videosink");
       
   121         pad = gst_element_get_static_pad(GST_ELEMENT(sink),"sink");
       
   122         caps = gst_caps_new_simple("video/x-raw-yuv",
       
   123                  "width", G_TYPE_INT,0,
       
   124                  "height", G_TYPE_INT,0,
       
   125                  NULL);
       
   126         gst_pad_set_caps(pad, caps);
       
   127 
       
   128         /* get current mirror state and rotate value */
       
   129         tempMirror = ctx->curMirror;
       
   130         tempRotation = ctx->curRotation;
       
   131         dataSrc = ctx->xaSource;
       
   132     }
       
   133 
       
   134     if( bCtx->ctxId == XAMediaRecorderAdaptation )
       
   135     {
       
   136         XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
   137 
       
   138         /* Get video pp elements */
       
   139         GstPad *pad = NULL;
       
   140         GstCaps *caps = NULL;
       
   141         scale = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_scale2");
       
   142         col1 = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_colsp1");
       
   143         cropElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_crop");
       
   144         rotateElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_rotate");
       
   145         mirrorElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_mirror");
       
   146         boxElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_box");
       
   147         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
   148         gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma");
       
   149         sink = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "datasink");
       
   150         pad = gst_element_get_static_pad(GST_ELEMENT(sink),"sink");
       
   151         caps = gst_caps_new_simple("video/x-raw-yuv",
       
   152                  "width", G_TYPE_INT,0,
       
   153                  "height", G_TYPE_INT,0,
       
   154                  NULL);
       
   155         gst_pad_set_caps(pad, caps);
       
   156 
       
   157         /* get current mirror state and rotate value */
       
   158         tempMirror = ctx->curMirror;
       
   159         tempRotation = ctx->curRotation;
       
   160     }
       
   161 
       
   162     if( bCtx->ctxId == XACameraAdaptation )
       
   163     {
       
   164         XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   165 
       
   166         GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera");
       
   167         if( !videoPP )
       
   168         {
       
   169             DEBUG_ERR("Could not receive videopp from camerabin!");
       
   170         }
       
   171         else
       
   172         {
       
   173             /* Get camera pp elements */
       
   174             GstPad *pad = NULL;
       
   175             GstCaps *caps = NULL;
       
   176             rotateElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_rotate");
       
   177             col1 = gst_bin_get_by_name( GST_BIN(videoPP), "pp_colsp1");
       
   178             cropElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_crop");
       
   179             mirrorElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_mirror");
       
   180             boxElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_box");
       
   181             balanceElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_balance");
       
   182             gammaElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_gamma");
       
   183             sink = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_crop");
       
   184             pad = gst_element_get_static_pad(GST_ELEMENT(sink),"sink");
       
   185             caps = gst_caps_new_simple("video/x-raw-yuv",
       
   186                      "width", G_TYPE_INT,0,
       
   187                      "height", G_TYPE_INT,0,
       
   188                      NULL);
       
   189             gst_pad_set_caps(pad, caps);
       
   190 
       
   191             /* get current mirror state and rotate value */
       
   192             tempMirror = ctx->curMirror;
       
   193             tempRotation = ctx->curRotation;
       
   194         }
       
   195     }
       
   196 
       
   197     /* Cropping */
       
   198     if( isSrcRect && pSrcRect && cropElement && col1 )
       
   199     {
       
   200 
       
   201         gint        cropRight = 0;
       
   202         gint        cropBottom = 0;
       
   203         gint        cropLeft = 0;
       
   204         gint        cropTop = 0;
       
   205         GstPad      *videoPad = NULL;
       
   206         gint        videoWidth = 0;
       
   207         gint        videoHeight = 0;
       
   208         DEBUG_INFO("Start cropping!");
       
   209 
       
   210         DEBUG_INFO_A1("pSrcRect->left:%d",(int)pSrcRect->left);
       
   211         DEBUG_INFO_A1("pSrcRect->top:%d",(int)pSrcRect->top);
       
   212         DEBUG_INFO_A1("pSrcRect->width:%d",(int)pSrcRect->width);
       
   213         DEBUG_INFO_A1("pSrcRect->height:%d", (int)pSrcRect->height);
       
   214 
       
   215         if( bCtx->ctxId == XACameraAdaptation )
       
   216         {
       
   217             GstCaps *caps = NULL;
       
   218             XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   219             gint capsCount = 0;
       
   220             gint iterator = 0;
       
   221             GstStructure *capsStruct = NULL;
       
   222 
       
   223             g_object_get( G_OBJECT(ctx->baseObj.bin), "filter-caps", &caps, NULL );
       
   224 
       
   225             if( !caps )
       
   226             {
       
   227                 DEBUG_ERR("Cannot receive caps (filter-caps) from camerabin!");
       
   228                 DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_RESULT_INTERNAL_ERROR");
       
   229                 return XA_RESULT_INTERNAL_ERROR;
       
   230             }
       
   231 
       
   232             capsCount = gst_caps_get_size( caps );
       
   233 
       
   234             for( iterator= 0; iterator < capsCount; iterator++ )
       
   235             {
       
   236                 capsStruct = gst_caps_get_structure( caps, iterator );
       
   237                 if( capsStruct )
       
   238                 {
       
   239                     if( !gst_structure_get_int( capsStruct, "width", &videoWidth ) )
       
   240                     {
       
   241                         DEBUG_ERR("Could not get width from filter-caps");
       
   242                         videoWidth = TEST_VIDEO_WIDTH;
       
   243                     }
       
   244                     if( !gst_structure_get_int( capsStruct, "height", &videoHeight) )
       
   245                     {
       
   246                         DEBUG_ERR("Could not get height from filter-caps");
       
   247                         videoHeight = TEST_VIDEO_HEIGHT;
       
   248                     }
       
   249                     DEBUG_INFO_A2("videoWidth:%d, videoHeight:%d",videoWidth,videoHeight);
       
   250                 }
       
   251             }
       
   252         }
       
   253         else
       
   254         {
       
   255             GstCaps* negcapas=NULL;
       
   256             videoPad = gst_element_get_pad( col1, "src" );
       
   257             negcapas = gst_pad_get_negotiated_caps( GST_PAD(videoPad) );
       
   258             if ( negcapas )
       
   259             {
       
   260                 if( !gst_video_get_size( videoPad, &videoWidth, &videoHeight ) )
       
   261                 {
       
   262                     DEBUG_ERR("WARN: Cannot receive video size, using defaults");
       
   263                     videoWidth = TEST_VIDEO_WIDTH;
       
   264                     videoHeight = TEST_VIDEO_HEIGHT;
       
   265                 }
       
   266             }
       
   267             else
       
   268             {
       
   269 				videoWidth = TEST_VIDEO_WIDTH;
       
   270 				videoHeight = TEST_VIDEO_HEIGHT;
       
   271             }
       
   272         }
       
   273 
       
   274         DEBUG_INFO_A2("Received video frame info, videoWidth:%d, videoHeight:%d",videoWidth,videoHeight);
       
   275         cropLeft = (gint)pSrcRect->left;
       
   276         cropTop = (gint)pSrcRect->top;
       
   277         cropRight = videoWidth - ((gint)pSrcRect->left + (gint)pSrcRect->width);
       
   278         cropBottom = videoHeight - ((gint)pSrcRect->top + (gint)pSrcRect->height);
       
   279         DEBUG_INFO_A4("Crop values - cropLeft:%d ,cropTop:%d,cropRight:%d,cropBottom:%d", cropLeft,cropTop,cropRight,cropBottom);
       
   280 
       
   281         if( cropBottom >= 0 && cropLeft >=0 && cropRight >= 0  && cropTop >= 0 )
       
   282         {
       
   283             g_object_set(G_OBJECT(cropElement), "bottom",cropBottom, NULL);
       
   284             g_object_set(G_OBJECT(cropElement), "left", cropLeft, NULL);
       
   285             g_object_set(G_OBJECT(cropElement), "right", cropRight, NULL);
       
   286             g_object_set(G_OBJECT(cropElement), "top", cropTop, NULL);
       
   287         }
       
   288         else
       
   289         {
       
   290             if( cropLeft > videoWidth || cropLeft < 0 ||
       
   291                 cropRight > videoWidth || cropRight < 0 ||
       
   292                 cropBottom > videoHeight || cropBottom < 0 ||
       
   293                 cropTop > videoHeight || cropTop < 0)
       
   294             {
       
   295                 DEBUG_INFO("Cropped params out of original frame.");
       
   296             }
       
   297         }
       
   298     }
       
   299 
       
   300     if(rotateElement && isRotate)
       
   301     {
       
   302         DEBUG_INFO("Start rotating!");
       
   303 
       
   304         /* calculate rotation */
       
   305         newRotation = tempRotation + rotation;
       
   306 
       
   307         if( newRotation > ROTATION_RATIO || newRotation < ROTATION_RATIO_NEG )
       
   308         {
       
   309             newRotation = newRotation % ROTATION_RATIO;
       
   310         }
       
   311 
       
   312         /* Set rotation */
       
   313         switch(newRotation)
       
   314         {
       
   315             case 0:
       
   316             {
       
   317                 /* no rotation */
       
   318                 DEBUG_INFO("Set rotation FLIP_NONE");
       
   319                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_NONE, NULL);
       
   320                 break;
       
   321             }
       
   322             case 90000:
       
   323             case -270000:
       
   324             {
       
   325                 /* rotation 90 degree */
       
   326                 DEBUG_INFO("Set rotation 90 degrees");
       
   327                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_CLOCKWISE, NULL);
       
   328                 break;
       
   329             }
       
   330             case 180000:
       
   331             case -180000:
       
   332             {
       
   333                 /* rotation 180 degree */
       
   334                 DEBUG_INFO("Set rotation 180 degrees");
       
   335                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_ROTATE_180, NULL);
       
   336                 break;
       
   337             }
       
   338             case 270000:
       
   339             case -90000:
       
   340             {
       
   341                 /* rotation 270 degree */
       
   342                 DEBUG_INFO("Set rotation 270 degrees");
       
   343                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_COUNTERCLOCKWISE, NULL);
       
   344                 break;
       
   345             }
       
   346             case 360000:
       
   347             case -360000:
       
   348             {
       
   349                 /* rotation 360 degree */
       
   350                 DEBUG_INFO("Set rotation 360 degrees");
       
   351                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_NONE, NULL);
       
   352                 break;
       
   353             }
       
   354             default:
       
   355             {
       
   356                 /* no rotation */
       
   357                 DEBUG_INFO("Set rotation default (FLIP_NONE) degree");
       
   358                 g_object_set(G_OBJECT(rotateElement), "method", FLIP_NONE, NULL);
       
   359                 break;
       
   360             }
       
   361         }
       
   362 
       
   363         /* Store current rotate value */
       
   364         if( bCtx->ctxId == XAMediaPlayerAdaptation )
       
   365         {
       
   366             XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   367             ctx->curRotation = newRotation;
       
   368         }
       
   369         if( bCtx->ctxId == XAMediaRecorderAdaptation )
       
   370         {
       
   371             XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
   372             ctx->curRotation = newRotation;
       
   373         }
       
   374         if( bCtx->ctxId == XACameraAdaptation )
       
   375         {
       
   376             XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   377             ctx->curRotation = newRotation;
       
   378         }
       
   379     }
       
   380 
       
   381     if(mirrorElement && isMirror)
       
   382     {
       
   383         /* solve new mirror state */
       
   384         switch(mirror)
       
   385         {
       
   386             case XA_VIDEOMIRROR_NONE:
       
   387             {
       
   388                 newMirror = tempMirror;
       
   389                 break;
       
   390             }
       
   391             case XA_VIDEOMIRROR_VERTICAL:
       
   392             {
       
   393                 if( tempMirror == XA_VIDEOMIRROR_VERTICAL )
       
   394                 {
       
   395                     newMirror = XA_VIDEOMIRROR_NONE;
       
   396                 }
       
   397                 else if( tempMirror == XA_VIDEOMIRROR_HORIZONTAL )
       
   398                 {
       
   399                     newMirror = XA_VIDEOMIRROR_BOTH;
       
   400                 }
       
   401                 else if( tempMirror == XA_VIDEOMIRROR_BOTH )
       
   402                 {
       
   403                     newMirror = XA_VIDEOMIRROR_HORIZONTAL;
       
   404                 }
       
   405                 else
       
   406                 {
       
   407                     newMirror = XA_VIDEOMIRROR_VERTICAL;
       
   408                 }
       
   409                 break;
       
   410             }
       
   411             case XA_VIDEOMIRROR_HORIZONTAL:
       
   412             {
       
   413                 if( tempMirror == XA_VIDEOMIRROR_VERTICAL )
       
   414                 {
       
   415                     newMirror = XA_VIDEOMIRROR_BOTH;
       
   416                 }
       
   417                 else if( tempMirror == XA_VIDEOMIRROR_HORIZONTAL )
       
   418                 {
       
   419                     newMirror = XA_VIDEOMIRROR_NONE;
       
   420                 }
       
   421                 else if( tempMirror == XA_VIDEOMIRROR_BOTH )
       
   422                 {
       
   423                     newMirror = XA_VIDEOMIRROR_VERTICAL;
       
   424                 }
       
   425                 else
       
   426                 {
       
   427                     newMirror = XA_VIDEOMIRROR_HORIZONTAL;
       
   428                 }
       
   429                 break;
       
   430             }
       
   431             case XA_VIDEOMIRROR_BOTH:
       
   432             {
       
   433                 if( tempMirror == XA_VIDEOMIRROR_VERTICAL )
       
   434                 {
       
   435                     newMirror = XA_VIDEOMIRROR_HORIZONTAL;
       
   436                 }
       
   437                 else if( tempMirror == XA_VIDEOMIRROR_HORIZONTAL )
       
   438                 {
       
   439                     newMirror = XA_VIDEOMIRROR_VERTICAL;
       
   440                 }
       
   441                 else if( tempMirror == XA_VIDEOMIRROR_BOTH )
       
   442                 {
       
   443                     newMirror = XA_VIDEOMIRROR_NONE;
       
   444                 }
       
   445                 else
       
   446                 {
       
   447                     newMirror = XA_VIDEOMIRROR_BOTH;
       
   448                 }
       
   449                 break;
       
   450             }
       
   451             default:
       
   452                 break;
       
   453         }
       
   454 
       
   455 
       
   456         DEBUG_INFO("Start mirroring!");
       
   457         /* Set mirror */
       
   458         switch(newMirror)
       
   459         {
       
   460             case XA_VIDEOMIRROR_NONE:
       
   461             {
       
   462                 /* none */
       
   463                 DEBUG_INFO("Set mirror none");
       
   464                 g_object_set(G_OBJECT(mirrorElement), "method", FLIP_NONE, NULL);
       
   465                 break;
       
   466             }
       
   467             case XA_VIDEOMIRROR_VERTICAL:
       
   468             {
       
   469                 /* vertical mirror */
       
   470                 DEBUG_INFO("Set mirror vertical");
       
   471                 g_object_set(G_OBJECT(mirrorElement), "method", FLIP_VERTICAL, NULL);
       
   472                 break;
       
   473             }
       
   474             case XA_VIDEOMIRROR_HORIZONTAL:
       
   475             {
       
   476                 /* horizontal mirror */
       
   477                 DEBUG_INFO("Set mirror horizontal");
       
   478                 g_object_set(G_OBJECT(mirrorElement), "method", FLIP_HORIZONTAL, NULL);
       
   479                 break;
       
   480             }
       
   481             case XA_VIDEOMIRROR_BOTH:
       
   482             {
       
   483                 /* both mirror */
       
   484                 DEBUG_INFO("Set mirror vertical and horizontal");
       
   485                 g_object_set(G_OBJECT(mirrorElement), "method", FLIP_ROTATE_180, NULL);
       
   486                 break;
       
   487             }
       
   488             default:
       
   489             {
       
   490                 /* Default no mirroring */
       
   491                 g_object_set(G_OBJECT(mirrorElement), "method", FLIP_NONE, NULL);
       
   492                 break;
       
   493             }
       
   494         }
       
   495 
       
   496         /* Store current mirror state */
       
   497         if( bCtx->ctxId == XAMediaPlayerAdaptation )
       
   498         {
       
   499             XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   500             ctx->curMirror = newMirror;
       
   501         }
       
   502         if( bCtx->ctxId == XAMediaRecorderAdaptation )
       
   503         {
       
   504             XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
   505             ctx->curMirror = newMirror;
       
   506         }
       
   507         if( bCtx->ctxId == XACameraAdaptation )
       
   508         {
       
   509             XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   510             ctx->curMirror = newMirror;
       
   511         }
       
   512     }
       
   513 
       
   514     /* Set scale */
       
   515     if ( isScaleOptions || isDestRect || isSrcRect )
       
   516     {
       
   517 		switch( scaleOptions )
       
   518 		{
       
   519 
       
   520 			case XA_VIDEOSCALE_STRETCH:
       
   521 			{
       
   522 				DEBUG_INFO("XA_VIDEOSCALE_STRETCH");
       
   523 				/* The source and destination rectangle's width and height params are used to calculate
       
   524 				 * the scaling factors independently. Aspect ratio is ignored. */
       
   525 				if (pDestRect)
       
   526 				{
       
   527 					if (bCtx->ctxId != XAMediaRecorderAdaptation)
       
   528 					{
       
   529 						GstPad *pad = NULL;
       
   530 						GstCaps* simplecaps = NULL;
       
   531 						g_object_set ( G_OBJECT(sink), "force-aspect-ratio", FALSE, NULL);
       
   532 						simplecaps = gst_caps_new_simple("video/x-raw-rgb",
       
   533 											"width", G_TYPE_INT, pDestRect->width,
       
   534 											"height", G_TYPE_INT, pDestRect->height,
       
   535 											"framerate", GST_TYPE_FRACTION, 0,1,
       
   536 											NULL);
       
   537 						DEBUG_API_A1("caps: %s",gst_caps_to_string(simplecaps));
       
   538 						pad = gst_element_get_static_pad(GST_ELEMENT(sink),"sink");
       
   539 						if (!gst_pad_set_caps(pad, simplecaps))
       
   540 						{
       
   541 							DEBUG_INFO("Stubbed at this point");
       
   542 							DEBUG_INFO("Cannot set destrect size during XA_VIDEOSCALE_STRETCH!");
       
   543 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_VIDEOSCALE_STRETCH");
       
   544 							return XA_RESULT_SUCCESS;
       
   545 						}
       
   546 						DEBUG_API_A1("ret: %lu",ret);
       
   547 					}
       
   548 					else
       
   549 					{
       
   550 						GstCaps* simplecaps = NULL;
       
   551 						GstPad *pad = NULL;
       
   552 						if ( !scale )
       
   553 						{
       
   554 							DEBUG_ERR("Could not get scaling element from pipeline!");
       
   555 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_RESULT_INTERNAL_ERROR");
       
   556 							return XA_RESULT_INTERNAL_ERROR;
       
   557 						}
       
   558 						simplecaps = gst_caps_new_simple("video/x-raw-yuv",
       
   559 											"width", G_TYPE_INT, pDestRect->width,
       
   560 											"height", G_TYPE_INT, pDestRect->height,
       
   561 											"framerate", GST_TYPE_FRACTION, 0,1,
       
   562 											NULL);
       
   563 						DEBUG_API_A1("caps: %s",gst_caps_to_string(simplecaps));
       
   564 						pad = gst_element_get_static_pad(GST_ELEMENT(scale),"src");
       
   565 						if (!gst_pad_set_caps(pad, simplecaps))
       
   566 						{
       
   567 							DEBUG_INFO("Stubbed at this point");
       
   568 							DEBUG_INFO("Cannot set destrect size during XA_VIDEOSCALE_STRETCH!");
       
   569 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_VIDEOSCALE_STRETCH");
       
   570 							return XA_RESULT_SUCCESS;
       
   571 						}
       
   572 
       
   573 					}
       
   574 				}
       
   575 				DEBUG_INFO("XA_VIDEOSCALE_STRETCH Done");
       
   576 
       
   577 				break;
       
   578 			}
       
   579 			case XA_VIDEOSCALE_FIT:
       
   580 			{
       
   581 				DEBUG_INFO("XA_VIDEOSCALE_FIT");
       
   582 				/* The miminum scale factor between the destination rectangle's width over the
       
   583 				 * source rectangle's source rectangle's width and the destination rectangle's height over
       
   584 				 * the source rectangle's height is used. Aspect ratio is maintained. Frame is centered */
       
   585 				if (pDestRect)
       
   586 				{
       
   587 					if (bCtx->ctxId != XAMediaRecorderAdaptation)
       
   588 					{
       
   589 						GstPad *pad = NULL;
       
   590 						GstCaps* simplecaps = NULL;
       
   591 						g_object_set ( G_OBJECT(sink), "force-aspect-ratio", TRUE, NULL);
       
   592 						simplecaps = gst_caps_new_simple("video/x-raw-rgb",
       
   593 											"width", G_TYPE_INT, pDestRect->width,
       
   594 											"height", G_TYPE_INT, pDestRect->height,
       
   595 											"framerate", GST_TYPE_FRACTION, 0,1,
       
   596 											NULL);
       
   597 						DEBUG_API_A1("caps: %s",gst_caps_to_string(simplecaps));
       
   598 						pad = gst_element_get_static_pad(GST_ELEMENT(sink),"sink");
       
   599 						if (!gst_pad_set_caps(pad, simplecaps))
       
   600 						{
       
   601 							DEBUG_INFO("Stubbed at this point");
       
   602 							DEBUG_INFO("Cannot set destrect size during XA_VIDEOSCALE_FIT!");
       
   603 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_VIDEOSCALE_FIT");
       
   604 							return XA_RESULT_SUCCESS;
       
   605 						}
       
   606 					}
       
   607 					else
       
   608 					{
       
   609 						GstPad *videoScalePad = NULL;
       
   610 						GstCaps *negcaps = NULL;
       
   611 						gint videoScalePadHeight = 0, videoScalePadWidth = 0;
       
   612 						gfloat scaleFactorWidth = 0;
       
   613 						gfloat scaleFactorHeight = 0;
       
   614 						gfloat scaleFactor = 0;
       
   615 						videoScalePad = gst_element_get_pad( col1, "src" );
       
   616 						negcaps = gst_pad_get_negotiated_caps( GST_PAD(videoScalePad) );
       
   617 						if ( negcaps )
       
   618 						{
       
   619 							if( !gst_video_get_size( videoScalePad, &videoScalePadWidth, &videoScalePadHeight ) )
       
   620 							{
       
   621 								DEBUG_ERR("Cannot receive current cropscalevideo size!");
       
   622 								DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_RESULT_INTERNAL_ERROR");
       
   623 								return XA_RESULT_INTERNAL_ERROR;
       
   624 							}
       
   625 						}
       
   626 						else
       
   627 						{
       
   628 							DEBUG_ERR("No negotiated caps in col1:src!");
       
   629 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit");
       
   630 							return XA_RESULT_SUCCESS;
       
   631 						}
       
   632 						if (pSrcRect->width != 0 && pSrcRect->height != 0)
       
   633 						{
       
   634 							scaleFactorWidth = (gfloat)videoScalePadWidth / (gfloat)pSrcRect->width;
       
   635 							scaleFactorHeight = (gfloat)videoScalePadHeight / (gfloat)pSrcRect->height;
       
   636 							if (scaleFactorWidth < scaleFactorHeight)
       
   637 							{
       
   638 								scaleFactor = scaleFactorWidth;
       
   639 							}
       
   640 							else
       
   641 							{
       
   642 								scaleFactor = scaleFactorHeight;
       
   643 							}
       
   644 
       
   645 							cropscaleBottom = (gint)(pSrcRect->height*scaleFactor - videoScalePadHeight)/2;
       
   646 							cropscaleLeft = (gint)(pSrcRect->width*scaleFactor - videoScalePadWidth)/2;
       
   647 							if (cropscaleLeft > 0){
       
   648 								cropscaleLeft *= -1;
       
   649 							}
       
   650 							cropscaleRight = cropscaleLeft;
       
   651 							if (cropscaleBottom > 0){
       
   652 								cropscaleBottom *= -1;
       
   653 							}
       
   654 							cropscaleTop = cropscaleBottom;
       
   655 							g_object_set (G_OBJECT (boxElement), "bottom", cropscaleBottom , NULL);
       
   656 							g_object_set (G_OBJECT (boxElement), "right", cropscaleRight, NULL);
       
   657 							g_object_set (G_OBJECT (boxElement), "left", cropscaleLeft, NULL);
       
   658 							g_object_set (G_OBJECT (boxElement), "top", cropscaleTop, NULL);
       
   659 						}
       
   660 					}
       
   661 				}
       
   662 				DEBUG_INFO("XA_VIDEOSCALE_FIT done");
       
   663 
       
   664 				break;
       
   665 			}
       
   666 			case XA_VIDEOSCALE_CROP:
       
   667 			{
       
   668 				DEBUG_INFO("XA_VIDEOSCALE_CROP");
       
   669 				/* The maximum scale factor between the destination rectangle's width over the source
       
   670 				 * rectangle's width and destination rectangle's height over the source rectangle's
       
   671 				 * height is used. Aspect ratio is maintained. Frame is centered. */
       
   672 				if( pDestRect && pSrcRect )
       
   673 				{
       
   674 					GstPad *videoScalePad = NULL;
       
   675 					GstCaps *negcaps = NULL;
       
   676 					gint videoScalePadHeight = 0, videoScalePadWidth = 0;
       
   677 					videoScalePad = gst_element_get_pad( col1, "src" );
       
   678 					negcaps = gst_pad_get_negotiated_caps( GST_PAD(videoScalePad) );
       
   679 					if ( negcaps )
       
   680 					{
       
   681 						if( !gst_video_get_size( videoScalePad, &videoScalePadWidth, &videoScalePadHeight ) )
       
   682 						{
       
   683 							DEBUG_ERR("Cannot receive current cropscalevideo size!");
       
   684 							DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit - XA_RESULT_INTERNAL_ERROR");
       
   685 							return XA_RESULT_INTERNAL_ERROR;
       
   686 						}
       
   687 					}
       
   688 					else
       
   689 					{
       
   690 						DEBUG_ERR("No negotiated caps in col1:src!");
       
   691 						DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit");
       
   692 						return XA_RESULT_SUCCESS;
       
   693 					}
       
   694 
       
   695 					DEBUG_INFO_A2( "Received video scale frame info, videoScalePadWidth:%d, "
       
   696 									"videoScalePadHeight:%d",videoScalePadWidth,videoScalePadHeight);
       
   697 
       
   698 					if( pSrcRect->height > 0 && pSrcRect->width > 0 )
       
   699 					{
       
   700 						if( pSrcRect->height > pDestRect->height )
       
   701 						{
       
   702 							videoscaleHeight = pSrcRect->height;
       
   703 							if( pDestRect->top == 0)
       
   704 							{
       
   705 								cropscaleTop = ((videoscaleHeight - pDestRect->height)/2);
       
   706 								cropscaleBottom = ((videoscaleHeight - pDestRect->height)/2);
       
   707 							}
       
   708 							else
       
   709 							{
       
   710 								cropscaleTop = (pDestRect->top/2);
       
   711 								cropscaleBottom = (pDestRect->top/2);
       
   712 							}
       
   713 						}
       
   714 						else if( pDestRect->height > pSrcRect->height )
       
   715 						{
       
   716 							videoscaleHeight = pDestRect->height;
       
   717 							if( pDestRect->top == 0)
       
   718 							{
       
   719 								cropscaleTop = -((videoscaleHeight - pSrcRect->height)/2);
       
   720 								cropscaleBottom = -((videoscaleHeight - pSrcRect->height)/2);
       
   721 							}
       
   722 							else
       
   723 							{
       
   724 								cropscaleTop = -(pDestRect->top/2);
       
   725 								cropscaleBottom = -(pDestRect->top/2);
       
   726 							}
       
   727 						}
       
   728 						else if( pDestRect->height == pSrcRect->height )
       
   729 						{
       
   730 						}
       
   731 						else
       
   732 						{
       
   733 						}
       
   734 						if( pSrcRect->width > pDestRect->width )
       
   735 						{
       
   736 							if( pDestRect->left == 0 )
       
   737 							{
       
   738 								cropscaleLeft = ((gint)(pSrcRect->width -pDestRect->width)/2);
       
   739 								cropscaleRight = ((gint)(pSrcRect->width -pDestRect->width)/2);
       
   740 							}
       
   741 							else
       
   742 							{
       
   743 								cropscaleLeft = (pDestRect->left/2);
       
   744 								cropscaleRight = (pDestRect->left/2);
       
   745 							}
       
   746 						}
       
   747 						else if( pDestRect->width > pSrcRect->width )
       
   748 						{
       
   749 							if( pDestRect->left == 0 )
       
   750 							{
       
   751 								cropscaleLeft =-((gint)(pDestRect->width -pSrcRect->width)/2);
       
   752 								cropscaleRight =-((gint)(pDestRect->width -pSrcRect->width)/2);
       
   753 							}
       
   754 							else
       
   755 							{
       
   756 								cropscaleLeft = -(pDestRect->left/2);
       
   757 								cropscaleRight = -(pDestRect->left/2);
       
   758 							}
       
   759 						}
       
   760 						else if( pDestRect->width == pSrcRect->width )
       
   761 						{
       
   762 						}
       
   763 						else
       
   764 						{
       
   765 						}
       
   766 					}
       
   767 					else
       
   768 					{
       
   769 						DEBUG_ERR("Invalid rectangle values in source rectangles");
       
   770 						DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit, Exit with invalid source rectangle values");
       
   771 						return XA_RESULT_PARAMETER_INVALID;
       
   772 					}
       
   773 					if( pDestRect->width != pSrcRect->width && pDestRect->height != pSrcRect->height )
       
   774 					{
       
   775 						  DEBUG_INFO_A4("Crop values - cropscaleLeft:%d "
       
   776 										",cropscaleTop:%d,"
       
   777 										"cropscaleRight:%d,"
       
   778 										"cropscaleBottom:%d",
       
   779 										cropscaleLeft,
       
   780 										cropscaleTop,
       
   781 										cropscaleRight,
       
   782 										cropscaleBottom);
       
   783 						g_object_set (G_OBJECT (boxElement), "bottom",cropscaleBottom , NULL);
       
   784 						g_object_set (G_OBJECT (boxElement), "right", cropscaleRight, NULL);
       
   785 						g_object_set (G_OBJECT (boxElement), "left", cropscaleLeft, NULL);
       
   786 						g_object_set (G_OBJECT (boxElement), "top",cropscaleTop, NULL);
       
   787 					}
       
   788 				}
       
   789 				break;
       
   790 			}
       
   791 			default:
       
   792 				DEBUG_INFO("no scale options!");
       
   793 				break;
       
   794 		}
       
   795     }
       
   796 
       
   797     if(pDestRect && boxElement)
       
   798     {
       
   799         /* is background color black */
       
   800         if((backgroundColor >> 8) & BLACK_BG_COLOR_MASK)
       
   801         {
       
   802             videoBackgroundColor = 0;
       
   803         }
       
   804         /* is background color green */
       
   805         else if((backgroundColor >> 8) & GREEN_BG_COLOR_MASK)
       
   806         {
       
   807             videoBackgroundColor = 1;
       
   808         }
       
   809         /* is background color blue */
       
   810         else if((backgroundColor >> 8) & BLUE_BG_COLOR_MASK)
       
   811         {
       
   812             videoBackgroundColor = 2;
       
   813         }
       
   814         else
       
   815         {
       
   816             /* by default black */
       
   817             videoBackgroundColor = 0;
       
   818         }
       
   819 
       
   820         /* check alpha value. Gst support values 0 to 1 and XA 0 to 255 */
       
   821         {
       
   822             XAuint32 tempColor = 0;
       
   823             tempColor = backgroundColor & ALPHA_VALUE_MASK;
       
   824 
       
   825             alphaValue = (gdouble)(tempColor/ALPHA_VALUE_MASK);
       
   826         }
       
   827     }
       
   828 
       
   829     if( dataSrc )
       
   830     {
       
   831         XAMediaType mediaType = XA_MEDIATYPE_UNKNOWN;
       
   832         ret = XACommon_CheckDataSource(dataSrc, &mediaType);
       
   833         if( ret == XA_RESULT_SUCCESS && mediaType == XA_MEDIATYPE_IMAGE )
       
   834         {
       
   835             gstOrigState = GST_STATE(bCtx->bin);
       
   836 
       
   837             DEBUG_INFO_A1("Sending change state request to state %d", GST_STATE_READY);
       
   838             gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), GST_STATE_READY);
       
   839             gstTmpState = GST_STATE(bCtx->bin);
       
   840 
       
   841             DEBUG_INFO_A1("Sending change state request to state %d", gstOrigState);
       
   842             gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), gstOrigState);
       
   843         }
       
   844     }
       
   845 
       
   846     DEBUG_API("<-XAVideoPostProcessingItfAdapt_Commit");
       
   847     return ret;
       
   848 }
       
   849 /*
       
   850  * XAresult XAVideoPostProcessingItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adapCtx)
       
   851  * Description: Safety thread entry
       
   852  */
       
   853 XAresult XAVideoPostProcessingItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adaptCtx)
       
   854 {
       
   855     DEBUG_API("->XAVideoPostProcessingItfAdapt_ThreadEntry");
       
   856     if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation &&
       
   857                         adaptCtx->ctxId != XAMediaRecorderAdaptation &&
       
   858                         adaptCtx->ctxId != XACameraAdaptation ))
       
   859     {
       
   860         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   861         DEBUG_API("<-XAVideoPostProcessingItfAdapt_ThreadEntry");
       
   862         /* invalid parameter */
       
   863         return XA_RESULT_PARAMETER_INVALID;
       
   864 
       
   865     }
       
   866 
       
   867     if ( adaptCtx->ctxId == XAMediaPlayerAdaptation )
       
   868     {
       
   869         XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaPlayer);
       
   870     }
       
   871     else if( adaptCtx->ctxId == XAMediaRecorderAdaptation )
       
   872     {
       
   873         XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaRecorder);
       
   874     }
       
   875     else if (adaptCtx->ctxId == XACameraAdaptation )
       
   876     {
       
   877         XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera);
       
   878     }
       
   879 
       
   880     DEBUG_API("<-XAVideoPostProcessingItfAdapt_ThreadEntry");
       
   881     return XA_RESULT_SUCCESS;
       
   882 }
       
   883 /*
       
   884  * XAresult XAVideoPostProcessingItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx)
       
   885  * Description: Safety thread exit
       
   886  */
       
   887 XAresult XAVideoPostProcessingItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx)
       
   888 {
       
   889     DEBUG_API("->XAVideoPostProcessingItfAdapt_ThreadExit");
       
   890     if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation &&
       
   891                         adaptCtx->ctxId != XAMediaRecorderAdaptation &&
       
   892                         adaptCtx->ctxId != XACameraAdaptation ))
       
   893     {
       
   894         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   895         DEBUG_API("<-XAVideoPostProcessingItfAdapt_ThreadExit");
       
   896         /* invalid parameter */
       
   897         return XA_RESULT_PARAMETER_INVALID;
       
   898 
       
   899     }
       
   900 
       
   901     if ( adaptCtx->ctxId == XAMediaPlayerAdaptation )
       
   902     {
       
   903         XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaPlayer);
       
   904     }
       
   905     else if( adaptCtx->ctxId == XAMediaRecorderAdaptation )
       
   906     {
       
   907         XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaRecorder);
       
   908     }
       
   909     else if (adaptCtx->ctxId == XACameraAdaptation )
       
   910     {
       
   911         XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   912     }
       
   913 
       
   914     DEBUG_API("<-XAVideoPostProcessingItfAdapt_ThreadExit");
       
   915     return XA_RESULT_SUCCESS;
       
   916 }