/*
 *	osgART/VideoManager
 *	osgART: AR ToolKit for OpenSceneGraph
 *
 *	Copyright (c) 2005-2007 ARToolworks, Inc. All rights reserved.
 *	
 *	Rev		Date		Who		Changes
 *  1.0   	2006-12-08  ---     Version 1.0 release.
 *
 */
/*
 * This file is part of osgART - AR Toolkit for OpenSceneGraph
 *
 * Copyright (c) 2005-2007 ARToolworks, Inc. All rights reserved.
 *
 * (See the AUTHORS file in the root of this distribution.)
 *
 *
 * OSGART is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * OSGART 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OSGART; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */


#ifndef OSGART_VIDEOMANAGER
#define OSGART_VIDEOMANAGER 1

// STL
#include <map>

// OSG.DB include (for plugins)
#include <osgDB/DynamicLibrary>

// graphics include
#include <osgART/Export>

// local include
#include "osgART/GenericVideo"
#include "osgART/VideoConfig"


namespace osgART {

	/**
	* \class VideoManager.
	*
	*/
	 
	class OSGART_EXPORT VideoManager {
	public:

		/** function signature for creating a video instance */
		typedef GenericVideo* (*p_VideoCreateFunc)();        
	    
		/** 
		* \brief singleton constructor.
		* Based on a singleton pattern, user can get the instance of the video manager
		* actually used by the program.
		* @return an instance of a video manager
		*/
		static VideoManager* getInstance();
	   
		/**
		* \brief destructor.
		*/
		virtual ~VideoManager();    

		/**
		* \brief add a video stream.
		* Register in the video manager a video stream.
		* \param video the video stream to add.
		* \return the id of the video stream
		*/
		int addVideoStream(GenericVideo* video);
		
		/**
		* \brief remove a video stream.
		* Remove a video stream from the VideoManager
		* \param video the video stream to register.
		*/
		void removeVideoStream(GenericVideo* video);
		
		/**
		* \brief obtain a video stream.
		* Return instance of a video stream identified by his id.
		* \return an instance of a video manager
		*/
		GenericVideo* getVideo(int idVideo);

		static
		GenericVideo* createVideoFromPlugin(const std::string& plugin);

		/**
		 * Delete the instance of the VideoManager
		 */
		 static
		 void destroy();
	    
	protected: 
	    
		// default constructor
		VideoManager();
		
	private:
	
		typedef std::map<std::string, osg::ref_ptr<osgDB::DynamicLibrary> > PluginMap;
		typedef std::map<int, osg::ref_ptr<GenericVideo> > VideoStreamMap;
	
		static VideoManager* _instance;
		
		static p_VideoCreateFunc createFunc(const std::string& filename);

		int numVideoStream;
		
		// video streams
		VideoStreamMap m_videomap;	
		
		// video plugins
		static PluginMap s_plugins;
	};

}

#endif
