Blame gst-libs/gst/video/gstvideoutils.h

Packit 0652a1
/* GStreamer
Packit 0652a1
 * Copyright (C) 2008 David Schleef <ds@schleef.org>
Packit 0652a1
 * Copyright (C) 2012 Collabora Ltd.
Packit 0652a1
 *	Author : Edward Hervey <edward@collabora.com>
Packit 0652a1
 *
Packit 0652a1
 * This library is free software; you can redistribute it and/or
Packit 0652a1
 * modify it under the terms of the GNU Library General Public
Packit 0652a1
 * License as published by the Free Software Foundation; either
Packit 0652a1
 * version 2 of the License, or (at your option) any later version.
Packit 0652a1
 *
Packit 0652a1
 * This library is distributed in the hope that it will be useful,
Packit 0652a1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0652a1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0652a1
 * Library General Public License for more details.
Packit 0652a1
 *
Packit 0652a1
 * You should have received a copy of the GNU Library General Public
Packit 0652a1
 * License along with this library; if not, write to the
Packit 0652a1
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 0652a1
 * Boston, MA 02110-1301, USA.
Packit 0652a1
 */
Packit 0652a1
Packit 0652a1
#ifndef __GST_VIDEO_H__
Packit 0652a1
#include <gst/video/video.h>
Packit 0652a1
#endif
Packit 0652a1
Packit 0652a1
#ifndef _GST_VIDEO_UTILS_H_
Packit 0652a1
#define _GST_VIDEO_UTILS_H_
Packit 0652a1
Packit 0652a1
#include <gst/gst.h>
Packit 0652a1
#include <gst/video/video-prelude.h>
Packit 0652a1
Packit 0652a1
G_BEGIN_DECLS
Packit 0652a1
#define GST_TYPE_VIDEO_CODEC_STATE \
Packit 0652a1
  (gst_video_codec_state_get_type())
Packit 0652a1
Packit 0652a1
#define GST_TYPE_VIDEO_CODEC_FRAME \
Packit 0652a1
  (gst_video_codec_frame_get_type())
Packit 0652a1
Packit 0652a1
typedef struct _GstVideoCodecState GstVideoCodecState;
Packit 0652a1
typedef struct _GstVideoCodecFrame GstVideoCodecFrame;
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GstVideoCodecState:
Packit 0652a1
 * @info: The #GstVideoInfo describing the stream
Packit 0652a1
 * @caps: The #GstCaps used in the caps negotiation of the pad.
Packit 0652a1
 * @codec_data: a #GstBuffer corresponding to the
Packit 0652a1
 *     'codec_data' field of a stream, or NULL.
Packit 0652a1
 * @allocation_caps: The #GstCaps for allocation query and pool
Packit 0652a1
 *     negotiation. Since: 1.10
Packit 0652a1
 *
Packit 0652a1
 * Structure representing the state of an incoming or outgoing video
Packit 0652a1
 * stream for encoders and decoders.
Packit 0652a1
 *
Packit 0652a1
 * Decoders and encoders will receive such a state through their
Packit 0652a1
 * respective @set_format vmethods.
Packit 0652a1
 *
Packit 0652a1
 * Decoders and encoders can set the downstream state, by using the
Packit 0652a1
 * @gst_video_decoder_set_output_state() or
Packit 0652a1
 * @gst_video_encoder_set_output_state() methods.
Packit 0652a1
 */
