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

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