Add doc too
[audio-opusfile.git] / lib / Audio / Opusfile.pm
CommitLineData
a3f1cbda
MG
1package Audio::Opusfile;
2
3use 5.014000;
4use strict;
5use warnings;
6use Carp;
7
8use parent qw/Exporter/;
9use AutoLoader;
10
11my @constants =
12 qw/OPUS_CHANNEL_COUNT_MAX
13 OP_ABSOLUTE_GAIN
14 OP_DEC_FORMAT_FLOAT
15 OP_DEC_FORMAT_SHORT
16 OP_DEC_USE_DEFAULT
17 OP_EBADHEADER
18 OP_EBADLINK
19 OP_EBADPACKET
20 OP_EBADTIMESTAMP
21 OP_EFAULT
22 OP_EIMPL
23 OP_EINVAL
24 OP_ENOSEEK
25 OP_ENOTAUDIO
26 OP_ENOTFORMAT
27 OP_EOF
28 OP_EREAD
29 OP_EVERSION
30 OP_FALSE
31 OP_GET_SERVER_INFO_REQUEST
32 OP_HEADER_GAIN
33 OP_HOLE
34 OP_HTTP_PROXY_HOST_REQUEST
35 OP_HTTP_PROXY_PASS_REQUEST
36 OP_HTTP_PROXY_PORT_REQUEST
37 OP_HTTP_PROXY_USER_REQUEST
38 OP_PIC_FORMAT_GIF
39 OP_PIC_FORMAT_JPEG
40 OP_PIC_FORMAT_PNG
41 OP_PIC_FORMAT_UNKNOWN
42 OP_PIC_FORMAT_URL
43 OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST
44 OP_TRACK_GAIN/;
45
46our @EXPORT_OK = @constants;
47our @EXPORT = @constants;
48
74630599 49our $VERSION = '0.002001';
a3f1cbda
MG
50
51sub AUTOLOAD {
52 # This AUTOLOAD is used to 'autoload' constants from the constant()
53 # XS function.
54
55 my $constname;
56 our $AUTOLOAD;
57 ($constname = $AUTOLOAD) =~ s/.*:://;
58 croak "&Audio::Opusfile::constant not defined" if $constname eq 'constant';
59 my ($error, $val) = constant($constname);
60 if ($error) { croak $error; }
61 {
62 no strict 'refs';
63 # Fixed between 5.005_53 and 5.005_61
64#XXX if ($] >= 5.00561) {
65#XXX *$AUTOLOAD = sub () { $val };
66#XXX }
67#XXX else {
68 *$AUTOLOAD = sub { $val };
69#XXX }
70 }
71 goto &$AUTOLOAD;
72}
73
74require XSLoader;
75XSLoader::load('Audio::Opusfile', $VERSION);
76require Audio::Opusfile::Tags;
2f4b5b1b 77require Audio::Opusfile::PictureTag;
a3f1cbda
MG
78
79# Preloaded methods go here.
80
81sub new_from_file {
82 my ($class, $file) = @_;
83 open_file($file)
84}
85
5fbea9a2
MG
86sub new_from_memory {
87 my ($class, $buf) = @_;
88 open_memory($buf)
89}
90
a3f1cbda
MG
911;
92__END__
93
94=encoding utf-8
95
96=head1 NAME
97
98Audio::Opusfile - Very incomplete interface to the libopusfile Ogg Opus library
99
100=head1 SYNOPSIS
101
102 use Audio::Opusfile;
103 my $of = Audio::Opusfile->new_from_file('silence.opus');
104 my $tags = $of->tags;
105 say $tags->query('TITLE'); # Cellule
106
107=head1 DESCRIPTION
108
109Opus is a totally open, royalty-free, highly versatile audio codec.
110Opus is unmatched for interactive speech and music transmission over
111the Internet, but is also intended for storage and streaming
112applications. It is standardized by the Internet Engineering Task
113Force (IETF) as RFC 6716 which incorporated technology from Skype's
114SILK codec and Xiph.Org's CELT codec.
115
116libopusfile is a library for decoding and basic manipulation of Ogg
117Opus files.
118
119Audio::Opusfile is an interface to libopusfile. At the moment its only
2f4b5b1b
MG
120function is reading metadata and tags from an Ogg Opus file. Future
121versions will give access to a larger part of the libopusfile API.
a3f1cbda
MG
122
123Expect the API to change in future versions.
124
125=head1 METHODS
126
127=over
128
129=item Audio::Opusfile->B<new_from_file>(I<$file>)
130
131Creates a new Audio::Opusfile object from an Ogg Opus file.
132
133Dies if the given file does not exist or is not a valid Ogg Opus file.
134
33fac129
MG
135=item Audio::Opusfile->B<new_from_memory>(I<$buffer>)
136
137Creates a new Audio::Opusfile object from a buffer containing Ogg Opus
138data.
139
140Dies if the given buffer does not contain valid data.
141
142=item Audio::Opusfile::test(I<$buffer>)
143
144Returns true if the given buffer looks like the beginning of a valid
145Ogg Opus file, false otherwise.
146
147Dies if the given buffer does not have sufficient data to tell if it
148is an Opus stream or if it looks like a Opus stream but parsing it
149failed.
150
2f4b5b1b
MG
151=item B<$of>->head
152
153Returns an L<Audio::Opusfile::Head> object corresponding to the file.
154
a3f1cbda
MG
155=item B<$of>->tags
156
157Returns an L<Audio::Opusfile::Tags> object corresponding to the file.
158
33fac129
MG
159=item B<$of>->seekable
160
161Returns whether or not the data source being read is seekable.
162
163=item B<$of>->link_count
164
165Returns the number of links in this chained stream. Always returns 1
166for unseekable sources.
167
168=item B<$of>->serialno([I<$link_index>])
169
170Get the serial number of the given link in a (possibly-chained) Ogg
171Opus stream. If the given index is greater than the total number of
172links, this returns the serial number of the last link.
173
174If the source is not seekable, I<$link_index> is negative, or
175I<$link_index> is not given, then this function returns the serial
176number of the current link.
177
a3f1cbda
MG
178=back
179
180=head1 EXPORT
181
182All constants are exported by default:
183
184 OPUS_CHANNEL_COUNT_MAX
185 OP_ABSOLUTE_GAIN
186 OP_DEC_FORMAT_FLOAT
187 OP_DEC_FORMAT_SHORT
188 OP_DEC_USE_DEFAULT
189 OP_EBADHEADER
190 OP_EBADLINK
191 OP_EBADPACKET
192 OP_EBADTIMESTAMP
193 OP_EFAULT
194 OP_EIMPL
195 OP_EINVAL
196 OP_ENOSEEK
197 OP_ENOTAUDIO
198 OP_ENOTFORMAT
199 OP_EOF
200 OP_EREAD
201 OP_EVERSION
202 OP_FALSE
203 OP_GET_SERVER_INFO_REQUEST
204 OP_HEADER_GAIN
205 OP_HOLE
206 OP_HTTP_PROXY_HOST_REQUEST
207 OP_HTTP_PROXY_PASS_REQUEST
208 OP_HTTP_PROXY_PORT_REQUEST
209 OP_HTTP_PROXY_USER_REQUEST
210 OP_PIC_FORMAT_GIF
211 OP_PIC_FORMAT_JPEG
212 OP_PIC_FORMAT_PNG
213 OP_PIC_FORMAT_UNKNOWN
214 OP_PIC_FORMAT_URL
215 OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST
216 OP_TRACK_GAIN
217
218
219=head1 SEE ALSO
220
221L<Audio::Opusfile::Tags>,
222L<http://opus-codec.org/>,
223L<http://opus-codec.org/docs/opusfile_api-0.7/index.html>
224
225=head1 AUTHOR
226
227Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
228
229=head1 COPYRIGHT AND LICENSE
230
231Copyright (C) 2016 by Marius Gavrilescu
232
233This library is free software; you can redistribute it and/or modify
234it under the same terms as Perl itself, either Perl version 5.24.0 or,
235at your option, any later version of Perl 5 you may have available.
236
237
238=cut
This page took 0.022094 seconds and 4 git commands to generate.