add smpeg to project

This commit is contained in:
dborth 2009-08-04 05:44:43 +00:00
parent ff80b8d007
commit 3c0e60b546
49 changed files with 27137 additions and 0 deletions

View file

@ -4,6 +4,7 @@ all:
cd SDL_image; $(MAKE) -f Makefile
cd SDL_net; $(MAKE) -f Makefile
cd SDL_ttf; $(MAKE) -f Makefile
cd smpeg; $(MAKE) -f Makefile
clean:
cd SDL; $(MAKE) -f Makefile clean
@ -11,6 +12,7 @@ clean:
cd SDL_image; $(MAKE) -f Makefile clean
cd SDL_net; $(MAKE) -f Makefile clean
cd SDL_ttf; $(MAKE) -f Makefile clean
cd smpeg; $(MAKE) -f Makefile clean
install:
cd SDL; $(MAKE) -f Makefile install
@ -18,3 +20,4 @@ install:
cd SDL_image; $(MAKE) -f Makefile install
cd SDL_net; $(MAKE) -f Makefile install
cd SDL_ttf; $(MAKE) -f Makefile install
cd smpeg; $(MAKE) -f Makefile install

142
smpeg/Makefile Normal file
View file

@ -0,0 +1,142 @@
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := libsmpeg
BUILD := obj
SOURCES := src src/video src/audio
DATA := data
INCLUDES := src -I$(LIBOGC_INC)/SDL
SRC_DIR := src
LIB_DIR := lib
INCLUDE_DIR := include
INSTALL_HEADER_DIR ?= $(LIBOGC_INC)
INSTALL_LIB_DIR ?= $(LIBOGC_LIB)
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -DDISABLE_VIDEO_CALLBACK_THREAD -DNOCONTROLS
CXXFLAGS = $(CFLAGS) -DDISABLE_VIDEO_CALLBACK_THREAD -DNOCONTROLS
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lSDL -lwiiuse -lbte -lfat -logc -lm
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBOGC_LIB)/SDL
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(LIB_DIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(filter-out $(dir)/glmovie.c $(dir)/glmovie-tile.c $(dir)/gtv.c $(dir)/plaympeg.c,$(wildcard $(dir)/*.c))))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
HEADERS := $(foreach dir,$(SOURCES),$(notdir $(filter-out $(dir)/glmovie.h $(dir)/gtv.h,$(wildcard $(dir)/*.h))))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
$(sFILES:.s=.o) $(SFILES:.S=.o)
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC) -I$(LIBOGC_INC)/SDL
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(LIB_DIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@-mkdir -p $(LIB_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
@-mkdir -p $(INCLUDE_DIR)
@cp $(wildcard $(SRC_DIR)/*.h) $(INCLUDE_DIR)
#---------------------------------------------------------------------------------
clean:
@rm -fr $(BUILD) $(OUTPUT).a
install:
@mkdir -p $(INSTALL_HEADER_DIR) $(INSTALL_LIB_DIR)
@mkdir -p $(INSTALL_HEADER_DIR)/mpeg
@cp -frv $(LIB_DIR)/*.* $(INSTALL_LIB_DIR)
@cp -frv include/*.* $(INSTALL_HEADER_DIR)/mpeg
#---------------------------------------------------------------------------------
run:
wiiload $(TARGET).dol
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
#$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).a: $(OFILES)
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

1
smpeg/src/BUGS Normal file
View file

@ -0,0 +1 @@
None known

389
smpeg/src/CHANGES Normal file
View file

@ -0,0 +1,389 @@
current:
Ryan C. Gordon - Sun Oct 29 02:16:02 EST 2006
* Patch from Chris Nelson to deal with SMPEG_error(NULL).
Ryan C. Gordon - Sat Mar 18 14:57:28 EST 2006
* Patch from Mike Frysinger to fix more asm stuff.
Sam Lantinga - Sun Mar 5 21:08:09 PST 2006
* Updated libtool build configuration
Ryan C. Gordon - Fri Dec 16 22:07:22 EST 2005
* gcc4 fixes (compliments of Gentoo Bugzilla #73579).
* gcc4.1 fixes, too. (compliments of Robert Marmorstein).
* Shortened filenames because "ar" apparently doesn't like them (thanks, LGP).
Ryan C. Gordon - Wed Oct 12 18:22:02 EDT 2005
* Patch from Jorge to allow graceful (and faster) exit of threads.
* Patch from Mike Frysinger to disable executable stack.
* Patch from Mike Frysinger to add sanity checks to autogen.sh
* Patch from Mike Frysinger for MMX/asm code fixes (PIC and TEXTREL stuff).
Ryan C. Gordon - Wed Aug 31 22:55:18 EDT 2005
* Disable executable stack in library (thanks, Mike Frysinger!)
Ryan C. Gordon - Wed Apr 27 11:15:01 EDT 2005
* automake fix in smpeg.m4 by Thomas Klausner.
Martin Köhler - Sun Mar 20 10:48:54 EST 2005
* PBProjects fix.
Steven Fuller - Mon Feb 9 23:26:08 CST 2004
* Added a --enable-video-callback-thread configure flag to disable thread
usage in smpeg.
Ryan C. Gordon - Fri Jan 2 22:50:11 EST 2004
* Added some sanity checks.
Ryan C. Gordon - Fri Jan 2 22:18:41 EST 2004
* Removed "Patches" file...it was screwing up my greps too much.
Ryan C. Gordon - Fri Jan 2 22:16:47 EST 2004
* SMPEG builds on Cygwin again.
Ryan C. Gordon - Wed Dec 31 00:07:51 EST 2003
* Check for SDL_CreateYUVOverlay() failure (happens for OpenGL surfaces).
Ryan C. Gordon - Tue Dec 30 23:37:07 EST 2003
* Check that SDL_BYTEORDER is sane (it wasn't, for SDL 1.2.5 on Linux/amd64).
Ryan C. Gordon - Fri Feb 14 21:02:00 EST 2003
* Memory leak fix that I missed from before (thanks, Pete Shinners).
Ryan C. Gordon - Sat Jan 25 19:20:58 EST 2003
* Memory leak fixes from NUNOKAWA Masato and Robert Diel.
Ryan C. Gordon - Wed Dec 18 16:47:52 EST 2002
* Apple Project Builder support by Eric Wing.
Ryan C. Gordon - Fri Dec 6 14:32:29 EST 2002
* Fixed for newer automakes.
Ryan C. Gordon - Wed Dec 4 18:00:33 EST 2002
* Now builds again when --enable-mmx is specified at configure time.
Ryan C. Gordon - Thu Sep 26 01:13:58 EDT 2002
* Minor Makefile.am patch for GCC 3.2
Ryan C. Gordon - Tue Jul 9 22:28:21 EDT 2002
* Removed #include <unistd.h> from glmovie.c
Ryan C. Gordon - Sun Jun 02 20:10:42 EST 2002
* ./autogen.sh accepts aclocal commandlines via the ACLOCAL_FLAGS envr var.
Ryan C. Gordon - Sun Jun 02 20:10:42 EST 2002
* ./autogen.sh is now flagged as executable in CVS.
Ryan C. Gordon - Sun Jun 02 20:10:42 EST 2002
* ./configure.in tweaked to not complain with newer autoconf.
Ryan C. Gordon - Sun Jun 02 20:10:42 EST 2002
* Newer ltconfig and hacks for libtool and .S files.
Adam Procter - Sat Jun 8 05:41:30 EDT 2002
* Fixed potential deadlock in MPEGaudio.cpp
Sam Lantinga - Sun Jun 9 00:24:10 EDT 2002
* Fix for crash when an MPEG file can't be opened.
0.4.5:
Sam Lantinga - Tue Jul 17 12:27:20 PDT 2001
* Skip MPEG audio frames with wildly varying frequencies
0.4.4:
Laurent Alacoque - Mon, 18 Jun 2001 15:51:51
* Fixed some hangs that occurred when seeking in MPEG files
Sam Lantinga - Fri Apr 27 15:54:30 PDT 2001
* Reworked the looping code - it should work better now
Sam Lantinga - Fri Apr 27 13:30:27 PDT 2001
* Fixed memory leak when sound was disabled
Sam Lantinga - Fri Apr 27 10:32:04 PDT 2001
* Widened initial search for audio streams in MPEG files
Sam Lantinga - Fri Apr 27 10:15:37 PDT 2001
* plaympeg now shows the name of the MPEG file in the caption
Sam Lantinga - Wed Apr 18 17:07:40 PDT 2001
* Added a check for the socklen_t type (thanks Michael Pruett)
Sam Lantinga - Mon Apr 16 14:20:07 PDT 2001
* Fixed crash with incorrectly encoded macroblock sequences
Mo DeJong - Mon Apr 16 12:26:04 PDT 2001
* Fixed crash when the MPEG file can't be opened
Joe Drew - Mon Apr 16 12:04:36 PDT 2001
* Fixed crash in gtv when seeking without a file loaded
0.4.3:
Sam Lantinga - Thu Apr 5 01:09:43 PDT 2001
* Updated for Simple DirectMedia Layer version 1.2.0
Sam Lantinga - Wed Apr 4 17:18:22 PDT 2001
* Fixed crash in gtv when doubling the video on Windows
Sam Lantinga - Wed Apr 4 17:18:14 PDT 2001
* Fixed audio stream detection in non-standard MPEG streams
Sam Lantinga - Wed Apr 4 16:42:53 PDT 2001
* Fixed hang on rewind when stream header contains no timestamp
Andreas Kloeckner - Wed Apr 4 14:43:49 PDT 2001
* SMPEG now uses the SDL_RWops file abstraction internally
Joe Drew - Wed Apr 4 13:40:44 PDT 2001
* Fixed bug where the audio was not updating the current time
Michel Darricau - Wed Apr 4 13:31:40 PDT 2001
* Added some changes for the popcorn MPEG library
Nicolas Vignal - Wed Apr 4 13:25:28 PDT 2001
* Added smpeg.m4
Sam Lantinga - Wed Feb 21 16:24:46 PST 2001
* SDL 1.2.0 supports 24 bpp displays, allow that in plaympeg
Sam Lantinga - Fri Feb 9 23:37:31 PST 2001
* Ported to MacOS X - one line fix. I love portable code! :)
It's still unusably slow, but it works! :)
Sam Lantinga - Thu Feb 8 17:33:15 PST 2001
* Fixed a hang playing invalid MPEG files
Matt Carlson - Fri Feb 2 18:13:08 PST 2001
* Fixed memory leak when used with OpenAL
Sam Lantinga - Mon Jan 8 07:49:20 PST 2001
* Return a non-zero status from plaympeg if playback fails
James Boucher - Mon Jan 8 06:53:31 PST 2001
* Changes to compile correctly on QNX RTP
Sam Lantinga - Thu Dec 21 10:52:28 PST 2000
* Fixed SMPEG_renderFinal() to a different display surface
Stephane Peter - Thu, 21 Dec 2000 02:07:07 -0800 (PST)
* Fixed plaympeg fullscreen toggling for multiple videos
Vivien Chappelier - Thu Dec 14 16:21:32 PST 2000
* Fixed MPEGSystem::TotalTime() hanging on small files
* Fixed system header decoding (caused misdetection of system streams)
* Added bilinear filter toggling with the 'f' key in plaympeg
Maxim Sobolev - Mon Dec 11 11:54:46 PST 2000
* Use the correct SDL configuration script on FreeBSD
0.4.2:
Sam Lantinga - Thu Dec 7 18:14:14 PST 2000
* Check for the GLU library when seeing if we can build the OpenGL example
Mo DeJong - Mon Dec 4 12:26:18 PST 2000
* Fixed crash when loading files of zero bytes
Sam Lantinga - Sat Dec 2 13:51:21 PST 2000
* Added --enable-threaded-system configure option (defaults off)
Sam Lantinga - Sat Dec 2 13:40:33 PST 2000
* Fixed end of stream detection
Sam Lantinga - Sat Dec 2 11:36:50 PST 2000
* Fixed crashes in gtv when trying to play MP3 files with no video
Sam Lantinga - Fri Dec 1 20:39:39 PST 2000
* Disabled the system thread by default.
You can re-enable it by looking for USE_SYSTEM_THREAD in MPEGsystem.cpp
Sam Lantinga - Fri Dec 1 18:07:50 PST 2000
* Fixed RenderFinal() to a different surface than the original one
Vivien Chappelier - Fri Nov 17 13:35:36 PST 2000
* Fixed seeking in MPEG files
Joe Valenzuela - Fri Nov 17 13:28:38 PST 2000
* Fixed crash in system data decoding
Bruce Merry - Fri Nov 10 09:49:59 PST 2000
* Removed movie size limitations from glmovie, works great!
Sam Lantinga - Fri Oct 27 15:11:33 PDT 2000
* Fixed hang when audio data was partially corrupt in the first block
Hiroshi Yamashita - Sat, 14 Oct 2000 23:43:33 +0900
* Fixed bug where audio was always mono
SiKang - Fri, 6 Oct 2000 15:23:13 +0900
* Fixed UDP port binding for raw:// MPEG support
Sam Lantinga - Thu Oct 5 14:07:35 PDT 2000
* Fixed spurious empty audio buffer at start of playback
Sam Lantinga - Thu Oct 5 12:58:43 PDT 2000
* SMPEG_playAudio() now returns the amount of audio data mixed
* SMPEG_playAudioSDL() wraps SMPEG_playAudio, as a callback hook for SDL.
Joe Valenzuela - Wed Oct 4 12:07:51 PDT 2000
* Added a configure option --disable-threaded-audio
Sam Lantinga - Wed Oct 4 10:12:58 PDT 2000
* Fixed various compiler warnings
Vivien Chappelier - Mon, 25 Sep 2000 20:37:43 +0200
* Added abstraction support for hardware acceleration (no card support yet)
Hiroshi Yamashita - Sat, 19 Aug 2000 00:22:25 +0900
* Fixed lseek problem on FreeBSD
0.4.1:
Vivien Chappelier - Sat Sep 23 17:48:59 PDT 2000
* Updated for SDL 1.1.5 and ATI hardware accelerated overlays
Richard Kim - Thu Sep 21 11:28:31 PDT 2000
* Fixed read buffer memory leak in MPEGsystem class
Tim Jansen - Thu Sep 21 11:13:06 PDT 2000
* Fixed potential stack corruption in MPEG level 3 audio decoding
Sam Lantinga - Wed Sep 6 03:04:12 PDT 2000
* Various Visual C++ cleanups, DirectX hardware acceleration with SDL
Sam Lantinga - Tue Sep 5 18:53:34 PDT 2000
* Added the --bilinear command line option to plaympeg for filtering
Tim Janson - Tue Sep 5 18:05:18 PDT 2000
* Fixed potential divide-by-zero with some illegal audio streams
Sam Lantinga - Tue Sep 5 14:09:14 PDT 2000
* Changed gtv to perform bilinear filtering instead of deblocking
Sam Lantinga - Tue Sep 5 13:39:36 PDT 2000
* Changed the filters to C implementations instead of C++ implementations
Vivien Chappelier - Tue Sep 5 12:09:10 PDT 2000
* Fixed crash with MPEG files containing audio frames in multiple layers
* Fixed crash when looping system streams
* Added video filter code
* Implemented a copy filter (default filter)
* Implemented a bilinear filter
* Implemented a subtle de-blocking filter
* Improved the motion detection code, crashes/hangs on fewer MPEG movies
Ray Kelm - Fri, 04 Aug 2000 20:58:00 -0400
* Added support for cross-compiling Windows DLL from Linux
Joe Valenzuela - Wed Aug 9 12:05:13 PDT 2000
* Added SMPEG_new_data() to play MPEG data already in memory
Vivien Chappelier - Sun Jul 23 13:48:33 2000
* Added the total time of an MPEG to the information structure
Vivien Chappelier - Sun Jul 23 13:48:33 2000
* Changed stream decoding to use more efficient condition variables
Kevin Squire - Thu Aug 3 18:23:01 PDT 2000
* Fixed a bug in the audio layer 2 decoding
Sam Lantinga - Thu Aug 3 17:56:09 PDT 2000
* Fixed FD_ZERO compile problem on some systems
Sam Lantinga - Thu Aug 3 17:51:35 PDT 2000
* Modified plaympeg to play videos even if audio device isn't available
Jens Vaasjo, Sam Lantinga, Nicholas Vining - Thu Aug 3 16:49:40 PDT 2000
* Modified glmovie to do fullscreen hardware accelerated display
David Hedbor - Wed Aug 2 14:08:20 PDT 2000
* Minor smpeg-config fixes for Solaris
Sam Lantinga - Wed Jun 21 14:58:24 PDT 2000
* The MMX idct code resulted in much less quality, so disabled by default
Sam Lantinga - Thu Jun 15 00:07:33 PDT 2000
* Added support for multiple tracks on a VCD disk
Vivien Chappelier - Wed Jun 14 12:43:54 PDT 2000
* Added VCD and URL support to plaympeg
0.4.0:
Vivien Chappelier - Fri Jun 9 14:20:16 PDT 2000
* Fixed rendering the final frame in a video stream
Hiroshi Yamashita - Thu Jun 8 12:03:42 PDT 2000
* Fixed frame counter and FPS calculation after seek
* Changed gtv so it actually changes the window size on doubling
Vivien Chappelier - Mon Jun 5 18:47:47 PDT 2000
* Fixed audio synchronization when seeking in an MPEG stream
Sam Lantinga - Sat Jun 3 20:13:42 PDT 2000
* Ported (easily) to BeOS
Sam Lantinga - Sat Jun 3 19:40:41 PDT 2000
* Added aggresive optimizations by default, use --enable-debug to disable
Mo DeJong - Sat Jun 3 19:37:00 PDT 2000
* Replaced target check for -lm with a simple library check
Sam Lantinga - Wed May 31 15:00:19 PDT 2000
* Various gtv improvements - centered video, audio on by default, etc.
Robert Dean - Wed May 31 10:13:02 PDT 2000
* Added drag-n-drop support to gtv (drag movies onto the control window)
Mo DeJong - Tue May 30 15:23:19 PDT 2000
* Fixed an audio deadlock when stopping playback
Markus Overhumer - Tue May 30 15:16:30 PDT 2000
* Some cleanups for compiling on Win32 with VC++
Vivien Chappelier - Fri May 26 10:53:44 PDT 2000
* Added a movable progress slidebar to gtv
Vivien, Manuel - Wed May 17 17:36:39 PDT 2000
* Added support for timestamp synchronization in the MPEG stream
Vivien, Damien - Mon May 8 11:06:08 PDT 2000
* Added support for seeking in the MPEG stream
Sam Lantinga - Fri Apr 28 15:57:25 PDT 2000
* Added support to plaympeg allowing the user to resize the window
Sam Lantinga - Fri Apr 28 14:22:14 PDT 2000
* Added ALT-ENTER fullscreen toggle to plaympeg
Sam Lantinga - Thu Apr 27 18:22:04 PDT 2000
* Added support for arbitrary output scaling:
new API function SMPEG_scaleXY()
* Added -scale wxh option to plaympeg
Sam Lantinga - Mon Apr 24 16:11:58 PDT 2000
* A much improved semaphore based ring buffer implementation
Sam Lantinga, Ryan Gordon - Mon Apr 24 14:12:59 PDT 2000
* plaympeg can now play files containing colons
Sam Lantinga - Tue Apr 18 17:12:16 PDT 2000
* Adjusted the audio startup timing based on experimentation
Hiroshi Yamashita - Tue Apr 18 15:48:14 PDT 2000
* Improved audio synchronization with longer movies (double rate_deal)
Sam Lantinga - Fri Apr 14 13:21:51 PDT 2000
* Added support for SDL asynchronous blitting
* Added support for FPS printing - see TIME_MPEG in video/MPEGvideo.cpp
Hiroshi Yamashita - Tue Apr 11 13:00:01 PDT 2000
* Tuned MPEG_BUFFER_SIZE for slower systems.
Atsushi Yamagata - Tue Apr 11 12:50:45 PDT 2000
* Added locale setting for gtv.
Hiroshi Yamashita - Tue Apr 11 09:59:11 PDT 2000
* Fixed audio popping and floating point exceptions in layer2 audio.
Sam Lantinga - Tue Apr 11 06:55:53 PDT 2000
* Ported to Win32.
Sam Lantinga - Sun Apr 9 16:42:47 PDT 2000
* Use SDL 1.1.3 for hardware accelerated YUV overlay support.
Vivien Chappelier - Thu Apr 6 12:40:36 PDT 2000
* Added MPEG streaming support - now plays many more MPEG streams.
0.3.5:
Sam Lantinga - Wed Apr 5 13:50:32 PDT 2000
* MMX code is disabled by default, as it appears to be slower than C code.
Sam Lantinga - Thu Mar 9 19:51:13 PST 2000
* Fixed a hang in MP3 playback if track plays all the way to the end.
Sam Lantinga - Wed Mar 8 11:01:16 PST 2000
* Added 16-bit MMX dither/IDCT code from the NIST MPEG-2/DVD player.
(http://home.germany.net/100-5083/)
* Added 32-bit MMX dither code from the kmpg MPEG-1 player.
(http://www.rhrk.uni-kl.de/~mvogt/linux/kmpg/)
Sam Lantinga - Wed Mar 8 07:25:33 PST 2000
* Added the math library to configure.in
Hiroshi Yamashita - Mon Mar 6 07:48:35 PST 2000
* Added audio information to the MPEG info.
* Added support for videos starting with Video Start Code 0xe0 0xe2.
* Added a fix for FreeBSD to ltmain.sh.
Sam Lantinga - Mon Mar 6 08:27:35 PST 2000
* Fixed a potential starting crash in plaympeg.
0.3.4:
Sam Lantinga - Fri Mar 3 13:40:43 PST 2000
* Split RPM into runtime and development packages.
* Added smpeg-config script to tell where the development runtime is installed.
Sam Lantinga - Fri Mar 3 13:25:10 PST 2000
* Fixed MP3 audio on big-endian systems.
Sam Lantinga - Wed Mar 1 07:02:17 PST 2000
* The control panel for the gtv player is placed in the upper left.
Sam Lantinga - Wed Mar 1 00:26:49 PST 2000
* If the audio couldn't be opened, the error is propogated to the user.
Sam Lantinga - Wed Mar 1 00:18:42 PST 2000
* The audio decoder thread now runs while the movie is paused.
Sam Lantinga - Tue Feb 29 15:22:52 PST 2000
* Added a hack to seek past raw video data in a system stream.
Sam Lantinga - Tue Feb 29 10:57:14 PST 2000
* Fixed pause and loop, with and without audio.
Sam Lantinga - Mon Feb 28 20:28:24 PST 2000
* Removed special SDL mixer support - not necessary. See README.SDL_mixer.
Sam Lantinga - Mon Feb 28 12:45:59 PST 2000
* Fixed a problem where audio stopped playing before the end of the movie.
Sam Lantinga - Thu Feb 10 13:17:29 PST 2000
* Don't crash if a picture block comes before a sequence header block.
Sam Lantinga - Sat Feb 5 08:56:25 PST 2000
* Remove autogenerated files from CVS.
Bill Kendrick - Thu Feb 03 16:57:27 PST 2000
* Does not init. audio or video unless necessary for the MPEG being played.
* If audio or video are unavailable, does not exit, just skips (or plays
whichever stream it can).
Bill Kendrick - Sat Jan 22 17:32:00 PST 2000
* Added --version to plaympeg and made usage help more complete.
Sam Lantinga - Mon Jan 24 12:57:54 PST 2000
* Disabled consistency checks by default, now plays more video streams
Laurent Bonnaud - Tue Jan 25 13:46:32 PST 2000
* Speeded up cropping by using an inline function
0.3.3:
Sam Lantinga - Mon Jan 17 19:52:32 PST 2000
* Updated for the new SDL mixer library release (1.0.3)
Sam Lantinga - Tue Jan 11 16:17:50 PST 2000
* Fixed so SMPEG compiles on stock RedHat 5.2 systems
Stephane Peter, Sam Lantinga - Thu Jan 10 15:22:33 PST 2000
* Fixed playing mono MP3 files on stereo audio output
Sam Lantinga - Thu Jan 6 13:02:32 PST 2000
* SMPEG now detects MP3 files again (broken by RIFF searching code)
* gtv is now included by default when building an RPM
Sam Lantinga - Mon Jan 3 20:54:32 PST 2000
* Changelog entries are now Y2K safe. ;-)
* SMPEG now handles pad packets in the initial system stream
Jim Studt - Mon Jan 3 20:57:52 PST 2000
* Fixed endian detection on unknown Linux systems (ARM)
Sam Lantinga - Mon Jan 3 21:09:01 PST 2000
* plaympeg now hides the mouse cursor in fullscreen mode
0.3.2:
SOL - Updated autoconf for SDL 1.0
SOL - Fixed audio decoding thread - releases waiting audio threads
SOL - Fixed audio playback of MPEG videos when using external mixer
KVC - Handle RIFF encoded MPEG streams
SOL - Handle system streams that encode packets without a header
Stefan Gybas - Contributed a man page for gtv.
0.3.1:
SOL - Fixed endlessly looping "mpegVidRsrc ParseMacroBlock" problem
SOL - Changed parseblock assertion so it doesn't halt playback
SOL - Fixed crashing bug in ParseReconBlock() with corrupt videos
SOL - Fixed audio synchronization problem with looping movies
0.3.0:
SOL - Added audio synchronization support.
SOL - Added autoconf support.
MKV - Added GTk mpeg player.
MKV - Added OpenGL mpeg player.
SP - Exported the audio mixing function for flexible audio setup.
Mo DeJong - plaympeg now prints out usage if given no arguments.
Stefan Gybas - Contributed a man page for plaympeg.
0.2.7:
SOL - Added volume change API
0.2.6:
SOL - Fixed possible crash when starting audio playback.
SOL - Fixed SMPEG on PPC - may still be buggy, but plays most MPEGs.
0.2.5:
SOL - Added --fullscreen command line option to plaympeg.
SOL - Added 32-bpp support, fixed fullscreen offset bug.
Initial Key:
SOL - Sam Lantinga (hercules@lokigames.com)
MKV - Michael Vance (briareos@lokigames.com)
SP - Stephane Peter (megastep@lokigames.com)

481
smpeg/src/COPYING Normal file
View file

@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

508
smpeg/src/MPEG.cpp Normal file
View file

@ -0,0 +1,508 @@
#include "SDL.h"
#include "MPEG.h"
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
MPEG::MPEG(const char * name, bool SDLaudio) :
MPEGerror()
{
SDL_RWops *source;
mpeg_mem = 0;
source = SDL_RWFromFile(name, "rb");
if (!source) {
InitErrorState();
SetError(SDL_GetError());
return;
}
Init(source, SDLaudio);
}
MPEG::MPEG(int Mpeg_FD, bool SDLaudio) :
MPEGerror()
{
SDL_RWops *source;
mpeg_mem = 0;
// *** FIXME we're leaking a bit of memory for the FILE *
// best solution would be to have SDL_RWFromFD
FILE *file = fdopen(Mpeg_FD, "rb");
if (!file) {
InitErrorState();
SetError(strerror(errno));
return;
}
source = SDL_RWFromFP(file,(SDL_bool) false);
if (!source) {
InitErrorState();
SetError(SDL_GetError());
return;
}
Init(source, SDLaudio);
}
MPEG::MPEG(void *data, int size, bool SDLaudio) :
MPEGerror()
{
SDL_RWops *source;
// The semantics are that the data passed in should be copied
// (?)
mpeg_mem = new char[size];
memcpy(mpeg_mem, data, size);
source = SDL_RWFromMem(mpeg_mem, size);
if (!source) {
InitErrorState();
SetError(SDL_GetError());
return;
}
Init(source, SDLaudio);
}
MPEG::MPEG(SDL_RWops *mpeg_source, bool SDLaudio) :
MPEGerror()
{
mpeg_mem = 0;
Init(mpeg_source, SDLaudio);
}
void MPEG::Init(SDL_RWops *mpeg_source, bool SDLaudio)
{
source = mpeg_source;
sdlaudio = SDLaudio;
/* Create the system that will parse the MPEG stream */
system = new MPEGsystem(source);
/* Initialize everything to invalid values for cleanup */
error = NULL;
audiostream = videostream = NULL;
audioaction = NULL;
videoaction = NULL;
audio = NULL;
video = NULL;
audioaction_enabled = SDLaudio;
videoaction_enabled = false;
loop = false;
pause = false;
parse_stream_list();
EnableAudio(audioaction_enabled);
EnableVideo(videoaction_enabled);
if ( ! audiostream && ! videostream ) {
SetError("No audio/video stream found in MPEG");
}
if ( system && system->WasError() ) {
SetError(system->TheError());
}
if ( audio && audio->WasError() ) {
SetError(audio->TheError());
}
if ( video && video->WasError() ) {
SetError(video->TheError());
}
if ( WasError() ) {
SetError(TheError());
}
}
void MPEG::InitErrorState() {
audio = NULL;
video = NULL;
system = NULL;
error = NULL;
source = NULL;
audiostream = videostream = NULL;
audioaction = NULL;
videoaction = NULL;
audio = NULL;
video = NULL;
audioaction_enabled = videoaction_enabled = false;
loop = false;
pause = false;
}
MPEG::~MPEG()
{
Stop();
if(video) delete video;
if(audio) delete audio;
if(system) delete system;
if(source) SDL_RWclose(source);
if ( mpeg_mem )
delete[] mpeg_mem;
}
bool MPEG::AudioEnabled(void) {
return(audioaction_enabled);
}
void MPEG::EnableAudio(bool enabled) {
if ( enabled && ! audioaction ) {
enabled = false;
}
audioaction_enabled = enabled;
/* Stop currently playing stream, if necessary */
if ( audioaction && ! audioaction_enabled ) {
audioaction->Stop();
}
/* Set the video time source */
if ( videoaction ) {
if ( audioaction_enabled ) {
videoaction->SetTimeSource(audioaction);
} else {
videoaction->SetTimeSource(NULL);
}
}
if(audiostream)
audiostream->enable(enabled);
}
bool MPEG::VideoEnabled(void) {
return(videoaction_enabled);
}
void MPEG::EnableVideo(bool enabled) {
if ( enabled && ! videoaction ) {
enabled = false;
}
videoaction_enabled = enabled;
/* Stop currently playing stream, if necessary */
if ( videoaction && ! videoaction_enabled ) {
videoaction->Stop();
}
if(videostream)
videostream->enable(enabled);
}
/* MPEG actions */
void MPEG::Loop(bool toggle) {
loop = toggle;
}
void MPEG::Play(void) {
if ( AudioEnabled() ) {
audioaction->Play();
}
if ( VideoEnabled() ) {
videoaction->Play();
}
}
void MPEG::Stop(void) {
if ( VideoEnabled() ) {
videoaction->Stop();
}
if ( AudioEnabled() ) {
audioaction->Stop();
}
}
void MPEG::Rewind(void) {
seekIntoStream(0);
}
void MPEG::Pause(void) {
pause = !pause;
if ( VideoEnabled() ) {
videoaction->Pause();
}
if ( AudioEnabled() ) {
audioaction->Pause();
}
}
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
MPEGstatus MPEG::GetStatus(void) {
MPEGstatus status;
status = MPEG_STOPPED;
if ( VideoEnabled() ) {
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
switch (videoaction->GetStatus()) {
case MPEG_PLAYING:
status = MPEG_PLAYING;
break;
default:
break;
}
}
if ( AudioEnabled() ) {
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
switch (audioaction->GetStatus()) {
case MPEG_PLAYING:
status = MPEG_PLAYING;
break;
default:
break;
}
}
if(status == MPEG_STOPPED && loop && !pause)
{
/* Here we go again */
Rewind();
Play();
if ( VideoEnabled() ) {
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
switch (videoaction->GetStatus()) {
case MPEG_PLAYING:
status = MPEG_PLAYING;
break;
default:
break;
}
}
if ( AudioEnabled() ) {
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
switch (audioaction->GetStatus()) {
case MPEG_PLAYING:
status = MPEG_PLAYING;
break;
default:
break;
}
}
}
return(status);
}
/* MPEG audio actions */
bool MPEG::GetAudioInfo(MPEG_AudioInfo *info) {
if ( AudioEnabled() ) {
return(audioaction->GetAudioInfo(info));
}
return(false);
}
void MPEG::Volume(int vol) {
if ( AudioEnabled() ) {
audioaction->Volume(vol);
}
}
bool MPEG::WantedSpec(SDL_AudioSpec *wanted) {
if( audiostream ) {
return(GetAudio()->WantedSpec(wanted));
}
return(false);
}
void MPEG::ActualSpec(const SDL_AudioSpec *actual) {
if( audiostream ) {
GetAudio()->ActualSpec(actual);
}
}
MPEGaudio *MPEG::GetAudio(void) { // Simple accessor used in the C interface
return audio;
}
/* MPEG video actions */
bool MPEG::GetVideoInfo(MPEG_VideoInfo *info) {
if ( VideoEnabled() ) {
return(videoaction->GetVideoInfo(info));
}
return(false);
}
bool MPEG::SetDisplay(SDL_Surface *dst, SDL_mutex *lock,
MPEG_DisplayCallback callback) {
if ( VideoEnabled() ) {
return(videoaction->SetDisplay(dst, lock, callback));
}
return(false);
}
void MPEG::MoveDisplay(int x, int y) {
if ( VideoEnabled() ) {
videoaction->MoveDisplay(x, y);
}
}
void MPEG::ScaleDisplayXY(int w, int h) {
if ( VideoEnabled() ) {
videoaction->ScaleDisplayXY(w, h);
}
}
void MPEG::SetDisplayRegion(int x, int y, int w, int h) {
if ( VideoEnabled() ) {
videoaction->SetDisplayRegion(x, y, w, h);
}
}
void MPEG::RenderFrame(int frame)
{
if ( VideoEnabled() ) {
videoaction->RenderFrame(frame);
}
}
void MPEG::RenderFinal(SDL_Surface *dst, int x, int y)
{
Stop();
if ( VideoEnabled() ) {
videoaction->RenderFinal(dst, x, y);
}
Rewind();
}
SMPEG_Filter * MPEG::Filter(SMPEG_Filter * filter)
{
if ( VideoEnabled() ) {
return(videoaction->Filter(filter));
}
return 0;
}
void MPEG::Seek(int position)
{
int was_playing = 0;
/* Cannot seek past end of file */
if((Uint32)position > system->TotalSize()) return;
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name with popcorn */
/* get info whrether we need to restart playing at the end */
if( GetStatus() == MPEG_PLAYING )
was_playing = 1;
if(!seekIntoStream(position)) return;
/* If we were playing and not rewind then play again */
if (was_playing)
Play();
if (VideoEnabled() && !was_playing)
videoaction->RenderFrame(0);
if ( pause && VideoEnabled() ) {
videoaction->Pause();
}
if ( pause && AudioEnabled() ) {
audioaction->Pause();
}
}
bool MPEG::seekIntoStream(int position)
{
/* First we stop everything */
Stop();
/* Go to the desired position into file */
if(!system->Seek(position)) return(false);
/* Seek first aligned data */
if(audiostream && audioaction_enabled)
while(audiostream->time() == -1)
if ( ! audiostream->next_packet() ) return false;
if(videostream && videoaction_enabled)
while(videostream->time() == -1)
if ( ! videostream->next_packet() ) return false;
/* Calculating current play time on audio only makes sense when there
is no video */
if ( audioaction && !videoaction) {
audioaction->Rewind();
audioaction->ResetSynchro(system->TimeElapsedAudio(position));
}
/* And forget what we previouly buffered */
else if ( audioaction ) {
audioaction->Rewind();
audioaction->ResetSynchro(audiostream->time());
}
if ( videoaction ) {
videoaction->Rewind();
videoaction->ResetSynchro(videostream->time());
}
return(true);
}
void MPEG::Skip(float seconds)
{
if(system->get_stream(SYSTEM_STREAMID))
{
system->Skip(seconds);
}
else
{
/* No system information in MPEG */
if( VideoEnabled() ) videoaction->Skip(seconds);
if( AudioEnabled() ) audioaction->Skip(seconds);
}
}
void MPEG::GetSystemInfo(MPEG_SystemInfo * sinfo)
{
sinfo->total_size = system->TotalSize();
sinfo->current_offset = system->Tell();
sinfo->total_time = system->TotalTime();
/* Get current time from audio or video decoder */
/* TODO: move timing reference in MPEGsystem */
sinfo->current_time = 0;
if( videoaction )
sinfo->current_time = videoaction->Time();
if( audioaction )
sinfo->current_time = audioaction->Time();
}
void MPEG::parse_stream_list()
{
MPEGstream ** stream_list;
register int i;
/* A new thread is created for each video and audio */
/* stream */
/* TODO: support MPEG systems containing more than */
/* one audio or video stream */
i = 0;
do
{
/* Retreive the list of streams */
stream_list = system->GetStreamList();
switch(stream_list[i]->streamid)
{
case SYSTEM_STREAMID:
break;
case AUDIO_STREAMID:
audiostream = stream_list[i];
audioaction_enabled = true;
audiostream->next_packet();
audio = new MPEGaudio(audiostream, sdlaudio);
audioaction = audio;
break;
case VIDEO_STREAMID:
videostream = stream_list[i];
videoaction_enabled = true;
videostream->next_packet();
video = new MPEGvideo(videostream);
videoaction = video;
break;
}
i++;
}
while(stream_list[i]);
}

135
smpeg/src/MPEG.h Normal file
View file

@ -0,0 +1,135 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
- Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn -
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A class used to parse and play MPEG streams */
#ifndef _MPEG_H_
#define _MPEG_H_
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "MPEGerror.h"
#include "MPEGstream.h"
#include "MPEGaction.h"
#include "MPEGaudio.h"
#include "MPEGvideo.h"
#include "MPEGsystem.h"
#include "MPEGfilter.h"
#define LENGTH_TO_CHECK_FOR_SYSTEM 0x50000 // Added by HanishKVC
/* The main MPEG class - parses system streams and creates other streams
A few design notes:
Making this derived from MPEGstream allows us to do system stream
parsing. We create an additional MPEG object for each type of
stream in the MPEG file because each needs a separate pointer to
the MPEG data. The MPEG stream then creates an accessor object to
do all the data parsing for that stream type. It's a little odd,
but seemed like the best way to implement stream parsing.
*/
class MPEG : public MPEGerror
{
public:
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
MPEG():MPEGerror(){}
MPEG(bool Sdlaudio, char *addresse,char *asset,long buffersize){}
MPEG(const char * name, bool SDLaudio = true);
MPEG(int Mpeg_FD, bool SDLaudio = true);
MPEG(void *data, int size, bool SDLaudio = true);
MPEG(SDL_RWops *mpeg_source,bool SDLaudio = true);
virtual ~MPEG();
/* Initialize the MPEG */
void Init(SDL_RWops *mpeg_source, bool SDLaudio);
void InitErrorState();
/* Enable/Disable audio and video */
bool AudioEnabled(void);
void EnableAudio(bool enabled);
bool VideoEnabled(void);
void EnableVideo(bool enabled);
/* MPEG actions */
void Loop(bool toggle);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
virtual void Play(void);
void Stop(void);
void Rewind(void);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
virtual void Pause(void);
virtual void Seek(int bytes);
void Skip(float seconds);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
MPEGstatus GetStatus(void);
void GetSystemInfo(MPEG_SystemInfo *info);
/* MPEG audio actions */
bool GetAudioInfo(MPEG_AudioInfo *info);
void Volume(int vol);
bool WantedSpec(SDL_AudioSpec *wanted);
void ActualSpec(const SDL_AudioSpec *actual);
MPEGaudio *GetAudio(void);
/* MPEG video actions */
bool GetVideoInfo(MPEG_VideoInfo *info);
bool SetDisplay(SDL_Surface *dst, SDL_mutex *lock,
MPEG_DisplayCallback callback);
void MoveDisplay(int x, int y);
void ScaleDisplayXY(int w, int h);
void SetDisplayRegion(int x, int y, int w, int h);
void RenderFrame(int frame);
void RenderFinal(SDL_Surface *dst, int x, int y);
SMPEG_Filter * Filter(SMPEG_Filter * filter);
public:
/* We need to have separate audio and video streams */
MPEGstream * audiostream;
MPEGstream * videostream;
MPEGsystem * system;
protected:
char *mpeg_mem; // Used to copy MPEG passed in as memory
SDL_RWops *source;
MPEGaudioaction *audioaction;
MPEGvideoaction *videoaction;
MPEGaudio *audio;
MPEGvideo *video;
bool audioaction_enabled;
bool videoaction_enabled;
bool sdlaudio;
bool loop;
bool pause;
void parse_stream_list();
bool seekIntoStream(int position);
};
#endif /* _MPEG_H_ */

141
smpeg/src/MPEGaction.h Normal file
View file

@ -0,0 +1,141 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
- Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn -
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A virtual class to provide basic MPEG playback actions */
#ifndef _MPEGACTION_H_
#define _MPEGACTION_H_
#include "SDL.h"
#include "MPEGfilter.h"
typedef enum {
MPEG_ERROR = -1,
MPEG_STOPPED,
MPEG_PLAYING
} MPEGstatus;
class MPEGaction {
public:
MPEGaction() {
playing = false;
paused = false;
looping = false;
play_time = 0.0;
}
virtual void Loop(bool toggle) {
looping = toggle;
}
virtual double Time(void) { /* Returns the time in seconds since start */
return play_time;
}
virtual void Play(void) = 0;
virtual void Stop(void) = 0;
virtual void Rewind(void) = 0;
virtual void ResetSynchro(double) = 0;
virtual void Skip(float seconds) = 0;
virtual void Pause(void) { /* A toggle action */
if ( paused ) {
paused = false;
Play();
} else {
Stop();
paused = true;
}
}
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name in popcorn */
virtual MPEGstatus GetStatus(void) = 0;
protected:
bool playing;
bool paused;
bool looping;
double play_time;
bool force_exit;
void ResetPause(void) {
paused = false;
}
};
/* For getting info about the audio portion of the stream */
typedef struct MPEG_AudioInfo {
int mpegversion;
int mode;
int frequency;
int layer;
int bitrate;
int current_frame;
} MPEG_AudioInfo;
/* Audio action class */
class MPEGaudioaction : public MPEGaction {
public:
virtual bool GetAudioInfo(MPEG_AudioInfo *info) {
return(true);
}
virtual void Volume(int vol) = 0;
};
/* Matches the declaration of SDL_UpdateRect() */
typedef void(*MPEG_DisplayCallback)(SDL_Surface* dst, int x, int y,
unsigned int w, unsigned int h);
/* For getting info about the video portion of the stream */
typedef struct MPEG_VideoInfo {
int width;
int height;
int current_frame;
double current_fps;
} MPEG_VideoInfo;
/* Video action class */
class MPEGvideoaction : public MPEGaction {
public:
virtual void SetTimeSource(MPEGaudioaction *source) {
time_source = source;
}
virtual bool GetVideoInfo(MPEG_VideoInfo *info) {
return(false);
}
virtual bool SetDisplay(SDL_Surface *dst, SDL_mutex *lock,
MPEG_DisplayCallback callback) = 0;
virtual void MoveDisplay(int x, int y) = 0;
virtual void ScaleDisplayXY(int w, int h) = 0;
virtual void SetDisplayRegion(int x, int y, int w, int h) = 0;
virtual void RenderFrame(int frame) = 0;
virtual void RenderFinal(SDL_Surface *dst, int x, int y) = 0;
virtual SMPEG_Filter * Filter(SMPEG_Filter * filter) = 0;
protected:
MPEGaudioaction *time_source;
};
/* For getting info about the system portion of the stream */
typedef struct MPEG_SystemInfo {
int total_size;
int current_offset;
double total_time;
double current_time;
} MPEG_SystemInfo;
#endif /* _MPEGACTION_H_ */

385
smpeg/src/MPEGaudio.h Normal file
View file

@ -0,0 +1,385 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
- Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn -
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A class based on the MPEG stream class, used to parse and play audio */
#ifndef _MPEGAUDIO_H_
#define _MPEGAUDIO_H_
#include "SDL.h"
#include "MPEGerror.h"
#include "MPEGaction.h"
#ifdef THREADED_AUDIO
#include "MPEGring.h"
#endif
void Play_MPEGaudioSDL(void *udata, Uint8 *stream, int len);
#ifdef THREADED_AUDIO
int Decode_MPEGaudio(void *udata);
#endif
class MPEGstream;
/* MPEG/WAVE Sound library
(C) 1997 by Woo-jae Jung */
/**************************/
/* Define values for MPEG */
/**************************/
#define SCALEBLOCK 12
#define CALCBUFFERSIZE 512
#define MAXSUBBAND 32
#define MAXCHANNEL 2
#define MAXTABLE 2
#define SCALE 32768
#define MAXSCALE (SCALE-1)
#define MINSCALE (-SCALE)
#define RAWDATASIZE (2*2*32*SSLIMIT)
#define LS 0
#define RS 1
#define SSLIMIT 18
#define SBLIMIT 32
#define WINDOWSIZE 4096
// Huffmancode
#define HTN 34
/********************/
/* Type definitions */
/********************/
typedef float REAL;
typedef struct
{
bool generalflag;
unsigned int part2_3_length;
unsigned int big_values;
unsigned int global_gain;
unsigned int scalefac_compress;
unsigned int window_switching_flag;
unsigned int block_type;
unsigned int mixed_block_flag;
unsigned int table_select[3];
unsigned int subblock_gain[3];
unsigned int region0_count;
unsigned int region1_count;
unsigned int preflag;
unsigned int scalefac_scale;
unsigned int count1table_select;
}layer3grinfo;
typedef struct
{
unsigned main_data_begin;
unsigned private_bits;
struct
{
unsigned scfsi[4];
layer3grinfo gr[2];
}ch[2];
}layer3sideinfo;
typedef struct
{
int l[23]; /* [cb] */
int s[3][13]; /* [window][cb] */
}layer3scalefactor; /* [ch] */
typedef struct
{
int tablename;
unsigned int xlen,ylen;
unsigned int linbits;
unsigned int treelen;
const unsigned int (*val)[2];
}HUFFMANCODETABLE;
// Class for Mpeg layer3
class Mpegbitwindow
{
public:
Mpegbitwindow(){bitindex=point=0;};
void initialize(void) {bitindex=point=0;};
int gettotalbit(void) const {return bitindex;};
void putbyte(int c) {buffer[point&(WINDOWSIZE-1)]=c;point++;};
void wrap(void);
void rewind(int bits) {bitindex-=bits;};
void forward(int bits) {bitindex+=bits;};
int getbit(void) {
register int r=(buffer[bitindex>>3]>>(7-(bitindex&7)))&1;
bitindex++;
return r;
}
int getbits9(int bits)
{
register unsigned short a;
{ int offset=bitindex>>3;
a=(((unsigned char)buffer[offset])<<8) | ((unsigned char)buffer[offset+1]);
}
a<<=(bitindex&7);
bitindex+=bits;
return (int)((unsigned int)(a>>(16-bits)));
}
int getbits(int bits);
private:
int point,bitindex;
char buffer[2*WINDOWSIZE];
};
/* The actual MPEG audio class */
class MPEGaudio : public MPEGerror, public MPEGaudioaction {
public:
MPEGaudio(MPEGstream *stream, bool initSDL = true);
virtual ~MPEGaudio();
/* MPEG actions */
bool GetAudioInfo(MPEG_AudioInfo *info);
double Time(void);
void Play(void);
void Stop(void);
void Rewind(void);
void ResetSynchro(double time);
void Skip(float seconds);
void Volume(int vol);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name in popcorn */
MPEGstatus GetStatus(void);
/* Returns the desired SDL audio spec for this stream */
bool WantedSpec(SDL_AudioSpec *wanted);
/* Inform SMPEG of the actual audio format if configuring SDL
outside of this class */
void ActualSpec(const SDL_AudioSpec *actual);
protected:
bool sdl_audio;
MPEGstream *mpeg;
int valid_stream;
bool stereo;
double rate_in_s;
Uint32 frags_playing;
Uint32 frag_time;
#ifdef THREADED_AUDIO
bool decoding;
SDL_Thread *decode_thread;
void StartDecoding(void);
void StopDecoding(void);
#endif
/* Code from splay 1.8.2 */
/*****************************/
/* Constant tables for layer */
/*****************************/
private:
static const int bitrate[2][3][15],frequencies[2][3];
static const REAL scalefactorstable[64];
static const HUFFMANCODETABLE ht[HTN];
static const REAL filter[512];
static REAL hcos_64[16],hcos_32[8],hcos_16[4],hcos_8[2],hcos_4;
/*************************/
/* MPEG header variables */
/*************************/
private:
int last_speed;
int layer,protection,bitrateindex,padding,extendedmode;
enum _mpegversion {mpeg1,mpeg2} version;
enum _mode {fullstereo,joint,dual,single} mode;
enum _frequency {frequency44100,frequency48000,frequency32000} frequency;
/***************************************/
/* Interface for setting music quality */
/***************************************/
private:
bool forcetomonoflag;
bool forcetostereoflag;
bool swapendianflag;
int downfrequency;
public:
void setforcetomono(bool flag);
void setdownfrequency(int value);
/******************************/
/* Frame management variables */
/******************************/
private:
int decodedframe,currentframe,totalframe;
/***************************************/
/* Variables made by MPEG-Audio header */
/***************************************/
private:
int tableindex,channelbitrate;
int stereobound,subbandnumber,inputstereo,outputstereo;
REAL scalefactor;
int framesize;
/*******************/
/* Mpegtoraw class */
/*******************/
public:
void initialize();
bool run(int frames, double *timestamp = NULL);
void clearbuffer(void);
/*****************************/
/* Loading MPEG-Audio stream */
/*****************************/
private:
Uint8 _buffer[4096];
Uint32 _buffer_pos;
int bitindex;
bool fillbuffer(int size);
void sync(void);
bool issync(void);
int getbyte(void);
int getbit(void);
int getbits8(void);
int getbits9(int bits);
int getbits(int bits);
/********************/
/* Global variables */
/********************/
private:
int lastfrequency,laststereo;
// for Layer3
int layer3slots,layer3framestart,layer3part2start;
REAL prevblck[2][2][SBLIMIT][SSLIMIT];
int currentprevblock;
layer3sideinfo sideinfo;
layer3scalefactor scalefactors[2];
Mpegbitwindow bitwindow;
int wgetbit (void) {return bitwindow.getbit (); }
int wgetbits9(int bits){return bitwindow.getbits9(bits);}
int wgetbits (int bits){return bitwindow.getbits (bits);}
/*************************************/
/* Decoding functions for each layer */
/*************************************/
private:
bool loadheader(void);
//
// Subbandsynthesis
//
REAL calcbufferL[2][CALCBUFFERSIZE],calcbufferR[2][CALCBUFFERSIZE];
int currentcalcbuffer,calcbufferoffset;
void computebuffer(REAL *fraction,REAL buffer[2][CALCBUFFERSIZE]);
void generatesingle(void);
void generate(void);
void subbandsynthesis(REAL *fractionL,REAL *fractionR);
void computebuffer_2(REAL *fraction,REAL buffer[2][CALCBUFFERSIZE]);
void generatesingle_2(void);
void generate_2(void);
void subbandsynthesis_2(REAL *fractionL,REAL *fractionR);
// Extarctor
void extractlayer1(void); // MPEG-1
void extractlayer2(void);
void extractlayer3(void);
void extractlayer3_2(void); // MPEG-2
// Functions for layer 3
void layer3initialize(void);
bool layer3getsideinfo(void);
bool layer3getsideinfo_2(void);
void layer3getscalefactors(int ch,int gr);
void layer3getscalefactors_2(int ch);
void layer3huffmandecode(int ch,int gr,int out[SBLIMIT][SSLIMIT]);
REAL layer3twopow2(int scale,int preflag,int pretab_offset,int l);
REAL layer3twopow2_1(int a,int b,int c);
void layer3dequantizesample(int ch,int gr,int in[SBLIMIT][SSLIMIT],
REAL out[SBLIMIT][SSLIMIT]);
void layer3fixtostereo(int gr,REAL in[2][SBLIMIT][SSLIMIT]);
void layer3reorderandantialias(int ch,int gr,REAL in[SBLIMIT][SSLIMIT],
REAL out[SBLIMIT][SSLIMIT]);
void layer3hybrid(int ch,int gr,REAL in[SBLIMIT][SSLIMIT],
REAL out[SSLIMIT][SBLIMIT]);
void huffmandecoder_1(const HUFFMANCODETABLE *h,int *x,int *y);
void huffmandecoder_2(const HUFFMANCODETABLE *h,int *x,int *y,int *v,int *w);
/********************/
/* Playing raw data */
/********************/
private:
int samplesperframe;
int rawdatareadoffset, rawdatawriteoffset;
Sint16 *rawdata;
#ifdef THREADED_AUDIO
MPEG_ring *ring;
#else
Sint16 spillover[ RAWDATASIZE ];
#endif
int volume;
void clearrawdata(void) {
rawdatareadoffset=0;
rawdatawriteoffset=0;
rawdata=NULL;
}
void putraw(short int pcm) {rawdata[rawdatawriteoffset++]=pcm;}
/********************/
/* Timestamp sync */
/********************/
public:
#define N_TIMESTAMPS 5
double timestamp[N_TIMESTAMPS];
/* Functions which access MPEGaudio internals */
friend void Play_MPEGaudioSDL(void *udata, Uint8 *stream, int len);
friend int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len);
#ifdef THREADED_AUDIO
friend int Decode_MPEGaudio(void *udata);
#endif
};
/* Need to duplicate the prototypes, this is not a typo :) */
void Play_MPEGaudioSDL(void *udata, Uint8 *stream, int len);
int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len);
#ifdef THREADED_AUDIO
int Decode_MPEGaudio(void *udata);
#endif
#endif /* _MPEGAUDIO_H_ */

