/* -LICENSE-START-
** Copyright (c) 2009 Blackmagic Design
**
** Permission is hereby granted, free of charge, to any person or organization
** obtaining a copy of the software and accompanying documentation covered by
** this license (the "Software") to use, reproduce, display, distribute,
** execute, and transmit the Software, and to prepare derivative works of the
** Software, and to permit third-parties to whom the Software is furnished to
** do so, all subject to the following:
** 
** The copyright notices in the Software and this entire statement, including
** the above license grant, this restriction and the following disclaimer,
** must be included in all copies of the Software, in whole or in part, and
** all derivative works of the Software, unless such copies or derivative
** works are solely in the form of machine-executable object code generated by
** a source language processor.
** 
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
** -LICENSE-END-
*/

/* Enum BMDVideoConnection - Video connection types */

typedef [v1_enum] enum  _BMDVideoConnection_v7_6 {
    bmdVideoConnectionSDI_v7_6                              = /* 'sdi ' */ 0x73646920,
    bmdVideoConnectionHDMI_v7_6                             = /* 'hdmi' */ 0x68646D69,
    bmdVideoConnectionOpticalSDI_v7_6                       = /* 'opti' */ 0x6F707469,
    bmdVideoConnectionComponent_v7_6                        = /* 'cpnt' */ 0x63706E74,
    bmdVideoConnectionComposite_v7_6                        = /* 'cmst' */ 0x636D7374,
    bmdVideoConnectionSVideo_v7_6                           = /* 'svid' */ 0x73766964
} BMDVideoConnection_v7_6;



/* Forward Declarations */

interface IDeckLinkDisplayModeIterator_v7_6;
interface IDeckLinkDisplayMode_v7_6;
interface IDeckLinkOutput_v7_6;
interface IDeckLinkInput_v7_6;
interface IDeckLinkTimecode_v7_6;
interface IDeckLinkVideoFrame_v7_6;
interface IDeckLinkMutableVideoFrame_v7_6;
interface IDeckLinkVideoInputFrame_v7_6;
interface IDeckLinkScreenPreviewCallback_v7_6;
interface IDeckLinkGLScreenPreviewHelper_v7_6;
interface IDeckLinkVideoConversion_v7_6;
interface IDeckLinkConfiguration_v7_6;


/* Interface IDeckLinkVideoOutputCallback - Frame completion callback. */

[
    object,
    uuid(E763A626-4A3C-49D1-BF13-E7AD3692AE52),
    helpstring("Frame completion callback.")
] interface IDeckLinkVideoOutputCallback_v7_6 : IUnknown
{
    HRESULT ScheduledFrameCompleted([in] IDeckLinkVideoFrame_v7_6 *completedFrame, [in] BMDOutputFrameCompletionResult result);
    HRESULT ScheduledPlaybackHasStopped(void);
};


/* Interface IDeckLinkInputCallback - Frame arrival callback. */

[
    object,
    uuid(31D28EE7-88B6-4CB1-897A-CDBF79A26414),
    helpstring("Frame arrival callback.")
] interface IDeckLinkInputCallback_v7_6 : IUnknown
{
    HRESULT VideoInputFormatChanged([in] BMDVideoInputFormatChangedEvents notificationEvents, [in] IDeckLinkDisplayMode_v7_6 *newDisplayMode, [in] BMDDetectedVideoInputFormatFlags detectedSignalFlags);
    HRESULT VideoInputFrameArrived([in] IDeckLinkVideoInputFrame_v7_6* videoFrame, [in] IDeckLinkAudioInputPacket* audioPacket);
};


/* Interface IDeckLinkDisplayModeIterator - enumerates over supported input/output display modes. */

[
    object,
    uuid(455D741F-1779-4800-86F5-0B5D13D79751),
    helpstring("enumerates over supported input/output display modes.")
] interface IDeckLinkDisplayModeIterator_v7_6 : IUnknown
{
    HRESULT Next([out] IDeckLinkDisplayMode_v7_6 **deckLinkDisplayMode);
};


