11#include " LuaBinding/LuaWrapper.hpp"
2+ #include " LuaBinding/VideoBindingHelpers.hpp"
23#include " lua/plus.hpp"
34#include " AppFrame.h"
5+ #include " d3d11/VideoTexture.hpp"
6+ #include " core/VideoDecoder.hpp"
47
58void luastg::binding::ResourceManager::Register (lua_State* L) noexcept
69{
@@ -52,6 +55,25 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept
5255 return luaL_error (L, " can't load texture from file '%s'." , path);
5356 return 0 ;
5457 }
58+ static int LoadVideo (lua_State* L) noexcept
59+ {
60+ lua::stack_t const ctx (L);
61+ const char * name = luaL_checkstring (L, 1 );
62+ const char * path = luaL_checkstring (L, 2 );
63+
64+ ResourcePool* pActivedPool = LRES.GetActivedPool ();
65+ if (!pActivedPool)
66+ return luaL_error (L, " can't load resource at this time." );
67+
68+ core::VideoOpenOptions opt;
69+ bool const has_options = ctx.index_of_top () >= 3 && ctx.is_table (3 );
70+ if (has_options)
71+ video::parseVideoOptions (L, 3 , opt);
72+
73+ if (!pActivedPool->LoadVideo (name, path, has_options ? &opt : nullptr ))
74+ return luaL_error (L, " can't load video from file '%s'." , path);
75+ return 0 ;
76+ }
5577 static int LoadSprite (lua_State* L) noexcept
5678 {
5779 const char * name = luaL_checkstring (L, 1 );
@@ -414,6 +436,14 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept
414436 lua_pushboolean (L, p->IsRenderTarget ());
415437 return 1 ;
416438 }
439+ static int IsVideoTexture (lua_State* L) noexcept
440+ {
441+ core::SmartReference<IResourceTexture> p = LRES.FindTexture (luaL_checkstring (L, 1 ));
442+ if (!p)
443+ return luaL_error (L, " texture '%s' not found." , luaL_checkstring (L, 1 ));
444+ lua_pushboolean (L, p->IsVideoTexture ());
445+ return 1 ;
446+ }
417447 static int SetTexturePreMulAlphaState (lua_State* L) noexcept
418448 {
419449 core::SmartReference<IResourceTexture> p = LRES.FindTexture (luaL_checkstring (L, 1 ));
@@ -696,13 +726,106 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept
696726 LRES.CacheTTFFontString (luaL_checkstring (L, 1 ), str, len);
697727 return 0 ;
698728 }
729+
730+ // Video control functions
731+
732+ static int VideoSeek (lua_State* L) noexcept {
733+ lua::stack_t const ctx (L);
734+ const char * name = luaL_checkstring (L, 1 );
735+ double time = luaL_checknumber (L, 2 );
736+ auto decoder = video::getDecoderFromResourceName (name);
737+ if (!decoder)
738+ return luaL_error (L, " video texture '%s' not found or is not a video texture." , name);
739+ bool ok = decoder->seek (time);
740+ ctx.push_value (ok);
741+ return 1 ;
742+ }
743+
744+ static int VideoSetLooping (lua_State* L) noexcept {
745+ lua::stack_t const ctx (L);
746+ const char * name = luaL_checkstring (L, 1 );
747+ bool loop = ctx.get_value <bool >(2 );
748+ auto decoder = video::getDecoderFromResourceName (name);
749+ if (!decoder)
750+ return luaL_error (L, " video texture '%s' not found." , name);
751+ decoder->setLooping (loop);
752+ return 0 ;
753+ }
754+
755+ static int VideoSetLoopRange (lua_State* L) noexcept {
756+ const char * name = luaL_checkstring (L, 1 );
757+ auto decoder = video::getDecoderFromResourceName (name);
758+ if (!decoder)
759+ return luaL_error (L, " video texture '%s' not found." , name);
760+ double loop_end = luaL_checknumber (L, 2 );
761+ double loop_duration = luaL_checknumber (L, 3 );
762+ decoder->setLoopRange (loop_end, loop_duration);
763+ return 0 ;
764+ }
765+
766+ static int VideoUpdate (lua_State* L) noexcept {
767+ lua::stack_t const ctx (L);
768+ const char * name = luaL_checkstring (L, 1 );
769+ double time = luaL_checknumber (L, 2 );
770+ auto decoder = video::getDecoderFromResourceName (name);
771+ if (!decoder)
772+ return luaL_error (L, " video texture '%s' not found or is not a video texture." , name);
773+ bool ok = decoder->updateToTime (time);
774+ ctx.push_value (ok);
775+ return 1 ;
776+ }
777+
778+ static int VideoGetInfo (lua_State* L) noexcept {
779+ const char * name = luaL_checkstring (L, 1 );
780+ auto decoder = video::getDecoderFromResourceName (name);
781+ if (!decoder)
782+ return luaL_error (L, " video texture '%s' not found." , name);
783+ video::pushVideoInfoToLua (L, decoder);
784+ return 1 ;
785+ }
786+
787+ static int VideoGetVideoStreams (lua_State* L) noexcept {
788+ const char * name = luaL_checkstring (L, 1 );
789+ auto decoder = video::getDecoderFromResourceName (name);
790+ if (!decoder)
791+ return luaL_error (L, " video texture '%s' not found." , name);
792+ video::pushVideoStreamsToLua (L, decoder);
793+ return 1 ;
794+ }
795+
796+ static int VideoGetAudioStreams (lua_State* L) noexcept {
797+ const char * name = luaL_checkstring (L, 1 );
798+ auto decoder = video::getDecoderFromResourceName (name);
799+ if (!decoder)
800+ return luaL_error (L, " video texture '%s' not found." , name);
801+ video::pushAudioStreamsToLua (L, decoder);
802+ return 1 ;
803+ }
804+
805+ static int VideoReopen (lua_State* L) noexcept {
806+ lua::stack_t const ctx (L);
807+ const char * name = luaL_checkstring (L, 1 );
808+ auto decoder = video::getDecoderFromResourceName (name);
809+ if (!decoder)
810+ return luaL_error (L, " video texture '%s' not found or is not a video texture." , name);
811+ core::VideoOpenOptions opt = decoder->getLastOpenOptions ();
812+ if (ctx.index_of_top () >= 2 && ctx.is_table (2 ))
813+ video::parseVideoOptions (L, 2 , opt);
814+ if (!decoder->reopen (opt)) {
815+ ctx.push_value (false );
816+ return 1 ;
817+ }
818+ ctx.push_value (true );
819+ return 1 ;
820+ }
699821 };
700822
701823 luaL_Reg const lib[] = {
702824 { " SetResLoadInfo" , &Wrapper::SetResLoadInfo },
703825 { " SetResourceStatus" , &Wrapper::SetResourceStatus },
704826 { " GetResourceStatus" , &Wrapper::GetResourceStatus },
705827 { " LoadTexture" , &Wrapper::LoadTexture },
828+ { " LoadVideo" , &Wrapper::LoadVideo },
706829 { " LoadImage" , &Wrapper::LoadSprite },
707830 { " CopyImage" , &Wrapper::CopySprite },
708831 { " LoadAnimation" , &Wrapper::LoadAnimation },
@@ -716,6 +839,7 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept
716839 { " LoadModel" , &Wrapper::LoadModel },
717840 { " CreateRenderTarget" , &Wrapper::CreateRenderTarget },
718841 { " IsRenderTarget" , &Wrapper::IsRenderTarget },
842+ { " IsVideoTexture" , &Wrapper::IsVideoTexture },
719843 { " SetTexturePreMulAlphaState" , &Wrapper::SetTexturePreMulAlphaState },
720844 { " SetTextureSamplerState" , &Wrapper::SetTextureSamplerState },
721845 { " GetTextureSize" , &Wrapper::GetTextureSize },
@@ -737,6 +861,17 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept
737861 { " SetFontState" , &Wrapper::SetFontState },
738862
739863 { " CacheTTFString" , &Wrapper::CacheTTFString },
864+
865+ // Video control functions
866+ { " VideoSeek" , &Wrapper::VideoSeek },
867+ { " VideoSetLooping" , &Wrapper::VideoSetLooping },
868+ { " VideoSetLoopRange" , &Wrapper::VideoSetLoopRange },
869+ { " VideoUpdate" , &Wrapper::VideoUpdate },
870+ { " VideoGetInfo" , &Wrapper::VideoGetInfo },
871+ { " VideoGetVideoStreams" , &Wrapper::VideoGetVideoStreams },
872+ { " VideoGetAudioStreams" , &Wrapper::VideoGetAudioStreams },
873+ { " VideoReopen" , &Wrapper::VideoReopen },
874+
740875 { NULL , NULL },
741876 };
742877
0 commit comments