private static Pair<String,byte[]> parseEsdsFromParent(ParsableByteArray parent,int position){
  parent.setPosition(position + Atom.HEADER_SIZE + 4);
  parent.skipBytes(1);
  int varIntByte=parent.readUnsignedByte();
  while (varIntByte > 127) {
    varIntByte=parent.readUnsignedByte();
  }
  parent.skipBytes(2);
  int flags=parent.readUnsignedByte();
  if ((flags & 0x80) != 0) {
    parent.skipBytes(2);
  }
  if ((flags & 0x40) != 0) {
    parent.skipBytes(parent.readUnsignedShort());
  }
  if ((flags & 0x20) != 0) {
    parent.skipBytes(2);
  }
  parent.skipBytes(1);
  varIntByte=parent.readUnsignedByte();
  while (varIntByte > 127) {
    varIntByte=parent.readUnsignedByte();
  }
  int objectTypeIndication=parent.readUnsignedByte();
  String mimeType;
switch (objectTypeIndication) {
case 0x6B:
    mimeType=MimeTypes.AUDIO_MPEG;
  return Pair.create(mimeType,null);
case 0x20:
mimeType=MimeTypes.VIDEO_MP4V;
break;
case 0x21:
mimeType=MimeTypes.VIDEO_H264;
break;
case 0x23:
mimeType=MimeTypes.VIDEO_H265;
break;
case 0x40:
case 0x66:
case 0x67:
case 0x68:
mimeType=MimeTypes.AUDIO_AAC;
break;
case 0xA5:
mimeType=MimeTypes.AUDIO_AC3;
break;
case 0xA6:
mimeType=MimeTypes.AUDIO_EC3;
break;
case 0xA9:
case 0xAC:
mimeType=MimeTypes.AUDIO_DTS;
return Pair.create(mimeType,null);
case 0xAA:
case 0xAB:
mimeType=MimeTypes.AUDIO_DTS_HD;
return Pair.create(mimeType,null);
default :
mimeType=null;
break;
}
parent.skipBytes(12);
parent.skipBytes(1);
varIntByte=parent.readUnsignedByte();
int varInt=varIntByte & 0x7F;
while (varIntByte > 127) {
varIntByte=parent.readUnsignedByte();
varInt=varInt << 8;
varInt|=varIntByte & 0x7F;
}
byte[] initializationData=new byte[varInt];
parent.readBytes(initializationData,0,varInt);
return Pair.create(mimeType,initializationData);
}

private static Pair < String , byte [ ] > parseEsdsFromParent ( ParsableByteArray parent , int position ) { parent . setPosition ( position + Atom . HEADER_SIZE + 4 ) ; parent . skipBytes ( 1 ) ; int varIntByte = parent . readUnsignedByte ( ) ; while ( varIntByte > 127 ) { varIntByte = parent . readUnsignedByte ( ) ; } parent . skipBytes ( 2 ) ; int flags = parent . readUnsignedByte ( ) ; if ( ( flags & 0x80 ) != 0 ) { parent . skipBytes ( 2 ) ; } if ( ( flags & 0x40 ) != 0 ) { parent . skipBytes ( parent . readUnsignedShort ( ) ) ; } if ( ( flags & 0x20 ) != 0 ) { parent . skipBytes ( 2 ) ; } parent . skipBytes ( 1 ) ; varIntByte = parent . readUnsignedByte ( ) ; while ( varIntByte > 127 ) { varIntByte = parent . readUnsignedByte ( ) ; } int objectTypeIndication = parent . readUnsignedByte ( ) ; String mimeType ; switch ( objectTypeIndication ) { case 0x6B : mimeType = MimeTypes . AUDIO_MPEG ; return Pair . create ( mimeType , null ) ; case 0x20 : mimeType = MimeTypes . VIDEO_MP4V ; break ; case 0x21 : mimeType = MimeTypes . VIDEO_H264 ; break ; case 0x23 : mimeType = MimeTypes . VIDEO_H265 ; break ; case 0x40 : case 0x66 : case 0x67 : case 0x68 : mimeType = MimeTypes . AUDIO_AAC ; break ; case 0xA5 : mimeType = MimeTypes . AUDIO_AC3 ; break ; case 0xA6 : mimeType = MimeTypes . AUDIO_EC3 ; break ; case 0xA9 : case 0xAC : mimeType = MimeTypes . AUDIO_DTS ; return Pair . create ( mimeType , null ) ; case 0xAA : case 0xAB : mimeType = MimeTypes . AUDIO_DTS_HD ; return Pair . create ( mimeType , null ) ; default : mimeType = null ; break ; } parent . skipBytes ( 12 ) ; parent . skipBytes ( 1 ) ; varIntByte = parent . readUnsignedByte ( ) ; int varInt = varIntByte & 0x7F ; while ( varIntByte > 127 ) { varIntByte = parent . readUnsignedByte ( ) ; varInt = varInt << 8 ; varInt |= varIntByte & 0x7F ; } byte [ ] initializationData = new byte [ varInt ] ; parent . readBytes ( initializationData , 0 , varInt ) ; return Pair . create ( mimeType , initializationData ) ; }
returns codec - specific initialization data contained in an esds box .
