     (reset! stream true)
     (Thread/sleep 40)
     ;wait for the first frame
-    (send video-agent stream-video host (when @save-video
-                                          (FileOutputStream. "vid.h264")))))
+    (send video-agent stream-video host nil)))
+
+
+

(ns sormilla.video
  (:import [com.twilight.h264.decoder AVFrame AVPacket H264Decoder MpegEncContext]
           [com.twilight.h264.player FrameUtils]
           [java.util Arrays]
           [java.awt.image BufferedImage]))

(def INBUF_SIZE 65535)
(def inbuf-int (int-array (+ INBUF_SIZE MpegEncContext/FF_INPUT_BUFFER_PADDING_SIZE)))
(def avpkt (AVPacket.))
(.av_init_packet avpkt)

(def codec (H264Decoder.))
(if (nil? codec) (println "Codec not found"))
(def c (MpegEncContext/avcodec_alloc_context))
(def picture (AVFrame/avcodec_alloc_frame))

(if-not (zero? (bit-and (.capabilities codec) H264Decoder/CODEC_CAP_TRUNCATED))
  (println "need to configure CODEC_FLAG_TRUNCATED"))

(if (< (.avcodec_open c codec) 0)
  (println "Could not open codec"))

(defn to-ba-int [b]
  (doall (for [i (range 0 (count b))]

    (let [vs (Socket. host 5555)]
      (.setSoTimeout vs 5000)
      ;wakes up the socket so that it will continue to stream data
      (doto (.getOutputStream vs)
        (.write (byte-array (map bin/ubyte [1 0 0 0])))
        (.flush))
      (reset! vsocket vs))))

(doto System/err
  (.write (byte-array (map bin/ubyte [65 66 67 10])))
  (.flush))
(.write (DataOutputStream. System/err) (byte-array (map byte [1 0 0 0])))
(.flush System/err)
(defn read-from-input [size]
  (let [bv (byte-array size)]
    (.read (.getInputStream @vsocket) bv)
