[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/movie movie.c
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus/src/movie movie.c |
Date: |
20 Dec 2003 14:49:00 +1100 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 03/12/20 14:49:00
Modified files:
src/movie : movie.c
Log message:
Tabs
Patches:
Index: stratagus/src/movie/movie.c
diff -u stratagus/src/movie/movie.c:1.19 stratagus/src/movie/movie.c:1.20
--- stratagus/src/movie/movie.c:1.19 Thu Nov 20 14:05:47 2003
+++ stratagus/src/movie/movie.c Sat Dec 20 14:48:59 2003
@@ -1,16 +1,16 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
-/address@hidden movie.c - Movie playback functions. */
+/address@hidden movie.c - Movie playback functions. */
//
-// (c) Copyright 2002-2003 by Lutz Sammer
+// (c) Copyright 2002-2004 by Lutz Sammer
//
// 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
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: movie.c,v 1.19 2003/11/20 03:05:47 jsalmon3 Exp $
+// $Id: movie.c,v 1.20 2003/12/20 03:48:59 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -55,132 +55,132 @@
#include "SDL.h"
#endif
-#ifdef USE_SDL /// Only supported with SDL for now
+#ifdef USE_SDL /// Only supported with SDL for now
-extern SDL_Surface* TheScreen; /// internal screen
+extern SDL_Surface* TheScreen; /// internal screen
/*----------------------------------------------------------------------------
--- Defines
+-- Defines
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
-local char MovieKeyPressed; /// Flag key is pressed to stop
+local char MovieKeyPressed; /// Flag key is pressed to stop
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Open a movie file.
+** Open a movie file.
**
-** @param name Filename of movie file.
+** @param name Filename of movie file.
**
-** @return Avi file handle on success.
+** @return Avi file handle on success.
*/
global AviFile* MovieOpen(const char* name)
{
- AviFile* avi;
- char buffer[PATH_MAX];
+ AviFile* avi;
+ char buffer[PATH_MAX];
- name = LibraryFileName(name, buffer);
- if (!(avi = AviOpen(name))) {
- return NULL;
- }
+ name = LibraryFileName(name, buffer);
+ if (!(avi = AviOpen(name))) {
+ return NULL;
+ }
- return avi;
+ return avi;
}
/**
-** Close a movie file.
+** Close a movie file.
**
-** @param avi Avi file handle.
+** @param avi Avi file handle.
*/
global void MovieClose(AviFile* avi)
{
- AviClose(avi);
+ AviClose(avi);
}
/**
-** Display the next movie frame.
+** Display the next movie frame.
**
-** @param avi Avi file handle.
-** @param pbi VP3 decoder.
-** @param overlay Output overlay.
-** @param rect Destination rectangle.
+** @param avi Avi file handle.
+** @param pbi VP3 decoder.
+** @param overlay Output overlay.
+** @param rect Destination rectangle.
**
-** @return True if eof.
+** @return True if eof.
*/
global int MovieDisplayFrame(AviFile* avi, PB_INSTANCE* pbi,
- SDL_Overlay* overlay, SDL_Rect rect)
+ SDL_Overlay* overlay, SDL_Rect rect)
{
- unsigned char* frame;
- int length;
- int i;
- YUV_BUFFER_CONFIG yuv;
+ unsigned char* frame;
+ int length;
+ int i;
+ YUV_BUFFER_CONFIG yuv;
- length = AviReadNextVideoFrame(avi, &frame);
- if (length < 0) { // EOF
- return 1;
- }
- if (length) {
- if (DecodeFrameToYUV(pbi, frame, length, -1, -1)) {
- fprintf(stderr, "DecodeFrameToYUV error\n");
- exit(-1);
- }
-
- SDL_LockYUVOverlay(overlay);
- GetYUVConfig(pbi, &yuv);
- for (i = 0; i < yuv.YHeight; ++i) { // copy Y
- memcpy(overlay->pixels[0] + i * overlay->pitches[0],
- yuv.YBuffer + (yuv.YHeight - i - 1) * yuv.YStride, yuv.YWidth);
- }
- for (i = 0; i < yuv.UVHeight; ++i) { // copy UV
- memcpy(overlay->pixels[1] + i * overlay->pitches[1],
- yuv.VBuffer + (yuv.UVHeight - i - 1) * yuv.UVStride,
- yuv.UVWidth);
- memcpy(overlay->pixels[2] + i * overlay->pitches[2],
- yuv.UBuffer + (yuv.UVHeight - i - 1) * yuv.UVStride,
- yuv.UVWidth);
+ length = AviReadNextVideoFrame(avi, &frame);
+ if (length < 0) { // EOF
+ return 1;
+ }
+ if (length) {
+ if (DecodeFrameToYUV(pbi, frame, length, -1, -1)) {
+ fprintf(stderr, "DecodeFrameToYUV error\n");
+ exit(-1);
+ }
+
+ SDL_LockYUVOverlay(overlay);
+ GetYUVConfig(pbi, &yuv);
+ for (i = 0; i < yuv.YHeight; ++i) { // copy Y
+ memcpy(overlay->pixels[0] + i * overlay->pitches[0],
+ yuv.YBuffer + (yuv.YHeight - i - 1) *
yuv.YStride, yuv.YWidth);
+ }
+ for (i = 0; i < yuv.UVHeight; ++i) { // copy UV
+ memcpy(overlay->pixels[1] + i * overlay->pitches[1],
+ yuv.VBuffer + (yuv.UVHeight - i - 1) *
yuv.UVStride,
+ yuv.UVWidth);
+ memcpy(overlay->pixels[2] + i * overlay->pitches[2],
+ yuv.UBuffer + (yuv.UVHeight - i - 1) *
yuv.UVStride,
+ yuv.UVWidth);
+ }
+ SDL_UnlockYUVOverlay(overlay);
}
- SDL_UnlockYUVOverlay(overlay);
- }
- SDL_DisplayYUVOverlay(overlay, &rect);
+ SDL_DisplayYUVOverlay(overlay, &rect);
- return 0;
+ return 0;
}
/*--------------------------------------------------------------------------*/
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackKey(unsigned dummy __attribute__((unused)))
{
- MovieKeyPressed = 0;
+ MovieKeyPressed = 0;
}
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackKey1(unsigned dummy __attribute__((unused)))
{
}
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackKey2(unsigned dummy1 __attribute__((unused)),
unsigned dummy2 __attribute__((unused)))
{
- MovieKeyPressed = 0;
+ MovieKeyPressed = 0;
}
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackKey3(unsigned dummy1 __attribute__((unused)),
unsigned dummy2 __attribute__((unused)))
@@ -188,16 +188,16 @@
}
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackKey4(unsigned dummy1 __attribute__((unused)),
unsigned dummy2 __attribute__((unused)))
{
- MovieKeyPressed = 0;
+ MovieKeyPressed = 0;
}
/**
-** Callback for input.
+** Callback for input.
*/
local void MovieCallbackMouse(int dummy_x __attribute__((unused)),
int dummy_y __attribute__((unused)))
@@ -205,172 +205,172 @@
}
/**
-** Callback for exit.
+** Callback for exit.
*/
local void MovieCallbackExit(void)
{
}
/**
-** Play a video file.
+** Play a video file.
**
-** @param name Filename of movie file.
-** @param flags Flags for movie playback.
+** @param name Filename of movie file.
+** @param flags Flags for movie playback.
**
-** @return True if file isn't a supported movie.
+** @return True if file isn't a supported movie.
**
-** @todo Support full screen and resolution changes.
+** @todo Support full screen and resolution changes.
*/
global int PlayMovie(const char* name, int flags)
{
- AviFile* avi;
- SDL_Overlay* overlay;
- PB_INSTANCE* pbi;
- EventCallback callbacks;
- SDL_Rect rect;
- int oldspeed;
+ AviFile* avi;
+ SDL_Overlay* overlay;
+ PB_INSTANCE* pbi;
+ EventCallback callbacks;
+ SDL_Rect rect;
+ int oldspeed;
- // FIXME: Should split this into lowlevel parts.
+ // FIXME: Should split this into lowlevel parts.
- if (!(avi = MovieOpen(name))) {
- return 1;
- }
+ if (!(avi = MovieOpen(name))) {
+ return 1;
+ }
- if (avi->AudioStream != -1) { // Only if audio available
- StopMusic();
- }
-
- //
- // Prepare video
- //
- if (flags & PlayMovieFullScreen) {
- DebugLevel0Fn("FIXME: full screen switch not supported\n");
- }
- overlay = SDL_CreateYUVOverlay(avi->Width, avi->Height,
- SDL_YV12_OVERLAY, TheScreen);
- if (!overlay) {
- fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
- exit(1);
- }
- if (overlay->hw_overlay) {
- DebugLevel0Fn("Got a hardware overlay.\n");
- }
- oldspeed = VideoSyncSpeed;
- VideoSyncSpeed = avi->FPS100 / FRAMES_PER_SECOND;
- SetVideoSync();
+ if (avi->AudioStream != -1) { // Only if audio available
+ StopMusic();
+ }
- StartDecoder(&pbi, avi->Width, avi->Height);
+ //
+ // Prepare video
+ //
+ if (flags & PlayMovieFullScreen) {
+ DebugLevel0Fn("FIXME: full screen switch not supported\n");
+ }
+ overlay = SDL_CreateYUVOverlay(avi->Width, avi->Height,
+ SDL_YV12_OVERLAY, TheScreen);
+ if (!overlay) {
+ fprintf(stderr, "Couldn't create overlay: %s\n",
SDL_GetError());
+ exit(1);
+ }
+ if (overlay->hw_overlay) {
+ DebugLevel0Fn("Got a hardware overlay.\n");
+ }
+ oldspeed = VideoSyncSpeed;
+ VideoSyncSpeed = avi->FPS100 / FRAMES_PER_SECOND;
+ SetVideoSync();
+
+ StartDecoder(&pbi, avi->Width, avi->Height);
#if defined(WITH_SOUND) && defined(USE_OGG)
- if (avi->AudioStream != -1) { // Only if audio available
- PlayAviOgg(avi);
- }
+ if (avi->AudioStream != -1) { // Only if audio available
+ PlayAviOgg(avi);
+ }
#endif
- callbacks.ButtonPressed = MovieCallbackKey;
- callbacks.ButtonReleased = MovieCallbackKey1;
- callbacks.MouseMoved = MovieCallbackMouse;
- callbacks.MouseExit = MovieCallbackExit;
- callbacks.KeyPressed = MovieCallbackKey2;
- callbacks.KeyReleased = MovieCallbackKey3;
- callbacks.KeyRepeated = MovieCallbackKey4;
- callbacks.NetworkEvent = NetworkEvent;
- callbacks.SoundReady = WriteSound;
-
- if (flags & PlayMovieZoomScreen) {
- if (flags & PlayMovieKeepAspect) {
- int wa;
- int ha;
-
- wa = VideoWidth * 100 / avi->Width;
- ha = VideoHeight * 100 / avi->Height;
- DebugLevel0Fn(" %d x %d\n" _C_ wa _C_ ha);
- if (wa < ha) { // Keep the aspect ratio
- rect.w = VideoWidth;
- rect.h = avi->Height * wa / 100;
- } else {
- rect.w = avi->Width * ha / 100;
- rect.h = VideoHeight;
- }
- } else { // Just zoom to max
- rect.w = VideoWidth;
- rect.h = VideoHeight;
- }
- } else {
- rect.w = avi->Width;
- rect.h = avi->Height;
- }
- rect.x = (VideoWidth - rect.w) / 2;
- rect.y = (VideoHeight - rect.h) / 2;
+ callbacks.ButtonPressed = MovieCallbackKey;
+ callbacks.ButtonReleased = MovieCallbackKey1;
+ callbacks.MouseMoved = MovieCallbackMouse;
+ callbacks.MouseExit = MovieCallbackExit;
+ callbacks.KeyPressed = MovieCallbackKey2;
+ callbacks.KeyReleased = MovieCallbackKey3;
+ callbacks.KeyRepeated = MovieCallbackKey4;
+ callbacks.NetworkEvent = NetworkEvent;
+ callbacks.SoundReady = WriteSound;
+
+ if (flags & PlayMovieZoomScreen) {
+ if (flags & PlayMovieKeepAspect) {
+ int wa;
+ int ha;
+
+ wa = VideoWidth * 100 / avi->Width;
+ ha = VideoHeight * 100 / avi->Height;
+ DebugLevel0Fn(" %d x %d\n" _C_ wa _C_ ha);
+ if (wa < ha) { // Keep the aspect ratio
+ rect.w = VideoWidth;
+ rect.h = avi->Height * wa / 100;
+ } else {
+ rect.w = avi->Width * ha / 100;
+ rect.h = VideoHeight;
+ }
+ } else { // Just zoom to max
+ rect.w = VideoWidth;
+ rect.h = VideoHeight;
+ }
+ } else {
+ rect.w = avi->Width;
+ rect.h = avi->Height;
+ }
+ rect.x = (VideoWidth - rect.w) / 2;
+ rect.y = (VideoHeight - rect.h) / 2;
- if (1) {
- int i;
+ if (1) {
+ int i;
- GetPbParam(pbi, PBC_SET_POSTPROC, &i);
- DebugLevel0Fn("Postprocess level %d\n" _C_ i);
- SetPbParam(pbi, PBC_SET_POSTPROC, 6);
- }
+ GetPbParam(pbi, PBC_SET_POSTPROC, &i);
+ DebugLevel0Fn("Postprocess level %d\n" _C_ i);
+ SetPbParam(pbi, PBC_SET_POSTPROC, 6);
+ }
- MovieKeyPressed = 1;
- while (MovieKeyPressed) {
+ MovieKeyPressed = 1;
+ while (MovieKeyPressed) {
- if (MovieDisplayFrame(avi, pbi, overlay, rect)) {
- break;
- }
+ if (MovieDisplayFrame(avi, pbi, overlay, rect)) {
+ break;
+ }
- WaitEventsOneFrame(&callbacks);
- }
+ WaitEventsOneFrame(&callbacks);
+ }
- if (avi->AudioStream != -1) { // Only if audio available
- StopMusic();
- }
+ if (avi->AudioStream != -1) { // Only if audio available
+ StopMusic();
+ }
- StopDecoder(&pbi);
- SDL_FreeYUVOverlay(overlay);
+ StopDecoder(&pbi);
+ SDL_FreeYUVOverlay(overlay);
- MovieClose(avi);
+ MovieClose(avi);
- VideoSyncSpeed = oldspeed;
- SetVideoSync();
+ VideoSyncSpeed = oldspeed;
+ SetVideoSync();
- return 0;
+ return 0;
}
#else
/**
-** Play a video file.
+** Play a video file.
**
-** @param file Filename of movie file.
-** @param flags Flags for movie playback.
+** @param file Filename of movie file.
+** @param flags Flags for movie playback.
**
-** @return True if file isn't a supported movie.
+** @return True if file isn't a supported movie.
**
-** @todo Support full screen and resolution changes.
+** @todo Support full screen and resolution changes.
*/
global int PlayMovie(const char* file, int flags)
{
- printf("FIXME: PlayMovie(\"%s\",%x) not supported.\n", file, flags);
+ printf("FIXME: PlayMovie(\"%s\",%x) not supported.\n", file, flags);
- return 1;
+ return 1;
}
#endif
/**
-** Initialize the movie module.
+** Initialize the movie module.
*/
global void InitMovie(void)
{
- VPInitLibrary();
+ VPInitLibrary();
}
/**
-** Cleanup the movie module.
+** Cleanup the movie module.
*/
global void CleanMovie(void)
{
- VPDeInitLibrary();
+ VPDeInitLibrary();
}
//@}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/movie movie.c,
address@hidden <=