62
smpeg/src/MPEGerror.h Normal file
View file

@ -0,0 +1,62 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A class used for error reporting in the MPEG classes */
#ifndef _MPEGERROR_H_
#define _MPEGERROR_H_
#include <stdio.h>
#include <stdarg.h>
class MPEGerror {
public:
MPEGerror() {
ClearError();
}
/* Set an error message */
void SetError(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsprintf(errbuf, fmt, ap);
va_end(ap);
error = errbuf;
}
/* Find out if an error occurred */
bool WasError(void) {
return(error != NULL);
}
char *TheError(void) {
return(error);
}
/* Clear any error message */
void ClearError(void) {
error = NULL;
}
protected:
char errbuf[512];
char *error;
};
#endif /* _MPEGERROR_H_ */

381
smpeg/src/MPEGfilter.c Normal file
View file

@ -0,0 +1,381 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "MPEGfilter.h"
/* General filter cleanup function */
static void filter_destroy(SMPEG_Filter *filter)
{
if ( filter ) {
if ( filter->data ) {
free(filter->data);
}
free(filter);
}
}
/**************************************************/
/* The null filter. Copies source rect to overlay */
/**************************************************/
static void filter_null_callback(SDL_Overlay * dst, SDL_Overlay * src, SDL_Rect * region, SMPEG_FilterInfo * info, void * data)
{
register Uint32 y;
register Uint8 * s, * d;
/* Y component */
s = src->pixels[0];
d = dst->pixels[0];
/* Go to the top left corner of the source rectangle */
s += region->y * src->pitches[0] + region->x;
for(y = 0; y < region->h; y++)
{
/* Copy lines */
memcpy(d, s, region->w);
s += src->pitches[0];
d += dst->pitches[0];
}
/* V component */
s = src->pixels[1];
d = dst->pixels[1];
s += (region->y >> 1) * src->pitches[1] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[1];
d += dst->pitches[1];
}
/* U component */
s = src->pixels[2];
d = dst->pixels[2];
s += (region->y >> 1) * src->pitches[2] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[2];
d += dst->pitches[2];
}
}
SMPEG_Filter *SMPEGfilter_null(void)
{
SMPEG_Filter *filter;
filter = (SMPEG_Filter *)malloc(sizeof(*filter));
if ( filter ) {
/* the null filter requires no extra info */
filter->flags = 0;
/* no private data */
filter->data = 0;
/* set the function pointers to the callback and destroy functions */
filter->callback = filter_null_callback;
filter->destroy = filter_destroy;
}
return filter;
}
/************************************************************************************/
/* The bilinear filter. A basic low-pass filter that will produce a smoother image. */
/* It uses the following convolution matrix: [0 1 0] */
/* [1 4 1] */
/* [0 1 0] */
/************************************************************************************/
static void filter_bilinear_callback(SDL_Overlay * dst, SDL_Overlay * src, SDL_Rect * region, SMPEG_FilterInfo * info, void * data)
{
register int x, y;
register Uint8 * s, * d;
s = src->pixels[0];
d = dst->pixels[0];
s += region->y * src->pitches[0] + region->x;
/* Skip first line */
memcpy(d, s, region->w);
d += dst->pitches[0];
s += src->pitches[0];
for(y = 1; y < region->h - 1; y++)
{
/* Skip first pixel */
*d++ = *s++;
for(x = 1; x < region->w - 1; x++)
{
*d++ =
(((*s) << 2) + // 4*(x,y) +
*(s - src->pitches[0]) + // (x,y-1) +
*(s - 1) + // (x-1,y) +
*(s + 1) + // (x+1,y) +
*(s + src->pitches[0])) // (x,y+1)
>> 3; // / 8
s++;
}
/* Skip last pixel */
*d++ = *s++;
/* Go to next line */
d += dst->pitches[0] - region->w;
s += src->pitches[0] - region->w;
}
/* Skip last line */
memcpy(d, s, region->w);
d += dst->pitches[0];
s += src->pitches[0];
/* V component (unfiltered) */
s = src->pixels[1];
d = dst->pixels[1];
s += (region->y >> 1) * src->pitches[1] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[1];
d += dst->pitches[1];
}
/* U component (unfiltered) */
s = src->pixels[2];
d = dst->pixels[2];
s += (region->y >> 1) * src->pitches[2] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[2];
d += dst->pitches[2];
}
}
SMPEG_Filter *SMPEGfilter_bilinear(void)
{
SMPEG_Filter *filter;
filter = (SMPEG_Filter *)malloc(sizeof(*filter));
if ( filter ) {
/* the bilinear filter requires no extra info */
filter->flags = 0;
/* no private data */
filter->data = 0;
/* set the function pointers to the callback and destroy functions */
filter->callback = filter_bilinear_callback;
filter->destroy = filter_destroy;
}
return filter;
}
/***************************************************************************************************/
/* The deblocking filter. It filters block borders and non-intra coded blocks to reduce blockiness */
/***************************************************************************************************/
static void filter_deblocking_callback(SDL_Overlay * dst, SDL_Overlay * src, SDL_Rect * region, SMPEG_FilterInfo * info, void * data)
{
int x, y;
Uint32 dL, dU, dR, dD;
Uint32 aL, aU, aR, aD;
Uint32 Q;
Uint16 * coeffs;
register Uint8 * s, * d;
/* retrieve the coeffs from private data */
coeffs = (Uint16 *) data;
/* Y component */
s = src->pixels[0];
d = dst->pixels[0];
s += region->y * src->pitches[0] + region->x;
/* Skip first line */
memcpy(d, s, region->w);
d += dst->pitches[0];
s += src->pitches[0];
for(y = 1; y < region->h - 1; y++)
{
/* Skip first pixel */
*d++ = *s++;
for(x = 1; x < region->w - 1; x++)
{
/* get current block quantization error from the info structure provided by the video decoder */
Q = info->yuv_mb_square_error[((region->y + y) >> 4) * (src->w >> 4) + ((region->x + x) >> 4)];
if(!Q)
*d++ = *s++; /* block is intra coded, don't filter */
else
{
/* compute differences with up, left, right and down neighbors */
dL = *s - *(s - 1) + 256;
dR = *s - *(s + 1) + 256;
dU = *s - *(s - src->pitches[0]) + 256;
dD = *s - *(s + src->pitches[0]) + 256;
/* get the corresponding filter coefficients from the lookup table */
aU = coeffs[(y & 7) + (Q << 12) + (dU << 3)];
aD = coeffs[(y & 7) + (Q << 12) + (dD << 3)];
aL = coeffs[(x & 7) + (Q << 12) + (dL << 3)];
aR = coeffs[(x & 7) + (Q << 12) + (dR << 3)];
/* apply the filter on current pixel */
*d++ =
((*s)*(4 * 65536 - aL - aR - aU - aD) + // (4-aL-aR-aU-aD)*(x,y) +
(*(s - src->pitches[0]))*aU + // aU*(x,y-1) +
(*(s - 1))*aL + // aL*(x-1,y) +
(*(s + 1))*aR + // aR*(x+1,y) +
(*(s + src->pitches[0]))*aD) // aU*(x,y+1)
>> 18; // remove fixed point and / 4
s++;
}
}
/* Skip last pixel */
*d++ = *s++;
/* Go to next line */
d += dst->pitches[0] - region->w;
s += src->pitches[0] - region->w;
}
/* Skip last line */
memcpy(d, s, region->w);
d += dst->pitches[0];
s += src->pitches[0];
/* V component (unfiltered) */
s = src->pixels[1];
d = dst->pixels[1];
s += (region->y >> 1) * src->pitches[1] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[1];
d += dst->pitches[1];
}
/* U component (unfiltered) */
s = src->pixels[2];
d = dst->pixels[2];
s += (region->y >> 1) * src->pitches[2] + (region->x >> 1);
for(y = 0; y < region->h; y+=2)
{
memcpy(d, s, region->w >> 1);
s += src->pitches[2];
d += dst->pitches[2];
}
}
static void *allocate_deblocking_data(void)
{
void * data;
Uint16 * c;
Uint32 q, q1, q5, q9, d;
/* precalc table is 256Kb long */
data = malloc(sizeof(*c)*8*32*512);
c = (Uint16 *)data;
/* precalc filter coefficients: */
/* 1 */
/* coeffs(Q,d,x,y) = _____________________ */
/* d(x,y)*d(x,y) */
/* 1 + _____________ */
/* Q*Q*k(x,y) */
/* where */
/* k(x,y) = [ 9 9 9 9 9 9 9 9 ] */
/* [ 9 5 5 5 5 5 5 9 ] */
/* [ 9 5 1 1 1 1 5 9 ] */
/* [ 9 5 1 1 1 1 5 9 ] */
/* [ 9 5 1 1 1 1 5 9 ] */
/* [ 9 5 1 1 1 1 5 9 ] */
/* [ 9 5 5 5 5 5 5 9 ] */
/* [ 9 9 9 9 9 9 9 9 ] */
/* and Q is the quantization error for the block */
/* and d is the difference between current pixel and neighbor pixel */
/* */
/* this is for the math :), now some additional tricks: */
/* */
/* all coeffs are multiplied by 65536 for precision (fixed point) */
/* and d is translated from [-128,127] to [0,255] (array indexation)*/
for(d = 0; d < 512*8; d++)
*c++ = 0;
for(q = 1; q < 32; q++)
{
q1 = q*q;
q9 = (q1 << 3) + q1;
q5 = (q1 << 2) + q1;
for(d = 0; d < 256; d++)
{
*c++ = (Uint16) ((q9 << 16) / ((256 - d)*(256 - d) + q9));
*c++ = (Uint16) ((q5 << 16) / ((256 - d)*(256 - d) + q5));
*c++ = (Uint16) ((q1 << 16) / ((256 - d)*(256 - d) + q1));
*c++ = (Uint16) ((q1 << 16) / ((256 - d)*(256 - d) + q1));
*c++ = (Uint16) ((q1 << 16) / ((256 - d)*(256 - d) + q1));
*c++ = (Uint16) ((q1 << 16) / ((256 - d)*(256 - d) + q1));
*c++ = (Uint16) ((q5 << 16) / ((256 - d)*(256 - d) + q5));
*c++ = (Uint16) ((q9 << 16) / ((256 - d)*(256 - d) + q9));
}
for(d = 0; d < 256; d++)
{
*c++ = (Uint16) ((q9 << 16) / (d*d + q9));
*c++ = (Uint16) ((q5 << 16) / (d*d + q5));
*c++ = (Uint16) ((q1 << 16) / (d*d + q1));
*c++ = (Uint16) ((q1 << 16) / (d*d + q1));
*c++ = (Uint16) ((q1 << 16) / (d*d + q1));
*c++ = (Uint16) ((q1 << 16) / (d*d + q1));
*c++ = (Uint16) ((q5 << 16) / (d*d + q5));
*c++ = (Uint16) ((q9 << 16) / (d*d + q9));
}
}
return data;
}
SMPEG_Filter *SMPEGfilter_deblocking(void)
{
SMPEG_Filter *filter;
filter = (SMPEG_Filter *)malloc(sizeof(*filter));
if ( filter ) {
/* Ask the video decoder to provide per-block quantization error */
filter->flags = SMPEG_FILTER_INFO_MB_ERROR;
/* allocate private data */
filter->data = allocate_deblocking_data();
if ( ! filter->data ) {
free(filter);
return (SMPEG_Filter *)0;
}
/* set the function pointers to the callback and destroy functions */
filter->callback = filter_deblocking_callback;
filter->destroy = filter_destroy;
}
return filter;
}

