2 SMPEG - SDL MPEG Player Library
3 Copyright (C) 1999 Loki Entertainment Software
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* This is the C interface to the SMPEG library */
26 #include "SDL_mutex.h"
27 #include "SDL_audio.h"
28 #include "MPEGframe.h"
34 #define SMPEG_MAJOR_VERSION 2
35 #define SMPEG_MINOR_VERSION 0
36 #define SMPEG_PATCHLEVEL 0
44 /* This macro can be used to fill a version structure with the compile-time
45 * version of the SDL library.
47 #define SMPEG_VERSION(X) \
49 (X)->major = SMPEG_MAJOR_VERSION; \
50 (X)->minor = SMPEG_MINOR_VERSION; \
51 (X)->patch = SMPEG_PATCHLEVEL; \
54 /* This is the actual SMPEG object */
55 typedef struct _SMPEG SMPEG;
57 /* Used to get information about the SMPEG object */
58 typedef struct _SMPEG_Info {
65 char audio_string[80];
66 int audio_current_frame;
67 Uint32 current_offset;
73 /* Possible MPEG status codes */
81 /* Matches the declaration of SDL_UpdateRect() */
82 typedef void(*SMPEG_DisplayCallback)(void *data, SMPEG_Frame *frame);
84 /* Create a new SMPEG object from an MPEG file.
85 On return, if 'info' is not NULL, it will be filled with information
86 about the MPEG object.
87 This function returns a new SMPEG object. Use SMPEG_error() to find out
88 whether or not there was a problem building the MPEG stream.
89 The sdl_audio parameter indicates if SMPEG should initialize the SDL audio
90 subsystem. If not, you will have to use the SMPEG_playaudio() function below
91 to extract the decoded data.
93 extern DECLSPEC SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio);
95 /* The same as above for a file descriptor */
96 extern DECLSPEC SMPEG* SMPEG_new_descr(int file, SMPEG_Info* info, int sdl_audio);
99 The same as above but for a raw chunk of data. SMPEG makes a copy of the
100 data, so the application is free to delete after a successful call to this
103 extern DECLSPEC SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio);
105 /* The same for a generic SDL_RWops structure.
106 'freesrc' should be non-zero if SMPEG should close the source when it's done.
108 extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio);
110 /* Get current information about an SMPEG object */
111 extern DECLSPEC void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info );
113 /* Enable or disable audio playback in MPEG stream */
114 extern DECLSPEC void SMPEG_enableaudio( SMPEG* mpeg, int enable );
116 /* Enable or disable video playback in MPEG stream */
117 extern DECLSPEC void SMPEG_enablevideo( SMPEG* mpeg, int enable );
119 /* Delete an SMPEG object */
120 extern DECLSPEC void SMPEG_delete( SMPEG* mpeg );
122 /* Get the current status of an SMPEG object */
123 extern DECLSPEC SMPEGstatus SMPEG_status( SMPEG* mpeg );
125 /* Set the audio volume of an MPEG stream, in the range 0-100 */
126 extern DECLSPEC void SMPEG_setvolume( SMPEG* mpeg, int volume );
128 /* Set the frame display callback for MPEG video
129 'lock' is a mutex used to synchronize access to the frame data, and is held during the update callback.
131 extern DECLSPEC void SMPEG_setdisplay(SMPEG* mpeg, SMPEG_DisplayCallback callback, void* data, SDL_mutex* lock);
133 /* Set or clear looping play on an SMPEG object */
134 extern DECLSPEC void SMPEG_loop( SMPEG* mpeg, int repeat );
136 /* Play an SMPEG object */
137 extern DECLSPEC void SMPEG_play( SMPEG* mpeg );
139 /* Pause/Resume playback of an SMPEG object */
140 extern DECLSPEC void SMPEG_pause( SMPEG* mpeg );
142 /* Stop playback of an SMPEG object */
143 extern DECLSPEC void SMPEG_stop( SMPEG* mpeg );
145 /* Rewind the play position of an SMPEG object to the beginning of the MPEG */
146 extern DECLSPEC void SMPEG_rewind( SMPEG* mpeg );
148 /* Seek 'bytes' bytes in the MPEG stream */
149 extern DECLSPEC void SMPEG_seek( SMPEG* mpeg, int bytes);
151 /* Skip 'seconds' seconds in the MPEG stream */
152 extern DECLSPEC void SMPEG_skip( SMPEG* mpeg, float seconds );
154 /* Render a particular frame in the MPEG video */
155 extern DECLSPEC void SMPEG_renderFrame( SMPEG* mpeg, int framenum );
157 /* Render the last frame of an MPEG video */
158 extern DECLSPEC void SMPEG_renderFinal( SMPEG* mpeg );
160 /* Return NULL if there is no error in the MPEG stream, or an error message
161 if there was a fatal error in the MPEG stream for the SMPEG object.
163 extern DECLSPEC char *SMPEG_error( SMPEG* mpeg );
165 /* Exported callback function for audio playback.
166 The function takes a buffer and the amount of data to fill, and returns
167 the amount of data in bytes that was actually written. This will be the
168 amount requested unless the MPEG audio has finished.
170 extern DECLSPEC int SMPEG_playAudio( SMPEG *mpeg, Uint8 *stream, int len );
172 /* Wrapper for SMPEG_playAudio() that can be passed to SDL and SDL_mixer
174 extern DECLSPEC void SMPEG_playAudioSDL( void *mpeg, Uint8 *stream, int len );
176 /* Get the best SDL audio spec for the audio stream */
177 extern DECLSPEC int SMPEG_wantedSpec( SMPEG *mpeg, SDL_AudioSpec *wanted );
179 /* Inform SMPEG of the actual SDL audio spec used for sound playback */
180 extern DECLSPEC void SMPEG_actualSpec( SMPEG *mpeg, SDL_AudioSpec *spec );
185 #endif /* _SMPEG_H_ */