Applied patch ready for merge
[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 warnings;
35 use Carp;
36 use SDL;
37
38 sub new {
39         my $proto = shift;
40         my $class = ref($proto) || $proto;
41         my %options = @_;
42
43         verify (%options, qw/ -from / ) if $SDL::DEBUG;
44
45         my $self;
46         if ( $options{-from} ) {
47                 croak "SDL::MPEG::new -from requires a SDL::Video object\n"
48                         unless $options{-from}->isa('SDL::Video');
49
50                 $self = \SDL::SMPEGGetInfo(${$options{-from}});
51         } else {
52                 $self = \SDL::NewSMPEGInfo();
53         }       
54         bless $self,$class;
55         return $self;
56 }
57
58 sub DESTROY {
59         SDL::FreeSMPEGInfo(${$_[0]});
60 }
61
62 sub has_audio {
63         SDL::SMPEGInfoHasAudio(${$_[0]});
64 }
65
66 sub has_video {
67         SDL::SMPEGInfoHasVideo(${$_[0]});
68 }
69
70 sub width {
71         SDL::SMPEGInfoWidth(${$_[0]});
72 }
73
74 sub height {
75         SDL::SMPEGInfoHeight(${$_[0]});
76 }
77
78 sub size {
79         SDL::SMPEGInfoTotalSize(${$_[0]});
80 }
81
82 sub offset {
83         SDL::SMPEGInfoCurrentOffset(${$_[0]});
84 }
85
86 sub frame {
87         SDL::SMPEGInfoCurrentFrame(${$_[0]});
88 }
89
90 sub fps {
91         SDL::SMPEGInfoCurrentFPS(${$_[0]});
92 }
93
94 sub time {
95         SDL::SMPEGInfoCurrentTime(${$_[0]});
96 }
97
98 sub length {
99         SDL::SMPEGInfoTotalTime(${$_[0]});
100 }
101
102 1;
103
104 __END__;
105
106 =pod
107
108
109 =head1 NAME
110
111 SDL::MPEG - a SDL perl extension
112
113 =head1 SYNOPSIS
114
115   $info = new SDL::MPEG -from => $mpeg;
116
117 =head1 DESCRIPTION
118
119 C<SDL::MPEG> provides an interface to quering the status
120 of a SMPEG stream.  
121
122 =head2 METHODS 
123
124 =over 4
125
126 =item *
127
128 C<SDL::MPEG::has_audio> returns true if it has audio track
129
130 =item *
131
132 C<SDL::MPEG::has_video> returns true if it has a video track
133
134 =item *
135
136 C<SDL::MPEG::width> returns the width of the video in pixels
137
138 =item *
139
140 C<SDL::MPEG::height> returns the height of the video in pixels
141
142 =item *
143
144 C<SDL::MPEG::size> returns the total size of the clip in bytes
145
146 =item *
147
148 C<SDL::MPEG::offset> returns the offset into the clip in bytes
149
150 =item *
151
152 C<SDL::MPEG::frame> returns the offset into the clip in fames 
153
154 =item *
155
156 C<SDL::MPEG::fps> returns the play rate in frames per second
157
158 =item *
159
160 C<SDL::MPEG::time> returns the current play time in seconds
161
162 =item *
163
164 C<SDL::MPEG::length> returns the total play time in seconds
165
166 =back
167
168 =head1 AUTHOR
169
170 David J. Goehrig
171
172 =head1 SEE ALSO
173
174 perl(1) SDL::Video(3)
175
176 =cut
177