public static IVideoStreamCodec getVideoCodec ( IoBuffer data ) { IVideoStreamCodec result = null ; //get the codec identifying byte int codecId = data . get ( ) & 0x0f ; try { switch ( codecId ) { case 2 : //sorenson result = ( IVideoStreamCodec ) Class . forName ( "org.red5.codec.SorensonVideo" ) . newInstance ( ) ; break ; case 3 : //screen video result = ( IVideoStreamCodec ) Class . forName ( "org.red5.codec.ScreenVideo" ) . newInstance ( ) ; break ; case 6 : //screen video 2 result = ( IVideoStreamCodec ) Class . forName ( "org.red5.codec.ScreenVideo2" ) . newInstance ( ) ; break ; case 7 : //avc/h.264 video result = ( IVideoStreamCodec ) Class . forName ( "org.red5.codec.AVCVideo" ) . newInstance ( ) ; break ; } } catch ( Exception ex ) { log . error ( "Error creating codec instance" , ex ) ; } data . rewind ( ) ; //if codec is not found do the old-style loop if ( result == null ) { for ( IVideoStreamCodec storedCodec : codecs ) { IVideoStreamCodec codec ; // XXX: this is a bit of a hack to create new instances of the // configured video codec for each stream try { codec = storedCodec . getClass ( ) . newInstance ( ) ; } catch ( Exception e ) { log . error ( "Could not create video codec instance" , e ) ; continue ; } if ( codec . canHandleData ( data ) ) { result = codec ; break ; } } } return result ; }
Create and return new video codec applicable for byte buffer data