2011-03-22 18 views
1

我有下一個類,它用於通過Java中的音頻或視頻文件傳輸RTP。創建用於屏幕傳輸的處理器RTSP

到目前爲止這麼好。

我要的是修改UnicastRtp類,使傳輸畫面,也就是說,你可以使用這樣一個MediaLocator:

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

我搜索互聯網上很多,並認爲解決的辦法是改變您創建和配置處理器的方式。

爲了傳輸屏幕的內容,它必須在StreamPantallaDataSourcePantalla類中得到支持。

我開發了一個程序,能夠在屏幕上顯示玩家的內容(使用相同的StreamPantallaDataSourcePantalla類),所以我知道它們運行良好。

現在我需要的是將UnicastRtp類更改爲可以配置處理器以傳輸屏幕內容。

希望得到任何幫助或線索。

非常感謝您的幫助。

問候!

回答

2

這是我的解決方案:

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(); 

商祺!