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#include "wrap_VideoStream.h"
22
23namespace love
24{
25namespace video
26{
27
28VideoStream *luax_checkvideostream(lua_State *L, int idx)
29{
30 return luax_checktype<VideoStream>(L, idx);
31}
32
33int w_VideoStream_setSync(lua_State *L)
34{
35 auto stream = luax_checkvideostream(L, 1);
36
37 if (luax_istype(L, 2, love::audio::Source::type))
38 {
39 auto src = luax_totype<love::audio::Source>(L, 2);
40 auto sync = new VideoStream::SourceSync(src);
41 stream->setSync(sync);
42 sync->release();
43 }
44 else if (luax_istype(L, 2, VideoStream::type))
45 {
46 auto other = luax_totype<VideoStream>(L, 2);
47 stream->setSync(other->getSync());
48 }
49 else if (lua_isnoneornil(L, 2))
50 {
51 auto newSync = new VideoStream::DeltaSync();
52 newSync->copyState(stream->getSync());
53 stream->setSync(newSync);
54 newSync->release();
55 }
56 else
57 return luax_typerror(L, 2, "Source or VideoStream or nil");
58
59 return 0;
60}
61
62int w_VideoStream_getFilename(lua_State *L)
63{
64 auto stream = luax_checkvideostream(L, 1);
65 luax_pushstring(L, stream->getFilename());
66 return 1;
67}
68
69int w_VideoStream_play(lua_State *L)
70{
71 auto stream = luax_checkvideostream(L, 1);
72 stream->play();
73 return 0;
74}
75
76int w_VideoStream_pause(lua_State *L)
77{
78 auto stream = luax_checkvideostream(L, 1);
79 stream->pause();
80 return 0;
81}
82
83int w_VideoStream_seek(lua_State *L)
84{
85 auto stream = luax_checkvideostream(L, 1);
86 double offset = luaL_checknumber(L, 2);
87 stream->seek(offset);
88 return 0;
89}
90
91int w_VideoStream_rewind(lua_State *L)
92{
93 auto stream = luax_checkvideostream(L, 1);
94 stream->seek(0);
95 return 0;
96}
97
98int w_VideoStream_tell(lua_State *L)
99{
100 auto stream = luax_checkvideostream(L, 1);
101 lua_pushnumber(L, stream->tell());
102 return 1;
103}
104
105int w_VideoStream_isPlaying(lua_State *L)
106{
107 auto stream = luax_checkvideostream(L, 1);
108 luax_pushboolean(L, stream->isPlaying());
109 return 1;
110}
111
112static const luaL_Reg videostream_functions[] =
113{
114 { "setSync", w_VideoStream_setSync },
115 { "getFilename", w_VideoStream_getFilename },
116 { "play", w_VideoStream_play },
117 { "pause", w_VideoStream_pause },
118 { "seek", w_VideoStream_seek },
119 { "rewind", w_VideoStream_rewind },
120 { "tell", w_VideoStream_tell },
121 { "isPlaying", w_VideoStream_isPlaying },
122 { 0, 0 }
123};
124
125int luaopen_videostream(lua_State *L)
126{
127 return luax_register_type(L, &VideoStream::type, videostream_functions, nullptr);
128}
129
130} // video
131} // love
132