b_map.put( "state", new Integer( 1 ));
b_map.put( "msg", MessageText.getString( "stream.analysing.media" ));
buffering_method.invoke(player, new Object[] { b_map });
final TranscodeJob tj = queue.add( dmr, profile, file, true );
try{
final AESemaphore sem = new AESemaphore( "analyserWait" );
synchronized( StreamManager.this ){
if ( cancelled ){
throw( new Exception( "Cancelled" ));
}
active_sem = sem;
active_job = tj;
}
final long[] properties = new long[3];
final Throwable[] error = { null };
tj.analyseNow(
new TranscodeAnalysisListener()
{
public void
analysisComplete(
TranscodeJob file,
TranscodeProviderAnalysis analysis )
{
try{
properties[0] = analysis.getLongProperty( TranscodeProviderAnalysis.PT_DURATION_MILLIS );
properties[1] = analysis.getLongProperty( TranscodeProviderAnalysis.PT_VIDEO_WIDTH );
properties[2] = analysis.getLongProperty( TranscodeProviderAnalysis.PT_VIDEO_HEIGHT );
tj.removeForce();
}finally{
sem.releaseForever();
}
}
public void
analysisFailed(
TranscodeJob file,
TranscodeException e )
{
try{
error[0] = e;
tj.removeForce();
}finally{
sem.releaseForever();
}
}
});
new AEThread2( "SM:anmon" )
{
public void
run()
{
boolean last_preview_mode = preview_mode;
while( !sem.isReleasedForever() && !cancelled ){
if ( !sem.reserve( 250 )){
if ( cancelled ){
return;
}
try{
Boolean b = (Boolean)is_active_method.invoke( player, new Object[0] );
if ( !b ){
cancel();
break;
}
}catch( Throwable e ){
}
if ( last_preview_mode != preview_mode ){
last_preview_mode = preview_mode;
b_map.put( "msg", MessageText.getString( last_preview_mode?"stream.analysing.media.preview":"stream.analysing.media" ));
}
DownloadStats stats = download.getStats();
b_map.put( "dl_rate", stats.getDownloadAverage());
b_map.put( "dl_size", stats.getDownloaded());
b_map.put( "dl_time", SystemTime.getMonotonousTime() - stream_start );
try{
buffering_method.invoke(player, new Object[] { b_map });
}catch( Throwable e ){
}
}
}
}
}.start();
sem.reserve();
synchronized( StreamManager.this ){
if ( cancelled ){
throw( new Exception( "Cancelled" ));
}
active_job = null;
active_sem = null;
}
if ( error[0] != null ){
throw( error[0] );
}
duration = properties[0];
video_width = properties[1];
video_height = properties[2];
if ( duration > 0 ){
if ( map == null ){
map = new HashMap<String, Map<String,Object>>();
}else{
map = new HashMap<String, Map<String,Object>>( map );
}
Map<String,Object> file_map = map.get( String.valueOf( file_index ));
if ( file_map == null ){
file_map = new HashMap<String, Object>();
map.put( String.valueOf( file_index ), file_map );
}
file_map.put( "duration", duration );
file_map.put( "video_width", video_width );
file_map.put( "video_height", video_height );
download.setMapAttribute( mi_ta, map );
}
}catch( Throwable e ){
tj.removeForce();
throw( e );
}
}catch( Throwable e ){