【问题标题】:Create processor for screen transmit RTSP为屏幕传输 RTSP 创建处理器
【发布时间】:2011-03-22 21:52:58
【问题描述】:

我有下一个类,用于通过Java中的音频或视频文件传输RTP。

到目前为止一切顺利。

我要的是修改UnicastRtp类来启用转屏,也就是可以像这样使用medialocator:

MediaLocator new ("screen://0,0,1280,800/25")

我在互联网上搜索了很多,并认为解决方案是改变您创建和配置处理器的方式。

为了传输屏幕内容,必须在StreamPantallaDataSourcePantalla类中支持。

我开发了一个程序,它能够在播放器中显示屏幕区域的内容(使用相同的 StreamPantallaDataSourcePantalla 类),所以我知道它们运行良好。

现在我需要更改UnicastRtp 类,以便能够配置处理器以传输屏幕内容。

不胜感激任何帮助或线索。

非常感谢您的帮助。

您好!

【问题讨论】:

    标签: java screen-scraping datasource rtp rtsp


    【解决方案1】:

    这是我的解决方案:

    MediaLocator ml=new MediaLocator("screen://0,0,1280,800/25");
    
    DataSource clone=null;
    
    try {
            ds = new DataSourcePantalla();
            ds.setLocator(ml);
            clone = javax.media.Manager.createCloneableDataSource(ds);
    } catch (Exception e) {
            System.out.println(e.getMessage());
    }
    
    try {
            ds.connect();
            clone.connect();
    } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
    Format[] outputFormat=new Format[1];
    FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.RAW_RTP);
    outputFormat[0]=new VideoFormat(VideoFormat.JPEG_RTP);
    ProcessorModel processorModel = new ProcessorModel(clone, outputFormat, outputType);
    
    // Try to create a processor to handle the input media locator
    try {
            processor = Manager.createRealizedProcessor(processorModel);
    } catch (NoProcessorException npe) {
            System.out.println(npe.getMessage());
    } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
    } 
    catch (CannotRealizeException e) {
            // TODO Auto-generated catch block
            System.out.println(e.getMessage());
    }
    
    boolean result = waitForState(processor, Processor.Configured);
    if (result == false){
            System.out.println("Error, No se pudo configurar el processor en UnicastRtpPantalla::createMyProcessor");
            return false;
    }
    
    TrackControl[] tracks = processor.getTrackControls();
    // Search through the tracks for a video track
    for (int i = 0; i < tracks.length; i++) {
            Format format = tracks[i].getFormat();
            if (tracks[i].isEnabled() && format instanceof VideoFormat) {
    System.out.println("Pista "+i+" de video tiene formato: "+tracks[i].getFormat());
    // Found a video track. Try to program it to output JPEG/RTP
    // Make sure the sizes are multiple of 8's.
    float frameRate = 25;//((VideoFormat) format).getFrameRate();
    Dimension size = new Dimension(1280, 800);//((VideoFormat) format).getSize();
    int w = (size.width % 8 == 0 ? size.width: (int) (size.width / 8) * 8);
    int h = (size.height % 8 == 0 ? size.height: (int) (size.height / 8) * 8);
    VideoFormat jpegFormat = new VideoFormat(VideoFormat.JPEG_RTP,
    new Dimension(w, h), Format.NOT_SPECIFIED,
    Format.byteArray, frameRate);
    tracks[i].setFormat(jpegFormat);
    System.out.println("Pista "+i+" de video se cambió a formato: "+tracks[i].getFormat());
            } else
    tracks[i].setEnabled(false);
    }
    //              // Set the output content descriptor to RAW_RTP
    ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
    processor.setContentDescriptor(cd);
    
    ds = processor.getDataOutput();
    

    问候!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      相关资源
      最近更新 更多