<commit_before>#lang racket/base

#|
   Copyright 2016-2017 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
|#

(provide (all-defined-out))
(require ffi/unsafe
         (except-in ffi/unsafe/define define-ffi-definer)
         ; Remove w/ Racket 6.10:
         ffi-definer-convention
         ; Uncomment w/ Racket 6.10:
         ; ffi/unsafe/define/conventions
         )

(define avcodec-lib (ffi-lib "libavcodec"))
(define-ffi-definer define-avcodec avcodec-lib
  #:make-c-id convention:hyphen->underscore)
(define avformat-lib (ffi-lib "libavformat"))
(define-ffi-definer define-avformat avformat-lib
  #:make-c-id convention:hyphen->underscore)
(define avutil-lib (ffi-lib "libavutil"))
(define-ffi-definer define-avutil avutil-lib
  #:make-c-id convention:hyphen->underscore)
(define swscale-lib (ffi-lib "libswscale"))
(define-ffi-definer define-swscale swscale-lib
  #:make-c-id convention:hyphen->underscore)

;; ===================================================================================================

(define (convert-err err)
  (bytes->string/locale (integer->integer-bytes (abs err) 4 #t)))

(define (MK-TAG [a #\space] [b #\space] [c #\space] [d #\space])
  (integer-bytes->integer (bytes (char->integer a)
                                 (char->integer b)
                                 (char->integer c)
                                 (char->integer d))
                          #t))

(define (FFERRTAG [a #\space] [b #\space] [c #\space] [d #\space])
  (- (MK-TAG a b c d)))

(define AVERROR-EOF (FFERRTAG #\E #\O #\F))
(define AV-NUM-DATA-POINTERS 8)
(define MAX-REORDER-DELAY 16)
(define EAGAIN 35)

(define SWS-BILINEAR 2)

;; ===================================================================================================

(struct exn:ffmpeg exn ())
(struct exn:ffmpeg:again exn:ffmpeg ())
(struct exn:ffmpeg:eof exn:ffmpeg ())

;; ===================================================================================================

(define _avcodec-id (_enum '(none
                             mpeg1video
                             mpeg2video
                             mpeg2video-xvmc ; Depricated and might be removed
                             h261
                             h263
                             rv10
                             rv20
                             mjpeg
                             mjpegb
                             ljpeg
                             sp5x
                             jpegls
                             mpeg4
                             rawvideo
                             msmpeg4v1
                             msmpeg4v2
                             msmpeg4v3
                             wmv1
                             wmv2
                             h263p
                             h263i
                             flv1
                             svq1
                             svq3
                             dvvideo
                             huffyuv
                             cyuv
                             h264
                             indeo3
                             ))) ;; XXX AND MORE! :)
(define _av-duration-estimation-method _fixint)
(define _avmedia-type (_enum '(unknown = -1
                               video
                               audio
                               data
                               subtitle
                               attachment
                               nb)))
(define _avcolor-primaries _fixint)
(define _avpixel-format (_enum '(unknown = -1
                                 yuv420p
                                 yuyv422
                                 rgb24
                                 bgr24
                                 yuv422p
                                 yuv444p
                                 yuv410p
                                 yuv411p
                                 gray8
                                 monowhite
                                 monoblack
                                 pal8
                                 yuvj420p
                                 ))) ;; XXX And more! :)
(define _avcolor-transfer-characteristic _fixint)
(define _avcolor-space _fixint)
(define _avcolor-range _fixint)
(define _avchroma-location _fixint)
(define _avfield-order _fixint)
(define _avsample-format _fixint)
(define _avaudio-service-type _fixint)
(define _avdiscard _fixint)
(define _avstream-parse-type _fixint)
(define _avpicture-type _fixint)

;; ===================================================================================================

(define-cstruct _byte-io-context
  ([buffer _bytes]
   [buffer-size _int]
   [buf-ptr _bytes]
   [buf-end _bytes]
   [opeque _pointer]
   [read-packet _fpointer]
   [write-packet _fpointer]
   [seek _fpointer]
   [pos _int64]
   [must-flush _int]
   [eof-reached _int]<commit_msg>Add a few more coding options.<commit_after>#lang racket/base

#|
   Copyright 2016-2017 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
|#

(provide (all-defined-out))
(require ffi/unsafe
         (except-in ffi/unsafe/define define-ffi-definer)
         ; Remove w/ Racket 6.10:
         ffi-definer-convention
         ; Uncomment w/ Racket 6.10:
         ; ffi/unsafe/define/conventions
         )

(define avcodec-lib (ffi-lib "libavcodec"))
(define-ffi-definer define-avcodec avcodec-lib
  #:make-c-id convention:hyphen->underscore)
(define avformat-lib (ffi-lib "libavformat"))
(define-ffi-definer define-avformat avformat-lib
  #:make-c-id convention:hyphen->underscore)
(define avutil-lib (ffi-lib "libavutil"))
(define-ffi-definer define-avutil avutil-lib
  #:make-c-id convention:hyphen->underscore)
(define swscale-lib (ffi-lib "libswscale"))
(define-ffi-definer define-swscale swscale-lib
  #:make-c-id convention:hyphen->underscore)

;; ===================================================================================================

(define (convert-err err)
  (bytes->string/locale (integer->integer-bytes (abs err) 4 #t)))

(define (MK-TAG [a #\space] [b #\space] [c #\space] [d #\space])
  (integer-bytes->integer (bytes (char->integer a)
                                 (char->integer b)
                                 (char->integer c)
                                 (char->integer d))
                          #t))

(define (FFERRTAG [a #\space] [b #\space] [c #\space] [d #\space])
  (- (MK-TAG a b c d)))

(define AVERROR-EOF (FFERRTAG #\E #\O #\F))
(define AV-NUM-DATA-POINTERS 8)
(define MAX-REORDER-DELAY 16)
(define EAGAIN 35)

(define SWS-BILINEAR 2)

;; ===================================================================================================

(struct exn:ffmpeg exn ())
(struct exn:ffmpeg:again exn:ffmpeg ())
(struct exn:ffmpeg:eof exn:ffmpeg ())

;; ===================================================================================================

(define _avcodec-id (_enum '(none
                             mpeg1video
                             mpeg2video
                             mpeg2video-xvmc ; Depricated and might be removed
                             h261
                             h263
                             rv10
                             rv20
                             mjpeg
                             mjpegb
                             ljpeg
                             sp5x
                             jpegls
                             mpeg4
                             rawvideo
                             msmpeg4v1
                             msmpeg4v2
                             msmpeg4v3
                             wmv1
                             wmv2
                             h263p
                             h263i
                             flv1
                             svq1
                             svq3
                             dvvideo
                             huffyuv
                             cyuv
                             h264
                             indeo3
                             ))) ;; XXX AND MORE! :)
(define _av-duration-estimation-method _fixint)
(define _avmedia-type (_enum '(unknown = -1
                               video
                               audio
                               data
                               subtitle
                               attachment
                               nb)))
(define _avcolor-primaries _fixint)
(define _avpixel-format (_enum '(unknown = -1
                                 yuv420p
                                 yuyv422
                                 rgb24
                                 bgr24
                                 yuv422p
                                 yuv444p
                                 yuv410p
                                 yuv411p
                                 gray8
                                 monowhite
                                 monoblack
                                 pal8
                                 yuvj420p
                                 yuvj422p
                                 yuvj444p
                                 ;xvmc-mpeg2-mc
                                 ;xvmc-mpeg2-idct
                                 uyvy422
                                 uyyvyy411
                                 bgr8
                                 bgr4
                                 bgr4-bytes
                                 rgb8
                                 rgb4
                                 rgb4-byte
                                 nv12
                                 nv21
                                 argb
                                 rgba
                                 abgr
                                 bgra
                                 gray16be
                                 gray16le
                                 yuv440p
                                 yuvj440p
                                 yuva420p
                                 vdpau-h264
                                 vdpau-mpeg1
                                 vdpau-mpeg2
                                 vdpau-wmv3
                                 wvdpau-vc1
                                 ))) ;; XXX And more! :)
(define _avcolor-transfer-characteristic _fixint)
(define _avcolor-space _fixint)
(define _avcolor-range _fixint)
(define _avchroma-location _fixint)
(define _avfield-order _fixint)
(define _avsample-format _fixint)
(define _avaudio-service-type _fixint)
(define _avdiscard _fixint)
(define _avstream-parse-type _fixint)
(define _avpicture-type _fixint)

;; ===================================================================================================

(define-cstruct _byte-io-context
  ([buffer _bytes]
   [buffer-size _int]
   [buf-ptr _bytes]
   [buf-end _bytes]
   [opeque _pointer]
   [read-packet _fpointer]
   [write-packet _fpointer]
   [seek _fpointer]
   [pos _int64]
   [must-flush _int]
   [eof-reached _int]
{'fraction_non_alphanumeric': 0.13533204924210704, 'fraction_numerical': 0.019093878234653715, 'mean_word_length': 1.1493880489560835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1648954', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2973, 'n_words': 714}