/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com

Copyright (c) 2010 I-maginer

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 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., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

You may alternatively use this source under the terms of a specific version of
the OpenSpace3D Unrestricted License provided you have obtained such a license from
I-maginer.
-----------------------------------------------------------------------------
*/

/*! \class ObjVlcMediaPlayer
*  \brief 
*  \
*  \version 1.0
*  \date may 2011
*/

#ifndef __OBJ_VLCMPLAYER_H__
#define __OBJ_VLCMPLAYER_H__

#include <string>
#include <vlc.h>
#include <scol.h>

// TODO in SCOL SDK
#define BUFFER_FLAG_MUTEX 2

class VlcSingleton
{
private:
  VlcSingleton();
  ~VlcSingleton();
protected:
public:

private:
  libvlc_instance_t* VLCinst;
  static VlcSingleton* _singleton;
protected:

public:
  static libvlc_instance_t* GetInstance();
  static void Kill();
  
private:
protected:
};


class ObjVlcMediaPlayer
{
public:
protected:
private:
	libvlc_media_player_t* VLCplayer;
  libvlc_event_manager_t* VLCeventManager;

  static void display(void *data, void *id);
  static void unlock(void *data, void *id, void *const *p_pixels);
  static void *lock(void *data, void **p_pixels);

  bool bVmem;
  bool bVlm;
  bool bLoop;
  std::string VlmName;

public:
  ObjVlcMediaPlayer();
  ObjVlcMediaPlayer(PtrObjBitmap bitmap, int width, int height, int pitch);
  ObjVlcMediaPlayer(std::string ip, int port, std::string device, std::string name, int width, int height, int rate);
  ~ObjVlcMediaPlayer();
  libvlc_media_player_t* getMediaPlayer();
  libvlc_instance_t* getVlcInstance();
    
	bool isVmem();
	bool isVlm();
  std::string getVlmName();
  
  void setWindow(HWND win);
  void setFullScreen(bool state);
  bool getFullScreenState();
  void toggleFullScreen();

  void setMediaPath(std::string path);
  void play();
  void pause();
  void stop();
  bool seek(float value);
  bool setPosition(float value);
  float getPosition();
  bool setTime(int value);
  int getTime();
  int getDuration();
  int getState();

  void setVolume(int vol);
  int getVolume();
  void setMute(bool state);
  bool getMute();

  void setLoop(bool state);
  bool getLoop();

protected:
private:
  void CommonConstructor();
};

static void _mediaEventCallback( const libvlc_event_t *ev, void *p);

#endif //__OBJ_VLCMPLAYER_H__
