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

Packit 971217
/* GStreamer
Packit 971217
 * Copyright (C) 2008 David Schleef <ds@schleef.org>
Packit 971217
 * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
Packit 971217
 * Copyright (C) 2011 Nokia Corporation. All rights reserved.
Packit 971217
 *   Contact: Stefan Kost <stefan.kost@nokia.com>
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_ENCODER_H_
Packit 971217
#define _GST_VIDEO_ENCODER_H_
Packit 971217
Packit 971217
#include <gst/video/gstvideoutils.h>
Packit 971217
Packit 971217
G_BEGIN_DECLS
Packit 971217
Packit 971217
#define GST_TYPE_VIDEO_ENCODER \
Packit 971217
  (gst_video_encoder_get_type())
Packit 971217
#define GST_VIDEO_ENCODER(obj) \
Packit 971217
  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoder))
Packit 971217
#define GST_VIDEO_ENCODER_CLASS(klass) \
Packit 971217
  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
Packit 971217
#define GST_VIDEO_ENCODER_GET_CLASS(obj) \
Packit 971217
  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
Packit 971217
#define GST_IS_VIDEO_ENCODER(obj) \
Packit 971217
  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_ENCODER))
Packit 971217
#define GST_IS_VIDEO_ENCODER_CLASS(klass) \
Packit 971217
  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_ENCODER))
Packit 971217
#define GST_VIDEO_ENCODER_CAST(enc) ((GstVideoEncoder*)enc)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_SINK_NAME:
Packit 971217
 *
Packit 971217
 * The name of the templates for the sink pad.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_SINK_NAME    "sink"
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_SRC_NAME:
Packit 971217
 *
Packit 971217
 * The name of the templates for the source pad.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_SRC_NAME     "src"
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_SRC_PAD:
Packit 971217
 * @obj: a #GstVideoEncoder
Packit 971217
 *
Packit 971217
 * Gives the pointer to the source #GstPad object of the element.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_SRC_PAD(obj)         (((GstVideoEncoder *) (obj))->srcpad)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_SINK_PAD:
Packit 971217
 * @obj: a #GstVideoEncoder
Packit 971217
 *
Packit 971217
 * Gives the pointer to the sink #GstPad object of the element.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_SINK_PAD(obj)        (((GstVideoEncoder *) (obj))->sinkpad)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_FLOW_NEED_DATA:
Packit 971217
 *
Packit 971217
 * Returned while parsing to indicate more data is needed.
Packit 971217
 **/
Packit 971217
#define GST_VIDEO_ENCODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_FLOW_DROPPED:
Packit 971217
 *
Packit 971217
 * Returned when the event/buffer should be dropped.
Packit 971217
 *
Packit 971217
 * Deprecated: since 1.8. use gst_video_encoder_finish_frame with
Packit 971217
 * a %NULL frame->output_buffer to drop the frame instead.
Packit 971217
 */
Packit 971217
#ifndef GST_DISABLE_DEPRECATED
Packit 971217
#define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
Packit 971217
#endif
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_INPUT_SEGMENT:
Packit 971217
 * @obj: base parse instance
Packit 971217
 *
