gstsegment.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef __GST_SEGMENT_H__
  22. #define __GST_SEGMENT_H__
  23. #include <gst/gstformat.h>
  24. G_BEGIN_DECLS
  25. #define GST_TYPE_SEGMENT (gst_segment_get_type())
  26. typedef struct _GstSegment GstSegment;
  27. /**
  28. * GstSeekType:
  29. * @GST_SEEK_TYPE_NONE: no change in position is required
  30. * @GST_SEEK_TYPE_SET: absolute position is requested
  31. * @GST_SEEK_TYPE_END: relative position to duration is requested
  32. *
  33. * The different types of seek events. When constructing a seek event with
  34. * gst_event_new_seek() or when doing gst_segment_do_seek ().
  35. */
  36. typedef enum {
  37. /* one of these */
  38. GST_SEEK_TYPE_NONE = 0,
  39. GST_SEEK_TYPE_SET = 1,
  40. GST_SEEK_TYPE_END = 2
  41. } GstSeekType;
  42. /**
  43. * GstSeekFlags:
  44. * @GST_SEEK_FLAG_NONE: no flag
  45. * @GST_SEEK_FLAG_FLUSH: flush pipeline
  46. * @GST_SEEK_FLAG_ACCURATE: accurate position is requested, this might
  47. * be considerably slower for some formats.
  48. * @GST_SEEK_FLAG_KEY_UNIT: seek to the nearest keyframe. This might be
  49. * faster but less accurate.
  50. * @GST_SEEK_FLAG_SEGMENT: perform a segment seek.
  51. * @GST_SEEK_FLAG_TRICKMODE: when doing fast forward or fast reverse playback, allow
  52. * elements to skip frames instead of generating all
  53. * frames. (Since 1.6)
  54. * @GST_SEEK_FLAG_SNAP_BEFORE: go to a location before the requested position,
  55. * if %GST_SEEK_FLAG_KEY_UNIT this means the keyframe at or before
  56. * the requested position the one at or before the seek target.
  57. * @GST_SEEK_FLAG_SNAP_AFTER: go to a location after the requested position,
  58. * if %GST_SEEK_FLAG_KEY_UNIT this means the keyframe at of after the
  59. * requested position.
  60. * @GST_SEEK_FLAG_SNAP_NEAREST: go to a position near the requested position,
  61. * if %GST_SEEK_FLAG_KEY_UNIT this means the keyframe closest
  62. * to the requested position, if both keyframes are at an equal
  63. * distance, behaves like %GST_SEEK_FLAG_SNAP_BEFORE.
  64. * @GST_SEEK_FLAG_TRICKMODE_KEY_UNITS: when doing fast forward or fast reverse
  65. * playback, request that elements only decode keyframes
  66. * and skip all other content, for formats that have
  67. * keyframes. (Since 1.6)
  68. * @GST_SEEK_FLAG_TRICKMODE_NO_AUDIO: when doing fast forward or fast reverse
  69. * playback, request that audio decoder elements skip
  70. * decoding and output only gap events or silence. (Since 1.6)
  71. * @GST_SEEK_FLAG_SKIP: Deprecated backward compatibility flag, replaced
  72. * by %GST_SEEK_FLAG_TRICKMODE
  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 emitted 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_TRICKMODE 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. * Beyond that, the %GST_SEEK_FLAG_TRICKMODE_KEY_UNITS flag can be used to
  97. * request that decoders skip all frames except key units, and
  98. * %GST_SEEK_FLAG_TRICKMODE_NO_AUDIO flags can be used to request that audio
  99. * decoders do no decoding at all, and simple output silence.
  100. *
  101. * The %GST_SEEK_FLAG_SNAP_BEFORE flag can be used to snap to the previous
  102. * relevant location, and the %GST_SEEK_FLAG_SNAP_AFTER flag can be used to
  103. * select the next relevant location. If %GST_SEEK_FLAG_KEY_UNIT is specified,
  104. * the relevant location is a keyframe. If both flags are specified, the nearest
  105. * of these locations will be selected. If none are specified, the implementation is
  106. * free to select whichever it wants.
  107. *
  108. * The before and after here are in running time, so when playing backwards,
  109. * the next location refers to the one that will played in next, and not the
  110. * one that is located after in the actual source stream.
  111. *
  112. * Also see part-seeking.txt in the GStreamer design documentation for more
  113. * details on the meaning of these flags and the behaviour expected of
  114. * elements that handle them.
  115. */
  116. typedef enum {
  117. GST_SEEK_FLAG_NONE = 0,
  118. GST_SEEK_FLAG_FLUSH = (1 << 0),
  119. GST_SEEK_FLAG_ACCURATE = (1 << 1),
  120. GST_SEEK_FLAG_KEY_UNIT = (1 << 2),
  121. GST_SEEK_FLAG_SEGMENT = (1 << 3),
  122. GST_SEEK_FLAG_TRICKMODE = (1 << 4),
  123. /* FIXME 2.0: Remove _SKIP flag,
  124. * which was kept for backward compat when _TRICKMODE was added */
  125. GST_SEEK_FLAG_SKIP = (1 << 4),
  126. GST_SEEK_FLAG_SNAP_BEFORE = (1 << 5),
  127. GST_SEEK_FLAG_SNAP_AFTER = (1 << 6),
  128. GST_SEEK_FLAG_SNAP_NEAREST = GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER,
  129. /* Careful to restart next flag with 1<<7 here */
  130. GST_SEEK_FLAG_TRICKMODE_KEY_UNITS = (1 << 7),
  131. GST_SEEK_FLAG_TRICKMODE_NO_AUDIO = (1 << 8),
  132. } GstSeekFlags;
  133. /**
  134. * GstSegmentFlags:
  135. * @GST_SEGMENT_FLAG_NONE: no flags
  136. * @GST_SEGMENT_FLAG_RESET: reset the pipeline running_time to the segment
  137. * running_time
  138. * @GST_SEGMENT_FLAG_TRICKMODE: perform skip playback (Since 1.6)
  139. * @GST_SEGMENT_FLAG_SEGMENT: send SEGMENT_DONE instead of EOS
  140. * @GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS: Decode only keyframes, where
  141. * possible (Since 1.6)
  142. * @GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO: Do not decode any audio, where
  143. * possible (Since 1.6)
  144. * @GST_SEGMENT_FLAG_SKIP: Deprecated backward compatibility flag, replaced
  145. * by @GST_SEGMENT_FLAG_TRICKMODE
  146. *
  147. * Flags for the GstSegment structure. Currently mapped to the corresponding
  148. * values of the seek flags.
  149. */
  150. /* Note: update gst_segment_do_seek() when adding new flags here */
  151. typedef enum { /*< flags >*/
  152. GST_SEGMENT_FLAG_NONE = GST_SEEK_FLAG_NONE,
  153. GST_SEGMENT_FLAG_RESET = GST_SEEK_FLAG_FLUSH,
  154. GST_SEGMENT_FLAG_TRICKMODE = GST_SEEK_FLAG_TRICKMODE,
  155. /* FIXME 2.0: Remove _SKIP flag,
  156. * which was kept for backward compat when _TRICKMODE was added */
  157. GST_SEGMENT_FLAG_SKIP = GST_SEEK_FLAG_TRICKMODE,
  158. GST_SEGMENT_FLAG_SEGMENT = GST_SEEK_FLAG_SEGMENT,
  159. GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS = GST_SEEK_FLAG_TRICKMODE_KEY_UNITS,
  160. GST_SEGMENT_FLAG_TRICKMODE_NO_AUDIO = GST_SEEK_FLAG_TRICKMODE_NO_AUDIO
  161. } GstSegmentFlags;
  162. /**
  163. * GstSegment:
  164. * @flags: flags for this segment
  165. * @rate: the playback rate of the segment
  166. * @applied_rate: the already applied rate to the segment
  167. * @format: the format of the segment values
  168. * @base: the running time (plus elapsed time, see offset) of the segment start
  169. * @offset: the amount (in buffer timestamps) that has already been elapsed in
  170. * the segment
  171. * @start: the start of the segment in buffer timestamp time (PTS)
  172. * @stop: the stop of the segment in buffer timestamp time (PTS)
  173. * @time: the stream time of the segment start
  174. * @position: the buffer timestamp position in the segment (used internally by
  175. * elements such as sources, demuxers or parsers to track progress)
  176. * @duration: the duration of the segment
  177. *
  178. * A helper structure that holds the configured region of
  179. * interest in a media file.
  180. */
  181. struct _GstSegment {
  182. /*< public >*/
  183. GstSegmentFlags flags;
  184. gdouble rate;
  185. gdouble applied_rate;
  186. GstFormat format;
  187. guint64 base;
  188. guint64 offset;
  189. guint64 start;
  190. guint64 stop;
  191. guint64 time;
  192. guint64 position;
  193. guint64 duration;
  194. /* < private > */
  195. gpointer _gst_reserved[GST_PADDING];
  196. };
  197. GType gst_segment_get_type (void);
  198. GstSegment * gst_segment_new (void) G_GNUC_MALLOC;
  199. GstSegment * gst_segment_copy (const GstSegment *segment) G_GNUC_MALLOC;
  200. void gst_segment_copy_into (const GstSegment *src, GstSegment *dest);
  201. void gst_segment_free (GstSegment *segment);
  202. void gst_segment_init (GstSegment *segment, GstFormat format);
  203. gint gst_segment_to_stream_time_full (const GstSegment *segment, GstFormat format, guint64 position, guint64 * stream_time);
  204. guint64 gst_segment_to_stream_time (const GstSegment *segment, GstFormat format, guint64 position);
  205. gint gst_segment_position_from_stream_time_full (const GstSegment * segment, GstFormat format, guint64 stream_time, guint64 * position);
  206. guint64 gst_segment_position_from_stream_time (const GstSegment * segment, GstFormat format, guint64 stream_time);
  207. guint64 gst_segment_to_running_time (const GstSegment *segment, GstFormat format, guint64 position);
  208. gint gst_segment_to_running_time_full (const GstSegment *segment, GstFormat format, guint64 position,
  209. guint64 * running_time);
  210. #ifndef GST_DISABLE_DEPRECATED
  211. guint64 gst_segment_to_position (const GstSegment *segment, GstFormat format, guint64 running_time);
  212. #endif
  213. gint gst_segment_position_from_running_time_full (const GstSegment *segment, GstFormat format, guint64 running_time, guint64 * position);
  214. guint64 gst_segment_position_from_running_time (const GstSegment *segment, GstFormat format, guint64 running_time);
  215. gboolean gst_segment_set_running_time (GstSegment *segment, GstFormat format, guint64 running_time);
  216. gboolean gst_segment_offset_running_time (GstSegment *segment, GstFormat format, gint64 offset);
  217. gboolean gst_segment_clip (const GstSegment *segment, GstFormat format, guint64 start,
  218. guint64 stop, guint64 *clip_start, guint64 *clip_stop);
  219. gboolean gst_segment_do_seek (GstSegment * segment, gdouble rate,
  220. GstFormat format, GstSeekFlags flags,
  221. GstSeekType start_type, guint64 start,
  222. GstSeekType stop_type, guint64 stop, gboolean * update);
  223. gboolean gst_segment_is_equal (const GstSegment * s0, const GstSegment * s1);
  224. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  225. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSegment, gst_segment_free)
  226. #endif
  227. G_END_DECLS
  228. #endif /* __GST_SEGMENT_H__ */