videoeditorengine/h263decoder/src/vdeti_mpeg.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 * Input stream type determination.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 /*
       
    24  * Includes
       
    25  */
       
    26 
       
    27 #include "h263dConfig.h"
       
    28 
       
    29 #include "debug.h"
       
    30 #include "sync.h"
       
    31 #include "vde.h"
       
    32 #include "vdemain.h" 
       
    33 #include "mpegcons.h"
       
    34 
       
    35 #include "core.h"
       
    36 
       
    37 
       
    38 /*
       
    39  * Functions visible outside this module
       
    40  */
       
    41 
       
    42 /*
       
    43  * vdeDetermineStreamType
       
    44  *
       
    45  * Parameters:
       
    46  *    hInstance                  instance data
       
    47  *
       
    48  * Function:
       
    49  *   This function detects the stream type, looking at the start code
       
    50  *   (h.263 vs. MPEG-4) and sets the flag "fMPEG4" which is
       
    51  *   used for the configuration of the decoder. 
       
    52  *   In case of an MPEG-4 stream calls the Video Object Header and the VOL Header
       
    53  *   decoding function to set initial parameters.
       
    54  *
       
    55  * Returns:
       
    56  *    VDE_OK                     if the stream type could be detected and 
       
    57  *                               it is supported
       
    58  *    VDE_ERROR_HALTED           if the stream type couldn't be detected or
       
    59  *                               the configuration is not supported
       
    60  *    VDE_ERROR                  if unrecoverable bitbuffer error occered
       
    61  *
       
    62  */
       
    63 int vdeDetermineStreamType(vdeHInstance_t hInstance, CMPEG4Transcoder *hTranscoder)
       
    64 {
       
    65    vdeInstance_t *vdeinstance = (vdeInstance_t *) hInstance;
       
    66    bibBuffer_t *inBuffer = vdeinstance->inBuffer;
       
    67 
       
    68    int numBitsGot,
       
    69       bitErrorIndication = 0;
       
    70    int16 error = 0;
       
    71    u_int32 bits;
       
    72 
       
    73    bits = bibShowBits(32, inBuffer, &numBitsGot, &bitErrorIndication, &error);
       
    74    if (error)
       
    75       return VDE_ERROR;
       
    76 
       
    77    /* If PSC */
       
    78    if ((bits >> 10) == 32) {
       
    79       vdeinstance->fMPEG4 = 0;
       
    80    } 
       
    81 
       
    82    /* Else check for Visual Sequence, Visual Object or Video Object start code */
       
    83    else if ((bits == MP4_VOS_START_CODE) || 
       
    84             (bits == MP4_VO_START_CODE) ||
       
    85             ((bits >> MP4_VID_ID_CODE_LENGTH) == MP4_VID_START_CODE) ||
       
    86             ((bits >> MP4_VOL_ID_CODE_LENGTH) == MP4_VOL_START_CODE)) {
       
    87 
       
    88       vdeinstance->fMPEG4 = 1;
       
    89 
       
    90       if (vdcDecodeMPEGVolHeader(vdeinstance->vdcHInstance, inBuffer, hTranscoder) != 0)
       
    91          return VDE_ERROR;
       
    92 
       
    93       bits = bibShowBits(22, inBuffer, &numBitsGot, &bitErrorIndication, &error);
       
    94       if (error)
       
    95          return VDE_ERROR;
       
    96 
       
    97       /* Check if H.263 PSC follows the VOL header, in which case this is 
       
    98          MPEG-4 with short header and is decoded as H.263 */
       
    99       if ( bits == 32 ) {
       
   100          vdeinstance->fMPEG4 = 0;
       
   101       }
       
   102 
       
   103    }
       
   104 
       
   105    /* Else no H.263 and no MPEG-4 start code detected -> let's try H.263,
       
   106       since MPEG-4 cannot anyway be decoded without starting header */
       
   107    else {
       
   108       vdeinstance->fMPEG4 = 0;
       
   109    }
       
   110 
       
   111    return VDE_OK;
       
   112 }
       
   113 
       
   114 // End of File