/* -*-c++-*- 
 * 
 * osgART - ARToolKit for OpenSceneGraph
 * Copyright (C) 2005-2008 Human Interface Technology Laboratory New Zealand
 * 
 * This file is part of osgART 2.0
 *
 * osgART 2.0 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 3 of the License, or
 * (at your option) any later version.
 *
 * osgART 2.0 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 2.0.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef OSGART_VIDEOIMAGESTREAM
#define OSGART_VIDEOIMAGESTREAM 1

// OSG include
#include <osg/Version>
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/ImageStream>
#include <osg/Stats>

// Local include
#include "osgART/Export"

namespace osgART {


	class OSGART_EXPORT VideoImageStream : public osg::ImageStream
	{	
	public:
	
		/** Constructor */
		VideoImageStream();
		
        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
        VideoImageStream(const VideoImageStream& image, 
			const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        virtual osg::Object* cloneType() const 
        { 
			return new VideoImageStream(); 
		}
        
        virtual osg::Object* clone(const osg::CopyOp& copyop) const 
        { 
			return new VideoImageStream(*this,copyop); 
		}
			
        virtual bool isSameKindAs(const osg::Object* obj) const 
        {
			return dynamic_cast<const VideoImageStream*>(obj) != 0; 
		}
        
        virtual const char* libraryName() const 
        {
			return "osgART"; 
		}
        
        virtual const char* className() const 
        {
			return "VideoImageStream";
		}			
		
		
		/**
		 * \brief start the  video stream grabbing.
		 * Start to get image from the  video stream. In function of the implementation on different
		 * platform, this function can run a thread, signal or real-time function. 
		 */
		virtual void start();
		
		/**
		 * \brief stop the  video stream grabbing.
		 * Stop to get image from the  video stream. In function of 
		 * the implementation on different platform, this function can 
		 * stop a thread, signal or real-time function. 
		 */
		virtual void stop();
		
		/**
		 * \brief open the Video stream.
		 * Access the Video stream (hardware or file) and get an handle on it.
		 */		
		virtual void open();
				
		/**
		 * \brief close the video stream.
		 * Terminate the connection with the video stream and 
		 * clean handle.
		 */	
		virtual void close(bool waitForThread = true);
		
		
		
#if (OPENSCENEGRAPH_SOVERSION <= 41)

		/** 
		 * This is a proxy method overiding ImageStream::update() for older 
		 * OpenSceneGraph versions
		 */
		inline virtual void update()
		{
			this->update(0);
		}

		/**
		 * Additionally we proxy the new API of OpenSceneGraph introduced 
		 * around version 2.5.6
		 */
		inline virtual void update(osg::NodeVisitor* nv) 
		{			
		}		
#endif
		/**
		 * Returns stats for the Video capture
		 *
		 * \return pointer to the stats connected to the video
		 */		 
		inline osg::Stats* getStats() { return _stats.get(); };
		
		/**
		 * Set the stats for the Video capture
		 *
		 * \param stats pointer to the stats capturing timings
		 */		 		
		inline void setStats(osg::Stats* stats) { _stats = stats; } ;
		
	protected:
	
		osg::ref_ptr<osg::Stats> _stats;
	
		virtual ~VideoImageStream();
		
		
	};
	

}

#endif