Packit 0652a1
struct _GstVideoCodecState
Packit 0652a1
{
Packit 0652a1
  /*< private >*/
Packit 0652a1
  gint ref_count;
Packit 0652a1
Packit 0652a1
  /*< public >*/
Packit 0652a1
  GstVideoInfo info;
Packit 0652a1
Packit 0652a1
  GstCaps *caps;
Packit 0652a1
Packit 0652a1
  GstBuffer *codec_data;
Packit 0652a1
Packit 0652a1
  GstCaps *allocation_caps;
Packit 0652a1
Packit 0652a1
  /*< private >*/
Packit 0652a1
  gpointer padding[GST_PADDING_LARGE - 1];
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GstVideoCodecFrameFlags:
Packit 0652a1
 * @GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY: is the frame only meant to be decoded
Packit 0652a1
 * @GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT: is the frame a synchronization point (keyframe)
Packit 0652a1
 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME: should the output frame be made a keyframe
Packit 0652a1
 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS: should the encoder output stream headers
Packit 0652a1
 *
Packit 0652a1
 * Flags for #GstVideoCodecFrame
Packit 0652a1
 */
Packit 0652a1
typedef enum
Packit 0652a1
{
Packit 0652a1
  GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY            = (1<<0),
Packit 0652a1
  GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT             = (1<<1),
Packit 0652a1
  GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME         = (1<<2),
Packit 0652a1
  GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS = (1<<3)
Packit 0652a1
} GstVideoCodecFrameFlags;
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_FLAGS:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * The entire set of flags for the @frame
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_FLAGS(frame) ((frame)->flags)
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_FLAG_IS_SET:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 * @flag: a flag to check for
Packit 0652a1
 *
Packit 0652a1
 * Checks whether the given @flag is set
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame,flag)   !!(GST_VIDEO_CODEC_FRAME_FLAGS(frame) & (flag))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_FLAG_SET:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 * @flag: Flag to set, can be any number of bits in guint32.
Packit 0652a1
 *
Packit 0652a1
 * This macro sets the given bits
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_FLAG_SET(frame,flag)     (GST_VIDEO_CODEC_FRAME_FLAGS(frame) |= (flag))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_FLAG_UNSET:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 * @flag: Flag to unset
Packit 0652a1
 *