67
smpeg/src/MPEGfilter.h Normal file
View file

@ -0,0 +1,67 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* MPEG filters */
#ifndef _MPEGFILTER_H_
#define _MPEGFILTER_H_
/* SMPEG filter info flags */
#define SMPEG_FILTER_INFO_MB_ERROR 1
#define SMPEG_FILTER_INFO_PIXEL_ERROR 2
/* Filter info from SMPEG */
typedef struct SMPEG_FilterInfo {
Uint16* yuv_mb_square_error;
Uint16* yuv_pixel_square_error;
} SMPEG_FilterInfo;
/* MPEG filter definition */
struct SMPEG_Filter;
/* Callback functions for the filter */
typedef void (* SMPEG_FilterCallback)( SDL_Overlay * dest, SDL_Overlay * source, SDL_Rect * region, SMPEG_FilterInfo * filter_info, void * data );
typedef void (* SMPEG_FilterDestroy)( struct SMPEG_Filter * filter );
/* The filter definition itself */
typedef struct SMPEG_Filter {
Uint32 flags;
void * data;
SMPEG_FilterCallback callback;
SMPEG_FilterDestroy destroy;
} SMPEG_Filter;
/* SMPEG built-in filters. */
#ifdef __cplusplus
extern "C" {
#endif
/* The null filter (default). It simply copies the source rectangle to the video overlay. */
extern DECLSPEC SMPEG_Filter * SMPEGfilter_null(void);
/* The bilinear filter. A basic low-pass filter that will produce a smoother image. */
extern DECLSPEC SMPEG_Filter * SMPEGfilter_bilinear(void);
/* The deblocking filter. It filters block borders and non-intra coded blocks to reduce blockiness */
extern DECLSPEC SMPEG_Filter * SMPEGfilter_deblocking(void);
#ifdef __cplusplus
};
#endif
#endif /* _MPEGFILTER_H_ */

60
smpeg/src/MPEGlist.cpp Normal file
View file

@ -0,0 +1,60 @@
#include "MPEGlist.h"
MPEGlist::MPEGlist()
{
size = 0;
data = 0;
lock = 0;
next = 0;
prev = 0;
TimeStamp = -1;
}
MPEGlist::~MPEGlist()
{
if(next) next->prev = prev;
if(prev) prev->next = next;
if(data)
{
delete[] data;
data = 0;
}
}
/* Return the next free buffer or allocate a new one if none is empty */
MPEGlist * MPEGlist::Alloc(Uint32 Buffer_Size)
{
MPEGlist * tmp;
tmp = next;
next = new MPEGlist;
next->next = tmp;
if ( Buffer_Size ) {
next->data = new Uint8[Buffer_Size];
if(!next->data)
{
fprintf(stderr, "Alloc : Not enough memory\n");
return(0);
}
} else {
next->data = 0;
}
next->size = Buffer_Size;
next->prev = this;
return(next);
}
/* Lock current buffer */
void MPEGlist::Lock()
{
lock++;
}
/* Unlock current buffer */
void MPEGlist::Unlock()
{
if(lock != 0) lock--;
}

45
smpeg/src/MPEGlist.h Normal file
View file

@ -0,0 +1,45 @@
/* bufferlist.h */
/* A class for buffering the I/O and allow multiple streams to read the data
asynchronously */
#ifndef _MPEGLIST_H_
#define _MPEGLIST_H_
#include "SDL.h"
class MPEGlist {
public:
MPEGlist();
~MPEGlist();
/* Get to the next free buffer or allocate a new one if none is free */
MPEGlist * Alloc(Uint32 Buffer_Size);
/* Lock current buffer */
void Lock();
/* Unlock current buffer */
void Unlock();
/* Get the buffer */
inline void * Buffer() { return(data); };
inline Uint32 Size() { return(size); };
inline MPEGlist * Next() { return(next); };
inline MPEGlist * Prev() { return(prev); };
inline Uint32 IsLocked() { return(lock); };
double TimeStamp;
private:
class MPEGlist * next;
class MPEGlist * prev;
Uint32 lock;
Uint8 * data;
Uint32 size;
};
#endif

259
smpeg/src/MPEGring.cpp Normal file
View file

