Changeset 1005 in SHVCSoftware for branches/SHM-dev/source/App/utils


Ignore:
Timestamp:
26 Jan 2015, 17:11:15 (10 years ago)
Author:
nokia
Message:

Implementation of JCTVC-R0235 - Processing of bitstreams without an available base layer

Location:
branches/SHM-dev/source/App/utils/ExtractAddLS
Files:
1 deleted
1 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/App/utils/ExtractAddLS/ExtractAddLS.c

    r1004 r1005  
    3434#include <stdlib.h>
    3535#include <stdio.h>
     36#include <string.h>
    3637
    3738
    3839enum NalUnitType
    3940{
    40   NAL_UNIT_CODED_SLICE_TRAIL_N = 0,   // 0
    41   NAL_UNIT_CODED_SLICE_TRAIL_R,   // 1
    42 
    43   NAL_UNIT_CODED_SLICE_TSA_N,     // 2
    44   NAL_UNIT_CODED_SLICE_TSA_R,       // 3
    45 
    46   NAL_UNIT_CODED_SLICE_STSA_N,    // 4
    47   NAL_UNIT_CODED_SLICE_STSA_R,    // 5
    48 
    49   NAL_UNIT_CODED_SLICE_RADL_N,    // 6
    50   NAL_UNIT_CODED_SLICE_RADL_R,      // 7
    51 
    52   NAL_UNIT_CODED_SLICE_RASL_N,    // 8
    53   NAL_UNIT_CODED_SLICE_RASL_R,      // 9
     41  NAL_UNIT_CODED_SLICE_TRAIL_N = 0,
     42  NAL_UNIT_CODED_SLICE_TRAIL_R,
     43
     44  NAL_UNIT_CODED_SLICE_TSA_N,
     45  NAL_UNIT_CODED_SLICE_TSA_R,
     46
     47  NAL_UNIT_CODED_SLICE_STSA_N,
     48  NAL_UNIT_CODED_SLICE_STSA_R,
     49
     50  NAL_UNIT_CODED_SLICE_RADL_N,
     51  NAL_UNIT_CODED_SLICE_RADL_R,
     52
     53  NAL_UNIT_CODED_SLICE_RASL_N,
     54  NAL_UNIT_CODED_SLICE_RASL_R,
    5455
    5556  NAL_UNIT_RESERVED_VCL_N10,
     
    6061  NAL_UNIT_RESERVED_VCL_R15,
    6162
    62   NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
    63   NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
    64   NAL_UNIT_CODED_SLICE_BLA_N_LP,  // 18
    65   NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
    66   NAL_UNIT_CODED_SLICE_IDR_N_LP,  // 20
    67   NAL_UNIT_CODED_SLICE_CRA,       // 21
     63  NAL_UNIT_CODED_SLICE_BLA_W_LP,
     64  NAL_UNIT_CODED_SLICE_BLA_W_RADL,
     65  NAL_UNIT_CODED_SLICE_BLA_N_LP,
     66  NAL_UNIT_CODED_SLICE_IDR_W_RADL,
     67  NAL_UNIT_CODED_SLICE_IDR_N_LP,
     68  NAL_UNIT_CODED_SLICE_CRA,
    6869  NAL_UNIT_RESERVED_IRAP_VCL22,
    6970  NAL_UNIT_RESERVED_IRAP_VCL23,
     
    7879  NAL_UNIT_RESERVED_VCL31,
    7980
    80   NAL_UNIT_VPS,                   // 32
    81   NAL_UNIT_SPS,                   // 33
    82   NAL_UNIT_PPS,                   // 34
    83   NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35
    84   NAL_UNIT_EOS,                   // 36
    85   NAL_UNIT_EOB,                   // 37
    86   NAL_UNIT_FILLER_DATA,           // 38
    87   NAL_UNIT_PREFIX_SEI,              // 39
    88   NAL_UNIT_SUFFIX_SEI,              // 40
     81  NAL_UNIT_VPS,
     82  NAL_UNIT_SPS,
     83  NAL_UNIT_PPS,
     84  NAL_UNIT_ACCESS_UNIT_DELIMITER,
     85  NAL_UNIT_EOS,
     86  NAL_UNIT_EOB,
     87  NAL_UNIT_FILLER_DATA,
     88  NAL_UNIT_PREFIX_SEI,
     89  NAL_UNIT_SUFFIX_SEI,
    8990  NAL_UNIT_RESERVED_NVCL41,
    9091  NAL_UNIT_RESERVED_NVCL42,
     
    113114};
    114115
     116char *nalUnitNames[] =
     117{
     118  "NAL_UNIT_CODED_SLICE_TRAIL_N",
     119  "NAL_UNIT_CODED_SLICE_TRAIL_R",
     120
     121  "NAL_UNIT_CODED_SLICE_TSA_N",
     122  "NAL_UNIT_CODED_SLICE_TSA_R",
     123
     124  "NAL_UNIT_CODED_SLICE_STSA_N",
     125  "NAL_UNIT_CODED_SLICE_STSA_R",
     126
     127  "NAL_UNIT_CODED_SLICE_RADL_N",
     128  "NAL_UNIT_CODED_SLICE_RADL_R",
     129
     130  "NAL_UNIT_CODED_SLICE_RASL_N",
     131  "NAL_UNIT_CODED_SLICE_RASL_R",
     132
     133  "NAL_UNIT_RESERVED_VCL_N10",
     134  "NAL_UNIT_RESERVED_VCL_R11",
     135  "NAL_UNIT_RESERVED_VCL_N12",
     136  "NAL_UNIT_RESERVED_VCL_R13",
     137  "NAL_UNIT_RESERVED_VCL_N14",
     138  "NAL_UNIT_RESERVED_VCL_R15",
     139
     140  "NAL_UNIT_CODED_SLICE_BLA_W_LP",
     141  "NAL_UNIT_CODED_SLICE_BLA_W_RADL",
     142  "NAL_UNIT_CODED_SLICE_BLA_N_LP",
     143  "NAL_UNIT_CODED_SLICE_IDR_W_RADL",
     144  "NAL_UNIT_CODED_SLICE_IDR_N_LP",
     145  "NAL_UNIT_CODED_SLICE_CRA",
     146  "NAL_UNIT_RESERVED_IRAP_VCL22",
     147  "NAL_UNIT_RESERVED_IRAP_VCL23",
     148
     149  "NAL_UNIT_RESERVED_VCL24",
     150  "NAL_UNIT_RESERVED_VCL25",
     151  "NAL_UNIT_RESERVED_VCL26",
     152  "NAL_UNIT_RESERVED_VCL27",
     153  "NAL_UNIT_RESERVED_VCL28",
     154  "NAL_UNIT_RESERVED_VCL29",
     155  "NAL_UNIT_RESERVED_VCL30",
     156  "NAL_UNIT_RESERVED_VCL31",
     157
     158  "NAL_UNIT_VPS",
     159  "NAL_UNIT_SPS",
     160  "NAL_UNIT_PPS",
     161  "NAL_UNIT_ACCESS_UNIT_DELIMITER",
     162  "NAL_UNIT_EOS",
     163  "NAL_UNIT_EOB",
     164  "NAL_UNIT_FILLER_DATA",
     165  "NAL_UNIT_PREFIX_SEI",
     166  "NAL_UNIT_SUFFIX_SEI",
     167  "NAL_UNIT_RESERVED_NVCL41",
     168  "NAL_UNIT_RESERVED_NVCL42",
     169  "NAL_UNIT_RESERVED_NVCL43",
     170  "NAL_UNIT_RESERVED_NVCL44",
     171  "NAL_UNIT_RESERVED_NVCL45",
     172  "NAL_UNIT_RESERVED_NVCL46",
     173  "NAL_UNIT_RESERVED_NVCL47",
     174  "NAL_UNIT_UNSPECIFIED_48",
     175  "NAL_UNIT_UNSPECIFIED_49",
     176  "NAL_UNIT_UNSPECIFIED_50",
     177  "NAL_UNIT_UNSPECIFIED_51",
     178  "NAL_UNIT_UNSPECIFIED_52",
     179  "NAL_UNIT_UNSPECIFIED_53",
     180  "NAL_UNIT_UNSPECIFIED_54",
     181  "NAL_UNIT_UNSPECIFIED_55",
     182  "NAL_UNIT_UNSPECIFIED_56",
     183  "NAL_UNIT_UNSPECIFIED_57",
     184  "NAL_UNIT_UNSPECIFIED_58",
     185  "NAL_UNIT_UNSPECIFIED_59",
     186  "NAL_UNIT_UNSPECIFIED_60",
     187  "NAL_UNIT_UNSPECIFIED_61",
     188  "NAL_UNIT_UNSPECIFIED_62",
     189  "NAL_UNIT_UNSPECIFIED_63"
     190};
     191
    115192typedef struct NalUnitHeader_s
    116193{
     
    126203  int currByte;
    127204 
    128   while (1)
     205  for (;;)
    129206  {
    130207    currByte = fgetc(inFile);
     
    201278  int numStartCodeZeros;
    202279  int nalIsSpsPpsEob;
     280  int nalIsVpsSpsPpsEos;
    203281  int removeNal;
    204 
    205   if (argc < 4 || argc > 5)
    206   {
    207     fprintf(stderr, "Usage: BLRewrite <infile> <outfile> <assigned base layer ID> [<max temporal ID>]\n");
     282  int layerIdListTarget[8];
     283  int i;
     284  int layerIdx;
     285  int numLayerIds;
     286  char nalName[32];
     287
     288  if (argc < 5 || argc > 10)
     289  {
     290    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");
     293    fprintf(stderr, "  If more than one layer ID is given, sub-bitstream extraction process for\n");
     294    fprintf(stderr, "  additional layer sets is performed (Layer ID list should exactly match\n");
     295    fprintf(stderr, "  an additional layer set defined in VPS)\n");
    208296    exit(1);
    209297  }
     
    223311  }
    224312
    225   assignedBaseLayerId = atoi(argv[3]);
    226   if (assignedBaseLayerId < 1 || assignedBaseLayerId > 7)
    227   {
    228     fprintf(stderr, "Invalid assigned base layer ID (must be in range 1-7)\n");
     313  tIdTarget = atoi(argv[3]);
     314  if (tIdTarget < 0 || tIdTarget > 6)
     315  {
     316    fprintf(stderr, "Invalid maximum temporal ID (must be in range 0-6)\n");
    229317    exit(1);
    230318  }
    231319
    232   if (argc == 5)
    233   {
    234     tIdTarget = atoi(argv[4]);
    235     if (tIdTarget < 0 || tIdTarget > 6)
    236     {
    237       fprintf(stderr, "Invalid maximum temporal ID (must be in range 0-6)\n");
     320  for (i = 4, layerIdx = 0; i < argc; i++, layerIdx++)
     321  {
     322    layerIdListTarget[layerIdx] = atoi(argv[i]);
     323    if (layerIdListTarget[layerIdx] < 1 || layerIdListTarget[layerIdx] > 7)
     324    {
     325      fprintf(stderr, "Invalid layer ID (must be in range 1-7)\n");
    238326      exit(1);
    239327    }
    240328  }
    241329
    242   while (1)
     330  numLayerIds = layerIdx;
     331  assignedBaseLayerId = layerIdListTarget[0];
     332
     333  /* Iterate through all NAL units */
     334  for (;;)
    243335  {
    244336    if (!findStartCodePrefix(inFile, &numStartCodeZeros))
     
    251343    }
    252344
    253     printf("NAL unit type: %i,  NUH layer ID: %i,  NUH Temporal ID: %i\n", nalu.nalUnitType, nalu.nuhLayerId, nalu.nuhTemporalIdPlus1 - 1);
    254 
    255     nalIsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB);
    256 
    257     removeNal = (!nalIsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId))
    258              || (nalIsSpsPpsEob && (nalu.nuhLayerId != 0) && (nalu.nuhLayerId != assignedBaseLayerId))
    259              || (nalu.nalUnitType == NAL_UNIT_VPS)
    260              || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget);
     345    if (numLayerIds == 1)
     346    {
     347      /* independent non-base layer rewriting process */
     348
     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
     356      nalu.nuhLayerId = 0;
     357    }
     358    else /* numLayerIds > 1 */
     359    {
     360      /* sub-bitstream extraction process for additional layer sets */
     361
     362      int isTargetLayer = 0;
     363
     364      for (i = 0; i < numLayerIds; i++)
     365      {
     366        if (layerIdListTarget[i] == nalu.nuhLayerId)
     367        {
     368          isTargetLayer = 1;
     369        }
     370      }
     371   
     372      nalIsVpsSpsPpsEos = (nalu.nalUnitType == NAL_UNIT_VPS || nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOS);
     373
     374      removeNal = (!(nalIsVpsSpsPpsEos || nalu.nalUnitType == NAL_UNIT_EOB) && !isTargetLayer)
     375                || (nalIsVpsSpsPpsEos && (nalu.nuhLayerId != 0) && !isTargetLayer)
     376                || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget);
     377    }
    261378
    262379    if (!removeNal)
     
    268385      long i;
    269386
    270       nalu.nuhLayerId = 0;
     387      printf("Keep  ");
     388
    271389      writeStartCodePrefixAndNUH(outFile, numStartCodeZeros, &nalu);
    272390
     
    283401      fseek(inFile, naluBytesStartPos, SEEK_SET);
    284402
    285       for (i = 0; i < numNaluBytes; i++)
     403      i = 0;
     404
     405      if (numLayerIds > 1 && nalu.nalUnitType == NAL_UNIT_VPS)
     406      {
     407        /* sub-bitstream extraction process for additional layer sets */
     408        int nalByte = fgetc(inFile);
     409        nalByte = nalByte & ~(0x04);  /* vps_base_layer_available_flag in each VPS is set equal to 0 */
     410        fputc(nalByte, outFile);
     411        i++;
     412      }
     413
     414      for (; i < numNaluBytes; i++)
    286415      {
    287416        fputc(fgetc(inFile), outFile);
    288417      }
    289418    }
     419    else
     420    {
     421      printf("-     ");
     422    }
     423
     424    strcpy(nalName, nalUnitNames[nalu.nalUnitType]);
     425    for (i = strlen(nalName); i < 31; i++)
     426    {
     427      nalName[i] = ' ';
     428    }
     429    nalName[31] = '\0';
     430
     431    printf("%s  layer ID: %i  temporal ID: %i\n", nalName, nalu.nuhLayerId, nalu.nuhTemporalIdPlus1 - 1);
    290432  }
    291433
  • branches/SHM-dev/source/App/utils/ExtractAddLS/ReadMe.txt

    r778 r1005  
    11
    2 This is a simple tool that extracts an independent non-base layer from a multi-layer bitstream, converts it to a base-layer bistream and writes it to a file. The tool is invoked as follows.
     2This a tool that either:
    33
    4   BLRewrite <infile> <outfile> <layer ID of the extracted layer>
     4  1. Extracts an independent non-base layer from a multi-layer bitstream, converts it to a base-layer bistream and writes it to a file. The extraction processs is defined in chapter F.10.2 of the HEVC version 2 specification.
    55
    6 The tool is based on the contribution JCTVC-Q0078 / JCTVC-R0042. Sub-bitstream extraction process done by the tool can be summarized as follows.
     6or
    77
    8 - NAL units with nal_unit_type not equal to SPS_NUT, PPS_NUT, EOS_NUT and EOB_NUT and with nuh_layer_id not equal to the assignedBaseLayerId are removed from outBitstream.
    9 - NAL units with nal_unit_type equal to SPS_NUT, PPS_NUT, EOS_NUT or EOB_NUT with nuh_layer_id not equal to 0 are removed from outBitstream.
    10 - For each NAL unit, the following applies:
    11   – When nuh_layer_id is equal to assignedBaseLayerId, nuh_layer_id is set equal to 0.
     8  2. Extracts an additional layer set sub-bitstream from multi-layer bitstream and writes it to a file. The extraction processs is defined in chapter F.10.3 of the HEVC version 2 specification.
    129
    13 The resulting bitstream can be decoded with an HEVC/H.265 v1 compliant decoder as long as the extracted independent layer conform with v1 specification text. The tool removes VPS from the output bitstream so an HEVC/H.265 decoder should not expect it to be present.
     10
     11The tool is invoked as follows:
     12
     13  ExtractAddLS <infile> <outfile> <Max temporal ID> <layer IDs of the extracted layers>
     14
     15The process that is invoked is decided based on the number of IDs that are given in the layer ID list.  If only one layer ID is given, independent non-base layer rewriting process is invoked. If more than one layer ID is given, sub-bitstream extraction for additional layer sets is invoked.
     16
     17The result of independent non-base layer rewriting process can be decoded with an HEVC/H.265 v1 compliant decoder as long as the extracted independent layer conform with v1 specification text. The tool removes VPS from the output bitstream during rewriting so an HEVC/H.265 decoder should not expect it to be present.
    1418
    1519
Note: See TracChangeset for help on using the changeset viewer.