boolean audioOnly = true;
while (this.hasMoreTags()) {
long pos = getCurrentPosition();
posTagMap.put(pos, idx++);
// Read tag header and duration
ITag tmpTag = this.readTagHeader();
duration = tmpTag.getTimestamp();
if (tmpTag.getDataType() == IoConstants.TYPE_VIDEO) {
if (audioOnly) {
audioOnly = false;
audioPositionList.clear();
audioTimestampList.clear();
}
if (firstVideoTag == -1) {
firstVideoTag = pos;
}
// Grab Frame type
fillBuffer(1);
byte frametype = in.get();
if (((frametype & MASK_VIDEO_FRAMETYPE) >> 4) == FLAG_FRAMETYPE_KEYFRAME) {
positionList.add(pos);
timestampList.add(tmpTag.getTimestamp());
}
} else if (tmpTag.getDataType() == IoConstants.TYPE_AUDIO) {
if (firstAudioTag == -1) {
firstAudioTag = pos;
}
if (audioOnly) {
audioPositionList.add(pos);
audioTimestampList.add(tmpTag.getTimestamp());
}
}
// XXX Paul: this 'properly' handles damaged FLV files - as far as
// duration/size is concerned
long newPosition = pos + tmpTag.getBodySize() + 15;
// log.debug("---->" + in.remaining() + " limit=" + in.limit() + "
// new pos=" + newPosition);
if (newPosition >= getTotalBytes()) {
log.info("New position exceeds limit");
if (log.isDebugEnabled()) {
log.debug("-----");
log.debug("Keyframe analysis");
log.debug(" data type=" + tmpTag.getDataType()
+ " bodysize=" + tmpTag.getBodySize());
log.debug(" remaining=" + getRemainingBytes() + " limit="
+ getTotalBytes() + " new pos=" + newPosition);
log.debug(" pos=" + pos);
log.debug("-----");
}