@ -0,0 +1,259 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "SDL_timer.h"
#include "MPEGring.h"
MPEG_ring:: MPEG_ring( Uint32 size, Uint32 count )
{
Uint32 tSize;
/* Set up the 'ring' pointer for all the old C code */
ring = this;
tSize = (size + sizeof(Uint32)) * count;
if( tSize )
{
ring->begin = (Uint8 *) malloc( tSize );
ring->timestamps = (double *) malloc( sizeof(double)*count );
}
else
ring->begin = 0;
if( ring->begin && count )
{
ring->end = ring->begin + tSize;
ring->read = ring->begin;
ring->write = ring->begin;
ring->timestamp_read = timestamps;
ring->timestamp_write = timestamps;
ring->bufSize = size;
ring->readwait = SDL_CreateSemaphore(0);
ring->writewait = SDL_CreateSemaphore(count);
}
else
{
ring->end = 0;
ring->read = 0;
ring->write = 0;
ring->bufSize = 0;
ring->readwait = 0;
}
if ( ring->begin && ring->readwait && ring->writewait ) {
ring->active = 1;
}
}
/* Release any waiting threads on the ring so they can be cleaned up.
The ring isn't valid after this call, so when threads are done you
should call MPRing_sdelete() on the ring.
*/
void
MPEG_ring:: ReleaseThreads( void )
{
/* Let the threads know that the ring is now inactive */
ring->active = 0;
if ( ring->readwait ) {
while ( SDL_SemValue(ring->readwait) == 0 ) {
SDL_SemPost(ring->readwait);
}
}
if ( ring->writewait ) {
while ( SDL_SemValue(ring->writewait) == 0 ) {
SDL_SemPost(ring->writewait);
}
}
}
MPEG_ring:: ~MPEG_ring( void )
{
if( ring )
{
/* Free up the semaphores */
ReleaseThreads();
/* Destroy the semaphores */
if( ring->readwait )
{
SDL_DestroySemaphore( ring->readwait );
ring->readwait = 0;
}
if( ring->writewait )
{
SDL_DestroySemaphore( ring->writewait );
ring->writewait = 0;
}
/* Free data buffer */
if ( ring->begin ) {
free( ring->begin );
free( ring->timestamps );
ring->begin = 0;
ring->timestamps = 0;
}
}
}
/*
Returns free buffer of ring->bufSize to be filled with data.
Zero is returned if there is no free buffer.
*/
Uint8 *
MPEG_ring:: NextWriteBuffer( void )
{
Uint8 *buffer;
buffer = 0;
if ( ring->active ) {
//printf("Waiting for write buffer (%d available)\n", SDL_SemValue(ring->writewait));
SDL_SemWait(ring->writewait);
//printf("Finished waiting for write buffer\n");
if ( ring->active ) {
buffer = ring->write + sizeof(Uint32);
}
}
return buffer;
}
/*
Call this when the buffer returned from MPRing_nextWriteBuffer() has
been filled. The passed length must not be larger than ring->bufSize.
*/
void
MPEG_ring:: WriteDone( Uint32 len, double timestamp)
{
if ( ring->active ) {
#ifdef NO_GRIFF_MODS
assert(len <= ring->bufSize);
#else
if ( len > ring->bufSize )
len = ring->bufSize;
#endif
*((Uint32*) ring->write) = len;
ring->write += ring->bufSize + sizeof(Uint32);
*(ring->timestamp_write++) = timestamp;
if( ring->write >= ring->end )
{
ring->write = ring->begin;
ring->timestamp_write = ring->timestamps;
}
//printf("Finished write buffer of %u bytes, making available for reads (%d+1 available for reads)\n", len, SDL_SemValue(ring->readwait));
SDL_SemPost(ring->readwait);
}
}
/*
Returns the number of bytes in the next ring buffer and sets the buffer
pointer to this buffer. If there is no buffer ready then the buffer
pointer is not changed and zero is returned.
*/
Uint32
MPEG_ring:: NextReadBuffer( Uint8** buffer )
{
Uint32 size;
size = 0;
if ( ring->active ) {
/* Wait for a buffer to become available */
//printf("Waiting for read buffer (%d available)\n", SDL_SemValue(ring->readwait));
SDL_SemWait(ring->readwait);
//printf("Finished waiting for read buffer\n");
if ( ring->active ) {
size = *((Uint32*) ring->read);
*buffer = ring->read + sizeof(Uint32);
}
}
return size;
}
/*
Call this when you have used some of the buffer previously returned by
MPRing_nextReadBuffer(), and want to update it so the rest of the data
is returned with the next call to MPRing_nextReadBuffer().
*/
double
MPEG_ring:: ReadTimeStamp(void)
{
if(ring->active)
return *ring->timestamp_read;
return(0);
}
void
MPEG_ring:: ReadSome( Uint32 used )
{
Uint8 *data;
Uint32 oldlen;
Uint32 newlen;
if ( ring->active ) {
data = ring->read + sizeof(Uint32);
oldlen = *((Uint32*) ring->read);
newlen = oldlen - used;
memmove(data, data+used, newlen);
*((Uint32*) ring->read) = newlen;
//printf("Reusing read buffer (%d+1 available)\n", SDL_SemValue(ring->readwait));
SDL_SemPost(ring->readwait);
}
}
/*
Call this when the buffer returned from MPRing_nextReadBuffer() is no
longer needed. This assumes there is only one read thread and one write
thread for a particular ring buffer.
*/
void
MPEG_ring:: ReadDone( void )
{
if ( ring->active ) {
ring->read += ring->bufSize + sizeof(Uint32);
ring->timestamp_read++;
if( ring->read >= ring->end )
{
ring->read = ring->begin;
ring->timestamp_read = ring->timestamps;
}
//printf("Finished read buffer, making available for writes (%d+1 available for writes)\n", SDL_SemValue(ring->writewait));
SDL_SemPost(ring->writewait);
}
}
/* EOF */

94
smpeg/src/MPEGring.h Normal file
View file

@ -0,0 +1,94 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A ring-buffer class for multi-threaded applications.
This assumes a single reader and a single writer, with blocking reads.
*/
#ifndef _MPEGRING_H
#define _MPEGRING_H
#include "SDL_types.h"
#include "SDL_thread.h"
class MPEG_ring {
public:
/* Create a ring with 'count' buffers, each 'size' bytes long */
MPEG_ring(Uint32 size, Uint32 count = 16);
/* Release any waiting threads on the ring so they can be cleaned up.
The ring isn't valid after this call, so when threads are done you
should call MPRing_sdelete() on the ring.
*/
void ReleaseThreads(void);
/* Destroy a ring after all threads are no longer using it */
virtual ~MPEG_ring();
/* Returns the maximum size of each buffer */
Uint32 BufferSize( void ) {
return(bufSize);
}
/* Returns how many buffers have available data */
int BuffersWritten(void) {
return(SDL_SemValue(ring->readwait));
}
/* Reserve a buffer for writing in the ring */
Uint8 *NextWriteBuffer( void );
/* Release a buffer, written to in the ring */
void WriteDone( Uint32 len, double timestamp=-1 );
/* Reserve a buffer for reading in the ring */
Uint32 NextReadBuffer( Uint8** buffer );
/* Read the timestamp of the current buffer */
double ReadTimeStamp(void);
/* Release a buffer having read some of it */
void ReadSome( Uint32 used );
/* Release a buffer having read all of it */
void ReadDone( void );
protected:
MPEG_ring *ring; /* Converted from C code, an alias for 'this' */
/* read only */
Uint32 bufSize;
/* private */
Uint8 *begin;
Uint8 *end;
double *timestamps;
double *timestamp_read;
double *timestamp_write;
Uint8 *read;
Uint8 *write;
/* For read/write synchronization */
int active;
SDL_semaphore *readwait;
SDL_semaphore *writewait;
};
#endif /* _MPEGRING_H */

348
smpeg/src/MPEGstream.cpp Normal file
View file

@ -0,0 +1,348 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* The generic MPEG stream class */
#include <string.h>
#include "MPEG.h"
#include "MPEGstream.h"
#include "video/video.h"
/* This is the limit of the quantity of pre-read data */
#define MAX_QUEUE (256 * 1024)
MPEGstream::MPEGstream(MPEGsystem * System, Uint8 Streamid)
{
system = System;
streamid = Streamid;
br = new MPEGlist();
cleareof = true;
data = 0;
stop = 0;
pos = 0;
preread_size = 0;
enabled = true;
mutex = SDL_CreateMutex();
}
MPEGstream::~MPEGstream()
{
MPEGlist * newbr;
SDL_DestroyMutex(mutex);
/* Free the list */
for(newbr = br; newbr->Prev(); newbr = newbr->Prev());
while(newbr->Next())
{
newbr = newbr->Next();
delete newbr->Prev();
}
delete newbr;
}
void
MPEGstream::reset_stream()
{
MPEGlist * newbr;
SDL_mutexP(mutex);
/* Seek the first buffer */
for(newbr = br; newbr->Prev(); newbr = newbr->Prev());
/* Free buffers */
while(newbr->Next())
{
newbr = newbr->Next();
delete newbr->Prev();
}
delete newbr;
br = new MPEGlist();
cleareof = true;
data = 0;
stop = 0;
pos = 0;
preread_size = 0;
SDL_mutexV(mutex);
}
void
MPEGstream::rewind_stream()
{
/* Note that this will rewind all streams, and other streams than this one */
/* will finish reading their prebuffured data (they are not reseted) */
/* This should works because there are always sequence start codes or */
/* audio start codes at the beginning of the streams */
/* Of course, this won't work on network streams */
/* Restart the system */
system->Rewind();
}
bool
MPEGstream:: next_system_buffer(void)
{
bool has_data = true;
/* No more buffer ? */
while(has_data && !br->Next())
{
SDL_mutexV(mutex);
system->RequestBuffer();
has_data = system->Wait();
SDL_mutexP(mutex);
}
if ( has_data && (br->Size() || cleareof) ) {
cleareof = false;
br = br->Next();
preread_size -= br->Size();
}
return(has_data);
}
bool
MPEGstream:: next_packet(bool recurse, bool update_timestamp)
{
SDL_mutexP(mutex);
/* Unlock current buffer */
br->Unlock();
/* Check for the end of stream mark */
next_system_buffer();
if(eof())
{
/* Report eof */
SDL_mutexV(mutex);
return(false);
}
/* Lock the buffer */
br->Lock();
/* Make sure that we have read buffers in advance if possible */
if(preread_size < MAX_QUEUE)
system->RequestBuffer();
/* Update stream datas */
data = (Uint8 *) br->Buffer();
stop = data + br->Size();
if(update_timestamp){
timestamp = br->TimeStamp;
timestamp_pos = pos;
}
SDL_mutexV(mutex);
return(true);
}
MPEGstream_marker *
MPEGstream:: new_marker(int offset)
{
MPEGstream_marker * marker;
SDL_mutexP(mutex);
/* We can't mark past the end of the stream */
if ( eof() ) {
SDL_mutexV(mutex);
return(0);
}
/* It may be possible to seek in the data stream, but punt for now */
if ( ((data+offset) < br->Buffer()) || ((data+offset) > stop) ) {
SDL_mutexV(mutex);
return(0);
}
/* Set up the mark */
marker = new MPEGstream_marker;
marker->marked_buffer = br;
marker->marked_data = data+offset;
marker->marked_stop = stop;
/* Lock the new buffer */
marker->marked_buffer->Lock();
SDL_mutexV(mutex);
return(marker);
}
bool
MPEGstream:: seek_marker(MPEGstream_marker const * marker)
{
SDL_mutexP(mutex);
if ( marker ) {
/* Release current buffer */
if(br->IsLocked())
{
br->Unlock();
marker->marked_buffer->Lock();
}
/* Reset the data positions */
br = marker->marked_buffer;
data = marker->marked_data;
stop = marker->marked_stop;
}
SDL_mutexV(mutex);
return(marker != 0);
}
void
MPEGstream:: delete_marker(MPEGstream_marker *marker)
{
if( marker && marker->marked_buffer)
{
marker->marked_buffer->Unlock();
delete marker;
}
}
Uint32
MPEGstream:: copy_data(Uint8 *area, Sint32 size, bool short_read)
{
Uint32 copied = 0;
bool timestamped = false;
while ( (size > 0) && !eof()) {
Uint32 len;
/* Get new data if necessary */
if ( data == stop ) {
/* try to use the timestamp of the first packet */
if ( ! next_packet(true, (timestamp == -1) || !timestamped) ) {
break;
}
timestamped = true;
}
SDL_mutexP(mutex);
/* Copy as much as we need */
if ( size <= (Sint32)(stop-data) ) {
len = size;
} else {
len = (stop-data);
}
memcpy(area, data, len);
area += len;
data += len;
size -= len;
copied += len;
pos += len;
/* Allow 32-bit aligned short reads? */
if ( ((copied%4) == 0) && short_read ) {
break;
}
SDL_mutexV(mutex);
}
return(copied);
}
int MPEGstream::copy_byte(void)
{
/* Get new data if necessary */
if ( data == stop ) {
if ( ! next_packet() ) {
return (-1);
}
}
pos ++;
return(*data++);
}
bool MPEGstream::eof() const
{
return(!br->Size());
}
void MPEGstream::insert_packet(Uint8 * Data, Uint32 Size, double timestamp)
{
MPEGlist * newbr;
/* Discard all packets if not enabled */
if(!enabled) return;
SDL_mutexP(mutex);
preread_size += Size;
/* Seek the last buffer */
for(newbr = br; newbr->Next(); newbr = newbr->Next());
/* Position ourselves at the end of the stream */
newbr = newbr->Alloc(Size);
if ( Size ) {
memcpy(newbr->Buffer(), Data, Size);
}
newbr->TimeStamp = timestamp;
SDL_mutexV(mutex);
garbage_collect();
}
/* - Check for unused buffers and free them - */
void MPEGstream::garbage_collect(void)
{
MPEGlist * newbr;
SDL_mutexP(mutex);
br->Lock();
/* First of all seek the first buffer */
for(newbr = br; newbr->Prev(); newbr = newbr->Prev());
/* Now free buffers until we find a locked buffer */
while(newbr->Next() && !newbr->IsLocked())
{
newbr = newbr->Next();
delete newbr->Prev();
}
br->Unlock();
SDL_mutexV(mutex);
}
void MPEGstream::enable(bool toggle)
{
enabled = toggle;
}
double MPEGstream::time()
{
return(br->TimeStamp);
}

116
smpeg/src/MPEGstream.h Normal file
View file

@ -0,0 +1,116 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* The generic MPEG stream class */
#ifndef _MPEGSTREAM_H_
#define _MPEGSTREAM_H_
#include "SDL_types.h"
#include "MPEGerror.h"
#include "MPEGvideo.h"
#include "MPEGaudio.h"
#include "MPEGlist.h"
#define AUDIO_STREAMID 0xc0
#define VIDEO_STREAMID 0xe0
#define SYSTEM_STREAMID 0xbb
struct MPEGstream_marker
{
/* Data to mark part of the stream */
MPEGlist * marked_buffer;
Uint8 *marked_data;
Uint8 *marked_stop;
};
class MPEGstream
{
public:
MPEGstream(class MPEGsystem * System, Uint8 Streamid);
~MPEGstream();
/* Cleanup the buffers and reset the stream */
void reset_stream(void);
/* Rewind the stream */
void rewind_stream(void);
/* Go to the next packet in the stream */
bool next_packet(bool recurse = true, bool update_timestamp = true);
/* Mark a position in the data stream */
MPEGstream_marker *new_marker(int offset);
/* Jump to the marked position */
bool seek_marker(MPEGstream_marker const * marker);
/* Jump to last successfully marked position */
void delete_marker(MPEGstream_marker * marker);
/* Copy data from the stream to a local buffer */
Uint32 copy_data(Uint8 *area, Sint32 size, bool short_read = false);
/* Copy a byte from the stream */
int copy_byte(void);
/* Check for end of file or an error in the stream */
bool eof(void) const;
/* Insert a new packet at the end of the stream */
void insert_packet(Uint8 * data, Uint32 size, double timestamp=-1);
/* Check for unused buffers and free them */
void garbage_collect(void);
/* Enable or disable the stream */
void enable(bool toggle);
/* Get stream time */
double time();
Uint32 pos;
Uint8 streamid;
protected:
Uint8 *data;
Uint8 *stop;
Uint32 preread_size;
class MPEGsystem * system;
MPEGlist * br;
bool cleareof;
bool enabled;
SDL_mutex * mutex;
/* Get a buffer from the stream */
bool next_system_buffer(void);
public:
/* "pos" where "timestamp" belongs */
Uint32 timestamp_pos;
double timestamp;
};
#endif /* _MPEGSTREAM_H_ */

1458
smpeg/src/MPEGsystem.cpp Normal file

File diff suppressed because it is too large Load diff

117
smpeg/src/MPEGsystem.h Normal file
View file

@ -0,0 +1,117 @@
/* A class based on the MPEG stream class, used to parse the system stream */
/* - Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn - */
#ifndef _MPEGSYSTEM_H_
#define _MPEGSYSTEM_H_
#define USE_SYSTEM_TIMESTAMP
#include "SDL.h"
#include "SDL_thread.h"
#include "MPEGerror.h"
class MPEGstream;
/* MPEG System library
by Vivien Chappelier */
/* The system class is necessary for splitting the MPEG stream into */
/* peaces of data that will be sent to the audio or video decoder. */
class MPEGsystem : public MPEGerror
{
public:
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
MPEGsystem() {}
MPEGsystem(SDL_RWops *mpeg_source);
virtual ~MPEGsystem();
/* Buffered I/O functions */
void RequestBuffer();
bool Wait();
Uint32 Tell();
void Rewind();
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
virtual void Start();
void Stop();
bool Eof() const;
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
virtual bool Seek(int length);
virtual Uint32 TotalSize();
virtual double TotalTime();
virtual double TimeElapsedAudio(int atByte);
/* Skip "seconds" seconds */
void Skip(double seconds);
/* Create all the streams present in the MPEG */
MPEGstream ** GetStreamList();
/* Insert a stream in the list */
void add_stream(MPEGstream * stream);
/* Search for a stream in the list */
MPEGstream * get_stream(Uint8 stream_id);
/* Test if a stream is in the list */
Uint8 exist_stream(Uint8 stream_id, Uint8 mask);
/* Reset all the system streams */
void reset_all_streams();
/* Set eof for all streams */
void end_all_streams();
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
/* Seek the first header */
virtual bool seek_first_header();
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
/* Seek the next header */
virtual bool seek_next_header();
protected:
/* Run the loop to fill the stream buffers */
static bool SystemLoop(MPEGsystem *system);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> need for override in popcorn */
/* Fill a buffer */
virtual Uint8 FillBuffer();
/* Read a new packet */
virtual void Read();
/* The system thread which fills the FIFO */
static int SystemThread(void * udata);
SDL_RWops *source;
SDL_Thread * system_thread;
bool system_thread_running;
MPEGstream ** stream_list;
Uint8 * read_buffer;
Uint8 * pointer;
int read_size;
Uint32 read_total;
Uint32 packet_total;
int request;
SDL_semaphore * request_wait;
SDL_mutex * system_mutex;
bool endofstream;
bool errorstream;
double frametime;
double stream_timestamp;
#ifdef USE_SYSTEM_TIMESTAMP
/* Current timestamp for this stream */
double timestamp;
double timedrift;
double skip_timestamp;
#endif
};
#endif

109
smpeg/src/MPEGvideo.h Normal file
View file

@ -0,0 +1,109 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
- Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn -
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A class based on the MPEG stream class, used to parse and play video */
#ifndef _MPEGVIDEO_H_
#define _MPEGVIDEO_H_
#include "SDL.h"
#include "SDL_thread.h"
#include "MPEGerror.h"
#include "MPEGaction.h"
class MPEGstream;
/* This is the MPEG video stream structure in the mpeg_play code */
struct vid_stream;
typedef struct vid_stream VidStream;
/* Temporary definition of time stamp structure. */
typedef double TimeStamp;
class MPEGvideo : public MPEGerror, public MPEGvideoaction {
/* Thread to play the video asynchronously */
friend int Play_MPEGvideo(void *udata);
/* Various mpeg_play functions that need our data */
friend VidStream* mpegVidRsrc( TimeStamp time_stamp, VidStream* vid_stream, int first );
friend int get_more_data( VidStream* vid_stream );
public:
MPEGvideo(MPEGstream *stream);
virtual ~MPEGvideo();
/* MPEG actions */
void Play(void);
void Stop(void);
void Rewind(void);
void ResetSynchro(double time);
void Skip(float seconds);
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name in popcorn */
MPEGstatus GetStatus(void);
/* MPEG video actions */
bool GetVideoInfo(MPEG_VideoInfo *info);
bool SetDisplay(SDL_Surface *dst, SDL_mutex *lock,
MPEG_DisplayCallback callback);
void MoveDisplay(int x, int y);
void ScaleDisplayXY(int w, int h);
void SetDisplayRegion(int x, int y, int w, int h);
void RenderFrame(int frame);
void RenderFinal(SDL_Surface *dst, int x, int y);
SMPEG_Filter * Filter(SMPEG_Filter * filter);
/* Display and sync functions */
void DisplayFrame( VidStream* vid_stream );
void ExecuteDisplay( VidStream* vid_stream );
int timeSync( VidStream* vid_stream );
/* Yes, it's a hack.. */
MPEGaudioaction *TimeSource(void ) {
return time_source;
}
protected:
MPEGstream *mpeg;
VidStream* _stream;
SDL_Surface* _dst;
SDL_mutex* _mutex;
SDL_Thread* _thread;
MPEG_DisplayCallback _callback;
int _ow; // original width of the movie
int _oh; // original height of the movie
int _w; // mb aligned width of the movie
int _h; // mb aligned height of the movie
SDL_Rect _srcrect; // source area
SDL_Rect _dstrect; // display area
SDL_Overlay *_image;// source image
float _fps; // frames per second
SMPEG_Filter * _filter; // pointer to the current filter used
SDL_mutex* _filter_mutex; // make sure the filter is not changed while being used
void RewindStream(void);
};
#endif /* _MPEGVIDEO_H_ */

129
smpeg/src/Makefile.am Normal file
View file

