audioaggregator: Split base class from audiomixer

Also:
-  Don't modify size on early buffer
   The size is the size of the buffer, not of remaining part.
- Use the input caps when manipulating the input buffer
   Also store in in the sink pad
- Reply to the position query in bytes too
- Put GAP flag on output if all inputs are GAP data
- Only try to clip buffer if the incoming segment is in time or samples
- Use incoming segment with incoming timestamp
   Handle non-time segments and NONE timestamps
- Don't reset the position when pushing out new caps
- Make a number of member variables private
- Correctly handle case where no pad has a buffer
  If none of the pads have buffers that can be handled, don't claim to be EOS.
- Ensure proper locking
- Only support time segments

https://bugzilla.gnome.org/show_bug.cgi?id=740236
This commit is contained in:
Olivier Crête 2014-11-06 17:15:17 -05:00
parent 66807c14fd
commit 1eef58c3ce
5 changed files with 1543 additions and 1036 deletions

View file

@ -4,7 +4,7 @@ ORC_SOURCE=gstaudiomixerorc
include $(top_srcdir)/common/orc.mak
libgstaudiomixer_la_SOURCES = gstaudiomixer.c
libgstaudiomixer_la_SOURCES = gstaudiomixer.c gstaudioaggregator.c
nodist_libgstaudiomixer_la_SOURCES = $(ORC_NODIST_SOURCES)
libgstaudiomixer_la_CFLAGS = \
-I$(top_srcdir)/gst-libs \
@ -18,5 +18,5 @@ libgstaudiomixer_la_LIBADD = \
$(GST_BASE_LIBS) $(GST_LIBS) $(ORC_LIBS)
libgstaudiomixer_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = gstaudiomixer.h
noinst_HEADERS = gstaudiomixer.h gstaudioaggregator.h

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,171 @@
/* GStreamer
* Copyright (C) 2014 Collabora
* Author: Olivier Crete <olivier.crete@collabora.com>
*
* gstaudioaggregator.h:
*
* 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
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_AUDIO_AGGREGATOR_H__
#define __GST_AUDIO_AGGREGATOR_H__
#ifndef GST_USE_UNSTABLE_API
#warning "The Base library from gst-plugins-bad is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include <gst/gst.h>
#include <gst/base/gstaggregator.h>
#include <gst/audio/audio.h>
G_BEGIN_DECLS
/*******************************
* GstAudioAggregator Structs *
*******************************/
typedef struct _GstAudioAggregator GstAudioAggregator;
typedef struct _GstAudioAggregatorPrivate GstAudioAggregatorPrivate;
typedef struct _GstAudioAggregatorClass GstAudioAggregatorClass;
/************************
* GstAudioAggregatorPad API *
***********************/
#define GST_TYPE_AUDIO_AGGREGATOR_PAD (gst_audio_aggregator_pad_get_type())
#define GST_AUDIO_AGGREGATOR_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_AGGREGATOR_PAD, GstAudioAggregatorPad))
#define GST_AUDIO_AGGREGATOR_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_AGGREGATOR_PAD, GstAudioAggregatorPadClass))
#define GST_AUDIO_AGGREGATOR_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AUDIO_AGGREGATOR_PAD, GstAudioAggregatorPadClass))
#define GST_IS_AUDIO_AGGREGATOR_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_AGGREGATOR_PAD))
#define GST_IS_AUDIO_AGGREGATOR_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_AGGREGATOR_PAD))
/****************************
* GstAudioAggregatorPad Structs *
***************************/
typedef struct _GstAudioAggregatorPad GstAudioAggregatorPad;
typedef struct _GstAudioAggregatorPadClass GstAudioAggregatorPadClass;
typedef struct _GstAudioAggregatorPadPrivate GstAudioAggregatorPadPrivate;
/**
* GstAudioAggregatorPad:
* @parent: The parent #GstAggregatorPad
* @info: The audio info for this pad set from the incoming caps
*
* The implementation the GstPad to use with #GstAudioAggregator
*/
struct _GstAudioAggregatorPad
{
GstAggregatorPad parent;
GstAudioInfo info;
/*< private >*/
GstAudioAggregatorPadPrivate * priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstAudioAggregatorPadClass:
*
*/
struct _GstAudioAggregatorPadClass
{
GstAggregatorPadClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GType gst_audio_aggregator_pad_get_type (void);
/**************************
* GstAudioAggregator API *
**************************/
#define GST_TYPE_AUDIO_AGGREGATOR (gst_audio_aggregator_get_type())
#define GST_AUDIO_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_AGGREGATOR,GstAudioAggregator))
#define GST_AUDIO_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_AGGREGATOR,GstAudioAggregatorClass))
#define GST_AUDIO_AGGREGATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AUDIO_AGGREGATOR,GstAudioAggregatorClass))
#define GST_IS_AUDIO_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_AGGREGATOR))
#define GST_IS_AUDIO_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_AGGREGATOR))
#define GST_FLOW_CUSTOM_SUCCESS GST_FLOW_NOT_HANDLED
/**
* GstAudioAggregator:
* @parent: The parent #GstAggregator
* @info: The information parsed from the current caps
* @current_caps: The caps set by the subclass
*
* GstAudioAggregator object
*/
struct _GstAudioAggregator
{
GstAggregator parent;
/* All member are read only for subclasses, must hold OBJECT lock */
GstAudioInfo info;
GstCaps *current_caps;
/*< private >*/
GstAudioAggregatorPrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstAudioAggregatorClass:
* @create_output_buffer: Create a new output buffer contains num_frames frames.
* @aggregate_one_buffer: Aggregates one input buffer to the output
* buffer. The in_offset and out_offset are in "frames", which is
* the size of a sample times the number of channels. Returns TRUE if
* any non-silence was added to the buffer
*/
struct _GstAudioAggregatorClass {
GstAggregatorClass parent_class;
GstBuffer * (* create_output_buffer) (GstAudioAggregator * aagg,
guint num_frames);
gboolean (* aggregate_one_buffer) (GstAudioAggregator * aagg,
GstAudioAggregatorPad * pad, GstBuffer * inbuf, guint in_offset,
GstBuffer * outbuf, guint out_offset, guint num_frames);
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
/*************************
* GstAggregator methods *
************************/
GType gst_audio_aggregator_get_type(void);
void
gst_audio_aggregator_set_sink_caps (GstAudioAggregator * aagg,
GstAudioAggregatorPad * pad, GstCaps * caps);
gboolean
gst_audio_aggregator_set_src_caps (GstAudioAggregator * aagg, GstCaps * caps);
G_END_DECLS
#endif /* __GST_AUDIO_AGGREGATOR_H__ */

File diff suppressed because it is too large Load diff

View file

@ -25,8 +25,8 @@
#define __GST_AUDIO_MIXER_H__
#include <gst/gst.h>
#include <gst/base/gstaggregator.h>
#include <gst/audio/audio.h>
#include "gstaudioaggregator.h"
G_BEGIN_DECLS
@ -49,32 +49,14 @@ typedef struct _GstAudioMixerPadClass GstAudioMixerPadClass;
* The audiomixer object structure.
*/
struct _GstAudioMixer {
GstAggregator aggregator;
/* the next are valid for both int and float */
GstAudioInfo info;
/* counters to keep track of timestamps */
gint64 offset;
/* Buffer starting at offset containing block_size samples */
GstBuffer *current_buffer;
/* current caps */
GstCaps *current_caps;
gboolean send_caps;
GstAudioAggregator element;
/* target caps (set via property) */
GstCaps *filter_caps;
GstClockTime alignment_threshold;
GstClockTime discont_wait;
/* Duration of every output buffer */
GstClockTime output_buffer_duration;
};
struct _GstAudioMixerClass {
GstAggregatorClass parent_class;
GstAudioAggregatorClass parent_class;
};
GType gst_audiomixer_get_type (void);
@ -87,36 +69,17 @@ GType gst_audiomixer_get_type (void);
#define GST_AUDIO_MIXER_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_AUDIO_MIXER_PAD,GstAudioMixerPadClass))
struct _GstAudioMixerPad {
GstAggregatorPad parent;
GstAudioAggregatorPad parent;
gdouble volume;
gint volume_i32;
gint volume_i16;
gint volume_i8;
gboolean mute;
/* < private > */
GstBuffer *buffer; /* current buffer we're mixing,
for comparison with collect.buffer
to see if we need to update our
cached values. */
guint position, size;
guint64 output_offset; /* Offset in output segment that
collect.pos refers to in the
current buffer. */
guint64 next_offset; /* Next expected offset in the input segment */
/* Last time we noticed a discont */
GstClockTime discont_time;
/* A new unhandled segment event has been received */
gboolean new_segment;
};
struct _GstAudioMixerPadClass {
GstAggregatorPadClass parent_class;
GstAudioAggregatorPadClass parent_class;
};
GType gst_audiomixer_pad_get_type (void);