Giter VIP home page Giter VIP logo

nim-nestegg's Introduction

nim-nestegg

WebM is a web standard audio/video file format supported by most browsers. It is a simplified subset of the Matroska file format and may only contain the VP8, VP9 or AV1 video codecs or the OGG or OPUS audio codecs.

This is a Nim wrapper for the nestegg C library, which was designed for portability and efficiency. The wrapper is based on nimterop and links statically. The design is thin but featureful- the C API is exposed as is to preserve flexibility but with Nim language constructs and memory safety.

Example

Example of regular use with one or more decoders

import nestegg

let file = open("myvideo.webm")
let demuxer = Demuxer(file)

for track in d.tracks:
  echo $track.kind, " track with ", $track.codec, " codec"

  # initialize decoder for each track here

for packet in demuxer:

  if packet.track.num == 0:
    echo $d.kind, " track with ", $d.codec, " codec"

    for chunk in packet:
      
      # send data chunk to decoder

      # if the decoder is also a C wrapper, an array
      # and a length are usually supplied
      # this is not memory safe
      
      myDecoder.sendData(chunk.data, chunk.length)

      # chunk.data is a ptr UncheckedArray[byte] and may need 
      # to be cast to whatever the decoder expects
      # myDecoder.sendData(cast[pointer](chunk.data), chunk.length)

file.close()

nestegg's internal debug logs can be output by compiling with -d:nestegg_debug.

See http://github.com/capocasa/lov, a minimalistic nim av1-opus-webm video player, for a fuller usage example, as well as project status.

Documentation

nim-nestegg module documentation, including the low level wrapper, is available

Advisory

nim-nestegg is memory-safe when using the high-level interface as documented.

Directly using C-allocated memory, modifying object structure or directly interfacing with the library are possible but not memory safe.

Internals

Memory safety

There are two blobs of memory allocated in C by the nestegg library, accessible by untraced references Demuxer.context and Packet.raw.

When Demuxer or Packet go out of scope, they have a finalizer that frees up that C-memory.

Track objects may contain references to Demuxer.context memory. Demuxer objects contain a traced reference to each of their Track, preventing preventing the Demuxer.context memory from going out of scope as long as it can be accessed via a Track.

Chunk objects may contain references to Packet.raw memory. Packet objects contain a traced references to ecah of their Chunk objects, preventing the Packet.raw memory from going out of scope as long as it can be accessed via a Chunk.

As always when using finalizers, garbage collection becomes heavier than usual.

nestegg

Nestegg itself is a high performance, highly portable C library for demuxing webm streams and should be usable just about everywhere nim is, as long as a C target is used (so emscripten yes, js no), and has seen a lot of production use with Mozilla and others.

Nestegg is not particularly helpful debugging corrupt webm files- it will tell you a file is broken, but not why. This can be circumnvented by inserting debug statements into the failing nestegg function's C code, but for most purposes other tools should be used to validate webm files so nestegg will play them.

nim-nestegg's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

beshrkayali

nim-nestegg's Issues

example code fails

 ~/r/e/nimapple   main ±nim c -r test.nim
Hint: used config file '/home/scarf/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/scarf/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
.................................................................................................................................................
# Resetting /home/scarf/.cache/nim/nimterop/nestegg
# Including library /home/scarf/.cache/nim/nimterop/nestegg/src/.libs/libnestegg.a

# Overriding CODEC_UNKNOWN TRACK_UNKNOWN
# Importing /home/scarf/.cache/nim/nimterop/nestegg/include/nestegg/nestegg.h
# Generated @ 2022-11-19T18:32:27+09:00
# Command line:
#   /home/scarf/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --preprocess -m:c --passL+=/home/scarf/.cache/nim/nimterop/nestegg/src/.libs/libnestegg.a --pnim --symOverride=CODEC_UNKNOWN,TRACK_UNKNOWN --nim:/home/scarf/.choosenim/toolchains/nim-#devel/bin/nim --pluginSourcePath=/home/scarf/.cache/nim/nimterop/cPlugins/nimterop_388908912.nim /home/scarf/.cache/nim/nimterop/nestegg/include/nestegg/nestegg.h -o /home/scarf/.cache/nim/nimterop/toastCache/nimterop_1553636112.nim

