/* ***** BEGIN LICENSE BLOCK *****
 * Version: RCSL 1.0/RPSL 1.0
 *
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
 *
 * The contents of this file, and the files included with this file, are
 * subject to the current version of the RealNetworks Public Source License
 * Version 1.0 (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the RealNetworks Community Source License Version 1.0
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
 * in which case the RCSL will apply. You may also obtain the license terms
 * directly from RealNetworks.  You may not use this file except in
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
 * applicable to this file, the RCSL.  Please see the applicable RPSL or
 * RCSL for the rights, obligations and limitations governing use of the
 * contents of the file.
 *
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the portions
 * it created.
 *
 * This file, and the files included with this file, is distributed and made
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 *
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */

/*
 *  RealPix live encoder interfaces
 *
 */

#ifndef _HXLVPIX_H
#define _HXLVPIX_H

/*
 * PixInitInfo
 *
 * This struct contains initialization information
 * and is passed in in the IHXLiveRealPix::StartEncoder()
 * method. All of the members of this struct are input variables.
 */
typedef struct HXEXPORT_CLASS _PixInitInfo
{
    UINT32  m_ulStructLength;       /* length in bytes of this structure */
    char   *m_pServerAddress;       /* name or ip address of server */
    UINT32  m_ulServerPort;         /* pn-encoder port on server */
    char   *m_pUsername;            /* username for authentication on server */
    char   *m_pPassword;            /* password for authentication on server */
    char   *m_pFilename;            /* filename which clients should open */
    char   *m_pTitle;               /* title of live presentation */
    char   *m_pAuthor;              /* author of live presentation */
    char   *m_pCopyright;           /* copyright on live presentation */
    UINT32  m_ulBitrate;            /* bitrate of realpix stream */
    UINT32  m_ulMaxFps;             /* max frames per second of effects */
    UINT32  m_ulDisplayWidth;       /* display width in pixels */
    UINT32  m_ulDisplayHeight;      /* display height in pixels */
    BOOL    m_bPreserveAspect;      /* preserve aspect ratio by default? */
    char   *m_pDefaultURL;          /* default URL to send browser to when clicked */
    UINT32  m_ulNumImageCodecs;     /* number of image codecs used in this stream */
    char  **m_ppImageCodec;         /* string names of codecs */
    UINT32  m_ulNumEffectPackages;  /* number of external effect packages used */
    char  **m_ppEffectPackage;      /* string names of effect packages*/
}
PixInitInfo;

/*
 * PixImageInfo
 *
 * This struct contains all the information for images which
 * should be sent down the stream. This struct is used in the 
 * IHXLiveRealPix::InitImage() method.
 */
typedef struct HXEXPORT_CLASS _PixImageInfo
{
    UINT32  m_ulStructLength;      /* Input:  size of struct */
    BYTE   *m_pImageBuffer;        /* Input:  buffer holding image data */
    UINT32  m_ulImageBufferSize;   /* Input:  size of image buffer */
    char   *m_pImageCodec;         /* Input:  image codec to be used */
    UINT32  m_ulHandle;            /* Output: image handle */
    UINT32  m_ulNumPackets;        /* Output: number of packets image will be sent */
    UINT32  m_ulTimeToSend;        /* Output: milliseconds required to send image */
}
PixImageInfo;

#define EFFECT_FILL           0
#define EFFECT_FADEIN         1
#define EFFECT_FADEOUT        2
#define EFFECT_CROSSFADE      3
#define EFFECT_WIPE           4
#define EFFECT_VIEWCHANGE     5
#define EFFECT_EXTERNAL       6
#define EFFECT_ANIMATE        7

#define WIPE_DIRECTION_UP     0
#define WIPE_DIRECTION_DOWN   1
#define WIPE_DIRECTION_LEFT   2
#define WIPE_DIRECTION_RIGHT  3

#define WIPE_TYPE_NORMAL      0
#define WIPE_TYPE_PUSH        1

/*
 * PixEffectInfo
 *
 * This struct contains all the information about the effect which 
 * the RealPix renderer should perform. This struct is used in the
 * IHXLiveRealPix::SendEffect() method.
 */
