/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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 NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_XV_IMG_HPP
#define NMM_XV_IMG_HPP NMM_XV_IMG_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/plugins/video/display/X/XVirtualImg.hpp"

#include <X11/extensions/Xvlib.h>

namespace NMM {

  /** Xv image.
   *
   * This is a class for writing video frames to a X Display using
   * XVideo extension.
   */
  class XvImg 
    : public XVirtualImg {

  protected:
    //! The port of the XVideo extension to use for passing video frames
    XvPortID        xvport;
    //! pointer to the XvImage used for putting the incomming images in
    XvImage*        xvimage;
    //! the format of the video frames as used by the XVideo extension
    unsigned int    xvformat;

    /**
     * This methods queries specified XServer for the existence of a
     * XVideo extension, opens the the XVideo port use this port to
     * gather all possible informations about the capabilities of the
     * XVideo extension. The informations are wrote out through a
     * MESSAGE_STREAM.
     * \param display The display to query for XVideo extension.
     * \param win A valid window needed for opening the XVideo port.
     * returns true iff XVideo is supported on the given Display and a
     * free port could be opened.
     */
    bool queryAdaptors(Display* display, Window win);

    // implementation of pure virtual methods from XVirtualImg
    virtual bool initImage();
    virtual void deinitImage();

  public:
    //! The number of the XVideo format "uvuy".
    static int XV_FORMAT_UYVY;
    //! The number of the XVideo format "yv12".
    static int XV_FORMAT_YV12;
    //! The number of the XVideo format "yuv2".
    static int XV_FORMAT_YUV2;
    //! The number of the XVideo format "i420".
    static int XV_FORMAT_I420; 

    /** Constructor.
     *
     * \param parent Node* to the DisplayNode, this Img is running in
     * \param width The width of the video frames, to be presented
     * \param height The width of the video frames, to be presented
     * \param title The title used for the X-Window to be created
     * \param format The XVideo format description of the video frames
     *               to be presented
     * \param fullscreen Flag to indicate, that the window should be
     *                   opened directly in fullscreen mode
     * \param ratio_x The x-component of the aspect ratio to use for
     *                presenting the video frames
     * \param ratio_y The y-component of the aspect ratio to use for
     *                presenting the video frames
     */
    XvImg(Node* parent,
          int width, int height,
          std::string title,
          unsigned int format, bool fullscreen,
          int ratio_x, int ratio_y);

    /** Destructor.
     */
    virtual ~XvImg();

    // implementation of pure virtual methods from XVirtualImg
    virtual void prepareOutput(Buffer*);
    virtual void update(Buffer*);

    virtual char* getImage();
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
