开发者

freezing application using xuggler

firstly I apologize for 开发者_Go百科my bad english.

I am trying xuggler to read a display video from ip webcam using rts protocol. xuggler connects to camera and starts read a stream. after several minutes my app freezes. I also tried debug, but I could not see what happened in native libraries, which xuggler uses. When i add to my code system.out.println() before mediaReader.readPacket(); and after it, I realized that xuggler freezes in readPacket() method. Do you have any idea how to solve it?

Code, which I am using:

public class Test {
private static VideoImage mScreen = null;
private static IMediaListener mediaListener = new MediaListenerAdapter() {
    @Override
    public void onVideoPicture(IVideoPictureEvent event) {

         try {

             BufferedImage bi = event.getImage();//Utils.videoPictureToImage(pic);;
            updateJavaWindow(bi);

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

};

/**
 * @param args
 */
public static void main(String[] args) {
    IMediaReader mediaReader = ToolFactory.makeReader("rtsp://10.0.1.16/live3.sdp");
    mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
    mediaReader.setAddDynamicStreams(true);
    mediaReader.setQueryMetaData(false);
    mediaReader.addListener(mediaListener);
    mediaReader.getContainer().setInputBufferLength(64000000);
    mediaReader.getContainer().setProperty("probesize", 500000);

    openJavaWindow();
    while(true){
        System.out.println("reading packet");
        IError err = mediaReader.readPacket();
        System.out.println("end packet");
        if(err != null ){
            break;
        }
    }
    closeJavaWindow();
}



  private static void updateJavaWindow(BufferedImage javaImage)
  {
    mScreen.setImage(javaImage);
  }

  /**
   * Opens a Swing window on screen.
   */
  private static void openJavaWindow()
  {
    mScreen = new VideoImage();
  }

  /**
   * Forces the swing thread to terminate; I'm sure there is a right
   * way to do this in swing, but this works too.
   */
  private static void closeJavaWindow()
  {
    System.exit(0);
  }

}

thank you for your answer

Marek


If you try to stream this camera using the same protocol to some other program, do you get the same result? It could be a problem further down the line that Xuggler can't control. It may be Xuggler not handling an error in the stream properly though - if that's the case there's nothing much I know that you can do. Certainly doesn't sound like something you've done wrong in the code as far as I can see.

Failing that, the only thing I can think of is somehow firing the command off in a separate thread and forcing it to terminate if it takes longer than a certain time to come back. You could then experiment with what fixes it - it might just be a separate call to readPacket() works ok, or you may need to close / reopen the stream. It's a bodge, but working bodges are better than nothing!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