Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
d15da192
Commit
d15da192
authored
8 years ago
by
callum_linden
Browse files
Options
Downloads
Patches
Plain Diff
Added restart on resize - kind of works
parent
e11ab024
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/media_plugins/libvlc/media_plugin_libvlc.cpp
+134
-211
134 additions, 211 deletions
indra/media_plugins/libvlc/media_plugin_libvlc.cpp
with
134 additions
and
211 deletions
indra/media_plugins/libvlc/media_plugin_libvlc.cpp
+
134
−
211
View file @
d15da192
...
@@ -35,8 +35,7 @@
...
@@ -35,8 +35,7 @@
#include
"media_plugin_base.h"
#include
"media_plugin_base.h"
#include
"vlc/vlc.h"
#include
"vlc/vlc.h"
#include
"vlc/libvlc_version.h"
#include
<time.h>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
...
@@ -52,23 +51,26 @@ class MediaPluginLibVLC :
...
@@ -52,23 +51,26 @@ class MediaPluginLibVLC :
private:
private:
bool
init
();
bool
init
();
void
update
(
F64
milliseconds
);
void
update
(
F64
milliseconds
);
bool
mFirstTime
;
time_t
mLastUpdateTime
;
static
void
*
lock
(
void
*
data
,
void
**
p_pixels
);
enum
Constants
{
ENumObjects
=
10
};
void
initVLC
();
unsigned
char
*
mBackgroundPixels
;
void
playMedia
(
const
std
::
string
url
);
int
mColorR
[
ENumObjects
];
void
resetVLC
();
int
mColorG
[
ENumObjects
];
int
mColorB
[
ENumObjects
];
libvlc_instance_t
*
gLibVLC
;
int
mXpos
[
ENumObjects
];
libvlc_media_t
*
gLibVLCMedia
;
int
mYpos
[
ENumObjects
];
libvlc_media_player_t
*
gLibVLCMediaPlayer
;
int
mXInc
[
ENumObjects
];
int
mYInc
[
ENumObjects
];
int
mBlockSize
[
ENumObjects
];
//float mCurVideoPosition;
libvlc_instance_t
*
gLibVLC
=
0
;
struct
gVLCContext
libvlc_media_t
*
gLibVLCMedia
=
0
;
{
libvlc_media_player_t
*
gLibVLCMediaPlayer
=
0
;
unsigned
char
*
texture_pixels
;
libvlc_media_player_t
*
mp
;
};
struct
gVLCContext
gVLCCallbackContext
;
};
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
...
@@ -76,15 +78,18 @@ class MediaPluginLibVLC :
...
@@ -76,15 +78,18 @@ class MediaPluginLibVLC :
MediaPluginLibVLC
::
MediaPluginLibVLC
(
LLPluginInstance
::
sendMessageFunction
host_send_func
,
void
*
host_user_data
)
:
MediaPluginLibVLC
::
MediaPluginLibVLC
(
LLPluginInstance
::
sendMessageFunction
host_send_func
,
void
*
host_user_data
)
:
MediaPluginBase
(
host_send_func
,
host_user_data
)
MediaPluginBase
(
host_send_func
,
host_user_data
)
{
{
mFirstTime
=
true
;
mTextureWidth
=
64
;
mTextureWidth
=
64
;
mTextureHeight
=
64
;
mTextureHeight
=
64
;
mWidth
=
0
;
mWidth
=
0
;
mHeight
=
0
;
mHeight
=
0
;
mDepth
=
4
;
mDepth
=
4
;
mPixels
=
0
;
mPixels
=
0
;
mLastUpdateTime
=
0
;
mBackgroundPixels
=
0
;
gLibVLC
=
0
;
gLibVLCMedia
=
0
;
gLibVLCMediaPlayer
=
0
;
//mCurVideoPosition = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
...
@@ -93,6 +98,88 @@ MediaPluginLibVLC::~MediaPluginLibVLC()
...
@@ -93,6 +98,88 @@ MediaPluginLibVLC::~MediaPluginLibVLC()
{
{
}
}
/////////////////////////////////////////////////////////////////////////////////
//
void
*
MediaPluginLibVLC
::
lock
(
void
*
data
,
void
**
p_pixels
)
{
struct
gVLCContext
*
context
=
(
gVLCContext
*
)
data
;
*
p_pixels
=
context
->
texture_pixels
;
return
NULL
;
}
////////////////////////////////////////////////////////////////////////////////
//
void
MediaPluginLibVLC
::
initVLC
()
{
char
const
*
vlc_argv
[]
=
{
"--no-xlib"
,
};
int
vlc_argc
=
sizeof
(
vlc_argv
)
/
sizeof
(
*
vlc_argv
);
gLibVLC
=
libvlc_new
(
vlc_argc
,
vlc_argv
);
if
(
!
gLibVLC
)
{
// TODO: do we need to do anything herE?
}
}
////////////////////////////////////////////////////////////////////////////////
//
void
MediaPluginLibVLC
::
resetVLC
()
{
libvlc_media_player_stop
(
gLibVLCMediaPlayer
);
libvlc_media_player_release
(
gLibVLCMediaPlayer
);
libvlc_release
(
gLibVLC
);
}
////////////////////////////////////////////////////////////////////////////////
//
void
MediaPluginLibVLC
::
playMedia
(
const
std
::
string
url
)
{
std
::
string
tmp_url
=
std
::
string
(
"https://callum-linden.s3.amazonaws.com/sample_media/jb.mp4"
);
if
(
gLibVLCMediaPlayer
)
{
libvlc_media_player_stop
(
gLibVLCMediaPlayer
);
libvlc_media_player_release
(
gLibVLCMediaPlayer
);
}
gLibVLCMedia
=
libvlc_media_new_location
(
gLibVLC
,
tmp_url
.
c_str
());
if
(
!
gLibVLCMedia
)
{
printf
(
"libvlc_media_new_location failed
\n
"
);
}
else
{
printf
(
"libvlc_media_new_location ok
\n
"
);
}
gLibVLCMediaPlayer
=
libvlc_media_player_new_from_media
(
gLibVLCMedia
);
if
(
!
gLibVLCMediaPlayer
)
{
printf
(
"libvlc_media_player_new_from_media failed
\n
"
);
}
else
{
printf
(
"libvlc_media_player_new_from_media ok...
\n
"
);
}
libvlc_media_release
(
gLibVLCMedia
);
gVLCCallbackContext
.
texture_pixels
=
mPixels
;
gVLCCallbackContext
.
mp
=
gLibVLCMediaPlayer
;
libvlc_video_set_callbacks
(
gLibVLCMediaPlayer
,
lock
,
NULL
,
NULL
,
&
gVLCCallbackContext
);
libvlc_video_set_format
(
gLibVLCMediaPlayer
,
"RV32"
,
mWidth
,
mHeight
,
mWidth
*
4
);
libvlc_media_player_play
(
gLibVLCMediaPlayer
);
//libvlc_media_player_set_position(gLibVLCMediaPlayer, mCurVideoPosition);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
void
MediaPluginLibVLC
::
receiveMessage
(
const
char
*
message_string
)
void
MediaPluginLibVLC
::
receiveMessage
(
const
char
*
message_string
)
...
@@ -108,54 +195,7 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -108,54 +195,7 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
{
{
if
(
message_name
==
"init"
)
if
(
message_name
==
"init"
)
{
{
char
const
*
vlc_argv
[]
=
initVLC
();
{
"--no-xlib"
,
};
int
vlc_argc
=
sizeof
(
vlc_argv
)
/
sizeof
(
*
vlc_argv
);
gLibVLC
=
libvlc_new
(
vlc_argc
,
vlc_argv
);
if
(
!
gLibVLC
)
{
}
//if (gLibVLCMediaPlayer)
//{
// libvlc_media_player_stop(gLibVLCMediaPlayer);
// libvlc_media_player_release(gLibVLCMediaPlayer);
//}
const
char
*
url
=
"https://callum-linden.s3.amazonaws.com/sample_media/jb.mp4"
;
gLibVLCMedia
=
libvlc_media_new_location
(
gLibVLC
,
url
);
if
(
!
gLibVLCMedia
)
{
printf
(
"libvlc_media_new_location failed
\n
"
);
}
else
{
printf
(
"libvlc_media_new_location ok
\n
"
);
}
gLibVLCMediaPlayer
=
libvlc_media_player_new_from_media
(
gLibVLCMedia
);
if
(
!
gLibVLCMediaPlayer
)
{
printf
(
"libvlc_media_player_new_from_media failed
\n
"
);
}
else
{
printf
(
"libvlc_media_player_new_from_media ok...
\n
"
);
}
libvlc_media_release
(
gLibVLCMedia
);
// gVLCCallbackContext.texture_pixels = gTexturePixels;
// gVLCCallbackContext.mp = gLibVLCMediaPlayer;
// libvlc_video_set_callbacks(gLibVLCMediaPlayer, lock, unlock, display, &gVLCCallbackContext);
libvlc_video_set_format
(
gLibVLCMediaPlayer
,
"RV32"
,
mTextureWidth
,
mTextureHeight
,
mTextureWidth
*
4
);
libvlc_media_player_play
(
gLibVLCMediaPlayer
);
LLPluginMessage
message
(
"base"
,
"init_response"
);
LLPluginMessage
message
(
"base"
,
"init_response"
);
LLSD
versions
=
LLSD
::
emptyMap
();
LLSD
versions
=
LLSD
::
emptyMap
();
...
@@ -164,23 +204,25 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -164,23 +204,25 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
versions
[
LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER
]
=
LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION
;
versions
[
LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER
]
=
LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION
;
message
.
setValueLLSD
(
"versions"
,
versions
);
message
.
setValueLLSD
(
"versions"
,
versions
);
std
::
string
plugin_version
=
"LibVLC plugin 0.0.0"
;
std
::
ostringstream
s
;
message
.
setValue
(
"plugin_version"
,
plugin_version
);
s
<<
"LibVLC plugin "
;
s
<<
LIBVLC_VERSION_MAJOR
;
s
<<
"."
;
s
<<
LIBVLC_VERSION_MINOR
;
s
<<
"."
;
s
<<
LIBVLC_VERSION_REVISION
;
message
.
setValue
(
"plugin_version"
,
s
.
str
());
sendMessage
(
message
);
sendMessage
(
message
);
}
}
else
if
(
message_name
==
"idle"
)
else
if
(
message_name
==
"idle"
)
{
{
// no response is necessary here.
// TODO move to VLC callback when VLC wants to draw a frame
F64
time
=
message_in
.
getValueReal
(
"time"
);
setDirty
(
0
,
0
,
mWidth
,
mHeight
);
// Convert time to milliseconds for update()
update
((
int
)(
time
*
1000.0
f
));
}
}
else
if
(
message_name
==
"cleanup"
)
else
if
(
message_name
==
"cleanup"
)
{
{
libvlc_media_player_stop
(
gLibVLCMediaPlayer
);
resetVLC
();
libvlc_media_player_release
(
gLibVLCMediaPlayer
);
libvlc_release
(
gLibVLC
);
}
}
else
if
(
message_name
==
"shm_added"
)
else
if
(
message_name
==
"shm_added"
)
{
{
...
@@ -201,6 +243,13 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -201,6 +243,13 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
{
{
if
(
mPixels
==
iter
->
second
.
mAddress
)
if
(
mPixels
==
iter
->
second
.
mAddress
)
{
{
/// only do thisis URLs are the same if ( )
//mCurVideoPosition = libvlc_media_player_get_position(gLibVLCMediaPlayer);
libvlc_media_player_stop
(
gLibVLCMediaPlayer
);
libvlc_media_player_release
(
gLibVLCMediaPlayer
);
gLibVLCMediaPlayer
=
0
;
// This is the currently active pixel buffer. Make sure we stop drawing to it.
// This is the currently active pixel buffer. Make sure we stop drawing to it.
mPixels
=
NULL
;
mPixels
=
NULL
;
mTextureSegmentName
.
clear
();
mTextureSegmentName
.
clear
();
...
@@ -233,9 +282,9 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -233,9 +282,9 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
message
.
setValueS32
(
"default_height"
,
1024
);
message
.
setValueS32
(
"default_height"
,
1024
);
message
.
setValueS32
(
"depth"
,
mDepth
);
message
.
setValueS32
(
"depth"
,
mDepth
);
message
.
setValueU32
(
"internalformat"
,
GL_RGB
);
message
.
setValueU32
(
"internalformat"
,
GL_RGB
);
message
.
setValueU32
(
"format"
,
GL_
RGBA
);
message
.
setValueU32
(
"format"
,
GL_
BGRA_EXT
);
message
.
setValueU32
(
"type"
,
GL_UNSIGNED_BYTE
);
message
.
setValueU32
(
"type"
,
GL_UNSIGNED_BYTE
);
message
.
setValueBoolean
(
"coords_opengl"
,
tru
e
);
message
.
setValueBoolean
(
"coords_opengl"
,
fals
e
);
sendMessage
(
message
);
sendMessage
(
message
);
}
}
else
if
(
message_name
==
"size_change"
)
else
if
(
message_name
==
"size_change"
)
...
@@ -255,10 +304,11 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -255,10 +304,11 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
mPixels
=
(
unsigned
char
*
)
iter
->
second
.
mAddress
;
mPixels
=
(
unsigned
char
*
)
iter
->
second
.
mAddress
;
mWidth
=
width
;
mWidth
=
width
;
mHeight
=
height
;
mHeight
=
height
;
mTextureWidth
=
texture_width
;
mTextureWidth
=
texture_width
;
mTextureHeight
=
texture_height
;
mTextureHeight
=
texture_height
;
};
playMedia
(
""
);
};
};
};
LLPluginMessage
message
(
LLPLUGIN_MESSAGE_CLASS_MEDIA
,
"size_change_response"
);
LLPluginMessage
message
(
LLPLUGIN_MESSAGE_CLASS_MEDIA
,
"size_change_response"
);
...
@@ -268,10 +318,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -268,10 +318,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
message
.
setValueS32
(
"texture_width"
,
texture_width
);
message
.
setValueS32
(
"texture_width"
,
texture_width
);
message
.
setValueS32
(
"texture_height"
,
texture_height
);
message
.
setValueS32
(
"texture_height"
,
texture_height
);
sendMessage
(
message
);
sendMessage
(
message
);
mLastUpdateTime
=
0
;
mFirstTime
=
true
;
}
}
else
if
(
message_name
==
"load_uri"
)
else
if
(
message_name
==
"load_uri"
)
{
{
...
@@ -281,7 +327,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -281,7 +327,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
std
::
string
event
=
message_in
.
getValue
(
"event"
);
std
::
string
event
=
message_in
.
getValue
(
"event"
);
if
(
event
==
"down"
)
if
(
event
==
"down"
)
{
{
}
}
else
if
(
event
==
"up"
)
else
if
(
event
==
"up"
)
{
{
...
@@ -297,128 +342,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
...
@@ -297,128 +342,6 @@ void MediaPluginLibVLC::receiveMessage( const char* message_string )
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
void
MediaPluginLibVLC
::
update
(
F64
milliseconds
)
{
if
(
mWidth
<
1
||
mWidth
>
2048
||
mHeight
<
1
||
mHeight
>
2048
)
return
;
if
(
mPixels
==
0
)
return
;
if
(
mFirstTime
)
{
for
(
int
n
=
0
;
n
<
ENumObjects
;
++
n
)
{
mXpos
[
n
]
=
(
mWidth
/
2
)
+
rand
()
%
(
mWidth
/
16
)
-
(
mWidth
/
32
);
mYpos
[
n
]
=
(
mHeight
/
2
)
+
rand
()
%
(
mHeight
/
16
)
-
(
mHeight
/
32
);
mColorR
[
n
]
=
rand
()
%
0x60
+
0x60
;
mColorG
[
n
]
=
rand
()
%
0x60
+
0x60
;
mColorB
[
n
]
=
rand
()
%
0x60
+
0x60
;
mXInc
[
n
]
=
0
;
while
(
mXInc
[
n
]
==
0
)
mXInc
[
n
]
=
rand
()
%
7
-
3
;
mYInc
[
n
]
=
0
;
while
(
mYInc
[
n
]
==
0
)
mYInc
[
n
]
=
rand
()
%
9
-
4
;
mBlockSize
[
n
]
=
rand
()
%
0x30
+
0x10
;
};
delete
[]
mBackgroundPixels
;
mBackgroundPixels
=
new
unsigned
char
[
mWidth
*
mHeight
*
mDepth
];
mFirstTime
=
false
;
};
if
(
time
(
NULL
)
>
mLastUpdateTime
+
3
)
{
const
int
num_squares
=
rand
()
%
20
+
4
;
int
sqr1_r
=
rand
()
%
0x80
+
0x20
;
int
sqr1_g
=
rand
()
%
0x80
+
0x20
;
int
sqr1_b
=
rand
()
%
0x80
+
0x20
;
int
sqr2_r
=
rand
()
%
0x80
+
0x20
;
int
sqr2_g
=
rand
()
%
0x80
+
0x20
;
int
sqr2_b
=
rand
()
%
0x80
+
0x20
;
for
(
int
y1
=
0
;
y1
<
num_squares
;
++
y1
)
{
for
(
int
x1
=
0
;
x1
<
num_squares
;
++
x1
)
{
int
px_start
=
mWidth
*
x1
/
num_squares
;
int
px_end
=
(
mWidth
*
(
x1
+
1
)
)
/
num_squares
;
int
py_start
=
mHeight
*
y1
/
num_squares
;
int
py_end
=
(
mHeight
*
(
y1
+
1
)
)
/
num_squares
;
for
(
int
y2
=
py_start
;
y2
<
py_end
;
++
y2
)
{
for
(
int
x2
=
px_start
;
x2
<
px_end
;
++
x2
)
{
int
rowspan
=
mWidth
*
mDepth
;
if
(
(
y1
%
2
)
^
(
x1
%
2
)
)
{
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
0
]
=
sqr1_r
;
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
1
]
=
sqr1_g
;
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
2
]
=
sqr1_b
;
}
else
{
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
0
]
=
sqr2_r
;
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
1
]
=
sqr2_g
;
mBackgroundPixels
[
y2
*
rowspan
+
x2
*
mDepth
+
2
]
=
sqr2_b
;
};
};
};
};
};
time
(
&
mLastUpdateTime
);
};
memcpy
(
mPixels
,
mBackgroundPixels
,
mWidth
*
mHeight
*
mDepth
);
for
(
int
n
=
0
;
n
<
ENumObjects
;
++
n
)
{
if
(
rand
()
%
50
==
0
)
{
mXInc
[
n
]
=
0
;
while
(
mXInc
[
n
]
==
0
)
mXInc
[
n
]
=
rand
()
%
7
-
3
;
mYInc
[
n
]
=
0
;
while
(
mYInc
[
n
]
==
0
)
mYInc
[
n
]
=
rand
()
%
9
-
4
;
};
if
(
mXpos
[
n
]
+
mXInc
[
n
]
<
0
||
mXpos
[
n
]
+
mXInc
[
n
]
>=
mWidth
-
mBlockSize
[
n
]
)
mXInc
[
n
]
=
-
mXInc
[
n
];
if
(
mYpos
[
n
]
+
mYInc
[
n
]
<
0
||
mYpos
[
n
]
+
mYInc
[
n
]
>=
mHeight
-
mBlockSize
[
n
]
)
mYInc
[
n
]
=
-
mYInc
[
n
];
mXpos
[
n
]
+=
mXInc
[
n
];
mYpos
[
n
]
+=
mYInc
[
n
];
for
(
int
y
=
0
;
y
<
mBlockSize
[
n
];
++
y
)
{
for
(
int
x
=
0
;
x
<
mBlockSize
[
n
];
++
x
)
{
mPixels
[
(
mXpos
[
n
]
+
x
)
*
mDepth
+
(
mYpos
[
n
]
+
y
)
*
mDepth
*
mWidth
+
0
]
=
mColorR
[
n
];
mPixels
[
(
mXpos
[
n
]
+
x
)
*
mDepth
+
(
mYpos
[
n
]
+
y
)
*
mDepth
*
mWidth
+
1
]
=
mColorG
[
n
];
mPixels
[
(
mXpos
[
n
]
+
x
)
*
mDepth
+
(
mYpos
[
n
]
+
y
)
*
mDepth
*
mWidth
+
2
]
=
mColorB
[
n
];
};
};
};
setDirty
(
0
,
0
,
mWidth
,
mHeight
);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
bool
MediaPluginLibVLC
::
init
()
bool
MediaPluginLibVLC
::
init
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment