com.google.android.exoplayer2.util.ParsableNalUnitBitArray Java Examples

The following examples show how to use com.google.android.exoplayer2.util.ParsableNalUnitBitArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: H265Reader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #2
Source File: H265Reader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #3
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #4
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #5
Source File: H265Reader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #6
Source File: H265Reader.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Skips scaling_list_data(). See H.265/HEVC (2014) 7.3.4.
 */
private static void skipScalingList(ParsableNalUnitBitArray bitArray) {
  for (int sizeId = 0; sizeId < 4; sizeId++) {
    for (int matrixId = 0; matrixId < 6; matrixId += sizeId == 3 ? 3 : 1) {
      if (!bitArray.readBit()) { // scaling_list_pred_mode_flag[sizeId][matrixId]
        // scaling_list_pred_matrix_id_delta[sizeId][matrixId]
        bitArray.readUnsignedExpGolombCodedInt();
      } else {
        int coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
        if (sizeId > 1) {
          // scaling_list_dc_coef_minus8[sizeId - 2][matrixId]
          bitArray.readSignedExpGolombCodedInt();
        }
        for (int i = 0; i < coefNum; i++) {
          bitArray.readSignedExpGolombCodedInt(); // scaling_list_delta_coef
        }
      }
    }
  }
}
 
Example #7
Source File: H265Reader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBit(); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBit(); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}
 
Example #8
Source File: H264Reader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #9
Source File: H264Reader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #10
Source File: H265Reader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBit(); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBit(); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}
 
Example #11
Source File: H264Reader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #12
Source File: H265Reader.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBits(1); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBits(1); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBits(1); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBits(1); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}
 
Example #13
Source File: H264Reader.java    From K-Sonic with MIT License 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #14
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBit(); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBit(); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}
 
Example #15
Source File: H264Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #16
Source File: H265Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBit(); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBit(); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}
 
Example #17
Source File: H264Reader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public SampleReader(TrackOutput output, boolean allowNonIdrKeyframes,
    boolean detectAccessUnits) {
  this.output = output;
  this.allowNonIdrKeyframes = allowNonIdrKeyframes;
  this.detectAccessUnits = detectAccessUnits;
  sps = new SparseArray<>();
  pps = new SparseArray<>();
  previousSliceHeader = new SliceHeaderData();
  sliceHeader = new SliceHeaderData();
  buffer = new byte[DEFAULT_BUFFER_SIZE];
  bitArray = new ParsableNalUnitBitArray(buffer, 0, 0);
  reset();
}
 
Example #18
Source File: H265Reader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the number of short term reference picture sets in a SPS as ue(v), then skips all of
 * them. See H.265/HEVC (2014) 7.3.7.
 */
private static void skipShortTermRefPicSets(ParsableNalUnitBitArray bitArray) {
  int numShortTermRefPicSets = bitArray.readUnsignedExpGolombCodedInt();
  boolean interRefPicSetPredictionFlag = false;
  int numNegativePics;
  int numPositivePics;
  // As this method applies in a SPS, the only element of NumDeltaPocs accessed is the previous
  // one, so we just keep track of that rather than storing the whole array.
  // RefRpsIdx = stRpsIdx - (delta_idx_minus1 + 1) and delta_idx_minus1 is always zero in SPS.
  int previousNumDeltaPocs = 0;
  for (int stRpsIdx = 0; stRpsIdx < numShortTermRefPicSets; stRpsIdx++) {
    if (stRpsIdx != 0) {
      interRefPicSetPredictionFlag = bitArray.readBit();
    }
    if (interRefPicSetPredictionFlag) {
      bitArray.skipBit(); // delta_rps_sign
      bitArray.readUnsignedExpGolombCodedInt(); // abs_delta_rps_minus1
      for (int j = 0; j <= previousNumDeltaPocs; j++) {
        if (bitArray.readBit()) { // used_by_curr_pic_flag[j]
          bitArray.skipBit(); // use_delta_flag[j]
        }
      }
    } else {
      numNegativePics = bitArray.readUnsignedExpGolombCodedInt();
      numPositivePics = bitArray.readUnsignedExpGolombCodedInt();
      previousNumDeltaPocs = numNegativePics + numPositivePics;
      for (int i = 0; i < numNegativePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s0_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s0_flag[i]
      }
      for (int i = 0; i < numPositivePics; i++) {
        bitArray.readUnsignedExpGolombCodedInt(); // delta_poc_s1_minus1[i]
        bitArray.skipBit(); // used_by_curr_pic_s1_flag[i]
      }
    }
  }
}