From: Marius Gavrilescu Date: Sat, 17 Sep 2016 23:34:30 +0000 (+0100) Subject: More functions X-Git-Tag: 0.003~3 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=5fbea9a258070b0c9e770e80aa52d17d66730d44;p=audio-opusfile.git More functions --- diff --git a/Opusfile.xs b/Opusfile.xs index 6a5f55d..43ab5a6 100644 --- a/Opusfile.xs +++ b/Opusfile.xs @@ -21,19 +21,55 @@ op_open_file(path) const char *path; PREINIT: int err; -CODE: - RETVAL = op_open_file(path, &err); +C_ARGS: + path, &err +POSTCALL: if(err) croak("op_open_file returned error %d\n", err); + +OggOpusFile* +op_open_memory(const char *data, size_t length(data)) +PREINIT: + int err; +C_ARGS: + data, XSauto_length_of_data, &err +POSTCALL: + if(err) + croak("op_open_memory returned error %d\n", err); + +bool +op_test(const char *data, size_t length(data)) +PROTOTYPE: $ +PREINIT: + int ret; +CODE: + ret = op_test (NULL, data, XSauto_length_of_data); + if(ret < 0 && ret != OP_ENOTFORMAT && ret != OP_EBADHEADER) + croak("op_test returned error %d\n", RETVAL); + RETVAL = !ret; OUTPUT: RETVAL + void DESTROY(of) OggOpusFile *of; CODE: op_free(of); +bool +op_seekable(of) + OggOpusFile* of; + +int +op_link_count(of) + OggOpusFile* of; + +int +op_serialno(of, li = -1) + OggOpusFile* of; + int li; + const OpusHead* op_head(of, li = -1) OggOpusFile *of; diff --git a/lib/Audio/Opusfile.pm b/lib/Audio/Opusfile.pm index e3e2f41..e0546ba 100644 --- a/lib/Audio/Opusfile.pm +++ b/lib/Audio/Opusfile.pm @@ -83,6 +83,11 @@ sub new_from_file { open_file($file) } +sub new_from_memory { + my ($class, $buf) = @_; + open_memory($buf) +} + 1; __END__ diff --git a/t/Audio-Opusfile.t b/t/Audio-Opusfile.t index 5e8c7ee..ca00190 100644 --- a/t/Audio-Opusfile.t +++ b/t/Audio-Opusfile.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 12; BEGIN { use_ok('Audio::Opusfile') }; my $fail = 0; @@ -29,7 +29,21 @@ foreach my $constname (qw( ok( $fail == 0 , 'Constants' ); my $of = Audio::Opusfile->new_from_file('empty.opus'); +ok $of->seekable, 'seekable'; +is $of->link_count, 1, 'link_count'; +is $of->serialno(0), 1745145935, 'serialno, arg=0'; +is $of->serialno(200), 1745145935, 'serialno, arg=200'; +is $of->serialno, 1745145935, 'serialno, no arg'; my $tags = $of->tags; is $tags->query_count('TITLE'), 1, 'query_count'; is $tags->query('TITLE'), 'Cellule', 'query'; is_deeply [$tags->query_all('TITLE')], ['Cellule'], 'query_all'; + +open my $fh, '<', 'empty.opus'; +read $fh, my $buf, 100; +ok Audio::Opusfile::test($buf), 'test'; + +seek $fh, 0, 0; +read $fh, $buf, 20000; +$of = Audio::Opusfile->new_from_memory($buf); +is $of->tags->query('TITLE'), 'Cellule', 'new_from_memory + query';