# const 'NESTEGG_TRACK_UNKNOWN' has unsupported value 'INT_MAX /**< Track is of type unknown. */'
# const 'NESTEGG_CODEC_UNKNOWN' has unsupported value 'INT_MAX /**< Track uses unknown codec. */'
{.push hint[ConvFromXtoItselfNotNeeded]: off.}


{.pragma: impnesteggHdr,
  header: "/home/scarf/.cache/nim/nimterop/nestegg/include/nestegg/nestegg.h".}
{.experimental: "codeReordering".}
{.passL: "/home/scarf/.cache/nim/nimterop/nestegg/src/.libs/libnestegg.a".}
const
  CODEC_UNKNOWN* = high(cint)
  TRACK_UNKNOWN* = high(cint)
  TRACK_VIDEO* = 0
  TRACK_AUDIO* = 1
  CODEC_VP8* = 0
  CODEC_VORBIS* = 1
  CODEC_VP9* = 2
  CODEC_OPUS* = 3
  CODEC_AV1* = 4
  VIDEO_MONO* = 0
  VIDEO_STEREO_LEFT_RIGHT* = 1
  VIDEO_STEREO_BOTTOM_TOP* = 2
  VIDEO_STEREO_TOP_BOTTOM* = 3
  VIDEO_STEREO_RIGHT_LEFT* = 11
  SEEK_SET* = 0
  SEEK_CUR* = 1
  SEEK_END* = 2
  LOG_DEBUG* = 1
  LOG_INFO* = 10
  LOG_WARNING* = 100
  LOG_ERROR* = 1000
  LOG_CRITICAL* = 10000
  ENCODING_COMPRESSION* = 0
  ENCODING_ENCRYPTION* = 1
  PACKET_HAS_SIGNAL_BYTE_FALSE* = 0
  PACKET_HAS_SIGNAL_BYTE_UNENCRYPTED* = 1
  PACKET_HAS_SIGNAL_BYTE_ENCRYPTED* = 2
  PACKET_HAS_SIGNAL_BYTE_PARTITIONED* = 4
  PACKET_HAS_KEYFRAME_FALSE* = 0
  PACKET_HAS_KEYFRAME_TRUE* = 1
  PACKET_HAS_KEYFRAME_UNKNOWN* = 2
