com.lemondronor.turboshrimp.pave

Code for reading and parsing video data in Parrot Video Encapsulated (PaVE) format, which is the format of the drone’s video stream.

Typically you will do something like the following to process drone video:

The following example code follows this pattern. It also puts the decoded images into an async channel, from which presumably another thread will get the images and display them on screen.

(let [queue (pave/make-frame-queue)
      input-stream (turboshrimp/video-input-stream my-drone)
      decoder (xuggler/decoder)
      ;; Create an async channel with a sliding buffer of size 1; If
      ;; our image rendering is slow this will drop frames, which is
      ;; good.
      image-channel (async/chan (async/sliding-buffer 1))]
  (doto (Thread.
         (fn []
           (loop [frame (pave/read-frame input-stream)]
             (when frame
               (pave/queue-frame queue frame))
             (recur (pave/read-frame input-stream)))))
    (.start))
  (doto (Thread.
         (fn []
           (loop [frame (pave/pull-frame queue 1000)]
             (when frame
               (let [^BufferedImage image (decoder frame)]
                 (a/go
                   (a/>! image-channel image))))
             (recur (pave/pull-frame queue 1000)))))
    (.start)))

dropped-frame-count

(dropped-frame-count queue)

Returns the number of video frames that have been dropped in order to reduce latency.

make-frame-queue

(make-frame-queue & {:keys [reduce-latency?], :or {reduce-latency? true}})

A frame queue that implements latency reduction by default.

This queue implements the recommended latency reduction technique for AR.Drone video, which is to drop any unprocessed P-frames whenever an I-frame is received.

To turn off latency reduction, you can call this with :reduce-latency? false.

pull-frame

(pull-frame queue & [timeout-ms])

Pulls a video frame from a frame queue.

Blocks until a frame is available. An optional timeout (in milliseconds) can be specified, in which case the call will return nil if a frame isn’t available in time.

queue-frame

(queue-frame queue frame)

Pushes a video frame into a frame queue.

read-frame

(read-frame is)

Reads a PaVE frame from an InputStream.

Skips over non-PaVE frames and returns the next PaVE frame. Returns nil if there are no more frames.