/* 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_MPEGVSHDETECTIONNODE_HPP
#define NMM_MPEGVSHDETECTIONNODE_HPP NMM_MPEGVSHDETECTIONNODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericMuxDemuxNode.hpp"

#include <inttypes.h>

namespace NMM{

  class MPEGVSHDetectionNode : public GenericMuxDemuxNode
  {
    
  public:
	
    /** Constructor
     */
    MPEGVSHDetectionNode(const char* = "MPEGVSHDetectionNode", const StreamQueue::Mode queue_mode = StreamQueue::DEFAULT_MODE, const int queue_size = 10);
	
    /** Destructor
     */
    ~MPEGVSHDetectionNode();
	

  protected:
    virtual Message* processBuffer(Buffer*);
    Result doInit();
    Result doInitOutput();
    virtual Result doDeactivate();
      
  private:

    bool        has_seen_first_vsh;

    /* Pointer to current position of stream data */
    uint8_t*    buf;
    int         cur_inbuffer_length;

    /* Pointer to the begin of the stream data */
    uint8_t*    tmpbuffer;
    int         inbuffer_size;

    /* Pointer to the end of the stream data */
    uint8_t*    end;

    /* The rest of the inbuffer. This rest and the beginning of a new inbuffer could be perhaps a VSH */
    uint8_t*    rest_buffer;
    int         rest_buffer_length;

    /* If we found a VSH we create a new outgoing buffer with the VSH at the beginning */
    Time        vsh_ts;
    Buffer*     out;

    bool        searchVSH();
    bool        isVideoSequenceHeader(unsigned int);
    bool        has_audio;
    bool        has_video;

  };
    
}
#include "nmm/nmm_suffix.hpp"

#endif
