Преглед на файлове

whitespace cleanup; added (stream-seek in) shorthand

Mark VandenBrink преди 12 години
родител
ревизия
cfdc9c6f55
променени са 5 файла, в които са добавени 29 реда и са изтрити 28 реда
  1. 7 6
      audio-streams.lisp
  2. 8 8
      id3-frame.lisp
  3. 8 8
      mp4-atom.lisp
  4. 5 5
      mpeg.lisp
  5. 1 1
      packages.lisp

+ 7 - 6
audio-streams.lisp

@@ -65,9 +65,10 @@
   "Returns the length of the underlying stream"
   (ccl::stream-length (stream in-stream)))
 
-
-(defmethod stream-seek ((in-stream base-stream) offset from)
-  "C-like stream positioner.  Takes an offset and a location (one of :start, :end, :current)."
+(defmethod stream-seek ((in-stream base-stream) &optional (offset 0) (from :current))
+  "C-like stream positioner.  Takes an offset and a location (one of :start, :end, :current).
+If offset is not passed, then assume 0.  If from is not passed, assume from current location.
+Thus (stream-seek in) == (stream-seek in 0 :current)"
   (with-slots (stream) in-stream
     (ecase from
       (:start (ccl::stream-position stream offset))
@@ -76,9 +77,9 @@
                     (ccl::stream-position stream (+ (ccl::stream-position stream) offset))))
       (:end (ccl::stream-position stream (- (ccl::stream-length stream) offset))))))
 
