开发者

Create processor for screen transmit RTSP

开发者 https://www.devze.com 2023-02-18 21:29 出处:网络
I have the next class, which is used to transmit RTP via audio or video files in Java. So far so good.

I have the next class, which is used to transmit RTP via audio or video files in Java.

So far so good.

What I want is to modify the UnicastRtp c开发者_运维知识库lass to enable the transfer the screen, that is, you can use a medialocator like this:

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

I searched a lot on Internet and think the solution is to change the way you create and configure the processor.

In order to transmit the contents of the screen, it must be supported in StreamPantalla and DataSourcePantalla classes.

I developed a program that is able to display content in a player from an area of the screen (using the same StreamPantalla and DataSourcePantalla classes ), so I know they work well.

Now what I need is change the UnicastRtp class to be able to configure a processor for transmitting the contents of the screen.

Would appreciate any help or clues.

Thank you very much for the help.

Greetings!


This is my solution:

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

Regards!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号