typedef struct HXEXPORT_CLASS _PixEffectInfo
{
    UINT32  m_ulStructLength;      /* Input:  Length in bytes of this struct */
    BYTE    m_ucEffectType;        /* Input:  Effect Type: EFFECT_FILL, EFFECT_FADEIN, etc. */
    UINT32  m_ulStart;             /* Input:  Start time in milliseconds of effect */
    UINT32  m_ulDuration;          /* Input:  Duration in milliseconds of effect */
    UINT32  m_ulTarget;            /* Input:  Handle of image to perform effect on */
    UINT32  m_ulSrcX;              /* Input:  Horizontal offset of source rectangle */
    UINT32  m_ulSrcY;              /* Input:  Vertical offset of source rectangle */
    UINT32  m_ulSrcW;              /* Input:  Width of source rectangle */
    UINT32  m_ulSrcH;              /* Input:  Height of source rectangle */
    UINT32  m_ulDstX;              /* Input:  Horizontal offset of destination rectangle */
    UINT32  m_ulDstY;              /* Input:  Vertical offset of destination rectangle */
    UINT32  m_ulDstW;              /* Input:  Width of destination rectangle */
    UINT32  m_ulDstH;              /* Input:  Height of destination rectangle */
    UINT32  m_ulMaxFps;            /* Input:  Max frames per second for this effect */
    BOOL    m_bAspectFlag;         /* Input:  TRUE: preserve aspect on this effect; FALSE: don't preserve */
    BYTE    m_ucRed;               /* Input:  Red component of fill or fadeout color */
    BYTE    m_ucGreen;             /* Input:  Green component of fill or fadeout color */
    BYTE    m_ucBlue;              /* Input:  Blue component of fill or fadeout color */
    BYTE    m_ucWipeDirection;     /* Input:  WIPE_DIRECTION_xxx, where xxx is UP, DOWN, LEFT, or RIGHT */
    BYTE    m_ucWipeType;          /* Input:  WIPE_TYPE_NORMAL or WIPE_TYPE_PUSH */
    char   *m_pURL;                /* Input:  URL for this effect */
    char   *m_pExtPackage;         /* Input:  Name of external effect package */
    char   *m_pExtName;            /* Input:  Name of external effect within the package */
    char   *m_pExtData;            /* Input   Opaque string data for external effect */
    char   *m_pExtFile;            /* Input:  File contents of external effect data */
    BOOL    m_bDiscardImage;       /* Input:  TRUE: discard image after doing effect; FALSE: don't discard */
    BOOL    m_bDisplayImmediately; /* Input:  FALSE: obey start time; TRUE: do effect immediately */
	UINT32  m_ulHandle;            /* Output: Handle by which effect will be referred to */
}
PixEffectInfo;

/*
 * Forward declarations of some interfaces defined here.
 */
typedef _INTERFACE IHXLiveRealPix         IHXLiveRealPix;
typedef _INTERFACE IHXLiveRealPixResponse IHXLiveRealPixResponse;
typedef _INTERFACE IHXLiveRealPixResend   IHXLiveRealPixResend;

/*
 * Forward declarations of interfaces used here
 */
typedef _INTERFACE IHXValues              IHXValues;

/*
 * Declaration of the DLL entry point
 */
STDAPI CreateLiveRealPix(IHXLiveRealPix **);

typedef HX_RESULT (HXEXPORT_PTR FPRMCREATELIVEREALPIX)(IHXLiveRealPix **ppLiveRealPix);

/****************************************************************************
 * 
 *  Interface:
 * 
 *  IHXLivePix
 * 
 *  Purpose:
 * 
 *  Asynchronous interface that allows an application to encode live RealPix
 * 
 *  IID_IHXLiveRealPix:
 * 
 *  {E7ADF466-477D-11d2-AA0C-0060972D23A7}
 *
 */
DEFINE_GUID(IID_IHXLiveRealPix,  0xe7adf466, 0x477d, 0x11d2, 0xaa, 0xc, 0x0,
            0x60, 0x97, 0x2d, 0x23, 0xa7);

#undef  INTERFACE
#define INTERFACE   IHXLiveRealPix