Packit 971217
 * Gives the segment of the element.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj)     (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_OUTPUT_SEGMENT:
Packit 971217
 * @obj: base parse instance
Packit 971217
 *
Packit 971217
 * Gives the segment of the element.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj)     (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_STREAM_LOCK:
Packit 971217
 * @encoder: video encoder instance
Packit 971217
 *
Packit 971217
 * Obtain a lock to protect the encoder function from concurrent access.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_VIDEO_ENCODER_STREAM_UNLOCK:
Packit 971217
 * @encoder: video encoder instance
Packit 971217
 *
Packit 971217
 * Release the lock that protects the encoder function from concurrent access.
Packit 971217
 */
Packit 971217
#define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
Packit 971217
Packit 971217
typedef struct _GstVideoEncoder GstVideoEncoder;
Packit 971217
typedef struct _GstVideoEncoderPrivate GstVideoEncoderPrivate;
Packit 971217
typedef struct _GstVideoEncoderClass GstVideoEncoderClass;
Packit 971217
Packit 971217
/**
Packit 971217
 * GstVideoEncoder:
Packit 971217
 *
Packit 971217
 * The opaque #GstVideoEncoder data structure.
Packit 971217
 */
Packit 971217
struct _GstVideoEncoder
Packit 971217
{
Packit 971217
  /*< private >*/
Packit 971217
  GstElement    element;
Packit 971217
Packit 971217
  /*< protected >*/
Packit 971217
  GstPad         *sinkpad;
Packit 971217
  GstPad         *srcpad;
Packit 971217
Packit 971217
  /* protects all data processing, i.e. is locked
Packit 971217
   * in the chain function, finish_frame and when
Packit 971217
   * processing serialized events */
Packit 971217
  GRecMutex stream_lock;
Packit 971217
Packit 971217
  /* MT-protected (with STREAM_LOCK) */
Packit 971217
  GstSegment      input_segment;
Packit 971217
  GstSegment      output_segment;
Packit 971217
Packit 971217
  /*< private >*/
Packit 971217
  GstVideoEncoderPrivate *priv;
Packit 971217
Packit 971217
  gpointer padding[GST_PADDING_LARGE];
Packit 971217
};
Packit 971217
Packit 971217
/**
Packit 971217
 * GstVideoEncoderClass:
Packit 971217
 * @open:           Optional.
Packit 971217
 *                  Called when the element changes to GST_STATE_READY.
Packit 971217
 *                  Allows opening external resources.
Packit 971217
 * @close:          Optional.
Packit 971217
 *                  Called when the element changes to GST_STATE_NULL.
Packit 971217
 *                  Allows closing external resources.
Packit 971217
 * @start:          Optional.
Packit 971217
 *                  Called when the element starts processing.
Packit 971217
 *                  Allows opening external resources.
Packit 971217
 * @stop:           Optional.
Packit 971217
 *                  Called when the element stops processing.
Packit 971217
 *                  Allows closing external resources.
Packit 971217
 * @set_format:     Optional.
Packit 971217
 *                  Notifies subclass of incoming data format.
Packit 971217
 *                  GstVideoCodecState fields have already been
Packit 971217
 *                  set according to provided caps.
Packit 971217
 * @handle_frame:   Provides input frame to subclass.
Packit 971217
 * @reset:          Optional.
Packit 971217
 *                  Allows subclass (encoder) to perform post-seek semantics reset.
Packit 971217
 *                  Deprecated.
Packit 971217
 * @finish:         Optional.
Packit 971217
 *                  Called to request subclass to dispatch any pending remaining
Packit 971217
 *                  data (e.g. at EOS).
Packit 971217
 * @pre_push:   Optional.
Packit 971217
 *                  Allows subclass to push frame downstream in whatever
Packit 971217
 *                  shape or form it deems appropriate.  If not provided,
Packit 971217
 *                  provided encoded frame data is simply pushed downstream.
Packit 971217
 * @getcaps:        Optional.
Packit 971217
 *                  Allows for a custom sink getcaps implementation (e.g.
Packit 971217
 *                  for multichannel input specification).  If not implemented,
Packit 971217
 *                  default returns gst_video_encoder_proxy_getcaps
Packit 971217
 *                  applied to sink template caps.
Packit 971217
 * @sink_event:     Optional.
Packit 971217
 *                  Event handler on the sink pad. This function should return
Packit 971217
 *                  TRUE if the event was handled and should be discarded
Packit 971217
 *                  (i.e. not unref'ed).
Packit 971217
 *                  Subclasses should chain up to the parent implementation to
Packit 971217
 *                  invoke the default handler.
Packit 971217
 * @src_event:      Optional.
Packit 971217
 *                  Event handler on the source pad. This function should return
Packit 971217
 *                  TRUE if the event was handled and should be discarded
Packit 971217
 *                  (i.e. not unref'ed).
Packit 971217
 *                  Subclasses should chain up to the parent implementation to
Packit 971217
 *                  invoke the default handler.
Packit 971217
 * @negotiate:      Optional.
Packit 971217
 *                  Negotiate with downstream and configure buffer pools, etc.
Packit 971217
 *                  Subclasses should chain up to the parent implementation to
Packit 971217
 *                  invoke the default handler.
Packit 971217
 * @decide_allocation: Optional.
Packit 971217
 *                     Setup the allocation parameters for allocating output
Packit 971217
 *                     buffers. The passed in query contains the result of the
Packit 971217
 *                     downstream allocation query.
Packit 971217
 *                     Subclasses should chain up to the parent implementation to
Packit 971217
 *                     invoke the default handler.
Packit 971217
 * @propose_allocation: Optional.
Packit 971217
 *                      Propose buffer allocation parameters for upstream elements.
Packit 971217
 *                      Subclasses should chain up to the parent implementation to
Packit 971217
 *                      invoke the default handler.
Packit 971217
 * @flush:              Optional.
Packit 971217
 *                      Flush all remaining data from the encoder without
Packit 971217
 *                      pushing it downstream. Since: 1.2
Packit 971217
 * @sink_query:     Optional.
Packit 971217
 *                  Query handler on the sink pad. This function should
Packit 971217
 *                  return TRUE if the query could be performed. Subclasses
Packit 971217
 *                  should chain up to the parent implementation to invoke the
Packit 971217
 *                  default handler. Since 1.4
Packit 971217
 * @src_query:      Optional.
Packit 971217
 *                  Query handler on the source pad. This function should
Packit 971217
 *                  return TRUE if the query could be performed. Subclasses
Packit 971217
 *                  should chain up to the parent implementation to invoke the
Packit 971217
 *                  default handler. Since 1.4
Packit 971217
 * @transform_meta: Optional. Transform the metadata on the input buffer to the
Packit 971217
 *                  output buffer. By default this method is copies all meta without
Packit 971217
 *                  tags and meta with only the "video" tag. subclasses can
Packit 971217
 *                  implement this method and return %TRUE if the metadata is to be
Packit 971217
 *                  copied. Since 1.6
Packit 971217
 *
Packit 971217
 * Subclasses can override any of the available virtual methods or not, as
Packit 971217
 * needed. At minimum @handle_frame needs to be overridden, and @set_format
Packit 971217
 * and @get_caps are likely needed as well.
Packit 971217
 */
Packit 971217
struct _GstVideoEncoderClass
Packit 971217
{
Packit 971217
  /*< private >*/
Packit 971217
  GstElementClass  element_class;
Packit 971217
Packit 971217
  /*< public >*/
Packit 971217
  /* virtual methods for subclasses */
Packit 971217
  gboolean      (*open)         (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*close)        (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*start)        (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*stop)         (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*set_format)   (GstVideoEncoder *encoder,
Packit 971217
				 GstVideoCodecState *state);
Packit 971217
Packit 971217
  GstFlowReturn (*handle_frame) (GstVideoEncoder *encoder,
Packit 971217
				 GstVideoCodecFrame *frame);
Packit 971217
Packit 971217
  gboolean      (*reset)        (GstVideoEncoder *encoder,
Packit 971217
				 gboolean hard);
Packit 971217
Packit 971217
  GstFlowReturn (*finish)       (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  GstFlowReturn (*pre_push)     (GstVideoEncoder *encoder,
Packit 971217
				 GstVideoCodecFrame *frame);
Packit 971217
Packit 971217
  GstCaps *     (*getcaps)      (GstVideoEncoder *enc,
Packit 971217
                                 GstCaps *filter);
Packit 971217
Packit 971217
  gboolean      (*sink_event)   (GstVideoEncoder *encoder,
Packit 971217
				 GstEvent *event);
Packit 971217
Packit 971217
  gboolean      (*src_event)    (GstVideoEncoder *encoder,
Packit 971217
				 GstEvent *event);
Packit 971217
Packit 971217
  gboolean      (*negotiate)    (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*decide_allocation)  (GstVideoEncoder *encoder, GstQuery *query);
Packit 971217
Packit 971217
  gboolean      (*propose_allocation) (GstVideoEncoder * encoder,
Packit 971217
                                       GstQuery * query);
Packit 971217
  gboolean      (*flush)              (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
  gboolean      (*sink_query)     (GstVideoEncoder *encoder,
Packit 971217
				   GstQuery *query);
Packit 971217
Packit 971217
  gboolean      (*src_query)      (GstVideoEncoder *encoder,
Packit 971217
				   GstQuery *query);
Packit 971217
Packit 971217
  gboolean      (*transform_meta) (GstVideoEncoder *encoder,
Packit 971217
                                   GstVideoCodecFrame *frame,
Packit 971217
                                   GstMeta * meta);
Packit 971217
Packit 971217
  /*< private >*/
Packit 971217
  gpointer       _gst_reserved[GST_PADDING_LARGE-4];
Packit 971217
};
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GType                gst_video_encoder_get_type (void);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstVideoCodecState*  gst_video_encoder_get_output_state (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstVideoCodecState*  gst_video_encoder_set_output_state (GstVideoEncoder * encoder,
Packit 971217
							 GstCaps * caps,
Packit 971217
							 GstVideoCodecState * reference);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
gboolean             gst_video_encoder_negotiate        (GstVideoEncoder * encoder);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstVideoCodecFrame*  gst_video_encoder_get_frame        (GstVideoEncoder *encoder,
Packit 971217
						         int frame_number);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstVideoCodecFrame*  gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GList *              gst_video_encoder_get_frames       (GstVideoEncoder *encoder);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstBuffer *          gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder,
Packit 971217
                                                               gsize size);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstFlowReturn        gst_video_encoder_allocate_output_frame  (GstVideoEncoder *encoder,
Packit 971217
						               GstVideoCodecFrame *frame,
Packit 971217
                                                               gsize size);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstFlowReturn        gst_video_encoder_finish_frame (GstVideoEncoder *encoder,
Packit 971217
						     GstVideoCodecFrame *frame);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstCaps *            gst_video_encoder_proxy_getcaps (GstVideoEncoder * enc,
Packit 971217
						      GstCaps         * caps,
Packit 971217
                                                      GstCaps         * filter);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_set_latency (GstVideoEncoder *encoder,
Packit 971217
						    GstClockTime min_latency,
Packit 971217
						    GstClockTime max_latency);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void		     gst_video_encoder_get_latency (GstVideoEncoder *encoder,
Packit 971217
						    GstClockTime *min_latency,
Packit 971217
						    GstClockTime *max_latency);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_set_headers (GstVideoEncoder *encoder,
Packit 971217
						    GList *headers);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_merge_tags  (GstVideoEncoder *encoder,
Packit 971217
                                                    const GstTagList *tags,
Packit 971217
                                                    GstTagMergeMode mode);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_get_allocator (GstVideoEncoder *encoder,
Packit 971217
                                                      GstAllocator **allocator,
Packit 971217
                                                      GstAllocationParams *params);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_set_min_pts(GstVideoEncoder *encoder, GstClockTime min_pts);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
void                 gst_video_encoder_set_qos_enabled (GstVideoEncoder * encoder, gboolean enabled);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
gboolean             gst_video_encoder_is_qos_enabled (GstVideoEncoder * encoder);
Packit 971217
Packit 971217
GST_VIDEO_API
Packit 971217
GstClockTimeDiff     gst_video_encoder_get_max_encode_time (GstVideoEncoder *encoder, GstVideoCodecFrame * frame);
Packit 971217
Packit 971217
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit 971217
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoEncoder, gst_object_unref)
Packit 971217
#endif
Packit 971217
Packit 971217
G_END_DECLS
Packit 971217
Packit 971217
#endif
Packit 971217