Commit 075b3317 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add C++/CX wrapper

parent 22b4134c
/*****************************************************************************
* MediaCX.hpp: Media API
*****************************************************************************
* Copyright 2014 the VideoLAN team
*
* Authors: Hugo Beauze-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "EventManagerCX.hpp"
#include "MediaCX.hpp"
namespace libVLCX
{
MediaPlayerEventCb::MediaPlayerEventCb(EventManager^ em)
: m_em(em)
{
}
void MediaPlayerEventCb::mediaChanged(const VLC::Media& media)
{
m_em->OnMediaChanged(ref new Media(media));
}
void MediaPlayerEventCb::nothingSpecial()
{
}
void MediaPlayerEventCb::opening()
{
m_em->OnOpening();
}
void MediaPlayerEventCb::buffering(float percent)
{
m_em->OnBuffering(percent);
}
void MediaPlayerEventCb::playing()
{
m_em->OnPlaying();
}
void MediaPlayerEventCb::paused()
{
m_em->OnPaused();
}
void MediaPlayerEventCb::stopped()
{
m_em->OnStopped();
}
void MediaPlayerEventCb::forward()
{
m_em->OnForward();
}
void MediaPlayerEventCb::backward()
{
m_em->OnBackward();
}
void MediaPlayerEventCb::endReached()
{
m_em->OnEndReached();
}
void MediaPlayerEventCb::encounteredError()
{
m_em->OnEncounteredError();
}
void MediaPlayerEventCb::timeChanged(libvlc_time_t time)
{
m_em->OnTimeChanged(time);
}
void MediaPlayerEventCb::positionChanged(float pos)
{
m_em->OnPositionChanged(pos);
}
void MediaPlayerEventCb::seekableChanged(bool val)
{
m_em->OnSeekableChanged(val);
}
void MediaPlayerEventCb::pausableChanged(bool val)
{
m_em->OnPausableChanged(val);
}
void MediaPlayerEventCb::titleChanged(int title)
{
m_em->OnTitleChanged(title);
}
void MediaPlayerEventCb::snapshotTaken(const std::string& str)
{
m_em->OnSnapshotTaken(ToPlatformString(str));
}
void MediaPlayerEventCb::lengthChanged(libvlc_time_t length)
{
m_em->OnLengthChanged(length);
}
void MediaPlayerEventCb::vout(int nbVout)
{
m_em->OnVoutCountChanged(nbVout);
}
void MediaPlayerEventCb::scrambledChanged(int val)
{
m_em->OnScrambledChanged(val);
}
void MediaPlayerEventCb::eSAdded(libvlc_track_type_t, int)
{
}
void MediaPlayerEventCb::eSDeleted(libvlc_track_type_t, int)
{
}
void MediaPlayerEventCb::eSSelected(libvlc_track_type_t, int)
{
}
EventManager::EventManager(VLC::EventManager& em)
: m_em(em)
, m_cb(new MediaPlayerEventCb(this))
{
em.attach(libvlc_MediaPlayerMediaChanged, m_cb.get());
em.attach(libvlc_MediaPlayerNothingSpecial, m_cb.get());
em.attach(libvlc_MediaPlayerOpening, m_cb.get());
em.attach(libvlc_MediaPlayerBuffering, m_cb.get());
em.attach(libvlc_MediaPlayerPlaying, m_cb.get());
em.attach(libvlc_MediaPlayerPaused, m_cb.get());
em.attach(libvlc_MediaPlayerStopped, m_cb.get());
em.attach(libvlc_MediaPlayerForward, m_cb.get());
em.attach(libvlc_MediaPlayerBackward, m_cb.get());
em.attach(libvlc_MediaPlayerEndReached, m_cb.get());
em.attach(libvlc_MediaPlayerEncounteredError, m_cb.get());
em.attach(libvlc_MediaPlayerTimeChanged, m_cb.get());
em.attach(libvlc_MediaPlayerPositionChanged, m_cb.get());
em.attach(libvlc_MediaPlayerSeekableChanged, m_cb.get());
em.attach(libvlc_MediaPlayerPausableChanged, m_cb.get());
em.attach(libvlc_MediaPlayerTitleChanged, m_cb.get());
em.attach(libvlc_MediaPlayerSnapshotTaken, m_cb.get());
em.attach(libvlc_MediaPlayerLengthChanged, m_cb.get());
em.attach(libvlc_MediaPlayerVout, m_cb.get());
em.attach(libvlc_MediaPlayerScrambledChanged, m_cb.get());
em.attach(libvlc_MediaPlayerESAdded, m_cb.get());
em.attach(libvlc_MediaPlayerESDeleted, m_cb.get());
em.attach(libvlc_MediaPlayerESSelected, m_cb.get());
}
}
\ No newline at end of file
/*****************************************************************************
* MediaCX.hpp: Media API
*****************************************************************************
* Copyright 2014 the VideoLAN team
*
* Authors: Hugo Beauze-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "EventManager.hpp"
#include "Media.hpp"
#include <memory>
namespace libVLCX
{
ref class Media;
public delegate void MediaChanged(Media^);
public delegate void NothingSpecial();
public delegate void Opening();
public delegate void Buffering(float);
public delegate void Playing();
public delegate void Paused();
public delegate void Stopped();
public delegate void Forward();
public delegate void Backward();
public delegate void EndReached();
public delegate void EncounteredError();
public delegate void TimeChanged(libvlc_time_t);
public delegate void PositionChanged(float);
public delegate void SeekableChanged(bool);
public delegate void PausableChanged(bool);
public delegate void TitleChanged(int);
public delegate void SnapshotTaken(Platform::String^);
public delegate void LengthChanged(libvlc_time_t);
public delegate void Vout(int);
public delegate void ScrambledChanged(int);
//public delegate void ESAdded(libvlc_track_type_t, int);
//public delegate void ESDeleted(libvlc_track_type_t, int);
//public delegate void ESSelected(libvlc_track_type_t, int);
ref class EventManager;
class MediaPlayerEventCb : public VLC::IMediaPlayerEventCb
{
public:
MediaPlayerEventCb(EventManager^ em);
virtual void mediaChanged(const VLC::Media&);
virtual void nothingSpecial();
virtual void opening();
virtual void buffering(float);
virtual void playing();
virtual void paused();
virtual void stopped();
virtual void forward();
virtual void backward();
virtual void endReached();
virtual void encounteredError();
virtual void timeChanged(libvlc_time_t);
virtual void positionChanged(float);
virtual void seekableChanged(bool);
virtual void pausableChanged(bool);
virtual void titleChanged(int);
virtual void snapshotTaken(const std::string&);
virtual void lengthChanged(libvlc_time_t);
virtual void vout(int);
virtual void scrambledChanged(int);
virtual void eSAdded(libvlc_track_type_t, int);
virtual void eSDeleted(libvlc_track_type_t, int);
virtual void eSSelected(libvlc_track_type_t, int);
private:
EventManager^ m_em;
};
public ref class EventManager sealed
{
public:
event MediaChanged^ OnMediaChanged;
event Opening^ OnOpening;
event Buffering^ OnBuffering;
event Playing^ OnPlaying;
event Paused^ OnPaused;
event Stopped^ OnStopped;
event Forward^ OnForward;
event Backward^ OnBackward;
event EndReached^ OnEndReached;
event EncounteredError^ OnEncounteredError;
event TimeChanged^ OnTimeChanged;
event PositionChanged^ OnPositionChanged;
event SeekableChanged^ OnSeekableChanged;
event PausableChanged^ OnPausableChanged;
event TitleChanged^ OnTitleChanged;
event SnapshotTaken^ OnSnapshotTaken;
event LengthChanged^ OnLengthChanged;
event Vout^ OnVoutCountChanged;
event ScrambledChanged^ OnScrambledChanged;
internal:
EventManager(VLC::EventManager& em);
private:
~EventManager(){}
private:
VLC::EventManager m_em;
std::unique_ptr<MediaPlayerEventCb> m_cb;
friend class MediaPlayerEventCb;
};
}
\ No newline at end of file
/*****************************************************************************
* InstanceCX.cpp: Instance API
*****************************************************************************
* Copyright 2014 the VideoLAN team
*
* Authors: Hugo Beauze-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "InstanceCX.hpp"
#include "Helpers.h"
#include <collection.h>
//HACK HACK HACK
using namespace Windows::Graphics::Display;
namespace libVLCX
{
Instance::Instance(Windows::Foundation::Collections::IVector<Platform::String^>^ argv, SwapChainPanel^ panel)
: m_chainPanel(panel)
{
int extraArgs = 4;
auto c_argv = new char*[argv->Size + extraArgs];
unsigned int i = 0;
for (auto arg : argv)
{
c_argv[i++] = _strdup((const char*) VLCString(arg));
}
InitializeHack(c_argv, i);
m_instance = VLC::Instance::create(argv->Size + extraArgs, c_argv);
for (i = 0; i < argv->Size + extraArgs; ++i)
free(c_argv[i]);
delete [] c_argv;
}
void Instance::InitializeHack(char** argv, unsigned int nbArgs)
{
m_dxManager.reset(new DirectXManger);
m_dxManager->CreateSwapPanel(m_chainPanel);
UpdateSize(m_chainPanel->ActualWidth, m_chainPanel->ActualHeight);
char ptr_d2dstring[40];
sprintf_s(ptr_d2dstring, "--winrt-d2dcontext=0x%p", m_dxManager->cp_d2dContext);
argv[nbArgs++] = _strdup(ptr_d2dstring);
char ptr_scstring[40];
sprintf_s(ptr_scstring, "--winrt-swapchain=0x%p", m_dxManager->cp_swapChain);
argv[nbArgs++] = _strdup(ptr_scstring);
char widthstring[40];
sprintf_s(widthstring, "--winrt-width=0x%p", &m_width);
argv[nbArgs++] = _strdup(widthstring);
char heightstring[40];
sprintf_s(heightstring, "--winrt-height=0x%p", &m_height);
argv[nbArgs++] = _strdup(heightstring);
}
void Instance::UpdateSize(float x, float y)
{
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
const float scaleFactor = Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->RawPixelsPerViewPixel;
#else
const float scaleFactor = (float) DisplayProperties::ResolutionScale / 100.f;
#endif
m_width = x * scaleFactor;
m_height = y * scaleFactor;
}
int Instance::addIntf(Platform::String^ name)
{
return m_instance.addIntf(VLCString(name));
}
void Instance::setUserAgent(Platform::String^ name, Platform::String^ http)
{
m_instance.setUserAgent(VLCString(name), VLCString(http));
}
void Instance::setAppId(Platform::String^ id, Platform::String^ version, Platform::String^ icon)
{
m_instance.setAppId(VLCString(id), VLCString(version), VLCString(icon));
}
Windows::Foundation::Collections::IVector<ModuleDescription^>^ Instance::audioFilterList()
{
return MarshallVector<ModuleDescription, VLC::ModuleDescription>(m_instance.audioFilterList());
}
Windows::Foundation::Collections::IVector<ModuleDescription^>^ Instance::videoFilterList()
{
return MarshallVector<ModuleDescription, VLC::ModuleDescription>(m_instance.videoFilterList());
}
Windows::Foundation::Collections::IVector<AudioOutputDescription^>^ Instance::audioOutputList()
{
return MarshallVector<AudioOutputDescription, VLC::AudioOutputDescription>(m_instance.audioOutputList());
}
Windows::Foundation::Collections::IVector<AudioOutputDeviceDescription^>^ Instance::audioOutputDeviceList(Platform::String^ aout)
{
return MarshallVector<AudioOutputDeviceDescription, VLC::AudioOutputDeviceDescription>(m_instance.audioOutputDeviceList(VLCString(aout)));
}
Instance::~Instance()
{
}
} // namespace VLC
/*****************************************************************************
* InstanceCX.hpp: Instance API
*****************************************************************************
* Copyright © 2014 the VideoLAN team
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include "StructuresCX.hpp"
#include "Instance.hpp"
#include <collection.h>
//<ugly>
#include "DirectXManager.h"
//</ugly>
namespace libVLCX
{
public ref class Instance sealed
{
public:
//<HACK HACK HACK>
void UpdateSize(float x, float y);
//</HACK HACK HACK>
/**
* Create and initialize a libvlc instance. This functions accept a list
* of "command line" arguments similar to the main(). These arguments
* affect the LibVLC instance default configuration.
*
* \version Arguments are meant to be passed from the command line to
* LibVLC, just like VLC media player does. The list of valid arguments
* depends on the LibVLC version, the operating system and platform, and
* set of available LibVLC plugins. Invalid or unsupported arguments will
* cause the function to fail (i.e. return NULL). Also, some arguments
* may alter the behaviour or otherwise interfere with other LibVLC
* functions.
*
* \warning There is absolutely no warranty or promise of forward,
* backward and cross-platform compatibility with regards to
* Instance::Instance() arguments. We recommend that you do not use them,
* other than when debugging.
*
* \param argc the number of arguments (should be 0)
*
* \param argv list of arguments (should be NULL)
*/
Instance(Windows::Foundation::Collections::IVector<Platform::String^>^ argv, SwapChainPanel^ panel);
/**
* Try to start a user interface for the libvlc instance.
*
* \param name interface name, or NULL for default
*
* \return 0 on success, -1 on error.
*/
int addIntf(Platform::String^ name);
/**
* Sets the application name. LibVLC passes this as the user agent string
* when a protocol requires it.
*
* \param name human-readable application name, e.g. "FooBar player
* 1.2.3"
*
* \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
*
* \version LibVLC 1.1.1 or later
*/
void setUserAgent(Platform::String^ name, Platform::String^ http);
/**
* Sets some meta-information about the application. See also
* Instance::setUserAgent() .
*
* \param id Java-style application identifier, e.g. "com.acme.foobar"
*
* \param version application version numbers, e.g. "1.2.3"
*
* \param icon application icon name, e.g. "foobar"
*
* \version LibVLC 2.1.0 or later.
*/
void setAppId(Platform::String^ id, Platform::String^ version, Platform::String^ icon);
/**
* Returns a list of audio filters that are available.
*
* \return a list of module descriptions. It should be freed with
* ModuleDescription::moduleDescriptionListRelease() . In case of an
* error, NULL is returned.
*
* \see ModuleDescription
*
* \see ModuleDescription::moduleDescriptionListRelease()
*/
Windows::Foundation::Collections::IVector<ModuleDescription^>^ audioFilterList();
/**
* Returns a list of video filters that are available.
*
* \return a list of module descriptions. It should be freed with
* ModuleDescription::moduleDescriptionListRelease() . In case of an
* error, NULL is returned.
*
* \see ModuleDescription
*
* \see ModuleDescription::moduleDescriptionListRelease()
*/
Windows::Foundation::Collections::IVector<ModuleDescription^>^ videoFilterList();
/**
* Gets the list of available audio output modules.
*
* \return list of available audio outputs. It must be freed it with
*
* \see AudioOutputDescription::audioOutputListRelease()
*
* \see AudioOutputDescription . In case of error, NULL is returned.
*/
Windows::Foundation::Collections::IVector<AudioOutputDescription^>^ audioOutputList();
/**
* Gets a list of audio output devices for a given audio output module,
*
* \see Audio::outputDeviceSet() .
*
* \note Not all audio outputs support this. In particular, an empty
* (NULL) list of devices does imply that the specified audio output does
* not work.
*
* \note The list might not be exhaustive.
*
* \warning Some audio output devices in the list might not actually work
* in some circumstances. By default, it is recommended to not specify
* any explicit audio device.
*
* \param psz_aout audio output name (as returned by
* Instance::audioOutputList() )
*
* \return A vector containing all audio output devices for this module
*
* \version LibVLC 2.1.0 or later.
*/
Windows::Foundation::Collections::IVector<AudioOutputDeviceDescription^>^ audioOutputDeviceList(Platform::String^ aout);
private:
void InitializeHack(char** argv, unsigned int nbArgs);
~Instance();
internal:
VLC::Instance m_instance;
// <HACK HACK HACK!>
std::unique_ptr<DirectXManger> m_dxManager;
float m_width;
float m_height;
SwapChainPanel^ m_chainPanel;
// </HACK HACK HACK>
};
} // namespace VLC
/*****************************************************************************
* MediaCX.hpp: Media API
*****************************************************************************
* Copyright 2014 the VideoLAN team
*
* Authors: Hugo Beauze-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "structuresCX.hpp"
#include "InstanceCX.hpp"
#include "EventManagerCX.hpp"
#include "MediaCX.hpp"
#include <collection.h>
namespace libVLCX
{
Media::Media(Instance^ instance, Platform::String^ location)
{
m_media = VLC::Media::fromLocation(instance->m_instance, VLCString(location));
}
void Media::addOption(Platform::String^ options)
{
m_media.addOption(VLCString(options));
}
void Media::addOptionFlag(Platform::String^ options, unsigned i_flags)
{
m_media.addOptionFlag(VLCString(options), i_flags);
}
Platform::String^ Media::mrl()
{
return ToPlatformString(m_media.mrl());
}
Media^ Media::duplicate()
{
return ref new Media(m_media.duplicate());
}
Platform::String^ Media::meta(MediaMeta e_meta)
{
return ToPlatformString(m_media.meta((libvlc_meta_t)e_meta));
}
void Media::setMeta(MediaMeta e_meta, Platform::String^ psz_value)
{
m_media.setMeta((libvlc_meta_t)e_meta, VLCString(psz_value));
}
int Media::saveMeta()
{
return m_media.saveMeta();
}
MediaState Media::state()
{
return (MediaState)m_media.state();
}
//bool Media::stats(libvlc_media_stats_t * p_stats);
EventManager^ Media::eventManager()
{
if (m_eventManager == nullptr)
m_eventManager = ref new EventManager(m_media.eventManager());
return m_eventManager;
}
libvlc_time_t Media::duration()
{
return m_media.duration();
}
void Media::parse()
{
m_media.parse();
}
void Media::parseAsync()
{
m_media.parseAsync();
}
bool Media::isParsed()
{
return m_media.isParsed();
}
void Media::setUserData(Platform::IntPtr p_new_user_data)
{
m_media.setUserData((void*) p_new_user_data);
}
Platform::IntPtr Media::userData()
{
return (Platform::IntPtr)m_media.userData();
}
Windows::Foundation::Collections::IVector<MediaTrack^>^ Media::tracks()
{
return MarshallVector<MediaTrack, VLC::MediaTrack>(m_media.tracks());
}
Media::Media(const VLC::Media& media)
: m_media(media)
{
}
} // namespace VLC
/*****************************************************************************
* MediaCX.hpp: Media API
*****************************************************************************
* Copyright © 2014 the VideoLAN team
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include "structuresCX.hpp"
#include "Media.hpp"
#include <collection.h>
namespace libVLCX