Ticket #62: ExtractAddLS.patch

File ExtractAddLS.patch, 3.6 KB (added by eeehey, 9 years ago)

Patch for ExtractAddLS.c

  • ExtractAddLS.c

     
    276276  int tIdTarget = 6;
    277277  NalUnitHeader nalu;
    278278  int numStartCodeZeros;
    279   int nalIsSpsPpsEob;
     279  int nalIsVpsSpsPpsEob;
    280280  int nalIsVpsSpsPpsEos;
    281281  int removeNal;
    282282  int layerIdListTarget[8];
     
    288288  if (argc < 5 || argc > 10)
    289289  {
    290290    fprintf(stderr, "\n  Usage: ExtractAddLS <infile> <outfile> <max temporal ID> <list of layer IDs> \n\n");
    291     fprintf(stderr, "  If only one layer ID is given, independent non-base layer rewriting process\n");
    292     fprintf(stderr, "  is performed\n");
     291    fprintf(stderr, "  If only one layer ID 0 is given, base layer extration process is performed\n");
     292    fprintf(stderr, "  If only one non-zero layer ID is given, independent non-base layer rewriting\n");
     293    fprintf(stderr, "  process is performed\n");
    293294    fprintf(stderr, "  If more than one layer ID is given, sub-bitstream extraction process for\n");
    294295    fprintf(stderr, "  additional layer sets is performed (Layer ID list should exactly match\n");
    295296    fprintf(stderr, "  an additional layer set defined in VPS)\n");
     
    320321  for (i = 4, layerIdx = 0; i < argc; i++, layerIdx++)
    321322  {
    322323    layerIdListTarget[layerIdx] = atoi(argv[i]);
    323     if (layerIdListTarget[layerIdx] < 1 || layerIdListTarget[layerIdx] > 7)
     324    if (layerIdListTarget[layerIdx] < 0 || layerIdListTarget[layerIdx] > 7)
    324325    {
    325326      fprintf(stderr, "Invalid layer ID (must be in range 1-7)\n");
    326327      exit(1);
     
    344345
    345346    if (numLayerIds == 1)
    346347    {
    347       /* independent non-base layer rewriting process */
     348      /* base layer or independent non-base layer bitstream extraction */
    348349
    349       nalIsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB);
    350 
    351       removeNal = (!nalIsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId))
    352                 || (nalIsSpsPpsEob && (nalu.nuhLayerId != 0) && (nalu.nuhLayerId != assignedBaseLayerId))
    353                 || (nalu.nalUnitType == NAL_UNIT_VPS)
    354                 || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget);
    355 
     350      /* temporary keep VPS so the extracted/rewriting bitstream can be decoded by HM */
     351      nalIsVpsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_VPS || nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB);
     352      removeNal = (!nalIsVpsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId))
     353                  || (nalIsVpsSpsPpsEob && (nalu.nuhLayerId != 0))
     354                  || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget);
    356355      nalu.nuhLayerId = 0;
    357356    }
    358357    else /* numLayerIds > 1 */
     
    402401
    403402      i = 0;
    404403
    405       if (numLayerIds > 1 && nalu.nalUnitType == NAL_UNIT_VPS)
     404      if (numLayerIds == 1 && nalu.nalUnitType == NAL_UNIT_VPS)
    406405      {
     406        char nalByte = fgetc(inFile);
     407        nalByte = nalByte | (0x0C);  // set vps_max_layers_minus1 bits(5-4) to 0 for HM decoder
     408        nalByte = nalByte & ~(0x03); // set vps_max_layers_minus1 bits(3-0) to 0 for HM decoder
     409        fputc(nalByte, outFile);
     410        i++;
     411        nalByte = fgetc(inFile);
     412        nalByte = nalByte & ~(0xF0);
     413        fputc(nalByte, outFile);
     414        i++;
     415      }
     416      else if (numLayerIds > 1 && nalu.nalUnitType == NAL_UNIT_VPS)
     417      {
    407418        /* sub-bitstream extraction process for additional layer sets */
    408419        int nalByte = fgetc(inFile);
    409420        nalByte = nalByte & ~(0x04);  /* vps_base_layer_available_flag in each VPS is set equal to 0 */