// ImageSync.idl : IDL source for ImageSync.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (ImageSync.tlb) and marshalling code.


//=====================================================================
//=====================================================================
// time information
//
// This represents a time (either reference or stream) in 100ns units
// The class library contains a CRefTime helper class
// that supports simple comparison and arithmetic operations
//=====================================================================
//=====================================================================


cpp_quote("#ifdef DSHOW_INDEPENDENT")
// Win32 HANDLEs have to be cast to these as the MIDL compiler doesn't
// like the HANDLE type or in fact anything remotely associated with
// them. If this ever gets ported to a MAC environment then these will
// have to become an alertable synchronisation object that it supports

//typedef DWORD_PTR HSEMAPHORE;
//typedef DWORD_PTR HEVENT;

typedef unsigned long HSEMAPHORE;
typedef unsigned long HEVENT;
typedef __int64 REFERENCE_TIME;
typedef double REFTIME;
cpp_quote("#endif")


cpp_quote("#if 0")
// This is temporary hack to get around the fact thatI don't know how to persuade
// MIDL to allow forward declarations.
typedef DWORD*    LPDIRECTDRAW7;
typedef DWORD*    LPDIRECTDRAWSURFACE7;
cpp_quote ("#endif")

cpp_quote("#include <ddraw.h>")


import "oaidl.idl";
import "ocidl.idl";


//=====================================================================
//=====================================================================
//
// DDraw information
//
//=====================================================================
//=====================================================================
cpp_quote("//")
cpp_quote("//   The following declarations within the 'if 0' block are dummy")
cpp_quote("//   typedef's used to make the ImageSync.idl build under midl.")
cpp_quote("//   The actual definitions are contained in ddraw.h.")
cpp_quote("//")

cpp_quote("#if 0")
typedef IUnknown*                 IReferenceClock;
cpp_quote("#endif")

cpp_quote("#include <ddraw.h>")


cpp_quote("#ifdef DSHOW_INDEPENDENT")
//=====================================================================
//=====================================================================
//
// QualityControl information
//
//=====================================================================
//=====================================================================
typedef enum tagQualityMessageType {
    Famine,
    Flood
} QualityMessageType;

typedef struct tagQuality {
    QualityMessageType Type;

    // milli-units.  1000 = no change
    // for Flood:
    // What proportion of the media samples currently
    // coming through are required in the future.
    // 800 means please drop another 20%
    // For Famine:
    // How much to "keep in" e.g. 800 means send me
    // 20% less e.g. by dropping 20% of the samples.
    // 1100 would mean "I'm coping, send me more".
    long               Proportion;

    // How much you need to catch up by
    REFERENCE_TIME       Late;

    // The stream time when this was generated (probably
    // corresponds to the start time on some sample).
    REFERENCE_TIME       TimeStamp;
} Quality;


//=====================================================================
//=====================================================================
//
// IQualProp
//
//=====================================================================
//=====================================================================
    [
        object,
        uuid(1bd0ecb0-f8e2-11ce-aac6-0020af0b99a3),

        helpstring("IQualProp Interface"),
        pointer_default(unique)
    ]
    interface IQualProp : IUnknown
    {
        HRESULT get_FramesDroppedInRenderer(
            [out] int *cFramesDropped
        );

        HRESULT get_FramesDrawn(
            [out] int *pcFramesDrawn
        );

        HRESULT get_AvgFrameRate(
            [out] int *piAvgFrameRate
        );

        HRESULT get_Jitter(
            [out] int *piJitter
        );

        HRESULT get_AvgSyncOffset(
            [out] int *piAvg
        );

        HRESULT get_DevSyncOffset(
            [out] int *piDev
        );
    };
cpp_quote("#endif")

//=====================================================================
//=====================================================================
//
// IVMRImagePresenter
//
//=====================================================================
//=====================================================================
    [
        object,
        uuid(CE704FE7-E71E-41fb-BAA2-C4403E1182F5),

        helpstring("IVMRImagePresenter Interface"),
        pointer_default(unique)
    ]
    interface IVMRImagePresenter : IUnknown
    {
        HRESULT StartPresenting();

        HRESULT StopPresenting();

        HRESULT PresentImage(
            [in] LPDIRECTDRAWSURFACE7 lpSurf,
            [in] DWORD dwFlags
        );
    };