type
  nestegg* {.importc, impnesteggHdr, incompleteStruct.} = object
  cpacket* {.impnesteggHdr, importc: "nestegg_packet", incompleteStruct.} = object
  io* {.bycopy, impnesteggHdr, importc: "nestegg_io".} = object ## 
                                                                 ##   < Opaque handle referencing a packet of data. 
                                                                 ##      User supplied IO context.
                                                                 ## 
    read*: proc (buffer: pointer; length: uint; userdata: pointer): cint {.cdecl.} ## 
                                                                                   ##   User supplied read callback.
                                                                                   ##         @param buffer   Buffer to read data into.
                                                                                   ##         @param length   Length of supplied buffer in bytes.
                                                                                   ##         @param userdata The #userdata supplied by the user.
                                                                                   ##         @retval  1 Read succeeded.
                                                                                   ##         @retval  0 End of stream.
                                                                                   ##         @retval -1 Error.
                                                                                   ## 
    seek*: proc (offset: int64; whence: cint; userdata: pointer): cint {.cdecl.} ## 
                                                                                 ##   User supplied seek callback.
                                                                                 ##         @param offset   Offset within the stream to seek to.
                                                                                 ##         @param whence   Seek direction.  One of #NESTEGG_SEEK_SET,
                                                                                 ##                         #NESTEGG_SEEK_CUR, or #NESTEGG_SEEK_END.
                                                                                 ##         @param userdata The #userdata supplied by the user.
                                                                                 ##         @retval  0 Seek succeeded.
                                                                                 ##         @retval -1 Error.
                                                                                 ## 
    tell*: proc (userdata: pointer): int64 {.cdecl.} ## 
                                                     ##   User supplied tell callback.
                                                     ##         @param userdata The #userdata supplied by the user.
                                                     ##         @returns Current position within the stream.
                                                     ##         @retval -1 Error.
                                                     ## 
    userdata*: pointer ## 
                       ##   User supplied pointer to be passed to the IO callbacks.
                       ## 
  
  video_params* {.bycopy, impnesteggHdr, importc: "nestegg_video_params".} = object ## 
                                                                                     ##   Parameters specific to a video track.
                                                                                     ## 
    stereo_mode*: cuint ## 
                        ##   < Video mode.  One of #NESTEGG_VIDEO_MONO,
                        ##                                       #NESTEGG_VIDEO_STEREO_LEFT_RIGHT,
                        ##                                       #NESTEGG_VIDEO_STEREO_BOTTOM_TOP, or
                        ##                                       #NESTEGG_VIDEO_STEREO_TOP_BOTTOM.
                        ## 
    width*: cuint            ## 
                             ##   < Width of the video frame in pixels.
                             ## 
    height*: cuint           ## 
                             ##   < Height of the video frame in pixels.
                             ## 
    display_width*: cuint    ## 
                             ##   < Display width of the video frame in pixels.
                             ## 
    display_height*: cuint   ## 
                             ##   < Display height of the video frame in pixels.
                             ## 
    crop_bottom*: cuint      ## 
                             ##   < Pixels to crop from the bottom of the frame.
                             ## 
    crop_top*: cuint         ## 
                             ##   < Pixels to crop from the top of the frame.
                             ## 
    crop_left*: cuint        ## 
                             ##   < Pixels to crop from the left of the frame.
                             ## 
    crop_right*: cuint       ## 
                             ##   < Pixels to crop from the right of the frame.
                             ## 
    alpha_mode*: cuint ## 
                       ##   < 1 if an additional opacity stream is available, otherwise 0.
                       ## 
    matrix_coefficients*: cuint ## 
                                ##   < See Table 4 of ISO/IEC 23001-8:2016.
                                ## 
    range*: cuint            ## 
                             ##   < Clipping of color ranges.
                             ## 
    transfer_characteristics*: cuint ## 
                                     ##   < See Table 3 of ISO/IEC 23091-4.
                                     ## 
    primaries*: cuint        ## 
                             ##   < See Table 2 of ISO/IEC 23091-4.
                             ## 
    primary_r_chromacity_x*: cdouble ## 
                                     ##   < Red X chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    primary_r_chromacity_y*: cdouble ## 
                                     ##   < Red Y chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    primary_g_chromacity_x*: cdouble ## 
                                     ##   < Green X chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    primary_g_chromacity_y*: cdouble ## 
                                     ##   < Green Y chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    primary_b_chromacity_x*: cdouble ## 
                                     ##   < Blue X chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    primary_b_chromacity_y*: cdouble ## 
                                     ##   < Blue Y chromaticity coordinate per CIE 1931.
                                     ##                                                 NaN means element not present.
                                     ## 
    white_point_chromaticity_x*: cdouble ## 
                                         ##   < White X chromaticity coordinate per CIE 1931.
                                         ##                                                 NaN means element not present.
                                         ## 
    white_point_chromaticity_y*: cdouble ## 
                                         ##   < White Y chromaticity coordinate per CIE 1931.
                                         ##                                                 NaN means element not present.
                                         ## 
    luminance_max*: cdouble ## 
                            ##   < Maximum luminance in cd/m2.
                            ##                                                 NaN means element not present.
                            ## 
    luminance_min*: cdouble ## 
                            ##   < Minimum luminance in cd/m2.
                            ##                                                 NaN means element not present.
                            ## 
  
  audio_params* {.bycopy, impnesteggHdr, importc: "nestegg_audio_params".} = object ## 
                                                                                     ##   Parameters specific to an audio track.
                                                                                     ## 
    rate*: cdouble           ## 
                             ##   < Sampling rate in Hz.
                             ## 
    channels*: cuint         ## 
                             ##   < Number of audio channels.
                             ## 
    depth*: cuint            ## 
                             ##   < Bits per sample.
                             ## 
    codec_delay*: uint64 ## 
                         ##   < Nanoseconds that must be discarded from the start.
                         ## 
    seek_preroll*: uint64 ## 
                          ##   < Nanoseconds that must be discarded after a seek.
                          ## 
  
  log* {.impnesteggHdr, importc: "nestegg_log".} = proc (context: ptr nestegg;
      severity: cuint; format: cstring) {.cdecl, varargs.}
