2012-01-21 21:57:41 +01:00
|
|
|
/***************************************************************************
|
2014-03-18 03:39:42 +01:00
|
|
|
* Copyright (C) 2010 by Dimok
|
|
|
|
* (C) 2014 by FIX94
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* WiiMovie.cpp
|
|
|
|
*
|
|
|
|
* for WiiXplorer 2010
|
|
|
|
***************************************************************************/
|
|
|
|
#include <unistd.h>
|
2014-03-17 18:38:32 +01:00
|
|
|
#include "memory/mem2.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "WiiMovie.hpp"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2014-03-01 00:11:02 +01:00
|
|
|
WiiMovie movie;
|
|
|
|
void WiiMovie::Init(const char *filepath)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
Frame = NULL;
|
|
|
|
BufferPos = 0;
|
|
|
|
Buffer[0].thread = false;
|
|
|
|
Buffer[1].thread = false;
|
2012-12-28 15:19:40 +01:00
|
|
|
VideoFrameCount = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
fps = 0.0f;
|
2012-12-28 15:19:40 +01:00
|
|
|
ExitRequested = false;
|
|
|
|
Playing = false;
|
2012-01-21 21:57:41 +01:00
|
|
|
ThreadStack = NULL;
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Opening video '%s'\n", filepath);
|
2014-03-01 00:11:02 +01:00
|
|
|
ReadThread = LWP_THREAD_NULL;
|
|
|
|
vFile = fopen(filepath, "rb");
|
|
|
|
if(!vFile)
|
2012-12-28 15:19:40 +01:00
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Open video failed\n");
|
2012-12-28 15:19:40 +01:00
|
|
|
ExitRequested = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
return;
|
2012-12-28 15:19:40 +01:00
|
|
|
}
|
2014-03-01 00:11:02 +01:00
|
|
|
if(Video.Init(vFile) == false)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Memory Allocation failed\n");
|
2014-03-01 00:11:02 +01:00
|
|
|
ExitRequested = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
return;
|
2014-03-01 00:11:02 +01:00
|
|
|
}
|
|
|
|
fps = Video.getFps();
|
2014-03-18 03:39:42 +01:00
|
|
|
inited = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-01 00:11:02 +01:00
|
|
|
void WiiMovie::DeInit()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
if(inited == false)
|
|
|
|
return;
|
|
|
|
inited = false;
|
|
|
|
//gprintf("Destructing WiiMovie object\n");
|
2012-12-28 15:19:40 +01:00
|
|
|
Playing = false;
|
|
|
|
ExitRequested = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
Stop();
|
|
|
|
|
2012-12-28 15:19:40 +01:00
|
|
|
if(ReadThread != LWP_THREAD_NULL)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
LWP_ResumeThread(ReadThread);
|
|
|
|
LWP_JoinThread(ReadThread, NULL);
|
|
|
|
}
|
2012-12-28 15:19:40 +01:00
|
|
|
if(ThreadStack != NULL)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-17 18:38:32 +01:00
|
|
|
MEM2_lo_free(ThreadStack);
|
2012-01-21 21:57:41 +01:00
|
|
|
ThreadStack = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-01 00:11:02 +01:00
|
|
|
Video.DeInit();
|
|
|
|
if(vFile != NULL)
|
|
|
|
fclose(vFile);
|
2014-03-22 22:32:40 +01:00
|
|
|
VideoF.dealloc();
|
2014-03-01 00:11:02 +01:00
|
|
|
vFile = NULL;
|
2014-03-18 03:39:42 +01:00
|
|
|
Frame = NULL;
|
|
|
|
TexHandle.Cleanup(Buffer[0]);
|
|
|
|
TexHandle.Cleanup(Buffer[1]);
|
|
|
|
Buffer[0].thread = false;
|
|
|
|
Buffer[1].thread = false;
|
|
|
|
BufferPos = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-18 03:39:42 +01:00
|
|
|
bool WiiMovie::Play(bool loop)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-01 00:11:02 +01:00
|
|
|
if(!vFile)
|
2012-12-28 15:19:40 +01:00
|
|
|
return false;
|
2014-03-01 00:11:02 +01:00
|
|
|
|
2014-03-17 18:38:32 +01:00
|
|
|
ThreadStack = (u8*)MEM2_lo_alloc(32768);
|
2014-03-01 00:11:02 +01:00
|
|
|
if(!ThreadStack)
|
2012-05-13 19:25:26 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Start playing video\n");
|
2014-03-01 00:11:02 +01:00
|
|
|
Video.loop = loop;
|
2012-12-28 15:19:40 +01:00
|
|
|
PlayTime.reset();
|
2014-03-01 00:11:02 +01:00
|
|
|
Playing = true;
|
2014-03-18 03:39:42 +01:00
|
|
|
Buffer[0].thread = false;
|
|
|
|
Buffer[1].thread = false;
|
2014-03-22 22:32:40 +01:00
|
|
|
LWP_CreateThread(&ReadThread, UpdateThread, this, ThreadStack, 32768, 63);
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Reading frames thread started\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiiMovie::Stop()
|
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
//gprintf("Stopping WiiMovie video\n");
|
2012-12-28 15:19:40 +01:00
|
|
|
ExitRequested = true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void * WiiMovie::UpdateThread(void *arg)
|
|
|
|
{
|
|
|
|
WiiMovie *movie = static_cast<WiiMovie *>(arg);
|
2012-12-28 15:19:40 +01:00
|
|
|
while(!movie->ExitRequested)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
movie->ReadNextFrame();
|
2014-03-18 03:39:42 +01:00
|
|
|
if(movie->Buffer[movie->BufferPos].thread == false)
|
2014-03-01 00:11:02 +01:00
|
|
|
movie->LoadNextFrame();
|
2014-03-18 03:39:42 +01:00
|
|
|
else if(movie->Frame->thread == false)
|
|
|
|
{
|
|
|
|
movie->Frame = &movie->Buffer[movie->BufferPos];
|
|
|
|
movie->BufferPos ^= 1;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiiMovie::ReadNextFrame()
|
|
|
|
{
|
2014-03-01 00:11:02 +01:00
|
|
|
for(u32 FramesNeeded = (u32)(PlayTime.elapsed()*fps); VideoFrameCount <= FramesNeeded; ++VideoFrameCount)
|
2012-12-28 15:19:40 +01:00
|
|
|
{
|
2014-03-01 00:11:02 +01:00
|
|
|
if(VideoFrameCount == FramesNeeded)
|
|
|
|
Playing = Video.loadNextFrame();
|
|
|
|
else
|
|
|
|
Video.loadNextFrame(true);
|
2012-12-28 15:19:40 +01:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiiMovie::LoadNextFrame()
|
|
|
|
{
|
2014-03-01 00:11:02 +01:00
|
|
|
if(!vFile || !Playing)
|
2012-12-28 15:19:40 +01:00
|
|
|
return;
|
2014-03-01 00:11:02 +01:00
|
|
|
Video.getCurrentFrame(VideoF);
|
2014-03-22 22:32:40 +01:00
|
|
|
if(!VideoF.data)
|
2012-12-28 15:19:40 +01:00
|
|
|
return;
|
2014-03-18 03:39:42 +01:00
|
|
|
TexData *CurFrame = &Buffer[BufferPos];
|
2014-03-22 22:32:40 +01:00
|
|
|
if(TexHandle.fromTHP(CurFrame, VideoF.data, VideoF.getWidth(), VideoF.getHeight()) == TE_OK)
|
2014-03-18 03:39:42 +01:00
|
|
|
{
|
|
|
|
CurFrame->thread = true;
|
|
|
|
Frame = CurFrame;
|
|
|
|
BufferPos ^= 1;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-01 00:11:02 +01:00
|
|
|
bool WiiMovie::Continue()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2014-03-18 03:39:42 +01:00
|
|
|
if(!vFile || !Playing)
|
2012-11-03 20:16:03 +01:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|