/* 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_TIMEDBUFFERDROPNODE_HPP_
#define _NMM_TIMEDBUFFERDROPNODE_HPP_

#include "nmm/plugins/general/IBufferDropImpl.hpp"
#include "nmm/multimedia/GenericFilterNode.hpp"

namespace NMM {

  /**
   * \class TimedBufferDropNode
   */
  class TimedBufferDropNode :
    public GenericFilterNode,
    public ITimedBufferDropImpl
  {
  public:
    typedef pair<Timestamp, Timestamp> inout_point_t;
    typedef priority_queue< inout_point_t > inout_points_t;
  private:
    // for in/out dropping
    bool first_time;
    bool currently_dropping;
    bool relative_inout_points;
    Interval first_ts_interval; ///< first timestamp in data stream
    inout_points_t inout_points; ///< queue of all inout points
    bool sent_endtrack_event;

  protected:
    /**
     * Adds an in and out point for removing timestamped buffers froms stream
     */
    virtual void addInOutPoint(const nmm_uint32& in_secs, const nmm_uint32& in_millisecs, const nmm_uint32& out_secs, const nmm_uint32& out_millisecs);

    /**
     * If true, all inout-points have to be specified relative to first timestamp in stream
     */
    virtual void useRelativeInOutPoints(const nmm_bool& relative);

    /**
     * Gets the status of relative or absolute inout-points
     */
    virtual nmm_bool isRelativeInOutPoints();

    /**
     * Here all formats are specified.
     */
    virtual Result doInit();
    
    /**
     * Here all output streams are added.
     */
    virtual Result doInitOutput();

    /**
     * The processBuffer method from superclass
     */
    virtual Message *processBuffer (Buffer *in);

  public:

    /**
     * The main constructor.
     */
    TimedBufferDropNode(const char *name = "TimedBufferDropNode", StreamQueue::Mode = StreamQueue::MODE_SUSPEND, int qsize = 5);
  };

  // an inout_point A is smaller than B, if the timestamp of the in-point A is bigger
  inline bool operator<(const TimedBufferDropNode::inout_point_t& a, const  TimedBufferDropNode::inout_point_t& b)
  {
    return !(a.first < b.first);
  };

}

#endif //_NMM_VIDEO_FILTER_OVERLAYNODE_HPP_