proc init*(context: ptr ptr nestegg; io: io; callback: log; max_offset: int64): cint {.
    importc: "nestegg_init", cdecl, impnesteggHdr.}
  ## 
                                                   ##   Initialize a nestegg context.  During initialization the parser will
                                                   ##       read forward in the stream processing all elements until the first
                                                   ##       block of media is reached.  All track metadata has been processed at this point.
                                                   ##       @param context  Storage for the new nestegg context.  @see nestegg_destroy
                                                   ##       @param io       User supplied IO context.
                                                   ##       @param callback Optional logging callback function pointer.  May be NULL.
                                                   ##       @param max_offset Optional maximum offset to be read. Set -1 to ignore.
                                                   ##       @retval  0 Success.
                                                   ##       @retval -1 Error.
                                                   ## 
proc destroy*(context: ptr nestegg) {.importc: "nestegg_destroy", cdecl,
                                      impnesteggHdr.}
  ## 
                                                     ##   Destroy a nestegg context and free associated memory.
                                                     ##       @param context #nestegg context to be freed.  @see nestegg_init
                                                     ## 
proc duration*(context: ptr nestegg; duration: ptr uint64): cint {.
    importc: "nestegg_duration", cdecl, impnesteggHdr.}
  ## 
                                                       ##   Query the duration of the media stream in nanoseconds.
                                                       ##       @param context  Stream context initialized by #nestegg_init.
                                                       ##       @param duration Storage for the queried duration.
                                                       ##       @retval  0 Success.
                                                       ##       @retval -1 Error.
                                                       ## 
proc tstamp_scale*(context: ptr nestegg; scale: ptr uint64): cint {.
    importc: "nestegg_tstamp_scale", cdecl, impnesteggHdr.}
  ## 
                                                           ##   Query the tstamp scale of the media stream in nanoseconds.
                                                           ##       @note Timestamps presented by nestegg have been scaled by this value
                                                           ##             before presentation to the caller.
                                                           ##       @param context Stream context initialized by #nestegg_init.
                                                           ##       @param scale   Storage for the queried scale factor.
                                                           ##       @retval  0 Success.
                                                           ##       @retval -1 Error.
                                                           ## 
proc track_count*(context: ptr nestegg; tracks: ptr cuint): cint {.
    importc: "nestegg_track_count", cdecl, impnesteggHdr.}
  ## 
                                                          ##   Query the number of tracks in the media stream.
                                                          ##       @param context Stream context initialized by #nestegg_init.
                                                          ##       @param tracks  Storage for the queried track count.
                                                          ##       @retval  0 Success.
                                                          ##       @retval -1 Error.
                                                          ## 
proc get_cue_point*(context: ptr nestegg; cluster_num: cuint; max_offset: int64;
                    start_pos: ptr int64; end_pos: ptr int64; tstamp: ptr uint64): cint {.
    importc: "nestegg_get_cue_point", cdecl, impnesteggHdr.}
  ## 
                                                            ##   Query the start and end offset for a particular cluster.
                                                            ##       @param context     Stream context initialized by #nestegg_init.
                                                            ##       @param cluster_num Zero-based cluster number; order they appear in cues.
                                                            ##       @param max_offset  Optional maximum offset to be read. Set -1 to ignore.
                                                            ##       @param start_pos   Starting offset of the cluster. -1 means non-existant.
                                                            ##       @param end_pos     Starting offset of the cluster. -1 means non-existant or
                                                            ##                          final cluster.
                                                            ##       @param tstamp      Starting timestamp of the cluster.
                                                            ##       @retval  0 Success.
                                                            ##       @retval -1 Error.
                                                            ## 
proc offset_seek*(context: ptr nestegg; offset: uint64): cint {.
    importc: "nestegg_offset_seek", cdecl, impnesteggHdr.}
  ## 
                                                          ##   Seek to @a offset.  Stream will seek directly to offset.
                                                          ##       Must be used to seek to the start of a cluster; the parser will not be
                                                          ##       able to understand other offsets.
                                                          ##       @param context Stream context initialized by #nestegg_init.
                                                          ##       @param offset  Absolute offset in bytes.
                                                          ##       @retval  0 Success.
                                                          ##       @retval -1 Error.
                                                          ## 
proc track_seek*(context: ptr nestegg; track: cuint; tstamp: uint64): cint {.
    importc: "nestegg_track_seek", cdecl, impnesteggHdr.}
  ## 
                                                         ##   Seek @a track to @a tstamp.  Stream seek will terminate at the earliest
                                                         ##       key point in the stream at or before @a tstamp.  Other tracks in the
                                                         ##       stream will output packets with unspecified but nearby timestamps.
                                                         ##       @param context Stream context initialized by #nestegg_init.
                                                         ##       @param track   Zero based track number.
                                                         ##       @param tstamp  Absolute timestamp in nanoseconds.
                                                         ##       @retval  0 Success.
                                                         ##       @retval -1 Error.
                                                         ## 
