More functions
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 17 Sep 2016 23:34:30 +0000 (00:34 +0100)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 17 Sep 2016 23:45:58 +0000 (00:45 +0100)
Opusfile.xs
lib/Audio/Opusfile.pm
t/Audio-Opusfile.t

index 6a5f55da6f2148f3303cc97fe552abcd71cb5ecd..43ab5a608fe34a6a016fc38d98cbaea41d433452 100644 (file)
@@ -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;
index e3e2f41c2932c94bc19dca4f06ad32a165596f0b..e0546ba435f09e2a77f964735c3c909697c5010a 100644 (file)
@@ -83,6 +83,11 @@ sub new_from_file {
        open_file($file)
 }
 
+sub new_from_memory {
+       my ($class, $buf) = @_;
+       open_memory($buf)
+}
+
 1;
 __END__
 
index 5e8c7ee77a78fd7e7d37a0ea4c7c04c9effcd817..ca00190215381a890161e0211bd97cd0f1608957 100644 (file)
@@ -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';
This page took 0.013743 seconds and 4 git commands to generate.