예제 #1
0
  @Override
  public void actionPerformed(ActionEvent e) {

    // if the current image nb is less than the length of the video
    if (frameNumber < VIDEO_LENGTH) {
      // update current imagenb
      frameNumber++;

      try {
        // get next frame to send from the video, as well as its size
        int imageLength = video.getnextframe(buffer);

        // Builds an RTPpacket object containing the frame
        RTPpacket rtpPacket =
            new RTPpacket(MJPEG_TYPE, frameNumber, frameNumber * FRAME_PERIOD, buffer, imageLength);

        // get to total length of the full rtp packet to send
        int packetLength = rtpPacket.getLength();

        // retrieve the packet bitstream and store it in an array of bytes
        byte[] packetBits = new byte[packetLength];
        rtpPacket.getPacket(packetBits);

        //				System.out.println("Send frame #" + imagenb);
        rtpTransport.send(packetBits, packetLength);

        // update GUI
        this.setChanged();
        this.notifyObservers(Update.FRAME);
      } catch (IOException ex) {
        RTSPServer.log("I/O exception sending RTSP packet: %s\n", ex.getMessage());
        return;
      }
    } else {
      // if we have reached the end of the video file, stop the timer
      timer.stop();
    }
  }
예제 #2
0
  private void doServerWait() {
    try {
      rtpTransport.setClientIp(rtspTransport.getClientIp());
      rtspTransport.open();
      setState(RTSP_STATES.INIT);
    } catch (IOException e) {
      RTSPServer.log("I/O exception opening RTSP socket\n");
      return;
    }

    // Wait for the SETUP message from the client
    RTSP_METHODS request;
    boolean done = false;
    while (!done) {
      request = rtspTransport.parseRequest(); // blocking
      if (request == RTSP_METHODS.SETUP) {
        done = true;
        setState(RTSP_STATES.READY);
        rtspTransport.sendResponse();
        try {
          video = new VideoStream(videoName);
          RTPTransport.open();
        } catch (SocketException e) {
          RTSPServer.log("socket exception creating RTP socket: %s\n", e.getMessage());
          return;
        } catch (FileNotFoundException e) {
          RTSPServer.log("video file not found: %s\n", e.getMessage());
          return;
        }
      }
    }

    // loop to handle RTSP requests
    while (true) {
      request = rtspTransport.parseRequest(); // blocking

      if ((request == RTSP_METHODS.PLAY) && (getState() == RTSP_STATES.READY)) {
        rtspTransport.sendResponse();
        timer.start();
        setState(RTSP_STATES.PLAYING);
      } else if ((request == RTSP_METHODS.PAUSE) && (getState() == RTSP_STATES.PLAYING)) {
        rtspTransport.sendResponse();
        timer.stop();
        setState(RTSP_STATES.READY);
      } else if (request == RTSP_METHODS.TEARDOWN) {
        rtspTransport.sendResponse();
        timer.stop();
        try {
          rtspTransport.close();
        } catch (IOException e) {
          RTSPServer.log("I/O exception closing RTSP socket: %s\n", e.getMessage());
        }
        RTPTransport.close();
        setState(RTSP_STATES.NONE);
        return;
      } else if (request == RTSP_METHODS.NONE) {
        timer.stop();
        try {
          rtspTransport.close();
        } catch (IOException e) {
          RTSPServer.log("I/O exception closing RTSP socket: %s\n", e.getMessage());
        }
        RTPTransport.close();
        setState(RTSP_STATES.NONE);
        RTSPServer.log("client disconnected\n");
        return;
      }
    }
  }
예제 #3
0
 public void setState(RTSP_STATES state) {
   this.state = state;
   RTSPServer.log("state %s (%d)\n", state, getSessionId());
   this.setChanged();
   this.notifyObservers(Update.STATE);
 }