Commit dd56c2c7 authored by Wim Taymans's avatar Wim Taymans

ffmpeg: port to new audio caps

parent 7ae8b453
...@@ -71,14 +71,18 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", ...@@ -71,14 +71,18 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS GST_STATIC_CAPS
("audio/x-raw-int, endianness = (int) BYTE_ORDER, signed = (boolean) true, width = (int) 16, depth = (int) 16, channels = (int) { 1 , 2 }, rate = (int) [1, MAX ]") ("audio/x-raw,"
"format = (string) " GST_AUDIO_NE (S16) ","
"channels = (int) { 1 , 2 }, rate = (int) [1, MAX ]")
); );
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS GST_STATIC_CAPS
("audio/x-raw-int, endianness = (int) BYTE_ORDER, signed = (boolean) true, width = (int) 16, depth = (int) 16, channels = (int) [ 1 , 6 ], rate = (int) [1, MAX ]") ("audio/x-raw,"
"format = (string) " GST_AUDIO_NE (S16) ","
"channels = (int) { 1 , 2 }, rate = (int) [1, MAX ]")
); );
GST_BOILERPLATE (GstFFMpegAudioResample, gst_ffmpegaudioresample, GST_BOILERPLATE (GstFFMpegAudioResample, gst_ffmpegaudioresample,
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "gstffmpegcodecmap.h" #include "gstffmpegcodecmap.h"
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/audio/audio.h>
#include <gst/pbutils/codec-utils.h> #include <gst/pbutils/codec-utils.h>
/* /*
...@@ -434,7 +435,7 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id, ...@@ -434,7 +435,7 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
* Unfortunately no encoder uses this yet.... * Unfortunately no encoder uses this yet....
*/ */
} }
#if 0
/* regardless of encode/decode, open up channels if applicable */ /* regardless of encode/decode, open up channels if applicable */
/* Until decoders/encoders expose the maximum number of channels /* Until decoders/encoders expose the maximum number of channels
* they support, we whitelist them here. */ * they support, we whitelist them here. */
...@@ -453,6 +454,7 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id, ...@@ -453,6 +454,7 @@ gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
default: default:
break; break;
} }
#endif
if (maxchannels == 1) if (maxchannels == 1)
caps = gst_caps_new_simple (mimetype, caps = gst_caps_new_simple (mimetype,
...@@ -1283,56 +1285,34 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id, ...@@ -1283,56 +1285,34 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
case CODEC_ID_PCM_S8: case CODEC_ID_PCM_S8:
case CODEC_ID_PCM_U8: case CODEC_ID_PCM_U8:
{ {
gint width = 0, depth = 0, endianness = 0; GstAudioFormat format;
gboolean signedness = FALSE; /* blabla */
switch (codec_id) { switch (codec_id) {
case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16LE:
width = 16; format = GST_AUDIO_FORMAT_S16_LE;
depth = 16;
endianness = G_LITTLE_ENDIAN;
signedness = TRUE;
break; break;
case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16BE:
width = 16; format = GST_AUDIO_FORMAT_S16_BE;
depth = 16;
endianness = G_BIG_ENDIAN;
signedness = TRUE;
break; break;
case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16LE:
width = 16; format = GST_AUDIO_FORMAT_U16_LE;
depth = 16;
endianness = G_LITTLE_ENDIAN;
signedness = FALSE;
break; break;
case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_U16BE:
width = 16; format = GST_AUDIO_FORMAT_U16_BE;
depth = 16;
endianness = G_BIG_ENDIAN;
signedness = FALSE;
break; break;
case CODEC_ID_PCM_S8: case CODEC_ID_PCM_S8:
width = 8; format = GST_AUDIO_FORMAT_S8;
depth = 8;
endianness = G_BYTE_ORDER;
signedness = TRUE;
break; break;
case CODEC_ID_PCM_U8: case CODEC_ID_PCM_U8:
width = 8; format = GST_AUDIO_FORMAT_U8;
depth = 8;
endianness = G_BYTE_ORDER;
signedness = FALSE;
break; break;
default: default:
g_assert (0); /* don't worry, we never get here */ g_assert (0); /* don't worry, we never get here */
break; break;
} }
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int", caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw",
"width", G_TYPE_INT, width, "format", G_TYPE_STRING, gst_audio_format_to_string (format), NULL);
"depth", G_TYPE_INT, depth,
"endianness", G_TYPE_INT, endianness,
"signed", G_TYPE_BOOLEAN, signedness, NULL);
} }
break; break;
...@@ -1799,50 +1779,30 @@ gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt, ...@@ -1799,50 +1779,30 @@ gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt,
AVCodecContext * context, enum CodecID codec_id) AVCodecContext * context, enum CodecID codec_id)
{ {
GstCaps *caps = NULL; GstCaps *caps = NULL;
GstAudioFormat format;
int bpp = 0;
gboolean integer = TRUE;
gboolean signedness = FALSE;
switch (sample_fmt) { switch (sample_fmt) {
case SAMPLE_FMT_S16: case SAMPLE_FMT_S16:
signedness = TRUE; format = GST_AUDIO_FORMAT_S16;
bpp = 16;
break; break;
case SAMPLE_FMT_S32: case SAMPLE_FMT_S32:
signedness = TRUE; format = GST_AUDIO_FORMAT_S32;
bpp = 32;
break; break;
case SAMPLE_FMT_FLT: case SAMPLE_FMT_FLT:
integer = FALSE; format = GST_AUDIO_FORMAT_F32;
bpp = 32;
break; break;
case SAMPLE_FMT_DBL: case SAMPLE_FMT_DBL:
integer = FALSE; format = GST_AUDIO_FORMAT_F64;
bpp = 64;
break; break;
default: default:
/* .. */ /* .. */
format = GST_AUDIO_FORMAT_UNKNOWN;
break; break;
} }
if (bpp) { if (format != GST_AUDIO_FORMAT_UNKNOWN) {
if (integer) { caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw",
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int", "format", G_TYPE_STRING, gst_audio_format_to_string (format), NULL);
"signed", G_TYPE_BOOLEAN, signedness,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
} else {
caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-float",
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"width", G_TYPE_INT, bpp, NULL);
}
}
if (caps != NULL) {
GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps); GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
} else { } else {
GST_LOG ("No caps found for sample_fmt=%d", sample_fmt); GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
...@@ -1964,11 +1924,11 @@ gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps, ...@@ -1964,11 +1924,11 @@ gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
AVCodecContext * context, gboolean raw) AVCodecContext * context, gboolean raw)
{ {
GstStructure *structure; GstStructure *structure;
gint depth = 0, width = 0, endianness = 0; const gchar *fmt;
gboolean signedness = FALSE; GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
const gchar *name;
g_return_if_fail (gst_caps_get_size (caps) == 1); g_return_if_fail (gst_caps_get_size (caps) == 1);
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "channels", &context->channels); gst_structure_get_int (structure, "channels", &context->channels);
...@@ -1979,35 +1939,29 @@ gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps, ...@@ -1979,35 +1939,29 @@ gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
if (!raw) if (!raw)
return; return;
name = gst_structure_get_name (structure); if (gst_structure_has_name (structure, "audio/x-raw")) {
if ((fmt = gst_structure_get_string (structure, "format"))) {
if (!strcmp (name, "audio/x-raw-float")) { format = gst_audio_format_from_string (fmt);
/* FLOAT */
if (gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "endianness", &endianness)) {
if (endianness == G_BYTE_ORDER) {
if (width == 32)
context->sample_fmt = SAMPLE_FMT_FLT;
else if (width == 64)
context->sample_fmt = SAMPLE_FMT_DBL;
}
}
} else {
/* INT */
if (gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "depth", &depth) &&
gst_structure_get_boolean (structure, "signed", &signedness) &&
gst_structure_get_int (structure, "endianness", &endianness)) {
if ((endianness == G_BYTE_ORDER) && (signedness == TRUE)) {
if ((width == 16) && (depth == 16))
context->sample_fmt = SAMPLE_FMT_S16;
else if ((width == 32) && (depth == 32))
context->sample_fmt = SAMPLE_FMT_S32;
}
} }
} }
}
switch (format) {
case GST_AUDIO_FORMAT_F32:
context->sample_fmt = SAMPLE_FMT_FLT;
break;
case GST_AUDIO_FORMAT_F64:
context->sample_fmt = SAMPLE_FMT_DBL;
break;
case GST_AUDIO_FORMAT_S32:
context->sample_fmt = SAMPLE_FMT_S32;
break;
case GST_AUDIO_FORMAT_S16:
context->sample_fmt = SAMPLE_FMT_S16;
break;
default:
break;
}
}
/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
* and other video properties in a AVCodecContext. * and other video properties in a AVCodecContext.
...@@ -2808,39 +2762,30 @@ gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context) ...@@ -2808,39 +2762,30 @@ gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
if (!strcmp (mimetype, "video/x-raw")) { if (!strcmp (mimetype, "video/x-raw")) {
id = CODEC_ID_RAWVIDEO; id = CODEC_ID_RAWVIDEO;
video = TRUE; video = TRUE;
} else if (!strcmp (mimetype, "audio/x-raw-int")) { } else if (!strcmp (mimetype, "audio/x-raw")) {
gint depth, width, endianness; GstAudioInfo info;
gboolean signedness;
if (gst_audio_info_from_caps (&info, caps)) {
if (gst_structure_get_int (structure, "endianness", &endianness) && switch (GST_AUDIO_INFO_FORMAT (&info)) {
gst_structure_get_boolean (structure, "signed", &signedness) && case GST_AUDIO_FORMAT_S8:
gst_structure_get_int (structure, "width", &width) && id = CODEC_ID_PCM_S8;
gst_structure_get_int (structure, "depth", &depth) && depth == width) {
switch (depth) {
case 8:
if (signedness) {
id = CODEC_ID_PCM_S8;
} else {
id = CODEC_ID_PCM_U8;
}
break; break;
case 16: case GST_AUDIO_FORMAT_U8:
switch (endianness) { id = CODEC_ID_PCM_U8;
case G_BIG_ENDIAN: break;
if (signedness) { case GST_AUDIO_FORMAT_S16_LE:
id = CODEC_ID_PCM_S16BE; id = CODEC_ID_PCM_S16LE;
} else { break;
id = CODEC_ID_PCM_U16BE; case GST_AUDIO_FORMAT_S16_BE:
} id = CODEC_ID_PCM_S16BE;
break; break;
case G_LITTLE_ENDIAN: case GST_AUDIO_FORMAT_U16_LE:
if (signedness) { id = CODEC_ID_PCM_U16LE;
id = CODEC_ID_PCM_S16LE; break;
} else { case GST_AUDIO_FORMAT_U16_BE:
id = CODEC_ID_PCM_U16LE; id = CODEC_ID_PCM_U16BE;
} break;
break; default:
}
break; break;
} }
if (id != CODEC_ID_NONE) if (id != CODEC_ID_NONE)
......
...@@ -1152,8 +1152,10 @@ gst_ffmpegdec_bufferpool (GstFFMpegDec * ffmpegdec, GstCaps * caps) ...@@ -1152,8 +1152,10 @@ gst_ffmpegdec_bufferpool (GstFFMpegDec * ffmpegdec, GstCaps * caps)
/* and store */ /* and store */
gst_buffer_pool_set_config (pool, config); gst_buffer_pool_set_config (pool, config);
if (ffmpegdec->pool) if (ffmpegdec->pool) {
gst_buffer_pool_set_active (ffmpegdec->pool, FALSE);
gst_object_unref (ffmpegdec->pool); gst_object_unref (ffmpegdec->pool);
}
ffmpegdec->pool = pool; ffmpegdec->pool = pool;
/* and activate */ /* and activate */
......
...@@ -265,8 +265,7 @@ gst_ffmpegmux_base_init (gpointer g_class) ...@@ -265,8 +265,7 @@ gst_ffmpegmux_base_init (gpointer g_class)
if (videosinkcaps) if (videosinkcaps)
gst_caps_unref (videosinkcaps); gst_caps_unref (videosinkcaps);
videosinkcaps = videosinkcaps = gst_caps_from_string ("video/x-raw, format=(string)RGB");
gst_caps_from_string ("video/x-raw-rgb, bpp=(int)24, depth=(int)24");
} }
/* pad templates */ /* pad templates */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment