25#include <scolPlugin.h>
53 int playerPtr = MMget(m, pos);
57 SCOL_PTR_TYPE player = *(SCOL_PTR_TYPE*)MMstart(m, MTOP(playerPtr));
67 *(SCOL_PTR_TYPE*)MMstart(m, MTOP(objm)) = 0;
83 MMechostr(MSKDEBUG,
"_CRMediaPlayer\n");
87 return SCERRSET(m, EARGNIL, MSKDEBUG);
94 catch (std::exception &)
96 return SCERRSET(m, EMEM, MSKDEBUG);
99 if ((MMpushPointer(m, player) != 0))
102 return SCERRVM(m, MERRMEM);
119 MMechostr(MSKDEBUG,
"_DSMediaPlayer\n");
121 int obj = MMget(m, 0);
130 MMset(m, 0, ITOM(0));
146 MMechostr(MSKDEBUG,
"_OPENmediaPlayerUrl\n");
148 int ipath = MMpull(m);
151 if ((player == NULL) || (ipath == NIL))
157 std::string path = MMstartstr(m, MTOP(ipath));
168 catch(std::exception &e)
170 std::string errs = e.what();
171 MMechostr(MSKRUNTIME,
"_OPENmediaPlayerUrl : %s", e.what());
191 MMechostr(MSKDEBUG,
"_OPENmediaPlayerFile\n");
193 int ipath = MMpull(m);
196 if ((player == NULL) || (ipath == NIL))
202 std::string path = MMstartstr(m, MTOP(ipath));
213 catch(std::exception &e)
215 MMechostr(MSKRUNTIME,
"_OPENmediaPlayerFile : %s", e.what());
234 MMechostr(MSKDEBUG,
"_BLTmediaPlayer\n");
236 int bitmap = MMpull(m);
239 if ((player == NULL) || (bitmap == NIL))
245 PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
246 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
270 MMechostr(MSKDEBUG,
"_BLTmediaPlayerBuffer\n");
272 int ibytesperpixel = MMpull(m);
273 int iheight = MMpull(m);
274 int iwidth = MMpull(m);
275 int iBuff = MMpull(m);
279 if ((player == NULL) || (iBuff == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibytesperpixel == NIL))
285 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
292 ibytesperpixel = MTOI(ibytesperpixel);
293 iheight = MTOI(iheight);
294 iwidth = MTOI(iwidth);
297 if (imagesrc.empty())
324 MMechostr(MSKDEBUG,
"_GETmediaPlayerBuffer\n");
343 if ((MMpushPointer(m, frame.data) != 0))
349 MMpush(m, ITOM(frame.cols));
350 MMpush(m, ITOM(frame.rows));
351 MMpush(m, ITOM(frame.channels()));
368 MMechostr(MSKDEBUG,
"_PLAYmediaPlayer\n");
383 catch (std::exception &e)
385 MMechostr(MSKRUNTIME,
"_PLAYmediaPlayer : %s\n", e.what());
402 MMechostr(MSKDEBUG,
"_PAUSEmediaPlayer\n");
417 catch (std::exception &e)
419 MMechostr(MSKRUNTIME,
"_PAUSEmediaPlayer : %s\n", e.what());
436 MMechostr(MSKDEBUG,
"_STOPmediaPlayer\n");
463 MMechostr(MSKDEBUG,
"_SETmediaPlayerSize\n");
465 int iheight = MMpull(m);
466 int iwidth = MMpull(m);
477 width = abs(MTOI(iwidth));
481 height = abs(MTOI(iheight));
483 player->
SetSize(width, height);
497 MMechostr(MSKDEBUG,
"_GETmediaPlayerSize\n");
512 player->
GetSize(width, height);
514 catch (std::exception& e)
516 MMechostr(MSKRUNTIME,
"_GETmediaPlayerSize : %s\n", e.what());
521 int result = MMmalloc(m, 2, TYPETAB);
528 MMstore(m, result, 0, ITOM(width));
529 MMstore(m, result, 1, ITOM(height));
530 MMset(m, 0, PTOM(result));
545 MMechostr(MSKDEBUG,
"_GETmediaPlayerSourceSize\n");
562 catch (std::exception& e)
564 MMechostr(MSKRUNTIME,
"_GETmediaPlayerSourceSize : %s\n", e.what());
569 int result = MMmalloc(m, 2, TYPETAB);
576 MMstore(m, result, 0, ITOM(width));
577 MMstore(m, result, 1, ITOM(height));
578 MMset(m, 0, PTOM(result));
593 MMechostr(MSKDEBUG,
"_GETmediaPlayerTime\n");
609 catch (std::exception& e)
611 MMechostr(MSKRUNTIME,
"_GETmediaPlayerTime : %s\n", e.what());
616 if (time > std::numeric_limits<int>::max())
618 MMechostr(MSKRUNTIME,
"_GETmediaPlayerTime : warning : timestamp is too large for int type : %u\n", time);
619 time = std::numeric_limits<int>::max();
622 MMset(m, 0, ITOM((
int)time));
637 MMechostr(MSKDEBUG,
"_GETmediaPlayerTime\n");
653 catch (std::exception& e)
655 MMechostr(MSKRUNTIME,
"_GETmediaPlayerLength : %s\n", e.what());
660 MMset(m, 0, ITOM((
int)length));
675 MMechostr(MSKDEBUG,
"_SEEKmediaPlayer\n");
677 int vtime = MMpull(m);
680 MMechostr(MSKRUNTIME,
"_SEEKmediaPlayer : video time is nil.\n");
698 catch (std::exception& e)
700 MMechostr(MSKRUNTIME,
"_SEEKmediaPlayer : %s\n", e.what());
719 MMechostr(MSKDEBUG,
"_SETmediaPlayerLoop\n");
721 int iloop = MMpull(m);
726 MMechostr(MSKRUNTIME,
"_SETmediaPlayerLoop : loop value is nil.\n");
737 player->
SetLoop(MTOI(iloop) == 0 ?
false :
true);
753 MMechostr(MSKDEBUG,
"_SETmediaPlayerStream\n");
755 int istream = MMpull(m);
760 MMechostr(MSKRUNTIME,
"_SETmediaPlayerStream : stream index is nil.\n");
775 catch (std::exception& e)
777 MMechostr(MSKRUNTIME,
"_SETmediaPlayerStream : couldn't open stream %d : %s\n", MTOI(istream), e.what());
795 MMechostr(MSKDEBUG,
"_SETmediaPlayerAudioStream\n");
797 int istream = MMpull(m);
802 MMechostr(MSKRUNTIME,
"_SETmediaPlayerAudioStream : stream index is nil.\n");
817 catch (std::exception& e)
819 MMechostr(MSKRUNTIME,
"_SETmediaPlayerAudioStream : couldn't open stream %d : %s\n", MTOI(istream), e.what());
836 MMechostr(MSKDEBUG,
"_GETmediaPlayerAudio\n");
840 if (player == NULL || !player->
HasAudio())
852 catch (std::exception& e)
854 MMechostr(MSKRUNTIME,
"_GETmediaPlayerAudio : %s\n", e.what());
865 int res = MMmalloc(m, STR_SIZE(bytes), TYPEBUF);
872 MMstore(m, res, 0, bytes);
873 char* buffer = MMstartstr(m, res);
874 memcpy(buffer, tmpBuffer, bytes);
876 MMset(m, 0, PTOM(res));
892 MMechostr(MSKDEBUG,
"_SETmediaPlayerAudioFormat\n");
894 int irate = MMpull(m);
895 int iformat = MMpull(m);
898 if ((irate == NIL) || (iformat == NIL) || (player == NULL))
900 MMechostr(MSKRUNTIME,
"_SETmediaPlayerAudioFormat : one or more invalid parameter\n");
909 catch (
const std::exception& e)
911 MMechostr(MSKRUNTIME,
"_SETmediaPlayerAudioFormat error: %s\n", e.what());
929 MMechostr(MSKDEBUG,
"_GETmediaPlayerHasAudio\n");
935 MMechostr(MSKRUNTIME,
"_GETmediaPlayerHasAudio : invalid media player object\n");
940 int hasAudio = player->
HasAudio() ? 1 : 0;
942 MMset(m, 0, ITOM(hasAudio));
957 MMechostr(MSKDEBUG,
"_GETmediaPlayerHasVideo\n");
963 MMechostr(MSKRUNTIME,
"_GETmediaPlayerHasVideo : invalid media player object\n");
968 int hasVideo = player->
HasVideo() ? 1 : 0;
970 MMset(m, 0, ITOM(hasVideo));
985 MMechostr(MSKDEBUG,
"_GETmediaPlayerState\n");
991 MMechostr(MSKRUNTIME,
"_GETmediaPlayerState : invalid media player object\n");
996 int state = (int)player->
GetState();
998 MMset(m, 0, ITOM(state));
1013 MMechostr(MSKDEBUG,
"_GETmediaPlayerIsLiveStream\n");
1019 MMechostr(MSKRUNTIME,
"_GETmediaPlayerIsLiveStream : invalid media player object\n");
1026 MMset(m, 0, ITOM(isLive));
1041 MMechostr(MSKDEBUG,
"_GETmediaPlayerIsSeekable\n");
1047 MMechostr(MSKRUNTIME,
"_GETmediaPlayerIsSeekable : invalid media player object\n");
1052 int isSeekable = player->
IsSeekable() ? 1 : 0;
1054 MMset(m, 0, ITOM(isSeekable));
1070 MMechostr(MSKDEBUG,
"_GETmediaPlayerAudioStreams\n");
1076 MMechostr(MSKRUNTIME,
"_GETmediaPlayerAudioStreams : invalid media player object\n");
1081 std::vector<std::string> streams = player->
ListStreams(AVMEDIA_TYPE_AUDIO);
1083 if (streams.empty())
1085 MMechostr(MSKRUNTIME,
"_GETmediaPlayerAudioStreams : no audio stream\n");
1093 for (
unsigned int i = 0; i < streams.size(); i++)
1095 std::string data = streams.at(i);
1096 Mpushstrbloc(m, (
char*)data.c_str());
1102 for (
unsigned int i = 0; i < streams.size(); i++)
1107 if (
int k=MBdeftab(m))
1125 MMechostr(MSKDEBUG,
"_GETmediaPlayerVideoStreams\n");
1131 MMechostr(MSKRUNTIME,
"_GETmediaPlayerVideoStreams : invalid media player object\n");
1136 std::vector<std::string> streams = player->
ListStreams(AVMEDIA_TYPE_VIDEO);
1138 if (streams.empty())
1140 MMechostr(MSKRUNTIME,
"_GETmediaPlayerAudioStreams : no video stream\n");
1147 for (
unsigned int i = 0; i < streams.size(); i++)
1149 std::string data = streams.at(i);
1150 Mpushstrbloc(m, (
char*)data.c_str());
1156 for (
unsigned int i = 0; i < streams.size(); i++)
1161 if (
int k=MBdeftab(m))
1193 return OBJcallreflex(m, 0);
1219 MMpush(m, ITOM((
int)ret));
1221 return OBJcallreflex(m, 1);
1230NativeDefinition videoToolkitEngine[] =
1232 {
"ObjMediaPlayer", TYPTYPE, NULL, NULL },
1240 {
"_CRmediaPlayer", 1,
"fun [Chn] ObjMediaPlayer",
_CRmediaPlayer },
1241 {
"_DSmediaPlayer", 1,
"fun [ObjMediaPlayer] I",
_DSmediaPlayer },
1242 {
"_OPENmediaPlayerUrl", 2,
"fun [ObjMediaPlayer S] ObjMediaPlayer",
_OPENmediaPlayerUrl },
1244 {
"_BLTmediaPlayer", 2,
"fun [ObjMediaPlayer ObjBitmap] ObjBitmap",
_BLTmediaPlayer },
1245 {
"_BLTmediaPlayerBuffer", 5,
"fun [ObjMediaPlayer ObjBuff I I I] ObjBuff",
_BLTmediaPlayerBuffer },
1247 {
"_PLAYmediaPlayer", 1,
"fun [ObjMediaPlayer] ObjMediaPlayer",
_PLAYmediaPlayer },
1248 {
"_PAUSEmediaPlayer", 1,
"fun [ObjMediaPlayer] ObjMediaPlayer",
_PAUSEmediaPlayer },
1249 {
"_STOPmediaPlayer", 1,
"fun [ObjMediaPlayer] ObjMediaPlayer",
_STOPmediaPlayer },
1250 {
"_SETmediaPlayerSize", 3,
"fun [ObjMediaPlayer I I] ObjMediaPlayer",
_SETmediaPlayerSize },
1255 {
"_SEEKmediaPlayer", 2,
"fun [ObjMediaPlayer I] ObjMediaPlayer",
_SEEKmediaPlayer },
1256 {
"_SETmediaPlayerLoop", 2,
"fun [ObjMediaPlayer I] ObjMediaPlayer",
_SETmediaPlayerLoop },
1268 {
"_CBmediaPlayerEnd", 3,
"fun [ObjMediaPlayer fun [ObjMediaPlayer u0] u1 u0] ObjMediaPlayer",
_CBmediaPlayerEnd},
1269 {
"_CBmediaPlayerLoaded", 3,
"fun [ObjMediaPlayer fun [ObjMediaPlayer u0 I] u1 u0] ObjMediaPlayer",
_CBmediaPlayerLoaded}
1279 MMechostr(MSKDEBUG,
" > Loading MediaPlayerToolkit\n");
1290 k = PKhardpak2(m,
"MediaPlayerToolkitEngine",
sizeof(videoToolkitEngine) /
sizeof(videoToolkitEngine[0]), videoToolkitEngine);
1291 MMechostr(MSKDEBUG,
" > Successfully Loaded\n\n");
1297 MMechostr(MSKDEBUG,
"\n");
1298 MMechostr(MSKDEBUG,
" > Unloading MediaPlayerToolkit\n");
1301 MMechostr(MSKDEBUG,
" > Successfully Unloaded\n\n");
int UnloadMediaPlayerToolkit()
int LoadMediaPlayerToolkit(mmachine m)