/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008 The gstreamermm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gstreamermm/clock.h>
#include <gstreamermm/format.h>

_DEFS(gstreamermm,gst)

namespace Gst
{

_WRAP_ENUM(SeekFlags, GstSeekFlags)
_WRAP_ENUM(SeekType, GstSeekType)

/** A class that describes the configured region of interest in a media file.
 * This helper structure holds the relevant values for tracking the region of
 * interest in a media file, called a segment.
 *
 * The structure can be used for two purposes:
 * 
 *  - performing seeks (handling seek events)
 *  - tracking playback regions (handling newsegment events)
 *
 * The segment is usually configured by the application with a seek event which
 * is propagated upstream and eventually handled by an element that performs
 * the seek.
 *
 * The configured segment is then propagated back downstream with a newsegment
 * event. This information is then used to clip media to the segment
 * boundaries.
 *
 * A segment structure is initialized with init(), which takes a Format that
 * will be used as the format of the segment values. The segment will be
 * configured with a start value of 0 and a stop/duration of -1, which is
 * undefined. The default rate and applied_rate is 1.0.
 *
 * The current position in the segment should be set with the set_last_stop().
 * The public last_stop field contains the last set stop position in the
 * segment.
 *
 * For elements that perform seeks, the current segment should be updated with
 * the set_seek() and the values from the seek event. This method will update
 * all the segment fields. The last_stop field will contain the new playback
 * position. If the cur_type was different from Gst::SEEK_TYPE_NONE, playback
 * continues from the last_stop position, possibly with updated flags or rate.
 *
 * For elements that want to synchronize to the pipeline clock,
 * to_running_time() can be used to convert a timestamp to a value that can be
 * used to synchronize to the clock. This function takes into account all
 * accumulated segments as well as any rate or applied_rate conversions.
 *
 * For elements that need to perform operations on media data in stream_time,
 * to_stream_time() can be used to convert a timestamp and the segment info to
 * stream time (which is always between 0 and the duration of the stream).
 *
 * Last reviewed on 2007-05-17 (0.10.13)
 */
class Segment
{
  _CLASS_BOXEDTYPE(Segment, GstSegment, gst_segment_new, gst_segment_copy, gst_segment_free)
  _IGNORE(gst_segment_free, gst_segment_copy)

public:
  _WRAP_METHOD(bool clip(Format format, guint64 start, guint64 stop, guint64& clip_start, guint64& clip_stop) const, gst_segment_clip)
  _WRAP_METHOD(void init(Format format), gst_segment_init)
  _WRAP_METHOD_DOCS_ONLY(gst_segment_do_seek)
  void set_seek(double rate, Format format, SeekFlags flags, SeekType start_type, gint64 start, SeekType stop_type, gint64 stop, bool& update);
  _WRAP_METHOD(guint64 to_running_time(Format format, guint64 position) const, gst_segment_to_running_time)
  _WRAP_METHOD(guint64 to_stream_time(Format format, guint64 position) const, gst_segment_to_stream_time)
  _WRAP_METHOD(guint64 to_position(Format format, guint64 running_time) const, gst_segment_to_position)
  _WRAP_METHOD(bool set_running_time(Format format, guint64 running_time), gst_segment_set_running_time)
};

} //namespace Gst