/* Interface IDeckLinkDisplayMode - represents a display mode */

[
    object,
    uuid(87451E84-2B7E-439E-A629-4393EA4A8550),
    helpstring("represents a display mode")
] interface IDeckLinkDisplayMode_v7_6 : IUnknown
{
    HRESULT GetName([out] BSTR *name);
    BMDDisplayMode GetDisplayMode(void);
    long GetWidth(void);
    long GetHeight(void);
    HRESULT GetFrameRate([out] BMDTimeValue *frameDuration, [out] BMDTimeScale *timeScale);
    BMDFieldDominance GetFieldDominance(void);
};


/* Interface IDeckLinkOutput - Created by QueryInterface from IDeckLink. */

[
    object,
    uuid(29228142-EB8C-4141-A621-F74026450955),
    local, 
    helpstring("Created by QueryInterface from IDeckLink.")
] interface IDeckLinkOutput_v7_6 : IUnknown
{
    HRESULT DoesSupportVideoMode(BMDDisplayMode displayMode, BMDPixelFormat pixelFormat, [out] BMDDisplayModeSupport *result);
    HRESULT GetDisplayModeIterator([out] IDeckLinkDisplayModeIterator_v7_6 **iterator);

    HRESULT SetScreenPreviewCallback([in] IDeckLinkScreenPreviewCallback_v7_6 *previewCallback);

    /* Video Output */

    HRESULT EnableVideoOutput(BMDDisplayMode displayMode, BMDVideoOutputFlags flags);
    HRESULT DisableVideoOutput(void);

    HRESULT SetVideoOutputFrameMemoryAllocator([in] IDeckLinkMemoryAllocator *theAllocator);
    HRESULT CreateVideoFrame(long width, long height, long rowBytes, BMDPixelFormat pixelFormat, BMDFrameFlags flags, [out] IDeckLinkMutableVideoFrame_v7_6 **outFrame);
    HRESULT CreateAncillaryData(BMDPixelFormat pixelFormat, [out] IDeckLinkVideoFrameAncillary **outBuffer);

    HRESULT DisplayVideoFrameSync([in] IDeckLinkVideoFrame_v7_6 *theFrame);
    HRESULT ScheduleVideoFrame([in] IDeckLinkVideoFrame_v7_6 *theFrame, BMDTimeValue displayTime, BMDTimeValue displayDuration, BMDTimeScale timeScale);
    HRESULT SetScheduledFrameCompletionCallback([in] IDeckLinkVideoOutputCallback_v7_6 *theCallback);
    HRESULT GetBufferedVideoFrameCount([out] unsigned long *bufferedFrameCount);

    /* Audio Output */

    HRESULT EnableAudioOutput(BMDAudioSampleRate sampleRate, BMDAudioSampleType sampleType, unsigned long channelCount, BMDAudioOutputStreamType streamType);
    HRESULT DisableAudioOutput(void);

    HRESULT WriteAudioSamplesSync([in] void *buffer, unsigned long sampleFrameCount, [out] unsigned long *sampleFramesWritten);

    HRESULT BeginAudioPreroll(void);
    HRESULT EndAudioPreroll(void);
    HRESULT ScheduleAudioSamples([in] void *buffer, unsigned long sampleFrameCount, BMDTimeValue streamTime, BMDTimeScale timeScale, [out] unsigned long *sampleFramesWritten);

    HRESULT GetBufferedAudioSampleFrameCount([out] unsigned long *bufferedSampleFrameCount);
    HRESULT FlushBufferedAudioSamples(void);

    HRESULT SetAudioCallback([in] IDeckLinkAudioOutputCallback *theCallback);

    /* Output Control */

    HRESULT StartScheduledPlayback(BMDTimeValue playbackStartTime, BMDTimeScale timeScale, double playbackSpeed);
    HRESULT StopScheduledPlayback(BMDTimeValue stopPlaybackAtTime, [out] BMDTimeValue *actualStopTime, BMDTimeScale timeScale);
    HRESULT IsScheduledPlaybackRunning([out] BOOL *active);
    HRESULT GetScheduledStreamTime(BMDTimeScale desiredTimeScale, [out] BMDTimeValue *streamTime, [out] double *playbackSpeed);

    /* Hardware Timing */

    HRESULT GetHardwareReferenceClock(BMDTimeScale desiredTimeScale, [out] BMDTimeValue *hardwareTime, [out] BMDTimeValue *timeInFrame, [out] BMDTimeValue *ticksPerFrame);
};


