Importing SDLPerl 2.2
[sdlgit/SDL_perl.git] / lib / SDL / MPEG.pm
1 #!/usr/bin/env perl
2 #
3 # MPEG.pm
4 #
5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6 #
7 # ------------------------------------------------------------------------------
8 #
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 # ------------------------------------------------------------------------------
24 #
25 # Please feel free to send questions, suggestions or improvements to:
26 #
27 #       David J. Goehrig
28 #       dgoehrig@cpan.org
29 #
30
31 package SDL::MPEG;
32
33 use strict;
34 use SDL;
35
36 sub new {
37         my $proto = shift;
38         my $class = ref($proto) || $proto;
39         my %options = @_;
40
41         verify (%options, qw/ -from / ) if $SDL::DEBUG;
42
43         my $self;
44         if ( $options{-from} ) {
45                 die "SDL::MPEG::new -from requires a SDL::Video object\n"
46                         unless $options{-from}->isa('SDL::Video');
47
48                 $self = \SDL::SMPEGGetInfo(${$options{-from}});
49         } else {
50                 $self = \SDL::NewSMPEGInfo();
51         }       
52         bless $self,$class;
53         return $self;
54 }
55
56 sub DESTROY {
57         SDL::FreeSMPEGInfo(${$_[0]});
58 }
59
60 sub has_audio {
61         SDL::SMPEGInfoHasAudio(${$_[0]});
62 }
63
64 sub has_video {
65         SDL::SMPEGInfoHasVideo(${$_[0]});
66 }
67
68 sub width {
69         SDL::SMPEGInfoWidth(${$_[0]});
70 }
71
72 sub height {
73         SDL::SMPEGInfoHeight(${$_[0]});
74 }
75
76 sub size {
77         SDL::SMPEGInfoTotalSize(${$_[0]});
78 }
79
80 sub offset {
81         SDL::SMPEGInfoCurrentOffset(${$_[0]});
82 }
83
84 sub frame {
85         SDL::SMPEGInfoCurrentFrame(${$_[0]});
86 }
87
88 sub fps {
89         SDL::SMPEGInfoCurrentFPS(${$_[0]});
90 }
91
92 sub time {
93         SDL::SMPEGInfoCurrentTime(${$_[0]});
94 }
95
96 sub length {
97         SDL::SMPEGInfoTotalTime(${$_[0]});
98 }
99
100 1;
101
102 __END__;
103
104 =pod
105
106
107 =head1 NAME
108
109 SDL::MPEG - a SDL perl extension
110
111 =head1 SYNOPSIS
112
113   $info = new SDL::MPEG -from => $mpeg;
114
115 =head1 DESCRIPTION
116
117 C<SDL::MPEG> provides an interface to quering the status
118 of a SMPEG stream.  
119
120 =head2 METHODS 
121
122 =over 4
123
124 =item *
125
126 C<SDL::MPEG::has_audio> returns true if it has audio track
127
128 =item *
129
130 C<SDL::MPEG::has_video> returns true if it has a video track
131
132 =item *
133
134 C<SDL::MPEG::width> returns the width of the video in pixels
135
136 =item *
137
138 C<SDL::MPEG::height> returns the height of the video in pixels
139
140 =item *
141
142 C<SDL::MPEG::size> returns the total size of the clip in bytes
143
144 =item *
145
146 C<SDL::MPEG::offset> returns the offset into the clip in bytes
147
148 =item *
149
150 C<SDL::MPEG::frame> returns the offset into the clip in fames 
151
152 =item *
153
154 C<SDL::MPEG::fps> returns the play rate in frames per second
155
156 =item *
157
158 C<SDL::MPEG::time> returns the current play time in seconds
159
160 =item *
161
162 C<SDL::MPEG::length> returns the total play time in seconds
163
164 =back
165
166 =head1 AUTHOR
167
168 David J. Goehrig
169
170 =head1 SEE ALSO
171
172 perl(1) SDL::Video(3)
173
174 =cut
175