mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
ffmpeg: Use stack-allocated channel positions array
This commit is contained in:
parent
d2702a091e
commit
42bc8f5ad7
2 changed files with 10 additions and 23 deletions
|
@ -102,11 +102,11 @@ static const struct
|
||||||
CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
|
CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstAudioChannelPosition *
|
static gboolean
|
||||||
gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
|
gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels,
|
||||||
|
GstAudioChannelPosition * pos)
|
||||||
{
|
{
|
||||||
guint nchannels = 0, i, j;
|
guint nchannels = 0, i, j;
|
||||||
GstAudioChannelPosition *pos = NULL;
|
|
||||||
gboolean none_layout = FALSE;
|
gboolean none_layout = FALSE;
|
||||||
|
|
||||||
for (i = 0; i < 64; i++) {
|
for (i = 0; i < 64; i++) {
|
||||||
|
@ -123,11 +123,9 @@ gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
|
||||||
if (nchannels != channels) {
|
if (nchannels != channels) {
|
||||||
GST_ERROR ("Number of channels is different (%u != %u)", channels,
|
GST_ERROR ("Number of channels is different (%u != %u)", channels,
|
||||||
nchannels);
|
nchannels);
|
||||||
return NULL;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = g_new (GstAudioChannelPosition, nchannels);
|
|
||||||
|
|
||||||
for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
|
for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
|
||||||
if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
|
if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
|
||||||
pos[j++] = _ff_to_gst_layout[i].gst;
|
pos[j++] = _ff_to_gst_layout[i].gst;
|
||||||
|
@ -156,21 +154,14 @@ gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
|
||||||
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||||
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||||
} else if (channel_layout == 0) {
|
} else if (channel_layout == 0) {
|
||||||
g_free (pos);
|
return FALSE;
|
||||||
pos = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < nchannels; i++)
|
for (i = 0; i < nchannels; i++)
|
||||||
pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
|
pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nchannels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER) {
|
return TRUE;
|
||||||
GST_DEBUG ("mono common case; won't set channel positions");
|
|
||||||
g_free (pos);
|
|
||||||
pos = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this macro makes a caps width fixed or unfixed width/height
|
/* this macro makes a caps width fixed or unfixed width/height
|
||||||
|
@ -305,10 +296,7 @@ gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
|
||||||
* default unfixed setting */
|
* default unfixed setting */
|
||||||
if (!caps) {
|
if (!caps) {
|
||||||
GST_DEBUG ("Creating default caps");
|
GST_DEBUG ("Creating default caps");
|
||||||
caps = gst_caps_new_simple (mimetype,
|
caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
|
||||||
"width", GST_TYPE_INT_RANGE, 16, 4096,
|
|
||||||
"height", GST_TYPE_INT_RANGE, 16, 4096,
|
|
||||||
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
||||||
|
@ -335,7 +323,7 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
|
||||||
/* fixed, non-probing context */
|
/* fixed, non-probing context */
|
||||||
if (context != NULL && context->channels != -1) {
|
if (context != NULL && context->channels != -1) {
|
||||||
GstAudioInfo info;
|
GstAudioInfo info;
|
||||||
GstAudioChannelPosition *pos;
|
GstAudioChannelPosition pos[64];
|
||||||
guint64 channel_layout = context->channel_layout;
|
guint64 channel_layout = context->channel_layout;
|
||||||
|
|
||||||
gst_audio_info_init (&info);
|
gst_audio_info_init (&info);
|
||||||
|
@ -364,15 +352,13 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
|
||||||
"rate", G_TYPE_INT, context->sample_rate,
|
"rate", G_TYPE_INT, context->sample_rate,
|
||||||
"channels", G_TYPE_INT, context->channels, NULL);
|
"channels", G_TYPE_INT, context->channels, NULL);
|
||||||
|
|
||||||
pos = gst_ff_channel_layout_to_gst (channel_layout, context->channels);
|
if (gst_ff_channel_layout_to_gst (channel_layout, context->channels, pos)) {
|
||||||
if (pos != NULL) {
|
|
||||||
guint64 mask;
|
guint64 mask;
|
||||||
|
|
||||||
if (gst_audio_channel_positions_to_mask (pos, context->channels, &mask)) {
|
if (gst_audio_channel_positions_to_mask (pos, context->channels, &mask)) {
|
||||||
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
|
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
g_free (pos);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gint maxchannels = 2;
|
gint maxchannels = 2;
|
||||||
|
|
|
@ -2226,6 +2226,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
|
||||||
"Decode audio: len=%d, have_data=%d", len, have_data);
|
"Decode audio: len=%d, have_data=%d", len, have_data);
|
||||||
|
|
||||||
if (len >= 0 && have_data > 0) {
|
if (len >= 0 && have_data > 0) {
|
||||||
|
/* FIXME: Reorder here */
|
||||||
/* Buffer size */
|
/* Buffer size */
|
||||||
gst_buffer_unmap (*outbuf, odata, have_data);
|
gst_buffer_unmap (*outbuf, odata, have_data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue