mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
Add support for audio decoders, completely untested so far
This commit is contained in:
parent
de5375da81
commit
77fbaae250
5 changed files with 1391 additions and 0 deletions
|
@ -201,4 +201,27 @@ enum
|
|||
AACObjectELD = 39
|
||||
};
|
||||
|
||||
/* Copies from AudioFormat.java */
|
||||
enum
|
||||
{
|
||||
CHANNEL_OUT_FRONT_LEFT = 0x4,
|
||||
CHANNEL_OUT_FRONT_RIGHT = 0x8,
|
||||
CHANNEL_OUT_FRONT_CENTER = 0x10,
|
||||
CHANNEL_OUT_LOW_FREQUENCY = 0x20,
|
||||
CHANNEL_OUT_BACK_LEFT = 0x40,
|
||||
CHANNEL_OUT_BACK_RIGHT = 0x80,
|
||||
CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
|
||||
CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
|
||||
CHANNEL_OUT_BACK_CENTER = 0x400,
|
||||
CHANNEL_OUT_SIDE_LEFT = 0x800,
|
||||
CHANNEL_OUT_SIDE_RIGHT = 0x1000,
|
||||
CHANNEL_OUT_TOP_CENTER = 0x2000,
|
||||
CHANNEL_OUT_TOP_FRONT_LEFT = 0x4000,
|
||||
CHANNEL_OUT_TOP_FRONT_CENTER = 0x8000,
|
||||
CHANNEL_OUT_TOP_FRONT_RIGHT = 0x10000,
|
||||
CHANNEL_OUT_TOP_BACK_LEFT = 0x20000,
|
||||
CHANNEL_OUT_TOP_BACK_CENTER = 0x40000,
|
||||
CHANNEL_OUT_TOP_BACK_RIGHT = 0x80000
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,9 +26,11 @@
|
|||
#include "gstamc-constants.h"
|
||||
|
||||
#include "gstamcvideodec.h"
|
||||
#include "gstamcaudiodec.h"
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/audio/audio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
@ -2468,6 +2470,107 @@ gst_amc_aac_profile_from_string (const gchar * profile)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static const struct
|
||||
{
|
||||
guint32 mask;
|
||||
GstAudioChannelPosition pos;
|
||||
} channel_mapping_table[] = {
|
||||
{
|
||||
CHANNEL_OUT_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
|
||||
CHANNEL_OUT_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
|
||||
CHANNEL_OUT_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
|
||||
CHANNEL_OUT_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE}, {
|
||||
CHANNEL_OUT_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
|
||||
CHANNEL_OUT_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
|
||||
CHANNEL_OUT_FRONT_LEFT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
|
||||
CHANNEL_OUT_FRONT_RIGHT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
|
||||
CHANNEL_OUT_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
|
||||
CHANNEL_OUT_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
|
||||
CHANNEL_OUT_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
|
||||
CHANNEL_OUT_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
CHANNEL_OUT_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_INVALID}
|
||||
};
|
||||
|
||||
GstAudioChannelPosition *
|
||||
gst_amc_audio_channel_mask_to_positions (guint32 channel_mask, gint channels)
|
||||
{
|
||||
GstAudioChannelPosition *pos = g_new0 (GstAudioChannelPosition, channels);
|
||||
gint i, j;
|
||||
|
||||
if (channel_mask == 0 && channels == 1) {
|
||||
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
|
||||
return pos;
|
||||
}
|
||||
|
||||
if (channel_mask == 0 && channels == 2) {
|
||||
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||
return pos;
|
||||
}
|
||||
|
||||
for (i = 0, j = 0; i < G_N_ELEMENTS (channel_mapping_table); i++) {
|
||||
if ((channel_mask & channel_mapping_table[i].mask)) {
|
||||
pos[j++] = channel_mapping_table[i].pos;
|
||||
if (channel_mapping_table[i].pos == GST_AUDIO_CHANNEL_POSITION_INVALID) {
|
||||
g_free (pos);
|
||||
GST_ERROR ("Unable to map channel mask 0x%08x",
|
||||
channel_mapping_table[i].mask);
|
||||
return NULL;
|
||||
}
|
||||
if (j == channels)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j != channels) {
|
||||
g_free (pos);
|
||||
GST_ERROR ("Unable to map all channel positions in mask 0x%08x",
|
||||
channel_mask);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
guint32
|
||||
gst_amc_audio_channel_mask_from_positions (GstAudioChannelPosition * positions,
|
||||
gint channels)
|
||||
{
|
||||
gint i, j;
|
||||
guint32 channel_mask = 0;
|
||||
|
||||
if (channels == 1 && !positions)
|
||||
return CHANNEL_OUT_FRONT_CENTER;
|
||||
if (channels == 2 && !positions)
|
||||
return CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT;
|
||||
|
||||
for (i = 0; i < channels; i++) {
|
||||
if (positions[i] == GST_AUDIO_CHANNEL_POSITION_INVALID)
|
||||
return 0;
|
||||
|
||||
for (j = 0; j < G_N_ELEMENTS (channel_mapping_table); j++) {
|
||||
if (channel_mapping_table[j].pos == positions[i]) {
|
||||
channel_mask |= channel_mapping_table[j].mask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == G_N_ELEMENTS (channel_mapping_table)) {
|
||||
GST_ERROR ("Unable to map channel position %d", positions[i]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return channel_mask;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
create_type_name (const gchar * parent_name, const gchar * codec_name)
|
||||
{
|
||||
|
@ -2579,6 +2682,8 @@ register_codecs (GstPlugin * plugin)
|
|||
|
||||
if (is_video && !codec_info->is_encoder) {
|
||||
type = gst_amc_video_dec_get_type ();
|
||||
} else if (is_audio && !codec_info->is_encoder) {
|
||||
type = gst_amc_audio_dec_get_type ();
|
||||
} else {
|
||||
GST_DEBUG ("Skipping unsupported codec type");
|
||||
continue;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/audio/multichannel.h>
|
||||
#include <jni.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -136,6 +137,9 @@ gint gst_amc_mpeg4_level_from_string (const gchar *level);
|
|||
const gchar * gst_amc_aac_profile_to_string (gint profile);
|
||||
gint gst_amc_aac_profile_from_string (const gchar *profile);
|
||||
|
||||
GstAudioChannelPosition* gst_amc_audio_channel_mask_to_positions (guint32 channel_mask, gint channels);
|
||||
guint32 gst_amc_audio_channel_mask_from_positions (GstAudioChannelPosition *positions, gint channels);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_AMC_H__ */
|
||||
|
|
1163
sys/androidmedia/gstamcaudiodec.c
Normal file
1163
sys/androidmedia/gstamcaudiodec.c
Normal file
File diff suppressed because it is too large
Load diff
96
sys/androidmedia/gstamcaudiodec.h
Normal file
96
sys/androidmedia/gstamcaudiodec.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_AMC_AUDIO_DEC_H__
|
||||
#define __GST_AMC_AUDIO_DEC_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/audio/multichannel.h>
|
||||
#include <gst/audio/gstaudiodecoder.h>
|
||||
|
||||
#include "gstamc.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_AMC_AUDIO_DEC \
|
||||
(gst_amc_audio_dec_get_type())
|
||||
#define GST_AMC_AUDIO_DEC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AMC_AUDIO_DEC,GstAmcAudioDec))
|
||||
#define GST_AMC_AUDIO_DEC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AMC_AUDIO_DEC,GstAmcAudioDecClass))
|
||||
#define GST_AMC_AUDIO_DEC_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AMC_AUDIO_DEC,GstAmcAudioDecClass))
|
||||
#define GST_IS_AMC_AUDIO_DEC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AMC_AUDIO_DEC))
|
||||
#define GST_IS_AMC_AUDIO_DEC_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AMC_AUDIO_DEC))
|
||||
|
||||
typedef struct _GstAmcAudioDec GstAmcAudioDec;
|
||||
typedef struct _GstAmcAudioDecClass GstAmcAudioDecClass;
|
||||
|
||||
struct _GstAmcAudioDec
|
||||
{
|
||||
GstAudioDecoder parent;
|
||||
|
||||
/* < private > */
|
||||
GstAmcCodec *codec;
|
||||
GstAmcBuffer *input_buffers, *output_buffers;
|
||||
gsize n_input_buffers, n_output_buffers;
|
||||
|
||||
GstCaps *input_caps;
|
||||
GList *codec_datas;
|
||||
gboolean input_caps_changed;
|
||||
|
||||
/* Output format of the codec */
|
||||
gint channels, rate;
|
||||
GstAudioChannelPosition *positions;
|
||||
|
||||
GstBuffer *codec_data;
|
||||
/* TRUE if the component is configured and saw
|
||||
* the first buffer */
|
||||
gboolean started;
|
||||
gboolean flushing;
|
||||
|
||||
GstClockTime last_upstream_ts;
|
||||
|
||||
/* Draining state */
|
||||
GMutex *drain_lock;
|
||||
GCond *drain_cond;
|
||||
/* TRUE if EOS buffers shouldn't be forwarded */
|
||||
gboolean draining;
|
||||
|
||||
/* TRUE if upstream is EOS */
|
||||
gboolean eos;
|
||||
|
||||
GstFlowReturn downstream_flow_ret;
|
||||
};
|
||||
|
||||
struct _GstAmcAudioDecClass
|
||||
{
|
||||
GstAudioDecoderClass parent_class;
|
||||
|
||||
const GstAmcCodecInfo *codec_info;
|
||||
};
|
||||
|
||||
GType gst_amc_audio_dec_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_AMC_AUDIO_DEC_H__ */
|
Loading…
Reference in a new issue