/* Interface IDeckLinkInput - Created by QueryInterface from IDeckLink. */

[
    object,
    uuid(300C135A-9F43-48E2-9906-6D7911D93CF1),
    helpstring("Created by QueryInterface from IDeckLink.")
] interface IDeckLinkInput_v7_6 : IUnknown
{
    HRESULT DoesSupportVideoMode(BMDDisplayMode displayMode, BMDPixelFormat pixelFormat, [out] BMDDisplayModeSupport *result);
    HRESULT GetDisplayModeIterator([out] IDeckLinkDisplayModeIterator_v7_6 **iterator);

    HRESULT SetScreenPreviewCallback([in] IDeckLinkScreenPreviewCallback_v7_6 *previewCallback);

    /* Video Input */

    HRESULT EnableVideoInput(BMDDisplayMode displayMode, BMDPixelFormat pixelFormat, BMDVideoInputFlags flags);
    HRESULT DisableVideoInput(void);
    HRESULT GetAvailableVideoFrameCount([out] unsigned long *availableFrameCount);

    /* Audio Input */

    HRESULT EnableAudioInput(BMDAudioSampleRate sampleRate, BMDAudioSampleType sampleType, unsigned long channelCount);
    HRESULT DisableAudioInput(void);
    HRESULT GetAvailableAudioSampleFrameCount([out] unsigned long *availableSampleFrameCount);

    /* Input Control */

    HRESULT StartStreams(void);
    HRESULT StopStreams(void);
    HRESULT PauseStreams(void);
    HRESULT FlushStreams(void);
    HRESULT SetCallback([in] IDeckLinkInputCallback_v7_6 *theCallback);

    /* Hardware Timing */

    HRESULT GetHardwareReferenceClock(BMDTimeScale desiredTimeScale, [out] BMDTimeValue *hardwareTime, [out] BMDTimeValue *timeInFrame, [out] BMDTimeValue *ticksPerFrame);
};


/* Interface IDeckLinkTimecode_v7_6 - Used for video frame timecode representation. */

[
    object,
    uuid(EFB9BCA6-A521-44F7-BD69-2332F24D9EE6),
    helpstring("Used for video frame timecode representation.")
] interface IDeckLinkTimecode_v7_6 : IUnknown
{
    BMDTimecodeBCD GetBCD(void);
    HRESULT GetComponents([out] unsigned char *hours, [out] unsigned char *minutes, [out] unsigned char *seconds, [out] unsigned char *frames);
    HRESULT GetString([out] BSTR *timecode);
    BMDTimecodeFlags GetFlags(void);
};


/* Interface IDeckLinkVideoFrame - Interface to encapsulate a video frame; can be caller-implemented. */

[
    object,
    uuid(A8D8238E-6B18-4196-99E1-5AF717B83D32),
    local, 
    helpstring("Interface to encapsulate a video frame; can be caller-implemented.")
] interface IDeckLinkVideoFrame_v7_6 : IUnknown
{
    long GetWidth(void);
    long GetHeight(void);
    long GetRowBytes(void);
    BMDPixelFormat GetPixelFormat(void);
    BMDFrameFlags GetFlags(void);
    HRESULT GetBytes([out] void **buffer);

    HRESULT GetTimecode(BMDTimecodeFormat format, [out] IDeckLinkTimecode_v7_6 **timecode);
    HRESULT GetAncillaryData([out] IDeckLinkVideoFrameAncillary **ancillary);
};


