First commit of SDL_Perl-2.1.3
[sdlgit/SDL_perl.git] / lib / SDL / Video.pm
1 #
2 #       Video.pm
3 #
4 #       A package for manipulating MPEG video 
5 #
6 #       Copyright (C) 2004 David J. Goehrig
7
8 package SDL::Video;
9
10 use strict;
11 use SDL;
12 use SDL::Surface;
13 use SDL::MPEG;
14
15 sub new {
16         my $proto = shift;
17         my $class = ref($proto) || $proto;
18         my %options = @_;
19
20         verify (%options, qw/ -name -audio / ) if $SDL::DEBUG;
21
22         my $n = $options{-name} || die "SDL::Video must supply a filename to SDL::Video::new\n";
23         my $a = $options{'-audio'} ? 1 : 0;
24         my $info = new SDL::MPEG();
25         
26         my $self = \SDL::NewSMPEG($n,$$info,$a);
27         bless $self,$class;
28         $self->audio(1);
29         $self->video(1);
30         return $self, $info;
31 }
32
33 sub DESTROY {
34         SDL::FreeSMPEG(${$_[0]});
35 }
36
37 sub error {
38         SDL::SMPEGError(${$_[0]});
39 }
40
41 sub audio {
42         SDL::SMPEGEnableAudio( ${$_[0]}, $_[1]);
43 }
44
45 sub video {
46         SDL::SMPEGEnableVideo( ${$_[0]}, $_[1]);
47 }
48
49 sub volume {
50         SDL::SMPEGSetVolume( ${$_[0]}, $_[1] );
51 }
52
53 sub display {
54         die "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
55         SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0);
56 }
57
58 sub scale {
59         return SDL::SMPEGScaleXY(${$_[0]},$_[1],$_[2]) if (@_ == 3 );
60         return SDL::SMPEGScaleXY(${$_[0]},$_[1]->width(),$_[1]->height()) if $_[1]->isa('SDL::Surface');
61         SDL::SMPEGScale(${$_[0]},$_[1]);
62 }
63
64 sub play {
65         SDL::SMPEGPlay(${$_[0]});
66 }
67
68 sub pause {
69         SDL::SMPEGPause(${$_[0]});
70 }
71
72 sub stop {
73         SDL::SMPEGStop(${$_[0]});
74 }
75
76 sub rewind {
77         SDL::SMPEGRewind(${$_[0]});
78 }
79
80 sub seek {
81         SDL::SMPEGSeek(${$_[0]},$_[1]);
82 }
83
84 sub skip {
85         SDL::SMPEGSkip(${$_[0]},$_[1]);
86 }
87
88 sub loop {
89         SDL::SMPEGLoop(${$_[0]},$_[1]);
90 }
91
92 sub region {
93         die "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
94         SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]});
95 }
96
97 sub frame {
98         SDL::SMPEGRenderFrame(${$_[0]},$_[1]);
99 }
100
101 sub info {
102         new SDL::MPEG -from => $_[0];
103 }
104
105 sub status {
106         SDL::SMPEGStatus(${$_[0]});
107 }
108
109 1;
110
111 __END__;
112
113 =pod
114
115
116 =head1 NAME
117
118 SDL::Video - a SDL perl extension
119
120 =head1 SYNOPSIS
121
122   $video = new SDL::Video ( -name => 'pr0n.mpg' );
123
124 =head1 DESCRIPTION
125
126 C<SDL::Video> adds support for MPEG video to your
127 SDL Perl application.  Videos are objects bound to
128 surfaces, whose playback is controled through the
129 object's interface.
130
131 =head2 METHODS 
132
133
134 =over 4
135
136 =item *
137
138 C<SDL::Video::error()> returns any error messages associated with playback 
139
140 =item * 
141
142 C<SDL::Video::audio(bool)> enables or disables audio playback, (on by default)
143
144 =item * 
145
146 C<SDL::Video::video(bool)> enables or disable video playback, (on by default)
147
148 =item * 
149
150 C<SDL::Video::loop(bool)> enables or disable playback looping (off by default) 
151
152 =item * 
153
154 C<SDL::Video::volume(int)> set the volume as per the mixer volume
155
156 =item * 
157
158 C<SDL::Video:display(surface)> binds the clip to a display surface
159
160 =item * 
161
162 C<SDL::Video::scale([x,y]|[surface]|int)> scales the clip by either x,y
163 factors, scales to the image dimensions, or a single scalar.
164
165 =item * 
166
167 C<SDL::Video::play()> plays the video clip, call C<SDL::Video::display()> before playing
168
169 =item * 
170
171 C<SDL::Video::pause()> pauses video playback
172
173 =item * 
174
175 C<SDL::Video::stop()> stops video playback
176
177 =item * 
178
179 C<SDL::Video::rewind()> resets the clip to the beginning 
180
181 =item * 
182
183 C<SDL::Video::seek(offset)> seeks to a particular byte offset
184
185 =item * 
186
187 C<SDL::Video::skip(time)> skips to a particular time
188
189 =item * 
190
191 C<SDL::Video::region(rect)> takes a SDL::Rect and defines the display area
192
193 =item * 
194
195 C<SDL::Video::frame(int)> renders a specific frame to the screen
196
197 =item * 
198
199 C<SDL::Video::info()> returns a new C<SDL::MPEG> object reflecting the current status
200
201 =item *
202
203 C<SDL::Video::status()> returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR
204
205 =back
206
207 =head1 AUTHOR
208
209 David J. Goehrig
210
211 =head1 SEE ALSO
212
213 perl(1) SDL::Surface(3) SDL::MPEG(3)
214
215 =cut
216