proc track_type*(context: ptr nestegg; track: cuint): cint {.
    importc: "nestegg_track_type", cdecl, impnesteggHdr.}
  ## 
                                                         ##   Query the type specified by @a track.
                                                         ##       @param context Stream context initialized by #nestegg_init.
                                                         ##       @param track   Zero based track number.
                                                         ##       @retval #NESTEGG_TRACK_VIDEO   Track type is video.
                                                         ##       @retval #NESTEGG_TRACK_AUDIO   Track type is audio.
                                                         ##       @retval #NESTEGG_TRACK_UNKNOWN Track type is unknown.
                                                         ##       @retval -1 Error.
                                                         ## 
proc track_codec_id*(context: ptr nestegg; track: cuint): cint {.
    importc: "nestegg_track_codec_id", cdecl, impnesteggHdr.}
  ## 
                                                             ##   Query the codec ID specified by @a track.
                                                             ##       @param context Stream context initialized by #nestegg_init.
                                                             ##       @param track   Zero based track number.
                                                             ##       @retval #NESTEGG_CODEC_VP8     Track codec is VP8.
                                                             ##       @retval #NESTEGG_CODEC_VP9     Track codec is VP9.
                                                             ##       @retval #NESTEGG_CODEC_AV1     Track codec is AV1.
                                                             ##       @retval #NESTEGG_CODEC_VORBIS  Track codec is Vorbis.
                                                             ##       @retval #NESTEGG_CODEC_OPUS    Track codec is Opus.
                                                             ##       @retval #NESTEGG_CODEC_UNKNOWN Track codec is unknown.
                                                             ##       @retval -1 Error.
                                                             ## 
proc track_codec_data_count*(context: ptr nestegg; track: cuint;
                             count: ptr cuint): cint {.
    importc: "nestegg_track_codec_data_count", cdecl, impnesteggHdr.}
  ## 
                                                                     ##   Query the number of codec initialization chunks for @a track.  Each
                                                                     ##       chunk of data should be passed to the codec initialization functions in
                                                                     ##       the order returned.
                                                                     ##       @param context Stream context initialized by #nestegg_init.
                                                                     ##       @param track   Zero based track number.
                                                                     ##       @param count   Storage for the queried chunk count.
                                                                     ##       @retval  0 Success.
                                                                     ##       @retval -1 Error.
                                                                     ## 
proc track_codec_data*(context: ptr nestegg; track: cuint; item: cuint;
                       data: ptr ptr cuchar; length: ptr uint): cint {.
    importc: "nestegg_track_codec_data", cdecl, impnesteggHdr.}
  ## 
                                                               ##   Get a pointer to chunk number @a item of codec initialization data for
                                                               ##       @a track.
                                                               ##       @param context Stream context initialized by #nestegg_init.
                                                               ##       @param track   Zero based track number.
                                                               ##       @param item    Zero based chunk item number.
                                                               ##       @param data    Storage for the queried data pointer.
                                                               ##                      The data is owned by the #nestegg context.
                                                               ##       @param length  Storage for the queried data size.
                                                               ##       @retval  0 Success.
                                                               ##       @retval -1 Error.
                                                               ## 
proc track_video_params*(context: ptr nestegg; track: cuint;
                         params: ptr video_params): cint {.
    importc: "nestegg_track_video_params", cdecl, impnesteggHdr.}
  ## 
                                                                 ##   Query the video parameters specified by @a track.
                                                                 ##       @param context Stream context initialized by #nestegg_init.
                                                                 ##       @param track   Zero based track number.
                                                                 ##       @param params  Storage for the queried video parameters.
                                                                 ##       @retval  0 Success.
                                                                 ##       @retval -1 Error.
                                                                 ## 
proc track_audio_params*(context: ptr nestegg; track: cuint;
                         params: ptr audio_params): cint {.
    importc: "nestegg_track_audio_params", cdecl, impnesteggHdr.}
  ## 
                                                                 ##   Query the audio parameters specified by @a track.
                                                                 ##       @param context Stream context initialized by #nestegg_init.
                                                                 ##       @param track   Zero based track number.
                                                                 ##       @param params  Storage for the queried audio parameters.
                                                                 ##       @retval  0 Success.
                                                                 ##       @retval -1 Error.
                                                                 ## 
