}
try{
TranscodeFileImpl transcode_file = allocateFile( profile, false, source, false );
AzureusContentFile acf = (AzureusContentFile)transcode_file.getTransientProperty( UPNPAV_FILE_KEY );
if ( acf != null ){
return;
}
final String tf_key = transcode_file.getKey();
synchronized( acf_map ){
acf = acf_map.get( tf_key );
}
if ( acf != null ){
return;
}
final DiskManagerFileInfo stream_file =
new DiskManagerFileInfoStream(
new DiskManagerFileInfoStream.StreamFactory()
{
private List<Object> current_requests = new ArrayList<Object>();
public StreamDetails
getStream(
Object request )
throws IOException
{
try{
TranscodeJobImpl job = getManager().getTranscodeManager().getQueue().add(
(TranscodeTarget)DeviceUPnPImpl.this,
profile,
source,
false,
true,
TranscodeTarget.TRANSCODE_UNKNOWN );
synchronized( this ){
current_requests.add( request );
}
while( true ){
InputStream is = job.getStream( 1000 );
if ( is != null ){
return( new StreamWrapper( is, job ));
}
int state = job.getState();
if ( state == TranscodeJobImpl.ST_FAILED ){
throw( new IOException( "Transcode failed: " + job.getError()));
}else if ( state == TranscodeJobImpl.ST_CANCELLED ){
throw( new IOException( "Transcode failed: job cancelled" ));
}else if ( state == TranscodeJobImpl.ST_COMPLETE ){
throw( new IOException( "Job complete but no stream!" ));
}
synchronized( this ){
if ( !current_requests.contains( request )){
break;
}
}
System.out.println( "waiting for stream" );
}
IOException error = new IOException( "Stream request cancelled" );
job.failed( error );
throw( error );
}catch( IOException e ){
throw( e );
}catch( Throwable e ){
throw( new IOException( "Failed to add transcode job: " + Debug.getNestedExceptionMessage(e)));
}finally{
synchronized( this ){
current_requests.remove( request );
}
}
}
public void
destroyed(
Object request )
{
synchronized( this ){
current_requests.remove( request );
}
}
},
transcode_file.getCacheFile());
acf = new AzureusContentFile()
{
public DiskManagerFileInfo
getFile()
{
return( stream_file );