@ -0,0 +1,129 @@
## Makefile.am for the smpeg library
bin_SCRIPTS = smpeg-config
CCLD = $(CXXLD)
# The smpeg library target
lib_LTLIBRARIES = libsmpeg.la
libsmpeg_la_SOURCES = \
MPEG.cpp \
MPEGring.cpp \
MPEGlist.cpp \
MPEGstream.cpp \
MPEGsystem.cpp \
MPEGfilter.c \
smpeg.cpp \
audio/MPEGaudio.cpp \
audio/bitwindow.cpp \
audio/filter.cpp \
audio/filter_2.cpp \
audio/hufftable.cpp \
audio/mpeglayer1.cpp \
audio/mpeglayer2.cpp \
audio/mpeglayer3.cpp \
audio/mpegtable.cpp \
audio/mpegtoraw.cpp \
video/MPEGvideo.cpp \
video/decoders.cpp \
video/decoders.h \
video/dither.h \
video/floatdct.cpp \
video/gdith.cpp \
video/jrevdct.cpp \
video/motionvec.cpp \
video/parseblock.cpp \
video/proto.h \
video/readfile.cpp \
video/util.cpp \
video/util.h \
video/video.cpp \
video/video.h \
video/vhar128.cpp \
video/vhar128.h \
video/mmxflags_asm.S \
video/mmxidct_asm.S
libsmpegincludedir = $(includedir)/smpeg
libsmpeginclude_HEADERS = \
MPEG.h \
MPEGaction.h \
MPEGaudio.h \
MPEGerror.h \
MPEGfilter.h \
MPEGring.h \
MPEGlist.h \
MPEGstream.h \
MPEGsystem.h \
MPEGvideo.h \
smpeg.h
libsmpeg_la_LDFLAGS = \
-release $(LT_RELEASE) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
EXTRA_DIST = \
CHANGES \
COPYING \
TODO \
README \
README.SDL_mixer \
plaympeg.1 \
gtv.1 \
VisualC.zip \
smpeg.m4 \
gcc-fat.sh \
autogen.sh \
audio/AUTHORS \
audio/COPYING.LIB \
audio/README \
audio/README.LIB \
video/README \
video/COPYRIGHT
video/16bit_mmx.lo: video/16bit_mmx.cpp
$(CXX) -c -o $@ $^ $(CXXFLAGS)
video/32bit_mmx.lo: video/32bit_mmx.cpp
$(CXX) -c -o $@ $^ $(CXXFLAGS)
# Sample MPEG players
if HAVE_GTK
GTK_PLAYER = gtv
else
GTK_PLAYER =
endif
if HAVE_OPENGL
OPENGL_PLAYER = glmovie
else
OPENGL_PLAYER =
endif
bin_PROGRAMS = plaympeg $(GTK_PLAYER) $(OPENGL_PLAYER)
# Sources for plaympeg
man_MANS = plaympeg.1 gtv.1
plaympeg_SOURCES = plaympeg.c
plaympeg_LDADD = libsmpeg.la
# Sources for gtv
gtv_SOURCES = gtv.c gtv.h
gtv_LDADD = @GTK_LIBS@ libsmpeg.la
# Sources for glmovie
glmovie_SOURCES = glmovie-tile.c glmovie.c glmovie.h
glmovie_LDADD = @GL_LIBS@ libsmpeg.la
# M4 macro file for inclusion with autoconf
m4datadir = $(datadir)/aclocal
m4data_DATA = smpeg.m4
# Rule to build tar-gzipped distribution package
$(PACKAGE)-$(VERSION).tar.gz: dist
# Rule to build RPM distribution package
rpm: $(PACKAGE)-$(VERSION).tar.gz
cp $(PACKAGE)-$(VERSION).tar.gz /usr/src/redhat/SOURCES
rpm -ba smpeg.spec

74
smpeg/src/README Normal file
View file

@ -0,0 +1,74 @@
SDL MPEG Player Library (SMPEG)
Version 0.4.5
July 17, 2001
Written by Karl Robillard and Sam Lantinga, Loki Software, Inc.
Streaming MPEG support contributed by Vivien Chappelier.
SMPEG is a free MPEG1 video player library with sound support. Video playback
is based on the ubiquitous Berkeley MPEG player, mpeg_play v2.2. Audio is
played through a slightly modified mpegsound library, part of Splay v0.8.2.
SMPEG supports MPEG audio (MP3), MPEG-1 video, and MPEG system streams.
This library is distributed under the GNU Library Public License (LGPL)
version 2.
plaympeg, gtv, and glmovie are simple video players provided to test the
library. The C library interface is 'documented' in smpeg.h, and the C++
library interface is spread out over the MPEG*.h files.
This is a work in progress. Only 16 or 32 bit color depth is supported.
The player will dynamically conver to other color depths, but playback
will be much faster if your display is already set to 16 bit color depth.
Currently it has only been tested on Linux.
Requirements:
* Simple DirectMedia Layer v1.2.0 or newer
http://www.libsdl.org/
To make:
Type 'make all'. This should build libsmpeg.a and plaympeg
Usage:
plaympeg [--noaudio] [--novideo] [--double|-2] [--loop|-l] file ...
Known Issues:
The MPEG decoding is a fairly slow and mathematically intensive
process. It could use even further optimization.
There isn't any synchronization between the audio and video threads,
and system stream timestamps are ignored. The video is synchronized
with audio by using video framerate and elapsed time. They are
are synchronized well enough for short clips, but long movies, or
movies with visual audio cues (like speech) don't look very good.
Reporting bugs:
Please report any bugs and/or fixes to smpeg@lokigames.com.
Looking at the code:
The functions that should be optimized to improve performance are:
Color16DitherImageMod() (Uses 5ms CPU, called few times)
Twox2Color16DitherImageMod() (Uses 10ms CPU, called few times)
j_rev_dct() (Uses 0.01ms CPU, but called many times)
ParseReconBlock() (Uses 0.01ms CPU, but called many times)
To improve framerate scheduling, look at timeSync() in video/gdith.cpp
Links:
Berkeley MPEG player http://bmrc.berkeley.edu/frame/research/mpeg
Splay http://my.netian.com/~polarb
SDL http://www.libsdl.org/

View file

@ -0,0 +1,38 @@
There is no longer explicit support for the SDL_mixer library.
You can have the SDL mixer library mix audio from a movie by hooking into
the SDL mixer music hooks:
#include "smpeg.h"
#include "SDL_mixer.h"
.. set up the mixer audio ...
/* Note the last parameter is zero! */
mpeg = SMPEG_new("file.mpg", &info, 0);
/* Play the movie, using SDL_mixer for audio */
SMPEG_enableaudio(mpeg, 0);
if ( play_audio ) {
SDL_AudioSpec audiofmt;
Uint16 format;
int freq, channels;
/* Tell SMPEG what the audio format is */
Mix_QuerySpec(&freq, &format, &channels);
audiofmt.format = format;
audiofmt.freq = freq;
audiofmt.channels = channels;
SMPEG_actualSpec(mpeg, &audiofmt);
/* Hook in the MPEG music mixer */
Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
SMPEG_enableaudio(mpeg, 1);
}
SMPEG_play(mpeg);
/* Stop the movie and unhook SMPEG from the mixer */
SMPEG_stop(mpeg);
Mix_HookMusic(NULL, NULL);

5
smpeg/src/TODO Normal file
View file

@ -0,0 +1,5 @@
* Add fast stream skip support - being worked on by Damien Chavarria
* Rewrite the stream code to use condition variables
* Add ATI hardware MPEG decoding acceleration
* Add MMX versions of pixel-doubled dither routines

6810
smpeg/src/acinclude.m4 Normal file

File diff suppressed because it is too large Load diff

16
smpeg/src/autogen.sh Normal file
View file

@ -0,0 +1,16 @@
#!/bin/sh
#
die() {
echo "'$0' failed to run properly"
exit 1
}
set -e
aclocal $ACLOCAL_FLAGS || die aclocal
automake --foreign || die automake
autoconf || die autoconf
#./configure $*
echo "Now you are ready to run ./configure"

1363
smpeg/src/config.guess vendored Normal file

File diff suppressed because it is too large Load diff

1473
smpeg/src/config.sub vendored Normal file

File diff suppressed because it is too large Load diff

311
smpeg/src/configure.in Normal file
View file

@ -0,0 +1,311 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(README)
dnl Set various version strings - taken gratefully from the GTk sources
#
# Making releases:
# MICRO_VERSION += 1;
# INTERFACE_AGE += 1;
# BINARY_AGE += 1;
# if any functions have been added, set INTERFACE_AGE to 0.
# if backwards compatibility has been broken,
# set BINARY_AGE and INTERFACE_AGE to 0.
#
MAJOR_VERSION=0
MINOR_VERSION=4
MICRO_VERSION=5
INTERFACE_AGE=4
BINARY_AGE=5
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
AC_SUBST(MAJOR_VERSION)
AC_SUBST(MINOR_VERSION)
AC_SUBST(MICRO_VERSION)
AC_SUBST(INTERFACE_AGE)
AC_SUBST(BINARY_AGE)
AC_SUBST(VERSION)
ASFLAGS=""
CCASFLAGS=""
AC_SUBST(ASFLAGS)
AC_SUBST(CCASFLAGS)
# libtool versioning
LT_RELEASE=$MAJOR_VERSION.$MINOR_VERSION
LT_CURRENT=`expr $MICRO_VERSION - $INTERFACE_AGE`
LT_REVISION=$INTERFACE_AGE
LT_AGE=`expr $BINARY_AGE - $INTERFACE_AGE`
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
dnl Detect the canonical build and host environments
AC_CANONICAL_HOST
dnl Setup for automake
AM_INIT_AUTOMAKE(smpeg, $VERSION)
dnl Check for tools
AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AM_PROG_AS
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_INSTALL
dnl Work around the lack of certain typedefs.
AC_TYPE_SOCKLEN_T
dnl The alpha architecture needs special flags for binary portability
case "$target" in
alpha*-*-linux*)
if test x$ac_cv_prog_gcc = xyes; then
CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
fi
;;
sparc*-*-solaris*)
LIBS="$LIBS -lsocket -lnsl"
;;
*-*-qnx*)
LIBS="$LIBS -lsocket"
;;
*-*-beos*)
ac_default_prefix=/boot/develop/tools/gnupro
;;
*-*-cygwin* | *-*-mingw32*)
if test "$build" != "$target"; then # cross-compiling
ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
fi
;;
esac
# Set runtime shared library paths as needed
case "$target" in
*-*-linux*)
SMPEG_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
;;
*-*-freebsd*)
SMPEG_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
;;
*-*-solaris*)
SMPEG_RLD_FLAGS="-R\${exec_prefix}/lib"
;;
esac
AC_SUBST(SMPEG_RLD_FLAGS)
dnl Add compiler-specific optimization flags
AC_ARG_ENABLE(debug,
[ --enable-debug Disable aggressive optimizations [default=yes]],
, enable_debug=yes)
if test x$enable_debug != xyes; then
if test x$ac_cv_prog_gcc = xyes; then
CFLAGS="$CFLAGS -fexpensive-optimizations -fomit-frame-pointer"
fi
case "$target" in
i486-*-*) # Yeah right. :)
if test x$ac_cv_prog_gcc = xyes; then
CFLAGS="$CFLAGS -march=486"
fi
;;
i?86-*-*)
if test x$ac_cv_prog_gcc = xyes; then
CFLAGS="$CFLAGS -march=pentium -mcpu=pentiumpro"
fi
;;
esac
fi
dnl Check for SDL
SDL_VERSION=1.2.0
AM_PATH_SDL($SDL_VERSION,
:,
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
)
CFLAGS="$CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"
dnl See if we need to pass -lm for the math library
AC_CHECK_LIB(m, sqrt, LIBS="$LIBS -lm")
dnl Check for MMX support
AC_ARG_ENABLE(mmx,
[ --enable-mmx enable MMX IDCT decoding routines [default=no]],
, enable_mmx=no)
if test x$enable_mmx = xyes; then
AC_MSG_CHECKING(for MMX optimizations)
use_mmx=no
case "$target" in
i?86*)
use_mmx=yes
;;
esac
AC_MSG_RESULT($use_mmx)
if test x$use_mmx = xyes; then
CFLAGS="$CFLAGS -DUSE_MMX"
ASFLAGS="$ASFLAGS -DUSE_MMX"
CCASFLAGS="$CCASFLAGS -DUSE_MMX"
fi
fi
dnl Check for ATI vha support
AC_ARG_ENABLE(ati,
[ --enable-ati enable ATI Rage128 hardware acceleration [default=no]],
, enable_ati=no)
if test x$enable_ati = xyes; then
use_ati=yes
AC_CHECK_LIB(r128hap, ATIHAP_StartCCE, LIBS="$LIBS -lr128hap", use_ati=no)
AC_CHECK_LIB(r128vha, VHA_Init, LIBS="$LIBS -lr128vha", use_ati=no)
AC_CHECK_LIB(r128ov, CreateOVSurface, LIBS="$LIBS -lr128ov", use_ati=no)
AC_MSG_CHECKING(for ATI Rage128 hardware acceleration)
AC_MSG_RESULT($use_ati)
if test x$use_ati = xyes; then
CFLAGS="$CFLAGS -DUSE_ATI"
fi
fi
dnl Check for system timestamp sync
AC_ARG_ENABLE(timestamp-sync,
[ --enable-timestamp-sync enable system timestamp sync [default=yes]],
, enable_timestamp_sync=no)
if test x$enable_timestamp_sync = xyes; then
CFLAGS="$CFLAGS -DUSE_TIMESTAMP_SYNC"
fi
dnl Enable the use of the system thread
AC_ARG_ENABLE(threaded-system,
[ --enable-threaded-system enable system thread [default=no]],
, enable_threaded_system=no)
if test x$enable_threaded_system = xyes; then
CFLAGS="$CFLAGS -DUSE_SYSTEM_THREAD"
fi
dnl Disable using a thread for the video callback
AC_ARG_ENABLE(video-callback-thread,
[ --enable-video-callback-thread enable video callback thread [default=yes]],
, enable_video_callback_thread=yes)
if test x$enable_video_callback_thread = xno; then
CFLAGS="$CFLAGS -DDISABLE_VIDEO_CALLBACK_THREAD"
fi
dnl Enable threaded audio
AC_ARG_ENABLE(threaded-audio,
[ --enable-threaded-audio enable threaded audio [default=yes]],
, enable_threaded_audio=yes)
if test x$enable_threaded_audio = xyes; then
CFLAGS="$CFLAGS -DTHREADED_AUDIO"
fi
dnl See if we can build the GTk player
AC_ARG_ENABLE(gtk_player,
[ --enable-gtk-player build a GTk sample SMPEG player [default=yes]],
, enable_gtk_player=yes)
have_gtk=no
if test x$enable_gtk_player = xyes; then
AM_PATH_GTK(1.2.1, have_gtk=yes)
if test x$have_gtk = xyes; then
CFLAGS="$CFLAGS $GTK_CFLAGS"
fi
AC_SUBST(GTK_LIBS)
fi
AM_CONDITIONAL(HAVE_GTK, test x$have_gtk = xyes)
dnl See if we can build the Mesa player
AC_ARG_ENABLE(opengl_player,
[ --enable-opengl-player build an OpenGL sample SMPEG player [default=yes]],
, enable_opengl_player=yes)
have_glu=no
if test x$enable_opengl_player = xyes; then
case "$target" in
*-*-cygwin* | *-*-mingw32*)
SYS_GL_LIBS="-lopengl32 -lglu32"
;;
*-*-beos*)
SYS_GL_LIBS="-lGL"
;;
*-*-darwin*)
SYS_GL_LIBS=""
;;
*)
AC_PATH_X
AC_PATH_XTRA
if test x$have_x = xyes; then
CFLAGS="$CFLAGS $X_CFLAGS"
SYS_GL_LIBS="$X_LIBS -lGL -lGLU"
else
SYS_GL_LIBS="-lGL -lGLU"
fi
;;
esac
AC_MSG_CHECKING(for OpenGL support)
have_opengl=no
AC_TRY_COMPILE([
#include <GL/gl.h>
#include <GL/glu.h>
],[
],[
have_opengl=yes
])
AC_MSG_RESULT($have_opengl)
if test x$have_opengl = xyes; then
GL_LIBS="$SYS_GL_LIBS"
else
echo "*** The OpenGL movie player will not be built (missing GL or GLU)"
fi
fi
AC_SUBST(GL_LIBS)
AM_CONDITIONAL(HAVE_OPENGL, test x$have_opengl = xyes)
dnl Disable assertions in release builds
AC_ARG_ENABLE(assertions,
[ --enable-assertions Enable consistency checks in decoding [default=no]],
, enable_assertions=no)
if test x$enable_assertions != xyes; then
CFLAGS="$CFLAGS -DNDEBUG"
fi
dnl Add the source include directories
CFLAGS="$CFLAGS -I.. -DNOCONTROLS"
CFLAGS="$CFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/audio -I\$(top_srcdir)/video"
CXXFLAGS="$CFLAGS"
dnl C++ flags are the same as the C flags
CXXFLAGS="$CFLAGS"
if test x$GCC = xyes; then
# Check to see if options -fno-rtti -fno-exceptions are supported
AC_MSG_CHECKING(if $CXX supports -fno-rtti -fno-exceptions)
use_fnoexceptions=no
save_CFLAGS="$CFLAGS"
save_CC="$CC"
CFLAGS="-fno-rtti -fno-exceptions"
CC="$CXX"
AC_TRY_COMPILE([
],[
],[
use_fnoexceptions=yes
])
AC_MSG_RESULT($use_fnoexceptions)
if test x$use_fnoexceptions = xyes; then
CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-rtti"
fi
CC="$save_CC"
CFLAGS="$save_CFLAGS"
fi
# Finally create all the generated files
AC_OUTPUT([
Makefile
smpeg-config
smpeg.spec
])

411
smpeg/src/depcomp Normal file
View file

@ -0,0 +1,411 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
# Copyright 1999, 2000 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
fi
# `libtool' can also be set to `yes' or `no'.
depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
# Some modes work just like other modes, but use different flags. We
# parameterize here, but still list the modes in the big case below,
# to make depend.m4 easier to write. Note that we *cannot* use a case
# here, because this file can only contain one case statement.
if test "$depmode" = hp; then
# HP compiler uses -M and no extra arg.
gccflag=-M
depmode=gcc
fi
if test "$depmode" = dashXmstdout; then
# This is just like dashmstdout with a different argument.
dashmflag=-xM
depmode=dashmstdout
fi
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
## it if -MD -MP comes after the -MF stuff. Hmm.
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
mv "$tmpdepfile" "$depfile"
;;
gcc)
## There are various ways to get dependency output from gcc. Here's
## why we pick this rather obscure method:
## - Don't want to use -MD because we'd like the dependencies to end
## up in a subdir. Having to rename by hand is ugly.
## (We might end up doing this anyway to support other compilers.)
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
## -MM, not -M (despite what the docs say).
## - Using -M directly means running the compiler twice (even worse
## than renaming).
if test -z "$gccflag"; then
gccflag=-MD,
fi
"$@" -Wp,"$gccflag$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
## The second -e expression handles DOS-style file names with drive letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the `deleted header file' problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
tr ' ' '
' < "$tmpdepfile" |
## Some versions of gcc put a space before the `:'. On the theory
## that the space means something, we add a space to the output as
## well.
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
sgi)
if test "$libtool" = yes; then
"$@" "-Wp,-MDupdate,$tmpdepfile"
else
"$@" -MDupdate "$tmpdepfile"
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
echo "$object : \\" > "$depfile"
# Clip off the initial element (the dependent). Don't try to be
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
# the IRIX cc adds comments like `#:fec' to the end of the
# dependency line.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
tr '
' ' ' >> $depfile
echo >> $depfile
# The second pass generates a dummy entry for each header file.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> $depfile
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. This file always lives in the current directory.
# Also, the AIX compiler puts `$object:' at the start of each line;
# $object doesn't have directory information.
stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
tmpdepfile="$stripped.u"
outname="$stripped.o"
if test "$libtool" = yes; then
"$@" -Wc,-M
else
"$@" -M
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
if test -f "$tmpdepfile"; then
# Each line is of the form `foo.o: dependent.h'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
tru64)
# The Tru64 AIX compiler uses -MD to generate dependencies as a side
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
# dependencies in `foo.d' instead, so we check for that too.
# Subdirectories are respected.
tmpdepfile1="$object.d"
tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'`
if test "$libtool" = yes; then
"$@" -Wc,-MD
else
"$@" -MD
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
if test -f "$tmpdepfile1"; then
tmpdepfile="$tmpdepfile1"
else
tmpdepfile="$tmpdepfile2"
fi
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
# That's a space and a tab in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
#nosideeffect)
# This comment above is used by automake to tell side-effect
# dependency tracking mechanisms from slower ones.
dashmstdout)
# Important note: in order to support this mode, a compiler *must*
# always write the proprocessed file to stdout, regardless of -o,
# because we must use -o when running libtool.
test -z "$dashmflag" && dashmflag=-M
( IFS=" "
case " $* " in
*" --mode=compile "*) # this is libtool, let us make it quiet
for arg
do # cycle over the arguments
case "$arg" in
"--mode=compile")
# insert --quiet before "--mode=compile"
set fnord "$@" --quiet
shift # fnord
;;
esac
set fnord "$@" "$arg"
shift # fnord
shift # "$arg"
done
;;
esac
"$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
) &
proc=$!
"$@"
stat=$?
wait "$proc"
if test "$stat" != 0; then exit $stat; fi
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
tr ' ' '
' < "$tmpdepfile" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
dashXmstdout)
# This case only exists to satisfy depend.m4. It is never actually
# run, as this mode is specially recognized in the preamble.
exit 1
;;
makedepend)
# X makedepend
(
shift
cleared=no
for arg in "$@"; do
case $cleared in no)
set ""; shift
cleared=yes
esac
case "$arg" in
-D*|-I*)
set fnord "$@" "$arg"; shift;;
-*)
;;
*)
set fnord "$@" "$arg"; shift;;
esac
done
obj_suffix="`echo $object | sed 's/^.*\././'`"
touch "$tmpdepfile"
${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
) &
proc=$!
"$@"
stat=$?
wait "$proc"
if test "$stat" != 0; then exit $stat; fi
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
tail +3 "$tmpdepfile" | tr ' ' '
' | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile" "$tmpdepfile".bak
;;
cpp)
# Important note: in order to support this mode, a compiler *must*
# always write the proprocessed file to stdout, regardless of -o,
# because we must use -o when running libtool.
( IFS=" "
case " $* " in
*" --mode=compile "*)
for arg
do # cycle over the arguments
case $arg in
"--mode=compile")
# insert --quiet before "--mode=compile"
set fnord "$@" --quiet
shift # fnord
;;
esac
set fnord "$@" "$arg"
shift # fnord
shift # "$arg"
done
;;
esac
"$@" -E |
sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
sed '$ s: \\$::' > "$tmpdepfile"
) &
proc=$!
"$@"
stat=$?
wait "$proc"
if test "$stat" != 0; then exit $stat; fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
cat < "$tmpdepfile" >> "$depfile"
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
msvisualcpp)
# Important note: in order to support this mode, a compiler *must*
# always write the proprocessed file to stdout, regardless of -o,
# because we must use -o when running libtool.
( IFS=" "
case " $* " in
*" --mode=compile "*)
for arg
do # cycle over the arguments
case $arg in
"--mode=compile")
# insert --quiet before "--mode=compile"
set fnord "$@" --quiet
shift # fnord
;;
esac
set fnord "$@" "$arg"
shift # fnord
shift # "$arg"
done
;;
esac
"$@" -E |
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
) &
proc=$!
"$@"
stat=$?
wait "$proc"
if test "$stat" != 0; then exit $stat; fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
echo " " >> "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;
none)
exec "$@"
;;
*)
echo "Unknown depmode $depmode" 1>&2
exit 1
;;
esac
exit 0

110
smpeg/src/gcc-fat.sh Normal file
View file

