Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
libvlcpp
Commits
6de088e2
Commit
6de088e2
authored
Feb 11, 2015
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shared/unique pointers to manage vlcpp/libvlc objects
parent
cdb2aad7
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
354 additions
and
820 deletions
+354
-820
src/EventManager.cpp
src/EventManager.cpp
+23
-28
src/EventManager.hpp
src/EventManager.hpp
+11
-17
src/Instance.cpp
src/Instance.cpp
+12
-47
src/Instance.hpp
src/Instance.hpp
+0
-29
src/Internal.hpp
src/Internal.hpp
+20
-15
src/Media.cpp
src/Media.cpp
+36
-77
src/Media.hpp
src/Media.hpp
+8
-35
src/MediaDiscoverer.cpp
src/MediaDiscoverer.cpp
+11
-29
src/MediaDiscoverer.hpp
src/MediaDiscoverer.hpp
+4
-18
src/MediaLibrary.cpp
src/MediaLibrary.cpp
+3
-43
src/MediaLibrary.hpp
src/MediaLibrary.hpp
+1
-31
src/MediaList.cpp
src/MediaList.cpp
+28
-83
src/MediaList.hpp
src/MediaList.hpp
+11
-39
src/MediaListPlayer.cpp
src/MediaListPlayer.cpp
+24
-68
src/MediaListPlayer.hpp
src/MediaListPlayer.hpp
+6
-35
src/MediaPlayer.cpp
src/MediaPlayer.cpp
+119
-184
src/MediaPlayer.hpp
src/MediaPlayer.hpp
+7
-38
src/common.hpp
src/common.hpp
+26
-0
src/vlc.hpp
src/vlc.hpp
+4
-4
No files found.
src/EventManager.cpp
View file @
6de088e2
...
...
@@ -27,18 +27,13 @@
namespace
VLC
{
EventManager
::
EventManager
(
const
EventManager
&
em
)
:
Internal
(
em
)
{
}
bool
EventManager
::
attach
(
libvlc_event_type_t
type
,
IMediaEventCb
*
cb
)
{
if
(
cb
==
NULL
)
return
false
;
if
(
type
<
libvlc_MediaMetaChanged
||
type
>
libvlc_MediaSubItemTreeAdded
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleMediaEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleMediaEvent
,
cb
);
return
true
;
}
...
...
@@ -48,7 +43,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaPlayerEventCb* cb)
return
false
;
if
(
type
<
libvlc_MediaPlayerMediaChanged
||
type
>
libvlc_MediaPlayerESSelected
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleMediaPlayerEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleMediaPlayerEvent
,
cb
);
return
true
;
}
...
...
@@ -58,7 +53,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaListEventCb* cb)
return
false
;
if
(
type
<
libvlc_MediaListItemAdded
||
type
>
libvlc_MediaListWillDeleteItem
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleMediaListEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleMediaListEvent
,
cb
);
return
true
;
}
...
...
@@ -68,7 +63,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaListPlayerEventCb* cb)
return
false
;
if
(
type
<
libvlc_MediaListPlayerPlayed
||
type
>
libvlc_MediaListPlayerStopped
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleMediaListPlayerEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleMediaListPlayerEvent
,
cb
);
return
true
;
}
...
...
@@ -78,7 +73,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaDiscovererEventCb* cb)
return
false
;
if
(
type
<
libvlc_MediaDiscovererStarted
||
type
>
libvlc_MediaDiscovererEnded
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleMediaDiscovererEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleMediaDiscovererEvent
,
cb
);
return
true
;
}
...
...
@@ -88,38 +83,38 @@ bool EventManager::attach( libvlc_event_type_t type, IVLMEventCb* cb )
return
false
;
if
(
type
<
libvlc_VlmMediaAdded
||
type
>
libvlc_VlmMediaInstanceStatusError
)
return
false
;
libvlc_event_attach
(
*
this
,
type
,
&
handleVLMEvent
,
cb
);
libvlc_event_attach
(
get
()
,
type
,
&
handleVLMEvent
,
cb
);
return
true
;
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IMediaEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleMediaEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleMediaEvent
,
cb
);
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IMediaPlayerEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleMediaPlayerEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleMediaPlayerEvent
,
cb
);
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IMediaListEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleMediaListEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleMediaListEvent
,
cb
);
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IMediaListPlayerEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleMediaListPlayerEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleMediaListPlayerEvent
,
cb
);
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IMediaDiscovererEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleMediaDiscovererEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleMediaDiscovererEvent
,
cb
);
}
void
EventManager
::
detach
(
libvlc_event_type_t
type
,
IVLMEventCb
*
cb
)
{
libvlc_event_detach
(
*
this
,
type
,
&
handleVLMEvent
,
cb
);
libvlc_event_detach
(
get
()
,
type
,
&
handleVLMEvent
,
cb
);
}
void
EventManager
::
handleMediaEvent
(
const
libvlc_event_t
*
event
,
void
*
data
)
...
...
@@ -131,7 +126,7 @@ void EventManager::handleMediaEvent(const libvlc_event_t* event, void* data)
cb
->
metaChanged
(
event
->
u
.
media_meta_changed
.
meta_type
);
break
;
case
libvlc_MediaSubItemAdded
:
cb
->
subItemAdded
(
Media
(
event
->
u
.
media_subitem_added
.
new_child
,
true
)
);
cb
->
subItemAdded
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_subitem_added
.
new_child
,
true
)
);
break
;
case
libvlc_MediaDurationChanged
:
cb
->
durationChanged
(
event
->
u
.
media_duration_changed
.
new_duration
);
...
...
@@ -140,13 +135,13 @@ void EventManager::handleMediaEvent(const libvlc_event_t* event, void* data)
cb
->
parsedChanged
(
event
->
u
.
media_parsed_changed
.
new_status
!=
0
);
break
;
case
libvlc_MediaFreed
:
cb
->
freed
(
Media
(
event
->
u
.
media_freed
.
md
,
true
)
);
cb
->
freed
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_freed
.
md
,
true
)
);
break
;
case
libvlc_MediaStateChanged
:
cb
->
stateChanged
(
event
->
u
.
media_state_changed
.
new_state
);
break
;
case
libvlc_MediaSubItemTreeAdded
:
cb
->
subItemTreeAdded
(
Media
(
event
->
u
.
media_subitemtree_added
.
item
,
true
)
);
cb
->
subItemTreeAdded
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_subitemtree_added
.
item
,
true
)
);
break
;
default:
assert
(
false
);
...
...
@@ -159,7 +154,7 @@ void EventManager::handleMediaPlayerEvent(const libvlc_event_t* event, void* dat
switch
(
event
->
type
)
{
case
libvlc_MediaPlayerMediaChanged
:
cb
->
mediaChanged
(
Media
(
event
->
u
.
media_player_media_changed
.
new_media
,
true
)
);
cb
->
mediaChanged
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_player_media_changed
.
new_media
,
true
)
);
break
;
case
libvlc_MediaPlayerNothingSpecial
:
cb
->
nothingSpecial
();
...
...
@@ -238,16 +233,16 @@ void EventManager::handleMediaListEvent(const libvlc_event_t* event, void* data)
switch
(
event
->
type
)
{
case
libvlc_MediaListItemAdded
:
cb
->
itemAdded
(
Media
(
event
->
u
.
media_list_item_added
.
item
,
true
),
event
->
u
.
media_list_item_added
.
index
);
cb
->
itemAdded
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_list_item_added
.
item
,
true
),
event
->
u
.
media_list_item_added
.
index
);
break
;
case
libvlc_MediaListWillAddItem
:
cb
->
willAddItem
(
Media
(
event
->
u
.
media_list_will_add_item
.
item
,
true
),
event
->
u
.
media_list_will_add_item
.
index
);
cb
->
willAddItem
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_list_will_add_item
.
item
,
true
),
event
->
u
.
media_list_will_add_item
.
index
);
break
;
case
libvlc_MediaListItemDeleted
:
cb
->
itemDeleted
(
Media
(
event
->
u
.
media_list_item_deleted
.
item
,
true
),
event
->
u
.
media_list_item_deleted
.
index
);
cb
->
itemDeleted
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_list_item_deleted
.
item
,
true
),
event
->
u
.
media_list_item_deleted
.
index
);
break
;
case
libvlc_MediaListWillDeleteItem
:
cb
->
willDeleteItem
(
Media
(
event
->
u
.
media_list_will_delete_item
.
item
,
true
),
event
->
u
.
media_list_will_delete_item
.
index
);
cb
->
willDeleteItem
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_list_will_delete_item
.
item
,
true
),
event
->
u
.
media_list_will_delete_item
.
index
);
break
;
default:
assert
(
false
);
...
...
@@ -263,7 +258,7 @@ void EventManager::handleMediaListPlayerEvent(const libvlc_event_t* event, void*
cb
->
played
();
break
;
case
libvlc_MediaListPlayerNextItemSet
:
cb
->
nextItemSet
(
Media
(
event
->
u
.
media_list_player_next_item_set
.
item
,
true
)
);
cb
->
nextItemSet
(
std
::
make_shared
<
Media
>
(
event
->
u
.
media_list_player_next_item_set
.
item
,
true
)
);
break
;
case
libvlc_MediaListPlayerStopped
:
cb
->
stopped
();
...
...
@@ -334,8 +329,8 @@ void EventManager::handleVLMEvent(const libvlc_event_t* event, void* data)
}
}
EventManager
::
EventManager
(
InternalPtr
obj
)
:
Internal
(
obj
)
EventManager
::
EventManager
(
Internal
::
InternalPtr
ptr
)
:
Internal
{
ptr
,
[](
InternalPtr
){
/* No-op; EventManager's are handled by their respective objects */
}
}
{
}
...
...
src/EventManager.hpp
View file @
6de088e2
...
...
@@ -37,19 +37,19 @@ class IMediaEventCb
public:
virtual
~
IMediaEventCb
()
{}
virtual
void
metaChanged
(
libvlc_meta_t
)
{}
virtual
void
subItemAdded
(
const
Media
&
)
{}
virtual
void
subItemAdded
(
Media
Ptr
)
{}
virtual
void
durationChanged
(
int64_t
)
{}
virtual
void
parsedChanged
(
bool
)
{}
virtual
void
freed
(
const
Media
&
)
{}
virtual
void
freed
(
Media
Ptr
)
{}
virtual
void
stateChanged
(
libvlc_state_t
)
{}
virtual
void
subItemTreeAdded
(
const
Media
&
)
{}
virtual
void
subItemTreeAdded
(
Media
Ptr
)
{}
};
class
IMediaPlayerEventCb
{
public:
virtual
~
IMediaPlayerEventCb
(){}
virtual
void
mediaChanged
(
const
Media
&
)
{}
virtual
void
mediaChanged
(
Media
Ptr
)
{}
virtual
void
nothingSpecial
()
{}
virtual
void
opening
()
{}
virtual
void
buffering
(
float
)
{}
...
...
@@ -78,10 +78,10 @@ class IMediaListEventCb
{
public:
virtual
~
IMediaListEventCb
()
{}
virtual
void
itemAdded
(
const
Media
&
,
int
)
{}
virtual
void
willAddItem
(
const
Media
&
,
int
)
{}
virtual
void
itemDeleted
(
const
Media
&
,
int
)
{}
virtual
void
willDeleteItem
(
const
Media
&
,
int
)
{}
virtual
void
itemAdded
(
Media
Ptr
,
int
)
{}
virtual
void
willAddItem
(
Media
Ptr
,
int
)
{}
virtual
void
itemDeleted
(
Media
Ptr
,
int
)
{}
virtual
void
willDeleteItem
(
Media
Ptr
,
int
)
{}
};
// MediaListView events are not being sent by VLC, so we don't implement them here
...
...
@@ -91,7 +91,7 @@ class IMediaListPlayerEventCb
public:
virtual
~
IMediaListPlayerEventCb
()
{}
virtual
void
played
()
{}
virtual
void
nextItemSet
(
const
Media
&
)
{}
virtual
void
nextItemSet
(
Media
Ptr
)
{}
virtual
void
stopped
()
{}
};
...
...
@@ -123,7 +123,8 @@ class IVLMEventCb
class
VLCPP_API
EventManager
:
public
Internal
<
libvlc_event_manager_t
>
{
public:
EventManager
(
const
EventManager
&
em
);
EventManager
(
InternalPtr
ptr
);
bool
attach
(
libvlc_event_type_t
type
,
IMediaEventCb
*
cb
);
bool
attach
(
libvlc_event_type_t
type
,
IMediaPlayerEventCb
*
cb
);
bool
attach
(
libvlc_event_type_t
type
,
IMediaListEventCb
*
cb
);
...
...
@@ -147,13 +148,6 @@ class VLCPP_API EventManager : public Internal<libvlc_event_manager_t>
static
void
handleVLMEvent
(
const
libvlc_event_t
*
event
,
void
*
data
);
static
void
handleEvent
(
const
libvlc_event_t
*
event
,
void
*
data
);
EventManager
(
InternalPtr
obj
);
friend
class
Media
;
friend
class
MediaDiscoverer
;
friend
class
MediaList
;
friend
class
MediaListPlayer
;
friend
class
MediaPlayer
;
};
}
...
...
src/Instance.cpp
View file @
6de088e2
...
...
@@ -27,26 +27,8 @@ namespace VLC
{
Instance
::
Instance
(
int
argc
,
const
char
*
const
*
argv
)
:
Internal
{
libvlc_new
(
argc
,
argv
),
libvlc_release
}
{
m_obj
=
libvlc_new
(
argc
,
argv
);
}
Instance
::
Instance
(
const
Instance
&
another
)
:
Internal
(
another
)
{
retain
();
}
Instance
&
Instance
::
operator
=
(
const
Instance
&
another
)
{
if
(
this
==
&
another
)
{
return
*
this
;
}
release
();
m_obj
=
another
.
m_obj
;
retain
();
return
*
this
;
}
bool
Instance
::
operator
==
(
const
Instance
&
another
)
const
...
...
@@ -54,49 +36,44 @@ bool Instance::operator==( const Instance& another ) const
return
m_obj
==
another
.
m_obj
;
}
Instance
::~
Instance
()
{
release
();
}
int
Instance
::
addIntf
(
const
std
::
string
&
name
)
{
return
libvlc_add_intf
(
m_obj
,
name
.
c_str
()
);
return
libvlc_add_intf
(
get
()
,
name
.
c_str
()
);
}
void
Instance
::
setExitHandler
(
void
(
*
cb
)(
void
*
),
void
*
opaque
)
{
libvlc_set_exit_handler
(
m_obj
,
cb
,
opaque
);
libvlc_set_exit_handler
(
get
()
,
cb
,
opaque
);
}
void
Instance
::
setUserAgent
(
const
std
::
string
&
name
,
const
std
::
string
&
http
)
{
libvlc_set_user_agent
(
m_obj
,
name
.
c_str
(),
http
.
c_str
()
);
libvlc_set_user_agent
(
get
()
,
name
.
c_str
(),
http
.
c_str
()
);
}
void
Instance
::
setAppId
(
const
std
::
string
&
id
,
const
std
::
string
&
version
,
const
std
::
string
&
icon
)
{
libvlc_set_app_id
(
m_obj
,
id
.
c_str
(),
version
.
c_str
(),
icon
.
c_str
()
);
libvlc_set_app_id
(
get
()
,
id
.
c_str
(),
version
.
c_str
(),
icon
.
c_str
()
);
}
void
Instance
::
logUnset
()
{
libvlc_log_unset
(
m_obj
);
libvlc_log_unset
(
get
()
);
}
void
Instance
::
logSet
(
libvlc_log_cb
cb
,
void
*
data
)
{
libvlc_log_set
(
m_obj
,
cb
,
data
);
libvlc_log_set
(
get
()
,
cb
,
data
);
}
void
Instance
::
logSetFile
(
FILE
*
stream
)
{
libvlc_log_set_file
(
m_obj
,
stream
);
libvlc_log_set_file
(
get
()
,
stream
);
}
std
::
vector
<
ModuleDescription
>
Instance
::
audioFilterList
()
{
libvlc_module_description_t
*
result
=
libvlc_audio_filter_list_get
(
m_obj
);
libvlc_module_description_t
*
result
=
libvlc_audio_filter_list_get
(
get
()
);
std
::
vector
<
ModuleDescription
>
res
;
if
(
result
==
NULL
)
return
res
;
...
...
@@ -112,7 +89,7 @@ std::vector<ModuleDescription> Instance::audioFilterList()
std
::
vector
<
ModuleDescription
>
Instance
::
videoFilterList
()
{
libvlc_module_description_t
*
result
=
libvlc_video_filter_list_get
(
m_obj
);
libvlc_module_description_t
*
result
=
libvlc_video_filter_list_get
(
get
()
);
std
::
vector
<
ModuleDescription
>
res
;
if
(
result
==
NULL
)
return
res
;
...
...
@@ -128,7 +105,7 @@ std::vector<ModuleDescription> Instance::videoFilterList()
std
::
vector
<
AudioOutputDescription
>
Instance
::
audioOutputList
()
{
libvlc_audio_output_t
*
result
=
libvlc_audio_output_list_get
(
m_obj
);
libvlc_audio_output_t
*
result
=
libvlc_audio_output_list_get
(
get
()
);
std
::
vector
<
AudioOutputDescription
>
res
;
if
(
result
==
NULL
)
return
res
;
...
...
@@ -144,7 +121,7 @@ std::vector<AudioOutputDescription> Instance::audioOutputList()
std
::
vector
<
AudioOutputDeviceDescription
>
Instance
::
audioOutputDeviceList
(
const
std
::
string
&
aout
)
{
libvlc_audio_output_device_t
*
devices
=
libvlc_audio_output_device_list_get
(
m_obj
,
aout
.
c_str
()
);
libvlc_audio_output_device_t
*
devices
=
libvlc_audio_output_device_list_get
(
get
()
,
aout
.
c_str
()
);
std
::
vector
<
AudioOutputDeviceDescription
>
res
;
if
(
devices
==
NULL
)
return
res
;
...
...
@@ -154,17 +131,5 @@ std::vector<AudioOutputDeviceDescription> Instance::audioOutputDeviceList(const
return
res
;
}
void
Instance
::
release
()
{
if
(
isValid
()
)
libvlc_release
(
m_obj
);
}
void
Instance
::
retain
()
{
if
(
isValid
()
)
libvlc_retain
(
m_obj
);
}
}
// namespace VLC
src/Instance.hpp
View file @
6de088e2
...
...
@@ -60,19 +60,6 @@ public:
*/
Instance
(
int
argc
,
const
char
*
const
*
argv
);
/**
* Copy libvlc_instance_t from another to new Instance object.
* \param another existing Instance
*/
Instance
(
const
Instance
&
another
);
/**
* Copy libvlc_instance_t from another Instance
* to this Instance
* \param another existing Instance
*/
Instance
&
operator
=
(
const
Instance
&
another
);
/**
* Check if 2 Instance objects contain the same libvlc_instance_t.
* \param another another Instance
...
...
@@ -80,8 +67,6 @@ public:
*/
bool
operator
==
(
const
Instance
&
another
)
const
;
~
Instance
();
/**
* Try to start a user interface for the libvlc instance.
*
...
...
@@ -240,20 +225,6 @@ public:
* \version LibVLC 2.1.0 or later.
*/
std
::
vector
<
AudioOutputDeviceDescription
>
audioOutputDeviceList
(
const
std
::
string
&
aout
);
private:
explicit
Instance
(
InternalPtr
ptr
,
bool
increaseRefCount
);
/**
* Decrement the reference count of a libvlc instance, and destroy it if
* it reaches zero.
*/
void
release
();
/**
* Increments the reference count of a libvlc instance. The initial
* reference count is 1 after Instance::Instance() returns.
*/
void
retain
();
};
}
// namespace VLC
...
...
src/Internal.hpp
View file @
6de088e2
...
...
@@ -26,31 +26,36 @@
#include <cassert>
#include <stdlib.h>
#include <vlc/libvlc.h>
#include <memory>
#include <stdexcept>
namespace
VLC
{
template
<
typename
T
>
template
<
typename
T
,
typename
Releaser
=
void
(
*
)(
T
*
)
>
class
Internal
{
public:
typedef
T
*
InternalPtr
;
InternalPtr
getInternalPtr
()
using
InternalType
=
T
;
using
InternalPtr
=
T
*
;
using
Pointer
=
std
::
unique_ptr
<
T
,
Releaser
>
;
InternalPtr
get
()
{
return
m_obj
.
get
();
}
bool
isValid
()
const
{
return
(
bool
)
m_obj
;
}
protected:
Internal
(
InternalPtr
obj
,
Releaser
releaser
)
:
m_obj
{
obj
,
releaser
}
{
if
(
obj
==
nullptr
)
throw
std
::
runtime_error
(
"Wrapping a NULL instance"
);
}
Internal
(
Releaser
releaser
)
:
m_obj
{
nullptr
,
releaser
}
{
assert
(
m_obj
!=
NULL
);
return
m_obj
;
}
operator
T
*
()
{
return
m_obj
;
}
bool
isValid
()
const
{
return
m_obj
!=
NULL
;
}
protected:
Internal
(
InternalPtr
obj
=
NULL
)
:
m_obj
(
obj
)
{}
Internal
(
const
Internal
&
copied
)
:
m_obj
(
copied
.
m_obj
)
{}
~
Internal
(){}
InternalPtr
m_obj
;
pr
ivate
:
I
nter
nal
&
operator
=
(
const
Internal
&
)
;
pr
otected
:
Poi
nter
m_obj
;
};
}
...
...
src/Media.cpp
View file @
6de088e2
...
...
@@ -27,66 +27,38 @@
namespace
VLC
{
Media
::
Media
(
Instance
&
instance
,
const
std
::
string
&
mrl
,
Media
::
FromType
type
)
:
Internal
(
NULL
)
Media
::
Media
(
Instance
Ptr
instance
,
const
std
::
string
&
mrl
,
Media
::
FromType
type
)
:
Internal
{
libvlc_media_release
}
{
InternalPtr
ptr
=
nullptr
;
switch
(
type
)
{
case
FromLocation
:
m_obj
=
libvlc_media_new_location
(
instance
,
mrl
.
c_str
()
);
ptr
=
libvlc_media_new_location
(
instance
->
get
()
,
mrl
.
c_str
()
);
break
;
case
FromPath
:
m_obj
=
libvlc_media_new_path
(
instance
,
mrl
.
c_str
()
);
ptr
=
libvlc_media_new_path
(
instance
->
get
()
,
mrl
.
c_str
()
);
break
;
case
AsNode
:
m_obj
=
libvlc_media_new_as_node
(
instance
,
mrl
.
c_str
()
);
ptr
=
libvlc_media_new_as_node
(
instance
->
get
()
,
mrl
.
c_str
()
);
break
;
default:
break
;
}
if
(
m_obj
==
NULL
)
if
(
ptr
==
nullptr
)
throw
std
::
runtime_error
(
"Failed to construct a media"
);
m_obj
.
reset
(
ptr
);
}
Media
::
Media
(
Instance
&
instance
,
int
fd
)
Media
::
Media
(
InstancePtr
instance
,
int
fd
)
:
Internal
{
libvlc_media_new_fd
(
instance
->
get
(),
fd
),
libvlc_media_release
}
{
m_obj
=
libvlc_media_new_fd
(
instance
,
fd
);
if
(
m_obj
==
NULL
)
throw
std
::
runtime_error
(
"Failed to construct a media"
);
}
Media
::
Media
(
MediaList
&
list
)
{
m_obj
=
libvlc_media_list_media
(
list
);
if
(
m_obj
==
NULL
)
throw
std
::
runtime_error
(
"Failed to construct a media"
);
}
Media
::
Media
(
const
Media
&
another
)
:
Internal
(
another
)
,
m_eventManager
(
NULL
)
Media
::
Media
(
MediaListPtr
list
)
:
Internal
{
libvlc_media_list_media
(
list
->
get
()
),
libvlc_media_release
}
{
retain
();
if
(
another
.
m_eventManager
!=
NULL
)
m_eventManager
=
new
EventManager
(
*
another
.
m_eventManager
);
}
Media
&
Media
::
operator
=
(
const
Media
&
another
)
{
if
(
this
==
&
another
)
{
return
*
this
;
}
release
();
m_obj
=
another
.
m_obj
;
delete
m_eventManager
;
if
(
another
.
m_eventManager
!=
NULL
)
m_eventManager
=
new
EventManager
(
*
another
.
m_eventManager
);
else
m_eventManager
=
NULL
;
retain
();
return
*
this
;
}
bool
Media
::
operator
==
(
const
Media
&
another
)
const
...
...
@@ -94,25 +66,19 @@ bool Media::operator==(const Media& another) const
return
m_obj
==
another
.
m_obj
;
}
Media
::~
Media
()
{
delete
m_eventManager
;
release
();
}
void
Media
::
addOption
(
const
std
::
string
&
psz_options
)
{
libvlc_media_add_option
(
m_obj
,
psz_options
.
c_str
());
libvlc_media_add_option
(
get
()
,
psz_options
.
c_str
());
}
void
Media
::
addOptionFlag
(
const
std
::
string
&
psz_options
,
unsigned
i_flags
)
{
libvlc_media_add_option_flag
(
m_obj
,
psz_options
.
c_str
(),
i_flags
);
libvlc_media_add_option_flag
(
get
()
,
psz_options
.
c_str
(),
i_flags
);
}
std
::
string
Media
::
mrl
()
{
char
*
c_result
=
libvlc_media_get_mrl
(
m_obj
);
char
*
c_result
=
libvlc_media_get_mrl
(
get
()
);
if
(
c_result
==
NULL
)
return
std
::
string
();
std
::
string
result
=
c_result
;
...
...
@@ -122,13 +88,13 @@ std::string Media::mrl()
Media
Media
::
duplicate
()
{
InternalPtr
obj
=
libvlc_media_duplicate
(
m_obj
);
InternalPtr
obj
=
libvlc_media_duplicate
(
get
()
);
return
Media
(
obj
,
true
);
}
std
::
string
Media
::
meta
(
libvlc_meta_t
e_meta
)
{
char
*
c_result
=
libvlc_media_get_meta
(
m_obj
,
e_meta
);
char
*
c_result
=
libvlc_media_get_meta
(
get
()
,
e_meta
);
if
(
c_result
==
NULL
)
return
std
::
string
();
std
::
string
result
=
c_result
;
...
...
@@ -138,68 +104,68 @@ std::string Media::meta(libvlc_meta_t e_meta)
void
Media
::
setMeta
(
libvlc_meta_t
e_meta
,
const
std
::
string
&
psz_value
)
{
libvlc_media_set_meta
(
m_obj
,
e_meta
,
psz_value
.
c_str
());
libvlc_media_set_meta
(
get
()
,
e_meta
,
psz_value
.
c_str
());
}
int
Media
::
saveMeta
()
{
return
libvlc_media_save_meta
(
m_obj
);
return
libvlc_media_save_meta
(
get
()
);
}
libvlc_state_t
Media
::
state
()
{
return
libvlc_media_get_state
(
m_obj
);
return
libvlc_media_get_state
(
get
()
);
}
bool
Media
::
stats
(
libvlc_media_stats_t
*
p_stats
)
{