khronosfws/openmax_al/src/gst_adaptation/xaimagecontrolsitfadaptation.c
changeset 19 4a629bc82c5e
child 20 b67dd1fc57c5
equal deleted inserted replaced
14:80975da52420 19:4a629bc82c5e
       
     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 "xaadaptationgst.h"
       
    20 #include "xamediaplayeradaptctx.h"
       
    21 #include "xamediarecorderadaptctx.h"
       
    22 #include "xacameraadaptctx.h"
       
    23 #include "xaimagecontrolsitfadaptation.h"
       
    24 
       
    25 /*
       
    26  * XAresult XAImageControlsItfAdapt_SetBrightness(XAAdaptationGstCtx *bCtx,
       
    27  *                                                XAuint32 brightness)
       
    28  */
       
    29 XAresult XAImageControlsItfAdapt_SetBrightness(XAAdaptationGstCtx *bCtx,
       
    30                                                XAuint32 brightness)
       
    31 {
       
    32     XAresult ret = XA_RESULT_SUCCESS;
       
    33 
       
    34     gdouble gstBrightness = 0;
       
    35     XAint32 tempBrightness = 0;
       
    36     GstElement *balanceElement = NULL;
       
    37     DEBUG_API("->XAImageControlsItfAdapt_SetBrightness")
       
    38 
       
    39     if(!bCtx || (bCtx->baseObj.ctxId != XAMediaPlayerAdaptation && bCtx->baseObj.ctxId != XAMediaRecorderAdaptation
       
    40        && bCtx->baseObj.ctxId != XACameraAdaptation))
       
    41     {
       
    42         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    43         DEBUG_API("<-XAImageControlsItfAdapt_SetBrightness")
       
    44         return XA_RESULT_PARAMETER_INVALID;
       
    45     }
       
    46 
       
    47     if( bCtx->baseObj.ctxId == XAMediaRecorderAdaptation )
       
    48     {
       
    49         XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
    50 
       
    51         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
    52     }
       
    53     if( bCtx->baseObj.ctxId == XAMediaPlayerAdaptation )
       
    54     {
       
    55         XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
    56 
       
    57         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
    58     }
       
    59     if( bCtx->baseObj.ctxId == XACameraAdaptation )
       
    60     {
       
    61         XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
    62 
       
    63         GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera");
       
    64         if ( !videoPP )
       
    65         {
       
    66             DEBUG_ERR("Could not receive videopp from camerabin!");
       
    67         }
       
    68         else
       
    69         {
       
    70             /* Get camera balance element */
       
    71             balanceElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_balance");
       
    72         }
       
    73     }
       
    74 
       
    75     /* count gstBrightness from XA contrast. Allowed values for gst is -1 to 1
       
    76      * and allowed value for XA is 0 to 100 */
       
    77     tempBrightness = brightness;
       
    78 
       
    79     gstBrightness = ( ((gdouble)tempBrightness - SCALE_VALUE_BRIGHTNESS) / SCALE_VALUE_BRIGHTNESS );
       
    80 
       
    81     if(balanceElement)
       
    82     {
       
    83         g_object_set(G_OBJECT(balanceElement), "brightness", gstBrightness, NULL);
       
    84 
       
    85         if(bCtx->baseObj.ctxId == XAMediaPlayerAdaptation)
       
    86         {
       
    87             ret = XAImageControlsItfAdapt_HandleImageType(bCtx);
       
    88         }
       
    89     }
       
    90 
       
    91 	if ( balanceElement )
       
    92 	{
       
    93         gst_object_unref(balanceElement);
       
    94 	}
       
    95 
       
    96     DEBUG_API("<-XAImageControlsItfAdapt_SetBrightness")
       
    97     return ret;
       
    98 }
       
    99 
       
   100 /*
       
   101  * XAresult XAImageControlsItfAdapt_SetContrast(XAAdaptationGstCtx *bCtx,
       
   102  *                                              XAuint32 contrast)
       
   103  */
       
   104 XAresult XAImageControlsItfAdapt_SetContrast(XAAdaptationGstCtx *bCtx,
       
   105                                              XAint32 contrast)
       
   106 {
       
   107     XAresult ret = XA_RESULT_SUCCESS;
       
   108 
       
   109     gdouble gstContrast = 1;
       
   110     GstElement *balanceElement = NULL;
       
   111     DEBUG_API("->XAImageControlsItfAdapt_SetContrast")
       
   112 
       
   113     if(!bCtx || (bCtx->baseObj.ctxId != XAMediaPlayerAdaptation && bCtx->baseObj.ctxId != XAMediaRecorderAdaptation
       
   114        && bCtx->baseObj.ctxId != XACameraAdaptation))
       
   115     {
       
   116         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   117         DEBUG_API("<-XAImageControlsItfAdapt_SetContrast")
       
   118         return XA_RESULT_PARAMETER_INVALID;
       
   119     }
       
   120 
       
   121     if( bCtx->baseObj.ctxId == XAMediaPlayerAdaptation )
       
   122     {
       
   123         XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   124 
       
   125         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
   126     }
       
   127     if( bCtx->baseObj.ctxId == XAMediaRecorderAdaptation )
       
   128     {
       
   129         XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
   130 
       
   131         balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance");
       
   132     }
       
   133     if( bCtx->baseObj.ctxId == XACameraAdaptation )
       
   134     {
       
   135         XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   136 
       
   137         GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera");
       
   138         if( !videoPP )
       
   139         {
       
   140             DEBUG_ERR("Could not receive videopp from camerabin!");
       
   141         }
       
   142         else
       
   143         {
       
   144             /* Get camera balance element */
       
   145             balanceElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_balance");
       
   146         }
       
   147     }
       
   148 
       
   149     /* count gstContrast from XA contrast. Allowed values for gst is 0 to 2
       
   150      * and allowed value for XA is -100 to 100 */
       
   151     gstContrast = (( (gdouble)contrast + SCALE_VALUE_CONTRAST ) / SCALE_VALUE_CONTRAST );
       
   152 
       
   153     if(balanceElement)
       
   154     {
       
   155         g_object_set(G_OBJECT(balanceElement), "contrast", gstContrast, NULL);
       
   156 
       
   157         if(bCtx->baseObj.ctxId == XAMediaPlayerAdaptation)
       
   158         {
       
   159             ret = XAImageControlsItfAdapt_HandleImageType(bCtx);
       
   160         }
       
   161     }
       
   162 
       
   163 	if ( balanceElement )
       
   164 	{
       
   165         gst_object_unref(balanceElement);
       
   166 	}
       
   167 
       
   168     DEBUG_API("<-XAImageControlsItfAdapt_SetContrast")
       
   169     return ret;
       
   170 }
       
   171 
       
   172 /*
       
   173  * XAresult XAImageControlsItfAdapt_SetGamma(XAAdaptationGstCtx *bCtx,
       
   174  *                                           XApermille gamma)
       
   175  */
       
   176 XAresult XAImageControlsItfAdapt_SetGamma(XAAdaptationGstCtx *bCtx,
       
   177                                           XApermille gamma)
       
   178 {
       
   179     XAresult ret = XA_RESULT_SUCCESS;
       
   180 
       
   181     gdouble gstGamma=0;
       
   182     GstElement *gammaElement = NULL;
       
   183     DEBUG_API("->XAImageControlsItfAdapt_SetGamma")
       
   184 
       
   185     if(!bCtx || (bCtx->baseObj.ctxId != XAMediaPlayerAdaptation && bCtx->baseObj.ctxId != XAMediaRecorderAdaptation
       
   186        && bCtx->baseObj.ctxId != XACameraAdaptation))
       
   187     {
       
   188         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   189         DEBUG_API("<-XAImageControlsItfAdapt_SetGamma")
       
   190         return XA_RESULT_PARAMETER_INVALID;
       
   191     }
       
   192 
       
   193     if( bCtx->baseObj.ctxId == XAMediaPlayerAdaptation )
       
   194     {
       
   195         XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   196 
       
   197         gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma");
       
   198     }
       
   199 
       
   200     if( bCtx->baseObj.ctxId == XAMediaRecorderAdaptation )
       
   201     {
       
   202         XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
       
   203 
       
   204         gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma");
       
   205     }
       
   206 
       
   207     if( bCtx->baseObj.ctxId == XACameraAdaptation )
       
   208     {
       
   209         XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx;
       
   210 
       
   211         GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera");
       
   212         if( !videoPP )
       
   213         {
       
   214             DEBUG_ERR("Could not receive videopp from camerabin!");
       
   215         }
       
   216         else
       
   217         {
       
   218             /* Get camera gamma element */
       
   219             gammaElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_gamma");
       
   220         }
       
   221     }
       
   222 
       
   223     /* count gstGamma from XA gamma */
       
   224     gstGamma = ( (gdouble)gamma / SCALE_VALUE_GAMMA );
       
   225 
       
   226     if(gammaElement)
       
   227     {
       
   228         g_object_set(G_OBJECT(gammaElement), "gamma", gstGamma, NULL);
       
   229 
       
   230         if(bCtx->baseObj.ctxId == XAMediaPlayerAdaptation)
       
   231         {
       
   232             ret = XAImageControlsItfAdapt_HandleImageType(bCtx);
       
   233         }
       
   234     }
       
   235 
       
   236 	if ( gammaElement )
       
   237 	{
       
   238         gst_object_unref(gammaElement);
       
   239 	}
       
   240 
       
   241     DEBUG_API("<-XAImageControlsItfAdapt_SetGamma")
       
   242     return ret;
       
   243 }
       
   244 
       
   245 /*
       
   246  * XAresult XAImageControlsItfAdapt_GetSupportedGammaSettings(XAAdaptationGstCtx *bCtx,
       
   247  *                                                            XApermille *pMinValue,
       
   248  *                                                            XApermille *pMaxValue,
       
   249  *                                                            XAuint32 *pNumSettings,
       
   250  *                                                            XApermille **ppSettings)
       
   251  */
       
   252 XAresult XAImageControlsItfAdapt_GetSupportedGammaSettings(XAAdaptationGstCtx *bCtx,
       
   253                                                            XApermille *pMinValue,
       
   254                                                            XApermille *pMaxValue,
       
   255                                                            XAuint32 *pNumSettings,
       
   256                                                            XApermille **ppSettings)
       
   257 {
       
   258     XAresult ret = XA_RESULT_SUCCESS;
       
   259     DEBUG_API("->XAImageControlsItfAdapt_GetSupportedGammaSettings")
       
   260 
       
   261     if(!bCtx || (bCtx->baseObj.ctxId != XAMediaPlayerAdaptation && bCtx->baseObj.ctxId != XAMediaRecorderAdaptation
       
   262        && bCtx->baseObj.ctxId != XACameraAdaptation) || !pMinValue || !pMaxValue || !pNumSettings)
       
   263     {
       
   264         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   265         /* invalid parameter */
       
   266         DEBUG_API("<-XAImageControlsItfAdapt_GetSupportedGammaSettings")
       
   267         return XA_RESULT_PARAMETER_INVALID;
       
   268     }
       
   269 
       
   270     *pMinValue = MIN_GAMMA_VALUE;
       
   271     *pMaxValue = MAX_GAMMA_VALUE;
       
   272 
       
   273     /* manual settings is continuous from min to max then pNumSetting return 0. */
       
   274     *pNumSettings = 0;
       
   275 
       
   276     DEBUG_API("<-XAImageControlsItfAdapt_GetSupportedGammaSettings")
       
   277     return ret;
       
   278 }
       
   279 /*
       
   280  * XAresult XAImageControlsItfAdapt_HandleImageType(XAAdaptationGstCtx *bCtx)
       
   281  * Description: this run gstreamer for image type
       
   282  *
       
   283  */
       
   284 XAresult XAImageControlsItfAdapt_HandleImageType(XAAdaptationGstCtx *bCtx)
       
   285 {
       
   286     XAresult ret = XA_RESULT_SUCCESS;
       
   287     XADataSource *dataSrc = NULL;
       
   288     GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS;
       
   289     GstState gstOrigState = GST_STATE_PLAYING;
       
   290     GstState gstTmpState = GST_STATE_PLAYING;
       
   291     XAMediaPlayerAdaptationCtx* mCtx = NULL;
       
   292     DEBUG_API("->XAImageControlsItfAdapt_HandleImageType");
       
   293 
       
   294     if( !bCtx || (bCtx->baseObj.ctxId != XAMediaPlayerAdaptation) )
       
   295     {
       
   296         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   297         DEBUG_API("<-XAImageControlsItfAdapt_HandleImageType")
       
   298         return XA_RESULT_PARAMETER_INVALID;
       
   299     }
       
   300 
       
   301     mCtx = (XAMediaPlayerAdaptationCtx*) bCtx;
       
   302 
       
   303     dataSrc = mCtx->xaSource;
       
   304 
       
   305     if( dataSrc )
       
   306     {
       
   307         XAMediaType mediaType;
       
   308         ret = XACommon_CheckDataSource(dataSrc, &mediaType);
       
   309         if( ret == XA_RESULT_SUCCESS && mediaType == XA_MEDIATYPE_IMAGE )
       
   310         {
       
   311             gstOrigState = GST_STATE(bCtx->bin);
       
   312 
       
   313             DEBUG_INFO_A1("Sending change state request to state %d", GST_STATE_READY);
       
   314             gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), GST_STATE_READY);
       
   315             gstTmpState = GST_STATE(bCtx->bin);
       
   316             if(gstRet == GST_STATE_CHANGE_SUCCESS && gstTmpState == GST_STATE_READY)
       
   317                 {
       
   318                 DEBUG_INFO_A1("Sending change state request to state %d", gstOrigState);
       
   319                 gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), gstOrigState);
       
   320                 }
       
   321         }
       
   322     }
       
   323     DEBUG_API("<-XAImageControlsItfAdapt_HandleImageType");
       
   324     return ret;
       
   325 }