proc track_encoding*(context: ptr nestegg; track: cuint): cint {.
    importc: "nestegg_track_encoding", cdecl, impnesteggHdr.}
  ## 
                                                             ##   Query the encoding status for @a track. If a track has multiple encodings
                                                             ##       the first will be returned.
                                                             ##       @param context Stream context initialized by #nestegg_init.
                                                             ##       @param track   Zero based track number.
                                                             ##       @retval #NESTEGG_ENCODING_COMPRESSION The track is compressed, but not encrypted.
                                                             ##       @retval #NESTEGG_ENCODING_ENCRYPTION The track is encrypted and compressed.
                                                             ##       @retval -1 Error.
                                                             ## 
proc track_content_enc_key_id*(context: ptr nestegg; track: cuint;
                               content_enc_key_id: ptr ptr cuchar;
                               content_enc_key_id_length: ptr uint): cint {.
    importc: "nestegg_track_content_enc_key_id", cdecl, impnesteggHdr.}
  ## 
                                                                       ##   Query the ContentEncKeyId for @a track. Will return an error if the track
                                                                       ##       in not encrypted, or is not recognized.
                                                                       ##       @param context                   Stream context initialized by #nestegg_init.
                                                                       ##       @param track                     Zero based track number.
                                                                       ##       @param content_enc_key_id        Storage for queried id. The content encryption key used.
                                                                       ##                                        Owned by nestegg and will be freed separately.
                                                                       ##       @param content_enc_key_id_length Length of the queried ContentEncKeyId in bytes.
                                                                       ##       @retval  0 Success.
                                                                       ##       @retval -1 Error.
                                                                       ## 
proc track_default_duration*(context: ptr nestegg; track: cuint;
                             duration: ptr uint64): cint {.
    importc: "nestegg_track_default_duration", cdecl, impnesteggHdr.}
  ## 
                                                                     ##   Query the default frame duration for @a track.  For a video track, this
                                                                     ##       is typically the inverse of the video frame rate.
                                                                     ##       @param context  Stream context initialized by #nestegg_init.
                                                                     ##       @param track    Zero based track number.
                                                                     ##       @param duration Storage for the default duration in nanoseconds.
                                                                     ##       @retval  0 Success.
                                                                     ##       @retval -1 Error.
                                                                     ## 
proc read_reset*(context: ptr nestegg): cint {.importc: "nestegg_read_reset",
    cdecl, impnesteggHdr.}
  ## 
                          ##   Reset parser state to the last valid state before nestegg_read_packet failed.
                          ##       @param context Stream context initialized by #nestegg_init.
                          ##       @retval  0 Success.
                          ##       @retval -1 Error.
                          ## 
proc read_packet*(context: ptr nestegg; packet: ptr ptr cpacket): cint {.
    importc: "nestegg_read_packet", cdecl, impnesteggHdr.}
  ## 
                                                          ##   Read a packet of media data.  A packet consists of one or more chunks of
                                                          ##       data associated with a single track.  nestegg_read_packet should be
                                                          ##       called in a loop while the return value is 1 to drive the stream parser
                                                          ##       forward.  @see nestegg_free_packet
                                                          ##       @param context Context returned by #nestegg_init.
                                                          ##       @param packet  Storage for the returned nestegg_packet.
                                                          ##       @retval  1 Additional packets may be read in subsequent calls.
                                                          ##       @retval  0 End of stream.
                                                          ##       @retval -1 Error.
                                                          ## 
proc free_packet*(packet: ptr cpacket) {.importc: "nestegg_free_packet", cdecl,
    impnesteggHdr.}
  ## 
                   ##   Destroy a nestegg_packet and free associated memory.
                   ##       @param packet #nestegg_packet to be freed. @see nestegg_read_packet
                   ## 