DECLARE_INTERFACE_(IHXLiveRealPix, IUnknown)
{
    /*
     *  IUnknown methods
     */
    STDMETHOD(QueryInterface)      (THIS_ REFIID riid, void **ppvObj) PURE;

    STDMETHOD_(ULONG32,AddRef)     (THIS) PURE;

    STDMETHOD_(ULONG32,Release)    (THIS) PURE;

    /*
     *  IHXLiveRealPix methods
     */

    /*
     * StartEncoder() must be called before anything else and a pointer to
     * an IHXLiveRealPixResponse interface must be passed in. The encoder will
     * respond to this call asynchronously with IHXLiveRealPixResponse::EncoderStarted().
     */
    STDMETHOD(StartEncoder)        (THIS_ PixInitInfo             *pInitInfo,
                                          IHXLiveRealPixResponse *pResponse) PURE;

    /*
     * InitImage() is called to prep an image for being sent. It returns several useful
     * pieces of information which the caller can make use of: the handle to refer to
     * the image in SendImage(), the number of packets this image will be broken up into,
     * and the time required to send this image in milliseconds. Note that InitImage()
     * simply breaks the image up into packets - nothing has been sent to the server yet.
     * This is not an asynchronous call - all processing has finished by the time this
     * call returns.
     */
    STDMETHOD(InitImage)           (THIS_ PixImageInfo *pImageInfo) PURE;

    /*
     * SendImage() tranfers the all the packets for the image referred to by ulImageHandle
     * into the packet send queue. Further calls to Process() will result in these
     * packets being sent to the RealServer. When all the packets for this image have
     * been sent, the encoder will respond with IHXLiveRealPixResponse::ImageSent().
     */
    STDMETHOD(SendImage)           (THIS_ UINT32 ulImageHandle) PURE;

    /*
     * SendEffect() creates an effect packet with the information contained in
     * the PixEffectInfo struct and immediately adds this packet to the packet
     * send queue. Further calls to Process() will result in this packet being 
     * sent to the server. A handle is returned in the PixEffectInfo struct by
     * which this effect can later be identified. When the effect has been
     * sent to the server, the encoder will respond with
     * IHXLiveRealPixResponse::EffectSent().
     */
    STDMETHOD(SendEffect)          (THIS_ PixEffectInfo *pEffectInfo) PURE;

    /*
     * StopEncoder() may be called at any time after calling StartEncoder().
     * This tells the encoder that no more images of effects are going to
     * be sent to the encoder. The encoder shuts down the connection to
     * the server and responds with IHXLiveRealPixResponse::EncoderStopped().
     */
    STDMETHOD(StopEncoder)         (THIS) PURE;

    /*
     * GetTime() returns the time in milliseconds since the encoder library was initialized.
     */
    STDMETHOD_(UINT32, GetTime)    (THIS) PURE;

    /*
     * Process() must be called in order to give the library time to send
     * packets to the server. It should be called very often in between SendImage()
     * and ImageSent(), as well as between SendEffect() and EffectSent(). Other
     * that these times, it should be called every 3-5 seconds.
     */
    STDMETHOD(Process)             (THIS) PURE;
};

/****************************************************************************
 * 
 *  Interface:
 * 
 *  IHXLiveRealPixResponse
 * 
 *  Purpose:
 * 
 *  Asynchronous response interface that allows an application to
 *  encode live RealPix
 * 
 *  IID_IHXLiveRealPixResponse:
 * 
 *  {E7ADF46C-477D-11d2-AA0C-0060972D23A7}
 *
 */
DEFINE_GUID(IID_IHXLiveRealPixResponse, 0xe7adf46c, 0x477d, 0x11d2, 0xaa, 0xc, 0x0,
            0x60, 0x97, 0x2d, 0x23, 0xa7);


#undef  INTERFACE
#define INTERFACE   IHXLiveRealPixResponse

