/* 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_GENERIC_BUFFERED_SYNC_SINK_NODE_HPP_
#define _NMM_GENERIC_BUFFERED_SYNC_SINK_NODE_HPP_

#include "nmm/nmm_prefix.hpp"

#include "GenericSyncSinkNode.hpp"
#include "visibility.hpp"

namespace NMM {

   /** A generic buffered synchronized sink node.
   * This is the base class of all node classes which represent buffered sink nodes with synchronization support.
   * A buffered sink node represents a presentation sink which buffers data before the actual presentation.
   * A typical examples are audio sinks.
   *
   * A synchronized sink node has a sink controller which performs intra-stream synchronization and may be
   * connected to a synchronizer that performs intra-stream synchronization with other sink 
   * The plug-in interface of this class models a device buffer typical for audio devices. The buffer is linear,
   * i.e. data once written will be played at most once (i.e. it is not a ring buffer). The interface provides
   * methods for writing data to the device, starting playback and getting the amount of data currently buffered.
   * Note that there is no method to stop the device, only for flushing the device. If the device is flushed,
   * playback stops immediately, and all remaining written data will never be played.
   * If the device is playing, all played back data is removed from the bufer. If the buffer becomes empty
   * while the device is playing, an underrun occurs. Plug-ins derived from this class must implement this
   * interface.
   */
  class DLLEXPORT GenericBSyncSinkNode : public GenericSyncSinkNode {
  public:
    /** Create a buffered synchronized sink node.
     *
     * @param name Name of the node
     * @param queue_mode Initial queue mode for all input queues
     * @param size Initial maximum queue size for all input queues
     */
    GenericBSyncSinkNode(const char* name,
                         const StreamQueue::Mode queue_mode = StreamQueue::DEFAULT_MODE,
                         const int size = StreamQueue::DEFAULT_SIZE);

    /** Virtual destructor.
     */
    virtual ~GenericBSyncSinkNode();
    
    /** Check if this sink is a buffered sink.
     * Typically, audio sinks are buffered sinks, and video sinks are unbuffered sinks.
     *
     * @return @c true if the sink is buffered, @c false if the sink is unbuffered
     */
    virtual nmm_bool isBuffered() const {
      return true;
    }

    /** @name Plugin-specific Methods
     */
    //@{
    /** Get output delay.
     * This method gets the interval that is still buffered in the audio device
     * internally. It is the delay in device time after which audio data is audible
     * if it is written at the current system time.
     *
     * The output delay increases when data is written to the device.
     * The output delay decreases over time during playback.
     *
     * This method is plug-in specific and must be implemented in a subclass.
     *
     * @return Current output delay
     */
    virtual Interval getOutputDelay()
    {
      DEBUG_STREAM2("GenericBSyncSinkNode::getOutputDelay" << endl);
      return 0;
    };
    //@}
  };
}

#include "nmm/nmm_suffix.hpp"

#endif // _NMM_GENERIC_BUFFERED_SYNC_SINK_NODE_HPP_
