当前位置: 首页>>代码示例>>Java>>正文


Java NalUnitUtil.findNalUnit方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.util.NalUnitUtil.findNalUnit方法的典型用法代码示例。如果您正苦于以下问题:Java NalUnitUtil.findNalUnit方法的具体用法?Java NalUnitUtil.findNalUnit怎么用?Java NalUnitUtil.findNalUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.util.NalUnitUtil的用法示例。


在下文中一共展示了NalUnitUtil.findNalUnit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consume

import com.google.android.exoplayer2.util.NalUnitUtil; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  int searchOffset = offset;
  while (true) {
    int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, searchOffset, limit, prefixFlags);

    if (startCodeOffset == limit) {
      // We've scanned to the end of the data without finding another start code.
      if (!hasOutputFormat) {
        csdBuffer.onData(dataArray, offset, limit);
      }
      return;
    }

    // We've found a start code with the following value.
    int startCodeValue = data.data[startCodeOffset + 3] & 0xFF;

    if (!hasOutputFormat) {
      // This is the number of bytes from the current offset to the start of the next start
      // code. It may be negative if the start code started in the previously consumed data.
      int lengthToStartCode = startCodeOffset - offset;
      if (lengthToStartCode > 0) {
        csdBuffer.onData(dataArray, offset, startCodeOffset);
      }
      // This is the number of bytes belonging to the next start code that have already been
      // passed to csdDataTargetBuffer.
      int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0;
      if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) {
        // The csd data is complete, so we can decode and output the media format.
        Pair<Format, Long> result = parseCsdBuffer(csdBuffer, formatId);
        output.format(result.first);
        frameDurationUs = result.second;
        hasOutputFormat = true;
      }
    }

    if (hasOutputFormat && (startCodeValue == START_GROUP || startCodeValue == START_PICTURE)) {
      int bytesWrittenPastStartCode = limit - startCodeOffset;
      if (foundFirstFrameInGroup) {
        @C.BufferFlags int flags = isKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
        int size = (int) (totalBytesWritten - framePosition) - bytesWrittenPastStartCode;
        output.sampleMetadata(frameTimeUs, flags, size, bytesWrittenPastStartCode, null);
        isKeyframe = false;
      }
      if (startCodeValue == START_GROUP) {
        foundFirstFrameInGroup = false;
        isKeyframe = true;
      } else /* startCodeValue == START_PICTURE */ {
        frameTimeUs = pesPtsUsAvailable ? pesTimeUs : (frameTimeUs + frameDurationUs);
        framePosition = totalBytesWritten - bytesWrittenPastStartCode;
        pesPtsUsAvailable = false;
        foundFirstFrameInGroup = true;
      }
    }

    offset = startCodeOffset;
    searchOffset = offset + 3;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:68,代码来源:H262Reader.java

示例2: consume

import com.google.android.exoplayer2.util.NalUnitUtil; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  // Scan the appended data, processing NAL units as they are encountered
  while (true) {
    int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags);

    if (nalUnitOffset == limit) {
      // We've scanned to the end of the data without finding the start of another NAL unit.
      nalUnitData(dataArray, offset, limit);
      return;
    }

    // We've seen the start of a NAL unit of the following type.
    int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset);

    // This is the number of bytes from the current offset to the start of the next NAL unit.
    // It may be negative if the NAL unit started in the previously consumed data.
    int lengthToNalUnit = nalUnitOffset - offset;
    if (lengthToNalUnit > 0) {
      nalUnitData(dataArray, offset, nalUnitOffset);
    }
    int bytesWrittenPastPosition = limit - nalUnitOffset;
    long absolutePosition = totalBytesWritten - bytesWrittenPastPosition;
    // Indicate the end of the previous NAL unit. If the length to the start of the next unit
    // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes
    // when notifying that the unit has ended.
    endNalUnit(absolutePosition, bytesWrittenPastPosition,
        lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs);
    // Indicate the start of the next NAL unit.
    startNalUnit(absolutePosition, nalUnitType, pesTimeUs);
    // Continue scanning the data.
    offset = nalUnitOffset + 3;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:43,代码来源:H264Reader.java

示例3: consume

import com.google.android.exoplayer2.util.NalUnitUtil; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  while (data.bytesLeft() > 0) {
    int offset = data.getPosition();
    int limit = data.limit();
    byte[] dataArray = data.data;

    // Append the data to the buffer.
    totalBytesWritten += data.bytesLeft();
    output.sampleData(data, data.bytesLeft());

    // Scan the appended data, processing NAL units as they are encountered
    while (offset < limit) {
      int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags);

      if (nalUnitOffset == limit) {
        // We've scanned to the end of the data without finding the start of another NAL unit.
        nalUnitData(dataArray, offset, limit);
        return;
      }

      // We've seen the start of a NAL unit of the following type.
      int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset);

      // This is the number of bytes from the current offset to the start of the next NAL unit.
      // It may be negative if the NAL unit started in the previously consumed data.
      int lengthToNalUnit = nalUnitOffset - offset;
      if (lengthToNalUnit > 0) {
        nalUnitData(dataArray, offset, nalUnitOffset);
      }

      int bytesWrittenPastPosition = limit - nalUnitOffset;
      long absolutePosition = totalBytesWritten - bytesWrittenPastPosition;
      // Indicate the end of the previous NAL unit. If the length to the start of the next unit
      // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes
      // when notifying that the unit has ended.
      endNalUnit(absolutePosition, bytesWrittenPastPosition,
          lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs);
      // Indicate the start of the next NAL unit.
      startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs);
      // Continue scanning the data.
      offset = nalUnitOffset + 3;
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:46,代码来源:H265Reader.java

