mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Add initial video playback support for Ogg Theora videos (resolves issue #66.)
The basic APIs are:
video = love.graphics.newVideo("myvideo.ogv")
love.graphics.draw(video, ...) -- Video objects are Drawables.
video:play(), video:pause()
video:getDuration(), video:tell(), video:rewind(), video:seek(seconds)
video:getSource()
video:getWidth(), video:getHeight(), video:setFilter(min, mag)
More advanced APIs include video:setSource(source), video:getStream(), and videostream:setSync.
To use a custom pixel shader when drawing a Video, call the new TexelVideo(texcoords) function instead of Texel(texture, texcoords) in order to get the pixel colors of a video frame.
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_VIDEO_VIDEOSTREAM_H
|
||||
#define LOVE_VIDEO_VIDEOSTREAM_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Stream.h"
|
||||
#include "audio/Source.h"
|
||||
#include "thread/threads.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace video
|
||||
{
|
||||
|
||||
class VideoStream : public Stream
|
||||
{
|
||||
public:
|
||||
virtual ~VideoStream() {}
|
||||
|
||||
virtual int getWidth() const = 0;
|
||||
virtual int getHeight() const = 0;
|
||||
virtual const std::string &getFilename() const = 0;
|
||||
|
||||
// Playback api
|
||||
virtual void play();
|
||||
virtual void pause();
|
||||
virtual void seek(double offset);
|
||||
virtual double tell();
|
||||
virtual bool isPlaying();
|
||||
|
||||
class FrameSync;
|
||||
class DeltaSync;
|
||||
|
||||
// The stream now owns the sync, do not reuse or free
|
||||
virtual void setSync(FrameSync *frameSync);
|
||||
virtual FrameSync *getSync() const;
|
||||
|
||||
// Data structures
|
||||
struct Frame
|
||||
{
|
||||
Frame();
|
||||
~Frame();
|
||||
|
||||
int yw, yh;
|
||||
unsigned char *yplane;
|
||||
|
||||
int cw, ch;
|
||||
unsigned char *cbplane;
|
||||
unsigned char *crplane;
|
||||
};
|
||||
|
||||
class FrameSync : public Object
|
||||
{
|
||||
public:
|
||||
virtual double getPosition() const = 0;
|
||||
virtual void update(double /*dt*/) {}
|
||||
virtual ~FrameSync() {}
|
||||
|
||||
void copyState(const FrameSync *other);
|
||||
|
||||
// Playback api
|
||||
virtual void play() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void seek(double offset) = 0;
|
||||
virtual double tell() const;
|
||||
virtual bool isPlaying() const = 0;
|
||||
};
|
||||
|
||||
class DeltaSync : public FrameSync
|
||||
{
|
||||
public:
|
||||
DeltaSync();
|
||||
~DeltaSync();
|
||||
|
||||
virtual double getPosition() const override;
|
||||
virtual void update(double dt) override;
|
||||
|
||||
virtual void play() override;
|
||||
virtual void pause() override;
|
||||
virtual void seek(double time) override;
|
||||
virtual bool isPlaying() const override;
|
||||
|
||||
private:
|
||||
bool playing;
|
||||
double position;
|
||||
double speed;
|
||||
love::thread::MutexRef mutex;
|
||||
};
|
||||
|
||||
class SourceSync : public FrameSync
|
||||
{
|
||||
public:
|
||||
SourceSync(love::audio::Source *source);
|
||||
|
||||
virtual double getPosition() const override;
|
||||
virtual void play() override;
|
||||
virtual void pause() override;
|
||||
virtual void seek(double time) override;
|
||||
virtual bool isPlaying() const override;
|
||||
|
||||
private:
|
||||
StrongRef<love::audio::Source> source;
|
||||
};
|
||||
|
||||
protected:
|
||||
StrongRef<FrameSync> frameSync;
|
||||
};
|
||||
|
||||
} // video
|
||||
} // love
|
||||
|
||||
#endif // LOVE_VIDEO_VIDEOSTREAM_H
|
||||
Reference in New Issue
Block a user