Home | History | Annotate | Download | only in parser
      1 /* ///////////////////////////////////////////////////////////////////////
      2 //
      3 //               INTEL CORPORATION PROPRIETARY INFORMATION
      4 //  This software is supplied under the terms of a license agreement or
      5 //  nondisclosure agreement with Intel Corporation and may not be copied
      6 //  or disclosed except in accordance with the terms of that agreement.
      7 //        Copyright (c) 2008 Intel Corporation. All Rights Reserved.
      8 //
      9 //  Description: Parses VC-1 picture layer for simple and main profiles.
     10 //
     11 */
     12 
     13 #include "vc1parse.h"
     14 
     15 /*------------------------------------------------------------------------------
     16  * Parse picture layer.  This function parses the picture header for simple or
     17  * main profile down to macroblock layer.
     18  * Table 16 of SMPTE 421M after processing up to PTYPE for I picture.
     19  * Table 17 of SMPTE 421M after processing up to PTYPE for BI picture.
     20  * Table 19 of SMPTE 421M after processing up to PTYPE for P picture.
     21  * Table 21 of SMPTE 421M after processing up to PTYPE for B picture.
     22  *------------------------------------------------------------------------------
     23  */
     24 
     25 vc1_Status vc1_ParsePictureHeader(void* ctxt, vc1_Info *pInfo)
     26 {
     27     uint32_t tempValue;
     28     vc1_Status status = VC1_STATUS_OK;
     29     vc1_metadata_t *md = &pInfo->metadata;
     30     vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
     31     int32_t result;
     32 
     33     if (md->PROFILE != VC1_PROFILE_ADVANCED)
     34     {
     35         // As per spec, for main/simple profile, if the size of the coded picture is <= 1B,
     36         // it shall be treated as a skipped frame.
     37         // In content with skipped frames, the data is "00".
     38         // rcv to vc1 conversion process adds an additional byte (0x80) to the picture, hence
     39         // the data looks like "00 80"
     40         // Hence if data is <= 2B, we will consider it skipped (check for 16+1b, if it fails, the frame is skipped).
     41         result = viddec_pm_peek_bits(ctxt, &tempValue, 17);
     42         if(result == -1)
     43         {
     44             picLayerHeader->PTYPE = VC1_SKIPPED_FRAME;
     45             return status;
     46         }
     47     }
     48 
     49     if (md->FINTERPFLAG == 1)
     50     {
     51         VC1_GET_BITS9(1, tempValue); /* INTERPFRM. */
     52     }
     53 
     54     VC1_GET_BITS9(2, tempValue); /* FRMCNT. */
     55 
     56     if (md->RANGERED == 1)
     57     {
     58         VC1_GET_BITS9(1, picLayerHeader->RANGEREDFRM);
     59     }
     60 
     61     if (md->MAXBFRAMES == 0)
     62     {
     63         VC1_GET_BITS9(1, picLayerHeader->PTYPE);
     64         if (picLayerHeader->PTYPE == 0)
     65             picLayerHeader->PTYPE = VC1_I_FRAME;
     66         else
     67             picLayerHeader->PTYPE = VC1_P_FRAME;
     68     }
     69     else
     70     {
     71         VC1_GET_BITS9(1, picLayerHeader->PTYPE);
     72         if (picLayerHeader->PTYPE == 0)
     73         {
     74             VC1_GET_BITS9(1, picLayerHeader->PTYPE);
     75             if (picLayerHeader->PTYPE == 0) {
     76                 picLayerHeader->PTYPE = VC1_B_FRAME; /* Or VC1_BI_FRAME. */
     77                 /* if peek(7) = 0b1111111 then ptype = bi */
     78                 VC1_PEEK_BITS( 7, tempValue );
     79                 if ( tempValue == 0x7f )
     80                     picLayerHeader->PTYPE = VC1_BI_FRAME;
     81             } else
     82                 picLayerHeader->PTYPE = VC1_I_FRAME;
     83         }
     84         else
     85             picLayerHeader->PTYPE = VC1_P_FRAME;
     86     }
     87 
     88     if (picLayerHeader->PTYPE == VC1_I_FRAME ||
     89         picLayerHeader->PTYPE == VC1_BI_FRAME)
     90     {
     91         status = vc1_ParsePictureHeader_ProgressiveIpicture(ctxt, pInfo);
     92     }
     93     else if (picLayerHeader->PTYPE == VC1_P_FRAME)
     94         status = vc1_ParsePictureHeader_ProgressivePpicture(ctxt, pInfo);
     95     else if (picLayerHeader->PTYPE == VC1_B_FRAME)
     96         status = vc1_ParsePictureHeader_ProgressiveBpicture(ctxt, pInfo);
     97     else
     98         status = VC1_STATUS_PARSE_ERROR;
     99 
    100     return status;
    101 }
    102