proc packet_has_keyframe*(packet: ptr cpacket): cint {.
    importc: "nestegg_packet_has_keyframe", cdecl, impnesteggHdr.}
  ## 
                                                                  ##   Query the keyframe status for a given packet.
                                                                  ##       @param packet Packet initialized by #nestegg_read_packet.
                                                                  ##       @retval #NESTEGG_PACKET_HAS_KEYFRAME_FALSE   Packet contains no keyframes.
                                                                  ##       @retval #NESTEGG_PACKET_HAS_KEYFRAME_TRUE    Packet contains keyframes.
                                                                  ##       @retval #NESTEGG_PACKET_HAS_KEYFRAME_UNKNOWN Unknown packet keyframe content.
                                                                  ##       @retval -1 Error.
                                                                  ## 
proc packet_track*(packet: ptr cpacket; track: ptr cuint): cint {.
    importc: "nestegg_packet_track", cdecl, impnesteggHdr.}
  ## 
                                                           ##   Query the track number of @a packet.
                                                           ##       @param packet Packet initialized by #nestegg_read_packet.
                                                           ##       @param track  Storage for the queried zero based track index.
                                                           ##       @retval  0 Success.
                                                           ##       @retval -1 Error.
                                                           ## 
proc packet_tstamp*(packet: ptr cpacket; tstamp: ptr uint64): cint {.
    importc: "nestegg_packet_tstamp", cdecl, impnesteggHdr.}
  ## 
                                                            ##   Query the timestamp in nanoseconds of @a packet.
                                                            ##       @param packet Packet initialized by #nestegg_read_packet.
                                                            ##       @param tstamp Storage for the queried timestamp in nanoseconds.
                                                            ##       @retval  0 Success.
                                                            ##       @retval -1 Error.
                                                            ## 
proc packet_duration*(packet: ptr cpacket; duration: ptr uint64): cint {.
    importc: "nestegg_packet_duration", cdecl, impnesteggHdr.}
  ## 
                                                              ##   Query the duration in nanoseconds of @a packet.
                                                              ##       @param packet Packet initialized by #nestegg_read_packet.
                                                              ##       @param duration Storage for the queried duration in nanoseconds.
                                                              ##       @retval  0 Success.
                                                              ##       @retval -1 Error.
                                                              ## 
proc packet_count*(packet: ptr cpacket; count: ptr cuint): cint {.
    importc: "nestegg_packet_count", cdecl, impnesteggHdr.}
  ## 
                                                           ##   Query the number of data chunks contained in @a packet.
                                                           ##       @param packet Packet initialized by #nestegg_read_packet.
                                                           ##       @param count  Storage for the queried chunk count.
                                                           ##       @retval  0 Success.
                                                           ##       @retval -1 Error.
                                                           ## 
proc packet_data*(packet: ptr cpacket; item: cuint; data: ptr ptr cuchar;
                  length: ptr uint): cint {.importc: "nestegg_packet_data",
    cdecl, impnesteggHdr.}
  ## 
                          ##   Get a pointer to chunk number @a item of packet data.
                          ##       @param packet  Packet initialized by #nestegg_read_packet.
                          ##       @param item    Zero based chunk item number.
                          ##       @param data    Storage for the queried data pointer.
                          ##                      The data is owned by the #nestegg_packet packet.
                          ##       @param length  Storage for the queried data size.
                          ##       @retval  0 Success.
                          ##       @retval -1 Error.
                          ## 
proc packet_additional_data*(packet: ptr cpacket; id: cuint;
                             data: ptr ptr cuchar; length: ptr uint): cint {.
    importc: "nestegg_packet_additional_data", cdecl, impnesteggHdr.}
  ## 
                                                                     ##   Get a pointer to additional data with identifier @a id of additional packet
                                                                     ##       data. If @a id isn't present in the packet, returns -1.
                                                                     ##       @param packet  Packet initialized by #nestegg_read_packet.
                                                                     ##       @param id      Codec specific identifer. For VP8, use 1 to get a VP8 encoded
                                                                     ##                      frame containing an alpha channel in its Y plane.
                                                                     ##       @param data    Storage for the queried data pointer.
                                                                     ##                      The data is owned by the #nestegg_packet packet.
                                                                     ##       @param length  Storage for the queried data size.
                                                                     ##       @retval  0 Success.
                                                                     ##       @retval -1 Error.
                                                                     ## 
proc packet_discard_padding*(packet: ptr cpacket; discard_padding: ptr int64): cint {.
    importc: "nestegg_packet_discard_padding", cdecl, impnesteggHdr.}
  ## 
                                                                     ##   Returns discard_padding for given packet
                                                                     ##       @param packet  Packet initialized by #nestegg_read_packet.
                                                                     ##       @param discard_padding pointer to store discard padding in.
                                                                     ##       @retval  0 Success.
                                                                     ##       @retval -1 Error.
                                                                     ## 