//=====================================================================
//=====================================================================
//
// IImageSyncStepComplete
//
//=====================================================================
//=====================================================================
    [
        object,
        uuid(1DBCA562-5C92-474a-A276-382079164970),

        helpstring("IImageSyncStepComplete Interface"),
        pointer_default(unique)
    ]
    interface IImageSyncStepComplete : IUnknown
    {
        HRESULT StepComplete(
            [in] BOOL fCancelled
        );
    };


typedef enum {
        ImageSync_State_Stopped,
        ImageSync_State_Cued,
        ImageSync_State_Playing
} ImageSequenceState;

//=====================================================================
//=====================================================================
//
// IImageSyncControl
//
//=====================================================================
//=====================================================================
    [
        object,
        uuid(A67F6A0D-883B-44ce-AA93-87BA3017E19C),

        helpstring("IImageSyncControl Interface"),
        pointer_default(unique)
    ]
    interface IImageSyncControl : IUnknown
    {
        // ============================================================
        // Synchronisation control
        // ============================================================

        HRESULT SetImagePresenter(
            [in] IVMRImagePresenter* lpImagePresenter
        );

        HRESULT SetReferenceClock(
            [in] IReferenceClock* lpRefClock
        );


        // ============================================================
        // Image sequence control
        // ============================================================

        HRESULT CueImageSequence(
        );

        HRESULT BeginImageSequence(
            [in] REFERENCE_TIME* baseTime
        );

        HRESULT EndImageSequence(
        );

        HRESULT GetImageSequenceState(
                [in] DWORD dwMSecsTimeOut,
                [out] DWORD* lpdwState
        );


        // ============================================================
        // Frame stepping
        // ============================================================

        HRESULT FrameStep(
            [in] IImageSyncStepComplete* lpStepComplete,
            [in] DWORD nFramesToStep,
            [in] DWORD dwStepFlags
        );

        HRESULT CancelFrameStep(
        );
    };

typedef enum {
        ImageSync_Sample_SyncPoint       = 0x00000001,
        ImageSync_Sample_Preroll         = 0x00000002,
        ImageSync_Sample_Discontinuity   = 0x00000004,
        ImageSync_Sample_TimeValid       = 0x00000008,
        ImageSync_Sample_DontPresent     = 0x00000010
} SampleFlags;

//=====================================================================
//=====================================================================
//
// IImageSync
//
//=====================================================================
//=====================================================================
    [
        object,
        uuid(56a86897-0ad4-11ce-b03a-0020af0ba770),

        helpstring("IImageSync Interface"),
        pointer_default(unique)
    ]
    interface IImageSync : IUnknown
    {
        // return the buffer to the renderer along with time stamps relating to
        // when the buffer should be presented.
        HRESULT Receive(
            [in] REFERENCE_TIME  startTime,     // sample start time
            [in] REFERENCE_TIME  endTime,       // sample end time
            [in] DWORD_PTR lpSurf,    // sample
            [in] DWORD dwSampleFlags            // flags relating to the sample
        );

        // ask for quality control information from the renderer
        HRESULT GetQualityControlMessage(
            [out] Quality* pQualityMsg          // where your cookie goes
        );
    };


//=====================================================================
//=====================================================================
//
// ImageSynchronization Class
//
//=====================================================================
//=====================================================================
[
	uuid(A4A309B1-F733-4646-A127-C95F98CB144B),
	version(1.0),
	helpstring("ImageSynchronization 1.0 Type Library")
]
library IMAGESYNCHRONIZATIONlib
{
	importlib("stdole2.tlb");

	[
		uuid(7D8AA343-6E63-4663-BE90-6B80F66540A3),
		helpstring("ImageSynchronization Class")
	]
	coclass ImageSynchronization
	{
		[default] interface IImageSyncControl;
	};
};