2007-01-21 07:30:19 +01:00
|
|
|
// Copyright (c) 2005-2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
|
|
|
#include <time.h>
|
2007-06-19 06:14:25 +02:00
|
|
|
#include <wx/wxprec.h>
|
2007-01-21 07:30:19 +01:00
|
|
|
#include <wx/glcanvas.h>
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/timer.h>
|
2008-01-20 07:14:40 +01:00
|
|
|
#include <wx/stopwatch.h>
|
2008-11-22 20:07:56 +01:00
|
|
|
#if ! wxUSE_GLCANVAS
|
2007-06-19 09:03:33 +02:00
|
|
|
#error "Aegisub requires wxWidgets to be compiled with OpenGL support."
|
|
|
|
#endif
|
2007-06-19 06:14:25 +02:00
|
|
|
#include <list>
|
2007-09-12 01:22:26 +02:00
|
|
|
#ifdef __APPLE__
|
2007-06-19 06:14:25 +02:00
|
|
|
#include <OpenGL/GL.h>
|
|
|
|
#include <OpenGL/glu.h>
|
|
|
|
#else
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
2007-09-12 01:22:26 +02:00
|
|
|
typedef GLuint GLhandleARB;
|
2007-06-19 06:14:25 +02:00
|
|
|
#endif
|
2007-01-21 07:30:19 +01:00
|
|
|
#include "video_frame.h"
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Prototypes
|
|
|
|
class SubtitlesGrid;
|
|
|
|
class AudioProvider;
|
|
|
|
class AudioDisplay;
|
|
|
|
class AssDialogue;
|
|
|
|
class VideoProvider;
|
|
|
|
class VideoDisplay;
|
|
|
|
class SubtitlesProvider;
|
2007-04-08 01:45:46 +02:00
|
|
|
class VideoContextThread;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Main class
|
|
|
|
class VideoContext : public wxEvtHandler {
|
|
|
|
friend class AudioProvider;
|
2007-07-01 02:19:55 +02:00
|
|
|
friend class VisualTool;
|
2007-04-08 01:45:46 +02:00
|
|
|
friend class VideoContextThread;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
static VideoContext *instance;
|
|
|
|
std::list<VideoDisplay*> displayList;
|
|
|
|
|
|
|
|
GLuint lastTex;
|
2007-09-12 01:22:26 +02:00
|
|
|
GLhandleARB yv12shader;
|
2007-01-21 07:30:19 +01:00
|
|
|
int lastFrame;
|
|
|
|
wxGLContext *glContext;
|
|
|
|
VideoFrameFormat vidFormat;
|
|
|
|
AegiVideoFrame tempFrame;
|
|
|
|
|
|
|
|
wxString tempfile;
|
|
|
|
VideoProvider *provider;
|
|
|
|
SubtitlesProvider *subsProvider;
|
|
|
|
|
|
|
|
bool keyFramesLoaded;
|
|
|
|
bool overKeyFramesLoaded;
|
|
|
|
wxArrayInt KeyFrames;
|
|
|
|
wxArrayInt overKeyFrames;
|
|
|
|
wxString keyFramesFilename;
|
|
|
|
|
|
|
|
wxMutex playMutex;
|
|
|
|
wxTimer playback;
|
2008-01-20 07:14:40 +01:00
|
|
|
wxStopWatch playTime;
|
2007-01-21 07:30:19 +01:00
|
|
|
int startFrame;
|
|
|
|
int endFrame;
|
|
|
|
int playNextFrame;
|
|
|
|
int nextFrame;
|
2007-04-08 01:45:46 +02:00
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
bool threaded;
|
2007-04-08 01:45:46 +02:00
|
|
|
bool threadLocked;
|
|
|
|
int threadNextFrame;
|
|
|
|
wxMutex vidMutex;
|
|
|
|
wxThread *thread;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
bool loaded;
|
|
|
|
bool isInverted;
|
|
|
|
bool isPlaying;
|
2007-06-02 15:48:36 +02:00
|
|
|
bool keepAudioSync;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
float texW,texH;
|
|
|
|
int w,h;
|
|
|
|
int frame_n;
|
|
|
|
int length;
|
|
|
|
double fps;
|
|
|
|
|
2007-01-23 07:32:16 +01:00
|
|
|
double arValue;
|
|
|
|
int arType;
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
void UnloadTexture();
|
|
|
|
void OnPlayTimer(wxTimerEvent &event);
|
|
|
|
|
|
|
|
public:
|
|
|
|
SubtitlesGrid *grid;
|
|
|
|
wxString videoName;
|
|
|
|
|
|
|
|
AssDialogue *curLine;
|
|
|
|
AudioDisplay *audio;
|
|
|
|
|
|
|
|
VideoContext();
|
|
|
|
~VideoContext();
|
|
|
|
|
|
|
|
void AddDisplay(VideoDisplay *display);
|
|
|
|
void RemoveDisplay(VideoDisplay *display);
|
|
|
|
|
|
|
|
VideoProvider *GetProvider() { return provider; }
|
2007-04-08 00:03:06 +02:00
|
|
|
AegiVideoFrame GetFrame(int n,bool raw=false);
|
|
|
|
|
|
|
|
void SaveSnapshot(bool raw);
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
wxGLContext *GetGLContext(wxGLCanvas *canvas);
|
|
|
|
GLuint GetFrameAsTexture(int n);
|
|
|
|
float GetTexW() { return texW; }
|
|
|
|
float GetTexH() { return texH; }
|
|
|
|
VideoFrameFormat GetFormat() { return vidFormat; }
|
2007-01-27 07:15:25 +01:00
|
|
|
void SetShader(bool enabled);
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
bool IsLoaded() { return loaded; }
|
|
|
|
bool IsPlaying() { return isPlaying; }
|
|
|
|
bool IsInverted() { return isInverted; }
|
|
|
|
|
2007-06-02 15:48:36 +02:00
|
|
|
void EnableAudioSync(bool sync = true) { keepAudioSync = sync; }
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
int GetWidth() { return w; }
|
|
|
|
int GetHeight() { return h; }
|
|
|
|
int GetLength() { return length; }
|
|
|
|
int GetFrameN() { return frame_n; }
|
|
|
|
double GetFPS() { return fps; }
|
|
|
|
void SetFPS(double _fps) { fps = _fps; }
|
|
|
|
|
2007-01-23 07:32:16 +01:00
|
|
|
double GetARFromType(int type);
|
|
|
|
void SetAspectRatio(int type,double value=1.0);
|
|
|
|
int GetAspectRatioType() { return arType; }
|
|
|
|
double GetAspectRatioValue() { return arValue; }
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
void SetVideo(const wxString &filename);
|
|
|
|
void Reset();
|
2007-04-08 21:27:46 +02:00
|
|
|
void Reload();
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
void JumpToFrame(int n);
|
2007-04-07 05:12:55 +02:00
|
|
|
void JumpToTime(int ms,bool exact=false);
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
void Refresh(bool video,bool subtitles);
|
|
|
|
void UpdateDisplays(bool full);
|
|
|
|
|
|
|
|
void GetScriptSize(int &w,int &h);
|
|
|
|
wxString GetTempWorkFile ();
|
|
|
|
|
|
|
|
void Play();
|
|
|
|
void PlayLine();
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
wxArrayInt GetKeyFrames();
|
|
|
|
void SetKeyFrames(wxArrayInt frames);
|
|
|
|
void SetOverKeyFrames(wxArrayInt frames);
|
|
|
|
void CloseOverKeyFrames();
|
|
|
|
bool OverKeyFramesLoaded();
|
|
|
|
bool KeyFramesLoaded();
|
|
|
|
wxString GetKeyFramesName() { return keyFramesFilename; }
|
|
|
|
void SetKeyFramesName(wxString name) { keyFramesFilename = name; }
|
|
|
|
|
|
|
|
static VideoContext *Get();
|
|
|
|
static void Clear();
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
2007-04-08 01:45:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
//////////
|
|
|
|
// Thread
|
|
|
|
class VideoContextThread : public wxThread {
|
|
|
|
private:
|
|
|
|
VideoContext *parent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VideoContextThread(VideoContext *parent);
|
|
|
|
wxThread::ExitCode Entry();
|
|
|
|
};
|