proc packet_encryption*(packet: ptr cpacket): cint {.
    importc: "nestegg_packet_encryption", cdecl, impnesteggHdr.}
  ## 
                                                                ##   Query if a packet is encrypted.
                                                                ##       @param packet Packet initialized by #nestegg_read_packet.
                                                                ##       @retval  #NESTEGG_PACKET_HAS_SIGNAL_BYTE_FALSE No signal byte, encryption
                                                                ##                information not read from packet.
                                                                ##       @retval  #NESTEGG_PACKET_HAS_SIGNAL_BYTE_UNENCRYPTED Encrypted bit not
                                                                ##                set, encryption information not read from packet.
                                                                ##       @retval  #NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED Encrypted bit set,
                                                                ##                encryption infomation read from packet.
                                                                ##       @retval  #NESTEGG_PACKET_HAS_SIGNAL_BYTE_PARTITIONED Partitioned bit set,
                                                                ##                encryption and parition information read from packet.
                                                                ##       @retval -1 Error.
                                                                ## 
proc packet_iv*(packet: ptr cpacket; iv: ptr ptr cuchar; length: ptr uint): cint {.
    importc: "nestegg_packet_iv", cdecl, impnesteggHdr.}
  ## 
                                                        ##   Query the IV for an encrypted packet. Expects a packet from an encrypted
                                                        ##       track, and will return error if given a packet that has no signal btye.
                                                        ##       @param packet Packet initialized by #nestegg_read_packet.
                                                        ##       @param iv     Storage for queried iv.
                                                        ##       @param length Length of returned iv, may be 0.
                                                        ##                     The data is owned by the #nestegg_packet packet.
                                                        ##       @retval  0 Success.
                                                        ##       @retval -1 Error.
                                                        ## 
proc packet_offsets*(packet: ptr cpacket; partition_offsets: ptr ptr uint32;
                     num_offsets: ptr uint8): cint {.
    importc: "nestegg_packet_offsets", cdecl, impnesteggHdr.}
  ## 
                                                             ##   Query the packet for offsets.
                                                             ##   @param packet            Packet initialized by #nestegg_read_packet.
                                                             ##   @param partition_offsets Storage for queried offsets.
                                                             ##   @param num_offsets       Length of returned offsets, may be 0.
                                                             ##   The data is owned by the #nestegg_packet packet.
                                                             ##   @retval  0 Success.
                                                             ##   @retval -1 Error.
                                                             ## 
proc packet_reference_block*(packet: ptr cpacket; reference_block: ptr int64): cint {.
    importc: "nestegg_packet_reference_block", cdecl, impnesteggHdr.}
  ## 
                                                                     ##   Returns reference_block given packet
                                                                     ##       @param packet          Packet initialized by #nestegg_read_packet.
                                                                     ##       @param reference_block pointer to store reference block in.
                                                                     ##       @retval  0 Success.
                                                                     ##       @retval -1 Error.
                                                                     ## 
proc has_cues*(context: ptr nestegg): cint {.importc: "nestegg_has_cues", cdecl,
    impnesteggHdr.}
  ## 
                   ##   Query the presence of cues.
                   ##       @param context  Stream context initialized by #nestegg_init.
                   ##       @retval 0 The media has no cues.
                   ##       @retval 1 The media has cues.
                   ## 
proc sniff*(buffer: ptr cuchar; length: uint): cint {.importc: "nestegg_sniff",
    cdecl, impnesteggHdr.}
  ## 
                          ##   Try to determine if the buffer looks like the beginning of a WebM file.
                          ##       @param buffer A buffer containing the beginning of a media file.
                          ##       @param length The size of the buffer.
                          ##       @retval 0 The file is not a WebM file.
                          ##       @retval 1 The file is a WebM file.
                          ## 
{.pop.}

# Saved to /home/scarf/.cache/nim/nimterop/toastCache/nimterop_1553636112.nim
.
/home/scarf/repo/etc/nimapple/test.nim(5, 22) Error: type mismatch: got 'File' for 'file' but expected 'Demuxer = ref DemuxerObj'

I'm not sure the reason of crash, also is it normal for nim compiler to spew out compilation process?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.