2011-01-27 15:52:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
|
|
|
|
* Copyright (C) 2011 Nokia Corporation. All rights reserved.
|
|
|
|
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-01-27 15:52:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* SECTION:gstaudioencoder
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: GstAudioEncoder
|
2011-01-27 15:52:50 +00:00
|
|
|
* @short_description: Base class for audio encoders
|
|
|
|
* @see_also: #GstBaseTransform
|
|
|
|
*
|
|
|
|
* This base class is for audio encoders turning raw audio samples into
|
|
|
|
* encoded audio data.
|
|
|
|
*
|
2011-09-05 14:01:09 +00:00
|
|
|
* GstAudioEncoder and subclass should cooperate as follows.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* ## Configuration
|
|
|
|
*
|
|
|
|
* * Initially, GstAudioEncoder calls @start when the encoder element
|
2011-01-27 15:52:50 +00:00
|
|
|
* is activated, which allows subclass to perform any global setup.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* * GstAudioEncoder calls @set_format to inform subclass of the format
|
2011-01-27 15:52:50 +00:00
|
|
|
* of input audio data that it is about to receive. Subclass should
|
2011-08-16 16:23:14 +00:00
|
|
|
* setup for encoding and configure various base class parameters
|
2011-01-27 15:52:50 +00:00
|
|
|
* appropriately, notably those directing desired input data handling.
|
|
|
|
* While unlikely, it might be called more than once, if changing input
|
|
|
|
* parameters require reconfiguration.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* * GstAudioEncoder calls @stop at end of all processing.
|
|
|
|
*
|
2011-09-05 14:01:09 +00:00
|
|
|
* As of configuration stage, and throughout processing, GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* maintains various parameters that provide required context,
|
2011-01-27 15:52:50 +00:00
|
|
|
* e.g. describing the format of input audio data.
|
2011-08-16 16:23:14 +00:00
|
|
|
* Conversely, subclass can and should configure these context parameters
|
|
|
|
* to inform base class of its expectation w.r.t. buffer handling.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* ## Data processing
|
|
|
|
*
|
|
|
|
* * Base class gathers input sample data (as directed by the context's
|
2011-01-27 15:52:50 +00:00
|
|
|
* frame_samples and frame_max) and provides this to subclass' @handle_frame.
|
2017-01-23 19:36:11 +00:00
|
|
|
* * If codec processing results in encoded data, subclass should call
|
2013-03-25 15:46:29 +00:00
|
|
|
* gst_audio_encoder_finish_frame() to have encoded data pushed
|
|
|
|
* downstream. Alternatively, it might also call
|
|
|
|
* gst_audio_encoder_finish_frame() (with a NULL buffer and some number of
|
|
|
|
* dropped samples) to indicate dropped (non-encoded) samples.
|
2017-01-23 19:36:11 +00:00
|
|
|
* * Just prior to actually pushing a buffer downstream,
|
2011-01-27 15:52:50 +00:00
|
|
|
* it is passed to @pre_push.
|
2017-01-23 19:36:11 +00:00
|
|
|
* * During the parsing process GstAudioEncoderClass will handle both
|
2011-01-27 15:52:50 +00:00
|
|
|
* srcpad and sinkpad events. Sink events will be passed to subclass
|
|
|
|
* if @event callback has been provided.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* ## Shutdown phase
|
|
|
|
*
|
|
|
|
* * GstAudioEncoder class calls @stop to inform the subclass that data
|
2011-01-27 15:52:50 +00:00
|
|
|
* parsing will be stopped.
|
|
|
|
*
|
|
|
|
* Subclass is responsible for providing pad template caps for
|
2013-12-20 21:54:39 +00:00
|
|
|
* source and sink pads. The pads need to be named "sink" and "src". It also
|
2011-01-27 15:52:50 +00:00
|
|
|
* needs to set the fixed caps on srcpad, when the format is ensured. This
|
|
|
|
* is typically when base class calls subclass' @set_format function, though
|
2011-09-05 14:01:09 +00:00
|
|
|
* it might be delayed until calling @gst_audio_encoder_finish_frame.
|
2011-01-27 15:52:50 +00:00
|
|
|
*
|
|
|
|
* In summary, above process should have subclass concentrating on
|
|
|
|
* codec data processing while leaving other matters to base class,
|
|
|
|
* such as most notably timestamp handling. While it may exert more control
|
|
|
|
* in this area (see e.g. @pre_push), it is very much not recommended.
|
|
|
|
*
|
|
|
|
* In particular, base class will either favor tracking upstream timestamps
|
|
|
|
* (at the possible expense of jitter) or aim to arrange for a perfect stream of
|
2011-09-05 19:45:22 +00:00
|
|
|
* output timestamps, depending on #GstAudioEncoder:perfect-timestamp.
|
2011-01-27 15:52:50 +00:00
|
|
|
* However, in the latter case, the input may not be so perfect or ideal, which
|
|
|
|
* is handled as follows. An input timestamp is compared with the expected
|
|
|
|
* timestamp as dictated by input sample stream and if the deviation is less
|
2011-09-05 14:01:09 +00:00
|
|
|
* than #GstAudioEncoder:tolerance, the deviation is discarded.
|
2011-03-09 11:18:56 +00:00
|
|
|
* Otherwise, it is considered a discontuinity and subsequent output timestamp
|
|
|
|
* is resynced to the new position after performing configured discontinuity
|
2011-09-05 19:45:22 +00:00
|
|
|
* processing. In the non-perfect-timestamp case, an upstream variation
|
|
|
|
* exceeding tolerance only leads to marking DISCONT on subsequent outgoing
|
2011-03-09 11:18:56 +00:00
|
|
|
* (while timestamps are adjusted to upstream regardless of variation).
|
2011-09-05 19:45:22 +00:00
|
|
|
* While DISCONT is also marked in the perfect-timestamp case, this one
|
|
|
|
* optionally (see #GstAudioEncoder:hard-resync)
|
2011-01-27 15:52:50 +00:00
|
|
|
* performs some additional steps, such as clipping of (early) input samples
|
|
|
|
* or draining all currently remaining input data, depending on the direction
|
|
|
|
* of the discontuinity.
|
|
|
|
*
|
2011-03-09 11:44:36 +00:00
|
|
|
* If perfect timestamps are arranged, it is also possible to request baseclass
|
|
|
|
* (usually set by subclass) to provide additional buffer metadata (in OFFSET
|
|
|
|
* and OFFSET_END) fields according to granule defined semantics currently
|
|
|
|
* needed by oggmux. Specifically, OFFSET is set to granulepos (= sample count
|
|
|
|
* including buffer) and OFFSET_END to corresponding timestamp (as determined
|
|
|
|
* by same sample count and sample rate).
|
|
|
|
*
|
2011-01-27 15:52:50 +00:00
|
|
|
* Things that subclass need to take care of:
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
|
|
|
* * Provide pad templates
|
|
|
|
* * Set source pad caps when appropriate
|
|
|
|
* * Inform base class of buffer processing needs using context's
|
2011-01-27 15:52:50 +00:00
|
|
|
* frame_samples and frame_bytes.
|
2017-01-23 19:36:11 +00:00
|
|
|
* * Set user-configurable properties to sane defaults for format and
|
2011-01-27 15:52:50 +00:00
|
|
|
* implementing codec at hand, e.g. those controlling timestamp behaviour
|
|
|
|
* and discontinuity processing.
|
2017-01-23 19:36:11 +00:00
|
|
|
* * Accept data in @handle_frame and provide encoded results to
|
2013-03-25 15:46:29 +00:00
|
|
|
* gst_audio_encoder_finish_frame().
|
2011-01-27 15:52:50 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
#include "gstaudioencoder.h"
|
2014-12-16 14:13:40 +00:00
|
|
|
#include "gstaudioutilsprivate.h"
|
2011-03-15 16:27:42 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
|
|
|
#include <gst/audio/audio.h>
|
2011-09-26 12:48:55 +00:00
|
|
|
#include <gst/pbutils/descriptions.h>
|
2011-03-15 16:27:42 +00:00
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_audio_encoder_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_audio_encoder_debug
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PERFECT_TS,
|
|
|
|
PROP_GRANULE,
|
|
|
|
PROP_HARD_RESYNC,
|
|
|
|
PROP_TOLERANCE
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_PERFECT_TS FALSE
|
|
|
|
#define DEFAULT_GRANULE FALSE
|
|
|
|
#define DEFAULT_HARD_RESYNC FALSE
|
|
|
|
#define DEFAULT_TOLERANCE 40000000
|
2012-02-16 11:18:03 +00:00
|
|
|
#define DEFAULT_HARD_MIN FALSE
|
|
|
|
#define DEFAULT_DRAINABLE TRUE
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
typedef struct _GstAudioEncoderContext
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
|
|
|
/* input */
|
2013-04-18 07:54:48 +00:00
|
|
|
/* last negotiated input caps */
|
|
|
|
GstCaps *input_caps;
|
|
|
|
/* last negotiated input info */
|
2011-08-27 11:39:50 +00:00
|
|
|
GstAudioInfo info;
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
/* output */
|
2012-08-09 13:20:45 +00:00
|
|
|
GstCaps *caps;
|
2016-04-01 10:25:14 +00:00
|
|
|
GstCaps *allocation_caps;
|
2012-08-09 13:20:45 +00:00
|
|
|
gboolean output_caps_changed;
|
2011-09-26 13:59:22 +00:00
|
|
|
gint frame_samples_min, frame_samples_max;
|
2011-08-16 16:23:14 +00:00
|
|
|
gint frame_max;
|
|
|
|
gint lookahead;
|
|
|
|
/* MT-protected (with LOCK) */
|
|
|
|
GstClockTime min_latency;
|
|
|
|
GstClockTime max_latency;
|
2012-03-30 10:47:28 +00:00
|
|
|
|
|
|
|
GList *headers;
|
|
|
|
gboolean new_headers;
|
2012-07-23 08:20:05 +00:00
|
|
|
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
2011-09-05 14:01:09 +00:00
|
|
|
} GstAudioEncoderContext;
|
2011-08-16 16:23:14 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
struct _GstAudioEncoderPrivate
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
|
|
|
/* activation status */
|
|
|
|
gboolean active;
|
|
|
|
|
|
|
|
/* input base/first ts as basis for output ts;
|
|
|
|
* kept nearly constant for perfect_ts,
|
|
|
|
* otherwise resyncs to upstream ts */
|
|
|
|
GstClockTime base_ts;
|
|
|
|
/* corresponding base granulepos */
|
|
|
|
gint64 base_gp;
|
|
|
|
/* input samples processed and sent downstream so far (w.r.t. base_ts) */
|
|
|
|
guint64 samples;
|
|
|
|
|
|
|
|
/* currently collected sample data */
|
|
|
|
GstAdapter *adapter;
|
|
|
|
/* offset in adapter up to which already supplied to encoder */
|
|
|
|
gint offset;
|
|
|
|
/* mark outgoing discont */
|
|
|
|
gboolean discont;
|
|
|
|
/* to guess duration of drained data */
|
|
|
|
GstClockTime last_duration;
|
|
|
|
|
|
|
|
/* subclass provided data in processing round */
|
|
|
|
gboolean got_data;
|
|
|
|
/* subclass gave all it could already */
|
|
|
|
gboolean drained;
|
|
|
|
/* subclass currently being forcibly drained */
|
|
|
|
gboolean force;
|
2012-07-26 12:27:38 +00:00
|
|
|
/* need to handle changed input caps */
|
|
|
|
gboolean do_caps;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* output bps estimatation */
|
|
|
|
/* global in samples seen */
|
|
|
|
guint64 samples_in;
|
|
|
|
/* global bytes sent out */
|
|
|
|
guint64 bytes_out;
|
|
|
|
|
|
|
|
/* context storage */
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderContext ctx;
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
gint64 tolerance;
|
|
|
|
gboolean perfect_ts;
|
|
|
|
gboolean hard_resync;
|
|
|
|
gboolean granule;
|
2012-02-16 11:18:03 +00:00
|
|
|
gboolean hard_min;
|
|
|
|
gboolean drainable;
|
2011-09-26 12:48:55 +00:00
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
/* upstream stream tags (global tags are passed through as-is) */
|
|
|
|
GstTagList *upstream_tags;
|
|
|
|
|
|
|
|
/* subclass tags */
|
2011-09-26 12:48:55 +00:00
|
|
|
GstTagList *tags;
|
2015-08-18 10:45:24 +00:00
|
|
|
GstTagMergeMode tags_merge_mode;
|
|
|
|
|
2012-08-09 13:48:03 +00:00
|
|
|
gboolean tags_changed;
|
2015-08-18 10:45:24 +00:00
|
|
|
|
2011-09-26 13:42:14 +00:00
|
|
|
/* pending serialized sink events, will be sent from finish_frame() */
|
|
|
|
GList *pending_events;
|
2011-01-27 15:52:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2018-06-23 19:33:16 +00:00
|
|
|
static gint private_offset = 0;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
static void gst_audio_encoder_class_init (GstAudioEncoderClass * klass);
|
|
|
|
static void gst_audio_encoder_init (GstAudioEncoder * parse,
|
|
|
|
GstAudioEncoderClass * klass);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
GType
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_type (void)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
static GType audio_encoder_type = 0;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
if (!audio_encoder_type) {
|
|
|
|
static const GTypeInfo audio_encoder_info = {
|
|
|
|
sizeof (GstAudioEncoderClass),
|
2011-01-27 15:52:50 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2011-09-05 14:01:09 +00:00
|
|
|
(GClassInitFunc) gst_audio_encoder_class_init,
|
2011-01-27 15:52:50 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-09-05 14:01:09 +00:00
|
|
|
sizeof (GstAudioEncoder),
|
2011-01-27 15:52:50 +00:00
|
|
|
0,
|
2011-09-05 14:01:09 +00:00
|
|
|
(GInstanceInitFunc) gst_audio_encoder_init,
|
2011-01-27 15:52:50 +00:00
|
|
|
};
|
|
|
|
const GInterfaceInfo preset_interface_info = {
|
|
|
|
NULL, /* interface_init */
|
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
audio_encoder_type = g_type_register_static (GST_TYPE_ELEMENT,
|
|
|
|
"GstAudioEncoder", &audio_encoder_info, G_TYPE_FLAG_ABSTRACT);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
private_offset =
|
|
|
|
g_type_add_instance_private (audio_encoder_type,
|
|
|
|
sizeof (GstAudioEncoderPrivate));
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
g_type_add_interface_static (audio_encoder_type, GST_TYPE_PRESET,
|
2011-01-27 15:52:50 +00:00
|
|
|
&preset_interface_info);
|
|
|
|
}
|
2011-09-05 14:01:09 +00:00
|
|
|
return audio_encoder_type;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
static inline GstAudioEncoderPrivate *
|
|
|
|
gst_audio_encoder_get_instance_private (GstAudioEncoder * self)
|
|
|
|
{
|
|
|
|
return (G_STRUCT_MEMBER_P (self, private_offset));
|
|
|
|
}
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
static void gst_audio_encoder_finalize (GObject * object);
|
|
|
|
static void gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
static void gst_audio_encoder_set_property (GObject * object,
|
2011-01-27 15:52:50 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2011-09-05 14:01:09 +00:00
|
|
|
static void gst_audio_encoder_get_property (GObject * object,
|
2011-01-27 15:52:50 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-11-21 12:35:34 +00:00
|
|
|
static gboolean gst_audio_encoder_sink_activate_mode (GstPad * pad,
|
|
|
|
GstObject * parent, GstPadMode mode, gboolean active);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-11-15 15:30:38 +00:00
|
|
|
static GstCaps *gst_audio_encoder_getcaps_default (GstAudioEncoder * enc,
|
|
|
|
GstCaps * filter);
|
|
|
|
|
2012-02-27 11:49:52 +00:00
|
|
|
static gboolean gst_audio_encoder_sink_event_default (GstAudioEncoder * enc,
|
|
|
|
GstEvent * event);
|
2012-03-30 10:15:27 +00:00
|
|
|
static gboolean gst_audio_encoder_src_event_default (GstAudioEncoder * enc,
|
|
|
|
GstEvent * event);
|
2011-11-17 11:48:25 +00:00
|
|
|
static gboolean gst_audio_encoder_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2012-03-30 10:15:27 +00:00
|
|
|
static gboolean gst_audio_encoder_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2011-09-06 13:24:32 +00:00
|
|
|
static gboolean gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc,
|
|
|
|
GstCaps * caps);
|
2011-11-17 11:48:25 +00:00
|
|
|
static GstFlowReturn gst_audio_encoder_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
2011-11-16 16:25:17 +00:00
|
|
|
static gboolean gst_audio_encoder_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_audio_encoder_sink_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2012-03-09 09:54:48 +00:00
|
|
|
static GstStateChangeReturn gst_audio_encoder_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2012-07-23 08:20:05 +00:00
|
|
|
static gboolean gst_audio_encoder_decide_allocation_default (GstAudioEncoder *
|
|
|
|
enc, GstQuery * query);
|
|
|
|
static gboolean gst_audio_encoder_propose_allocation_default (GstAudioEncoder *
|
|
|
|
enc, GstQuery * query);
|
2012-08-09 13:27:33 +00:00
|
|
|
static gboolean gst_audio_encoder_negotiate_default (GstAudioEncoder * enc);
|
2013-12-05 14:39:57 +00:00
|
|
|
static gboolean gst_audio_encoder_negotiate_unlocked (GstAudioEncoder * enc);
|
2012-07-23 08:20:05 +00:00
|
|
|
|
2015-06-29 15:38:38 +00:00
|
|
|
static gboolean gst_audio_encoder_transform_meta_default (GstAudioEncoder *
|
|
|
|
encoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
|
|
|
|
|
2015-08-16 11:12:01 +00:00
|
|
|
static gboolean gst_audio_encoder_sink_query_default (GstAudioEncoder * encoder,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_audio_encoder_src_query_default (GstAudioEncoder * encoder,
|
|
|
|
GstQuery * query);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_class_init (GstAudioEncoderClass * klass)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-03-09 09:54:48 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2012-03-09 09:54:48 +00:00
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
2011-01-27 15:52:50 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_audio_encoder_debug, "audioencoder", 0,
|
|
|
|
"audio encoder base class");
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
if (private_offset != 0)
|
|
|
|
g_type_class_adjust_private_offset (klass, &private_offset);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
gobject_class->set_property = gst_audio_encoder_set_property;
|
|
|
|
gobject_class->get_property = gst_audio_encoder_get_property;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_audio_encoder_finalize);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PERFECT_TS,
|
2011-08-16 16:25:43 +00:00
|
|
|
g_param_spec_boolean ("perfect-timestamp", "Perfect Timestamps",
|
2011-01-27 15:52:50 +00:00
|
|
|
"Favour perfect timestamps over tracking upstream timestamps",
|
|
|
|
DEFAULT_PERFECT_TS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_GRANULE,
|
2011-08-16 16:25:43 +00:00
|
|
|
g_param_spec_boolean ("mark-granule", "Granule Marking",
|
2011-09-05 19:45:22 +00:00
|
|
|
"Apply granule semantics to buffer metadata (implies perfect-timestamp)",
|
2011-01-27 15:52:50 +00:00
|
|
|
DEFAULT_GRANULE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_HARD_RESYNC,
|
2011-03-09 11:24:34 +00:00
|
|
|
g_param_spec_boolean ("hard-resync", "Hard Resync",
|
2011-01-27 15:52:50 +00:00
|
|
|
"Perform clipping and sample flushing upon discontinuity",
|
|
|
|
DEFAULT_HARD_RESYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TOLERANCE,
|
2011-03-09 11:24:34 +00:00
|
|
|
g_param_spec_int64 ("tolerance", "Tolerance",
|
2011-03-15 16:27:42 +00:00
|
|
|
"Consider discontinuity if timestamp jitter/imperfection exceeds tolerance (ns)",
|
2011-01-27 15:52:50 +00:00
|
|
|
0, G_MAXINT64, DEFAULT_TOLERANCE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-11-15 15:30:38 +00:00
|
|
|
|
2012-03-09 09:54:48 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_change_state);
|
2012-03-22 10:35:13 +00:00
|
|
|
|
2011-11-15 15:30:38 +00:00
|
|
|
klass->getcaps = gst_audio_encoder_getcaps_default;
|
2012-03-30 10:15:27 +00:00
|
|
|
klass->sink_event = gst_audio_encoder_sink_event_default;
|
|
|
|
klass->src_event = gst_audio_encoder_src_event_default;
|
2015-08-16 11:12:01 +00:00
|
|
|
klass->sink_query = gst_audio_encoder_sink_query_default;
|
|
|
|
klass->src_query = gst_audio_encoder_src_query_default;
|
2012-07-23 08:20:05 +00:00
|
|
|
klass->propose_allocation = gst_audio_encoder_propose_allocation_default;
|
|
|
|
klass->decide_allocation = gst_audio_encoder_decide_allocation_default;
|
2012-08-09 13:27:33 +00:00
|
|
|
klass->negotiate = gst_audio_encoder_negotiate_default;
|
2015-06-29 15:38:38 +00:00
|
|
|
klass->transform_meta = gst_audio_encoder_transform_meta_default;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_init (GstAudioEncoder * enc, GstAudioEncoderClass * bclass)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
|
|
|
GstPadTemplate *pad_template;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "gst_audio_encoder_init");
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
enc->priv = gst_audio_encoder_get_instance_private (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* only push mode supported */
|
|
|
|
pad_template =
|
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
|
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
enc->sinkpad = gst_pad_new_from_template (pad_template, "sink");
|
|
|
|
gst_pad_set_event_function (enc->sinkpad,
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_sink_event));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_pad_set_query_function (enc->sinkpad,
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_sink_query));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_pad_set_chain_function (enc->sinkpad,
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_chain));
|
2011-11-21 12:35:34 +00:00
|
|
|
gst_pad_set_activatemode_function (enc->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_sink_activate_mode));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "sinkpad created");
|
|
|
|
|
|
|
|
/* and we don't mind upstream traveling stuff that much ... */
|
|
|
|
pad_template =
|
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
|
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
enc->srcpad = gst_pad_new_from_template (pad_template, "src");
|
2012-03-30 10:15:27 +00:00
|
|
|
gst_pad_set_event_function (enc->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_src_event));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_pad_set_query_function (enc->srcpad,
|
2011-09-05 14:01:09 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_audio_encoder_src_query));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_pad_use_fixed_caps (enc->srcpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
|
|
|
|
GST_DEBUG_OBJECT (enc, "src created");
|
|
|
|
|
|
|
|
enc->priv->adapter = gst_adapter_new ();
|
|
|
|
|
2012-01-19 08:48:38 +00:00
|
|
|
g_rec_mutex_init (&enc->stream_lock);
|
2011-09-26 13:45:40 +00:00
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* property default */
|
2011-08-16 16:59:13 +00:00
|
|
|
enc->priv->granule = DEFAULT_GRANULE;
|
|
|
|
enc->priv->perfect_ts = DEFAULT_PERFECT_TS;
|
|
|
|
enc->priv->hard_resync = DEFAULT_HARD_RESYNC;
|
|
|
|
enc->priv->tolerance = DEFAULT_TOLERANCE;
|
2012-02-16 11:18:03 +00:00
|
|
|
enc->priv->hard_min = DEFAULT_HARD_MIN;
|
|
|
|
enc->priv->drainable = DEFAULT_DRAINABLE;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* init state */
|
2015-02-03 11:12:18 +00:00
|
|
|
enc->priv->ctx.min_latency = 0;
|
2015-02-11 12:43:11 +00:00
|
|
|
enc->priv->ctx.max_latency = 0;
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_reset (enc, TRUE);
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "init ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-26 12:48:55 +00:00
|
|
|
GST_LOG_OBJECT (enc, "reset full %d", full);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
if (full) {
|
|
|
|
enc->priv->active = FALSE;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
enc->priv->samples_in = 0;
|
|
|
|
enc->priv->bytes_out = 0;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2011-09-26 12:48:55 +00:00
|
|
|
|
2012-03-30 10:47:28 +00:00
|
|
|
g_list_foreach (enc->priv->ctx.headers, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (enc->priv->ctx.headers);
|
|
|
|
enc->priv->ctx.headers = NULL;
|
|
|
|
enc->priv->ctx.new_headers = FALSE;
|
|
|
|
|
2013-06-19 11:21:45 +00:00
|
|
|
if (enc->priv->ctx.allocator)
|
|
|
|
gst_object_unref (enc->priv->ctx.allocator);
|
|
|
|
enc->priv->ctx.allocator = NULL;
|
|
|
|
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2013-06-19 11:21:45 +00:00
|
|
|
gst_caps_replace (&enc->priv->ctx.input_caps, NULL);
|
2012-09-06 10:15:59 +00:00
|
|
|
gst_caps_replace (&enc->priv->ctx.caps, NULL);
|
2016-04-01 10:25:14 +00:00
|
|
|
gst_caps_replace (&enc->priv->ctx.allocation_caps, NULL);
|
2013-06-19 11:21:45 +00:00
|
|
|
|
2012-04-04 17:43:32 +00:00
|
|
|
memset (&enc->priv->ctx, 0, sizeof (enc->priv->ctx));
|
|
|
|
gst_audio_info_init (&enc->priv->ctx.info);
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2012-04-04 17:43:32 +00:00
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
if (enc->priv->upstream_tags) {
|
|
|
|
gst_tag_list_unref (enc->priv->upstream_tags);
|
|
|
|
enc->priv->upstream_tags = NULL;
|
|
|
|
}
|
2011-09-26 12:48:55 +00:00
|
|
|
if (enc->priv->tags)
|
2012-09-14 15:53:21 +00:00
|
|
|
gst_tag_list_unref (enc->priv->tags);
|
2011-09-26 12:48:55 +00:00
|
|
|
enc->priv->tags = NULL;
|
2015-08-18 10:45:24 +00:00
|
|
|
enc->priv->tags_merge_mode = GST_TAG_MERGE_APPEND;
|
2012-08-09 13:48:03 +00:00
|
|
|
enc->priv->tags_changed = FALSE;
|
2011-09-26 13:42:14 +00:00
|
|
|
|
|
|
|
g_list_foreach (enc->priv->pending_events, (GFunc) gst_event_unref, NULL);
|
|
|
|
g_list_free (enc->priv->pending_events);
|
|
|
|
enc->priv->pending_events = NULL;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 11:21:09 +00:00
|
|
|
gst_segment_init (&enc->input_segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (&enc->output_segment, GST_FORMAT_TIME);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
gst_adapter_clear (enc->priv->adapter);
|
|
|
|
enc->priv->got_data = FALSE;
|
|
|
|
enc->priv->drained = TRUE;
|
|
|
|
enc->priv->offset = 0;
|
|
|
|
enc->priv->base_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
enc->priv->base_gp = -1;
|
|
|
|
enc->priv->samples = 0;
|
|
|
|
enc->priv->discont = FALSE;
|
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_finalize (GObject * object)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc = GST_AUDIO_ENCODER (object);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
g_object_unref (enc->priv->adapter);
|
|
|
|
|
2012-01-19 08:48:38 +00:00
|
|
|
g_rec_mutex_clear (&enc->stream_lock);
|
2011-09-26 13:45:40 +00:00
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2012-03-09 09:54:48 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_audio_encoder_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
GstAudioEncoder *enc = GST_AUDIO_ENCODER (element);
|
|
|
|
GstAudioEncoderClass *klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
if (klass->open) {
|
|
|
|
if (!klass->open (enc))
|
|
|
|
goto open_failed;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
if (klass->close) {
|
|
|
|
if (!klass->close (enc))
|
|
|
|
goto close_failed;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), ("Failed to open codec"));
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
close_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), ("Failed to close codec"));
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 11:21:09 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_push_event (GstAudioEncoder * enc, GstEvent * event)
|
|
|
|
{
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEGMENT:{
|
|
|
|
GstSegment seg;
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
gst_event_copy_segment (event, &seg);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "starting segment %" GST_SEGMENT_FORMAT, &seg);
|
|
|
|
|
|
|
|
enc->output_segment = seg;
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_pad_push_event (enc->srcpad, event);
|
|
|
|
}
|
|
|
|
|
2014-01-29 15:32:16 +00:00
|
|
|
static inline void
|
|
|
|
gst_audio_encoder_push_pending_events (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
GstAudioEncoderPrivate *priv = enc->priv;
|
|
|
|
|
|
|
|
if (priv->pending_events) {
|
|
|
|
GList *pending_events, *l;
|
|
|
|
|
|
|
|
pending_events = priv->pending_events;
|
|
|
|
priv->pending_events = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "Pushing pending events");
|
|
|
|
for (l = pending_events; l; l = l->next)
|
|
|
|
gst_audio_encoder_push_event (enc, l->data);
|
|
|
|
g_list_free (pending_events);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
static GstEvent *
|
|
|
|
gst_audio_encoder_create_merged_tags_event (GstAudioEncoder * enc)
|
2014-01-29 15:32:16 +00:00
|
|
|
{
|
2015-08-18 10:45:24 +00:00
|
|
|
GstTagList *merged_tags;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "upstream : %" GST_PTR_FORMAT, enc->priv->upstream_tags);
|
|
|
|
GST_LOG_OBJECT (enc, "encoder : %" GST_PTR_FORMAT, enc->priv->tags);
|
|
|
|
GST_LOG_OBJECT (enc, "mode : %d", enc->priv->tags_merge_mode);
|
|
|
|
|
|
|
|
merged_tags =
|
|
|
|
gst_tag_list_merge (enc->priv->upstream_tags, enc->priv->tags,
|
|
|
|
enc->priv->tags_merge_mode);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "merged : %" GST_PTR_FORMAT, merged_tags);
|
|
|
|
|
|
|
|
if (merged_tags == NULL)
|
|
|
|
return NULL;
|
2014-01-29 15:32:16 +00:00
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
if (gst_tag_list_is_empty (merged_tags)) {
|
|
|
|
gst_tag_list_unref (merged_tags);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add codec info to pending tags */
|
2014-01-29 15:32:16 +00:00
|
|
|
#if 0
|
2015-08-18 10:45:24 +00:00
|
|
|
caps = gst_pad_get_current_caps (enc->srcpad);
|
|
|
|
gst_pb_utils_add_codec_description_to_tag_list (merged_tags,
|
|
|
|
GST_TAG_AUDIO_CODEC, caps);
|
2014-01-29 15:32:16 +00:00
|
|
|
#endif
|
2015-08-18 10:45:24 +00:00
|
|
|
|
|
|
|
return gst_event_new_tag (merged_tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_encoder_check_and_push_pending_tags (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
if (enc->priv->tags_changed) {
|
|
|
|
GstEvent *tags_event;
|
|
|
|
|
|
|
|
tags_event = gst_audio_encoder_create_merged_tags_event (enc);
|
|
|
|
|
|
|
|
if (tags_event != NULL)
|
|
|
|
gst_audio_encoder_push_event (enc, tags_event);
|
|
|
|
|
2014-01-29 15:32:16 +00:00
|
|
|
enc->priv->tags_changed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 15:38:38 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_transform_meta_default (GstAudioEncoder *
|
|
|
|
encoder, GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
|
|
|
|
{
|
|
|
|
const GstMetaInfo *info = meta->info;
|
|
|
|
const gchar *const *tags;
|
|
|
|
|
|
|
|
tags = gst_meta_api_type_get_tags (info->api);
|
|
|
|
|
|
|
|
if (!tags || (g_strv_length ((gchar **) tags) == 1
|
|
|
|
&& gst_meta_api_type_has_tag (info->api,
|
|
|
|
g_quark_from_string (GST_META_TAG_AUDIO_STR))))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstAudioEncoder *encoder;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
} CopyMetaData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
|
|
|
|
{
|
|
|
|
CopyMetaData *data = user_data;
|
|
|
|
GstAudioEncoder *encoder = data->encoder;
|
|
|
|
GstAudioEncoderClass *klass = GST_AUDIO_ENCODER_GET_CLASS (encoder);
|
|
|
|
GstBuffer *outbuf = data->outbuf;
|
|
|
|
const GstMetaInfo *info = (*meta)->info;
|
|
|
|
gboolean do_copy = FALSE;
|
|
|
|
|
2015-07-01 08:58:07 +00:00
|
|
|
if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
|
2015-06-29 15:38:38 +00:00
|
|
|
/* never call the transform_meta with memory specific metadata */
|
|
|
|
GST_DEBUG_OBJECT (encoder, "not copying memory specific metadata %s",
|
|
|
|
g_type_name (info->api));
|
|
|
|
do_copy = FALSE;
|
|
|
|
} else if (klass->transform_meta) {
|
|
|
|
do_copy = klass->transform_meta (encoder, outbuf, *meta, inbuf);
|
|
|
|
GST_DEBUG_OBJECT (encoder, "transformed metadata %s: copy: %d",
|
|
|
|
g_type_name (info->api), do_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we only copy metadata when the subclass implemented a transform_meta
|
|
|
|
* function and when it returns %TRUE */
|
2017-05-02 11:31:14 +00:00
|
|
|
if (do_copy && info->transform_func) {
|
2015-06-29 15:38:38 +00:00
|
|
|
GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
|
|
|
|
GST_DEBUG_OBJECT (encoder, "copy metadata %s", g_type_name (info->api));
|
|
|
|
/* simply copy then */
|
|
|
|
info->transform_func (outbuf, *meta, inbuf,
|
|
|
|
_gst_meta_transform_copy, ©_data);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-09 11:18:56 +00:00
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_finish_frame:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-01-27 15:52:50 +00:00
|
|
|
* @buffer: encoded data
|
|
|
|
* @samples: number of samples (per channel) represented by encoded data
|
|
|
|
*
|
2011-09-27 13:31:20 +00:00
|
|
|
* Collects encoded data and pushes encoded data downstream.
|
|
|
|
* Source pad caps must be set when this is called.
|
2011-01-27 15:52:50 +00:00
|
|
|
*
|
|
|
|
* If @samples < 0, then best estimate is all samples provided to encoder
|
|
|
|
* (subclass) so far. @buf may be NULL, in which case next number of @samples
|
|
|
|
* are considered discarded, e.g. as a result of discontinuous transmission,
|
2011-09-27 13:31:20 +00:00
|
|
|
* and a discontinuity is marked.
|
2011-01-27 15:52:50 +00:00
|
|
|
*
|
2018-04-02 06:34:58 +00:00
|
|
|
* Note that samples received in #GstAudioEncoderClass.handle_frame()
|
2011-11-28 10:30:18 +00:00
|
|
|
* may be invalidated by a call to this function.
|
|
|
|
*
|
2011-01-27 15:52:50 +00:00
|
|
|
* Returns: a #GstFlowReturn that should be escalated to caller (of caller)
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf,
|
2011-01-27 15:52:50 +00:00
|
|
|
gint samples)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
GstAudioEncoderPrivate *priv;
|
|
|
|
GstAudioEncoderContext *ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2013-12-05 14:39:57 +00:00
|
|
|
gboolean needs_reconfigure = FALSE;
|
2015-06-29 15:38:38 +00:00
|
|
|
GstBuffer *inbuf = NULL;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
priv = enc->priv;
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx = &enc->priv->ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* subclass should not hand us no data */
|
2011-08-29 11:28:08 +00:00
|
|
|
g_return_val_if_fail (buf == NULL || gst_buffer_get_size (buf) > 0,
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_FLOW_ERROR);
|
|
|
|
|
2012-01-02 14:39:58 +00:00
|
|
|
/* subclass should know what it is producing by now */
|
2012-08-09 13:20:45 +00:00
|
|
|
if (!ctx->caps)
|
2012-01-02 14:39:58 +00:00
|
|
|
goto no_caps;
|
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
|
2011-11-21 18:28:01 +00:00
|
|
|
GST_LOG_OBJECT (enc,
|
|
|
|
"accepting %" G_GSIZE_FORMAT " bytes encoded data as %d samples",
|
2011-09-28 09:35:46 +00:00
|
|
|
buf ? gst_buffer_get_size (buf) : -1, samples);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2013-12-05 14:39:57 +00:00
|
|
|
needs_reconfigure = gst_pad_check_reconfigure (enc->srcpad);
|
|
|
|
if (G_UNLIKELY (ctx->output_caps_changed || needs_reconfigure)) {
|
|
|
|
if (!gst_audio_encoder_negotiate_unlocked (enc)) {
|
2013-09-12 07:42:36 +00:00
|
|
|
gst_pad_mark_reconfigure (enc->srcpad);
|
2013-06-30 16:16:35 +00:00
|
|
|
if (GST_PAD_IS_FLUSHING (enc->srcpad))
|
|
|
|
ret = GST_FLOW_FLUSHING;
|
|
|
|
else
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
2016-05-06 14:30:57 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2012-07-23 10:01:12 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* mark subclass still alive and providing */
|
2011-09-27 14:18:05 +00:00
|
|
|
if (G_LIKELY (buf))
|
|
|
|
priv->got_data = TRUE;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2014-01-29 15:32:16 +00:00
|
|
|
gst_audio_encoder_push_pending_events (enc);
|
2011-09-26 13:42:14 +00:00
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
/* send after pending events, which likely includes segment event */
|
|
|
|
gst_audio_encoder_check_and_push_pending_tags (enc);
|
2011-09-26 12:48:55 +00:00
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* remove corresponding samples from input */
|
|
|
|
if (samples < 0)
|
2011-08-16 16:23:14 +00:00
|
|
|
samples = (enc->priv->offset / ctx->info.bpf);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (samples)) {
|
2011-03-10 13:28:48 +00:00
|
|
|
/* track upstream ts if so configured */
|
2011-08-16 16:59:13 +00:00
|
|
|
if (!enc->priv->perfect_ts) {
|
2011-01-27 15:52:50 +00:00
|
|
|
guint64 ts, distance;
|
|
|
|
|
2012-11-14 00:03:15 +00:00
|
|
|
ts = gst_adapter_prev_pts (priv->adapter, &distance);
|
2011-08-16 16:23:14 +00:00
|
|
|
g_assert (distance % ctx->info.bpf == 0);
|
|
|
|
distance /= ctx->info.bpf;
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc, "%" G_GUINT64_FORMAT " samples past prev_ts %"
|
|
|
|
GST_TIME_FORMAT, distance, GST_TIME_ARGS (ts));
|
|
|
|
GST_LOG_OBJECT (enc, "%" G_GUINT64_FORMAT " samples past base_ts %"
|
|
|
|
GST_TIME_FORMAT, priv->samples, GST_TIME_ARGS (priv->base_ts));
|
|
|
|
/* when draining adapter might be empty and no ts to offer */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (ts) && ts != priv->base_ts) {
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
GstClockTime old_ts, next_ts;
|
|
|
|
|
|
|
|
/* passed into another buffer;
|
|
|
|
* mild check for discontinuity and only mark if so */
|
|
|
|
next_ts = ts +
|
2011-08-16 16:23:14 +00:00
|
|
|
gst_util_uint64_scale (distance, GST_SECOND, ctx->info.rate);
|
2011-01-27 15:52:50 +00:00
|
|
|
old_ts = priv->base_ts +
|
2011-08-16 16:23:14 +00:00
|
|
|
gst_util_uint64_scale (priv->samples, GST_SECOND, ctx->info.rate);
|
2011-01-27 15:52:50 +00:00
|
|
|
diff = GST_CLOCK_DIFF (next_ts, old_ts);
|
|
|
|
GST_LOG_OBJECT (enc, "ts diff %d ms", (gint) (diff / GST_MSECOND));
|
|
|
|
/* only mark discontinuity if beyond tolerance */
|
2011-08-16 16:59:13 +00:00
|
|
|
if (G_UNLIKELY (diff < -enc->priv->tolerance ||
|
|
|
|
diff > enc->priv->tolerance)) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "marked discont");
|
|
|
|
priv->discont = TRUE;
|
|
|
|
}
|
2011-08-17 16:48:41 +00:00
|
|
|
if (diff > GST_SECOND / ctx->info.rate / 2 ||
|
2011-08-16 16:23:14 +00:00
|
|
|
diff < -GST_SECOND / ctx->info.rate / 2) {
|
2011-06-17 09:54:08 +00:00
|
|
|
GST_LOG_OBJECT (enc, "new upstream ts %" GST_TIME_FORMAT
|
|
|
|
" at distance %" G_GUINT64_FORMAT, GST_TIME_ARGS (ts), distance);
|
|
|
|
/* re-sync to upstream ts */
|
|
|
|
priv->base_ts = ts;
|
|
|
|
priv->samples = distance;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (enc, "new upstream ts only introduces jitter");
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* advance sample view */
|
2011-08-16 16:23:14 +00:00
|
|
|
if (G_UNLIKELY (samples * ctx->info.bpf > priv->offset)) {
|
2015-07-02 11:15:58 +00:00
|
|
|
guint avail = gst_adapter_available (priv->adapter);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
if (G_LIKELY (!priv->force)) {
|
2014-09-23 09:56:33 +00:00
|
|
|
/* we should have received EOS to enable force */
|
2011-01-27 15:52:50 +00:00
|
|
|
goto overflow;
|
|
|
|
} else {
|
|
|
|
priv->offset = 0;
|
2015-07-02 11:15:58 +00:00
|
|
|
if (avail > 0 && samples * ctx->info.bpf >= avail) {
|
|
|
|
inbuf = gst_adapter_take_buffer_fast (priv->adapter, avail);
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_adapter_clear (priv->adapter);
|
2015-07-02 11:15:58 +00:00
|
|
|
} else if (avail > 0) {
|
2015-06-29 15:38:38 +00:00
|
|
|
inbuf =
|
|
|
|
gst_adapter_take_buffer_fast (priv->adapter,
|
|
|
|
samples * ctx->info.bpf);
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-02 11:15:58 +00:00
|
|
|
guint avail = gst_adapter_available (priv->adapter);
|
|
|
|
|
|
|
|
if (avail > 0) {
|
|
|
|
inbuf =
|
|
|
|
gst_adapter_take_buffer_fast (priv->adapter,
|
|
|
|
samples * ctx->info.bpf);
|
|
|
|
}
|
2011-08-16 16:23:14 +00:00
|
|
|
priv->offset -= samples * ctx->info.bpf;
|
2011-01-27 15:52:50 +00:00
|
|
|
/* avoid subsequent stray prev_ts */
|
|
|
|
if (G_UNLIKELY (gst_adapter_available (priv->adapter) == 0))
|
|
|
|
gst_adapter_clear (priv->adapter);
|
|
|
|
}
|
2011-03-10 13:28:48 +00:00
|
|
|
/* sample count advanced below after buffer handling */
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* collect output */
|
2011-03-10 13:28:48 +00:00
|
|
|
if (G_LIKELY (buf)) {
|
2011-08-29 11:28:08 +00:00
|
|
|
gsize size;
|
|
|
|
|
2012-03-30 10:47:28 +00:00
|
|
|
/* Pushing headers first */
|
|
|
|
if (G_UNLIKELY (priv->ctx.new_headers)) {
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "Sending headers");
|
|
|
|
|
|
|
|
for (tmp = priv->ctx.headers; tmp; tmp = tmp->next) {
|
|
|
|
GstBuffer *tmpbuf = gst_buffer_ref (tmp->data);
|
|
|
|
|
|
|
|
tmpbuf = gst_buffer_make_writable (tmpbuf);
|
|
|
|
size = gst_buffer_get_size (tmpbuf);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (priv->discont)) {
|
|
|
|
GST_LOG_OBJECT (enc, "marking discont");
|
|
|
|
GST_BUFFER_FLAG_SET (tmpbuf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
priv->discont = FALSE;
|
|
|
|
}
|
2012-03-31 10:54:36 +00:00
|
|
|
|
|
|
|
/* Ogg codecs like Vorbis use offset/offset-end in a special
|
|
|
|
* way and both should be 0 for these codecs */
|
|
|
|
if (priv->base_gp >= 0) {
|
|
|
|
GST_BUFFER_OFFSET (tmpbuf) = 0;
|
|
|
|
GST_BUFFER_OFFSET_END (tmpbuf) = 0;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_OFFSET (tmpbuf) = priv->bytes_out;
|
|
|
|
GST_BUFFER_OFFSET_END (tmpbuf) = priv->bytes_out + size;
|
|
|
|
}
|
2012-03-30 10:47:28 +00:00
|
|
|
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2012-03-30 10:47:28 +00:00
|
|
|
priv->bytes_out += size;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2012-03-30 10:47:28 +00:00
|
|
|
|
2015-12-03 13:47:38 +00:00
|
|
|
ret = gst_pad_push (enc->srcpad, tmpbuf);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_WARNING_OBJECT (enc, "pushing header returned %s",
|
2016-11-15 12:27:17 +00:00
|
|
|
gst_flow_get_name (ret));
|
2015-12-03 13:47:38 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2012-03-30 10:47:28 +00:00
|
|
|
}
|
|
|
|
priv->ctx.new_headers = FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-29 11:28:08 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
|
|
|
|
2011-11-21 18:28:01 +00:00
|
|
|
GST_LOG_OBJECT (enc, "taking %" G_GSIZE_FORMAT " bytes for output", size);
|
2011-08-29 11:28:08 +00:00
|
|
|
buf = gst_buffer_make_writable (buf);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* decorate */
|
|
|
|
if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (priv->base_ts))) {
|
2015-10-12 11:02:58 +00:00
|
|
|
/* FIXME ? lookahead could lead to weird ts and duration ?
|
|
|
|
* (particularly if not in perfect mode) */
|
|
|
|
/* mind sample rounding and produce perfect output */
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = priv->base_ts +
|
|
|
|
gst_util_uint64_scale (priv->samples - ctx->lookahead, GST_SECOND,
|
|
|
|
ctx->info.rate);
|
|
|
|
GST_BUFFER_DTS (buf) = GST_BUFFER_TIMESTAMP (buf);
|
2011-03-10 13:28:48 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "out samples %d", samples);
|
|
|
|
if (G_LIKELY (samples > 0)) {
|
|
|
|
priv->samples += samples;
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = priv->base_ts +
|
|
|
|
gst_util_uint64_scale (priv->samples - ctx->lookahead, GST_SECOND,
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx->info.rate) - GST_BUFFER_TIMESTAMP (buf);
|
2011-01-27 15:52:50 +00:00
|
|
|
priv->last_duration = GST_BUFFER_DURATION (buf);
|
|
|
|
} else {
|
|
|
|
/* duration forecast in case of handling remainder;
|
|
|
|
* the last one is probably like the previous one ... */
|
|
|
|
GST_BUFFER_DURATION (buf) = priv->last_duration;
|
|
|
|
}
|
|
|
|
if (priv->base_gp >= 0) {
|
|
|
|
/* pamper oggmux */
|
|
|
|
/* FIXME: in longer run, muxer should take care of this ... */
|
|
|
|
/* offset_end = granulepos for ogg muxer */
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = priv->base_gp + priv->samples -
|
2011-08-16 16:23:14 +00:00
|
|
|
enc->priv->ctx.lookahead;
|
2011-01-27 15:52:50 +00:00
|
|
|
/* offset = timestamp corresponding to granulepos for ogg muxer */
|
|
|
|
GST_BUFFER_OFFSET (buf) =
|
|
|
|
GST_FRAMES_TO_CLOCK_TIME (GST_BUFFER_OFFSET_END (buf),
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx->info.rate);
|
2011-01-27 15:52:50 +00:00
|
|
|
} else {
|
|
|
|
GST_BUFFER_OFFSET (buf) = priv->bytes_out;
|
2011-08-29 11:28:08 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buf) = priv->bytes_out + size;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 15:38:38 +00:00
|
|
|
if (klass->transform_meta) {
|
|
|
|
if (G_LIKELY (inbuf)) {
|
|
|
|
CopyMetaData data;
|
|
|
|
|
|
|
|
data.encoder = enc;
|
|
|
|
data.outbuf = buf;
|
|
|
|
gst_buffer_foreach_meta (inbuf, foreach_metadata, &data);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (enc,
|
|
|
|
"Can't copy metadata because input buffer disappeared");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2011-08-29 11:28:08 +00:00
|
|
|
priv->bytes_out += size;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2011-03-10 13:28:48 +00:00
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
if (G_UNLIKELY (priv->discont)) {
|
|
|
|
GST_LOG_OBJECT (enc, "marking discont");
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
priv->discont = FALSE;
|
|
|
|
}
|
2011-03-10 13:28:48 +00:00
|
|
|
|
|
|
|
if (klass->pre_push) {
|
|
|
|
/* last chance for subclass to do some dirty stuff */
|
|
|
|
ret = klass->pre_push (enc, &buf);
|
|
|
|
if (ret != GST_FLOW_OK || !buf) {
|
|
|
|
GST_DEBUG_OBJECT (enc, "subclass returned %s, buf %p",
|
|
|
|
gst_flow_get_name (ret), buf);
|
2012-03-30 10:47:28 +00:00
|
|
|
|
2011-03-10 13:28:48 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-11-21 18:28:01 +00:00
|
|
|
GST_LOG_OBJECT (enc,
|
|
|
|
"pushing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
|
2011-08-29 11:28:08 +00:00
|
|
|
", duration %" GST_TIME_FORMAT, size,
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
|
|
|
|
|
|
|
ret = gst_pad_push (enc->srcpad, buf);
|
|
|
|
GST_LOG_OBJECT (enc, "buffer pushed: %s", gst_flow_get_name (ret));
|
2011-03-10 13:28:48 +00:00
|
|
|
} else {
|
|
|
|
/* merely advance samples, most work for that already done above */
|
|
|
|
priv->samples += samples;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 13:28:48 +00:00
|
|
|
exit:
|
2015-06-29 15:38:38 +00:00
|
|
|
if (inbuf)
|
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-01-02 14:39:58 +00:00
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, ("no caps set"), (NULL));
|
2012-04-04 17:43:32 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2012-01-02 14:39:58 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
overflow:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
|
2014-09-23 09:56:33 +00:00
|
|
|
("received more encoded samples %d than provided %d as inputs",
|
2011-08-16 16:23:14 +00:00
|
|
|
samples, priv->offset / ctx->info.bpf), (NULL));
|
2011-01-27 15:52:50 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2011-09-26 13:45:40 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
2014-09-23 09:56:33 +00:00
|
|
|
/* no way we can let this pass */
|
|
|
|
g_assert_not_reached ();
|
|
|
|
/* really no way */
|
2011-09-26 13:45:40 +00:00
|
|
|
goto exit;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adapter tracking idea:
|
|
|
|
* - start of adapter corresponds with what has already been encoded
|
|
|
|
* (i.e. really returned by encoder subclass)
|
|
|
|
* - start + offset is what needs to be fed to subclass next */
|
|
|
|
static GstFlowReturn
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_push_buffers (GstAudioEncoder * enc, gboolean force)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
GstAudioEncoderPrivate *priv;
|
|
|
|
GstAudioEncoderContext *ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
gint av, need;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (klass->handle_frame != NULL, GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
priv = enc->priv;
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx = &enc->priv->ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
while (ret == GST_FLOW_OK) {
|
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
av = gst_adapter_available (priv->adapter);
|
|
|
|
|
|
|
|
g_assert (priv->offset <= av);
|
|
|
|
av -= priv->offset;
|
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
need =
|
|
|
|
ctx->frame_samples_min >
|
|
|
|
0 ? ctx->frame_samples_min * ctx->info.bpf : av;
|
|
|
|
GST_LOG_OBJECT (enc, "available: %d, needed: %d, force: %d", av, need,
|
|
|
|
force);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
if ((need > av) || !av) {
|
|
|
|
if (G_UNLIKELY (force)) {
|
|
|
|
priv->force = TRUE;
|
|
|
|
need = av;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
priv->force = FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
if (ctx->frame_samples_max > 0)
|
|
|
|
need = MIN (av, ctx->frame_samples_max * ctx->info.bpf);
|
|
|
|
|
|
|
|
if (ctx->frame_samples_min == ctx->frame_samples_max) {
|
|
|
|
/* if we have some extra metadata,
|
|
|
|
* provide for integer multiple of frames to allow for better granularity
|
|
|
|
* of processing */
|
|
|
|
if (ctx->frame_samples_min > 0 && need) {
|
|
|
|
if (ctx->frame_max > 1)
|
|
|
|
need = need * MIN ((av / need), ctx->frame_max);
|
|
|
|
else if (ctx->frame_max == 0)
|
|
|
|
need = need * (av / need);
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 11:18:03 +00:00
|
|
|
priv->got_data = FALSE;
|
|
|
|
if (G_LIKELY (need)) {
|
2011-08-29 11:28:08 +00:00
|
|
|
const guint8 *data;
|
|
|
|
|
|
|
|
data = gst_adapter_map (priv->adapter, priv->offset + need);
|
|
|
|
buf =
|
2012-03-20 09:23:47 +00:00
|
|
|
gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
|
|
|
|
(gpointer) data, priv->offset + need, priv->offset, need, NULL, NULL);
|
2012-02-16 11:18:03 +00:00
|
|
|
} else if (!priv->drainable) {
|
|
|
|
GST_DEBUG_OBJECT (enc, "non-drainable and no more data");
|
|
|
|
goto finish;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "providing subclass with %d bytes at offset %d",
|
|
|
|
need, priv->offset);
|
|
|
|
|
|
|
|
/* mark this already as consumed,
|
|
|
|
* which it should be when subclass gives us data in exchange for samples */
|
|
|
|
priv->offset += need;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2011-08-16 16:23:14 +00:00
|
|
|
priv->samples_in += need / ctx->info.bpf;
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2012-02-16 11:18:03 +00:00
|
|
|
/* subclass might not want to be bothered with leftover data,
|
|
|
|
* so take care of that here if so, otherwise pass along */
|
|
|
|
if (G_UNLIKELY (priv->force && priv->hard_min && buf)) {
|
|
|
|
GST_DEBUG_OBJECT (enc, "bypassing subclass with leftover");
|
|
|
|
ret = gst_audio_encoder_finish_frame (enc, NULL, -1);
|
|
|
|
} else {
|
|
|
|
ret = klass->handle_frame (enc, buf);
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-08-29 11:28:08 +00:00
|
|
|
if (G_LIKELY (buf)) {
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_buffer_unref (buf);
|
2011-11-10 17:32:39 +00:00
|
|
|
gst_adapter_unmap (priv->adapter);
|
2011-08-29 11:28:08 +00:00
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2012-02-16 11:18:03 +00:00
|
|
|
finish:
|
2011-01-27 15:52:50 +00:00
|
|
|
/* no data to feed, no leftover provided, then bail out */
|
|
|
|
if (G_UNLIKELY (!buf && !priv->got_data)) {
|
|
|
|
priv->drained = TRUE;
|
|
|
|
GST_LOG_OBJECT (enc, "no more data drained from subclass");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_drain (GstAudioEncoder * enc)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-12-22 15:54:18 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "draining");
|
2011-01-27 15:52:50 +00:00
|
|
|
if (enc->priv->drained)
|
|
|
|
return GST_FLOW_OK;
|
2011-12-22 15:54:18 +00:00
|
|
|
else {
|
|
|
|
GST_DEBUG_OBJECT (enc, "... really");
|
2011-09-05 14:01:09 +00:00
|
|
|
return gst_audio_encoder_push_buffers (enc, TRUE);
|
2011-12-22 15:54:18 +00:00
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 10:09:56 +00:00
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_base_gp (GstAudioEncoder * enc)
|
2011-03-22 10:09:56 +00:00
|
|
|
{
|
|
|
|
GstClockTime ts;
|
|
|
|
|
2011-08-16 16:59:13 +00:00
|
|
|
if (!enc->priv->granule)
|
2011-03-22 10:09:56 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* use running time for granule */
|
|
|
|
/* incoming data is clipped, so a valid input should yield a valid output */
|
2012-03-30 11:21:09 +00:00
|
|
|
ts = gst_segment_to_running_time (&enc->input_segment, GST_FORMAT_TIME,
|
2011-03-22 10:09:56 +00:00
|
|
|
enc->priv->base_ts);
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
|
|
|
enc->priv->base_gp =
|
2011-08-16 16:23:14 +00:00
|
|
|
GST_CLOCK_TIME_TO_FRAMES (enc->priv->base_ts, enc->priv->ctx.info.rate);
|
2011-04-28 10:01:43 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "new base gp %" G_GINT64_FORMAT, enc->priv->base_gp);
|
2011-03-22 10:09:56 +00:00
|
|
|
} else {
|
|
|
|
/* should reasonably have a valid base,
|
|
|
|
* otherwise start at 0 if we did not already start there earlier */
|
|
|
|
if (enc->priv->base_gp < 0) {
|
|
|
|
enc->priv->base_gp = 0;
|
|
|
|
GST_DEBUG_OBJECT (enc, "new base gp %" G_GINT64_FORMAT,
|
2011-04-28 10:01:43 +00:00
|
|
|
enc->priv->base_gp);
|
2011-03-22 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc;
|
|
|
|
GstAudioEncoderPrivate *priv;
|
|
|
|
GstAudioEncoderContext *ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
gboolean discont;
|
2011-08-29 11:28:08 +00:00
|
|
|
gsize size;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
enc = GST_AUDIO_ENCODER (parent);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
priv = enc->priv;
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx = &enc->priv->ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
|
2012-07-26 12:27:38 +00:00
|
|
|
if (G_UNLIKELY (priv->do_caps)) {
|
|
|
|
GstCaps *caps = gst_pad_get_current_caps (enc->sinkpad);
|
|
|
|
if (!caps)
|
|
|
|
goto not_negotiated;
|
|
|
|
if (!gst_audio_encoder_sink_setcaps (enc, caps)) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
goto not_negotiated;
|
|
|
|
}
|
2012-09-06 10:15:59 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-07-26 12:27:38 +00:00
|
|
|
priv->do_caps = FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* should know what is coming by now */
|
2011-08-16 16:23:14 +00:00
|
|
|
if (!ctx->info.bpf)
|
2011-01-27 15:52:50 +00:00
|
|
|
goto not_negotiated;
|
|
|
|
|
2011-08-29 11:28:08 +00:00
|
|
|
size = gst_buffer_get_size (buffer);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc,
|
2011-11-21 18:28:01 +00:00
|
|
|
"received buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
|
2011-08-29 11:28:08 +00:00
|
|
|
", duration %" GST_TIME_FORMAT, size,
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
|
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
/* input should be whole number of sample frames */
|
2011-08-29 11:28:08 +00:00
|
|
|
if (size % ctx->info.bpf)
|
2011-01-27 15:52:50 +00:00
|
|
|
goto wrong_buffer;
|
|
|
|
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
{
|
|
|
|
GstClockTime duration;
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
|
|
|
|
/* verify buffer duration */
|
2011-08-29 11:28:08 +00:00
|
|
|
duration = gst_util_uint64_scale (size, GST_SECOND,
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx->info.rate * ctx->info.bpf);
|
2011-01-27 15:52:50 +00:00
|
|
|
diff = GST_CLOCK_DIFF (duration, GST_BUFFER_DURATION (buffer));
|
|
|
|
if (GST_BUFFER_DURATION (buffer) != GST_CLOCK_TIME_NONE &&
|
2011-08-16 16:23:14 +00:00
|
|
|
(diff > GST_SECOND / ctx->info.rate / 2 ||
|
|
|
|
diff < -GST_SECOND / ctx->info.rate / 2)) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "incoming buffer had incorrect duration %"
|
|
|
|
GST_TIME_FORMAT ", expected duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
|
|
|
|
GST_TIME_ARGS (duration));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
discont = GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
if (G_UNLIKELY (discont)) {
|
|
|
|
GST_LOG_OBJECT (buffer, "marked discont");
|
|
|
|
enc->priv->discont = discont;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clip to segment */
|
2012-03-30 11:21:09 +00:00
|
|
|
buffer = gst_audio_buffer_clip (buffer, &enc->input_segment, ctx->info.rate,
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx->info.bpf);
|
2011-01-27 15:52:50 +00:00
|
|
|
if (G_UNLIKELY (!buffer)) {
|
|
|
|
GST_DEBUG_OBJECT (buffer, "no data after clipping to segment");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-08-29 11:28:08 +00:00
|
|
|
size = gst_buffer_get_size (buffer);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc,
|
2011-11-21 18:28:01 +00:00
|
|
|
"buffer after segment clipping has size %" G_GSIZE_FORMAT " with ts %"
|
|
|
|
GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT, size,
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (priv->base_ts)) {
|
|
|
|
priv->base_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
GST_DEBUG_OBJECT (enc, "new base ts %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (priv->base_ts));
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_base_gp (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for continuity;
|
|
|
|
* checked elsewhere in non-perfect case */
|
2011-08-16 16:59:13 +00:00
|
|
|
if (enc->priv->perfect_ts) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GstClockTimeDiff diff = 0;
|
|
|
|
GstClockTime next_ts = 0;
|
|
|
|
|
|
|
|
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
|
|
|
|
GST_CLOCK_TIME_IS_VALID (priv->base_ts)) {
|
|
|
|
guint64 samples;
|
|
|
|
|
|
|
|
samples = priv->samples +
|
2011-08-16 16:23:14 +00:00
|
|
|
gst_adapter_available (priv->adapter) / ctx->info.bpf;
|
2011-01-27 15:52:50 +00:00
|
|
|
next_ts = priv->base_ts +
|
2011-08-16 16:23:14 +00:00
|
|
|
gst_util_uint64_scale (samples, GST_SECOND, ctx->info.rate);
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc, "buffer is %" G_GUINT64_FORMAT
|
|
|
|
" samples past base_ts %" GST_TIME_FORMAT
|
|
|
|
", expected ts %" GST_TIME_FORMAT, samples,
|
|
|
|
GST_TIME_ARGS (priv->base_ts), GST_TIME_ARGS (next_ts));
|
|
|
|
diff = GST_CLOCK_DIFF (next_ts, GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
GST_LOG_OBJECT (enc, "ts diff %d ms", (gint) (diff / GST_MSECOND));
|
|
|
|
/* if within tolerance,
|
|
|
|
* discard buffer ts and carry on producing perfect stream,
|
|
|
|
* otherwise clip or resync to ts */
|
2011-08-16 16:59:13 +00:00
|
|
|
if (G_UNLIKELY (diff < -enc->priv->tolerance ||
|
|
|
|
diff > enc->priv->tolerance)) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "marked discont");
|
|
|
|
discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do some fancy tweaking in hard resync case */
|
2011-08-16 16:59:13 +00:00
|
|
|
if (discont && enc->priv->hard_resync) {
|
2011-01-27 15:52:50 +00:00
|
|
|
if (diff < 0) {
|
|
|
|
guint64 diff_bytes;
|
|
|
|
|
|
|
|
GST_WARNING_OBJECT (enc, "Buffer is older than expected ts %"
|
|
|
|
GST_TIME_FORMAT ". Clipping buffer", GST_TIME_ARGS (next_ts));
|
|
|
|
|
|
|
|
diff_bytes =
|
2011-08-16 16:23:14 +00:00
|
|
|
GST_CLOCK_TIME_TO_FRAMES (-diff, ctx->info.rate) * ctx->info.bpf;
|
2011-08-29 11:28:08 +00:00
|
|
|
if (diff_bytes >= size) {
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
goto done;
|
|
|
|
}
|
2011-08-29 11:28:08 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
|
|
|
gst_buffer_resize (buffer, diff_bytes, size - diff_bytes);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) += diff;
|
|
|
|
/* care even less about duration after this */
|
|
|
|
} else {
|
|
|
|
/* drain stuff prior to resync */
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_drain (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-08 18:13:11 +00:00
|
|
|
if (discont) {
|
|
|
|
/* now re-sync ts */
|
2017-08-08 18:35:25 +00:00
|
|
|
GstClockTime shift =
|
|
|
|
gst_util_uint64_scale (gst_adapter_available (priv->adapter),
|
|
|
|
GST_SECOND, ctx->info.rate * ctx->info.bpf);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (shift > GST_BUFFER_TIMESTAMP (buffer))) {
|
|
|
|
/* ERROR */
|
|
|
|
goto wrong_time;
|
|
|
|
}
|
|
|
|
/* arrange for newly added samples to come out with the ts
|
|
|
|
* of the incoming buffer that adds these */
|
|
|
|
priv->base_ts = GST_BUFFER_TIMESTAMP (buffer) - shift;
|
|
|
|
priv->samples = 0;
|
2011-10-08 18:13:11 +00:00
|
|
|
gst_audio_encoder_set_base_gp (enc);
|
|
|
|
priv->discont |= discont;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_adapter_push (enc->priv->adapter, buffer);
|
|
|
|
/* new stuff, so we can push subclass again */
|
|
|
|
enc->priv->drained = FALSE;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
ret = gst_audio_encoder_push_buffers (enc, FALSE);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
GST_LOG_OBJECT (enc, "chain leaving");
|
2011-09-26 13:45:40 +00:00
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, CORE, NEGOTIATION, (NULL),
|
|
|
|
("encoder not initialized"));
|
|
|
|
gst_buffer_unref (buffer);
|
2011-09-26 13:45:40 +00:00
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto done;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
wrong_buffer:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),
|
2011-11-21 18:28:01 +00:00
|
|
|
("buffer size %" G_GSIZE_FORMAT " not a multiple of %d",
|
|
|
|
gst_buffer_get_size (buffer), ctx->info.bpf));
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2011-09-26 13:45:40 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
2017-08-08 18:35:25 +00:00
|
|
|
wrong_time:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),
|
|
|
|
("buffer going too far back in time"));
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 13:24:32 +00:00
|
|
|
gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc, GstCaps * caps)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
GstAudioEncoderContext *ctx;
|
2011-08-29 11:28:08 +00:00
|
|
|
GstAudioInfo state;
|
2013-04-18 07:54:48 +00:00
|
|
|
gboolean res = TRUE;
|
2011-08-27 11:39:50 +00:00
|
|
|
guint old_rate;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
/* subclass must do something here ... */
|
|
|
|
g_return_val_if_fail (klass->set_format != NULL, FALSE);
|
|
|
|
|
2011-08-16 16:23:14 +00:00
|
|
|
ctx = &enc->priv->ctx;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (!gst_caps_is_fixed (caps))
|
|
|
|
goto refuse_caps;
|
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
if (enc->priv->ctx.input_caps
|
|
|
|
&& gst_caps_is_equal (enc->priv->ctx.input_caps, caps))
|
|
|
|
goto same_caps;
|
|
|
|
|
|
|
|
if (!gst_audio_info_from_caps (&state, caps))
|
|
|
|
goto refuse_caps;
|
|
|
|
|
2013-06-01 07:05:16 +00:00
|
|
|
if (enc->priv->ctx.input_caps && gst_audio_info_is_equal (&state, &ctx->info))
|
2013-04-18 07:54:48 +00:00
|
|
|
goto same_caps;
|
|
|
|
|
2011-03-16 17:41:03 +00:00
|
|
|
/* adjust ts tracking to new sample rate */
|
2011-08-29 11:28:08 +00:00
|
|
|
old_rate = GST_AUDIO_INFO_RATE (&ctx->info);
|
2011-08-27 11:39:50 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (enc->priv->base_ts) && old_rate) {
|
2011-03-16 17:41:03 +00:00
|
|
|
enc->priv->base_ts +=
|
2011-08-27 11:39:50 +00:00
|
|
|
GST_FRAMES_TO_CLOCK_TIME (enc->priv->samples, old_rate);
|
2011-03-16 17:41:03 +00:00
|
|
|
enc->priv->samples = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
/* drain any pending old data stuff */
|
|
|
|
gst_audio_encoder_drain (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
/* context defaults */
|
2016-01-16 09:17:50 +00:00
|
|
|
/* FIXME 2.0: This is quite unexpected behaviour. We should never
|
|
|
|
* just reset *settings* of a subclass inside the base class */
|
2013-04-18 07:54:48 +00:00
|
|
|
enc->priv->ctx.frame_samples_min = 0;
|
|
|
|
enc->priv->ctx.frame_samples_max = 0;
|
|
|
|
enc->priv->ctx.frame_max = 0;
|
|
|
|
enc->priv->ctx.lookahead = 0;
|
2011-08-17 16:32:54 +00:00
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
if (klass->set_format)
|
|
|
|
res = klass->set_format (enc, &state);
|
2011-10-30 14:51:48 +00:00
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
if (res) {
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2013-04-18 07:54:48 +00:00
|
|
|
ctx->info = state;
|
|
|
|
gst_caps_replace (&enc->priv->ctx.input_caps, caps);
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2013-04-18 07:54:48 +00:00
|
|
|
} else {
|
2011-11-16 18:00:30 +00:00
|
|
|
/* invalidate state to ensure no casual carrying on */
|
2013-04-18 07:54:48 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "subclass did not accept format");
|
|
|
|
gst_audio_info_init (&state);
|
|
|
|
goto exit;
|
|
|
|
}
|
2011-11-16 18:00:30 +00:00
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
exit:
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
return res;
|
|
|
|
|
2013-04-18 07:54:48 +00:00
|
|
|
same_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (enc, "new audio format identical to configured format");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* ERRORS */
|
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (enc, "rejected caps %" GST_PTR_FORMAT, caps);
|
2011-09-26 13:45:40 +00:00
|
|
|
goto exit;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 11:18:56 +00:00
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_proxy_getcaps:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2014-12-17 22:14:38 +00:00
|
|
|
* @caps: (allow-none): initial caps
|
|
|
|
* @filter: (allow-none): filter caps
|
2011-01-27 15:52:50 +00:00
|
|
|
*
|
|
|
|
* Returns caps that express @caps (or sink template caps if @caps == NULL)
|
|
|
|
* restricted to channel/rate combinations supported by downstream elements
|
|
|
|
* (e.g. muxers).
|
|
|
|
*
|
2015-02-19 18:51:19 +00:00
|
|
|
* Returns: (transfer full): a #GstCaps owned by caller
|
2011-01-27 15:52:50 +00:00
|
|
|
*/
|
|
|
|
GstCaps *
|
2012-07-25 12:56:20 +00:00
|
|
|
gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc, GstCaps * caps,
|
|
|
|
GstCaps * filter)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2014-12-16 14:13:40 +00:00
|
|
|
return __gst_audio_element_proxy_getcaps (GST_ELEMENT_CAST (enc),
|
|
|
|
GST_AUDIO_ENCODER_SINK_PAD (enc), GST_AUDIO_ENCODER_SRC_PAD (enc),
|
|
|
|
caps, filter);
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2011-11-15 15:30:38 +00:00
|
|
|
gst_audio_encoder_getcaps_default (GstAudioEncoder * enc, GstCaps * filter)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2012-07-25 12:56:20 +00:00
|
|
|
caps = gst_audio_encoder_proxy_getcaps (enc, NULL, filter);
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc, "returning caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:48:47 +00:00
|
|
|
static GList *
|
|
|
|
_flush_events (GstPad * pad, GList * events)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
for (tmp = events; tmp; tmp = tmp->next) {
|
2014-09-17 12:18:49 +00:00
|
|
|
if (GST_EVENT_TYPE (tmp->data) != GST_EVENT_EOS &&
|
|
|
|
GST_EVENT_TYPE (tmp->data) != GST_EVENT_SEGMENT &&
|
|
|
|
GST_EVENT_IS_STICKY (tmp->data)) {
|
2013-10-10 21:48:47 +00:00
|
|
|
gst_pad_store_sticky_event (pad, GST_EVENT_CAST (tmp->data));
|
|
|
|
}
|
2014-09-17 12:18:49 +00:00
|
|
|
gst_event_unref (tmp->data);
|
2013-10-10 21:48:47 +00:00
|
|
|
}
|
|
|
|
g_list_free (events);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
static gboolean
|
2012-02-27 11:49:52 +00:00
|
|
|
gst_audio_encoder_sink_event_default (GstAudioEncoder * enc, GstEvent * event)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
2012-02-27 11:49:52 +00:00
|
|
|
gboolean res;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-08-29 11:28:08 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-08-29 11:28:08 +00:00
|
|
|
GstSegment seg;
|
|
|
|
|
|
|
|
gst_event_copy_segment (event, &seg);
|
|
|
|
|
|
|
|
if (seg.format == GST_FORMAT_TIME) {
|
2011-09-30 09:54:26 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "received TIME SEGMENT %" GST_SEGMENT_FORMAT,
|
|
|
|
&seg);
|
2011-01-27 15:52:50 +00:00
|
|
|
} else {
|
2011-09-30 09:54:26 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "received SEGMENT %" GST_SEGMENT_FORMAT, &seg);
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "unsupported format; ignoring");
|
2012-02-27 11:49:52 +00:00
|
|
|
res = TRUE;
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
/* finish current segment */
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_drain (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
/* reset partially for new segment */
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_reset (enc, FALSE);
|
2011-01-27 15:52:50 +00:00
|
|
|
/* and follow along with segment */
|
2012-03-30 11:21:09 +00:00
|
|
|
enc->input_segment = seg;
|
2012-03-05 11:25:50 +00:00
|
|
|
|
|
|
|
enc->priv->pending_events =
|
|
|
|
g_list_append (enc->priv->pending_events, event);
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2012-02-27 11:49:52 +00:00
|
|
|
|
|
|
|
res = TRUE;
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GST_EVENT_FLUSH_START:
|
2012-03-30 11:21:09 +00:00
|
|
|
res = gst_audio_encoder_push_event (enc, event);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
/* discard any pending stuff */
|
2011-03-16 17:41:03 +00:00
|
|
|
/* TODO route through drain ?? */
|
2011-01-27 15:52:50 +00:00
|
|
|
if (!enc->priv->drained && klass->flush)
|
|
|
|
klass->flush (enc);
|
|
|
|
/* and get (re)set for the sequel */
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_reset (enc, FALSE);
|
2011-09-26 13:42:14 +00:00
|
|
|
|
2013-10-10 21:48:47 +00:00
|
|
|
enc->priv->pending_events = _flush_events (enc->srcpad,
|
|
|
|
enc->priv->pending_events);
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2011-09-26 13:42:14 +00:00
|
|
|
|
2012-03-30 11:21:09 +00:00
|
|
|
res = gst_audio_encoder_push_event (enc, event);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_EVENT_EOS:
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_drain (enc);
|
2014-01-29 15:32:16 +00:00
|
|
|
|
|
|
|
/* check for pending events and tags */
|
|
|
|
gst_audio_encoder_push_pending_events (enc);
|
2015-08-18 10:45:24 +00:00
|
|
|
gst_audio_encoder_check_and_push_pending_tags (enc);
|
2014-01-29 15:32:16 +00:00
|
|
|
|
2011-09-26 13:45:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2012-02-27 11:49:52 +00:00
|
|
|
|
|
|
|
/* forward immediately because no buffer or serialized event
|
|
|
|
* will come after EOS and nothing could trigger another
|
|
|
|
* _finish_frame() call. */
|
2012-03-30 11:21:09 +00:00
|
|
|
res = gst_audio_encoder_push_event (enc, event);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-09 15:06:31 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
enc->priv->do_caps = TRUE;
|
|
|
|
res = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:45:24 +00:00
|
|
|
case GST_EVENT_STREAM_START:
|
|
|
|
{
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
/* Flush upstream tags after a STREAM_START */
|
|
|
|
GST_DEBUG_OBJECT (enc, "received STREAM_START. Clearing taglist");
|
|
|
|
if (enc->priv->upstream_tags) {
|
|
|
|
gst_tag_list_unref (enc->priv->upstream_tags);
|
|
|
|
enc->priv->upstream_tags = NULL;
|
|
|
|
enc->priv->tags_changed = TRUE;
|
|
|
|
}
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
res = gst_audio_encoder_push_event (enc, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-26 11:42:38 +00:00
|
|
|
case GST_EVENT_TAG:
|
|
|
|
{
|
|
|
|
GstTagList *tags;
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &tags);
|
|
|
|
|
2012-08-09 14:24:47 +00:00
|
|
|
if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_STREAM) {
|
2015-08-18 10:45:24 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
if (enc->priv->upstream_tags != tags) {
|
|
|
|
tags = gst_tag_list_copy (tags);
|
|
|
|
|
|
|
|
/* FIXME: make generic based on GST_TAG_FLAG_ENCODED */
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_CODEC);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_AUDIO_CODEC);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_VIDEO_CODEC);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_SUBTITLE_CODEC);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_CONTAINER_FORMAT);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_BITRATE);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_NOMINAL_BITRATE);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_MAXIMUM_BITRATE);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_MINIMUM_BITRATE);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_ENCODER);
|
|
|
|
gst_tag_list_remove_tag (tags, GST_TAG_ENCODER_VERSION);
|
|
|
|
|
|
|
|
if (enc->priv->upstream_tags)
|
|
|
|
gst_tag_list_unref (enc->priv->upstream_tags);
|
|
|
|
enc->priv->upstream_tags = tags;
|
|
|
|
GST_INFO_OBJECT (enc, "upstream stream tags: %" GST_PTR_FORMAT, tags);
|
|
|
|
}
|
2012-08-09 14:24:47 +00:00
|
|
|
gst_event_unref (event);
|
2015-08-18 10:45:24 +00:00
|
|
|
event = gst_audio_encoder_create_merged_tags_event (enc);
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2015-08-18 12:58:57 +00:00
|
|
|
|
|
|
|
/* No tags, go out of here instead of fall through */
|
|
|
|
if (!event) {
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-09 14:24:47 +00:00
|
|
|
}
|
2012-08-09 15:06:31 +00:00
|
|
|
/* fall through */
|
2011-08-29 11:28:08 +00:00
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
default:
|
2012-02-27 11:49:52 +00:00
|
|
|
/* Forward non-serialized events immediately. */
|
|
|
|
if (!GST_EVENT_IS_SERIALIZED (event)) {
|
|
|
|
res =
|
|
|
|
gst_pad_event_default (enc->sinkpad, GST_OBJECT_CAST (enc), event);
|
|
|
|
} else {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
enc->priv->pending_events =
|
|
|
|
g_list_append (enc->priv->pending_events, event);
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-27 11:49:52 +00:00
|
|
|
return res;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_audio_encoder_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc;
|
|
|
|
GstAudioEncoderClass *klass;
|
2012-02-27 11:49:52 +00:00
|
|
|
gboolean ret;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
enc = GST_AUDIO_ENCODER (parent);
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "received event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
2012-03-30 10:15:27 +00:00
|
|
|
if (klass->sink_event)
|
|
|
|
ret = klass->sink_event (enc, event);
|
2012-02-27 12:08:36 +00:00
|
|
|
else {
|
|
|
|
gst_event_unref (event);
|
2012-02-27 11:49:52 +00:00
|
|
|
ret = FALSE;
|
2012-02-27 12:08:36 +00:00
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2012-02-27 11:49:52 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "event result %d", ret);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-08-16 11:12:01 +00:00
|
|
|
gst_audio_encoder_sink_query_default (GstAudioEncoder * enc, GstQuery * query)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2015-08-16 11:12:01 +00:00
|
|
|
GstPad *pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
|
2011-11-15 15:30:38 +00:00
|
|
|
gboolean res = FALSE;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_FORMATS:
|
|
|
|
{
|
|
|
|
gst_query_set_formats (query, 3,
|
|
|
|
GST_FORMAT_TIME, GST_FORMAT_BYTES, GST_FORMAT_DEFAULT);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
res = gst_audio_info_convert (&enc->priv->ctx.info,
|
|
|
|
src_fmt, src_val, dest_fmt, &dest_val);
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
if (!res)
|
2011-01-27 15:52:50 +00:00
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
2011-11-15 15:30:38 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
|
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
if (klass->getcaps) {
|
|
|
|
caps = klass->getcaps (enc, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-23 08:20:05 +00:00
|
|
|
case GST_QUERY_ALLOCATION:
|
|
|
|
{
|
|
|
|
GstAudioEncoderClass *klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
|
|
|
|
if (klass->propose_allocation)
|
|
|
|
res = klass->propose_allocation (enc, query);
|
|
|
|
break;
|
|
|
|
}
|
2011-01-27 15:52:50 +00:00
|
|
|
default:
|
2015-08-16 11:12:01 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT (enc), query);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-08-16 11:12:01 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_sink_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAudioEncoder *encoder;
|
|
|
|
GstAudioEncoderClass *encoder_class;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
encoder = GST_AUDIO_ENCODER (parent);
|
|
|
|
encoder_class = GST_AUDIO_ENCODER_GET_CLASS (encoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (encoder, "received query %d, %s", GST_QUERY_TYPE (query),
|
|
|
|
GST_QUERY_TYPE_NAME (query));
|
|
|
|
|
|
|
|
if (encoder_class->sink_query)
|
|
|
|
ret = encoder_class->sink_query (encoder, query);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-30 10:15:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_src_event_default (GstAudioEncoder * enc, GstEvent * event)
|
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (enc->srcpad, GST_OBJECT_CAST (enc), event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstAudioEncoder *enc;
|
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
enc = GST_AUDIO_ENCODER (parent);
|
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "received event %d, %s", GST_EVENT_TYPE (event),
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
if (klass->src_event)
|
|
|
|
ret = klass->src_event (enc, event);
|
|
|
|
else {
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-23 08:20:05 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_decide_allocation_default (GstAudioEncoder * enc,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAllocator *allocator = NULL;
|
|
|
|
GstAllocationParams params;
|
|
|
|
gboolean update_allocator;
|
|
|
|
|
|
|
|
/* we got configuration from our peer or the decide_allocation method,
|
|
|
|
* parse them */
|
|
|
|
if (gst_query_get_n_allocation_params (query) > 0) {
|
|
|
|
/* try the allocator */
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
|
|
|
update_allocator = TRUE;
|
|
|
|
} else {
|
|
|
|
allocator = NULL;
|
|
|
|
gst_allocation_params_init (¶ms);
|
|
|
|
update_allocator = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_allocator)
|
|
|
|
gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_propose_allocation_default (GstAudioEncoder * enc,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
/* FIXME ? are any of these queries (other than latency) an encoder's business
|
|
|
|
* also, the conversion stuff might seem to make sense, but seems to not mind
|
|
|
|
* segment stuff etc at all
|
|
|
|
* Supposedly that's backward compatibility ... */
|
|
|
|
static gboolean
|
2015-08-16 11:12:01 +00:00
|
|
|
gst_audio_encoder_src_query_default (GstAudioEncoder * enc, GstQuery * query)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2015-08-16 11:12:01 +00:00
|
|
|
GstPad *pad = GST_AUDIO_ENCODER_SRC_PAD (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "handling query: %" GST_PTR_FORMAT, query);
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat fmt, req_fmt;
|
|
|
|
gint64 pos, val;
|
|
|
|
|
2011-03-15 16:27:42 +00:00
|
|
|
if ((res = gst_pad_peer_query (enc->sinkpad, query))) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc, "returning peer response");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_parse_position (query, &req_fmt, NULL);
|
2016-11-15 12:27:17 +00:00
|
|
|
|
|
|
|
/* Refuse BYTES format queries. If it made sense to
|
|
|
|
* * answer them, upstream would have already */
|
|
|
|
if (req_fmt == GST_FORMAT_BYTES) {
|
|
|
|
GST_LOG_OBJECT (enc, "Ignoring BYTES position query");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
fmt = GST_FORMAT_TIME;
|
2011-11-16 16:25:17 +00:00
|
|
|
if (!(res = gst_pad_peer_query_position (enc->sinkpad, fmt, &pos)))
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-16 16:25:17 +00:00
|
|
|
if ((res =
|
|
|
|
gst_pad_peer_query_convert (enc->sinkpad, fmt, pos, req_fmt,
|
|
|
|
&val))) {
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_query_set_position (query, req_fmt, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat fmt, req_fmt;
|
|
|
|
gint64 dur, val;
|
|
|
|
|
2011-03-15 16:27:42 +00:00
|
|
|
if ((res = gst_pad_peer_query (enc->sinkpad, query))) {
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_LOG_OBJECT (enc, "returning peer response");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &req_fmt, NULL);
|
2016-11-15 12:27:17 +00:00
|
|
|
|
|
|
|
/* Refuse BYTES format queries. If it made sense to
|
|
|
|
* * answer them, upstream would have already */
|
|
|
|
if (req_fmt == GST_FORMAT_BYTES) {
|
|
|
|
GST_LOG_OBJECT (enc, "Ignoring BYTES position query");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
fmt = GST_FORMAT_TIME;
|
2011-11-16 16:25:17 +00:00
|
|
|
if (!(res = gst_pad_peer_query_duration (enc->sinkpad, fmt, &dur)))
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-16 16:25:17 +00:00
|
|
|
if ((res =
|
|
|
|
gst_pad_peer_query_convert (enc->sinkpad, fmt, dur, req_fmt,
|
|
|
|
&val))) {
|
2011-01-27 15:52:50 +00:00
|
|
|
gst_query_set_duration (query, req_fmt, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_FORMATS:
|
|
|
|
{
|
|
|
|
gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
2016-07-04 09:07:54 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
res = __gst_audio_encoded_audio_convert (&enc->priv->ctx.info,
|
|
|
|
enc->priv->bytes_out, enc->priv->samples_in, src_fmt, src_val,
|
|
|
|
&dest_fmt, &dest_val);
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
if (!res)
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
2011-03-15 16:27:42 +00:00
|
|
|
if ((res = gst_pad_peer_query (enc->sinkpad, query))) {
|
2011-01-27 15:52:50 +00:00
|
|
|
gboolean live;
|
|
|
|
GstClockTime min_latency, max_latency;
|
|
|
|
|
|
|
|
gst_query_parse_latency (query, &live, &min_latency, &max_latency);
|
|
|
|
GST_DEBUG_OBJECT (enc, "Peer latency: live %d, min %"
|
|
|
|
GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
/* add our latency */
|
2015-02-11 12:43:11 +00:00
|
|
|
min_latency += enc->priv->ctx.min_latency;
|
|
|
|
if (max_latency == -1 || enc->priv->ctx.max_latency == -1)
|
|
|
|
max_latency = -1;
|
|
|
|
else
|
2011-08-16 16:23:14 +00:00
|
|
|
max_latency += enc->priv->ctx.max_latency;
|
2011-01-27 15:52:50 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
gst_query_set_latency (query, live, min_latency, max_latency);
|
|
|
|
}
|
2011-03-15 16:27:42 +00:00
|
|
|
break;
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
default:
|
2015-08-16 11:12:01 +00:00
|
|
|
res = gst_pad_query_default (pad, GST_OBJECT (enc), query);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-08-16 11:12:01 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAudioEncoder *encoder;
|
|
|
|
GstAudioEncoderClass *encoder_class;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
encoder = GST_AUDIO_ENCODER (parent);
|
|
|
|
encoder_class = GST_AUDIO_ENCODER_GET_CLASS (encoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (encoder, "received query %d, %s", GST_QUERY_TYPE (query),
|
|
|
|
GST_QUERY_TYPE_NAME (query));
|
|
|
|
|
|
|
|
if (encoder_class->src_query)
|
|
|
|
ret = encoder_class->src_query (encoder, query);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 15:52:50 +00:00
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_property (GObject * object, guint prop_id,
|
2011-01-27 15:52:50 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
enc = GST_AUDIO_ENCODER (object);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PERFECT_TS:
|
2011-08-16 16:59:13 +00:00
|
|
|
if (enc->priv->granule && !g_value_get_boolean (value))
|
2011-09-05 19:45:22 +00:00
|
|
|
GST_WARNING_OBJECT (enc, "perfect-timestamp can not be set FALSE "
|
|
|
|
"while granule handling is enabled");
|
2011-01-27 15:52:50 +00:00
|
|
|
else
|
2011-08-16 16:59:13 +00:00
|
|
|
enc->priv->perfect_ts = g_value_get_boolean (value);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_HARD_RESYNC:
|
2011-08-16 16:59:13 +00:00
|
|
|
enc->priv->hard_resync = g_value_get_boolean (value);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_TOLERANCE:
|
2011-08-16 16:59:13 +00:00
|
|
|
enc->priv->tolerance = g_value_get_int64 (value);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_property (GObject * object, guint prop_id,
|
2011-01-27 15:52:50 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
enc = GST_AUDIO_ENCODER (object);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PERFECT_TS:
|
2011-08-16 16:59:13 +00:00
|
|
|
g_value_set_boolean (value, enc->priv->perfect_ts);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_GRANULE:
|
2011-08-16 16:59:13 +00:00
|
|
|
g_value_set_boolean (value, enc->priv->granule);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_HARD_RESYNC:
|
2011-08-16 16:59:13 +00:00
|
|
|
g_value_set_boolean (value, enc->priv->hard_resync);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_TOLERANCE:
|
2011-08-16 16:59:13 +00:00
|
|
|
g_value_set_int64 (value, enc->priv->tolerance);
|
2011-01-27 15:52:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_activate (GstAudioEncoder * enc, gboolean active)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
2012-10-04 12:40:32 +00:00
|
|
|
gboolean result = TRUE;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-08-16 16:59:13 +00:00
|
|
|
g_return_val_if_fail (!enc->priv->granule || enc->priv->perfect_ts, FALSE);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "activate %d", active);
|
|
|
|
|
|
|
|
if (active) {
|
2014-12-22 10:36:58 +00:00
|
|
|
/* arrange clean state */
|
|
|
|
gst_audio_encoder_reset (enc, TRUE);
|
2011-09-26 12:48:55 +00:00
|
|
|
|
2012-10-04 12:40:32 +00:00
|
|
|
if (!enc->priv->active && klass->start)
|
|
|
|
result = klass->start (enc);
|
2011-01-27 15:52:50 +00:00
|
|
|
} else {
|
|
|
|
/* We must make sure streaming has finished before resetting things
|
|
|
|
* and calling the ::stop vfunc */
|
|
|
|
GST_PAD_STREAM_LOCK (enc->sinkpad);
|
|
|
|
GST_PAD_STREAM_UNLOCK (enc->sinkpad);
|
|
|
|
|
|
|
|
if (enc->priv->active && klass->stop)
|
|
|
|
result = klass->stop (enc);
|
|
|
|
|
|
|
|
/* clean up */
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_reset (enc, TRUE);
|
2011-01-27 15:52:50 +00:00
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (enc, "activate return: %d", result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-21 12:35:34 +00:00
|
|
|
gst_audio_encoder_sink_activate_mode (GstPad * pad, GstObject * parent,
|
|
|
|
GstPadMode mode, gboolean active)
|
2011-01-27 15:52:50 +00:00
|
|
|
{
|
|
|
|
gboolean result = TRUE;
|
2011-09-05 14:01:09 +00:00
|
|
|
GstAudioEncoder *enc;
|
2011-01-27 15:52:50 +00:00
|
|
|
|
2011-11-18 12:56:04 +00:00
|
|
|
enc = GST_AUDIO_ENCODER (parent);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "sink activate push %d", active);
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
result = gst_audio_encoder_activate (enc, active);
|
2011-01-27 15:52:50 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
enc->priv->active = active;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "sink activate push return: %d", result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_audio_info:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
2011-08-27 11:39:50 +00:00
|
|
|
* Returns: a #GstAudioInfo describing the input audio format
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
2011-08-27 11:39:50 +00:00
|
|
|
GstAudioInfo *
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_audio_info (GstAudioEncoder * enc)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), NULL);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
return &enc->priv->ctx.info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-26 13:59:22 +00:00
|
|
|
* gst_audio_encoder_set_frame_samples_min:
|
2011-09-05 14:01:09 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* @num: number of samples per frame
|
|
|
|
*
|
|
|
|
* Sets number of samples (per channel) subclass needs to be handed,
|
2011-09-26 13:59:22 +00:00
|
|
|
* at least or will be handed all available if 0.
|
|
|
|
*
|
2011-09-26 14:35:55 +00:00
|
|
|
* If an exact number of samples is required, gst_audio_encoder_set_frame_samples_max()
|
|
|
|
* must be called with the same number.
|
2016-01-16 09:17:50 +00:00
|
|
|
*
|
|
|
|
* Note: This value will be reset to 0 every time before
|
2018-04-02 06:34:58 +00:00
|
|
|
* #GstAudioEncoderClass.set_format() is called.
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-09-26 13:59:22 +00:00
|
|
|
gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:23:14 +00:00
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
enc->priv->ctx.frame_samples_min = num;
|
2012-12-02 12:33:43 +00:00
|
|
|
GST_LOG_OBJECT (enc, "set to %d", num);
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-26 13:59:22 +00:00
|
|
|
* gst_audio_encoder_get_frame_samples_min:
|
2011-09-05 14:01:09 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
2011-09-26 13:59:22 +00:00
|
|
|
* Returns: currently minimum requested samples per frame
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
gint
|
2011-09-26 13:59:22 +00:00
|
|
|
gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
return enc->priv->ctx.frame_samples_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_set_frame_samples_max:
|
2011-09-05 14:01:09 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* @num: number of samples per frame
|
|
|
|
*
|
|
|
|
* Sets number of samples (per channel) subclass needs to be handed,
|
2011-09-26 13:59:22 +00:00
|
|
|
* at most or will be handed all available if 0.
|
2011-08-27 12:15:54 +00:00
|
|
|
*
|
2011-09-26 14:35:55 +00:00
|
|
|
* If an exact number of samples is required, gst_audio_encoder_set_frame_samples_min()
|
|
|
|
* must be called with the same number.
|
2016-01-16 09:17:50 +00:00
|
|
|
*
|
|
|
|
* Note: This value will be reset to 0 every time before
|
2018-04-02 06:34:58 +00:00
|
|
|
* #GstAudioEncoderClass.set_format() is called.
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-09-26 13:59:22 +00:00
|
|
|
gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:23:14 +00:00
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
enc->priv->ctx.frame_samples_max = num;
|
2012-12-02 12:33:43 +00:00
|
|
|
GST_LOG_OBJECT (enc, "set to %d", num);
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-13 10:11:06 +00:00
|
|
|
* gst_audio_encoder_get_frame_samples_max:
|
2011-09-05 14:01:09 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
2011-09-26 13:59:22 +00:00
|
|
|
* Returns: currently maximum requested samples per frame
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
gint
|
2011-09-26 13:59:22 +00:00
|
|
|
gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
2011-09-26 13:59:22 +00:00
|
|
|
return enc->priv->ctx.frame_samples_max;
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_frame_max:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* @num: number of frames
|
|
|
|
*
|
2011-09-26 13:59:22 +00:00
|
|
|
* Sets max number of frames accepted at once (assumed minimally 1).
|
|
|
|
* Requires @frame_samples_min and @frame_samples_max to be the equal.
|
2016-01-16 09:17:50 +00:00
|
|
|
*
|
|
|
|
* Note: This value will be reset to 0 every time before
|
2018-04-02 06:34:58 +00:00
|
|
|
* #GstAudioEncoderClass.set_format() is called.
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
enc->priv->ctx.frame_max = num;
|
2012-12-02 12:33:43 +00:00
|
|
|
GST_LOG_OBJECT (enc, "set to %d", num);
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_frame_max:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
|
|
|
* Returns: currently configured maximum handled frames
|
|
|
|
*/
|
|
|
|
gint
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_frame_max (GstAudioEncoder * enc)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
return enc->priv->ctx.frame_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_lookahead:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* @num: lookahead
|
|
|
|
*
|
|
|
|
* Sets encoder lookahead (in units of input rate samples)
|
2016-01-16 09:17:50 +00:00
|
|
|
*
|
|
|
|
* Note: This value will be reset to 0 every time before
|
2018-04-02 06:34:58 +00:00
|
|
|
* #GstAudioEncoderClass.set_format() is called.
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
enc->priv->ctx.lookahead = num;
|
2012-12-02 12:33:43 +00:00
|
|
|
GST_LOG_OBJECT (enc, "set to %d", num);
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_lookahead:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
|
|
|
* Returns: currently configured encoder lookahead
|
|
|
|
*/
|
|
|
|
gint
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_lookahead (GstAudioEncoder * enc)
|
2011-08-16 16:23:14 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
return enc->priv->ctx.lookahead;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_latency:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:23:14 +00:00
|
|
|
* @min: minimum latency
|
|
|
|
* @max: maximum latency
|
|
|
|
*
|
|
|
|
* Sets encoder latency.
|
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_latency (GstAudioEncoder * enc,
|
2011-08-16 16:23:14 +00:00
|
|
|
GstClockTime min, GstClockTime max)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2015-02-03 11:12:18 +00:00
|
|
|
g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min));
|
|
|
|
g_return_if_fail (min <= max);
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->ctx.min_latency = min;
|
|
|
|
enc->priv->ctx.max_latency = max;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2012-12-02 12:33:43 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "set to %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min), GST_TIME_ARGS (max));
|
2015-02-03 11:15:25 +00:00
|
|
|
|
|
|
|
/* post latency message on the bus */
|
|
|
|
gst_element_post_message (GST_ELEMENT (enc),
|
|
|
|
gst_message_new_latency (GST_OBJECT (enc)));
|
2011-08-16 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_latency:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-09-05 19:45:22 +00:00
|
|
|
* @min: (out) (allow-none): a pointer to storage to hold minimum latency
|
|
|
|
* @max: (out) (allow-none): a pointer to storage to hold maximum latency
|
2011-08-16 16:23:14 +00:00
|
|
|
*
|
2011-09-05 19:45:22 +00:00
|
|
|
* Sets the variables pointed to by @min and @max to the currently configured
|
|
|
|
* latency.
|
2011-08-16 16:23:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_latency (GstAudioEncoder * enc,
|
2011-08-16 16:23:14 +00:00
|
|
|
GstClockTime * min, GstClockTime * max)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:23:14 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
if (min)
|
|
|
|
*min = enc->priv->ctx.min_latency;
|
|
|
|
if (max)
|
|
|
|
*max = enc->priv->ctx.max_latency;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
2011-08-16 16:59:13 +00:00
|
|
|
|
2012-03-30 10:57:02 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_encoder_set_headers:
|
2012-07-13 10:11:06 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2012-07-04 09:25:11 +00:00
|
|
|
* @headers: (transfer full) (element-type Gst.Buffer): a list of
|
|
|
|
* #GstBuffer containing the codec header
|
2012-03-30 10:57:02 +00:00
|
|
|
*
|
|
|
|
* Set the codec headers to be sent downstream whenever requested.
|
|
|
|
*/
|
2012-03-30 10:47:28 +00:00
|
|
|
void
|
|
|
|
gst_audio_encoder_set_headers (GstAudioEncoder * enc, GList * headers)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (enc, "new headers %p", headers);
|
|
|
|
|
|
|
|
if (enc->priv->ctx.headers) {
|
|
|
|
g_list_foreach (enc->priv->ctx.headers, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (enc->priv->ctx.headers);
|
|
|
|
}
|
|
|
|
enc->priv->ctx.headers = headers;
|
|
|
|
enc->priv->ctx.new_headers = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-04-01 10:25:14 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_encoder_set_allocation_caps:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
* @allocation_caps: (allow-none): a #GstCaps or %NULL
|
|
|
|
*
|
|
|
|
* Sets a caps in allocation query which are different from the set
|
|
|
|
* pad's caps. Use this function before calling
|
|
|
|
* gst_audio_encoder_negotiate(). Setting to %NULL the allocation
|
|
|
|
* query will use the caps from the pad.
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_audio_encoder_set_allocation_caps (GstAudioEncoder * enc,
|
|
|
|
GstCaps * allocation_caps)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
|
|
|
|
|
|
|
gst_caps_replace (&enc->priv->ctx.allocation_caps, allocation_caps);
|
|
|
|
}
|
|
|
|
|
2011-08-16 16:59:13 +00:00
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_mark_granule:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
* @enabled: new state
|
|
|
|
*
|
|
|
|
* Enable or disable encoder granule handling.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc, gboolean enabled)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "enabled: %d", enabled);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->granule = enabled;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_mark_granule:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
*
|
|
|
|
* Queries if the encoder will handle granule marking.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if granule marking is enabled.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), FALSE);
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->granule;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_perfect_timestamp:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
* @enabled: new state
|
|
|
|
*
|
|
|
|
* Enable or disable encoder perfect output timestamp preference.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
|
2011-08-16 16:59:13 +00:00
|
|
|
gboolean enabled)
|
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "enabled: %d", enabled);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->perfect_ts = enabled;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_perfect_timestamp:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
*
|
|
|
|
* Queries encoder perfect timestamp behaviour.
|
|
|
|
*
|
2011-09-13 19:10:43 +00:00
|
|
|
* Returns: TRUE if perfect timestamp setting enabled.
|
2011-08-16 16:59:13 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), FALSE);
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->perfect_ts;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_hard_sync:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
* @enabled: new state
|
|
|
|
*
|
|
|
|
* Sets encoder hard resync handling.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc, gboolean enabled)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "enabled: %d", enabled);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->hard_resync = enabled;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_hard_sync:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
*
|
|
|
|
* Queries encoder's hard resync setting.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if hard resync is enabled.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), FALSE);
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->hard_resync;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_set_tolerance:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
* @tolerance: new tolerance
|
|
|
|
*
|
|
|
|
* Configures encoder audio jitter tolerance threshold.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
2012-09-10 09:20:34 +00:00
|
|
|
gst_audio_encoder_set_tolerance (GstAudioEncoder * enc, GstClockTime tolerance)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->tolerance = tolerance;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
2012-12-02 12:33:43 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (enc, "set to %" GST_TIME_FORMAT, GST_TIME_ARGS (tolerance));
|
2011-08-16 16:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-05 14:01:09 +00:00
|
|
|
* gst_audio_encoder_get_tolerance:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2011-08-16 16:59:13 +00:00
|
|
|
*
|
|
|
|
* Queries current audio jitter tolerance threshold.
|
|
|
|
*
|
|
|
|
* Returns: encoder audio jitter tolerance threshold.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
2012-09-10 09:20:34 +00:00
|
|
|
GstClockTime
|
2011-09-05 14:01:09 +00:00
|
|
|
gst_audio_encoder_get_tolerance (GstAudioEncoder * enc)
|
2011-08-16 16:59:13 +00:00
|
|
|
{
|
2012-09-10 09:20:34 +00:00
|
|
|
GstClockTime result;
|
2011-08-16 16:59:13 +00:00
|
|
|
|
2011-09-05 14:01:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
2011-08-16 16:59:13 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->tolerance;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-09-26 13:14:41 +00:00
|
|
|
|
2012-02-16 11:18:03 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_encoder_set_hard_min:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
* @enabled: new state
|
|
|
|
*
|
|
|
|
* Configures encoder hard minimum handling. If enabled, subclass
|
|
|
|
* will never be handed less samples than it configured, which otherwise
|
|
|
|
* might occur near end-of-data handling. Instead, the leftover samples
|
|
|
|
* will simply be discarded.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_audio_encoder_set_hard_min (GstAudioEncoder * enc, gboolean enabled)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->hard_min = enabled;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_get_hard_min:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
*
|
|
|
|
* Queries encoder hard minimum handling.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if hard minimum handling is enabled.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_audio_encoder_get_hard_min (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->hard_min;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_set_drainable:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
* @enabled: new state
|
|
|
|
*
|
|
|
|
* Configures encoder drain handling. If drainable, subclass might
|
|
|
|
* be handed a NULL buffer to have it return any leftover encoded data.
|
|
|
|
* Otherwise, it is not considered so capable and will only ever be passed
|
|
|
|
* real data.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_audio_encoder_set_drainable (GstAudioEncoder * enc, gboolean enabled)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->priv->drainable = enabled;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_get_drainable:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
*
|
|
|
|
* Queries encoder drain handling.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if drainable handling is enabled.
|
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_audio_encoder_get_drainable (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), 0);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
result = enc->priv->drainable;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-26 13:14:41 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_encoder_merge_tags:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2015-08-18 10:45:24 +00:00
|
|
|
* @tags: (allow-none): a #GstTagList to merge, or NULL to unset
|
|
|
|
* previously-set tags
|
|
|
|
* @mode: the #GstTagMergeMode to use, usually #GST_TAG_MERGE_REPLACE
|
2011-09-26 13:14:41 +00:00
|
|
|
*
|
2015-08-18 10:45:24 +00:00
|
|
|
* Sets the audio encoder tags and how they should be merged with any
|
|
|
|
* upstream stream tags. This will override any tags previously-set
|
|
|
|
* with gst_audio_encoder_merge_tags().
|
2011-09-26 13:14:41 +00:00
|
|
|
*
|
|
|
|
* Note that this is provided for convenience, and the subclass is
|
2015-08-18 10:45:24 +00:00
|
|
|
* not required to use this and can still do tag handling on its own.
|
2011-09-26 13:14:41 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
|
|
|
|
const GstTagList * tags, GstTagMergeMode mode)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
|
|
|
g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
|
2015-08-18 10:45:24 +00:00
|
|
|
g_return_if_fail (tags == NULL || mode != GST_TAG_MERGE_UNDEFINED);
|
2011-09-26 13:14:41 +00:00
|
|
|
|
2012-08-09 13:48:03 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2015-08-18 10:45:24 +00:00
|
|
|
if (enc->priv->tags != tags) {
|
|
|
|
if (enc->priv->tags) {
|
|
|
|
gst_tag_list_unref (enc->priv->tags);
|
|
|
|
enc->priv->tags = NULL;
|
|
|
|
enc->priv->tags_merge_mode = GST_TAG_MERGE_APPEND;
|
|
|
|
}
|
|
|
|
if (tags) {
|
|
|
|
enc->priv->tags = gst_tag_list_ref ((GstTagList *) tags);
|
|
|
|
enc->priv->tags_merge_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "setting encoder tags to %" GST_PTR_FORMAT, tags);
|
|
|
|
enc->priv->tags_changed = TRUE;
|
|
|
|
}
|
2012-08-09 13:48:03 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
2011-09-26 13:14:41 +00:00
|
|
|
}
|
2012-02-01 15:00:37 +00:00
|
|
|
|
2012-08-09 13:27:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_negotiate_default (GstAudioEncoder * enc)
|
2012-02-01 15:00:37 +00:00
|
|
|
{
|
2012-08-09 13:20:45 +00:00
|
|
|
GstAudioEncoderClass *klass;
|
2013-08-23 17:17:16 +00:00
|
|
|
gboolean res = TRUE;
|
2012-07-23 08:20:05 +00:00
|
|
|
GstQuery *query = NULL;
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
2013-08-23 17:17:16 +00:00
|
|
|
GstCaps *caps, *prevcaps;
|
2012-02-01 15:00:37 +00:00
|
|
|
|
2012-08-09 13:20:45 +00:00
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_CAPS (enc->priv->ctx.caps), FALSE);
|
2012-02-01 15:00:37 +00:00
|
|
|
|
2012-08-09 13:20:45 +00:00
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
2012-02-01 15:00:37 +00:00
|
|
|
|
2012-08-09 13:20:45 +00:00
|
|
|
caps = enc->priv->ctx.caps;
|
2016-04-01 10:25:14 +00:00
|
|
|
if (enc->priv->ctx.allocation_caps == NULL)
|
|
|
|
enc->priv->ctx.allocation_caps = gst_caps_ref (caps);
|
2012-08-09 13:20:45 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
|
2012-02-01 15:32:53 +00:00
|
|
|
|
2013-05-08 13:56:34 +00:00
|
|
|
if (enc->priv->pending_events) {
|
2013-08-23 17:17:16 +00:00
|
|
|
GList **pending_events, *l;
|
2013-05-08 13:56:34 +00:00
|
|
|
|
2013-08-23 17:17:16 +00:00
|
|
|
pending_events = &enc->priv->pending_events;
|
2013-05-08 13:56:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "Pushing pending events");
|
2013-08-23 17:17:16 +00:00
|
|
|
for (l = *pending_events; l;) {
|
2013-05-08 13:56:34 +00:00
|
|
|
GstEvent *event = GST_EVENT (l->data);
|
2013-08-23 17:17:16 +00:00
|
|
|
GList *tmp;
|
2013-05-08 13:56:34 +00:00
|
|
|
|
2013-08-23 17:17:16 +00:00
|
|
|
if (GST_EVENT_TYPE (event) < GST_EVENT_CAPS) {
|
|
|
|
gst_audio_encoder_push_event (enc, l->data);
|
|
|
|
tmp = l;
|
|
|
|
l = l->next;
|
|
|
|
*pending_events = g_list_delete_link (*pending_events, tmp);
|
|
|
|
} else {
|
|
|
|
l = l->next;
|
2013-05-08 13:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 17:17:16 +00:00
|
|
|
prevcaps = gst_pad_get_current_caps (enc->srcpad);
|
|
|
|
if (!prevcaps || !gst_caps_is_equal (prevcaps, caps))
|
|
|
|
res = gst_pad_set_caps (enc->srcpad, caps);
|
|
|
|
if (prevcaps)
|
|
|
|
gst_caps_unref (prevcaps);
|
|
|
|
|
2012-07-23 08:20:05 +00:00
|
|
|
if (!res)
|
|
|
|
goto done;
|
2012-08-09 13:20:45 +00:00
|
|
|
enc->priv->ctx.output_caps_changed = FALSE;
|
2012-07-25 13:51:45 +00:00
|
|
|
|
2016-04-01 10:25:14 +00:00
|
|
|
query = gst_query_new_allocation (enc->priv->ctx.allocation_caps, TRUE);
|
2012-07-23 08:20:05 +00:00
|
|
|
if (!gst_pad_peer_query (enc->srcpad, query)) {
|
|
|
|
GST_DEBUG_OBJECT (enc, "didn't get downstream ALLOCATION hints");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (klass->decide_allocation != NULL);
|
|
|
|
res = klass->decide_allocation (enc, query);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, res,
|
|
|
|
query);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
goto no_decide_allocation;
|
|
|
|
|
|
|
|
/* we got configuration from our peer or the decide_allocation method,
|
|
|
|
* parse them */
|
|
|
|
if (gst_query_get_n_allocation_params (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
|
|
|
} else {
|
|
|
|
allocator = NULL;
|
|
|
|
gst_allocation_params_init (¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enc->priv->ctx.allocator)
|
|
|
|
gst_object_unref (enc->priv->ctx.allocator);
|
|
|
|
enc->priv->ctx.allocator = allocator;
|
|
|
|
enc->priv->ctx.params = params;
|
2012-02-01 15:00:37 +00:00
|
|
|
|
|
|
|
done:
|
2012-07-23 08:20:05 +00:00
|
|
|
if (query)
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
2012-02-01 15:00:37 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-08-09 13:20:45 +00:00
|
|
|
no_decide_allocation:
|
2012-02-01 15:00:37 +00:00
|
|
|
{
|
2012-08-09 13:20:45 +00:00
|
|
|
GST_WARNING_OBJECT (enc, "Subclass failed to decide allocation");
|
2012-02-01 15:00:37 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2012-08-09 13:20:45 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 14:39:57 +00:00
|
|
|
static gboolean
|
|
|
|
gst_audio_encoder_negotiate_unlocked (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
GstAudioEncoderClass *klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
if (G_LIKELY (klass->negotiate))
|
|
|
|
ret = klass->negotiate (enc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:27:33 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_encoder_negotiate:
|
2012-09-13 21:11:56 +00:00
|
|
|
* @enc: a #GstAudioEncoder
|
2012-08-09 13:27:33 +00:00
|
|
|
*
|
2013-12-05 14:39:57 +00:00
|
|
|
* Negotiate with downstream elements to currently configured #GstCaps.
|
|
|
|
* Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
|
|
|
|
* negotiate fails.
|
2013-12-20 21:54:39 +00:00
|
|
|
*
|
2017-10-03 21:31:18 +00:00
|
|
|
* Returns: %TRUE if the negotiation succeeded, else %FALSE.
|
2012-08-09 13:27:33 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_audio_encoder_negotiate (GstAudioEncoder * enc)
|
|
|
|
{
|
|
|
|
GstAudioEncoderClass *klass;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_AUDIO_ENCODER (enc), FALSE);
|
|
|
|
|
|
|
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
2013-12-05 14:39:57 +00:00
|
|
|
gst_pad_check_reconfigure (enc->srcpad);
|
|
|
|
if (klass->negotiate) {
|
2012-08-09 13:27:33 +00:00
|
|
|
ret = klass->negotiate (enc);
|
2013-12-05 14:39:57 +00:00
|
|
|
if (!ret)
|
|
|
|
gst_pad_mark_reconfigure (enc->srcpad);
|
|
|
|
}
|
2012-08-09 13:27:33 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:39:21 +00:00
|
|
|
/**
|
2012-08-09 13:20:45 +00:00
|
|
|
* gst_audio_encoder_set_output_format:
|
|
|
|
* @enc: a #GstAudioEncoder
|
2014-08-09 12:14:48 +00:00
|
|
|
* @caps: (transfer none): #GstCaps
|
2012-08-09 13:20:45 +00:00
|
|
|
*
|
|
|
|
* Configure output caps on the srcpad of @enc.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
2016-04-04 14:39:21 +00:00
|
|
|
*/
|
2012-08-09 13:20:45 +00:00
|
|
|
gboolean
|
|
|
|
gst_audio_encoder_set_output_format (GstAudioEncoder * enc, GstCaps * caps)
|
|
|
|
{
|
2012-08-13 22:32:59 +00:00
|
|
|
gboolean res = TRUE;
|
2012-08-09 13:20:45 +00:00
|
|
|
GstCaps *templ_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (enc, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
if (!gst_caps_is_fixed (caps))
|
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
/* Only allow caps that are a subset of the template caps */
|
|
|
|
templ_caps = gst_pad_get_pad_template_caps (enc->srcpad);
|
|
|
|
if (!gst_caps_is_subset (caps, templ_caps)) {
|
|
|
|
gst_caps_unref (templ_caps);
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
gst_caps_unref (templ_caps);
|
|
|
|
|
|
|
|
gst_caps_replace (&enc->priv->ctx.caps, caps);
|
|
|
|
enc->priv->ctx.output_caps_changed = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
refuse_caps:
|
2012-07-23 08:20:05 +00:00
|
|
|
{
|
2012-08-09 13:20:45 +00:00
|
|
|
GST_WARNING_OBJECT (enc, "refused caps %" GST_PTR_FORMAT, caps);
|
|
|
|
res = FALSE;
|
2012-07-23 08:20:05 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_allocate_output_buffer:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
* @size: size of the buffer
|
|
|
|
*
|
|
|
|
* Helper function that allocates a buffer to hold an encoded audio frame
|
|
|
|
* for @enc's current output format.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): allocated buffer
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
|
|
|
gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc, gsize size)
|
|
|
|
{
|
2012-07-23 10:01:12 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2013-12-05 14:39:57 +00:00
|
|
|
gboolean needs_reconfigure = FALSE;
|
2012-07-23 08:20:05 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (size > 0, NULL);
|
|
|
|
|
|
|
|
GST_DEBUG ("alloc src buffer");
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
|
|
|
|
|
2013-12-05 14:39:57 +00:00
|
|
|
needs_reconfigure = gst_pad_check_reconfigure (enc->srcpad);
|
2012-08-09 13:20:45 +00:00
|
|
|
if (G_UNLIKELY (enc->priv->ctx.output_caps_changed || (enc->priv->ctx.caps
|
2013-12-05 14:39:57 +00:00
|
|
|
&& needs_reconfigure))) {
|
|
|
|
if (!gst_audio_encoder_negotiate_unlocked (enc)) {
|
2013-05-24 14:52:50 +00:00
|
|
|
GST_INFO_OBJECT (enc, "Failed to negotiate, fallback allocation");
|
2013-09-12 07:42:36 +00:00
|
|
|
gst_pad_mark_reconfigure (enc->srcpad);
|
2013-05-24 14:52:50 +00:00
|
|
|
goto fallback;
|
|
|
|
}
|
2012-07-23 10:01:12 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 08:20:05 +00:00
|
|
|
buffer =
|
|
|
|
gst_buffer_new_allocate (enc->priv->ctx.allocator, size,
|
|
|
|
&enc->priv->ctx.params);
|
2013-05-24 14:52:50 +00:00
|
|
|
if (!buffer) {
|
|
|
|
GST_INFO_OBJECT (enc, "couldn't allocate output buffer");
|
|
|
|
goto fallback;
|
|
|
|
}
|
2012-07-23 08:20:05 +00:00
|
|
|
|
2013-05-24 14:52:50 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
fallback:
|
|
|
|
buffer = gst_buffer_new_allocate (NULL, size, NULL);
|
2012-07-23 08:20:05 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
|
|
|
|
|
|
|
return buffer;
|
2012-02-01 15:00:37 +00:00
|
|
|
}
|
2012-08-07 15:21:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_encoder_get_allocator:
|
|
|
|
* @enc: a #GstAudioEncoder
|
|
|
|
* @allocator: (out) (allow-none) (transfer full): the #GstAllocator
|
|
|
|
* used
|
|
|
|
* @params: (out) (allow-none) (transfer full): the
|
2018-04-02 06:34:58 +00:00
|
|
|
* #GstAllocationParams of @allocator
|
2012-08-07 15:21:53 +00:00
|
|
|
*
|
|
|
|
* Lets #GstAudioEncoder sub-classes to know the memory @allocator
|
|
|
|
* used by the base class and its @params.
|
|
|
|
*
|
|
|
|
* Unref the @allocator after use it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_audio_encoder_get_allocator (GstAudioEncoder * enc,
|
|
|
|
GstAllocator ** allocator, GstAllocationParams * params)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
|
|
|
|
|
|
|
|
if (allocator)
|
|
|
|
*allocator = enc->priv->ctx.allocator ?
|
|
|
|
gst_object_ref (enc->priv->ctx.allocator) : NULL;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
*params = enc->priv->ctx.params;
|
|
|
|
}
|