Package org.gudy.azureus2.plugins.ipc

Examples of org.gudy.azureus2.plugins.ipc.IPCInterface


    if ( pi == null ){
     
      throw( new IOException( "Plugin id " + plugin_str + " not installed" ));
    }
   
    IPCInterface ipc = pi.getIPC();
   
    try{
      if ( ipc.canInvoke( "handleURLProtocol", new Object[]{ this, arg })){
         
        input_stream = (InputStream)ipc.invoke( "handleURLProtocol", new Object[]{ this, arg });

      }else{
     
        input_stream = (InputStream)ipc.invoke( "handleURLProtocol", new Object[]{ arg });
      }
    }catch( IPCException ipce ){
     
      Throwable e = ipce;
     
View Full Code Here


  protected void
  addListener(
    PluginInterface  pi )
  {
    try{     
      IPCInterface my_ipc =
        new IPCInterfaceImpl(
          new Object()
          {
            public Map<String,Object>
            browseReceived(
View Full Code Here

    if ( getManager().isClosing()){
     
      return;
    }
   
    IPCInterface  ipc = itunes.getIPC();
   
    try{
      Map<String,Object> properties = (Map<String,Object>)ipc.invoke( "getProperties", new Object[]{} );

      is_installed = (Boolean)properties.get( "installed" );
     
      boolean  was_running = is_running;
     
View Full Code Here

       
        try{
          File  file = transcode_file.getTargetFile().getFile();
         
          try{
            IPCInterface  ipc = itunes.getIPC();
           
            if ( !is_running ){
             
              log( "Auto-starting iTunes" );
            }

            Map<String,Object> result = (Map<String,Object>)ipc.invoke( "addFileToLibrary", new Object[]{ file } );
   
            Throwable error = (Throwable)result.get( "error" );
           
            if ( error != null ){
             
View Full Code Here

        if ( av_pi == null ){
       
          throw( new TranscodeException( "Media Server plugin not found" ));
        }
       
        IPCInterface av_ipc = av_pi.getIPC();
       
        String url_str = (String)av_ipc.invoke( "getContentURL", new Object[]{ input });
   
        if ( url_str != null && url_str.length() > 0 ){
       
          source_url = new URL( url_str );
     
          pipe = new TranscodePipeStreamSource( source_url.getHost(), source_url.getPort());
       
          source_url = UrlUtils.setHost( source_url, "127.0.0.1" );

          source_url = UrlUtils.setPort( source_url, pipe.getPort());         
        }
      }
     
      if ( source_file == null && source_url == null ){
     
        throw( new TranscodeException( "File doesn't exist" ));
      }

      final TranscodePipe f_pipe = pipe;
     
      try
        final IPCInterface  ipc = plugin_interface.getIPC();

        final Object analysis_context;
       
        if ( source_url != null ){
         
          analysis_context = ipc.invoke(
            "analyseContent",
            new Object[]{
              source_url,
              profile.getName() });
        }else{
         
          analysis_context = ipc.invoke(
            "analyseContent",
            new Object[]{
              source_file,
              profile.getName() });
        }
       
        final Map<String,Object>  result = new HashMap<String, Object>();
       
        final TranscodeProviderAnalysisImpl analysis =
          new TranscodeProviderAnalysisImpl()
          {
            public void
            cancel()
            {
              try{
                ipc.invoke( "cancelAnalysis", new Object[]{ analysis_context });
               
              }catch( Throwable e ){
               
                Debug.printStackTrace( e );
              }
            }
           
            public boolean
            foundVideoStream()
            {
              return( getLongProperty( PT_VIDEO_WIDTH ) > 0 );
            }
           
            public boolean
            getBooleanProperty(
              int    property )
            {
              if ( property == PT_TRANSCODE_REQUIRED ){
               
                return( getBooleanProperty( "xcode_required", true ));
               
              }else{
               
                Debug.out( "Unknown property: " + property );
               
                return( false );
              }
            }
           
            public void
            setBooleanProperty(
              int    property,
              boolean  value )
            {
              if ( property == PT_FORCE_TRANSCODE ){
               
                result.put( "force_xcode", value );
               
              }else{
               
                Debug.out( "Unknown property: " + property );
              }
            }
           
            public long
            getLongProperty(
              int    property )
            {
              if ( property == PT_DURATION_MILLIS ){
               
                long duration = getLongProperty( "duration_millis", 0 );
               
                long audio_duration  = getLongProperty( "audio_duration_millis", 0 );
               
                if ( duration <= 0 && audio_duration > 0 ){
                 
                  duration = audio_duration;
                }
               
                if ( audio_duration > 0 && audio_duration < duration ){
                 
                  duration = audio_duration;
                }
             
                return( duration );
               
              }else if ( property == PT_VIDEO_WIDTH ){
               
                return( getLongProperty( "video_width", 0 ));
 
              }else if ( property == PT_VIDEO_HEIGHT ){
               
                return( getLongProperty( "video_height", 0 ));
 
              }else if ( property == PT_SOURCE_SIZE ){
               
                return( getLongProperty( "source_size", 0 ));

              }else if ( property == PT_ESTIMATED_XCODE_SIZE ){
               
                return( getLongProperty( "estimated_transcoded_size", 0 ));

              }else{
               
                Debug.out( "Unknown property: " + property );
               
                return( 0 );
              }
            }
           
            protected boolean
            getBooleanProperty(
              String    name,
              boolean    def )
            {
              Boolean b = (Boolean)result.get( name );
             
              if ( b != null ){
               
                return( b );
              }
             
              return( def );
            }
           
            protected long
            getLongProperty(
              String    name,
              long    def )
            {
              Long l = (Long)result.get( name );
             
              if ( l != null ){
               
                return( l );
              }
             
              return( def );
            }
           
            public Map<String,Object>
            getResult()
            {
              return( result );
            }
          };
         
        new AEThread2( "analysisStatus", true )
        {
          public void
          run()
          {
            try{
              while( true ){
                               
                try{
                  Map status = (Map)ipc.invoke( "getAnalysisStatus", new Object[]{ analysis_context });
                 
                  long  state = (Long)status.get( "state" );
                 
                  if ( state == 0 ){
 
View Full Code Here

        }
      }
     
      if ( source_url == null ){
       
        IPCInterface av_ipc = av_pi.getIPC();
       
        String url_str = (String)av_ipc.invoke( "getContentURL", new Object[]{ input });
       
       
        if ( url_str == null || url_str.length() == 0 ){
         
            // see if we can use the file directly
         
          File source_file = input.getFile();
         
          if ( source_file.exists()){
           
            pipe =
              new TranscodePipeFileSource(
                  source_file,
                  new TranscodePipe.errorListener()
                  {
                    public void
                    error(
                      Throwable e )
                    {
                      _adapter.failed(
                        new TranscodeException( "File access error", e ));
                     
                      if ( xcode_job[0] != null ){
                       
                        xcode_job[0].cancel();
                      }
                    }
                  });
           
            source_url = new URL( "http://127.0.0.1:" + pipe.getPort() + "/" );
           
          }else{
           
            throw( new TranscodeException( "Source file doesn't exist" ));
          }
        }else{
          source_url = new URL( url_str );
       
          pipe = new TranscodePipeStreamSource( source_url.getHost(), source_url.getPort());
         
          source_url = UrlUtils.setHost( source_url, "127.0.0.1" );

          source_url = UrlUtils.setPort( source_url, pipe.getPort());   
        }
      }
     
      final TranscodePipe f_pipe = pipe;
     
      try
        final IPCInterface  ipc = plugin_interface.getIPC();

        final Object context;
       
        final TranscodeProviderAdapter  adapter;
       
        if ( output.getProtocol().equals( "tcp" )){
         
          adapter = _adapter;
         
          context =
            ipc.invoke(
              "transcodeToTCP",
              new Object[]{
                ((TranscodeProviderAnalysisImpl)analysis).getResult(),
                source_url,
                profile.getName(),
                output.getPort() });
        }else{
         
          final File file = new File( output.toURI());
           
          adapter =
            new TranscodeProviderAdapter()
            {
              public void
              updateProgress(
                int    percent,
                int    eta_secs,
                int    width,
                int    height )
              {
                _adapter.updateProgress( percent, eta_secs, width, height );
              }
             
              public void
              streamStats(
                long          connect_rate,
                long          write_speed )
              {
                _adapter.streamStats(connect_rate, write_speed);
              }
             
              public void
              failed(
                TranscodeException    error )
              {
                try{
                  file.delete();
                 
                }finally{
                 
                  _adapter.failed( error );
                }
              }
             
              public void
              complete()
              {
                _adapter.complete();
              }
            };
           
          context =
            ipc.invoke(
              "transcodeToFile",
              new Object[]{
                ((TranscodeProviderAnalysisImpl)analysis).getResult(),
                source_url,
                profile.getName(),
                file });
        }
 
        new AEThread2( "xcodeStatus", true )
          {
            public void
            run()
            {
              try{
                boolean  in_progress = true;
               
                while( in_progress ){
                 
                  in_progress = false;
                 
                  if ( f_pipe != null ){
                   
                    adapter.streamStats( f_pipe.getConnectionRate(), f_pipe.getWriteSpeed());                   
                  }
                 
                  try{
                    Map status = (Map)ipc.invoke( "getTranscodeStatus", new Object[]{ context });
                   
                    long  state = (Long)status.get( "state" );
                   
                    if ( state == 0 ){
                     
                      int  percent = (Integer)status.get( "percent" );
                     
                      Integer  i_eta  = (Integer)status.get( "eta_secs" );
                     
                      int eta = i_eta==null?-1:i_eta;
                     
                      Integer  i_width  = (Integer)status.get( "new_width" );
                     
                      int width = i_width==null?0:i_width;
                     
                      Integer  i_height  = (Integer)status.get( "new_height" );
                     
                      int height = i_height==null?0:i_height;
                     
                      adapter.updateProgress( percent, eta, width, height );
                     
                      if ( percent == 100 ){
                       
                        adapter.complete();
   
                      }else{
                       
                        in_progress = true;
                     
                        Thread.sleep(1000);
                      }
                    }else if ( state == 1 ){
                     
                      adapter.failed( new TranscodeException( "Transcode cancelled" ));
                     
                    }else{
                     
                      adapter.failed( new TranscodeException( "Transcode failed", (Throwable)status.get( "error" )));
                    }
                  }catch( Throwable e ){
                   
                    adapter.failed( new TranscodeException( "Failed to get status", e ));
                  }
                }
              }finally{
               
                if ( f_pipe != null ){
               
                  f_pipe.destroy();
                }
              }
            }
          }.start();
         
     
        xcode_job[0] =
          new TranscodeProviderJob()
          {
            public void
            pause()
            {
              if ( f_pipe != null ){
             
                f_pipe.pause();
              }
            }
           
            public void
            resume()
            {
              if ( f_pipe != null ){
               
                f_pipe.resume();
              }
            }
 
            public void
            cancel()
            {
              try{
                ipc.invoke( "cancelTranscode", new Object[]{ context });
               
              }catch( Throwable e ){
               
                Debug.printStackTrace( e );
              }
View Full Code Here

          if ( av_pi == null ){
         
            throw( new TranscodeException( "Media Server plugin not found" ));
          }
         
          IPCInterface av_ipc = av_pi.getIPC();
         
          String url_str = (String)av_ipc.invoke( "getContentURL", new Object[]{ source });
         
         
          if ( url_str == null || url_str.length() == 0 ){
           
              // see if we can use the file directly
           
            File source_file = source.getFile();
           
            if ( source_file.exists()){
             
              job.setStream( new BufferedInputStream( new FileInputStream( source_file )));
             
            }else{
             
              throw( new TranscodeException( "No UPnPAV URL and file doesn't exist" ));
            }
          }else{
           
            URL source_url = new URL( url_str );
         
            job.setStream( source_url.openConnection().getInputStream());
          }
        }else{
         
          if ( device.getAlwaysCacheFiles()){
           
            PluginInterface av_pi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByID( "azupnpav" );
           
            if ( av_pi == null ){
           
              throw( new TranscodeException( "Media Server plugin not found" ));
            }
           
            IPCInterface av_ipc = av_pi.getIPC();
           
            String url_str = (String)av_ipc.invoke( "getContentURL", new Object[]{ source });
           
            InputStream  is;
           
            long    length;
           
View Full Code Here

   
    if ( existing != filter ){
   
      setPersistentBooleanProperty( PP_FILTER_FILES, filter );
   
      IPCInterface ipc = upnpav_ipc;
     
      if ( ipc != null ){
       
        try{
          ipc.invoke( "invalidateDirectory", new Object[]{});

        }catch( Throwable e ){
        }
      }
    }
View Full Code Here

  }
 
  protected void
  browseReceived()
  {
    IPCInterface ipc = upnp_manager.getUPnPAVIPC();
   
    if ( ipc == null ){
     
      return;
    }
View Full Code Here

  addDynamicXCode(
    final DiskManagerFileInfo    source )
  {
    final TranscodeProfile profile = dynamic_transcode_profile;
   
    IPCInterface      ipc  = upnpav_ipc;
   
    if ( profile == null || ipc == null ){
     
      return;
    }
   
    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 );
               }
              
            public Object
            getProperty(
              String    name )
            {
                // TODO: duration etc

              if ( name.equals( MY_ACF_KEY )){
               
                return( new Object[]{ DeviceUPnPImpl.this, tf_key });
               
              }else if ( name.equals( PT_PERCENT_DONE )){
               
                return( new Long(1000));
               
              }else if ( name.equals( PT_ETA )){
               
                return( new Long(0));
              }
             
              return( null );
            }
          };
     
      synchronized( acf_map ){

        acf_map.put( tf_key, acf );
      }
         
      transcode_file.setTransientProperty( UPNPAV_FILE_KEY, acf );

      syncCategories( transcode_file, true );
         
      synchronized( this ){
       
        if ( dynamic_xcode_map == null ){
         
          dynamic_xcode_map = new HashMap<String,AzureusContentFile>();
        }
       
        dynamic_xcode_map.put( tf_key, acf );
      }
     
      ipc.invoke( "addContent", new Object[]{ acf });
     
    }catch( Throwable e ){
     
      Debug.out( e );
    }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.plugins.ipc.IPCInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.