/**
   * addPipeline will add a pipeline for the specified capture device to the bin.
   *
   * @param captureDevice {@code CaptureDevice} to create pipeline around
   * @param pipeline The {@code Pipeline} bin to add it to
   * @return True, if successful
   */
  protected boolean addCaptureDeviceBinsToPipeline(CaptureDevice captureDevice, Pipeline pipeline) {

    CaptureDeviceBin captureDeviceBin = null;
    try {
      captureDeviceBin = new CaptureDeviceBin(captureDevice, properties);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    pipeline.add(captureDeviceBin.getBin());
    // Add them to a list so that we can send EOS's to their source Elements.
    captureDeviceBins.add(captureDeviceBin);
    return true;
  }
  public void PlayVideoStream() {
    // debugGST();

    String rtspsource = "";
    if (Parent.Camera.GetColorMode() == ColorMode.RGB) {
      rtspsource =
          "rtspsrc location=rtsp://"
              + Parent.Camera.GetIP()[0]
              + ":554 protocols=0x00000001 latency=60 name=camerasource ! rtpjpegdepay ! jpegdec ! decodebin2 ! ffmpegcolorspace name=elphelstream";
    } else if (Parent.Camera.GetColorMode() == ColorMode.JP46) {
      //            rtspsrc location=rtsp://" + Parent.Camera.GetIP() + ":554 protocols=0x00000001
      // latency=50 ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 !
      // ffmpegcolorspace ! videorate ! "video/x-raw-yuv, format=(fourcc)I420, width=(int)1920,
      // height=(int)1088, framerate=(fraction)25/1" ! xvimagesink sync=false max-lateness=-1
      rtspsource =
          "rtspsrc location=rtsp://"
              + Parent.Camera.GetIP()[0]
              + ":554 protocols=0x00000001 latency=60 name=camerasource ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 method=0 ! ffmpegcolorspace  name=elphelstream";
    } else {
      // TODO in this mode we dont see anything from the non-jpeg compliant stream so the jp46
      // filter wont help, but what else should we show?
      rtspsource =
          "rtspsrc location=rtsp://"
              + Parent.Camera.GetIP()[0]
              + ":554 protocols=0x00000001 latency=60 name=camerasource ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 method=0 name=elphelstream";
    }

    pipe = Pipeline.launch(rtspsource);

    videoComponent.setKeepAspect(true);
    Element videosink = videoComponent.getElement();
    pipe.add(videosink);

    pipe.getElementByName("elphelstream").link(videosink);

    pipe.getBus()
        .connect(
            new Bus.EOS() {

              public void endOfStream(GstObject source) {
                System.out.println("Finished playing file");
                // Gst.quit();
              }
            });
    /*pipe.getBus().connect(new Bus.INFO() {

    public void infoMessage(GstObject source, int code, String message) {
    System.out.println("message: " + message);
    }
    });
    pipe.getBus().connect(new Bus.MESSAGE() {

    public void busMessage(Bus bus, Message message) {
    System.out.println("message: " + message);
    }
    });
    pipe.getBus().connect(new Bus.WARNING() {

    public void warningMessage(GstObject source, int code, String message) {
    System.out.println("warning: " + message);
    }
    });*/
    pipe.getBus()
        .connect(
            new Bus.ERROR() {

              public void errorMessage(GstObject source, int code, String message) {
                System.out.println("Error occurred: " + message);
                Gst.quit();
              }
            });
    /*pipe.getBus().connect(new Bus.STATE_CHANGED() {

    public void stateChanged(GstObject source, State old, State current, State pending) {
    if (source == pipe) {
    System.out.println("Pipeline state changed from " + old + " to " + current);
    }
    }
    });*/

    pipe.setState(State.PLAYING);

    /*
    Playbin.add(videosink);
    //     Pipeline pipe = new Pipeline("SimplePipeline");
    /*
    Element src = ElementFactory.make("rtspsrc", "elphelsrc");
    src.set("location", "rtsp://" + Parent.Camera.GetIP()[0] + ":554");
    src.set("protocols", "00000001"); // "0x00000001" doesnt work
    src.set("latency", "50");
    Playbin.add(src);*/
    // Playbin.getElementByName("elphelsrc").link(Playbin.getSinks().get(0));
    // Element sink = ElementFactory.make("fakesink", "Destination");
    // Playbin.addMany(src, sink);
    // src.link(sink);*/
    // Playbin2
    /*
    try {
    Playbin.setURI(new URI("rtsp://" + Parent.Camera.GetIP()[0] + ":554"));
    } catch (URISyntaxException ex) {
    Logger.getLogger(GstreamerPlayer.class.getName()).log(Level.SEVERE, null, ex);
    }
    //.getElementByName("uri").set("protocols", "00000001");
    //Playbin.getElementByName("uri").set("latency", "50");

    //Playbin.setInputFile(new File("test.avi")); // works

    // Playbin.set("buffer-duration", 0); // NO Effect
    // Playbin.set("buffer-size", 0); // NO Effect

    Playbin.setState(State.PLAYING);
     */
    /*
    final List<URI> playList = new LinkedList<URI>();
    for (String arg : args) {
    playList.add(new File(arg).toURI());
    }

    GSTPlayer.setPreferredSize(new Dimension(640, 480));
    GSTPlayer.setControlsVisible(false);
    //player.setKeepAspect(true);
    GSTPlayer.getMediaPlayer().setPlaylist(playList);
    GSTPlayer.getMediaPlayer().play();

     */
    // GstreamerPlayer.SetVideocomponent(GstreamerVideoComponent);
    /*
    String rtspsource = "";
    if (Parent.Camera.GetColorMode() == ColorMode.RGB) {
    rtspsource = "rtspsrc location=rtsp://" + Parent.Camera.GetIP()[0] + ":554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! decodebin ! ffmpegcolorspace name=elphelstream";
    } else if (Parent.Camera.GetColorMode() == ColorMode.JP46) {
    //            rtspsrc location=rtsp://" + Parent.Camera.GetIP() + ":554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 ! ffmpegcolorspace ! videorate ! "video/x-raw-yuv, format=(fourcc)I420, width=(int)1920, height=(int)1088, framerate=(fraction)25/1" ! xvimagesink sync=false max-lateness=-1
    rtspsource = "rtspsrc location=rtsp://" + Parent.Camera.GetIP()[0] + ":554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 method=0 ! ffmpegcolorspace  name=elphelstream";
    } else {
    //TODO in this mode we dont see anything from the non-jpeg compliant stream so the jp46 filter wont help, but what else should we show?
    rtspsource = "rtspsrc location=rtsp://" + Parent.Camera.GetIP()[0] + ":554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! jp462bayer ! queue ! bayer2rgb2 method=0 name=elphelstream";
    }

    //Notes

    //LUT
    //gst-launch rtspsrc location=rtsp://192.168.10.141:554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! ffmpegcolorspace ! videorate ! coloreffects preset=heat ! ffmpegcolorspace ! autovideosink -v

    //edge detection:
    //gst-launch rtspsrc location=rtsp://192.168.10.141:554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! ffmpegcolorspace ! videorate ! edgetv ! ffmpegcolorspace ! autovideosink -v

    // kind of scopes
    //gst-launch rtspsrc location=rtsp://192.168.10.141:554 protocols=0x00000001 latency=50 ! rtpjpegdepay ! jpegdec ! queue ! ffmpegcolorspace ! videorate ! revtv ! ffmpegcolorspace ! autovideosink -v

    pipe = Pipeline.launch(rtspsource);

    videoComponent.setKeepAspect(true);
    Element videosink = videoComponent.getElement();
    pipe.add(videosink);
    pipe.getElementByName("elphelstream").link(videosink);


    pipe.setState(State.PLAYING);
    List<Element> sinks = pipe.getSinks();

    /*

    String rtspsource = "rtspsrc location=rtsp://" + Parent.Camera.GetIP() + ":554 latency=30 ! rtpjpegdepay ! jpegdec name=elphelstream";
    pipe = Pipeline.launch(rtspsource);

    //pipe = new Pipeline("GstreamerViewer");

    //videosrc = ElementFactory.make("videotestsrc", "source");
    //videosrc = ElementFactory.make("rtspsource ", "source");
    ///videosrc.setCaps(Caps.fromString("location=rtsp://192.168.10.141:554 latency=30"));
    //Element rtpjpegdepay = ElementFactory.make("rtpjpegdepay", "rtpjpegdepay");
    //Element jpegdec = ElementFactory.make("jpegdec", "jpegdec");

    Element videosink = ElementFactory.make("xvimagesink", "sink");

    //Element videosink = videoComponent.getElement();
    pipe.add(videosink);
    pipe.getElementByName("elphelstream").link(videosink);

    //playbin.setInputFile(new File(args[0]));
    //pipe.addMany(videosrc, rtpjpegdepay, jpegdec, videosink);
    //videosrc.link(videosink);
    //Element.linkMany(videosrc, rtpjpegdepay, jpegdec, videosink);
    pipe.setState(State.PLAYING);
    Gst.main();
    pipe.setState(State.NULL);


    //gst-launch rtspsrc location=rtsp://192.168.10.141:554 latency=30 ! rtpjpegdepay ! jpegdec ! xvimagesink

    //VideoComponent videoComponent = new VideoComponent();
    //videosink = videoComponent.getElement();
    //playbin.setVideoSink(videosink);


    //Element.linkMany(videosrc, videosink);*/
  }
Exemple #3
-10
  private static void startStreaming(final VideoComponent vc, String settings, int port) {
    Gst.init();
    clientPipe = new Pipeline("pipeline");
    pushLog("> CTRL: " + "PLAY");
    pushLog("> SYS: " + " INIT STREAM");

    System.out.println("Starting with: C=" + clientLoc + ", S=" + serverLoc);

    // VIDEO
    Element udpVideoSrc = ElementFactory.make("udpsrc", "src1");
    udpVideoSrc.setCaps(
        Caps.fromString(
            "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG, payload=(int)96, ssrc=(uint)2156703816, clock-base=(uint)1678649553, seqnum-base=(uint)31324"));
    udpVideoSrc.set("uri", "udp://" + clientLoc + ":" + port);

    Element videoRtcpIn = ElementFactory.make("udpsrc", "src3");
    videoRtcpIn.set("uri", "udp://" + clientLoc + ":" + (port + 1));

    Element videoRtcpOut = ElementFactory.make("udpsink", "snk1");
    videoRtcpOut.set("host", serverLoc);
    videoRtcpOut.set("port", "" + (port + 5));
    videoRtcpOut.set("sync", "false");
    videoRtcpOut.set("async", "false");

    Element udpAudioSrc = null, audioRtcpIn = null, audioRtcpOut = null, taud = null;

    if (attribute.equalsIgnoreCase("active")) {
      // AUDIO
      udpAudioSrc = ElementFactory.make("udpsrc", "src2");
      udpAudioSrc.setCaps(
          Caps.fromString(
              "application/x-rtp, media=(string)audio, clock-rate=(int)8000, encoding-name=(string)L16, encoding-params=(string)2, channels=(int)2, payload=(int)96, ssrc=(uint)3489550614, clock-base=(uint)2613725642, seqnum-base=(uint)1704"));
      udpAudioSrc.set("uri", "udp://" + clientLoc + ":" + (port + 2));

      taud = ElementFactory.make("tee", "taud");
      Element qaud = ElementFactory.make("queue", "qaud");
      AppSink appAudioSink = (AppSink) ElementFactory.make("appsink", "appAudioSink");
      appAudioSink.set("emit-signals", true);
      appAudioSink.setSync(false);
      audioQ = new LinkedList<FrameInfo>();
      appAudioSink.connect(
          new AppSink.NEW_BUFFER() {
            public void newBuffer(AppSink sink) {
              Buffer b = sink.getLastBuffer();
              if (b != null) {
                audioQ.offer(new FrameInfo(System.currentTimeMillis(), b.getSize()));
              }
            }
          });

      audioRtcpIn = ElementFactory.make("udpsrc", "src4");
      audioRtcpIn.set("uri", "udp://" + clientLoc + ":" + (port + 3));

      audioRtcpOut = ElementFactory.make("udpsink", "snk2");
      audioRtcpOut.set("host", serverLoc);
      audioRtcpOut.set("port", "" + (port + 7));
      audioRtcpOut.set("sync", "false");
      audioRtcpOut.set("async", "false");

      clientPipe.addMany(taud, qaud, appAudioSink);
      clientPipe.addMany(udpAudioSrc, audioRtcpIn, audioRtcpOut);
      Element.linkMany(udpAudioSrc, taud, qaud, appAudioSink);
    }

    Element tvid = ElementFactory.make("tee", "tvid");
    Element qvid = ElementFactory.make("queue", "qvid");
    AppSink appVideoSink = (AppSink) ElementFactory.make("appsink", "appVideoSink");
    appVideoSink.set("emit-signals", true);
    appVideoSink.setSync(false);
    videoQ = new LinkedList<FrameInfo>();
    appVideoSink.connect(
        new AppSink.NEW_BUFFER() {
          public void newBuffer(AppSink sink) {
            Buffer b = sink.getLastBuffer();
            if (b != null) {
              videoQ.offer(new FrameInfo(System.currentTimeMillis(), b.getSize()));
              // System.out.println(System.currentTimeMillis());
            }
          }
        });
    clientPipe.addMany(tvid, qvid, appVideoSink);
    clientPipe.addMany(udpVideoSrc, videoRtcpIn, videoRtcpOut);
    Element.linkMany(udpVideoSrc, tvid, qvid, appVideoSink);

    // VIDEO BIN

    videoBin = new Bin("videoBin");

    // src1
    Element videoDepay = ElementFactory.make("rtpjpegdepay", "depay");
    Element videoDecode = ElementFactory.make("jpegdec", "decode");
    Element videoRate = ElementFactory.make("videorate", "rate1");
    Element videoColor = ElementFactory.make("ffmpegcolorspace", "color");
    Element videoSrc1Caps = ElementFactory.make("capsfilter", "src1caps");
    videoSrc1Caps.setCaps(Caps.fromString("video/x-raw-yuv, framerate=30/1"));
    Element videoColor2 = ElementFactory.make("ffmpegcolorspace", "color2");

    videoBin.addMany(videoDepay, videoDecode, videoRate, videoColor, videoSrc1Caps, videoColor2);
    Element.linkMany(videoDepay, videoDecode, videoRate, videoColor, videoSrc1Caps, videoColor2);

    videoBin.addPad(new GhostPad("sink", videoDepay.getStaticPad("sink")));
    clientPipe.add(videoBin);

    final Bin audioBin = new Bin("audioBin");

    if (attribute.equalsIgnoreCase("active")) {
      // AUDIO BIN

      final Element audioDepay = ElementFactory.make("rtpL16depay", "auddepay");
      Element audioConvert = ElementFactory.make("audioconvert", "audconv");
      mute = ElementFactory.make("volume", "vol");
      mute.set("mute", "true");
      final Element audioSink = ElementFactory.make("autoaudiosink", "audsink");

      audioBin.addMany(audioDepay, audioConvert, mute, audioSink);
      Element.linkMany(audioDepay, audioConvert, mute, audioSink);

      audioBin.addPad(new GhostPad("sink", audioDepay.getStaticPad("sink")));
      clientPipe.add(audioBin);
    }

    // RTPBIN

    final RTPBin rtp = new RTPBin("rtp");
    clientPipe.add(rtp);

    Element.linkPads(tvid, "src1", rtp, "recv_rtp_sink_0");
    Element.linkPads(videoRtcpIn, "src", rtp, "recv_rtcp_sink_0");
    Element.linkPads(rtp, "send_rtcp_src_0", videoRtcpOut, "sink");

    if (attribute.equalsIgnoreCase("active")) {
      Element.linkPads(taud, "src1", rtp, "recv_rtp_sink_1");
      Element.linkPads(audioRtcpIn, "src", rtp, "recv_rtcp_sink_1");
      Element.linkPads(rtp, "send_rtcp_src_1", audioRtcpOut, "sink");
    }

    // BUS

    rtp.connect(
        new Element.PAD_ADDED() {
          @Override
          public void padAdded(Element arg0, Pad arg1) {
            if (arg1.getName().startsWith("recv_rtp_src_0")) {
              arg1.link(videoBin.getStaticPad("sink"));
            } else if (arg1.getName().startsWith("recv_rtp_src_1")
                && attribute.equalsIgnoreCase("active")) {
              arg1.link(audioBin.getStaticPad("sink"));
            }
            clientPipe.debugToDotFile(1, "clientsucc");
          }
        });

    Bus bus = clientPipe.getBus();

    bus.connect(
        new Bus.ERROR() {
          public void errorMessage(GstObject source, int code, String message) {
            pushLog("> GSTREAMER ERROR: code=" + code + " message=" + message);
            clientPipe.debugToDotFile(1, "clienterr");
          }
        });
    bus.connect(
        new Bus.EOS() {

          public void endOfStream(GstObject source) {
            clientPipe.setState(State.NULL);
            System.out.println("EOS");
          }
        });

    videoBin.add(vc.getElement());

    AppSink appJointSink = (AppSink) ElementFactory.make("appsink", "appJointSink");
    appJointSink.set("emit-signals", true);
    appJointSink.setSync(false);
    jointQ = new LinkedList<CompareInfo>();
    appJointSink.connect(
        new AppSink.NEW_BUFFER() {
          public void newBuffer(AppSink sink) {
            /*
            int vs = 0; int as = 0;
            while (videoQ != null) {
            	vs++; videoQ.poll();
            }
            while (audioQ != null) {
            	as++; audioQ.poll();
            }
            System.out.println("Compare: " + as + " : " + vs);
            */
          }
        });

    Element.linkMany(videoColor2, vc.getElement());

    Thread videoThread =
        new Thread() {
          public void run() {
            clientPipe.setState(org.gstreamer.State.PLAYING);
          }
        };
    videoThread.start();
    clientPipe.debugToDotFile(0, "appsink");
  }