-(defmethod stream-pos ((in-stream base-stream))
-  "Short hand for getting current stream read position"
-  (stream-seek in-stream 0 :current))
+;; (defmethod stream-seek ((in-stream base-stream))
+;;   "Short hand for getting current stream read position"
+;;   (stream-seek in-stream 0 :current))
 
 (defun stream-read-octets (instream bytes &key (bits-per-byte 8))
   "Used to slurp in octets for the stream-read-* methods"

+ 8 - 8
id3-frame.lisp

@@ -157,7 +157,7 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
     (with-slots (version revision flags size ext-header frames v21-tag-header) me
       (stream-seek instream 128 :end)
       (when (string= "TAG" (stream-read-string-with-len instream 3))
-        (log-id3-frame "looking at last 128 bytes at ~:d to try to read id3v21 header" (stream-seek instream 0 :current))
+        (log-id3-frame "looking at last 128 bytes at ~:d to try to read id3v21 header" (stream-seek instream))
         (handler-case
             (setf v21-tag-header (make-instance 'v21-tag-header :instream instream))
           (id3-frame-condition (c)
@@ -196,10 +196,10 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
 ;;; the bytes an raw octets.
 (defun get-name-value-pair (instream len name-encoding value-encoding)
   (log5:with-context  "get-name-value-pair"
-    (log-id3-frame "reading from ~:d, len ~:d, name-encoding = ~d, value-encoding = ~d" (stream-seek instream 0 :current) len name-encoding value-encoding)
-    (let* ((old-pos (stream-seek instream 0 :current))
+    (log-id3-frame "reading from ~:d, len ~:d, name-encoding = ~d, value-encoding = ~d" (stream-seek instream) len name-encoding value-encoding)
+    (let* ((old-pos (stream-seek instream))
            (name (stream-read-string instream :encoding name-encoding))
-           (name-len (- (stream-seek instream 0 :current) old-pos))
+           (name-len (- (stream-seek instream) old-pos))
            (value))
 
       (log-id3-frame "name = <~a>, name-len = ~d" name name-len)
@@ -845,7 +845,7 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
 (defun make-frame (version instream)
   "Create an appropriate mp3 frame by reading data from INSTREAM."
   (log5:with-context "make-frame"
-    (let* ((pos (stream-seek instream 0 :current))
+    (let* ((pos (stream-seek instream))
            (byte (stream-read-u8 instream))
            frame-name frame-len frame-flags frame-class)
 
@@ -875,7 +875,7 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
 
       ;; edge case where found a frame name, but it is not valid or where making this frame
       ;; would blow past the end of the file/buffer
-      (when (or (> (+ (stream-seek instream 0 :current) frame-len) (stream-size instream))
+      (when (or (> (+ (stream-seek instream) frame-len) (stream-size instream))
                 (null frame-class))
         (error 'id3-frame-condition :message "bad frame found" :object frame-name :location pos))
 
@@ -889,7 +889,7 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
                (log-id3-frame "Starting loop through ~:d bytes" (stream-size stream))
                (let (frames this-frame)
                  (do ()
-                     ((>= (stream-seek stream 0 :current) (stream-size stream)))
+                     ((>= (stream-seek stream) (stream-size stream)))
                    (handler-case
                        (progn
                          (setf this-frame (make-frame version stream))
@@ -897,7 +897,7 @@ Note: extended headers are subject to unsynchronization, so make sure that INSTR
                            (log-id3-frame "hit padding: returning ~d frames" (length frames))
                            (return-from read-loop (values t (nreverse frames))))
 
-                         (log-id3-frame "bottom of read-loop: pos = ~:d, size = ~:d" (stream-seek stream 0 :current) (stream-size stream))
+                         (log-id3-frame "bottom of read-loop: pos = ~:d, size = ~:d" (stream-seek stream) (stream-size stream))
                          (push this-frame frames))
                      (condition (c)
                        (log-id3-frame "got condition ~a when making frame" c)

+ 8 - 8
mp4-atom.lisp

@@ -106,10 +106,10 @@
 at top-level and also for container ATOMs that need to read their contents."
   (log5:with-context "atom-read-loop"
     (do ()
-        ((>= (stream-seek mp4-file 0 :current) end))
-      (log-mp4-atom "atom-read-loop: @~:d before dispatch" (stream-seek mp4-file 0 :current))
+        ((>= (stream-seek mp4-file) end))
+      (log-mp4-atom "atom-read-loop: @~:d before dispatch" (stream-seek mp4-file))
       (funcall func)
-      (log-mp4-atom "atom-read-loop: @~:d after dispatch" (stream-seek mp4-file 0 :current)))))
+      (log-mp4-atom "atom-read-loop: @~:d after dispatch" (stream-seek mp4-file)))))
 
 (defclass mp4-atom ()
   ((atom-file-position :accessor atom-file-position :initarg :atom-file-position)
@@ -152,8 +152,8 @@ Loop through this container and construct constituent atoms"
   (log5:with-context "atom-ilst-initializer"
     (with-slots (atom-size atom-type atom-children) me
       (log-mp4-atom "atom-ilst-init: found ilst atom <~a> @ ~:d, looping for ~:d bytes"
-                    (as-string atom-type) (stream-seek mp4-file 0 :current) (- atom-size 8))
-      (atom-read-loop mp4-file (+ (stream-seek mp4-file 0 :current)  (- atom-size 8))
+                    (as-string atom-type) (stream-seek mp4-file) (- atom-size 8))
+      (atom-read-loop mp4-file (+ (stream-seek mp4-file)  (- atom-size 8))
                       (lambda ()
                         (let ((child (make-mp4-atom mp4-file atom-type)))
                           ;(log-mp4-atom "adding new child ~a" (vpprint child nil))
@@ -362,7 +362,7 @@ Loop through this container and construct constituent atoms"
     (setf flags    (stream-read-u24 mp4-file))
     (assert (= 3 (stream-read-u8 mp4-file)) () "Expected a description tag of 3")
     (let* ((len1 (read-descriptor-len mp4-file))
-           (end-of-atom (+ (stream-seek mp4-file 0 :current) len1)))
+           (end-of-atom (+ (stream-seek mp4-file) len1)))
       (setf esid (stream-read-u16 mp4-file))
       (setf s-priority (stream-read-u8 mp4-file))
       ;; XXX should do some range checking here against LEN1...
@@ -457,7 +457,7 @@ Loop through this container and construct constituent atoms"
 (defun make-mp4-atom (mp4-file &optional parent-type)
   "Get current file position, read in size/type, then construct the correct atom."
   (log5:with-context "make-mp4-atom"
-    (let* ((pos (stream-seek mp4-file 0 :current))
+    (let* ((pos (stream-seek mp4-file))
            (siz (stream-read-u32 mp4-file))
            (typ (stream-read-u32 mp4-file))
            (atom))
@@ -500,7 +500,7 @@ Loop through this container and construct constituent atoms"
       (error 'mp4-atom-condition :location "find-mp4-atoms" :object mp4-file :message "is not an mp4-file" ))
 
     (log-mp4-atom "find-mp4-atoms: ~a, before read-file loop, file-position = ~:d, end = ~:d"
-                  (stream-filename mp4-file) (stream-seek mp4-file 0 :current) (stream-size mp4-file))
+                  (stream-filename mp4-file) (stream-seek mp4-file) (stream-size mp4-file))
 
     (let ((atoms))
       (atom-read-loop mp4-file (stream-size mp4-file)

+ 5 - 5
mpeg.lisp

@@ -174,7 +174,7 @@
   (log5:with-context "load-frame"
     (with-frame-slots (me)
       (when (null b-array)              ; has header already been read in?
-        (setf pos (stream-seek instream 0 :current))
+        (setf pos (stream-seek instream))
         (setf b-array (stream-read-sequence instream 4)))
 
       (if (parse-header me)
@@ -320,7 +320,7 @@
 (defun find-first-sync (in)
   (log5:with-context "find-first-sync"
 
-    (log-mpeg-frame "Looking for first sync, begining at file position ~:d" (stream-seek in 0 :current))
+    (log-mpeg-frame "Looking for first sync, begining at file position ~:d" (stream-seek in))
     (let ((b-array (make-octets 4))
           (pos))
 
@@ -331,7 +331,7 @@
           ;; parse fails (i.e. a false sync), do we skip forward, or try to parse
           ;; the second byte as the FF?
           (loop
-             (setf pos (stream-seek in 0 :current))
+             (setf pos (stream-seek in))
              (setf (aref b-array 0) (stream-read-u8 in))
              (when (= (aref b-array 0) #xff)
                (setf (aref b-array 1) (stream-read-u8 in))
@@ -358,7 +358,7 @@
     (let ((nxt-frame (make-instance 'frame)))
       (when (not (payload me))
         (log-mpeg-frame "no payload in current frame, skipping from ~:d forward ~:d bytes"
-                        (stream-seek instream 0 :current)
+                        (stream-seek instream)
                         (- (size me) 4) :current)
         (stream-seek instream (- (size me) 4) :current))
 
@@ -433,7 +433,7 @@
 (defun get-mpeg-audio-info (in &key (max-frames nil))
   "Get MPEG Layer 3 audio information."
   (log5:with-context "get-mpeg-audio-info"
-    (let ((pos (stream-seek in 0 :current))
+    (let ((pos (stream-seek in))
           (first-frame (find-first-sync in))
           (info (make-instance 'mpeg-audio-info)))
 

+ 1 - 1
packages.lisp

@@ -15,7 +15,7 @@
            #:mp3-file-stream #:mp4-file-stream #:base-mem-stream
            #:id3-header #:audio-info #:mp4-atoms
            #:parse-mp3-file #:parse-mp4-file
-           #:make-mem-stream #:stream-filename
+           #:make-mem-stream #:make-file-stream #:stream-filename #:stream-pos
            #:stream-read-u8 #:stream-read-u16 #:stream-read-u24 #:stream-read-u32 #:stream-read-u64 #:stream-read-octets
            #:stream-decode-iso-string #:stream-deocode-ucs-string #:stream-decode-ucs-be-string
            #:stream-decode-utf-8-string #:stream-decode-string #:stream-read-iso-string-with-len