@ -0,0 +1,110 @@
#!/bin/sh
# Build Universal binaries on Mac OS X, thanks Ryan!
#
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
# PowerPC compiler flags (10.2 runtime compatibility)
GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
GCC_LINK_PPC="\
-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
# Intel compiler flags (10.4 runtime compatibility)
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
GCC_LINK_X86="\
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
# Output both PowerPC and Intel object files
args="$*"
compile=yes
link=yes
while test x$1 != x; do
case $1 in
--version) exec gcc $1;;
-v) exec gcc $1;;
-V) exec gcc $1;;
-print-prog-name=*) exec gcc $1;;
-print-search-dirs) exec gcc $1;;
-E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
compile=no; link=no;;
-c) link=no;;
-o) output=$2;;
*.c|*.cc|*.cpp|*.S) source=$1;;
esac
shift
done
if test x$link = xyes; then
GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
fi
if test x"$output" = x; then
if test x$link = xyes; then
output=a.out
elif test x$compile = xyes; then
output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
fi
fi
if test x"$output" != x; then
dir=ppc/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
if test -f "ppc/$1" && test "$1" != "$output"; then
ppc_args="$ppc_args ppc/$1"
else
ppc_args="$ppc_args $1"
fi
shift
done
$GCC_COMPILE_PPC $ppc_args || exit $?
if test x"$output" != x; then
cp $output ppc/$output
fi
if test x"$output" != x; then
dir=x86/`dirname $output`
if test -d $dir; then
:
else
mkdir -p $dir
fi
fi
set -- $args
while test x$1 != x; do
if test -f "x86/$1" && test "$1" != "$output"; then
x86_args="$x86_args x86/$1"
else
x86_args="$x86_args $1"
fi
shift
done
$GCC_COMPILE_X86 $x86_args || exit $?
if test x"$output" != x; then
cp $output x86/$output
fi
if test x"$output" != x; then
lipo -create -o $output ppc/$output x86/$output
fi

263
smpeg/src/glmovie-tile.c Normal file
View file

@ -0,0 +1,263 @@
/*
* MODIFIED by Bruce Merry (bmerry@iafrica.com) on 10/11/2000
* - fixed to handle arbitrary tile dimensions, not just 1x2
* - max_texture_size renamed to texture_size and used as a variable
* (to change the max texture size, edit the assigned value in the decl)
* - hardcoded 256's changed to texture_size to allow small texture sizes
* (e.g. for very low-res movies)
* - all pieces of movie copied into the top left corner of texture tiles,
* instead of being offset
* - mechanism for keeping tiles aligned changed: a one texel border is
* included in the tiles, which I think is used by the filtering even though
* it is not explicitly selected for rendering (I think - I don't know much
* about OpenGL, I've just fiddled until it looked right)
* - removed glmovie_is_power_of_2: it was not needed and
* it only went up to 2048 anyway.
*/
#include "glmovie.h"
#include <stdlib.h>
#include <string.h>
/* Some data is redundant at this stage. */
typedef struct glmovie_texture_t {
GLuint id; /* OpenGL texture id. */
GLuint poly_width; /* Quad width for tile. */
GLuint poly_height; /* Quad height for tile. */
GLuint movie_width; /* Width of movie inside tile. */
GLuint movie_height; /* Height of movie inside tile. */
GLuint skip_rows; /* Number of rows of movie to skip */
GLuint skip_pixels; /* Number of columns of movie to skip */
GLuint row; /* Row number of tile in scheme. */
GLuint col; /* Column number of tile in scheme. */
} glmovie_texture;
/* Boy, is this not thread safe. */
/* Our evil maximum texture size. Boo 3Dfx! */
static GLuint texture_size = 256;
/* Keep this around for easy freeing later. */
static GLuint* texture_ids = NULL;
/* Our main data. */
static glmovie_texture* textures = NULL;
static GLuint num_texture_rows = 0;
static GLuint num_texture_cols = 0;
/* Width and height of all tiling. */
static GLuint tiled_width = 0;
static GLuint tiled_height = 0;
/* Width and height of entire movie. */
static GLuint movie_width = 0;
static GLuint movie_height = 0;
/*
* Draw the frame data.
*
* Parameters:
* frame: Actual RGBA frame data
*/
void glmovie_draw( GLubyte* frame )
{
GLuint i;
GLdouble shift;
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
shift = 1 / ((double) texture_size);
for (i = 0; i < num_texture_rows * num_texture_cols; i++) {
glBindTexture( GL_TEXTURE_2D, textures[i].id );
glPixelStorei( GL_UNPACK_ROW_LENGTH, movie_width );
glPixelStorei( GL_UNPACK_SKIP_ROWS, textures[i].skip_rows );
glPixelStorei( GL_UNPACK_SKIP_PIXELS, textures[i].skip_pixels );
glTexSubImage2D( GL_TEXTURE_2D,
0,
0, /* offset_x */
0, /* offset_y */
textures[i].movie_width + 2,
textures[i].movie_height + 2,
GL_RGBA,
GL_UNSIGNED_BYTE,
frame );
glBegin( GL_QUADS );
glTexCoord2f( shift, shift );
glVertex2i( textures[i].col * texture_size,
textures[i].row * texture_size );
glTexCoord2f( shift, shift + (textures[i].movie_height)/((double) texture_size) );
glVertex2i( textures[i].col * texture_size,
(textures[i].row + 1) * texture_size);
glTexCoord2f( shift + (textures[i].movie_width)/((double) texture_size),
shift + (textures[i].movie_height)/((double) texture_size) );
glVertex2i( (textures[i].col + 1) * texture_size,
(textures[i].row + 1) * texture_size);
glTexCoord2f( shift + (textures[i].movie_width)/((double) texture_size), shift );
glVertex2i( (textures[i].col + 1) * texture_size,
textures[i].row * texture_size );
glEnd( );
}
}
/*
* Here we need to center the OpenGL viewport within the
* window size that we are given.
*
* Parameters:
* width: Width of the window in pixels
* height: Height of the window in pixels
*/
void glmovie_resize( GLuint width, GLuint height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
gluOrtho2D( 0, tiled_width, tiled_height, 0 );
}
/*
* Calculates the next power of 2 given a particular value.
* Useful for calculating proper texture sizes for non power-of-2
* aligned texures.
*
* Parameters:
* seed: Value to begin from
* Returns:
* Next power of 2 beginning from 'seed'
*/
GLuint glmovie_next_power_of_2( GLuint seed )
{
GLuint i;
for( i = 1; i < seed; i *= 2 ) { };
return i;
}
/*
* Initialize the movie player subsystem with the width and height
* of the *movie data* (as opposed to the window).
*
* Parameters:
* width: Width of movie in pixels
* height: Height of movie in pixels
* Returns:
* GL_NO_ERROR on success
* Any of the enumerated GL errors on failure
*/
GLenum glmovie_init( GLuint width, GLuint height )
{
/* Initial black texels. */
GLubyte* pixels;
/* Absolute offsets from within tiled frame. */
GLuint offset_x = 0;
GLuint offset_y = 0;
GLuint skip_rows = 0;
GLuint skip_pixels = 0;
GLuint i, j, current;
/* Save original movie dimensions. */
movie_width = width;
movie_height = height;
/* Get the power of 2 dimensions. */
tiled_width = glmovie_next_power_of_2( width );
tiled_height = glmovie_next_power_of_2( height );
while ( texture_size > tiled_width || texture_size > tiled_height )
texture_size /= 2;
/* Now break it up into quads. */
num_texture_rows = tiled_height / texture_size;
num_texture_cols = tiled_width / texture_size;
/* Time for fun with data structures. */
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glEnable( GL_TEXTURE_2D );
glEnable( GL_DITHER );
texture_ids = (GLuint*) malloc( sizeof( GLuint ) * num_texture_rows * num_texture_cols );
if( !texture_ids ) {
return GL_OUT_OF_MEMORY;
}
glGenTextures( num_texture_rows * num_texture_cols, texture_ids );
textures = (glmovie_texture*) malloc( sizeof( glmovie_texture ) *
num_texture_rows * num_texture_cols );
if( !textures ) {
glDeleteTextures( num_texture_rows * num_texture_cols, texture_ids );
free( texture_ids );
return GL_OUT_OF_MEMORY;
}
for ( i = 0; i < num_texture_rows; i++ ) {
skip_pixels = 0;
for ( j = 0; j < num_texture_cols; j++ ) {
current = i * num_texture_cols + j;
/* Setup texture. */
textures[current].id = texture_ids[current];
textures[current].poly_width = texture_size;
textures[current].poly_height = texture_size;
textures[current].movie_width =
(movie_width - 2) * (j + 1) / num_texture_cols - skip_pixels;
textures[current].movie_height =
(movie_height - 2) * (i + 1) / num_texture_rows - skip_rows;
textures[current].row = i;
textures[current].col = j;
textures[current].skip_pixels = skip_pixels;
textures[current].skip_rows = skip_rows;
skip_pixels += textures[current].movie_width;
pixels = (GLubyte*) malloc( textures[current].poly_width * textures[current].poly_height * 4 );
memset( pixels, 0, textures[current].poly_width * textures[current].poly_height * 4 );
if( !pixels ) {
glDeleteTextures( num_texture_rows * num_texture_cols, texture_ids );
free( texture_ids );
free( textures );
return GL_OUT_OF_MEMORY;
}
/* Do all of our useful binding. */
glBindTexture( GL_TEXTURE_2D, textures[current].id );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
/* Specify our 256x256 black texture. */
glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGB,
textures[current].poly_width,
textures[current].poly_height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
pixels );
free( pixels );
}
skip_rows += textures[current].movie_height;
}
/* Simple state setup at the end. */
glClearColor( 0.0, 0.0, 0.0, 0.0 );
return glGetError( );
}
/*
* Free any resources associated with the movie player.
*/
void glmovie_quit( void )
{
glDeleteTextures( num_texture_rows * num_texture_cols, texture_ids );
free( texture_ids );
free( textures );
}

122
smpeg/src/glmovie.c Normal file
View file

@ -0,0 +1,122 @@
/* HACK
* If you stick glx.h before MPEG.h, the preprocessor
* will start replacing the MPEG methods Status with an
* X11 variable type... blech.
*/
#include "smpeg.h"
#include "SDL.h"
#include <stdlib.h>
#include <string.h>
/*#include <unistd.h>*/
#include "glmovie.h"
static void glmpeg_update( SDL_Surface*, Sint32, Sint32, Uint32, Uint32 );
int main( int argc, char* argv[] )
{
SMPEG* mpeg;
SMPEG_Info mpeg_info;
SDL_Surface* screen;
SDL_Surface* surface;
if( argc < 2 ) {
fprintf( stderr, "Usage: %s file.mpg\n", argv[0]);
return 1;
}
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 ) {
fprintf( stderr, "glmovie: I couldn't initizlize SDL (shrug)\n" );
return 1;
}
mpeg = SMPEG_new( argv[1], &mpeg_info, 1 );
if( !mpeg ) {
fprintf( stderr, "glmovie: I'm not so sure about this %s file...\n", argv[1] );
SDL_Quit();
return 1;
}
/* Grab the mouse and input and set the video mode */
SDL_ShowCursor(0);
//SDL_WM_GrabInput(SDL_GRAB_ON);
screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); //|SDL_FULLSCREEN);
if ( !screen ) {
fprintf( stderr, "glmovie: Couldn't set 640x480 GL video mode: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
/* Everything needs to be in RGB for GL, but needs to be 32-bit for SMPEG. */
surface = SDL_AllocSurface( SDL_SWSURFACE,
mpeg_info.width,
mpeg_info.height,
32,
0x000000FF,
0x0000FF00,
0x00FF0000,
0xFF000000 );
if( !surface ) {
fprintf( stderr, "glmovie: I couldn't make a surface (boo hoo)\n" );
SDL_Quit();
exit( 1 );
}
/* *Initialize* with mpeg size. */
if ( glmovie_init( mpeg_info.width, mpeg_info.height ) != GL_NO_ERROR ) {
fprintf( stderr, "glmovie: glmovie_init() failed!\n" );
SDL_Quit();
exit( 1 );
}
/* *Resize* with window size. */
glmovie_resize( screen->w, screen->h );
SMPEG_setdisplay( mpeg, surface, NULL, glmpeg_update );
SMPEG_play( mpeg );
while( SMPEG_status( mpeg ) == SMPEG_PLAYING ) {
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_KEYDOWN:
if ( event.key.keysym.sym == SDLK_ESCAPE ) {
SMPEG_stop( mpeg );
}
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_QUIT:
SMPEG_stop( mpeg );
break;
}
}
SDL_Delay(100);
}
glmovie_quit( );
SDL_Quit();
return 0;
}
static void glmpeg_update( SDL_Surface* surface, Sint32 x, Sint32 y, Uint32 w, Uint32 h )
{
GLenum error;
if (( !surface ) || ( !surface->pixels )) {
fprintf(stderr, "\n\nERROR: There's no surface for drawing?!\n\n");
exit(1);
}
glmovie_draw( (GLubyte*) surface->pixels );
error = glGetError( );
if( error != GL_NO_ERROR ) {
fprintf( stderr, "glmovie: GL error: %s\n", gluErrorString( error ) );
exit( 1 );
}
SDL_GL_SwapBuffers();
}

23
smpeg/src/glmovie.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef _GLMOVIE_H_
#define _GLMOVIE_H_
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
GLenum glmovie_init( GLuint, GLuint );
void glmovie_quit( void );
void glmovie_draw( GLubyte* );
void glmovie_resize( GLuint, GLuint );
GLuint glmovie_next_power_of_2( GLuint seed );
GLboolean glmovie_is_power_of_2( GLuint value );
#ifdef __cplusplus
}
#endif
#endif

29
smpeg/src/gtv.1 Normal file
View file

@ -0,0 +1,29 @@
.TH GTV 1
.SH NAME
gtv \- MPEG audio (MP3) and video (MPEG-1) player with GTK+ GUI
.SH SYNOPSIS
\fBgtv\fR \fIfile\fR
.SH DESCRIPTION
.I gtv
is an MPEG audio and video player that uses the SDL MPEG Player Library.
It can play back MPEG audio (layer 1, 2 and 3), MPEG video (MPEG-1) and
MPEG system (audio and video combined) files. MPEG-2 video files (as found
on DVDs) are not supported.
.PP
The video player works best on a 16 bit color depth X11 display,
it works on other color depths with reduced speed as well. You'll need a
CPU with 300 MHz or more to play back an MPEG system stream with 25 frames
per secons (fps) at full speed.
.SH "SEE ALSO"
SMPEG home page at http://www.lokigames.com/development/smpeg.php3
.SH AUTHOR
The SDL MPEG Player Library was written by Karl Robillard and Sam Lantinga
of Loki Entertainment Software. Please report any bugs and/or fixes to
smpeg@lokigames.com.
.PP
This manual page was written by Stefan Gybas <sgybas@debian.org> for the
Debian GNU/Linux system, but may be used elsewhere under the GPL.

1317
smpeg/src/gtv.c Normal file

File diff suppressed because it is too large Load diff

26
smpeg/src/gtv.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef GTV_H
#define GTV_H
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "smpeg.h"
#define FILENAME_BUFFER_SIZE 256
#ifdef __cplusplus
extern "C" {
#endif
/* Nothing here presently. */
#ifdef __cplusplus
}
#endif
#endif

251
smpeg/src/install-sh Normal file
View file

@ -0,0 +1,251 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

6864
smpeg/src/ltmain.sh Normal file

File diff suppressed because it is too large Load diff

283
smpeg/src/missing Normal file
View file

@ -0,0 +1,283 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
# Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
run=:
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
else
configure_ac=configure.in
fi
case "$1" in
--run)
# Try to run requested program, and just exit if it succeeds.
run=
shift
"$@" && exit 0
;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case "$1" in
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch]"
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing 0.3 - GNU automake"
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
aclocal)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case "$f" in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if [ ! -f y.tab.h ]; then
echo >y.tab.h
fi
if [ ! -f y.tab.c ]; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if [ ! -f lex.yy.c ]; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
help2man)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
fi
if [ -f "$file" ]; then
touch $file
else
test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page"
exit 1
fi
;;
makeinfo)
if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
# We have makeinfo, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
fi
touch $file
;;
tar)
shift
if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run"
exit 1
fi
# We have already tried tar in the generic part.
# Look for gnutar/gtar before invocation to avoid ugly error
# messages.
if (gnutar --version > /dev/null 2>&1); then
gnutar ${1+"$@"} && exit 0
fi
if (gtar --version > /dev/null 2>&1); then
gtar ${1+"$@"} && exit 0
fi
firstarg="$1"
if shift; then
case "$firstarg" in
*o*)
firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" ${1+"$@"} && exit 0
;;
esac
case "$firstarg" in
*h*)
firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" ${1+"$@"} && exit 0
;;
esac
fi
echo 1>&2 "\
WARNING: I can't seem to be able to run \`tar' with the given arguments.
You may want to install GNU tar or Free paxutils, or check the
command line arguments."
exit 1
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and you do not seem to have it handy on your
system. You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequirements for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0

40
smpeg/src/mkinstalldirs Normal file
View file

@ -0,0 +1,40 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
# $Id: mkinstalldirs 9 1999-10-21 15:55:01Z hercules $
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp"
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

56
smpeg/src/plaympeg.1 Normal file
View file

@ -0,0 +1,56 @@
.TH PLAYMPEG 1
.SH NAME
plaympeg \- MPEG audio (MP3) and video (MPEG-1) player
.SH SYNOPSIS
\fBplaympeg\fR [\fIoptions\fR] \fIfile ...\fR
.SH DESCRIPTION
.I plaympeg
is an MPEG audio and video player that uses the SDL MPEG Player Library.
It can play back MPEG audio (layer 1, 2 and 3), MPEG video (MPEG-1) and
MPEG system (audio and video combined) files. MPEG-2 video files (as found
on DVDs) are not supported.
.PP
The video player works best on a 16 bit color depth X11 display,
it works on other color depths with reduced speed as well. You'll need a
CPU with 300 MHz or more to play back an MPEG system stream with 25 frames
per secons (fps) at full speed.
.SH OPTIONS
.TP
.B \--help
Show short usage information
.TP
.B \--noaudio
Don't play the audio stream (if available)
.TP
.B \--novideo
Don't play the video stream (if available)
.TP
.B \--fullscreen
Play the MPEG video stream in fullscreen mode (this requires root privileges
or a setuid plaympeg binary)
.TP
.B \-2, \--double
Play the MPEG video stream at double size
.TP
.B \-l, \--loop
Play the stream (audio or video) over and over again
.TP
.B \-v N, \--volume N
Set the volume of the audio stream to N% (N in the range of 0 to 100)
.TP
.B \-s S, \--scale S
Play the MPEG video stream at S size
.SH "SEE ALSO"
SMPEG home page at http://www.lokigames.com/development/smpeg.php3
.SH AUTHOR
The SDL MPEG Player Library was written by Karl Robillard and Sam Lantinga
of Loki Entertainment Software. Please report any bugs and/or fixes to
smpeg@lokigames.com.
.PP
This manual page was written by Stefan Gybas <sgybas@debian.org> for the
Debian GNU/Linux system, but may be used elsewhere under the GPL.

910
smpeg/src/plaympeg.c Normal file
View file

