/* 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.
 *
 */

/*
 * Code is based on a52dec package that is
 * Copyrighted 2000-2001 by Michel Lespinasse <walken@zoy.org>
 * and copyrighted 1999-2000 by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 */

#ifndef NMM_AC3PARSENODE_HPP
#define NMM_AC3PARSENODE_HPP NMM_AC3PARSENODE_HPP

#include <inttypes.h>
#include "nmm/multimedia/GenericProcessorNode.hpp"

extern "C" {
  #include <a52dec/a52.h>
}

namespace NMM {
  
  class AC3ParseNode :
    public GenericProcessorNode
  {
  private:
    /**
     * liba52 uses a internal state machine, this variable is part of
     * most liba52 function calls.
     */
    a52_state_t* a52_state;
    
    /* buffer to hold temporary data */
    uint8_t   buf[3840];
    uint8_t*  bufptr;
    uint8_t*  bufpos;
    
    /* pointer to start and end position of input buffer */
    uint8_t* buffer_start;
    uint8_t* buffer_end;
    
    /* number of audio channels */
    int channels;
    
    /* here the samplerate of the ac3 stream can be found */
    int sample_rate;

    /* Bit rate of ac3 stream */
    int bit_rate;

    /* special flags that some liba52 function calls need */
    int flags;
    
  public:
    AC3ParseNode( const char * = "AC3ParseNode", StreamQueue::Mode = StreamQueue::MODE_SUSPEND, int = 20);
    ~AC3ParseNode();
    
    Message* processBuffer( Buffer *in_buffer);
    
  protected:
    virtual Result doInit();
    virtual Result doInitOutput();
    virtual Result doFlush();
  };
  
}

#endif //NMM_AC3PARSENODE_HPP



