1/**
2 * Copyright (c) 2006-2023 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21#ifndef LOVE_VIDEO_VIDEOSTREAM_H
22#define LOVE_VIDEO_VIDEOSTREAM_H
23
24// LOVE
25#include "common/Stream.h"
26#include "audio/Source.h"
27#include "thread/threads.h"
28
29namespace love
30{
31namespace video
32{
33
34class VideoStream : public Stream
35{
36public:
37
38 static love::Type type;
39
40 virtual ~VideoStream() {}
41
42 virtual int getWidth() const = 0;
43 virtual int getHeight() const = 0;
44 virtual const std::string &getFilename() const = 0;
45
46 // Playback api
47 virtual void play();
48 virtual void pause();
49 virtual void seek(double offset);
50 virtual double tell() const;
51 virtual bool isPlaying() const;
52
53 class FrameSync;
54 class DeltaSync;
55
56 // The stream now owns the sync, do not reuse or free
57 virtual void setSync(FrameSync *frameSync);
58 virtual FrameSync *getSync() const;
59
60 // Data structures
61 struct Frame
62 {
63 Frame();
64 ~Frame();
65
66 int yw, yh;
67 unsigned char *yplane;
68
69 int cw, ch;
70 unsigned char *cbplane;
71 unsigned char *crplane;
72 };
73
74 class FrameSync : public Object
75 {
76 public:
77 virtual double getPosition() const = 0;
78 virtual void update(double /*dt*/) {}
79 virtual ~FrameSync() {}
80
81 void copyState(const FrameSync *other);
82
83 // Playback api
84 virtual void play() = 0;
85 virtual void pause() = 0;
86 virtual void seek(double offset) = 0;
87 virtual double tell() const;
88 virtual bool isPlaying() const = 0;
89 };
90
91 class DeltaSync : public FrameSync
92 {
93 public:
94 DeltaSync();
95 ~DeltaSync();
96
97 virtual double getPosition() const override;
98 virtual void update(double dt) override;
99
100 virtual void play() override;
101 virtual void pause() override;
102 virtual void seek(double time) override;
103 virtual bool isPlaying() const override;
104
105 private:
106 bool playing;
107 double position;
108 double speed;
109 love::thread::MutexRef mutex;
110 };
111
112 class SourceSync : public FrameSync
113 {
114 public:
115 SourceSync(love::audio::Source *source);
116
117 virtual double getPosition() const override;
118 virtual void play() override;
119 virtual void pause() override;
120 virtual void seek(double time) override;
121 virtual bool isPlaying() const override;
122
123 private:
124 StrongRef<love::audio::Source> source;
125 };
126
127protected:
128 StrongRef<FrameSync> frameSync;
129};
130
131} // video
132} // love
133
134#endif // LOVE_VIDEO_VIDEOSTREAM_H
135