/* Interface IDeckLinkMutableVideoFrame - Created by IDeckLinkOutput::CreateVideoFrame. */

[
    object,
    uuid(46FCEE00-B4E6-43D0-91C0-023A7FCEB34F),
    local, 
    helpstring("Created by IDeckLinkOutput::CreateVideoFrame.")
] interface IDeckLinkMutableVideoFrame_v7_6 : IDeckLinkVideoFrame_v7_6
{
    HRESULT SetFlags(BMDFrameFlags newFlags);

    HRESULT SetTimecode(BMDTimecodeFormat format, [in] IDeckLinkTimecode_v7_6 *timecode);
    HRESULT SetTimecodeFromComponents(BMDTimecodeFormat format, unsigned char hours, unsigned char minutes, unsigned char seconds, unsigned char frames, BMDTimecodeFlags flags);
    HRESULT SetAncillaryData([in] IDeckLinkVideoFrameAncillary *ancillary);
};


/* Interface IDeckLinkVideoInputFrame - Provided by the IDeckLinkVideoInput frame arrival callback. */

[
    object,
    uuid(9A74FA41-AE9F-47AC-8CF4-01F42DD59965),
    local, 
    helpstring("Provided by the IDeckLinkVideoInput frame arrival callback.")
] interface IDeckLinkVideoInputFrame_v7_6 : IDeckLinkVideoFrame_v7_6
{
    HRESULT GetStreamTime([out] BMDTimeValue *frameTime, [out] BMDTimeValue *frameDuration, BMDTimeScale timeScale);
    HRESULT GetHardwareReferenceTimestamp(BMDTimeScale timeScale, [out] BMDTimeValue *frameTime, [out] BMDTimeValue *frameDuration);
};


/* Interface IDeckLinkScreenPreviewCallback - Screen preview callback */

[
    object,
    uuid(373F499D-4B4D-4518-AD22-6354E5A5825E),
    local, 
    helpstring("Screen preview callback")
] interface IDeckLinkScreenPreviewCallback_v7_6 : IUnknown
{
    HRESULT DrawFrame([in] IDeckLinkVideoFrame_v7_6 *theFrame);
};


/* Interface IDeckLinkGLScreenPreviewHelper - Created with CoCreateInstance(). */

[
    object,
    uuid(BA575CD9-A15E-497B-B2C2-F9AFE7BE4EBA),
    local, 
    helpstring("Created with CoCreateInstance().")
] interface IDeckLinkGLScreenPreviewHelper_v7_6 : IUnknown
{

    /* Methods must be called with OpenGL context set */

    HRESULT InitializeGL(void);
    HRESULT PaintGL(void);
    HRESULT SetFrame([in] IDeckLinkVideoFrame_v7_6 *theFrame);
};


/* Interface IDeckLinkVideoConversion - Created with CoCreateInstance(). */

[
    object,
    uuid(3EB504C9-F97D-40FE-A158-D407D48CB53B),
    local, 
    helpstring("Created with CoCreateInstance().")
] interface IDeckLinkVideoConversion_v7_6 : IUnknown
{
    HRESULT ConvertFrame([in] IDeckLinkVideoFrame_v7_6* srcFrame, [in] IDeckLinkVideoFrame_v7_6* dstFrame);
};

/* Interface IDeckLinkConfiguration_v7_6 - Created by QueryInterface from IDeckLink. */

