9d3a8d187568f0e7ff1be5ce41f347da35dfe363
[platform/upstream/gstreamer.git] / gst / gstsegment.h
1 /* GStreamer
2  * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3  *
4  * gstsegment.h: Header for GstSegment subsystem
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #ifndef __GST_SEGMENT_H__
24 #define __GST_SEGMENT_H__
25
26 #include <gst/gstformat.h>
27
28 G_BEGIN_DECLS
29
30 #define GST_TYPE_SEGMENT             (gst_segment_get_type())
31
32 typedef struct _GstSegment GstSegment;
33
34 /**
35  * GstSeekType:
36  * @GST_SEEK_TYPE_NONE: no change in position is required
37  * @GST_SEEK_TYPE_SET: absolute position is requested
38  * @GST_SEEK_TYPE_END: relative position to duration is requested
39  *
40  * The different types of seek events. When constructing a seek event with
41  * gst_event_new_seek() or when doing gst_segment_do_seek ().
42  */
43 typedef enum {
44   /* one of these */
45   GST_SEEK_TYPE_NONE            = 0,
46   GST_SEEK_TYPE_SET             = 1,
47   GST_SEEK_TYPE_END             = 2
48 } GstSeekType;
49
50 /**
51  * GstSeekFlags:
52  * @GST_SEEK_FLAG_NONE: no flag
53  * @GST_SEEK_FLAG_FLUSH: flush pipeline
54  * @GST_SEEK_FLAG_ACCURATE: accurate position is requested, this might
55  *                     be considerably slower for some formats.
56  * @GST_SEEK_FLAG_KEY_UNIT: seek to the nearest keyframe. This might be
57  *                     faster but less accurate.
58  * @GST_SEEK_FLAG_SEGMENT: perform a segment seek.
59  * @GST_SEEK_FLAG_SKIP: when doing fast foward or fast reverse playback, allow
60  *                     elements to skip frames instead of generating all
61  *                     frames. Since 0.10.22.
62  * @GST_SEEK_FLAG_SNAP_BEFORE: go to a location before the requested position,
63  *                     if KEY_UNIT this means the keyframe at or before the
64  *                     requested position the one at or before the seek target.
65  *                     Since 0.10.37.
66  * @GST_SEEK_FLAG_SNAP_AFTER: go to a location after the requested position,
67  *                     if KEY_UNIT this means the keyframe at of after the
68  *                     requested position. Since 0.10.37.
69  * @GST_SEEK_FLAG_SNAP_NEAREST: go to a position near the requested position,
70  *                     if KEY_UNIT this means the keyframe closest to the
71  *                     requested position, if both keyframes are at an equal
72  *                     distance, behaves like SNAP_BEFORE. Since 0.10.37.
73  *
74  * Flags to be used with gst_element_seek() or gst_event_new_seek(). All flags
75  * can be used together.
76  *
77  * A non flushing seek might take some time to perform as the currently
78  * playing data in the pipeline will not be cleared.
79  *
80  * An accurate seek might be slower for formats that don't have any indexes
81  * or timestamp markers in the stream. Specifying this flag might require a
82  * complete scan of the file in those cases.
83  *
84  * When performing a segment seek: after the playback of the segment completes,
85  * no EOS will be emmited by the element that performed the seek, but a
86  * #GST_MESSAGE_SEGMENT_DONE message will be posted on the bus by the element.
87  * When this message is posted, it is possible to send a new seek event to
88  * continue playback. With this seek method it is possible to perform seamless
89  * looping or simple linear editing.
90  *
91  * When doing fast forward (rate > 1.0) or fast reverse (rate < -1.0) trickmode
92  * playback, the @GST_SEEK_FLAG_SKIP flag can be used to instruct decoders
93  * and demuxers to adjust the playback rate by skipping frames. This can improve
94  * performance and decrease CPU usage because not all frames need to be decoded.
95  *
96  * The @GST_SEEK_FLAG_SNAP_BEFORE flag can be used to snap to the previous
97  * relevant location, and the @GST_SEEK_FLAG_SNAP_AFTER flag can be used to
98  * select the next relevant location. If KEY_UNIT is specified, the relevant
99  * location is a keyframe. If both flags are specified, the nearest of these
100  * locations will be selected. If none are specified, the implementation is
101  * free to select whichever it wants.
102  * The before and after here are in running time, so when playing backwards,
103  * the next location refers to the one that will played in next, and not the
104  * one that is located after in the actual source stream.
105  *
106  * Also see part-seeking.txt in the GStreamer design documentation for more
107  * details on the meaning of these flags and the behaviour expected of
108  * elements that handle them.
109  */
110 typedef enum {
111   GST_SEEK_FLAG_NONE            = 0,
112   GST_SEEK_FLAG_FLUSH           = (1 << 0),
113   GST_SEEK_FLAG_ACCURATE        = (1 << 1),
114   GST_SEEK_FLAG_KEY_UNIT        = (1 << 2),
115   GST_SEEK_FLAG_SEGMENT         = (1 << 3),
116   GST_SEEK_FLAG_SKIP            = (1 << 4),
117   GST_SEEK_FLAG_SNAP_BEFORE     = (1 << 5),
118   GST_SEEK_FLAG_SNAP_AFTER      = (1 << 6),
119   GST_SEEK_FLAG_SNAP_NEAREST    = GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER,
120   /* Careful to restart next flag with 1<<7 here */
121 } GstSeekFlags;
122
123 /**
124  * GstSegmentFlags:
125  * @GST_SEGMENT_FLAG_NONE: no flags
126  * @GST_SEGMENT_FLAG_RESET: reset the pipeline running_time to the segment
127  *                          running_time
128  * @GST_SEGMENT_FLAG_SKIP: perform skip playback
129  *
130  * Flags for the GstSegment structure. Currently mapped to the corresponding
131  * values of the seek flags.
132  */
133 typedef enum {
134   GST_SEGMENT_FLAG_NONE            = GST_SEEK_FLAG_NONE,
135   GST_SEGMENT_FLAG_RESET           = GST_SEEK_FLAG_FLUSH,
136   GST_SEGMENT_FLAG_SKIP            = GST_SEEK_FLAG_SKIP
137 } GstSegmentFlags;
138
139 /**
140  * GstSegment:
141  * @flags: flags for this segment
142  * @rate: the rate of the segment
143  * @applied_rate: the already applied rate to the segment
144  * @format: the format of the segment values
145  * @base: the base time of the segment
146  * @start: the start of the segment
147  * @stop: the stop of the segment
148  * @time: the stream time of the segment
149  * @position: the position in the segment
150  * @duration: the duration of the segment
151  *
152  * A helper structure that holds the configured region of
153  * interest in a media file.
154  */
155 struct _GstSegment {
156   /*< public >*/
157   GstSegmentFlags flags;
158
159   gdouble         rate;
160   gdouble         applied_rate;
161
162   GstFormat       format;
163   guint64         base;
164   guint64         start;
165   guint64         stop;
166   guint64         time;
167
168   guint64         position;
169   guint64         duration;
170
171   /* < private > */
172   gpointer        _gst_reserved[GST_PADDING];
173 };
174
175 GType        gst_segment_get_type            (void);
176
177 GstSegment * gst_segment_new                 (void) G_GNUC_MALLOC;
178 GstSegment * gst_segment_copy                (const GstSegment *segment) G_GNUC_MALLOC;
179 void         gst_segment_copy_into           (const GstSegment *src, GstSegment *dest);
180 void         gst_segment_free                (GstSegment *segment);
181
182 void         gst_segment_init                (GstSegment *segment, GstFormat format);
183
184 guint64      gst_segment_to_stream_time      (const GstSegment *segment, GstFormat format, guint64 position);
185 guint64      gst_segment_to_running_time     (const GstSegment *segment, GstFormat format, guint64 position);
186 guint64      gst_segment_to_position         (const GstSegment *segment, GstFormat format, guint64 running_time);
187
188 gboolean     gst_segment_set_running_time    (GstSegment *segment, GstFormat format, guint64 running_time);
189
190 gboolean     gst_segment_clip                (const GstSegment *segment, GstFormat format, guint64 start,
191                                               guint64 stop, guint64 *clip_start, guint64 *clip_stop);
192
193
194 gboolean     gst_segment_do_seek             (GstSegment * segment, gdouble rate,
195                                               GstFormat format, GstSeekFlags flags,
196                                               GstSeekType start_type, guint64 start,
197                                               GstSeekType stop_type, guint64 stop, gboolean * update);
198
199 G_END_DECLS
200
201 #endif /* __GST_SEGMENT_H__ */