/*****************************************************************************
 * sdi_declink.c: SDI Blackmagic Declink cards
 *****************************************************************************
 * Copyright (C) 2010 M2X BV
 * $Id: 65fdcc50113a80bf5a02d14f310cda54c8f0d414 $
 *
 * Authors: Jean-Paul Saman <jpsaman@videolan.org>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_demux.h>

#include "sdi_declink.h"

/*****************************************************************************
 * declink_Open:
 *****************************************************************************/
static int declink_Open(vlc_object_t *p_this)
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;

#ifdef WIN32
    p_sys->deckLinkIterator = NULL;
    HRESULT hr = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
                              IID_IDeckLinkIterator, (void**)&deckLinkIterator);
    if (SUCCEEDED(hr))
    {
        return VLC_SUCCESS;
    }
    return VLC_EGENERIC;
#else
    p_sys->deckLinkIterator = CreateDeckLinkIteratorInstance();
    if (p_sys->deckLinkIterator == NULL)
        return VLC_EGENERIC;
#endif

    return VLC_SUCCESS;
}

/*****************************************************************************
 * declink_Close:
 *****************************************************************************/
static void declink_Close( vlc_object_t *p_this )
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;

#ifdef WIN32
    p_sys->deckLinkIterator->Release();
#elif defined(HAVE_LINUX) || defined(__APPLE__)
    DestroyDeckLinkIteratorInstance(p_sys->deckLinkIterator);
#endif
    return VLC_SUCCESS;
}

/*****************************************************************************
 * declink_Demux:
 *****************************************************************************/
static int declink_Demux(demux_t *p_demux)
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;

    return VLC_SUCCESS;
}

/*****************************************************************************
 * declink_Control:
 *****************************************************************************/
static int declink_Control(demux_t *p_demux, int i_query, va_list args)
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;

    return VLC_SUCCESS;
}

/*****************************************************************************
 * Other:
 *****************************************************************************/