Packit 0652a1
 * This macro usets the given bits.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame,flag)   (GST_VIDEO_CODEC_FRAME_FLAGS(frame) &= ~(flag))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Tests if the buffer should only be decoded but not sent downstream.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY(frame)     (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Sets the buffer to not be sent downstream.
Packit 0652a1
 *
Packit 0652a1
 * Decoder implementation can use this if they have frames that
Packit 0652a1
 * are not meant to be displayed.
Packit 0652a1
 *
Packit 0652a1
 * Encoder implementation can safely ignore this field.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame)    (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Tests if the frame is a synchronization point (like a keyframe).
Packit 0652a1
 *
Packit 0652a1
 * Decoder implementations can use this to detect keyframes.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT(frame)      (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Sets the frame to be a synchronization point (like a keyframe).
Packit 0652a1
 *
Packit 0652a1
 * Encoder implementations should set this accordingly.
Packit 0652a1
 *
Packit 0652a1
 * Decoder implementing parsing features should set this when they
Packit 0652a1
 * detect such a synchronization point.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT(frame)     (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT(frame)   (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
Packit 0652a1
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Tests if the frame must be encoded as a keyframe. Applies only to
Packit 0652a1
 * frames provided to encoders. Decoders can safely ignore this field.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME(frame)      (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME(frame)     (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME(frame)   (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS:
Packit 0652a1
 * @frame: a #GstVideoCodecFrame
Packit 0652a1
 *
Packit 0652a1
 * Tests if encoder should output stream headers before outputting the
Packit 0652a1
 * resulting encoded buffer for the given frame.
Packit 0652a1
 *
Packit 0652a1
 * Applies only to frames provided to encoders. Decoders can safely
Packit 0652a1
 * ignore this field.
Packit 0652a1
 */
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS(frame)      (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME_HEADERS(frame)     (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
Packit 0652a1
#define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME_HEADERS(frame)   (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * GstVideoCodecFrame:
Packit 0652a1
 * @pts: Presentation timestamp
Packit 0652a1
 * @dts: Decoding timestamp
Packit 0652a1
 * @duration: Duration of the frame
Packit 0652a1
 * @system_frame_number: Unique identifier for the frame. Use this if you need
Packit 0652a1
 *       to get hold of the frame later (like when data is being decoded).
Packit 0652a1
 *       Typical usage in decoders is to set this on the opaque value provided
Packit 0652a1
 *       to the library and get back the frame using gst_video_decoder_get_frame()
Packit 0652a1
 * @distance_from_sync: Distance in frames from the last synchronization point.
Packit 0652a1
 * @input_buffer: the input #GstBuffer that created this frame. The buffer is owned
Packit 0652a1
 *           by the frame and references to the frame instead of the buffer should
Packit 0652a1
 *           be kept.
Packit 0652a1
 * @output_buffer: the output #GstBuffer. Implementations should set this either
Packit 0652a1
 *           directly, or by using the
Packit 0652a1
 *           @gst_video_decoder_allocate_output_frame() or
Packit 0652a1
 *           @gst_video_decoder_allocate_output_buffer() methods. The buffer is
Packit 0652a1
 *           owned by the frame and references to the frame instead of the
Packit 0652a1
 *           buffer should be kept.
Packit 0652a1
 * @deadline: Running time when the frame will be used.
Packit 0652a1
 *
Packit 0652a1
 * A #GstVideoCodecFrame represents a video frame both in raw and
Packit 0652a1
 * encoded form.
Packit 0652a1
 */
Packit 0652a1
struct _GstVideoCodecFrame
Packit 0652a1
{
Packit 0652a1
  /*< private >*/
Packit 0652a1
  gint ref_count;
Packit 0652a1
  guint32 flags;
Packit 0652a1
Packit 0652a1
  /*< public >*/
Packit 0652a1
  guint32 system_frame_number;	/* ED */
Packit 0652a1
Packit 0652a1
  /*< private >*/
Packit 0652a1
  guint32 decode_frame_number;	/* ED */
Packit 0652a1
  guint32 presentation_frame_number; /* ED */
Packit 0652a1
Packit 0652a1
  /*< public >*/
Packit 0652a1
  GstClockTime dts;       /* ED */
Packit 0652a1
  GstClockTime pts;       /* ED */
Packit 0652a1
  GstClockTime duration;  /* ED */
Packit 0652a1
Packit 0652a1
  int distance_from_sync;	/* ED */
Packit 0652a1
Packit 0652a1
  GstBuffer *input_buffer;	/* ED */
Packit 0652a1
  GstBuffer *output_buffer;	/* ED */
Packit 0652a1
Packit 0652a1
  GstClockTime deadline;	/* D */
Packit 0652a1
Packit 0652a1
  /*< private >*/
Packit 0652a1
Packit 0652a1
  /* Events that should be pushed downstream *before*
Packit 0652a1
   * the next output_buffer */
Packit 0652a1
  GList *events;		/* ED */
Packit 0652a1
Packit 0652a1
  gpointer       user_data;
Packit 0652a1
  GDestroyNotify user_data_destroy_notify;
Packit 0652a1
Packit 0652a1
  union {
Packit 0652a1
    struct {
Packit 0652a1
      GstClockTime ts;
Packit 0652a1
      GstClockTime ts2;
Packit 0652a1
    } ABI;
Packit 0652a1
    gpointer padding[GST_PADDING_LARGE];
Packit 0652a1
  } abidata;
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
/* GstVideoCodecState */
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
GType           gst_video_codec_state_get_type (void);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
GstVideoCodecState *gst_video_codec_state_ref (GstVideoCodecState * state);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
void                gst_video_codec_state_unref (GstVideoCodecState * state);
Packit 0652a1
Packit 0652a1
Packit 0652a1
/* GstVideoCodecFrame */
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
GType                gst_video_codec_frame_get_type (void);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
GstVideoCodecFrame  *gst_video_codec_frame_ref (GstVideoCodecFrame * frame);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
void                 gst_video_codec_frame_unref (GstVideoCodecFrame * frame);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
void                 gst_video_codec_frame_set_user_data (GstVideoCodecFrame *frame,
Packit 0652a1
						          gpointer user_data,
Packit 0652a1
				                          GDestroyNotify notify);
Packit 0652a1
Packit 0652a1
GST_VIDEO_API
Packit 0652a1
gpointer             gst_video_codec_frame_get_user_data (GstVideoCodecFrame *frame);
Packit 0652a1
Packit 0652a1
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit 0652a1
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecFrame, gst_video_codec_frame_unref)
Packit 0652a1
#endif
Packit 0652a1
Packit 0652a1
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit 0652a1
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecState, gst_video_codec_state_unref)
Packit 0652a1
#endif
Packit 0652a1
Packit 0652a1
G_END_DECLS
Packit 0652a1
Packit 0652a1
#endif