/* 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_BUFFERED_SINK_CONTROLLER_HPP_
#define _NMM_BUFFERED_SINK_CONTROLLER_HPP_

#include "nmm/nmm_prefix.hpp"

#include "SinkController.hpp"

namespace NMM {

  class AudioVideoSynchronizer;
  class GenericBSyncSinkNode;

  /** Buffered sink controller.
   *  In addition to the isBufferValid - method from controller, a 
   *  sinkcontroller has a waitToPresent - method which allows it to
   *  tell the sink node how long it should wait before presenting the 
   *  next buffer.
   */
  class BSinkController : public SinkController {
  private:
    GenericBSyncSinkNode* node; ///< The synchronized node

  public:
    /** Create a controller.
     *
     * @param mode Initial mode of the controller
     */
    BSinkController(const IController::Mode mode);

    /** Create a controller for a node.
     *
     * @param parent The synchronized node to which this controller belongs
     * @param mode Initial mode of the controller
     */
    BSinkController(GenericBSyncSinkNode* parent = 0, 
		    const IController::Mode mode = Controller::DEFAULT_MODE);

    /** Virtual destructor.
     */
    virtual ~BSinkController();

    /** Check if a timestamp is valid.
     * If the controller is in ONLINE mode, this method is called to determine if a
     * buffer with given timestamp can be presented in time. In this case, the buffer is "valid",
     * otherwise it is "invalid".
     * The implementation must be provided by a subclass.
     *
     * @param timestamp The timestamp of the buffer to check.
     * @return @c true if the buffer is valid, @c false if the buffer is invalid
     */
    virtual bool checkBufferValid(const Timestamp timestamp);

    /** Determine the time to wait for presenting a buffer.
     * This method determines and returns the amount of time that the node should wait before presenting
     * the buffer.
     * If the waiting interval would be smaller than the minimum waiting interval, this method returns zero.
     * The waiting interval is capped by the maximum waiting interval.
     *
     * @param timestamp Buffer timestamp
     * @return Time to wait for presenting this buffer
     */
    Interval waitToPresent(const Timestamp timestamp); 

  };

}

#include "nmm/nmm_suffix.hpp"

#endif // _NMM_BUFFERED_SINK_CONTROLLER_HPP_
