// ------------------------ // Handler for timer // ------------------------ public void actionPerformed(ActionEvent e) { // if the current image nb is less than the length of the video if (imagenb < VIDEO_LENGTH) { // update current imagenb imagenb++; try { // get next frame to send from the video, as well as its size int image_length = video.getnextframe(buf); // Builds an RTPpacket object containing the frame RTPpacket rtp_packet = new RTPpacket(MJPEG_TYPE, imagenb, imagenb * FRAME_PERIOD, buf, image_length); // get to total length of the full rtp packet to send int packet_length = rtp_packet.getlength(); // retrieve the packet bitstream and store it in an array of bytes byte[] packet_bits = new byte[packet_length]; rtp_packet.getpacket(packet_bits); // send the packet as a DatagramPacket over the UDP socket senddp = new DatagramPacket(packet_bits, packet_length, ClientIPAddr, RTP_dest_port); RTPsocket.send(senddp); // System.out.println("Send frame #"+imagenb); // print the header bitstream rtp_packet.printheader(); // update GUI label.setText("Send frame #" + imagenb); } catch (Exception ex) { System.out.println("Exception caught: " + ex); System.exit(0); } } else { // if we have reached the end of the video file, stop the timer timer.stop(); } }