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