/*  This file is part of the KDE project
    Copyright (C) 2006-2007 Tim Beaulen <tbscope@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "mediaobjectdecoder.h"

#include "qbtgstreamer/coreplugins/qbtgstreamertypefindelement.h"

#include "backend.h"

#include <QString>
#include <QTime>

namespace Phonon
{
namespace GStreamer
{

MediaObjectDecoder::MediaObjectDecoder(Backend *backend, QbtGStreamerElement *sourceElement, QbtGStreamerBin *mediaObjectBin)
{
    m_backend = backend;

    QString mediaObjectDecoderName = "MediaObjectDecoder_" + QTime::currentTime().toString("hhmmss");
    setObjectName(mediaObjectDecoderName);

    QString typefindName = "TypeFind_" + QTime::currentTime().toString("hhmmss");
    m_typefindElement = new QbtGStreamerTypeFindElement();
    m_typefindElement->setName(typefindName);

    if (!m_typefindElement) {
        m_backend->debugmessage(2, 0, objectName(), "FATAL! Could not create a type find element!");
        return;
    }

    if (!mediaObjectBin->addElement(m_typefindElement)) {
        m_backend->debugmessage(2, 0, objectName(), "FATAL! Could not add the type find element to the media object bin!");
        return;
    }

    sourceElement->link(m_typefindElement);

    connect(m_typefindElement, SIGNAL(haveType(QbtGStreamerTypeFindElement *, uint, QbtGStreamerCapabilities *, QbtGStreamerDataPointer *)), this, SLOT(slotHaveType(QbtGStreamerTypeFindElement *, uint, QbtGStreamerCapabilities *, QbtGStreamerDataPointer *)));

    m_backend->debugmessage(0, 0, objectName(), "Created");
}

MediaObjectDecoder::~MediaObjectDecoder()
{
    delete m_typefindElement;
}

void MediaObjectDecoder::slotHaveType(QbtGStreamerTypeFindElement *element, uint probability, QbtGStreamerCapabilities *caps, QbtGStreamerDataPointer *data)
{
    Q_UNUSED(data)
    
    m_backend->debugmessage(0, 4, objectName(), "Detected media type " + caps->toString() + " (probability " + probability + "%)");

    /*QbtGStreamerPad *pad;

    pad = element->pad("src");
    tryToPlug(pad, caps);

    delete pad;*/
} 

}} // Phonon::GStreamer


#include "mediaobjectdecoder.moc"