DECLARE_INTERFACE_(IHXLiveRealPixResponse, IUnknown)
{
    /*
     *  IUnknown methods
     */
    STDMETHOD(QueryInterface)      (THIS_ REFIID riid, void **ppvObj) PURE;

    STDMETHOD_(ULONG32,AddRef)     (THIS) PURE;

    STDMETHOD_(ULONG32,Release)    (THIS) PURE;

    /*
     *  IHXLiveRealPixResponse methods
     */

    /*
     * EncoderStarted() is the asynchronous response to StartEncoder(). The status
     * argument tells whether initializing the server was successful or not, and the pszHeaderString
     * argument returns the text string returned by the RealServer.
     */
    STDMETHOD(EncoderStarted)      (THIS_ HX_RESULT status, const char *pszHeaderString) PURE;

    /*
     * ImageSent() is the asynchronous response to SendImage(). The ulImageHandle argument
     * identifies which image has just completed sending to the server, and the status 
     * argument tells whether or not the send was successful or not.
     */
    STDMETHOD(ImageSent)           (THIS_ HX_RESULT status, UINT32 ulImageHandle) PURE;

    /*
     * EffectSent() is the asynchronous response to SendEffect(). The ulEffectHandle argument
     * identifies which effect has just completed sending to the server, and the status 
     * argument tells whether or not the send was successful or not.
     */
    STDMETHOD(EffectSent)          (THIS_ HX_RESULT status, UINT32 ulEffectHandle) PURE;

    /*
     * EncoderStopped() is the asynchronous response to StopEncoder(). The status
     * argument tells whether or not the stopping of the encoder was successful.
     * If the status is HXR_OK, then the application can then shut down or turn
     * around and call StartEncoder() again.
     */
    STDMETHOD(EncoderStopped)      (THIS_ HX_RESULT status) PURE;

    /*
     * ErrorOccurred() is called when the encoder receives an error from the RealServer.
     * Depending upon the severity of the error, the RealServer may then shut down
     * the encoder and an EncoderStopped() call would be made. Therefore, the
     * application should be ready to handle an EncoderStopped() call at any time.
     * If an error occurs, it's probably a good idea to call StopEncoder() and shut
     * down the encoder from the application side anyway.
     */
    STDMETHOD(ErrorOccurred)       (THIS_ const UINT8   unSeverity,
                                          const ULONG32 ulHXCode,
                                          const ULONG32 ulUserCode,
                                          const char   *pszUserString,
                                          const char   *pszMoreInfoURL) PURE;
};

/****************************************************************************
 * 
 *  Interface:
 * 
 *  IHXLiveRealPixResend
 * 
 *  Purpose:
 * 
 *  Allows re-sending and releasing of images with IHXLiveRealPix
 * 
 *  IID_IHXLiveRealPixResend:
 * 
 *  {D814DA11-8B02-11D3-8AF3-00C0F030B4E5}
 */
DEFINE_GUID(IID_IHXLiveRealPixResend, 0xd814da11, 0x8b02, 0x11d3, 0x8a, 0xfe, 0x0,
            0xc0, 0xf0, 0x30, 0xb4, 0xe5);


#undef  INTERFACE
#define INTERFACE   IHXLiveRealPixResend

DECLARE_INTERFACE_(IHXLiveRealPixResend, IUnknown)
{
    /*
     *  IUnknown methods
     */
    STDMETHOD(QueryInterface)      (THIS_ REFIID riid, void** ppvObj) PURE;

    STDMETHOD_(ULONG32,AddRef)     (THIS) PURE;

    STDMETHOD_(ULONG32,Release)    (THIS) PURE;

    /*
     *  IHXLiveRealPixResend methods
     */

    /*
     * InitResend() informs the encoder that from now on, after an
     * image is sent with SendImage() it should not be discarded 
     * but held in the encoder until ReleaseImage() is called().
     */
    STDMETHOD(InitResend)   (THIS_ IHXValues* pOptions) PURE;

    /*
     * ReleaseImage() informs the encoder that the application no longer
     * intends to call SendImage() on the image referenced by ulImageHandle
     * and that it can discard the image. Further calls to SendImage(x) will
     * return HXR_UNKNOWN_IMAGE after ReleaseImage(x) has been called.
     * ReleaseImage(x) will return HXR_UNKNOWN_IMAGE if x is an unknown handle.
     */
    STDMETHOD(ReleaseImage) (THIS_ UINT32 ulImageHandle) PURE;

    /*
     * DumpAllQueuedPackets() clears any packets currently waiting to be
     * sent to the server. These packets were put on the send queue by
     * either IHXLiveRealPix::SendImage() or IHXLiveRealPix::SendEffect().
     */
    STDMETHOD(DumpAllQueuedPackets) (THIS) PURE;
};

#endif
