videoeditorengine/h263decoder/src/vdemain.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Video decoder engine main module.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 /*
       
    24  * Includes
       
    25  */
       
    26 
       
    27 #include "h263dConfig.h"
       
    28 
       
    29 #include "vdemain.h"
       
    30 #include "renapi.h"
       
    31 #include "rendri.h"
       
    32 #include "h263dext.h"
       
    33 #include "vde.h"
       
    34 
       
    35 #include "biblin.h"
       
    36 
       
    37 
       
    38 /*
       
    39  * Global functions
       
    40  */
       
    41   
       
    42 /* {{-output"vdeFree.txt"}} */
       
    43 /*
       
    44  * vdeFree
       
    45  *    
       
    46  *
       
    47  * Parameters:
       
    48  *    Nothing
       
    49  *
       
    50  * Function:
       
    51  *    This function deinitializes this module.
       
    52  *
       
    53  * Returns:
       
    54  *    VDE_OK                     if the function was successful
       
    55  *    VDE_ERROR                  indicating a general error
       
    56  *
       
    57  *    
       
    58  */
       
    59 
       
    60 int vdeFree(void)
       
    61 /* {{-output"vdeFree.txt"}} */
       
    62 {
       
    63    if (vdcFree() < 0)
       
    64       return VDE_ERROR;
       
    65 
       
    66    return VDE_OK;
       
    67 }
       
    68 
       
    69 
       
    70 /* {{-output"vdeGetLatestFrame.txt"}} */
       
    71 /*
       
    72  * vdeGetLatestFrame
       
    73  *    
       
    74  *
       
    75  * Parameters:
       
    76  *    hInstance                  instance data
       
    77  *    
       
    78  *    ppy, ppu, ppv              used to return Y, U and V frame pointers
       
    79  *
       
    80  *    pLumWidth, pLumHeight      used to return luminance image width and height
       
    81  *                               Note these values can be counted on even if
       
    82  *                               the function returns an error.
       
    83  *
       
    84  *    pFrameNum                  used to return frame number
       
    85  *
       
    86  * Function:
       
    87  *    This function returns the latest correctly decoded frame
       
    88  *    (and some side-information).
       
    89  *
       
    90  *    Note that no thread synchronization is used since the function
       
    91  *    is used only from the mobidntc.c and it is very likely that
       
    92  *    the same decoder instance is used only from a single calling
       
    93  *    thread at the same time.
       
    94  *
       
    95  * Returns:
       
    96  *    VDE_OK                     if the function was successful
       
    97  *    VDE_ERROR                  indicating a general error
       
    98  */
       
    99 
       
   100 
       
   101 int vdeGetLatestFrame(
       
   102    vdeHInstance_t hInstance,
       
   103    u_char **ppy, u_char **ppu, u_char **ppv,
       
   104    int *pLumWidth, int *pLumHeight,
       
   105    int *pFrameNum)
       
   106 /* {{-output"vdeGetLatestFrame.txt"}} */
       
   107 {
       
   108    int
       
   109       retValue;
       
   110 
       
   111    vdeImb_t
       
   112       *pImb;
       
   113 
       
   114    vdeImsItem_t 
       
   115       *pImsItem;
       
   116 
       
   117    vdeInstance_t 
       
   118       *instance = (vdeInstance_t *) hInstance;
       
   119 
       
   120 
       
   121    vdeAssert(instance != NULL);
       
   122 
       
   123    /* Ensure that image width and height are returned anyway */
       
   124    *pLumWidth = instance->lumWidth;
       
   125    *pLumHeight = instance->lumHeight;
       
   126 
       
   127    retValue = vdeImsGetReference(
       
   128       &instance->imageStore, 
       
   129       VDEIMS_REF_LATEST, 0, 
       
   130       &pImsItem);
       
   131    if (retValue < 0)
       
   132       return retValue;
       
   133 
       
   134    if (!pImsItem)
       
   135       return VDE_ERROR;
       
   136 
       
   137    pImb = pImsItem->imb;
       
   138 
       
   139    if (vdeImbYUV(pImb, ppy, ppu, ppv, pLumWidth, pLumHeight) < 0)
       
   140       return VDE_ERROR;
       
   141 
       
   142    *pFrameNum = renDriFrameNumber(pImb->drawItem);
       
   143 
       
   144    return VDE_OK;
       
   145 }
       
   146 
       
   147 
       
   148 
       
   149 /* {{-output"vdeInit.txt"}} */
       
   150 /*
       
   151  * vdeInit
       
   152  *    
       
   153  *
       
   154  * Parameters:
       
   155  *    param                      a h263dOpen_t structure containing
       
   156  *                               the initialization parameters
       
   157  *
       
   158  * Function:
       
   159  *    This function allocates and initializes an H.263 video decoder engine
       
   160  *    (VDE) instance.
       
   161  *
       
   162  * Returns:
       
   163  *    a handle to the new instance or
       
   164  *    NULL if the initialization fails
       
   165  *
       
   166  *    
       
   167  */
       
   168 
       
   169 vdeHInstance_t vdeInit(h263dOpen_t *param)
       
   170 /* {{-output"vdeInit.txt"}} */
       
   171 {
       
   172    vdeInstance_t *instance;
       
   173 
       
   174    vdeAssert(param);
       
   175    vdeAssert(!param->fRPS || (param->fRPS && param->numReferenceFrames > 1));
       
   176 
       
   177    instance = (vdeInstance_t *) 
       
   178       vdeMalloc(sizeof(vdeInstance_t) + param->freeSpace);
       
   179    if (instance == NULL)
       
   180       goto errInstanceAllocation;
       
   181    memset(instance, 0, sizeof(vdeInstance_t));
       
   182 
       
   183    if (param->lumWidth % 16)
       
   184       param->lumWidth = (param->lumWidth / 16 + 1) * 16;
       
   185    
       
   186    if (param->lumHeight % 16)
       
   187       param->lumHeight = (param->lumHeight / 16 + 1) * 16;
       
   188 
       
   189    if (vdeImsOpen(&instance->imageStore, param->numPreallocatedFrames, 
       
   190       param->lumWidth, param->lumHeight) < 0)
       
   191       goto errVdeImsOpen;
       
   192 
       
   193    instance->vdcHInstance = vdcOpen(&instance->imageStore, 
       
   194       param->fRPS ? param->numReferenceFrames : 1,
       
   195       (void *) instance);
       
   196    if (!instance->vdcHInstance)
       
   197       goto errVdcOpen;
       
   198 
       
   199    if (vdeFrtOpen(&instance->renStore) < 0)
       
   200       goto errRenStore;
       
   201 
       
   202    if (vdeFrtOpen(&instance->startCallbackStore) < 0)
       
   203       goto errStartCallbackStore;
       
   204 
       
   205    if (vdeFrtOpen(&instance->endCallbackStore) < 0)
       
   206       goto errEndCallbackStore;
       
   207 
       
   208 
       
   209    instance->lumWidth = param->lumWidth;
       
   210    instance->lumHeight = param->lumHeight;
       
   211 
       
   212    return (vdeHInstance_t) instance;
       
   213 
       
   214    /* Error cases (release resources in reverse order) */
       
   215 
       
   216 errEndCallbackStore:
       
   217     
       
   218    vdeFrtClose(&instance->startCallbackStore);
       
   219 errStartCallbackStore:
       
   220 
       
   221    vdeFrtClose(&instance->renStore);
       
   222 errRenStore:
       
   223 
       
   224    vdcClose(instance->vdcHInstance);
       
   225 errVdcOpen:
       
   226 
       
   227    vdeImsClose(&instance->imageStore);
       
   228 errVdeImsOpen:
       
   229 
       
   230    vdeDealloc(instance);
       
   231 errInstanceAllocation:
       
   232 
       
   233    return NULL;
       
   234 }
       
   235 
       
   236 
       
   237 /* {{-output"vdeIsINTRA.txt"}} */
       
   238 /*
       
   239  * vdeIsINTRA
       
   240  *    
       
   241  *
       
   242  * Parameters:
       
   243  *    hInstance                  handle of instance data
       
   244  *    frameStart                 pointer to memory chunk containing a frame
       
   245  *    frameLength                number of bytes in frame
       
   246  *
       
   247  * Function:
       
   248  *    This function returns 1 if the passed frame is an INTRA frame.
       
   249  *    Otherwise the function returns 0.
       
   250  *
       
   251  * Note:
       
   252  *    This function does not use vdeque services since it is intended to be
       
   253  *    used in non-thread version of the codec only.
       
   254  *
       
   255  * Returns:
       
   256  *    See above.
       
   257  */
       
   258 
       
   259 int vdeIsINTRA(
       
   260    vdeHInstance_t hInstance,
       
   261    void *frameStart,
       
   262    unsigned frameLength)
       
   263 /* {{-output"vdeIsINTRA.txt"}} */
       
   264 {
       
   265    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   266 
       
   267    vdeAssert(instance != NULL);
       
   268 
       
   269    /* Note: We assume that vdeDetermineStreamType has been called to
       
   270       decide whether the stream is MPEG-4 or H.263 */
       
   271       
       
   272    if (instance->fMPEG4)
       
   273       return vdcIsMPEGINTRA(instance->vdcHInstance, frameStart, frameLength);
       
   274    else
       
   275       return vdcIsINTRA(instance->vdcHInstance, frameStart, frameLength);
       
   276 }
       
   277 
       
   278 
       
   279 /* {{-output"vdeLoad.txt"}} */
       
   280 /*
       
   281  * vdeLoad
       
   282  *    
       
   283  *
       
   284  * Parameters:
       
   285  *    rendererFileName           file from which to get renderer functions
       
   286  *
       
   287  * Function:
       
   288  *    This function initializes this module.
       
   289  *
       
   290  *    Renderer functions are dynamically loaded from the given file.
       
   291  *    If rendererFileName is NULL, renderer functions are expected to be
       
   292  *    statically linked.
       
   293  *
       
   294  * Returns:
       
   295  *    VDE_OK                     if the function was successful
       
   296  *    VDE_ERROR                  indicating a general error
       
   297  *
       
   298  *    
       
   299  */
       
   300 
       
   301 int vdeLoad(const char * /*rendererFileName*/)
       
   302 /* {{-output"vdeLoad.txt"}} */
       
   303 {
       
   304 
       
   305    if (vdcLoad() < 0)
       
   306       return VDE_ERROR;
       
   307 
       
   308    return VDE_OK;
       
   309 }
       
   310 
       
   311 
       
   312 
       
   313 
       
   314 /* {{-output"vdeSetInputBuffer.txt"}} */
       
   315 /*
       
   316  * vdeSetInputBuffer
       
   317  *    
       
   318  *
       
   319  * Parameters:
       
   320  *    hInstance                  handle of instance data
       
   321  *    buffer                     a new bit buffer to use
       
   322  *
       
   323  * Function:
       
   324  *    This function sets the bit buffer to use for decoding.
       
   325  *    It is intended that this function is used mainly in applications
       
   326  *    where frames are provided one by one from applications.
       
   327  *    Some upper level function must create a bit buffer for each frame,
       
   328  *    pass a pointer to the created bit buffer to the decoder using this
       
   329  *    function and then decode the frame.
       
   330  *
       
   331  * Returns:
       
   332  *    VDE_OK                     if the function was successful
       
   333  *    VDE_ERROR                  indicating a general error
       
   334  *
       
   335  *    
       
   336  */
       
   337 
       
   338 int vdeSetInputBuffer(vdeHInstance_t hInstance, bibBuffer_t *buffer)
       
   339 /* {{-output"vdeSetInputBuffer.txt"}} */
       
   340 {
       
   341    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   342 
       
   343    if (instance == NULL)
       
   344       return VDE_ERROR;
       
   345 
       
   346    instance->inBuffer = buffer;
       
   347 
       
   348    return VDE_OK;
       
   349 }
       
   350 
       
   351 
       
   352 
       
   353 int vdeSetOutputBuffer(vdeHInstance_t hInstance, bibBuffer_t *buffer)
       
   354 /* {{-output"vdeSetOutputBuffer.txt"}} */
       
   355 {
       
   356    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   357 
       
   358    if (instance == NULL)
       
   359       return VDE_ERROR;
       
   360 
       
   361    instance->outBuffer = buffer;
       
   362 
       
   363    return VDE_OK;
       
   364 }
       
   365 
       
   366 int vdeSetBufferEdit(vdeHInstance_t hInstance, bibBufferEdit_t *bufEdit)
       
   367 /* {{-output"vdeSetOutputBuffer.txt"}} */
       
   368 {
       
   369    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   370 
       
   371    if (instance == NULL)
       
   372       return VDE_ERROR;
       
   373 
       
   374    instance->bufEdit = bufEdit;
       
   375 
       
   376    return VDE_OK;
       
   377 }
       
   378 
       
   379 int vdeSetVideoEditParams(vdeHInstance_t hInstance, int aColorEffect, TBool aGetDecodedFrame, 
       
   380                           TInt aColorToneU, TInt aColorToneV)
       
   381 {
       
   382    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   383 
       
   384    if (instance == NULL)
       
   385       return VDE_ERROR;
       
   386 
       
   387    instance->iColorEffect = aColorEffect;
       
   388    instance->iGetDecodedFrame = aGetDecodedFrame;
       
   389    instance->iColorToneU = aColorToneU;
       
   390    instance->iColorToneV = aColorToneV;
       
   391 
       
   392    return VDE_OK;
       
   393 }
       
   394 
       
   395 
       
   396 
       
   397 
       
   398 
       
   399 
       
   400 
       
   401 
       
   402 
       
   403 /* {{-output"vdeShutDown.txt"}} */
       
   404 /*
       
   405  * vdeShutDown
       
   406  *    
       
   407  *
       
   408  * Parameters:
       
   409  *    hInstance                  handle of instance data
       
   410  *
       
   411  * Function:
       
   412  *    This function has to be called in the end of each video sequence.
       
   413  *    It frees the resources (the VDE instance) allocated by vdeInit.
       
   414  *
       
   415  * Returns:
       
   416  *    VDE_OK                     if the closing was successful
       
   417  *    VDE_ERROR                  indicating a general error
       
   418  *
       
   419  *    
       
   420  */
       
   421 
       
   422 int vdeShutDown(vdeHInstance_t hInstance)
       
   423 /* {{-output"vdeShutDown.txt"}} */
       
   424 {
       
   425    int retValue = VDE_OK;
       
   426    vdeInstance_t *instance = (vdeInstance_t *) hInstance;
       
   427 
       
   428    if (vdcClose(instance->vdcHInstance) < 0)
       
   429       retValue = VDE_ERROR;
       
   430 
       
   431    if (vdeFrtClose(&instance->endCallbackStore) < 0)
       
   432       retValue = VDE_ERROR;
       
   433 
       
   434    if (vdeFrtClose(&instance->startCallbackStore) < 0)
       
   435       retValue = VDE_ERROR;
       
   436 
       
   437    if (vdeFrtClose(&instance->renStore) < 0)
       
   438       retValue = VDE_ERROR;
       
   439 
       
   440    if (vdeImsClose(&instance->imageStore) < 0)
       
   441       retValue = VDE_ERROR;
       
   442 
       
   443    vdeDealloc(instance);
       
   444 
       
   445    return retValue;
       
   446 }
       
   447 
       
   448 // End of File