<commit_before>;;; Trentino video player, makes use of CL-VIDEO library
;;; 2017 <NAME> <<EMAIL>>
;;;; This code is licensed under the MIT license.

(defpackage mezzano.gui.trentino
  (:use #:cl)
  (:export #:spawn))

(in-package #:mezzano.gui.trentino)

(defclass media-player ()
  ((%fifo :initarg :fifo :reader fifo)
   (%window :initarg :window :reader window)
   (%thread :initarg :thread :reader thread)
   (%font :initarg :font :reader font)
   (%frame :initarg :frame :reader frame)))

(defgeneric dispatch-event (viewer event))

(defmethod dispatch-event (window (event null)))

(defmethod dispatch-event (window (event mezzano.gui.compositor:window-activation-event))
  (setf (mezzano.gui.widgets:activep (frame window)) (mezzano.gui.compositor:state event))
  (mezzano.gui.widgets:draw-frame (frame window)))

(defmethod dispatch-event (window (event mezzano.gui.compositor:mouse-event))
  (mezzano.gui.widgets:frame-mouse-event (frame window) event))

(defmethod dispatch-event (window (event mezzano.gui.compositor:window-close-event))
  (declare (ignore window event))
  (throw 'mezzano.supervisor::terminate-thread nil))

(define-condition pause-event () ())

(defmethod dispatch-event (window (event mezzano.gui.compositor:key-event))
  (when (not (mezzano.gui.compositor:key-releasep event))
    (let* ((ch (mezzano.gui.compositor:key-key event)))
      (cond ((char= ch #\Space)
             (signal 'pause-event))))))

(defclass mezzano-pcm-output (cl-video:audio-output)
  ((astream :accessor astream)))

(defmethod cl-video:sink-frame-element-type ((aout mezzano-pcm-output))
  'float)

(defmethod cl-video:initialize-sink ((aout mezzano-pcm-output))
  (setf (astream aout) (mezzano.driver.sound:make-sound-output-sink
			:buffer-size-in-samples 
			:format (ecase (cl-video:significant-bits-per-sample (cl-video:audio-rec aout))
				  (8 :pcm-u8)
				  (16 :pcm-s16le)))))

(defmethod cl-video:sink-frame ((aout mezzano-pcm-output) frame)
  (mezzano.driver.sound:output-sound frame (astream aout) :end (length frame)))

(defmethod cl-video:close-sink ((aout mezzano-pcm-output))
  )

(defmethod cl-video:translate-source-frame ((aout mezzano-pcm-output) frame)
  (with-slots (audio-rec) aout
    (loop for i from 0 below (length frame)
	 do (setf (aref frame i) (aref (cl-video:buffer audio-rec))))))

;;; we speccialize own class & method to resample stream as necessary for Intel HDA
;;; but we still want to run decode in another thread

(defmethod play-audio-stream ((container cl-video:av-container))
  (let* ((aout (cl-video:audio-out container))
	 (audio-rec (cl-video:audio-rec aout)))
    (when audio-rec
      (mezzano.supervisor:make-thread
       #'(lambda ()
	   (cl-video:stream-playback-start audio-rec)
	   (unwind-protect
		(unless (not (and (eql (cl-video:compression-code audio-rec) 1) ; uncompressed
				  (eql (cl-video:sample-rate audio-rec) 44100)
				  (member (cl-video:significant-bits-per-sample audio-rec) '(8 16))))
		  (loop until (cl-video:finish container)
		     for cur = (if (cl-video:pause container) cur (cl-video:pop-chunk-rcursor audio-rec))<commit_msg>symbol designators<commit_after>;;; Trentino video player, makes use of CL-VIDEO library
;;; 2017 <NAME> <<EMAIL>>
;;;; This code is licensed under the MIT license.

(defpackage mezzano.gui.trentino
  (:use #:cl)
  (:export #:spawn))

(in-package #:mezzano.gui.trentino)

(defclass media-player ()
  ((%fifo :initarg :fifo :reader fifo)
   (%window :initarg :window :reader window)
   (%thread :initarg :thread :reader thread)
   (%font :initarg :font :reader font)
   (%frame :initarg :frame :reader frame)))

(defgeneric dispatch-event (viewer event))

(defmethod dispatch-event (window (event null)))

(defmethod dispatch-event (window (event mezzano.gui.compositor:window-activation-event))
  (setf (mezzano.gui.widgets:activep (frame window)) (mezzano.gui.compositor:state event))
  (mezzano.gui.widgets:draw-frame (frame window)))

(defmethod dispatch-event (window (event mezzano.gui.compositor:mouse-event))
  (mezzano.gui.widgets:frame-mouse-event (frame window) event))

(defmethod dispatch-event (window (event mezzano.gui.compositor:window-close-event))
  (declare (ignore window event))
  (throw 'mezzano.supervisor::terminate-thread nil))

(define-condition pause-event () ())

(defmethod dispatch-event (window (event mezzano.gui.compositor:key-event))
  (when (not (mezzano.gui.compositor:key-releasep event))
    (let* ((ch (mezzano.gui.compositor:key-key event)))
      (cond ((char= ch #\Space)
             (signal 'pause-event))))))

(defclass mezzano-pcm-output (cl-video:audio-output)
  ((astream :accessor astream)))

(defmethod cl-video:sink-frame-element-type ((aout mezzano-pcm-output))
  'float)

(defmethod cl-video:initialize-sink ((aout mezzano-pcm-output))
  (setf (astream aout) (mezzano.driver.sound:make-sound-output-sink
			:buffer-size-in-samples 
			:format (ecase (cl-video:significant-bits-per-sample (cl-video:audio-rec aout))
				  (8 :pcm-u8)
				  (16 :pcm-s16le)))))

(defmethod cl-video:sink-frame ((aout mezzano-pcm-output) frame)
  (mezzano.driver.sound:output-sound frame (astream aout) :end (length frame)))

(defmethod cl-video:close-sink ((aout mezzano-pcm-output))
  )

(defmethod cl-video:translate-source-frame ((aout mezzano-pcm-output) frame)
  (with-slots (cl-video:audio-rec) aout
    (loop for i from 0 below (length frame)
	 do (setf (aref frame i) (aref (cl-video:buffer cl-video:audio-rec))))))

;;; we speccialize own class & method to resample stream as necessary for Intel HDA
;;; but we still want to run decode in another thread

(defmethod play-audio-stream ((container cl-video:av-container))
  (let* ((aout (cl-video:audio-out container))
	 (audio-rec (cl-video:audio-rec aout)))
    (when audio-rec
      (mezzano.supervisor:make-thread
       #'(lambda ()
	   (cl-video:stream-playback-start audio-rec)
	   (unwind-protect
		(unless (not (and (eql (cl-video:compression-code audio-rec) 1) ; uncompressed
				  (eql (cl-video:sample-rate audio-rec) 44100)
				  (member (cl-video:significant-bits-per-sample audio-rec) '(8 16))))
		  (loop until (cl-video:finish container)
		     for cur = (if (cl-video:pause container) cur (cl-video:pop-chunk-rcursor audio-rec))
{'fraction_non_alphanumeric': 0.15357542793153095, 'fraction_numerical': 0.00639897616381379, 'mean_word_length': 4.493848857644991, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2709938', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2178, 'n_words': 518}