@ -0,0 +1,910 @@
/*
plaympeg - Sample MPEG player using the SMPEG library
Copyright (C) 1999 Loki Entertainment Software
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#ifdef unix
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#define NET_SUPPORT /* General network support */
#define RAW_SUPPORT /* Raw data transport support */
#define HTTP_SUPPORT /* HTTP support */
#define FTP_SUPPORT /* FTP support */
#ifdef linux
#define VCD_SUPPORT /* Video CD support */
#endif
#endif
#ifdef NET_SUPPORT
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif
#ifdef VCD_SUPPORT
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/cdrom.h>
#endif
#include "smpeg.h"
void usage(char *argv0)
{
printf(
"Usage: %s [options] file ...\n"
"Where the options are one of:\n"
" --noaudio Don't play audio stream\n"
" --novideo Don't play video stream\n"
" --fullscreen Play MPEG in fullscreen mode\n"
" --double or -2 Play MPEG at double size\n"
" --loop or -l Play MPEG over and over\n"
" --bilinear Use software bilinear filtering\n"
" --volume N or -v N Set audio volume to N (0-100)\n"
" --title T or -t T Set window's title to T\n"
" --scale wxh or -s wxh Play MPEG at given resolution\n"
" --seek N or -S N Skip N bytes\n"
#ifdef USE_SYSTEM_TIMESTAMP
" --skip N or -k N Skip N seconds\n"
#endif
" --help or -h\n"
" --version or -V\n"
"Specifying - as filename will use stdin for input\n", argv0);
}
#ifdef NET_SUPPORT
int is_address_multicast(unsigned long address)
{
if((address & 255) >= 224 && (address & 255) <= 239) return(1);
return(0);
}
int tcp_open(char * address, int port)
{
struct sockaddr_in stAddr;
struct hostent * host;
int sock;
struct linger l;
memset(&stAddr,0,sizeof(stAddr));
stAddr.sin_family = AF_INET ;
stAddr.sin_port = htons(port);
if((host = gethostbyname(address)) == NULL) return(0);
stAddr.sin_addr = *((struct in_addr *) host->h_addr_list[0]) ;
if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return(0);
l.l_onoff = 1; l.l_linger = 5;
if(setsockopt(sock, SOL_SOCKET, SO_LINGER, (char*) &l, sizeof(l)) < 0) return(0);
if(connect(sock, (struct sockaddr *) &stAddr, sizeof(stAddr)) < 0) return(0);
return(sock);
}
int udp_open(char * address, int port)
{
int enable = 1L;
struct sockaddr_in stAddr;
struct sockaddr_in stLclAddr;
struct ip_mreq stMreq;
struct hostent * host;
int sock;
stAddr.sin_family = AF_INET;
stAddr.sin_port = htons(port);
if((host = gethostbyname(address)) == NULL) return(0);
stAddr.sin_addr = *((struct in_addr *) host->h_addr_list[0]) ;
/* Create a UDP socket */
if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return(0);
/* Allow multiple instance of the client to share the same address and port */
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof(unsigned long int)) < 0) return(0);
/* If the address is multicast, register to the multicast group */
if(is_address_multicast(stAddr.sin_addr.s_addr))
{
/* Bind the socket to port */
stLclAddr.sin_family = AF_INET;
stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY);
stLclAddr.sin_port = stAddr.sin_port;
if(bind(sock, (struct sockaddr*) & stLclAddr, sizeof(stLclAddr)) < 0) return(0);
/* Register to a multicast address */
stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr;
stMreq.imr_interface.s_addr = INADDR_ANY;
if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) & stMreq, sizeof(stMreq)) < 0) return(0);
}
else
{
/* Bind the socket to port */
stLclAddr.sin_family = AF_INET;
stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY);
stLclAddr.sin_port = htons(0);
if(bind(sock, (struct sockaddr*) & stLclAddr, sizeof(stLclAddr)) < 0) return(0);
}
return(sock);
}
#ifdef RAW_SUPPORT
int raw_open(char * arg)
{
char * host;
int port;
int sock;
/* Check for URL syntax */
if(strncmp(arg, "raw://", strlen("raw://"))) return(0);
/* Parse URL */
port = 0;
host = arg + strlen("raw://");
if(strchr(host, ':') != NULL) /* port is specified */
{
port = atoi(strchr(host, ':') + 1);
*strchr(host, ':') = 0;
}
/* Open a UDP socket */
if(!(sock = udp_open(host, port)))
perror("raw_open");
return(sock);
}
#endif
#ifdef HTTP_SUPPORT
int http_open(char * arg)
{
char * host;
int port;
char * request;
int tcp_sock;
char http_request[1024];
char c;
/* Check for URL syntax */
if(strncmp(arg, "http://", strlen("http://"))) return(0);
/* Parse URL */
port = 80;
host = arg + strlen("http://");
if((request = strchr(host, '/')) == NULL) return(0);
*request++ = 0;
if(strchr(host, ':') != NULL) /* port is specified */
{
port = atoi(strchr(host, ':') + 1);
*strchr(host, ':') = 0;
}
/* Open a TCP socket */
if(!(tcp_sock = tcp_open(host, port)))
{
perror("http_open");
return(0);
}
/* Send HTTP GET request */
sprintf(http_request,
"GET /%s HTTP/1.0\r\n"
"User-Agent: Mozilla/2.0 (Win95; I)\r\n"
"Pragma: no-cache\r\n"
"Host: %s\r\n"
"Accept: */*\r\n"
"\r\n",
request, host);
send(tcp_sock, http_request, strlen(http_request), 0);
/* Parse server reply */
do read(tcp_sock, &c, sizeof(char)); while(c != ' ');
read(tcp_sock, http_request, 4*sizeof(char));
http_request[4] = 0;
if(strcmp(http_request, "200 "))
{
fprintf(stderr, "http_open: ");
do {
read(tcp_sock, &c, sizeof(char));
fprintf(stderr, "%c", c);
}
while(c != '\r');
fprintf(stderr, "\n");
return(0);
}
return(tcp_sock);
}
#endif
#ifdef FTP_SUPPORT
int ftp_get_reply(int tcp_sock)
{
int i;
char c;
char answer[1024];
do {
/* Read a line */
for(i = 0, c = 0; i < 1024 && c != '\n'; i++)
{
read(tcp_sock, &c, sizeof(char));
answer[i] = c;
}
answer[i] = 0;
fprintf(stderr, answer + 4);
}
while(answer[3] == '-');
answer[3] = 0;
return(atoi(answer));
}
int ftp_open(char * arg)
{
char * host;
int port;
char * dir;
char * file;
int tcp_sock;
int data_sock;
char ftp_request[1024];
struct sockaddr_in stLclAddr;
socklen_t namelen;
int i;
/* Check for URL syntax */
if(strncmp(arg, "ftp://", strlen("ftp://"))) return(0);
/* Parse URL */
port = 21;
host = arg + strlen("ftp://");
if((dir = strchr(host, '/')) == NULL) return(0);
*dir++ = 0;
if((file = strrchr(dir, '/')) == NULL) {
file = dir;
dir = NULL;
} else
*file++ = 0;
if(strchr(host, ':') != NULL) /* port is specified */
{
port = atoi(strchr(host, ':') + 1);
*strchr(host, ':') = 0;
}
/* Open a TCP socket */
if(!(tcp_sock = tcp_open(host, port)))
{
perror("ftp_open");
return(0);
}
/* Send FTP USER and PASS request */
ftp_get_reply(tcp_sock);
sprintf(ftp_request, "USER anonymous\r\n");
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 331) return(0);
sprintf(ftp_request, "PASS smpeguser@\r\n");
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 230) return(0);
sprintf(ftp_request, "TYPE I\r\n");
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 200) return(0);
if(dir != NULL)
{
sprintf(ftp_request, "CWD %s\r\n", dir);
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 250) return(0);
}
/* Get interface address */
namelen = sizeof(stLclAddr);
if(getsockname(tcp_sock, (struct sockaddr *) &stLclAddr, &namelen) < 0)
return(0);
/* Open data socket */
if ((data_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) return(0);
stLclAddr.sin_family = AF_INET;
/* Get the first free port */
for(i = 0; i < 0xC000; i++) {
stLclAddr.sin_port = htons(0x4000 + i);
if(bind(data_sock, (struct sockaddr *) &stLclAddr, sizeof(stLclAddr)) >= 0) break;
}
port = 0x4000 + i;
if(listen(data_sock, 1) < 0) return(0);
i = ntohl(stLclAddr.sin_addr.s_addr);
sprintf(ftp_request, "PORT %d,%d,%d,%d,%d,%d\r\n",
(i >> 24) & 0xFF, (i >> 16) & 0xFF,
(i >> 8) & 0xFF, i & 0xFF,
(port >> 8) & 0xFF, port & 0xFF);
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 200) return(0);
sprintf(ftp_request, "RETR %s\r\n", file);
send(tcp_sock, ftp_request, strlen(ftp_request), 0);
if(ftp_get_reply(tcp_sock) != 150) return(0);
return(accept(data_sock, NULL, NULL));
}
#endif
#endif
#ifdef VCD_SUPPORT
int vcd_read(int fd, int lba, unsigned char *buf)
{
struct cdrom_msf *msf;
msf = (struct cdrom_msf*) buf;
msf->cdmsf_min0 = (lba + CD_MSF_OFFSET) / CD_FRAMES / CD_SECS;
msf->cdmsf_sec0 = (lba + CD_MSF_OFFSET) / CD_FRAMES % CD_SECS;
msf->cdmsf_frame0 = (lba + CD_MSF_OFFSET) % CD_FRAMES;
return(ioctl(fd, CDROMREADMODE2, buf));
}
int vcd_open(char * arg)
{
struct stat buf;
struct cdrom_tocentry toc;
char *pip;
int track;
int pipe_fd[2];
int fd;
int pid, parent;
unsigned char * buffer;
/* Track defaults to 02, unless requested otherwise */
track = 02;
pip = strrchr(arg, ':');
if ( pip ) {
*pip = '\0';
track = atoi(pip+1) + 1;
}
/* See if the CD-ROM device file exists */
if ( (stat(arg, &buf) < 0) || !S_ISBLK(buf.st_mode) ) {
if ( pip ) {
*pip = ':';
}
return(0);
}
fd = open(arg, O_RDONLY, 0);
if ( fd < 0 ) {
if ( pip ) {
*pip = ':';
}
return(0);
}
/* Track 02 (changed to 'track') contains MPEG data */
if ( track < 2 ) {
printf("Warning: VCD data normally starts on track 2\n");
}
toc.cdte_track = track;
toc.cdte_format = CDROM_LBA;
if(ioctl(fd, CDROMREADTOCENTRY, &toc) < 0) return(0);
if(pipe(pipe_fd) < 0) return(0);
parent = getpid();
pid = fork();
if(pid < 0) return(0);
if(!pid)
{
/* Child process fills the pipe */
int pos;
struct timeval timeout;
fd_set fdset;
buffer = (unsigned char *) malloc(CD_FRAMESIZE_RAW0);
for(pos = toc.cdte_addr.lba; vcd_read(fd, pos, buffer) >= 0; pos ++)
{
if(kill(parent, 0) < 0) break;
FD_ZERO(&fdset);
FD_SET(pipe_fd[1], &fdset);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
if(select(pipe_fd[1]+1, NULL, &fdset, NULL, &timeout) <= 0) break;
if(write(pipe_fd[1], buffer, CD_FRAMESIZE_RAW0) < 0) break;
}
free(buffer);
exit(0);
}
return(pipe_fd[0]);
}
#endif
void update(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
if ( screen->flags & SDL_DOUBLEBUF ) {
SDL_Flip(screen);
}
}
/* Flag telling the UI that the movie or song should be skipped */
int done;
void next_movie(int sig)
{
done = 1;
}
int main(int argc, char *argv[])
{
int use_audio, use_video;
int fullscreen;
int scalesize;
int scale_width, scale_height;
int loop_play;
int i, pause;
int volume;
Uint32 seek;
float skip;
int bilinear_filtering;
SDL_Surface *screen;
SMPEG *mpeg;
SMPEG_Info info;
char *basefile;
const char *title = NULL;
SDL_version sdlver;
SMPEG_version smpegver;
int fd;
char buf[32];
int status;
/* Get the command line options */
use_audio = 1;
use_video = 1;
fullscreen = 0;
scalesize = 1;
scale_width = 0;
scale_height = 0;
loop_play = 0;
volume = 100;
seek = 0;
skip = 0;
bilinear_filtering = 0;
fd = 0;
for ( i=1; argv[i] && (argv[i][0] == '-') && (argv[i][1] != 0); ++i ) {
if ( (strcmp(argv[i], "--noaudio") == 0) ||
(strcmp(argv[i], "--nosound") == 0) ) {
use_audio = 0;
} else
if ( strcmp(argv[i], "--novideo") == 0 ) {
use_video = 0;
} else
if ( strcmp(argv[i], "--fullscreen") == 0 ) {
fullscreen = 1;
} else
if ((strcmp(argv[i], "--double") == 0)||(strcmp(argv[i], "-2") == 0)) {
scalesize = 2;
} else
if ((strcmp(argv[i], "--loop") == 0) || (strcmp(argv[i], "-l") == 0)) {
loop_play = 1;
} else
if ( strcmp(argv[i], "--bilinear") == 0 ) {
bilinear_filtering = 1;
} else
if ((strcmp(argv[i], "--seek") == 0)||(strcmp(argv[i], "-S") == 0)) {
++i;
if ( argv[i] ) {
seek = atol(argv[i]);
}
} else
if ((strcmp(argv[i], "--skip") == 0)||(strcmp(argv[i], "-k") == 0)) {
++i;
if ( argv[i] ) {
skip = (float)atof(argv[i]);
}
} else
if ((strcmp(argv[i], "--volume") == 0)||(strcmp(argv[i], "-v") == 0)) {
++i;
if (i >= argc)
{
fprintf(stderr, "Please specify volume when using --volume or -v\n");
return(1);
}
if ( argv[i] ) {
volume = atoi(argv[i]);
}
if ( ( volume < 0 ) || ( volume > 100 ) ) {
fprintf(stderr, "Volume must be between 0 and 100\n");
volume = 100;
}
} else
if ((strcmp(argv[i], "--title") == 0)||(strcmp(argv[i], "-t") == 0)) {
++i;
if (i >= argc)
{
fprintf(stderr, "Please specify title when using --title or -t\n");
return(1);
}
if ( argv[i] ) {
title = argv[i];
}
} else
if ((strcmp(argv[i], "--version") == 0) ||
(strcmp(argv[i], "-V") == 0)) {
sdlver = *SDL_Linked_Version();
SMPEG_VERSION(&smpegver);
printf("SDL version: %d.%d.%d\n"
"SMPEG version: %d.%d.%d\n",
sdlver.major, sdlver.minor, sdlver.patch,
smpegver.major, smpegver.minor, smpegver.patch);
return(0);
} else
if ((strcmp(argv[i], "--scale") == 0)||(strcmp(argv[i], "-s") == 0)) {
++i;
if ( argv[i] ) {
sscanf(argv[i], "%dx%d", &scale_width, &scale_height);
}
} else
if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)) {
usage(argv[0]);
return(0);
} else {
fprintf(stderr, "Warning: Unknown option: %s\n", argv[i]);
}
}
/* If there were no arguments just print the usage */
if (argc == 1) {
usage(argv[0]);
return(0);
}
#if defined(linux) || defined(__FreeBSD__) /* Plaympeg doesn't need a mouse */
putenv("SDL_NOMOUSE=1");
#endif
/* Play the mpeg files! */
status = 0;
for ( ; argv[i]; ++i ) {
/* Initialize SDL */
if ( use_video ) {
if ((SDL_Init(SDL_INIT_VIDEO) < 0) || !SDL_VideoDriverName(buf, 1)) {
fprintf(stderr, "Warning: Couldn't init SDL video: %s\n",
SDL_GetError());
fprintf(stderr, "Will ignore video stream\n");
use_video = 0;
}
}
if ( use_audio ) {
if ((SDL_Init(SDL_INIT_AUDIO) < 0) || !SDL_AudioDriverName(buf, 1)) {
fprintf(stderr, "Warning: Couldn't init SDL audio: %s\n",
SDL_GetError());
fprintf(stderr, "Will ignore audio stream\n");
use_audio = 0;
}
}
/* Allow Ctrl-C when there's no video output */
signal(SIGINT, next_movie);
/* Create the MPEG stream */
#ifdef NET_SUPPORT
#ifdef RAW_SUPPORT
/* Check if source is an IP address and port*/
if((fd = raw_open(argv[i])) != 0)
mpeg = SMPEG_new_descr(fd, &info, use_audio);
else
#endif
#ifdef HTTP_SUPPORT
/* Check if source is an http URL */
if((fd = http_open(argv[i])) != 0)
mpeg = SMPEG_new_descr(fd, &info, use_audio);
else
#endif
#ifdef FTP_SUPPORT
/* Check if source is an http URL */
if((fd = ftp_open(argv[i])) != 0)
mpeg = SMPEG_new_descr(fd, &info, use_audio);
else
#endif
#endif
#ifdef VCD_SUPPORT
/* Check if source is a CDROM device */
if((fd = vcd_open(argv[i])) != 0)
mpeg = SMPEG_new_descr(fd, &info, use_audio);
else
#endif
{
if(strcmp(argv[i], "-") == 0) /* Use stdin for input */
mpeg = SMPEG_new_descr(0, &info, use_audio);
else
mpeg = SMPEG_new(argv[i], &info, use_audio);
}
if ( SMPEG_error(mpeg) ) {
fprintf(stderr, "%s: %s\n", argv[i], SMPEG_error(mpeg));
SMPEG_delete(mpeg);
status = -1;
continue;
}
SMPEG_enableaudio(mpeg, use_audio);
SMPEG_enablevideo(mpeg, use_video);
SMPEG_setvolume(mpeg, volume);
/* Enable software bilinear filtering, if desired */
if ( bilinear_filtering ) {
SMPEG_Filter *filter;
filter = SMPEGfilter_bilinear();
filter = SMPEG_filter( mpeg, filter );
filter->destroy(filter);
}
/* Print information about the video */
basefile = strrchr(argv[i], '/');
if ( basefile ) {
++basefile;
} else {
basefile = argv[i];
}
if ( info.has_audio && info.has_video ) {
printf("%s: MPEG system stream (audio/video)\n", basefile);
} else if ( info.has_audio ) {
printf("%s: MPEG audio stream\n", basefile);
} else if ( info.has_video ) {
printf("%s: MPEG video stream\n", basefile);
}
if ( info.has_video ) {
printf("\tVideo %dx%d resolution\n", info.width, info.height);
}
if ( info.has_audio ) {
printf("\tAudio %s\n", info.audio_string);
}
if ( info.total_size ) {
printf("\tSize: %d\n", info.total_size);
}
if ( info.total_time ) {
printf("\tTotal time: %f\n", info.total_time);
}
/* Set up video display if needed */
if ( info.has_video && use_video ) {
const SDL_VideoInfo *video_info;
Uint32 video_flags;
int video_bpp;
int width, height;
/* Get the "native" video mode */
video_info = SDL_GetVideoInfo();
switch (video_info->vfmt->BitsPerPixel) {
case 16:
case 24:
case 32:
video_bpp = video_info->vfmt->BitsPerPixel;
break;
default:
video_bpp = 16;
break;
}
if ( scale_width ) {
width = scale_width;
} else {
width = info.width;
}
width *= scalesize;
if ( scale_height ) {
height = scale_height;
} else {
height = info.height;
}
height *= scalesize;
video_flags = SDL_SWSURFACE;
if ( fullscreen ) {
video_flags = SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE;
}
video_flags |= SDL_ASYNCBLIT;
video_flags |= SDL_RESIZABLE;
screen = SDL_SetVideoMode(width, height, video_bpp, video_flags);
if ( screen == NULL ) {
fprintf(stderr, "Unable to set %dx%d video mode: %s\n",
width, height, SDL_GetError());
continue;
}
if (title != NULL) {
SDL_WM_SetCaption(title, title);
} else {
SDL_WM_SetCaption(argv[i], "plaympeg");
}
if ( screen->flags & SDL_FULLSCREEN ) {
SDL_ShowCursor(0);
}
SMPEG_setdisplay(mpeg, screen, NULL, update);
SMPEG_scaleXY(mpeg, screen->w, screen->h);
} else {
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
/* Set any special playback parameters */
if ( loop_play ) {
SMPEG_loop(mpeg, 1);
}
/* Seek starting position */
if(seek) SMPEG_seek(mpeg, seek);
/* Skip seconds to starting position */
if(skip) SMPEG_skip(mpeg, skip);
/* Play it, and wait for playback to complete */
SMPEG_play(mpeg);
done = 0;
pause = 0;
while ( ! done && ( pause || (SMPEG_status(mpeg) == SMPEG_PLAYING) ) ) {
SDL_Event event;
while ( use_video && SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_VIDEORESIZE: {
SDL_Surface *old_screen = screen;
SMPEG_pause(mpeg);
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, screen->format->BitsPerPixel, screen->flags);
if ( old_screen != screen ) {
SMPEG_setdisplay(mpeg, screen, NULL, update);
}
SMPEG_scaleXY(mpeg, screen->w, screen->h);
SMPEG_pause(mpeg);
} break;
case SDL_KEYDOWN:
if ( (event.key.keysym.sym == SDLK_ESCAPE) || (event.key.keysym.sym == SDLK_q) ) {
// Quit
done = 1;
} else if ( event.key.keysym.sym == SDLK_RETURN ) {
// toggle fullscreen
if ( event.key.keysym.mod & KMOD_ALT ) {
SDL_WM_ToggleFullScreen(screen);
fullscreen = (screen->flags & SDL_FULLSCREEN);
SDL_ShowCursor(!fullscreen);
}
} else if ( event.key.keysym.sym == SDLK_UP ) {
// Volume up
if ( volume < 100 ) {
if ( event.key.keysym.mod & KMOD_SHIFT ) { // 10+
volume += 10;
} else if ( event.key.keysym.mod & KMOD_CTRL ) { // 100+
volume = 100;
} else { // 1+
volume++;
}
if ( volume > 100 )
volume = 100;
SMPEG_setvolume(mpeg, volume);
}
} else if ( event.key.keysym.sym == SDLK_DOWN ) {
// Volume down
if ( volume > 0 ) {
if ( event.key.keysym.mod & KMOD_SHIFT ) {
volume -= 10;
} else if ( event.key.keysym.mod & KMOD_CTRL ) {
volume = 0;
} else {
volume--;
}
if ( volume < 0 )
volume = 0;
SMPEG_setvolume(mpeg, volume);
}
} else if ( event.key.keysym.sym == SDLK_PAGEUP ) {
// Full volume
volume = 100;
SMPEG_setvolume(mpeg, volume);
} else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) {
// Volume off
volume = 0;
SMPEG_setvolume(mpeg, volume);
} else if ( event.key.keysym.sym == SDLK_SPACE ) {
// Toggle play / pause
if ( SMPEG_status(mpeg) == SMPEG_PLAYING ) {
SMPEG_pause(mpeg);
pause = 1;
} else {
SMPEG_play(mpeg);
pause = 0;
}
} else if ( event.key.keysym.sym == SDLK_RIGHT ) {
// Forward
if ( event.key.keysym.mod & KMOD_SHIFT ) {
SMPEG_skip(mpeg, 100);
} else if ( event.key.keysym.mod & KMOD_CTRL ) {
SMPEG_skip(mpeg, 50);
} else {
SMPEG_skip(mpeg, 5);
}
} else if ( event.key.keysym.sym == SDLK_LEFT ) {
// Reverse
if ( event.key.keysym.mod & KMOD_SHIFT ) {
} else if ( event.key.keysym.mod & KMOD_CTRL ) {
} else {
}
} else if ( event.key.keysym.sym == SDLK_KP_MINUS ) {
// Scale minus
if ( scalesize > 1 ) {
scalesize--;
}
} else if ( event.key.keysym.sym == SDLK_KP_PLUS ) {
// Scale plus
scalesize++;
} else if ( event.key.keysym.sym == SDLK_f ) {
// Toggle filtering on/off
if ( bilinear_filtering ) {
SMPEG_Filter *filter = SMPEGfilter_null();
filter = SMPEG_filter( mpeg, filter );
filter->destroy(filter);
bilinear_filtering = 0;
} else {
SMPEG_Filter *filter = SMPEGfilter_bilinear();
filter = SMPEG_filter( mpeg, filter );
filter->destroy(filter);
bilinear_filtering = 1;
}
}
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
SDL_Delay(1000/2);
}
SMPEG_delete(mpeg);
}
SDL_Quit();
#if defined(RAW_SUPPORT) || defined(HTTP_SUPPORT) || defined(FTP_SUPPORT) || \
defined(VCD_SUPPORT)
if(fd) close(fd);
#endif
return(status);
}

61
smpeg/src/smpeg-config.in Normal file
View file

@ -0,0 +1,61 @@
#!/bin/sh
prefix=@prefix@
exec_prefix=@exec_prefix@
exec_prefix_set=no
usage="\
Usage: @PACKAGE@-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cflags]"
if test $# -eq 0; then
echo "${usage}" 1>&2
exit 1
fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--prefix=*)
prefix=$optarg
if test $exec_prefix_set = no ; then
exec_prefix=$optarg
fi
;;
--prefix)
echo $prefix
;;
--exec-prefix=*)
exec_prefix=$optarg
exec_prefix_set=yes
;;
--exec-prefix)
echo $exec_prefix
;;
--version)
echo @VERSION@
;;
--cflags)
if test @includedir@ != /usr/include ; then
includes=-I@includedir@
fi
echo $includes -I@includedir@/smpeg `@SDL_CONFIG@ --cflags`
;;
--libs)
if [ "`uname`" = "SunOS" ]; then
libdirs="-L@libdir@ -R@libdir@"
else
libdirs="-L@libdir@ @SMPEG_RLD_FLAGS@"
fi
echo $libdirs -lsmpeg `@SDL_CONFIG@ --libs`
;;
*)
echo "${usage}" 1>&2
exit 1
;;
esac
shift
done

384
smpeg/src/smpeg.cpp Normal file
View file

