/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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 NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_MPEGAUDIOENCODENODE_HPP
#define NMM_MPEGAUDIOENCODENODE_HPP NMM_MPEGAUDIOENCODENODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericProcessorNode.hpp"

#include "nmm/multimedia/interfaces/ITrackImpl.hpp"
#include "nmm/plugins/interfaces/IEncodeImpl.hpp"
#include "nmm/plugins/interfaces/ITagInfoImpl.hpp"

#include <string>

#include <lame/lame.h>

namespace NMM {

  class MPEGAudioEncodeNode :
    public GenericProcessorNode,
    public ITrackImpl,
    public IEncodeImpl,
    public ITagInfoImpl
  {
  public:
    MPEGAudioEncodeNode(const char* name = "MPEGAudioEncodeNode",
                        const StreamQueue::Mode queue_mode = StreamQueue::MODE_SUSPEND,
                        const int queue_size = StreamQueue::DEFAULT_SIZE);

    ~MPEGAudioEncodeNode();

  protected:
    virtual Result doInit();
    virtual Result doDeinit();
    virtual Result doInitOutput();
    virtual Result doDeinitOutput();
    virtual Result doActivate();
    virtual Result doDeactivate();

    virtual Message* processBuffer(Buffer *in_buffer); 

    virtual Result started(const Interval& overall_duration);
    virtual Result startTrack(const string& filename);
    virtual Result endTrack();
    virtual Result finished();

    virtual Result TagInfo(const string& title, const string& album, const string& _artist, const string& _year, const string& _genre);

    /**
     * IEncode interface.
     * The bitrate parameter is not used.
     * The valid range for the quality is [0...9] (integer).
     */
    virtual void setQuality(const nmm_float& q);
    virtual nmm_float getQuality();
    virtual void setBitrate(const nmm_int32& i);
    virtual nmm_int32 getBitrate();

  private:
    ThreadMutex mae_mutex;

    const int audio_codec;

    string filename;
    string year;
    string genre;
    string artist;
    string title;
    string album;

    enum EVENTSTATE { START, DATA, END, FINISHED, TEST };
    EVENTSTATE event;

    lame_global_flags *gfp;

    bool encoding;
    int channels;
    uint lame_quality;

  };

}

#include "nmm/nmm_suffix.hpp"

#endif
