public static IAudioStreamCodec getAudioCodec ( IoBuffer data ) { IAudioStreamCodec result = null ; try { //get the codec identifying byte int codecId = ( data . get ( ) & 0xf0 ) >> 4 ; switch ( codecId ) { case 10 : //aac result = ( IAudioStreamCodec ) Class . forName ( "org.red5.codec.AACAudio" ) . newInstance ( ) ; break ; case 11 : result = ( IAudioStreamCodec ) Class . forName ( "org.red5.codec.SpeexAudio" ) . newInstance ( ) ; break ; case 2 : case 14 : result = ( IAudioStreamCodec ) Class . forName ( "org.red5.codec.MP3Audio" ) . newInstance ( ) ; break ; } data . rewind ( ) ; } catch ( Exception ex ) { log . error ( "Error creating codec instance" , ex ) ; } //if codec is not found do the old-style loop if ( result == null ) { for ( IAudioStreamCodec storedCodec : codecs ) { IAudioStreamCodec codec ; // XXX: this is a bit of a hack to create new instances of the // configured audio codec for each stream try { codec = storedCodec . getClass ( ) . newInstance ( ) ; } catch ( Exception e ) { log . error ( "Could not create audio codec instance" , e ) ; continue ; } if ( codec . canHandleData ( data ) ) { result = codec ; break ; } } } return result ; }
Create and return new audio codec applicable for byte buffer data