@ -0,0 +1,384 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
- Modified by Michel Darricau from eProcess <mdarricau@eprocess.fr> for popcorn -
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* This is the C interface to the SMPEG library */
#include "MPEG.h"
#include "MPEGfilter.h"
#include "smpeg.h"
extern "C" {
/* This is the actual SMPEG object */
struct _SMPEG {
MPEG *obj;
};
static inline int sanityCheckByteorder(void)
{
int sane = 0;
union {
Uint32 ui32;
Uint8 ui8[4];
} swapper;
swapper.ui32 = 0x00000001;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
sane = (swapper.ui8[0] == 0x01);
#else
sane = (swapper.ui8[3] == 0x01);
#endif
if (!sane) {
fprintf(stderr,
"\n\n"
"*************************************************************\n"
" SMPEG ERROR: SDL is wrong about this platform's byte order!\n"
" You need to fix your SDL install before SMPEG can work!\n"
"*************************************************************\n"
"\n\n");
}
return(sane);
}
/* Create a new SMPEG object from an MPEG file.
On return, if 'info' is not NULL, it will be filled with information
about the MPEG object.
This function returns a new SMPEG object. Use SMPEG_error() to find out
whether or not there was a problem building the MPEG stream.
The sdl_audio parameter indicates if SMPEG should initialize the SDL audio
subsystem. If not, you will have to use the SMPEG_playaudio() function below
to extract the decoded data.
*/
SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio)
{
SMPEG *mpeg;
if (!sanityCheckByteorder())
return(NULL);
/* Create a new SMPEG object! */
mpeg = new SMPEG;
mpeg->obj = new MPEG(file, sdl_audio ? true : false);
/* Find out the details of the stream, if requested */
SMPEG_getinfo(mpeg, info);
/* We're done! */
return(mpeg);
}
/* The same as above except for file descriptors */
SMPEG* SMPEG_new_descr(int file, SMPEG_Info* info, int sdl_audio)
{
SMPEG *mpeg;
if (!sanityCheckByteorder())
return(NULL);
/* Create a new SMPEG object! */
mpeg = new SMPEG;
mpeg->obj = new MPEG(file, sdl_audio ? true : false);
/* Find out the details of the stream, if requested */
SMPEG_getinfo(mpeg, info);
/* We're done! */
return(mpeg);
}
/*
The same as above but for a raw chunk of data. SMPEG makes a copy of the
data, so the application is free to delete after a successful call to this
function.
*/
SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio)
{
SMPEG *mpeg;
if (!sanityCheckByteorder())
return(NULL);
/* Create a new SMPEG object! */
mpeg = new SMPEG;
mpeg->obj = new MPEG(data, size, sdl_audio ? true : false);
/* Find out the details of the stream, if requested */
SMPEG_getinfo(mpeg, info);
/* We're done! */
return(mpeg);
}
SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio)
{
SMPEG *mpeg;
if (!sanityCheckByteorder())
return(NULL);
/* Create a new SMPEG object! */
mpeg = new SMPEG;
mpeg->obj = new MPEG(src, sdl_audio ? true : false);
/* Find out the details of the stream, if requested */
SMPEG_getinfo(mpeg, info);
/* We're done! */
return(mpeg);
}
/* Get current information about an SMPEG object */
void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info )
{
if ( info ) {
MPEG_AudioInfo ainfo;
MPEG_VideoInfo vinfo;
MPEG_SystemInfo sinfo;
memset(info, 0, (sizeof *info));
if ( mpeg->obj ) {
info->has_audio = (mpeg->obj->audiostream != NULL);
if ( info->has_audio ) {
mpeg->obj->GetAudioInfo(&ainfo);
info->audio_current_frame = ainfo.current_frame;
sprintf(info->audio_string,
"MPEG-%d Layer %d %dkbit/s %dHz %s",
ainfo.mpegversion+1,
ainfo.layer,
ainfo.bitrate,
ainfo.frequency,
(ainfo.mode == 3) ? "mono" : "stereo");
}
info->has_video = (mpeg->obj->videostream != NULL);
if ( info->has_video ) {
mpeg->obj->GetVideoInfo(&vinfo);
info->width = vinfo.width;
info->height = vinfo.height;
info->current_frame = vinfo.current_frame;
info->current_fps = vinfo.current_fps;
}
if(mpeg->obj->system != NULL)
{
mpeg->obj->GetSystemInfo(&sinfo);
info->total_size = sinfo.total_size;
info->current_offset = sinfo.current_offset;
info->total_time = sinfo.total_time;
info->current_time = sinfo.current_time;
}
else
{
info->total_size = 0;
info->current_offset = 0;
}
}
}
}
/* Enable or disable audio playback in MPEG stream */
void SMPEG_enableaudio( SMPEG* mpeg, int enable )
{
mpeg->obj->EnableAudio(enable ? true : false);
}
/* Enable or disable video playback in MPEG stream */
void SMPEG_enablevideo( SMPEG* mpeg, int enable )
{
mpeg->obj->EnableVideo(enable ? true : false);
}
/* Delete an SMPEG object */
void SMPEG_delete( SMPEG* mpeg )
{
delete mpeg->obj;
delete mpeg;
}
/* Get the current status of an SMPEG object */
SMPEGstatus SMPEG_status( SMPEG* mpeg )
{
SMPEGstatus status;
status = SMPEG_ERROR;
/* Michel Darricau from eProcess <mdarricau@eprocess.fr> conflict name in popcorn */
switch (mpeg->obj->GetStatus()) {
case MPEG_STOPPED:
if ( ! mpeg->obj->WasError() ) {
status = SMPEG_STOPPED;
}
break;
case MPEG_PLAYING:
status = SMPEG_PLAYING;
break;
case MPEG_ERROR:
status = SMPEG_ERROR;
break;
}
return(status);
}
/* Set the audio volume of an MPEG stream */
void SMPEG_setvolume( SMPEG* mpeg, int volume )
{
mpeg->obj->Volume(volume);
}
/* Set the destination surface for MPEG video playback */
void SMPEG_setdisplay( SMPEG* mpeg, SDL_Surface* dst, SDL_mutex* surfLock,
SMPEG_DisplayCallback callback)
{
mpeg->obj->SetDisplay(dst, surfLock, callback);
}
/* Set or clear looping play on an SMPEG object */
void SMPEG_loop( SMPEG* mpeg, int repeat )
{
mpeg->obj->Loop(repeat ? true : false);
}
/* Scale pixel display on an SMPEG object */
void SMPEG_scale( SMPEG* mpeg, int scale )
{
MPEG_VideoInfo vinfo;
if ( mpeg->obj->videostream != NULL ) {
mpeg->obj->GetVideoInfo(&vinfo);
mpeg->obj->ScaleDisplayXY(vinfo.width*scale, vinfo.height*scale);
}
}
void SMPEG_scaleXY( SMPEG* mpeg, int w, int h )
{
mpeg->obj->ScaleDisplayXY(w, h);
}
/* Move the video display area within the destination surface */
void SMPEG_move( SMPEG* mpeg, int x, int y )
{
mpeg->obj->MoveDisplay(x, y);
}
/* Set the region of the video to be shown */
void SMPEG_setdisplayregion(SMPEG* mpeg, int x, int y, int w, int h)
{
mpeg->obj->SetDisplayRegion(x, y, w, h);
}
/* Play an SMPEG object */
void SMPEG_play( SMPEG* mpeg )
{
mpeg->obj->Play();
}
/* Pause/Resume playback of an SMPEG object */
void SMPEG_pause( SMPEG* mpeg )
{
mpeg->obj->Pause();
}
/* Stop playback of an SMPEG object */
void SMPEG_stop( SMPEG* mpeg )
{
mpeg->obj->Stop();
}
/* Rewind the play position of an SMPEG object to the beginning of the MPEG */
void SMPEG_rewind( SMPEG* mpeg )
{
mpeg->obj->Rewind();
}
/* Seek 'bytes' bytes of the MPEG */
void SMPEG_seek( SMPEG* mpeg, int bytes )
{
mpeg->obj->Seek(bytes);
}
/* Skip 'seconds' seconds of the MPEG */
void SMPEG_skip( SMPEG* mpeg, float seconds )
{
mpeg->obj->Skip(seconds);
}
/* Render a particular frame in the MPEG video */
void SMPEG_renderFrame( SMPEG* mpeg, int framenum )
{
mpeg->obj->RenderFrame(framenum);
}
/* Render the last frame of an MPEG video */
void SMPEG_renderFinal( SMPEG* mpeg, SDL_Surface* dst, int x, int y )
{
mpeg->obj->RenderFinal(dst, x, y);
}
/* Set video filter */
SMPEG_Filter * SMPEG_filter( SMPEG* mpeg, SMPEG_Filter * filter )
{
return((SMPEG_Filter *) mpeg->obj->Filter((SMPEG_Filter *) filter));
}
/* Exported function for general audio playback */
int SMPEG_playAudio( SMPEG* mpeg, Uint8 *stream, int len)
{
MPEGaudio *audio = mpeg->obj->GetAudio();
return Play_MPEGaudio(audio, stream, len);
}
void SMPEG_playAudioSDL( void* mpeg, Uint8 *stream, int len)
{
MPEGaudio *audio = ((SMPEG *)mpeg)->obj->GetAudio();
Play_MPEGaudio(audio, stream, len);
}
/* Get the best SDL audio spec for the audio stream */
int SMPEG_wantedSpec( SMPEG *mpeg, SDL_AudioSpec *wanted )
{
return (int)mpeg->obj->WantedSpec(wanted);
}
/* Inform SMPEG of the actual SDL audio spec used for sound playback */
void SMPEG_actualSpec( SMPEG *mpeg, SDL_AudioSpec *spec )
{
mpeg->obj->ActualSpec(spec);
}
/* Return NULL if there is no error in the MPEG stream, or an error message
if there was a fatal error in the MPEG stream for the SMPEG object.
*/
char *SMPEG_error( SMPEG* mpeg )
{
char *error = NULL;
if (mpeg == NULL) {
error = (char *) "NULL mpeg (unknown error)";
} else {
if ( mpeg->obj->WasError() ) {
error = mpeg->obj->TheError();
}
}
return(error);
}
/* Extern "C" */
};

207
smpeg/src/smpeg.h Normal file
View file

@ -0,0 +1,207 @@
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* This is the C interface to the SMPEG library */
#ifndef _SMPEG_H_
#define _SMPEG_H_
#include "SDL.h"
#include "SDL_mutex.h"
#include "SDL_audio.h"
#include "MPEGfilter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SMPEG_MAJOR_VERSION 0
#define SMPEG_MINOR_VERSION 4
#define SMPEG_PATCHLEVEL 5
typedef struct {
Uint8 major;
Uint8 minor;
Uint8 patch;
} SMPEG_version;
/* This macro can be used to fill a version structure with the compile-time
* version of the SDL library.
*/
#define SMPEG_VERSION(X) \
{ \
(X)->major = SMPEG_MAJOR_VERSION; \
(X)->minor = SMPEG_MINOR_VERSION; \
(X)->patch = SMPEG_PATCHLEVEL; \
}
/* This is the actual SMPEG object */
typedef struct _SMPEG SMPEG;
/* Used to get information about the SMPEG object */
typedef struct _SMPEG_Info {
int has_audio;
int has_video;
int width;
int height;
int current_frame;
double current_fps;
char audio_string[80];
int audio_current_frame;
Uint32 current_offset;
Uint32 total_size;
double current_time;
double total_time;
} SMPEG_Info;
/* Possible MPEG status codes */
typedef enum {
SMPEG_ERROR = -1,
SMPEG_STOPPED,
SMPEG_PLAYING
} SMPEGstatus;
/* Matches the declaration of SDL_UpdateRect() */
typedef void(*SMPEG_DisplayCallback)(SDL_Surface* dst, int x, int y,
unsigned int w, unsigned int h);
/* Create a new SMPEG object from an MPEG file.
On return, if 'info' is not NULL, it will be filled with information
about the MPEG object.
This function returns a new SMPEG object. Use SMPEG_error() to find out
whether or not there was a problem building the MPEG stream.
The sdl_audio parameter indicates if SMPEG should initialize the SDL audio
subsystem. If not, you will have to use the SMPEG_playaudio() function below
to extract the decoded data.
*/
extern DECLSPEC SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio);
/* The same as above for a file descriptor */
extern DECLSPEC SMPEG* SMPEG_new_descr(int file, SMPEG_Info* info, int sdl_audio);
/*
The same as above but for a raw chunk of data. SMPEG makes a copy of the
data, so the application is free to delete after a successful call to this
function.
*/
extern DECLSPEC SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio);
/* The same for a generic SDL_RWops structure. */
extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio);
/* Get current information about an SMPEG object */
extern DECLSPEC void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info );
/* Enable or disable audio playback in MPEG stream */
extern DECLSPEC void SMPEG_enableaudio( SMPEG* mpeg, int enable );
/* Enable or disable video playback in MPEG stream */
extern DECLSPEC void SMPEG_enablevideo( SMPEG* mpeg, int enable );
/* Delete an SMPEG object */
extern DECLSPEC void SMPEG_delete( SMPEG* mpeg );
/* Get the current status of an SMPEG object */
extern DECLSPEC SMPEGstatus SMPEG_status( SMPEG* mpeg );
/* Set the audio volume of an MPEG stream, in the range 0-100 */
extern DECLSPEC void SMPEG_setvolume( SMPEG* mpeg, int volume );
/* Set the destination surface for MPEG video playback
'surfLock' is a mutex used to synchronize access to 'dst', and can be NULL.
'callback' is a function called when an area of 'dst' needs to be updated.
If 'callback' is NULL, the default function (SDL_UpdateRect) will be used.
*/
extern DECLSPEC void SMPEG_setdisplay(SMPEG* mpeg, SDL_Surface* dst, SDL_mutex* surfLock,
SMPEG_DisplayCallback callback);
/* Set or clear looping play on an SMPEG object */
extern DECLSPEC void SMPEG_loop( SMPEG* mpeg, int repeat );
/* Scale pixel display on an SMPEG object */
extern DECLSPEC void SMPEG_scaleXY( SMPEG* mpeg, int width, int height );
extern DECLSPEC void SMPEG_scale( SMPEG* mpeg, int scale );
/* */
#define SMPEG_double(mpeg, on) \
SMPEG_scale(mpeg, (on) ? 2 : 1)
/* Move the video display area within the destination surface */
extern DECLSPEC void SMPEG_move( SMPEG* mpeg, int x, int y );
/* Set the region of the video to be shown */
extern DECLSPEC void SMPEG_setdisplayregion(SMPEG* mpeg, int x, int y, int w, int h);
/* Play an SMPEG object */
extern DECLSPEC void SMPEG_play( SMPEG* mpeg );
/* Pause/Resume playback of an SMPEG object */
extern DECLSPEC void SMPEG_pause( SMPEG* mpeg );
/* Stop playback of an SMPEG object */
extern DECLSPEC void SMPEG_stop( SMPEG* mpeg );
/* Rewind the play position of an SMPEG object to the beginning of the MPEG */
extern DECLSPEC void SMPEG_rewind( SMPEG* mpeg );
/* Seek 'bytes' bytes in the MPEG stream */
extern DECLSPEC void SMPEG_seek( SMPEG* mpeg, int bytes);
/* Skip 'seconds' seconds in the MPEG stream */
extern DECLSPEC void SMPEG_skip( SMPEG* mpeg, float seconds );
/* Render a particular frame in the MPEG video
API CHANGE: This function no longer takes a target surface and position.
Use SMPEG_setdisplay() and SMPEG_move() to set this information.
*/
extern DECLSPEC void SMPEG_renderFrame( SMPEG* mpeg, int framenum );
/* Render the last frame of an MPEG video */
extern DECLSPEC void SMPEG_renderFinal( SMPEG* mpeg, SDL_Surface* dst, int x, int y );
/* Set video filter */
extern DECLSPEC SMPEG_Filter * SMPEG_filter( SMPEG* mpeg, SMPEG_Filter * filter );
/* Return NULL if there is no error in the MPEG stream, or an error message
if there was a fatal error in the MPEG stream for the SMPEG object.
*/
extern DECLSPEC char *SMPEG_error( SMPEG* mpeg );
/* Exported callback function for audio playback.
The function takes a buffer and the amount of data to fill, and returns
the amount of data in bytes that was actually written. This will be the
amount requested unless the MPEG audio has finished.
*/
extern DECLSPEC int SMPEG_playAudio( SMPEG *mpeg, Uint8 *stream, int len );
/* Wrapper for SMPEG_playAudio() that can be passed to SDL and SDL_mixer
*/
extern DECLSPEC void SMPEG_playAudioSDL( void *mpeg, Uint8 *stream, int len );
/* Get the best SDL audio spec for the audio stream */
extern DECLSPEC int SMPEG_wantedSpec( SMPEG *mpeg, SDL_AudioSpec *wanted );
/* Inform SMPEG of the actual SDL audio spec used for sound playback */
extern DECLSPEC void SMPEG_actualSpec( SMPEG *mpeg, SDL_AudioSpec *spec );
#ifdef __cplusplus
}
#endif
#endif /* _SMPEG_H_ */

170
smpeg/src/smpeg.m4 Normal file
View file

@ -0,0 +1,170 @@
# Configure paths for SMPEG
# Nicolas Vignal 11/19/2000
# stolen from Sam Lantinga
# stolen from Manish Singh
# stolen back from Frank Belew
# stolen from Manish Singh
# Shamelessly stolen from Owen Taylor
dnl AM_PATH_SMPEG([MINIMUM-VERSION, [ACTION-IF-FOUND [,
ACTION-IF-NOT-FOUND]]])
dnl Test for SMPEG, and define SMPEG_CFLAGS and SMPEG_LIBS
dnl
AC_DEFUN([AM_PATH_SMPEG],
[dnl
dnl Get the cflags and libraries from the smpeg-config script
dnl
AC_ARG_WITH(smpeg-prefix,[ --with-smpeg-prefix=PFX Prefix where SMPEG is installed (optional)],
smpeg_prefix="$withval", smpeg_prefix="")
AC_ARG_WITH(smpeg-exec-prefix,[ --with-smpeg-exec-prefix=PFX Exec prefix where SMPEG is installed (optional)],
smpeg_exec_prefix="$withval", smpeg_exec_prefix="")
AC_ARG_ENABLE(smpegtest, [ --disable-smpegtest Do not try to compile and run a test SMPEG program],
, enable_smpegtest=yes)
if test x$smpeg_exec_prefix != x ; then
smpeg_args="$smpeg_args --exec-prefix=$smpeg_exec_prefix"
if test x${SMPEG_CONFIG+set} != xset ; then
SMPEG_CONFIG=$smpeg_exec_prefix/bin/smpeg-config
fi
fi
if test x$smpeg_prefix != x ; then
smpeg_args="$smpeg_args --prefix=$smpeg_prefix"
if test x${SMPEG_CONFIG+set} != xset ; then
SMPEG_CONFIG=$smpeg_prefix/bin/smpeg-config
fi
fi
AC_PATH_PROG(SMPEG_CONFIG, smpeg-config, no)
min_smpeg_version=ifelse([$1], ,0.2.7,$1)
AC_MSG_CHECKING(for SMPEG - version >= $min_smpeg_version)
no_smpeg=""
if test "$SMPEG_CONFIG" = "no" ; then
no_smpeg=yes
else
SMPEG_CFLAGS=`$SMPEG_CONFIG $smpegconf_args --cflags`
SMPEG_LIBS=`$SMPEG_CONFIG $smpegconf_args --libs`
smpeg_major_version=`$SMPEG_CONFIG $smpeg_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
smpeg_minor_version=`$SMPEG_CONFIG $smpeg_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
smpeg_micro_version=`$SMPEG_CONFIG $smpeg_config_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
if test "x$enable_smpegtest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $SMPEG_CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SMPEG_LIBS $SDL_LIBS"
dnl
dnl Now check if the installed SMPEG is sufficiently new. (Also sanity
dnl checks the results of smpeg-config to some extent
dnl
rm -f conf.smpegtest
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "smpeg.h"
char*
my_strdup (char *str)
{
char *new_str;
if (str)
{
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
strcpy (new_str, str);
}
else
new_str = NULL;
return new_str;
}
int main (int argc, char *argv[])
{
int major, minor, micro;
char *tmp_version;
/* This hangs on some systems (?)
system ("touch conf.smpegtest");
*/
{ FILE *fp = fopen("conf.smpegtest", "a"); if ( fp ) fclose(fp); }
/* HP/UX 9 (%@#!) writes to sscanf strings */
tmp_version = my_strdup("$min_smpeg_version");
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
printf("%s, bad version string\n", "$min_smpeg_version");
exit(1);
}
if (($smpeg_major_version > major) ||
(($smpeg_major_version == major) && ($smpeg_minor_version > minor)) ||
(($smpeg_major_version == major) && ($smpeg_minor_version == minor) && ($smpeg_micro_version >= micro)))
{
return 0;
}
else
{
printf("\n*** 'smpeg-config --version' returned %d.%d.%d, but the minimum version\n", $smpeg_major_version, $smpeg_minor_version, $smpeg_micro_version);
printf("*** of SMPEG required is %d.%d.%d. If smpeg-config is correct, then it is\n", major, minor, micro);
printf("*** best to upgrade to the required version.\n");
printf("*** If smpeg-config was wrong, set the environment variable SMPEG_CONFIG\n");
printf("*** to point to the correct copy of smpeg-config, and remove the file\n");
printf("*** config.cache before re-running configure\n");
return 1;
}
}
],, no_smpeg=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
if test "x$no_smpeg" = x ; then
AC_MSG_RESULT(yes)
ifelse([$2], , :, [$2])
else
AC_MSG_RESULT(no)
if test "$SMPEG_CONFIG" = "no" ; then
echo "*** The smpeg-config script installed by SMPEG could not be found"
echo "*** If SMPEG was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the SMPEG_CONFIG environment variable to the"
echo "*** full path to smpeg-config."
else
if test -f conf.smpegtest ; then
:
else
echo "*** Could not run SMPEG test program, checking why..."
CFLAGS="$CFLAGS $SMPEG_CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SMPEG_LIBS $SDL_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include "smpeg.h"
], [ return 0; ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding SMPEG or finding the wrong"
echo "*** version of SMPEG. If it is not finding SMPEG, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means SMPEG was incorrectly installed"
echo "*** or that you have moved SMPEG since it was installed. In the latter case, you"
echo "*** may want to edit the smpeg-config script: $SMPEG_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
SMPEG_CFLAGS=""
SMPEG_LIBS=""
ifelse([$3], , :, [$3])
fi
AC_SUBST(SMPEG_CFLAGS)
AC_SUBST(SMPEG_LIBS)
rm -f conf.smpegtest
])

90
smpeg/src/smpeg.spec.in Normal file
View file

@ -0,0 +1,90 @@
# Note that this is NOT a relocatable package
%define ver @VERSION@
%define rel 1
%define prefix /usr
Summary: SDL MPEG Library
Name: smpeg
Version: %ver
Release: %rel
Copyright: LGPL
Group: System Environment/Libraries
Source0: @PACKAGE@-%{PACKAGE_VERSION}.tar.gz
URL: http://www.lokigames.com/development/smpeg.php3
BuildRoot: /tmp/@PACKAGE@-%{PACKAGE_VERSION}-root
Packager: Sam Lantinga <hercules@lokigames.com>
Docdir: %{prefix}/doc
%description
SMPEG is based on UC Berkeley's mpeg_play software MPEG decoder
and SPLAY, an mpeg audio decoder created by Woo-jae Jung. We have
completed the initial work to wed these two projects in order to
create a general purpose MPEG video/audio player for the Linux OS.
%package devel
Summary: Libraries, includes and more to develop SMPEG applications.
Group: Development/Libraries
Requires: %{name}
%description devel
SMPEG is based on UC Berkeley's mpeg_play software MPEG decoder
and SPLAY, an mpeg audio decoder created by Woo-jae Jung. We have
completed the initial work to wed these two projects in order to
create a general purpose MPEG video/audio player for the Linux OS.
This is the libraries, include files and other resources you can use
to develop SMPEG applications.
%prep
rm -rf ${RPM_BUILD_ROOT}
%setup -q
%build
# Needed for snapshot releases.
if [ ! -f configure ]; then
CFLAGS="$RPM_OPT_FLAGS" ./autogen.sh --prefix=%prefix --disable-debug --disable-opengl-player
else
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix --disable-debug --disable-opengl-player
fi
if [ "$SMP" != "" ]; then
(make "MAKE=make -k -j $SMP"; exit 0)
make
else
make
fi
%install
rm -rf $RPM_BUILD_ROOT
make prefix=$RPM_BUILD_ROOT%{prefix} install
%clean
rm -rf $RPM_BUILD_ROOT
%post
/sbin/ldconfig
%postun
/sbin/ldconfig
%files
%defattr(-, root, root)
%doc CHANGES COPYING README
%{prefix}/lib/lib*.so.*
%{prefix}/bin/plaympeg
%{prefix}/bin/gtv
%{prefix}/man/*
%files devel
%defattr(-, root, root)
%doc CHANGES COPYING README
%{prefix}/bin/@PACKAGE@-config
%{prefix}/include/*
%{prefix}/lib/lib*.a
%{prefix}/lib/lib*.so
%changelog
* Fri Mar 3 2000 Sam Lantinga <hercules@lokigames.com>
- Split package into development and runtime packages