示例4: consume

import com.google.android.exoplayer2.util.NalUnitUtil; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  int searchOffset = offset;
  while (true) {
    int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, searchOffset, limit, prefixFlags);

    if (startCodeOffset == limit) {
      // We've scanned to the end of the data without finding another start code.
      if (!hasOutputFormat) {
        csdBuffer.onData(dataArray, offset, limit);
      }
      return;
    }

    // We've found a start code with the following value.
    int startCodeValue = data.data[startCodeOffset + 3] & 0xFF;

    if (!hasOutputFormat) {
      // This is the number of bytes from the current offset to the start of the next start
      // code. It may be negative if the start code started in the previously consumed data.
      int lengthToStartCode = startCodeOffset - offset;
      if (lengthToStartCode > 0) {
        csdBuffer.onData(dataArray, offset, startCodeOffset);
      }
      // This is the number of bytes belonging to the next start code that have already been
      // passed to csdDataTargetBuffer.
      int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0;
      if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) {
        // The csd data is complete, so we can decode and output the media format.
        Pair<Format, Long> result = parseCsdBuffer(csdBuffer);
        output.format(result.first);
        frameDurationUs = result.second;
        hasOutputFormat = true;
      }
    }

    if (hasOutputFormat && (startCodeValue == START_GROUP || startCodeValue == START_PICTURE)) {
      int bytesWrittenPastStartCode = limit - startCodeOffset;
      if (foundFirstFrameInGroup) {
        @C.BufferFlags int flags = isKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
        int size = (int) (totalBytesWritten - framePosition) - bytesWrittenPastStartCode;
        output.sampleMetadata(frameTimeUs, flags, size, bytesWrittenPastStartCode, null);
        isKeyframe = false;
      }
      if (startCodeValue == START_GROUP) {
        foundFirstFrameInGroup = false;
        isKeyframe = true;
      } else /* startCodeValue == START_PICTURE */ {
        frameTimeUs = pesPtsUsAvailable ? pesTimeUs : (frameTimeUs + frameDurationUs);
        framePosition = totalBytesWritten - bytesWrittenPastStartCode;
        pesPtsUsAvailable = false;
        foundFirstFrameInGroup = true;
      }
    }

    offset = startCodeOffset;
    searchOffset = offset + 3;
  }
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:68,代码来源:H262Reader.java

示例5: consume

import com.google.android.exoplayer2.util.NalUnitUtil; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  while (true) {
    int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags);

    if (startCodeOffset == limit) {
      // We've scanned to the end of the data without finding another start code.
      if (!hasOutputFormat) {
        csdBuffer.onData(dataArray, offset, limit);
      }
      return;
    }

    // We've found a start code with the following value.
    int startCodeValue = data.data[startCodeOffset + 3] & 0xFF;

    if (!hasOutputFormat) {
      // This is the number of bytes from the current offset to the start of the next start
      // code. It may be negative if the start code started in the previously consumed data.
      int lengthToStartCode = startCodeOffset - offset;
      if (lengthToStartCode > 0) {
        csdBuffer.onData(dataArray, offset, startCodeOffset);
      }
      // This is the number of bytes belonging to the next start code that have already been
      // passed to csdBuffer.
      int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0;
      if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) {
        // The csd data is complete, so we can decode and output the media format.
        Pair<Format, Long> result = parseCsdBuffer(csdBuffer, formatId);
        output.format(result.first);
        frameDurationUs = result.second;
        hasOutputFormat = true;
      }
    }

    if (startCodeValue == START_PICTURE || startCodeValue == START_SEQUENCE_HEADER) {
      int bytesWrittenPastStartCode = limit - startCodeOffset;
      if (startedFirstSample && sampleHasPicture && hasOutputFormat) {
        // Output the sample.
        @C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
        int size = (int) (totalBytesWritten - samplePosition) - bytesWrittenPastStartCode;
        output.sampleMetadata(sampleTimeUs, flags, size, bytesWrittenPastStartCode, null);
      }
      if (!startedFirstSample || sampleHasPicture) {
        // Start the next sample.
        samplePosition = totalBytesWritten - bytesWrittenPastStartCode;
        sampleTimeUs = pesTimeUs != C.TIME_UNSET ? pesTimeUs
            : (startedFirstSample ? (sampleTimeUs + frameDurationUs) : 0);
        sampleIsKeyframe = false;
        pesTimeUs = C.TIME_UNSET;
        startedFirstSample = true;
      }
      sampleHasPicture = startCodeValue == START_PICTURE;
    } else if (startCodeValue == START_GROUP) {
      sampleIsKeyframe = true;
    }

    offset = startCodeOffset + 3;
  }
}
 
开发者ID:y20k,项目名称:transistor,代码行数:69,代码来源:H262Reader.java


注:本文中的com.google.android.exoplayer2.util.NalUnitUtil.findNalUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。