[Scummvm-git-logs] scummvm master -> fcb3d6af8377dff8d7bfcc99a27356c6126e4ae6
dreammaster
dreammaster at scummvm.org
Sun Feb 7 17:23:31 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
b0545a2f69 AGS: Support playing AVI and MPEG videos
fcb3d6af83 AGS: Remove DirectX video playback code
Commit: b0545a2f697c7e5e77862da84273926c1e75197d
https://github.com/scummvm/scummvm/commit/b0545a2f697c7e5e77862da84273926c1e75197d
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-02-07T09:23:27-08:00
Commit Message:
AGS: Support playing AVI and MPEG videos
Changed paths:
engines/ags/engine/ac/global_video.cpp
engines/ags/engine/media/video/video.cpp
engines/ags/engine/media/video/video.h
diff --git a/engines/ags/engine/ac/global_video.cpp b/engines/ags/engine/ac/global_video.cpp
index e8183a3ec9..517cdbf88c 100644
--- a/engines/ags/engine/ac/global_video.cpp
+++ b/engines/ags/engine/ac/global_video.cpp
@@ -63,6 +63,10 @@ void pause_sound_if_necessary_and_play_video(const char *name, int skip, int fla
if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "ogv") == 0)) {
play_theora_video(name, skip, flags);
+ } else if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "mpg") == 0)) {
+ play_mpeg_video(name, skip, flags);
+ } else if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "avi") == 0)) {
+ play_avi_video(name, skip, flags);
} else {
char videoFilePath[MAX_PATH];
get_install_dir_path(videoFilePath, name);
diff --git a/engines/ags/engine/media/video/video.cpp b/engines/ags/engine/media/video/video.cpp
index b4c385a68e..09ef28dca1 100644
--- a/engines/ags/engine/media/video/video.cpp
+++ b/engines/ags/engine/media/video/video.cpp
@@ -20,6 +20,8 @@
*
*/
+#include "video/avi_decoder.h"
+#include "video/mpegps_decoder.h"
#include "video/theora_decoder.h"
#include "ags/shared/core/platform.h"
#include "ags/shared/core/types.h"
@@ -51,10 +53,7 @@ namespace AGS3 {
using AGS::Shared::AssetManager;
-void play_theora_video(const char *name, int skip, int flags) {
-#if !defined (USE_THEORADEC)
- Display("This games uses Theora videos but ScummVM has been compiled without Theora support");
-#else
+static void play_video(Video::VideoDecoder *decoder, const char *name, int skip, int flags) {
std::unique_ptr<Stream> video_stream(AssetManager::OpenAsset(name));
if (!video_stream) {
Display("Unable to load theora video '%s'", name);
@@ -72,10 +71,9 @@ void play_theora_video(const char *name, int skip, int flags) {
stop_all_sound_and_music();
}
- Video::TheoraDecoder decoder;
AGS::Shared::ScummVMReadStream *stream = new AGS::Shared::ScummVMReadStream(video_stream.get(), DisposeAfterUse::NO);
- if (!decoder.loadStream(stream)) {
+ if (!decoder->loadStream(stream)) {
delete stream;
Display("Unable to decode theora video '%s'", name);
return;
@@ -83,11 +81,11 @@ void play_theora_video(const char *name, int skip, int flags) {
update_polled_stuff_if_runtime();
- decoder.start();
- while (!SHOULD_QUIT && !decoder.endOfVideo()) {
- if (decoder.needsUpdate()) {
+ decoder->start();
+ while (!SHOULD_QUIT && !decoder->endOfVideo()) {
+ if (decoder->needsUpdate()) {
// Get the next video frame and draw onto the screen
- const Graphics::Surface *frame = decoder.decodeNextFrame();
+ const Graphics::Surface *frame = decoder->decodeNextFrame();
if (stretchVideo && frame->w == scr.w && frame->h == scr.h)
// Don't need to stretch video after all
@@ -123,6 +121,24 @@ void play_theora_video(const char *name, int skip, int flags) {
}
invalidate_screen();
+}
+
+void play_avi_video(const char *name, int skip, int flags) {
+ Video::AVIDecoder decoder;
+ play_video(&decoder, name, skip, flags);
+}
+
+void play_mpeg_video(const char *name, int skip, int flags) {
+ Video::MPEGPSDecoder decoder;
+ play_video(&decoder, name, skip, flags);
+}
+
+void play_theora_video(const char *name, int skip, int flags) {
+#if !defined (USE_THEORADEC)
+ Display("This games uses Theora videos but ScummVM has been compiled without Theora support");
+#else
+ Video::TheoraDecoder decoder;
+ play_video(&decoder, name, skip, flags);
#endif
}
diff --git a/engines/ags/engine/media/video/video.h b/engines/ags/engine/media/video/video.h
index 558189e3f7..77f9cd560a 100644
--- a/engines/ags/engine/media/video/video.h
+++ b/engines/ags/engine/media/video/video.h
@@ -25,6 +25,8 @@
namespace AGS3 {
+void play_avi_video(const char *name, int skip, int flags);
+void play_mpeg_video(const char *name, int skip, int flags);
void play_theora_video(const char *name, int skip, int flags);
void play_flc_file(int numb, int playflags);
Commit: fcb3d6af8377dff8d7bfcc99a27356c6126e4ae6
https://github.com/scummvm/scummvm/commit/fcb3d6af8377dff8d7bfcc99a27356c6126e4ae6
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-02-07T09:23:27-08:00
Commit Message:
AGS: Remove DirectX video playback code
Changed paths:
R engines/ags/engine/media/video/vmr9_graph.h
R engines/ags/engine/platform/windows/media/video/acwavi.cpp
R engines/ags/engine/platform/windows/media/video/acwavi3d.cpp
engines/ags/engine/ac/global_video.cpp
engines/ags/engine/gfx/ali3dscummvm.cpp
engines/ags/engine/gfx/ali3dscummvm.h
engines/ags/engine/platform/windows/acplwin.cpp
engines/ags/engine/platform/windows/gfx/ali3dd3d.cpp
engines/ags/engine/platform/windows/gfx/ali3dd3d.h
diff --git a/engines/ags/engine/ac/global_video.cpp b/engines/ags/engine/ac/global_video.cpp
index 517cdbf88c..a634bb2991 100644
--- a/engines/ags/engine/ac/global_video.cpp
+++ b/engines/ags/engine/ac/global_video.cpp
@@ -24,6 +24,7 @@
#include "ags/engine/ac/gamesetup.h"
#include "ags/engine/ac/gamestate.h"
#include "ags/engine/ac/global_audio.h"
+#include "ags/engine/ac/global_display.h"
#include "ags/engine/ac/global_game.h"
#include "ags/engine/ac/global_video.h"
#include "ags/engine/ac/path_helper.h"
@@ -52,9 +53,6 @@ void scrPlayVideo(const char *name, int skip, int flags) {
pause_sound_if_necessary_and_play_video(name, skip, flags);
}
-
-#ifndef AGS_NO_VIDEO_PLAYER
-
void pause_sound_if_necessary_and_play_video(const char *name, int skip, int flags) {
int musplaying = play.cur_music_number, i;
int ambientWas[MAX_SOUND_CHANNELS];
@@ -68,10 +66,7 @@ void pause_sound_if_necessary_and_play_video(const char *name, int skip, int fla
} else if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "avi") == 0)) {
play_avi_video(name, skip, flags);
} else {
- char videoFilePath[MAX_PATH];
- get_install_dir_path(videoFilePath, name);
-
- platform->PlayVideo(videoFilePath, skip, flags);
+ Display("Unsupported video '%s'", name);
}
if (flags < 10) {
@@ -86,11 +81,4 @@ void pause_sound_if_necessary_and_play_video(const char *name, int skip, int fla
}
}
-#else
-
-void pause_sound_if_necessary_and_play_video(const char *name, int skip, int flags) {
-}
-
-#endif
-
} // namespace AGS3
diff --git a/engines/ags/engine/gfx/ali3dscummvm.cpp b/engines/ags/engine/gfx/ali3dscummvm.cpp
index d64c5e9ebd..a4425d63bf 100644
--- a/engines/ags/engine/gfx/ali3dscummvm.cpp
+++ b/engines/ags/engine/gfx/ali3dscummvm.cpp
@@ -56,10 +56,6 @@ extern "C" extern LPDIRECTDRAW2 directdraw;
extern "C" DDRAW_SURFACE * gfx_directx_primary_surface;
#endif // AGS_DDRAW_GAMMA_CONTROL
-#ifndef AGS_NO_VIDEO_PLAYER
-extern int dxmedia_play_video(const char *, bool, int, int);
-#endif
-
namespace AGS {
namespace Engine {
namespace ALGfx {
@@ -717,19 +713,6 @@ void ALScummVMGraphicsDriver::BoxOutEffect(bool blackingOut, int speed, int dela
}
// end fading routines
-#ifndef AGS_NO_VIDEO_PLAYER
-
-bool ALScummVMGraphicsDriver::PlayVideo(const char *filename, bool useAVISound, VideoSkipType skipType, bool stretchToFullScreen) {
-#if AGS_PLATFORM_OS_WINDOWS
- int result = dxmedia_play_video(filename, useAVISound, skipType, stretchToFullScreen ? 1 : 0);
- return (result == 0);
-#else
- return 0;
-#endif
-}
-
-#endif
-
// add the alpha values together, used for compositing alpha images
unsigned long _trans_alpha_blender32(unsigned long x, unsigned long y, unsigned long n) {
unsigned long res, g;
diff --git a/engines/ags/engine/gfx/ali3dscummvm.h b/engines/ags/engine/gfx/ali3dscummvm.h
index 4628a4cf9a..f2c8607a34 100644
--- a/engines/ags/engine/gfx/ali3dscummvm.h
+++ b/engines/ags/engine/gfx/ali3dscummvm.h
@@ -191,9 +191,6 @@ public:
void FadeOut(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue) override;
void FadeIn(int speed, PALETTE pal, int targetColourRed, int targetColourGreen, int targetColourBlue) override;
void BoxOutEffect(bool blackingOut, int speed, int delay) override;
-#ifndef AGS_NO_VIDEO_PLAYER
- bool PlayVideo(const char *filename, bool useAVISound, VideoSkipType skipType, bool stretchToFullScreen) override;
-#endif
bool SupportsGammaControl() override;
void SetGamma(int newGamma) override;
void UseSmoothScaling(bool enabled) override {
diff --git a/engines/ags/engine/media/video/vmr9_graph.h b/engines/ags/engine/media/video/vmr9_graph.h
deleted file mode 100644
index d3488fbd9b..0000000000
--- a/engines/ags/engine/media/video/vmr9_graph.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-//=============================================================================
-//
-// vmr9_graph.h: interface for the CVMR9Graph class.
-//
-//=============================================================================
-
-#ifndef AGS_ENGINE_MEDIA_VIDEO_VMR9_GRAPH_H
-#define AGS_ENGINE_MEDIA_VIDEO_VMR9_GRAPH_H
-
-//include <dshow.h>
-//include <Vmr9.h>
-
-namespace AGS3 {
-
-//#pragma comment( lib, "strmiids.lib" )
-//#pragma comment( lib, "Quartz.lib" )
-//#pragma comment( lib, "d3d9.lib" )
-//#pragma comment( lib, "d3dx9.lib" )
-
-#define WM_MEDIA_NOTIF (WM_APP + 777)
-
-class CVMR9Graph {
- // Constructor / destructor
-public:
- CVMR9Graph();
- CVMR9Graph(HWND MediaWindow, IDirect3DDevice9 *device, int NumberOfStream = 4);
- ~CVMR9Graph();
-
- // Methods
-public:
- // Graph configuration
- void SetNumberOfLayer(int nNumberOfLayer);
- BOOL SetMediaWindow(HWND MediaWindow);
- BOOL SetMediaFile(const char *pszFileName, bool withSound, int nLayer = 0);
- BOOL PreserveAspectRatio(BOOL bPreserve = TRUE);
- IBaseFilter *AddFilter(const char *pszName, const GUID &clsid);
-
- // Graph control
- BOOL PlayGraph();
- BOOL StopGraph();
- BOOL ResetGraph();
- OAFilterState GetState();
- IMediaEvent *GetPtrMediaEvent();
- IMediaControl *GetPtrMediaControl();
- IMediaSeeking *GetPtrMediaSeeking();
- IBasicAudio *GetPtrBasicAudio();
-
-
- // Layer control
- BOOL GetVideoRect(LPRECT pRect);
- int GetAlphaLayer(int nLayer);
- BOOL SetAlphaLayer(int nLayer, int nAlpha);
- DWORD GetLayerZOrder(int nLayer);
- BOOL SetLayerZOrder(int nLayer, DWORD dwZOrder);
- BOOL SetLayerRect(int nLayer, RECT layerRect);
-
- // Bitmap control
- BOOL SetBitmapParams(int nAlpha, COLORREF cTransColor, RECT bitmapRect);
-
- // Reflected from window
- BOOL Repaint();
- BOOL Resize();
-
- // helper
- LPCTSTR GetLastError();
-
- // Internal
- BOOL BuildAndRenderGraph(bool withSound);
-
-protected:
- // INIT helper methods
- void InitDefaultValues();
- void ReleaseAllInterfaces();
-
- // GRAPH methods
- BOOL BuildFilterGraph(bool withSound);
- BOOL BuildVMR();
- BOOL BuildSoundRenderer();
- BOOL RenderGraph();
-
- // DIRECT3D methods
- BOOL BuildDirect3d();
-
-
- // LAYER helper methods
- BOOL IsValidLayer(int nLayer);
- VMR9NormalizedRect NormalizeRect(LPRECT pRect);
-
- // DSOW helper methods
- HRESULT AddToRot(IUnknown *pUnkGraph);
- void RemoveFromRot();
- IPin *GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir);
- void ReportError(const char *pszError, HRESULT hrCode);
- HRESULT GetNextFilter(IBaseFilter *pFilter, PIN_DIRECTION Dir, IBaseFilter **ppNext);
- BOOL RemoveFilterChain(IBaseFilter *pFilter, IBaseFilter *pStopFilter);
- HRESULT AddFilterByClsid(IGraphBuilder *pGraph, LPCWSTR wszName, const GUID &clsid, IBaseFilter **ppF);
-
- // Attributes
-public:
- bool UseAVISound;
-
-protected:
- DWORD m_dwRotId;
- char m_pszErrorDescription[1024 + MAX_ERROR_TEXT_LEN];
- int m_nNumberOfStream;
- const char *m_pszFileName;
- long m_oldWndProc;
- // MEDIA WINDOW
- HWND m_hMediaWindow;
- // SRC interfaces array
- IBaseFilter *m_srcFilterArray[10];
- // SOUND interfaces
- IBaseFilter *m_pDirectSoundFilter;
- // GRAPH interfaces
- IUnknown *m_pGraphUnknown;
- IGraphBuilder *m_pGraphBuilder;
- IFilterGraph *m_pFilterGraph;
- IFilterGraph2 *m_pFilterGraph2;
- IMediaControl *m_pMediaControl;
- IMediaSeeking *m_pMediaSeeking;
- //IMediaEvent* m_pMediaEvent;
- IMediaEventEx *m_pMediaEventEx;
- // VMR9 interfaces
- IBaseFilter *m_pVMRBaseFilter;
- IVMRFilterConfig9 *m_pVMRFilterConfig;
- IVMRMixerBitmap9 *m_pVMRMixerBitmap;
- IVMRMixerControl9 *m_pVMRMixerControl;
- IVMRMonitorConfig9 *m_pVMRMonitorConfig;
- IVMRWindowlessControl9 *m_pVMRWindowlessControl;
- // DIRECT3D interfaces
- //IDirect3DDevice9* m_pD3DDevice;
- IDirect3DSurface9 *m_pD3DSurface;
-};
-
-} // namespace AGS3
-
-#endif
diff --git a/engines/ags/engine/platform/windows/acplwin.cpp b/engines/ags/engine/platform/windows/acplwin.cpp
index eda5ca2d98..08aad2ad86 100644
--- a/engines/ags/engine/platform/windows/acplwin.cpp
+++ b/engines/ags/engine/platform/windows/acplwin.cpp
@@ -50,13 +50,6 @@
namespace AGS3 {
-#ifndef AGS_NO_VIDEO_PLAYER
-extern void dxmedia_abort_video();
-extern void dxmedia_pause_video();
-extern void dxmedia_resume_video();
-extern char lastError[200];
-#endif
-
using namespace AGS::Shared;
using namespace AGS::Engine;
@@ -148,10 +141,6 @@ struct AGSWin32 : AGSPlatformDriver {
virtual bool LockMouseToWindow();
virtual void UnlockMouse();
-#ifndef AGS_NO_VIDEO_PLAYER
- virtual void PlayVideo(const char *name, int skip, int flags);
-#endif
-
private:
void add_game_to_game_explorer(IGameExplorer *pFwGameExplorer, GUID *guid, const char *guidAsText, bool allUsers);
@@ -683,15 +672,9 @@ void AGSWin32::DisplaySwitchIn() {
}
void AGSWin32::PauseApplication() {
-#ifndef AGS_NO_VIDEO_PLAYER
- dxmedia_pause_video();
-#endif
}
void AGSWin32::ResumeApplication() {
-#ifndef AGS_NO_VIDEO_PLAYER
- dxmedia_resume_video();
-#endif
}
void AGSWin32::GetSystemDisplayModes(std::vector<DisplayMode> &dms) {
@@ -852,56 +835,7 @@ int AGSWin32::InitializeCDPlayer() {
#endif
}
-#ifndef AGS_NO_VIDEO_PLAYER
-
-void AGSWin32::PlayVideo(const char *name, int skip, int flags) {
-
- char useloc[250];
- sprintf(useloc, "%s\\%s", ResPaths.DataDir.GetCStr(), name);
-
- bool useSound = true;
- if (flags >= 10) {
- flags -= 10;
- useSound = false;
- } else {
- // for some reason DirectSound can't be shared, so uninstall
- // allegro sound before playing the video
- shutdown_sound();
- }
-
- bool isError = false;
- if (Common::File::TestReadFile(useloc)) {
- isError = (gfxDriver->PlayVideo(useloc, useSound, (VideoSkipType)skip, (flags > 0)) == 0);
- } else {
- isError = true;
- sprintf(lastError, "File not found: %s", useloc);
- }
-
- if (isError) {
- // turn "Always display as speech" off, to make sure error
- // gets displayed correctly
- int oldalways = game.options[OPT_ALWAYSSPCH];
- game.options[OPT_ALWAYSSPCH] = 0;
- Display("Video playing error: %s", lastError);
- game.options[OPT_ALWAYSSPCH] = oldalways;
- }
-
- if (useSound) {
- // Restore sound system
- install_sound(usetup.digicard, usetup.midicard, NULL);
- if (usetup.mod_player)
- init_mod_player(NUM_MOD_DIGI_VOICES);
- }
-
- set_palette_range(palette, 0, 255, 0);
-}
-
-#endif
-
void AGSWin32::AboutToQuitGame() {
-#ifndef AGS_NO_VIDEO_PLAYER
- dxmedia_abort_video();
-#endif
}
void AGSWin32::PostAllegroExit() {
diff --git a/engines/ags/engine/platform/windows/gfx/ali3dd3d.cpp b/engines/ags/engine/platform/windows/gfx/ali3dd3d.cpp
index 269c5b0507..a53c0a328d 100644
--- a/engines/ags/engine/platform/windows/gfx/ali3dd3d.cpp
+++ b/engines/ags/engine/platform/windows/gfx/ali3dd3d.cpp
@@ -47,11 +47,6 @@
namespace AGS3 {
-#ifndef AGS_NO_VIDEO_PLAYER
-extern int dxmedia_play_video_3d(const char *filename, IDirect3DDevice9 *device, bool useAVISound, int canskip, int stretch);
-extern void dxmedia_shutdown_3d();
-#endif
-
using namespace AGS::Shared;
// Necessary to update textures from 8-bit bitmaps
@@ -906,11 +901,6 @@ PGfxFilter D3DGraphicsDriver::GetGraphicsFilter() const {
}
void D3DGraphicsDriver::UnInit() {
-#ifndef AGS_NO_VIDEO_PLAYER
- // TODO: this should not be done inside the graphics driver!
- dxmedia_shutdown_3d();
-#endif
-
OnUnInit();
ReleaseDisplayMode();
@@ -1740,17 +1730,6 @@ void D3DGraphicsDriver::BoxOutEffect(bool blackingOut, int speed, int delay) {
ResetFxPool();
}
-#ifndef AGS_NO_VIDEO_PLAYER
-
-bool D3DGraphicsDriver::PlayVideo(const char *filename, bool useAVISound, VideoSkipType skipType, bool stretchToFullScreen) {
- direct3ddevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 0, 0, 255), 0.5f, 0);
-
- int result = dxmedia_play_video_3d(filename, direct3ddevice, useAVISound, skipType, stretchToFullScreen ? 1 : 0);
- return (result == 0);
-}
-
-#endif
-
void D3DGraphicsDriver::SetScreenFade(int red, int green, int blue) {
D3DBitmap *ddb = static_cast<D3DBitmap *>(MakeFx(red, green, blue));
ddb->SetStretch(_spriteBatches[_actSpriteBatch].Viewport.GetWidth(),
diff --git a/engines/ags/engine/platform/windows/gfx/ali3dd3d.h b/engines/ags/engine/platform/windows/gfx/ali3dd3d.h
index 62558e34c6..1f7784f52c 100644
--- a/engines/ags/engine/platform/windows/gfx/ali3dd3d.h
+++ b/engines/ags/engine/platform/windows/gfx/ali3dd3d.h
@@ -212,9 +212,6 @@ public:
void FadeOut(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue) override;
void FadeIn(int speed, PALETTE p, int targetColourRed, int targetColourGreen, int targetColourBlue) override;
void BoxOutEffect(bool blackingOut, int speed, int delay) override;
-#ifndef AGS_NO_VIDEO_PLAYER
- bool PlayVideo(const char *filename, bool useSound, VideoSkipType skipType, bool stretchToFullScreen) override;
-#endif
bool SupportsGammaControl() override;
void SetGamma(int newGamma) override;
void UseSmoothScaling(bool enabled) override {
diff --git a/engines/ags/engine/platform/windows/media/video/acwavi.cpp b/engines/ags/engine/platform/windows/media/video/acwavi.cpp
deleted file mode 100644
index 1266dc8ff3..0000000000
--- a/engines/ags/engine/platform/windows/media/video/acwavi.cpp
+++ /dev/null
@@ -1,442 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-//=============================================================================
-//
-// AVI/MPG player for AGS
-// Adapted from MS DirectX Media example program to work with allegro
-// 2002 Chris Jones
-//
-//=============================================================================
-
-#include "ags/shared/core/platform.h"
-
-#if AGS_PLATFORM_OS_WINDOWS && ! defined (AGS_NO_VIDEO_PLAYER)
-
-//#define ALLEGRO_STATICLINK // already defined in project settings
-#include "ags/lib/allegro.h"
-//include <winalleg.h>
-//include <windows.h>
-//include <stdlib.h>
-//include <amstream.h>
-//include <mmstream.h> // Multimedia stream interfaces
-//include <ddstream.h> // DirectDraw multimedia stream interfaces
-//include <initguid.h> // Defines DEFINE_GUID macro and enables GUID initialization
-#include "ags/shared/ac/draw.h"
-#include "ags/shared/gfx/bitmap.h"
-#include "ags/shared/gfx/graphicsdriver.h"
-#include "ags/shared/main/game_run.h"
-#include "ags/shared/platform/base/agsplatformdriver.h"
-
-namespace AGS3 {
-
-using namespace AGS::Shared;
-using namespace AGS::Engine;
-
-//link with the following libraries under project/settings/link...
-//amstrmid.lib quartz.lib strmbase.lib ddraw.lib
-
-extern void update_audio_system_on_game_loop();
-extern void update_polled_stuff_if_runtime();
-extern int ags_mgetbutton();
-extern volatile char want_exit;
-extern IGraphicsDriver *gfxDriver;
-//int errno;
-char lastError[300];
-
-//Global variables
-HWND ghWnd;
-BOOL g_bAppactive = FALSE; // The window is active
-bool useSound = true;
-volatile bool currentlyPlaying = false;
-volatile bool currentlyPaused = false;
-
-//DirectDrawEx Global interfaces
-extern "C" extern LPDIRECTDRAW2 directdraw;
-//extern "C" extern IUnknown* directsound;
-extern "C" extern BITMAP *gfx_directx_create_system_bitmap(int width, int height);
-
-//Global MultiMedia streaming interfaces
-IMultiMediaStream *g_pMMStream = NULL;
-IMediaStream *g_pPrimaryVidStream = NULL;
-IDirectDrawMediaStream *g_pDDStream = NULL;
-IDirectDrawStreamSample *g_pSample = NULL;
-
-Bitmap *vscreen = NULL;
-Bitmap *vsMemory = NULL;
-
-//Function prototypes
-HRESULT RenderFileToMMStream(LPCTSTR szFilename);
-HRESULT InitRenderToSurface();
-void RenderToSurface();
-
-void ExitCode() {
- //Release MultiMedia streaming Objects
- if (g_pMMStream != NULL) {
- g_pMMStream->Release();
- g_pMMStream = NULL;
- }
- if (g_pSample != NULL) {
- g_pSample->Release();
- g_pSample = NULL;
- }
- if (g_pDDStream != NULL) {
- g_pDDStream->Release();
- g_pDDStream = NULL;
- }
- if (g_pPrimaryVidStream != NULL) {
- g_pPrimaryVidStream->Release();
- g_pPrimaryVidStream = NULL;
- }
-}
-
-typedef struct BMP_EXTRA_INFO {
- LPDIRECTDRAWSURFACE2 surf;
- struct BMP_EXTRA_INFO *next;
- struct BMP_EXTRA_INFO *prev;
- int flags;
- int lock_nesting;
-} BMP_EXTRA_INFO;
-
-LPDIRECTDRAWSURFACE get_bitmap_surface(Bitmap *bmp) {
- BMP_EXTRA_INFO *bei = (BMP_EXTRA_INFO *)((BITMAP *)bmp->GetAllegroBitmap())->extra;
-
- // convert the DDSurface2 back to a standard DDSurface
- return (LPDIRECTDRAWSURFACE)bei->surf;
-}
-LPDIRECTDRAWSURFACE2 get_bitmap_surface2(Bitmap *bmp) {
- BMP_EXTRA_INFO *bei = (BMP_EXTRA_INFO *)((BITMAP *)bmp->GetAllegroBitmap())->extra;
-
- return bei->surf;
-}
-
-//Create the stream sample which will be used to call updates on the video
-HRESULT InitRenderToSurface() {
-
- HRESULT hr;
- DDSURFACEDESC ddsd;
-
- //Use the multimedia stream to get the primary video media stream
- hr = g_pMMStream->GetMediaStream(MSPID_PrimaryVideo, &g_pPrimaryVidStream);
- if (FAILED(hr)) {
- strcpy(lastError, "MMStream::GetMediaStream failed to create the primary video stream.");
- return E_FAIL;
- }
-
- //Use the media stream to get the IDirectDrawMediaStream
- hr = g_pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&g_pDDStream);
- if (FAILED(hr)) {
- strcpy(lastError, "The video stream does not support the IDirectDrawMediaStream interface; ensure you have the latest DirectX version installed.");
- return E_FAIL;
- }
-
- //Must set dwSize before calling GetFormat
- ddsd.dwSize = sizeof(ddsd);
- hr = g_pDDStream->GetFormat(&ddsd, NULL, NULL, NULL);
- if (FAILED(hr)) {
- strcpy(lastError, "IDirectDrawMediaStream::GetFormat failed");
- return E_FAIL;
- }
-
- RECT rect;
- rect.top = rect.left = 0;
- // these are the width and height of the video
- rect.bottom = ddsd.dwHeight;
- rect.right = ddsd.dwWidth;
-
- if (vscreen == NULL)
- vscreen = BitmapHelper::CreateRawBitmapOwner(gfx_directx_create_system_bitmap(ddsd.dwWidth, ddsd.dwHeight));
-
- if (vscreen == NULL) {
- strcpy(lastError, "Unable to create the DX Video System Bitmap");
- return E_FAIL;
- }
-
- vsMemory = BitmapHelper::CreateBitmap(vscreen->GetWidth(), vscreen->GetHeight(), vscreen->GetColorDepth());
-
- IDirectDrawSurface *g_pDDSOffscreen;
- g_pDDSOffscreen = get_bitmap_surface(vscreen);
-
- //Create the stream sample
- hr = g_pDDStream->CreateSample(g_pDDSOffscreen, &rect, 0, &g_pSample);
- if (FAILED(hr)) {
- strcpy(lastError, "VideoStream::CreateSample failed");
- return E_FAIL;
- }
-
- return NOERROR;
-}
-
-//Renders a file to a multimedia stream
-HRESULT RenderFileToMMStream(LPCTSTR szFilename) {
- HRESULT hr;
- IAMMultiMediaStream *pAMStream = NULL;
-
- //Convert filename to Unicode
- WCHAR wFile[MAX_PATH];
- MultiByteToWideChar(CP_ACP, 0, szFilename, -1, wFile,
- sizeof(wFile) / sizeof(wFile[0]));
-
- //Create the AMMultiMediaStream object
- hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
- IID_IAMMultiMediaStream, (void **)&pAMStream);
-
- if (FAILED(hr)) {
- strcpy(lastError, "Could not create a CLSID_MultiMediaStream object. "
- "Make sure you have the latest version of DirectX installed.");
- return E_FAIL;
- }
-
- //Initialize stream
- hr = pAMStream->Initialize(STREAMTYPE_READ, 0, NULL);
- if (FAILED(hr)) {
- strcpy(lastError, "AMStream::Initialize failed.");
- return E_FAIL;
- }
- //Add primary video stream
- hr = pAMStream->AddMediaStream(directdraw, &MSPID_PrimaryVideo, 0, NULL);
- if (FAILED(hr)) {
- strcpy(lastError, "AddMediaStream failed.");
- return E_FAIL;
- }
- //Add primary audio stream
- if (useSound) {
- //hr = pAMStream->AddMediaStream(directsound, &MSPID_PrimaryAudio, 0, NULL);
- hr = pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL);
- if (FAILED(hr)) {
- strcpy(lastError, "AddMediaStream failed.");
- return E_FAIL;
- }
- }
- //Opens and automatically creates a filter graph for the specified media file
- hr = pAMStream->OpenFile(wFile, 0);
- if (FAILED(hr)) {
- pAMStream->Release();
- sprintf(lastError, "File not found or format not supported: %s", szFilename);
- return E_FAIL;
- }
-
- //save the local stream to the global variable
- g_pMMStream = pAMStream;
- // Add a reference to the file
- //pAMStream->AddRef();
-
- return NOERROR;
-}
-
-int newWidth, newHeight;
-
-//Perform frame by frame updates and blits. Set the stream
-//state to STOP if there are no more frames to update.
-void RenderToSurface(Bitmap *vscreen) {
- //update each frame
- if (g_pSample->Update(0, NULL, NULL, 0) != S_OK) {
- g_bAppactive = FALSE;
- g_pMMStream->SetState(STREAMSTATE_STOP);
- } else {
- g_bAppactive = TRUE;
- Bitmap *screen_bmp = gfxDriver->GetMemoryBackBuffer();
- // TODO: don't render on screen bitmap, use gfxDriver->DrawSprite instead!
- screen_bmp->Acquire();
- // Because vscreen is a DX Video Bitmap, it can be stretched
- // onto the screen (also a Video Bmp) but not onto a memory
- // bitmap (which is what "screen" is when using gfx filters)
- if (screen_bmp->IsVideoBitmap()) {
- screen_bmp->StretchBlt(vscreen,
- RectWH(0, 0, vscreen->GetWidth(), vscreen->GetHeight()),
- RectWH(screen_bmp->GetWidth() / 2 - newWidth / 2,
- screen_bmp->GetHeight() / 2 - newHeight / 2,
- newWidth, newHeight));
- } else {
- vsMemory->Blit(vscreen, 0, 0, 0, 0, vscreen->GetWidth(), vscreen->GetHeight());
- screen_bmp->StretchBlt(vsMemory,
- RectWH(0, 0, vscreen->GetWidth(), vscreen->GetHeight()),
- RectWH(screen_bmp->GetWidth() / 2 - newWidth / 2,
- screen_bmp->GetHeight() / 2 - newHeight / 2,
- newWidth, newHeight));
- }
- screen_bmp->Release();
-
- // if we're not playing AVI sound, poll the audio system
- if (!useSound)
- update_audio_system_on_game_loop();
-
- render_to_screen();
- }
-}
-
-void dxmedia_pause_video() {
-
- if (currentlyPlaying) {
- currentlyPaused = true;
- g_pMMStream->SetState(STREAMSTATE_STOP);
- }
-
-}
-
-void dxmedia_resume_video() {
-
- if (currentlyPlaying) {
- currentlyPaused = false;
- g_pMMStream->SetState(STREAMSTATE_RUN);
- }
-
-}
-
-void dxmedia_abort_video() {
-
- if (currentlyPlaying) {
-
- currentlyPlaying = false;
- g_pMMStream->SetState(STREAMSTATE_STOP);
-
- ExitCode();
- CoUninitialize();
- delete vscreen;
- vscreen = NULL;
- if (vsMemory != NULL) {
- delete vsMemory;
- vsMemory = NULL;
- }
- strcpy(lastError, "Played successfully.");
- }
-
-}
-
-int dxmedia_play_video(const char *filename, bool pUseSound, int canskip, int stretch) {
- HRESULT hr;
-
- useSound = pUseSound;
- ghWnd = win_get_window();
-
- CoInitialize(NULL);
-
- if (!useSound)
- update_polled_stuff_if_runtime();
-
- hr = RenderFileToMMStream(filename);
- if (FAILED(hr)) {
- ExitCode();
- CoUninitialize();
- return -1;
- }
-
- if (!useSound)
- update_polled_stuff_if_runtime();
-
- hr = InitRenderToSurface();
- if (FAILED(hr)) {
- ExitCode();
- CoUninitialize();
- return -1;
- }
-
- newWidth = vscreen->GetWidth();
- newHeight = vscreen->GetHeight();
-
- Bitmap *screen_bmp = gfxDriver->GetMemoryBackBuffer();
-
- if ((stretch == 1) ||
- (vscreen->GetWidth() > screen_bmp->GetWidth()) ||
- (vscreen->GetHeight() > screen_bmp->GetHeight())) {
- // If they want to stretch, or if it's bigger than the screen, then stretch
- float widthRatio = (float)vscreen->GetWidth() / (float)screen_bmp->GetWidth();
- float heightRatio = (float)vscreen->GetHeight() / (float)screen_bmp->GetHeight();
-
- if (widthRatio > heightRatio) {
- newWidth = vscreen->GetWidth() / widthRatio;
- newHeight = vscreen->GetHeight() / widthRatio;
- } else {
- newWidth = vscreen->GetWidth() / heightRatio;
- newHeight = vscreen->GetHeight() / heightRatio;
- }
- }
-
- //Now set the multimedia stream to RUN
- hr = g_pMMStream->SetState(STREAMSTATE_RUN);
- g_bAppactive = TRUE;
-
- if (FAILED(hr)) {
- sprintf(lastError, "Unable to play stream: 0x%08X", hr);
- ExitCode();
- CoUninitialize();
- delete vscreen;
- return -1;
- }
- // in case we're not full screen, clear the background
- screen_bmp->Clear();
-
- currentlyPlaying = true;
-
- gfxDriver->ClearDrawLists();
-
- while ((g_bAppactive) && (!want_exit)) {
-
- while (currentlyPaused) {
- platform->YieldCPU();
- }
-
- RenderToSurface(vscreen);
- //Sleep(0);
- int key, mbut, mwheelz;
- if (run_service_key_controls(key)) {
- if ((canskip == 1) && (key == 27))
- break;
- if (canskip >= 2)
- break;
- }
- if (run_service_mb_controls(mbut, mwheelz) && mbut >= 0 && (canskip == 3))
- break;
- }
-
- dxmedia_abort_video();
-
- return 0;
-}
-
-#if 0
-
-int WINAPI WinMain(
- HINSTANCE hInstance, // handle to current instance
- HINSTANCE hPrevInstance, // handle to previous instance
- LPSTR lpCmdLine, // pointer to command line
- int nCmdShow) {
-
- install_allegro(SYSTEM_AUTODETECT, &errno, atexit);
-
- install_keyboard();
-
- set_color_depth(16);
- set_gfx_mode(GFX_DIRECTX_WIN, 640, 480, 0, 0);
-
- set_display_switch_mode(SWITCH_BACKGROUND);
-
- dxmedia_play_video("f:\\download\\Seinfeld S05E04 - The Sniffing Accountant.mpg", 1, 1);
- dxmedia_play_video("f:\\download\\Family Guy S02E16 - There's Something About Paulie.mpg", 2, 1);
-
- return 0;
-}
-#endif
-
-} // namespace AGS3
-
-#endif
diff --git a/engines/ags/engine/platform/windows/media/video/acwavi3d.cpp b/engines/ags/engine/platform/windows/media/video/acwavi3d.cpp
deleted file mode 100644
index 0b70185d65..0000000000
--- a/engines/ags/engine/platform/windows/media/video/acwavi3d.cpp
+++ /dev/null
@@ -1,927 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-//=============================================================================
-//
-// AVI/MPG player for AGS
-// VMR9-based player to work with D3D
-//
-//=============================================================================
-
-#include "ags/shared/core/platform.h"
-
-#if AGS_PLATFORM_OS_WINDOWS && ! defined (AGS_NO_VIDEO_PLAYER)
-
-//#define ALLEGRO_STATICLINK // already defined in project settings
-#include "ags/lib/allegro.h"
-//include <winalleg.h>
-//include <allegro/platform/aintwin.h>
-//include <d3d9.h>
-//include <strmif.h>
-#define DWORD_PTR DWORD*
-#define LONG_PTR LONG*
-#define LPD3DVECTOR D3DVECTOR*
-#define _D3DTYPES_H_
-#define _STRSAFE_H_INCLUDED_
-typedef float D3DVALUE, *LPD3DVALUE;
-#include "ags/shared/ac/common.h"
-#include "ags/shared/main/game_run.h"
-#include "ags/shared/media/video/vmr9_graph.h"
-#include "ags/shared/platform/base/agsplatformdriver.h"
-////include <atlbase.h>
-#include "ags/shared/media/audio/audio_system.h"
-
-namespace AGS3 {
-
-#define USES_CONVERSION int _convert = 0; _convert; UINT _acp = CP_ACP; _acp; LPCWSTR _lpw = NULL; _lpw; LPCSTR _lpa = NULL; _lpa
-
-inline LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars, UINT acp) {
- // verify that no illegal character present
- // since lpw was allocated based on the size of lpa
- // don't worry about the number of chars
- lpw[0] = '\0';
- MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars);
- return lpw;
-}
-inline LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars) {
- return AtlA2WHelper(lpw, lpa, nChars, CP_ACP);
-}
-#define ATLA2WHELPER AtlA2WHelper
-
-#define A2W(lpa) (\
- ((_lpa = lpa) == NULL) ? NULL : (\
- _convert = (lstrlenA(_lpa)+1),\
- ATLA2WHELPER((LPWSTR) alloca(_convert*2), _lpa, _convert)))
-
-
-// Interface from main game
-
-extern int ags_mgetbutton();
-extern void update_audio_system_on_game_loop();
-extern volatile char want_exit;
-extern char lastError[300];
-CVMR9Graph *graph = NULL;
-
-void dxmedia_shutdown_3d() {
- if (graph != NULL) {
- delete graph;
- graph = NULL;
- }
-}
-
-int dxmedia_play_video_3d(const char *filename, IDirect3DDevice9 *device, bool useAVISound, int canskip, int stretch) {
- HWND gameWindow = win_get_window();
-
- if (graph == NULL) {
- graph = new CVMR9Graph(gameWindow, device);
- }
-
- if (!useAVISound)
- update_audio_system_on_game_loop();
-
- if (!graph->SetMediaFile(filename, useAVISound)) {
- dxmedia_shutdown_3d();
- return -1;
- }
- graph->SetLayerZOrder(0, 0);
-
- if (!useAVISound)
- update_audio_system_on_game_loop();
-
- if (!graph->PlayGraph()) {
- dxmedia_shutdown_3d();
- return -1;
- }
-
-
- OAFilterState filterState = State_Running;
- while ((filterState != State_Stopped) && (!want_exit)) {
- WaitForNextFrame();
-
- if (!useAVISound)
- update_audio_system_on_game_loop();
-
- filterState = graph->GetState();
-
- int key, mbut, mwheelz;
- if (run_service_key_controls(key)) {
- if ((canskip == 1) && (key == 27))
- break;
- if (canskip >= 2)
- break;
- }
- if (run_service_mb_controls(mbut, mwheelz) && mbut >= 0 && (canskip == 3))
- break;
-
- //device->Present(NULL, NULL, 0, NULL);
- }
-
- graph->StopGraph();
-
- dxmedia_shutdown_3d();
- return 0;
-}
-
-
-// VMR9Graph.cpp: implementation of the CVMR9Graph class.
-//
-//////////////////////////////////////////////////////////////////////
-
-
-////include <atlbase.h>
-
-#if AGS_PLATFORM_DEBUG
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#define new DEBUG_NEW
-#endif
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-// Function name : CVMR9Graph::CVMR9Graph
-// Description : constructor
-// Return type :
-CVMR9Graph::CVMR9Graph() {
- InitDefaultValues();
-}
-
-
-// Function name : CVMR9Graph
-// Description : constructor
-// Return type :
-// Argument : HWND MediaWindow
-// Argument : int NumberOfStream
-CVMR9Graph::CVMR9Graph(HWND MediaWindow, IDirect3DDevice9 *device, int NumberOfStream) {
- InitDefaultValues();
-
- if (MediaWindow != NULL) {
- m_hMediaWindow = MediaWindow;
- }
-
- if (NumberOfStream > 0 && NumberOfStream < 11) {
- m_nNumberOfStream = NumberOfStream;
- }
-
- //m_pD3DDevice = device;
- m_oldWndProc = GetWindowLong(m_hMediaWindow, GWL_WNDPROC);
-}
-
-// Function name : CVMR9Graph::~CVMR9Graph
-// Description : destructor
-// Return type :
-CVMR9Graph::~CVMR9Graph() {
- ReleaseAllInterfaces();
- long newProc = GetWindowLong(m_hMediaWindow, GWL_WNDPROC);
-}
-
-
-// Function name : CVMR9Graph::InitDefaultValues
-// Description : initialize all default values
-// Return type : void
-void CVMR9Graph::InitDefaultValues() {
- ZeroMemory(m_pszErrorDescription, 1024);
- m_dwRotId = -1;
- m_nNumberOfStream = 4; // default VMR9 config
- m_hMediaWindow = NULL;
- // SRC interfaces
- for (int i = 0; i < 10; i++) {
- m_srcFilterArray[i] = NULL;
- }
- // SOUND interface
- m_pDirectSoundFilter = NULL;
- // GRAPH interfaces
- m_pGraphUnknown = NULL;
- m_pGraphBuilder = NULL;
- m_pFilterGraph = NULL;
- m_pFilterGraph2 = NULL;
- m_pMediaControl = NULL;
- m_pMediaSeeking = NULL;
- //m_pMediaEvent = NULL;
- m_pMediaEventEx = NULL;
- // VMR9 interfaces
- m_pVMRBaseFilter = NULL;
- m_pVMRFilterConfig = NULL;
- m_pVMRMixerBitmap = NULL;
- m_pVMRMixerControl = NULL;
- m_pVMRMonitorConfig = NULL;
- m_pVMRWindowlessControl = NULL;
- // DIRECT3D interfaces
- m_pD3DSurface = NULL;
-}
-
-// Function name : CVMR9Graph::ReleaseAllInterfaces
-// Description : release all of the graph interfaces
-// Return type : void
-void CVMR9Graph::ReleaseAllInterfaces() {
- // CALLBACK handle
- /*if (m_pMediaEventEx != NULL) {
- m_pMediaEventEx->SetNotifyWindow(NULL, WM_MEDIA_NOTIF, NULL);
- }*/
- // SRC interfaces
- for (int i = 0; i < 10; i++) {
- IBaseFilter *pSrcFilter = m_srcFilterArray[i];
- if (pSrcFilter != NULL) {
- pSrcFilter->Release();
- m_srcFilterArray[i] = NULL;
- }
- }
- // SOUND interfaces
- if (m_pDirectSoundFilter != NULL) {
- m_pDirectSoundFilter->Release();
- m_pDirectSoundFilter = NULL;
- }
- // VMR9 interfaces
- if (m_pVMRFilterConfig != NULL) {
- m_pVMRFilterConfig->Release();
- m_pVMRFilterConfig = NULL;
- }
- if (m_pVMRMixerBitmap != NULL) {
- m_pVMRMixerBitmap->Release();
- m_pVMRMixerBitmap = NULL;
- }
- if (m_pVMRMixerControl != NULL) {
- m_pVMRMixerControl->Release();
- m_pVMRMixerControl = NULL;
- }
- if (m_pVMRMonitorConfig != NULL) {
- m_pVMRMonitorConfig->Release();
- m_pVMRMonitorConfig = NULL;
- }
- if (m_pVMRWindowlessControl != NULL) {
- m_pVMRWindowlessControl->Release();
- m_pVMRWindowlessControl = NULL;
- }
- if (m_pVMRBaseFilter != NULL) {
- m_pVMRBaseFilter->Release();
- m_pVMRBaseFilter = NULL;
- }
- // GRAPH interfaces
- if (m_pGraphBuilder != NULL) {
- m_pGraphBuilder->Release();
- m_pGraphBuilder = NULL;
- }
- if (m_pFilterGraph != NULL) {
- m_pFilterGraph->Release();
- m_pFilterGraph = NULL;
- }
- if (m_pFilterGraph2 != NULL) {
- m_pFilterGraph2->Release();
- m_pFilterGraph2 = NULL;
- }
- if (m_pMediaControl != NULL) {
- m_pMediaControl->Release();
- m_pMediaControl = NULL;
- }
- if (m_pMediaSeeking != NULL) {
- m_pMediaSeeking->Release();
- m_pMediaSeeking = NULL;
- }
- /*if (m_pMediaEvent != NULL) {
- m_pMediaEvent->Release();
- m_pMediaEvent = NULL;
- }*/
- /*if (m_pMediaEventEx != NULL) {
- m_pMediaEventEx->Release();
- m_pMediaEventEx = NULL;
- }*/
- if (m_pGraphUnknown != NULL) {
- m_pGraphUnknown->Release();
- m_pGraphUnknown = NULL;
- }
- // DIRECT3D interfaces
- if (m_pD3DSurface != NULL) {
- m_pD3DSurface->Release();
- m_pD3DSurface = NULL;
- }
-}
-
-//////////////////////////////////////////////////////////////////////
-// Helper Functions
-//////////////////////////////////////////////////////////////////////
-
-
-// Function name : CVMR9Graph::GetLastError
-// Description : get the last error description
-// Return type : LPCTSTR
-LPCTSTR CVMR9Graph::GetLastError() {
- return (const char *)m_pszErrorDescription;
-}
-
-
-// Function name : CVMR9Graph::AddToRot
-// Description : let the graph instance be accessible from graphedit
-// Return type : HRESULT
-// Argument : IUnknown *pUnkGraph
-// Argument : DWORD *pdwRegister
-HRESULT CVMR9Graph::AddToRot(IUnknown *pUnkGraph) {
- if (pUnkGraph == NULL) {
- return E_INVALIDARG;
- }
-
- IMoniker *pMoniker;
- IRunningObjectTable *pROT;
- if (FAILED(GetRunningObjectTable(0, &pROT))) {
- return E_FAIL;
- }
- WCHAR wsz[256];
- wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph, GetCurrentProcessId());
- HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker);
- if (SUCCEEDED(hr)) {
- hr = pROT->Register(0, pUnkGraph, pMoniker, &m_dwRotId);
- pMoniker->Release();
- }
- pROT->Release();
-
- return hr;
-}
-
-
-// Function name : CVMR9Graph::RemoveFromRot
-// Description : remove the graph instance accessibility from graphedit
-// Return type : void
-void CVMR9Graph::RemoveFromRot() {
- if (m_dwRotId != -1) {
- IRunningObjectTable *pROT;
- if (SUCCEEDED(GetRunningObjectTable(0, &pROT))) {
- pROT->Revoke(m_dwRotId);
- m_dwRotId = -1;
- pROT->Release();
- }
- }
-}
-
-
-// Function name : CVMR9Graph::GetPin
-// Description : return the desired pin
-// Return type : IPin*
-// Argument : IBaseFilter *pFilter
-// Argument : PIN_DIRECTION PinDir
-IPin *CVMR9Graph::GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir) {
- BOOL bFound = FALSE;
- IEnumPins *pEnum;
- IPin *pPin;
-
- pFilter->EnumPins(&pEnum);
- while (pEnum->Next(1, &pPin, 0) == S_OK) {
- PIN_DIRECTION PinDirThis;
- pPin->QueryDirection(&PinDirThis);
- if (PinDir == PinDirThis) {
- IPin *pTmp = 0;
- if (SUCCEEDED(pPin->ConnectedTo(&pTmp))) { // Already connected, not the pin we want.
- pTmp->Release();
- } else { // Unconnected, this is the pin we want.
- bFound = true;
- break;
- }
- }
- pPin->Release();
- }
- pEnum->Release();
-
- return (bFound ? pPin : 0);
-}
-
-
-// Function name : CVMR9Graph::ReportError
-// Description : report an error in the dump device
-// Return type : void
-// Argument : const char* pszError
-// Argument : HRESULT hrCode
-void CVMR9Graph::ReportError(const char *pszError, HRESULT hrCode) {
- TCHAR szErr[MAX_ERROR_TEXT_LEN];
- DWORD res = AMGetErrorText(hrCode, szErr, MAX_ERROR_TEXT_LEN);
- if (res != 0) {
- sprintf(m_pszErrorDescription, "[ERROR in %s, line %d] %s : COM Error 0x%x, %s", __FILE__, __LINE__, pszError, hrCode, szErr);
- } else {
- sprintf(m_pszErrorDescription, "[ERROR in %s, line %d] %s : COM Error 0x%x", __FILE__, __LINE__, pszError, hrCode);
- }
- strcpy(lastError, m_pszErrorDescription);
- //TRACE("%s \r\n", m_pszErrorDescription);
-}
-
-
-// Function name : CVMR9Graph::GetNextFilter
-// Description :
-// Return type : HRESULT
-// Argument : IBaseFilter *pFilter
-// Argument : PIN_DIRECTION Dir
-// Argument : IBaseFilter **ppNext
-HRESULT CVMR9Graph::GetNextFilter(IBaseFilter *pFilter, PIN_DIRECTION Dir, IBaseFilter **ppNext) {
- if (!pFilter || !ppNext) return E_POINTER;
-
- IEnumPins *pEnum = 0;
- IPin *pPin = 0;
- HRESULT hr = pFilter->EnumPins(&pEnum);
- if (FAILED(hr)) return hr;
- while (S_OK == pEnum->Next(1, &pPin, 0)) {
- // See if this pin matches the specified direction.
- PIN_DIRECTION ThisPinDir;
- hr = pPin->QueryDirection(&ThisPinDir);
- if (FAILED(hr)) {
- // Something strange happened.
- hr = E_UNEXPECTED;
- pPin->Release();
- break;
- }
- if (ThisPinDir == Dir) {
- // Check if the pin is connected to another pin.
- IPin *pPinNext = 0;
- hr = pPin->ConnectedTo(&pPinNext);
- if (SUCCEEDED(hr)) {
- // Get the filter that owns that pin.
- PIN_INFO PinInfo;
- hr = pPinNext->QueryPinInfo(&PinInfo);
- pPinNext->Release();
- pPin->Release();
- pEnum->Release();
- if (FAILED(hr) || (PinInfo.pFilter == NULL)) {
- // Something strange happened.
- return E_UNEXPECTED;
- }
- // This is the filter we're looking for.
- *ppNext = PinInfo.pFilter; // Client must release.
- return S_OK;
- }
- }
- pPin->Release();
- }
- pEnum->Release();
- // Did not find a matching filter.
- return E_FAIL;
-}
-
-
-// Function name : CVMR9Graph::RemoveFilterChain
-// Description : remove a chain of filter, stopping at pStopFilter
-// Return type : BOOL
-// Argument : IBaseFilter* pFilter
-// Argument : IBaseFilter* pStopFilter
-BOOL CVMR9Graph::RemoveFilterChain(IBaseFilter *pFilter, IBaseFilter *pStopFilter) {
- HRESULT hr;
-
- IBaseFilter *pFilterFound = NULL;
-
- hr = GetNextFilter(pFilter, PINDIR_OUTPUT, &pFilterFound);
- if (SUCCEEDED(hr) && pFilterFound != pStopFilter) {
- RemoveFilterChain(pFilterFound, pStopFilter);
- pFilterFound->Release();
- }
-
- m_pFilterGraph->RemoveFilter(pFilter);
-
- return TRUE;
-}
-
-
-// Function name : CVMR9Graph::AddFilterByClsid
-// Description : add a filter in the chain
-// Return type : HRESULT
-// Argument : IGraphBuilder *pGraph
-// Argument : LPCWSTR wszName
-// Argument : const GUID& clsid
-// Argument : IBaseFilter **ppF
-HRESULT CVMR9Graph::AddFilterByClsid(IGraphBuilder *pGraph, LPCWSTR wszName, const GUID &clsid, IBaseFilter **ppF) {
- *ppF = NULL;
- HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)ppF);
- if (SUCCEEDED(hr)) {
- hr = pGraph->AddFilter((*ppF), wszName);
- }
- return hr;
-}
-
-
-//////////////////////////////////////////////////////////////////////
-// Layer helper methods
-//////////////////////////////////////////////////////////////////////
-
-
-// Function name : CVMR9Graph::IsValidLayer
-// Description : check for valid layer
-// Return type : BOOL
-// Argument : int nLayer
-BOOL CVMR9Graph::IsValidLayer(int nLayer) {
- if (nLayer > 9 || nLayer < 0) return FALSE;
-
- IBaseFilter *pBaseFilter = m_srcFilterArray[nLayer];
- if (pBaseFilter == NULL)
- return FALSE;
- else
- return TRUE;
-}
-
-
-
-//////////////////////////////////////////////////////////////////////
-// Graph Construction / Render
-//////////////////////////////////////////////////////////////////////
-
-
-// We need this because the filter graph must be built
-// on the D3D thread
-static int wndproc_build_filter_graph() {
- return graph->BuildAndRenderGraph(graph->UseAVISound);
-}
-
-BOOL CVMR9Graph::BuildAndRenderGraph(bool withSound) {
- USES_CONVERSION;
-
- int nLayer = 0;
- HRESULT hr;
-
- // ENSURE that a valid graph builder is available
- if (m_pGraphBuilder == NULL) {
- BOOL bRet = BuildFilterGraph(withSound);
- if (!bRet) return bRet;
- }
-
- // ENSURE that the filter graph is in a stop state
- OAFilterState filterState;
- m_pMediaControl->GetState(500, &filterState);
- if (filterState != State_Stopped) {
- m_pMediaControl->Stop();
- }
-
- // CHECK a source filter availaibility for the layer
- if (m_srcFilterArray[nLayer] == NULL) {
- char pszFilterName[10];
- sprintf(pszFilterName, "SRC%02d", nLayer);
- IBaseFilter *pBaseFilter = NULL;
- hr = m_pGraphBuilder->AddSourceFilter(A2W(m_pszFileName), A2W(pszFilterName), &pBaseFilter);
- if (FAILED(hr)) {
- ReportError("Could not find a source filter for this file", hr);
- return FALSE;
- }
- m_srcFilterArray[nLayer] = pBaseFilter;
- } else {
- // suppress the old src filter
- IBaseFilter *pBaseFilter = m_srcFilterArray[nLayer];
- RemoveFilterChain(pBaseFilter, m_pVMRBaseFilter);
- pBaseFilter->Release();
- m_srcFilterArray[nLayer] = NULL;
- // create a new src filter
- char pszFilterName[10];
- sprintf(pszFilterName, "SRC%02d", nLayer);
- hr = m_pGraphBuilder->AddSourceFilter(A2W(m_pszFileName), A2W(pszFilterName), &pBaseFilter);
- m_srcFilterArray[nLayer] = pBaseFilter;
- if (FAILED(hr)) {
- m_srcFilterArray[nLayer] = NULL;
- ReportError("Could not load the file", hr);
- return FALSE;
- }
- }
-
- // RENDER the graph
- BOOL bRet = RenderGraph();
- if (!bRet) return bRet;
-
- return TRUE;
-}
-
-// Function name : CVMR9Graph::SetMediaFile
-// Description : set a media source
-// Return type : BOOL
-// Argument : const char* pszFileName
-// Argument : int nLayer = 0
-BOOL CVMR9Graph::SetMediaFile(const char *pszFileName, bool withSound, int nLayer) {
-
- if (pszFileName == NULL) {
- ReportError("Could not load a file with an empty file name", E_INVALIDARG);
- return FALSE;
- }
-
- UseAVISound = withSound;
- m_pszFileName = pszFileName;
-
- if (!wnd_call_proc(wndproc_build_filter_graph))
- return FALSE;
-
-
- return TRUE;
-}
-
-// Function name : CVMR9Graph::BuildFilterGraph
-// Description : construct the filter graph
-// Return type : BOOL
-BOOL CVMR9Graph::BuildFilterGraph(bool withSound) {
- HRESULT hr;
-
- ReleaseAllInterfaces();
- RemoveFromRot();
-
- // BUILD the filter graph
- hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IUnknown, (void **) &m_pGraphUnknown);
- if (FAILED(hr)) {
- ReportError("Could not build the graph", hr);
- return FALSE;
- }
- // QUERY the filter graph interfaces
- hr = m_pGraphUnknown->QueryInterface(IID_IGraphBuilder, (void **) &m_pGraphBuilder);
- hr = m_pGraphUnknown->QueryInterface(IID_IFilterGraph, (void **) &m_pFilterGraph);
- hr = m_pGraphUnknown->QueryInterface(IID_IFilterGraph2, (void **) &m_pFilterGraph2);
- hr = m_pGraphUnknown->QueryInterface(IID_IMediaControl, (void **) & m_pMediaControl);
- hr = m_pGraphUnknown->QueryInterface(IID_IMediaSeeking, (void **) & m_pMediaSeeking);
- //hr = m_pGraphUnknown->QueryInterface(IID_IMediaEvent, (void**) &m_pMediaEvent);
- //hr = m_pGraphUnknown->QueryInterface(IID_IMediaEventEx, (void**) &m_pMediaEventEx);
-
- /* // SET the graph state window callback
- if (m_pMediaEventEx != NULL) {
- m_pMediaEventEx->SetNotifyWindow((OAHWND)m_hMediaWindow, WM_MEDIA_NOTIF, NULL);
- //m_pMediaEventEx->SetNotifyWindow(NULL, NULL, NULL);
- }*/
-
- if (withSound)
- BuildSoundRenderer();
-
-// Don't known what's wrong... but RenderEx crash when playing whith graphedit build 021204 ...
- //do we need this??
- //AddToRot(m_pGraphUnknown);
-
- return BuildVMR();
-}
-
-
-// Function name : CVMR9Graph::BuildVMR
-// Description : construct and add the VMR9 renderer to the graph
-// Return type : BOOL
-BOOL CVMR9Graph::BuildVMR() {
- HRESULT hr;
-
- if (m_hMediaWindow == NULL) {
- ReportError("Could not operate without a Window", E_FAIL);
- return FALSE;
- }
-
- if (m_pGraphBuilder == NULL) {
- ReportError("Could not build the VMR, the graph isn't valid", E_FAIL);
- return FALSE;
- }
-
- // BUILD the VMR9
- IBaseFilter *pVmr = NULL;
- hr = CoCreateInstance(CLSID_VideoMixingRenderer9, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **) &m_pVMRBaseFilter);
- if (FAILED(hr)) {
- ReportError("Could not create an instance ofthe VMR9", hr);
- return FALSE;
- }
-
- // ADD the VMR9 to the graph
- hr = m_pGraphBuilder->AddFilter(m_pVMRBaseFilter, L"VMR9");
- if (FAILED(hr)) {
- ReportError("Could not add the VMR9 to the Graph", hr);
- return FALSE;
- }
-
- // DIRECT3D
- //BOOL bD3D = BuildDirect3d();
-
- // QUERY the VMR9 interfaces
- hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRFilterConfig9, (void **) &m_pVMRFilterConfig);
- if (SUCCEEDED(hr)) {
- // CONFIGURE the VMR9
- m_pVMRFilterConfig->SetRenderingMode(VMR9Mode_Windowless);
- m_pVMRFilterConfig->SetNumberOfStreams(m_nNumberOfStream);
- }
-
- hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRWindowlessControl9, (void **) &m_pVMRWindowlessControl);
- if (SUCCEEDED(hr)) {
- // CONFIGURE the VMR9
- m_pVMRWindowlessControl->SetVideoClippingWindow(m_hMediaWindow);
- m_pVMRWindowlessControl->SetAspectRatioMode(VMR9ARMode_LetterBox);
- }
-
- hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRMixerBitmap9, (void **) &m_pVMRMixerBitmap);
- hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRMixerControl9, (void **) &m_pVMRMixerControl);
- hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRMonitorConfig9, (void **) &m_pVMRMonitorConfig);
-
- return TRUE;
-}
-
-
-// Function name : CVMR9Graph::BuildSoundRendered
-// Description : build the DirectSound renderer
-// Return type : BOOL
-BOOL CVMR9Graph::BuildSoundRenderer() {
- HRESULT hr;
-
- hr = AddFilterByClsid(m_pGraphBuilder, L"DirectSound", CLSID_DSoundRender, &m_pDirectSoundFilter);
- if (FAILED(hr)) {
- ReportError("Could not add the DirectSoundRenderer", hr);
- return FALSE;
- }
- return TRUE;
-}
-
-// Function name : CVMR9Graph::RenderGraph
-// Description : render the graph
-// Return type : BOOL
-BOOL CVMR9Graph::RenderGraph() {
- HRESULT hr;
-
- if (m_pFilterGraph2 == NULL) {
- ReportError("Could not render the graph because it is not fully constructed", E_FAIL);
- return FALSE;
- }
-
- for (int i = 0; i < 10; i++) {
- IBaseFilter *pBaseFilter = m_srcFilterArray[i];
- if (pBaseFilter != NULL) {
- IPin *pPin;
- while ((pPin = GetPin(pBaseFilter, PINDIR_OUTPUT)) != NULL) {
- hr = m_pFilterGraph2->RenderEx(pPin, AM_RENDEREX_RENDERTOEXISTINGRENDERERS, NULL);
- if (FAILED(hr)) {
- ReportError("Unable to render the pin", hr);
- return FALSE;
- }
- }
- }
- }
- return TRUE;
-}
-
-
-// Function name : CVMR9Graph::PreserveAspectRatio
-// Description : set aspect ratio mode
-// Return type : BOOL
-// Argument : BOOL bPreserve
-BOOL CVMR9Graph::PreserveAspectRatio(BOOL bPreserve) {
- if (m_pVMRWindowlessControl == NULL) {
- ReportError("Can't set aspect ratio, no VMR", E_FAIL);
- return FALSE;
- }
-
- if (bPreserve)
- m_pVMRWindowlessControl->SetAspectRatioMode(VMR9ARMode_LetterBox);
- else
- m_pVMRWindowlessControl->SetAspectRatioMode(VMR9ARMode_None);
-
- return TRUE;
-}
-
-
-// Function name : CVMR9Graph::AddFilter
-// Description : manually add a filter in the graph
-// Return type : IBaseFilter* : caller responsible of release
-// Argument : const char* pszName
-// Argument : const GUID& clsid
-IBaseFilter *CVMR9Graph::AddFilter(const char *pszName, const GUID &clsid) {
- USES_CONVERSION;
-
- HRESULT hr;
-
- IBaseFilter *pBaseFilter = NULL;
-
- if (pszName == NULL) {
- ReportError("Can't add filter, no valid name", E_INVALIDARG);
- return NULL;
- }
-
- hr = AddFilterByClsid(m_pGraphBuilder, A2W(pszName), clsid, &pBaseFilter);
- if (FAILED(hr)) {
- ReportError("Can't add filter", hr);
- return NULL;
- }
-
- return pBaseFilter;
-}
-
-// Function name : CVMR9Graph::PlayGraph
-// Description : run the graph
-// Return type : BOOL
-BOOL CVMR9Graph::PlayGraph() {
- if (m_pMediaControl == NULL) {
- ReportError("Can't play, no graph", E_FAIL);
- return FALSE;
- }
- if (m_pVMRWindowlessControl == NULL) {
- ReportError("Can't play, no VMR", E_FAIL);
- return FALSE;
- }
-
- // MEDIA SIZE
- LONG Width;
- LONG Height;
- LONG ARWidth;
- LONG ARHeight;
- m_pVMRWindowlessControl->GetNativeVideoSize(&Width, &Height, &ARWidth, &ARHeight);
-
- RECT mediaRect;
- mediaRect.left = 0;
- mediaRect.top = 0;
- mediaRect.right = Width;
- mediaRect.bottom = Height;
-
- RECT wndRect;
- GetClientRect(m_hMediaWindow, &wndRect);
-
- m_pVMRWindowlessControl->SetVideoPosition(&mediaRect, &wndRect);
-
- // RUN
- m_pMediaControl->Run();
-
- return TRUE;
-}
-
-
-// Function name : CVMR9Graph::StopGraph
-// Description : stop the graph
-// Return type : BOOL
-BOOL CVMR9Graph::StopGraph() {
- if (m_pMediaControl == NULL) {
- ReportError("Can't stop, no graph", E_FAIL);
- return FALSE;
- }
-
- m_pMediaControl->Stop();
-
- return TRUE;
-}
-
-OAFilterState CVMR9Graph::GetState() {
- OAFilterState filterState;
- m_pMediaControl->GetState(500, &filterState);
- if (filterState == State_Running) {
- LONGLONG curPos;
- m_pMediaSeeking->GetCurrentPosition(&curPos);
- LONGLONG length;
- m_pMediaSeeking->GetDuration(&length);
-
- if (curPos >= length) {
- filterState = State_Stopped;
- }
- }
-
- return filterState;
-}
-
-
-// Function name : CVMR9Graph::ResetGraph
-// Description : reset the graph - clean interfaces
-// Return type : BOOL
-BOOL CVMR9Graph::ResetGraph() {
- // STOP the graph
- if (m_pMediaControl != NULL) {
- m_pMediaControl->Stop();
- }
-
- try {
- ReleaseAllInterfaces();
- } catch (...) {
- ReportError("Can't reset graph, we have serious bugs...", E_FAIL);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-// Function name : SetLayerZOrder
-// Description : set z order of the layer
-// Return type : BOOL
-// Argument : int nLayer
-// Argument : DWORD dwZOrder : bigger is away
-BOOL CVMR9Graph::SetLayerZOrder(int nLayer, DWORD dwZOrder) {
- HRESULT hr;
-
- if (!IsValidLayer(nLayer)) {
- ReportError("Can't set order, incorect layer", E_INVALIDARG);
- return FALSE;
- }
-
- if (m_pVMRMixerControl == NULL) {
- ReportError("Can't set order, no VMR", E_FAIL);
- return FALSE;
- }
-
- hr = m_pVMRMixerControl->SetZOrder(nLayer, dwZOrder);
- if (FAILED(hr)) {
- ReportError("Can't set ZOrder", hr);
- return FALSE;
- }
-
- return TRUE;
-}
-
-} // namespace AGS3
-
-#endif
More information about the Scummvm-git-logs
mailing list