[
    object,
    uuid(B8EAD569-B764-47F0-A73F-AE40DF6CBF10),
    helpstring("Created by QueryInterface from IDeckLink.")
] interface IDeckLinkConfiguration_v7_6 : IUnknown
{
    HRESULT GetConfigurationValidator([out] IDeckLinkConfiguration_v7_6 **configObject);
    HRESULT WriteConfigurationToPreferences(void);

    /* Video Output Configuration */

    HRESULT SetVideoOutputFormat([in] BMDVideoConnection_v7_6 videoOutputConnection);
    HRESULT IsVideoOutputActive([in] BMDVideoConnection_v7_6 videoOutputConnection, [out] BOOL *active);

    HRESULT SetAnalogVideoOutputFlags([in] BMDAnalogVideoFlags analogVideoFlags);
    HRESULT GetAnalogVideoOutputFlags([out] BMDAnalogVideoFlags *analogVideoFlags);

    HRESULT EnableFieldFlickerRemovalWhenPaused([in] BOOL enable);
    HRESULT IsEnabledFieldFlickerRemovalWhenPaused([out] BOOL *enabled);

    HRESULT Set444And3GBpsVideoOutput([in] BOOL enable444VideoOutput, [in] BOOL enable3GbsOutput);
    HRESULT Get444And3GBpsVideoOutput([out] BOOL *is444VideoOutputEnabled, [out] BOOL *threeGbsOutputEnabled);

    HRESULT SetVideoOutputConversionMode([in] BMDVideoOutputConversionMode conversionMode);
    HRESULT GetVideoOutputConversionMode([out] BMDVideoOutputConversionMode *conversionMode);

    HRESULT Set_HD1080p24_to_HD1080i5994_Conversion([in] BOOL enable);
    HRESULT Get_HD1080p24_to_HD1080i5994_Conversion([out] BOOL *enabled);

    /* Video Input Configuration */

    HRESULT SetVideoInputFormat([in] BMDVideoConnection_v7_6 videoInputFormat);
    HRESULT GetVideoInputFormat([out] BMDVideoConnection_v7_6 *videoInputFormat);

    HRESULT SetAnalogVideoInputFlags([in] BMDAnalogVideoFlags analogVideoFlags);
    HRESULT GetAnalogVideoInputFlags([out] BMDAnalogVideoFlags *analogVideoFlags);

    HRESULT SetVideoInputConversionMode([in] BMDVideoInputConversionMode conversionMode);
    HRESULT GetVideoInputConversionMode([out] BMDVideoInputConversionMode *conversionMode);

    HRESULT SetBlackVideoOutputDuringCapture([in] BOOL blackOutInCapture);
    HRESULT GetBlackVideoOutputDuringCapture([out] BOOL *blackOutInCapture);

    HRESULT Set32PulldownSequenceInitialTimecodeFrame([in] unsigned long aFrameTimecode);
    HRESULT Get32PulldownSequenceInitialTimecodeFrame([out] unsigned long *aFrameTimecode);

    HRESULT SetVancSourceLineMapping([in] unsigned long activeLine1VANCsource, [in] unsigned long activeLine2VANCsource, [in] unsigned long activeLine3VANCsource);
    HRESULT GetVancSourceLineMapping([out] unsigned long *activeLine1VANCsource, [out] unsigned long *activeLine2VANCsource, [out] unsigned long *activeLine3VANCsource);

    /* Audio Input Configuration */

    HRESULT SetAudioInputFormat([in] BMDAudioConnection audioInputFormat);
    HRESULT GetAudioInputFormat([out] BMDAudioConnection *audioInputFormat);
};



/* Coclasses */

importlib("stdole2.tlb");

[
    uuid(D398CEE7-4434-4CA3-9BA6-5AE34556B905),
    helpstring("CDeckLinkGLScreenPreviewHelper Class (DeckLink API v7.6)")
] coclass CDeckLinkGLScreenPreviewHelper_v7_6
{
    [default] interface IDeckLinkGLScreenPreviewHelper_v7_6;
};

[
    uuid(FFA84F77-73BE-4FB7-B03E-B5E44B9F759B),
    helpstring("CDeckLinkVideoConversion Class (DeckLink API v7.6)")
] coclass CDeckLinkVideoConversion_v7_6
{
    [default] interface IDeckLinkVideoConversion_v7_6;
};

