* limitations under the License.
*/
+#include <gst/audio/audio.h>
#include "webrtc.h"
#include "webrtc_private.h"
#include <tbm_surface_internal.h>
}
}
+static GstAudioFormat __get_gst_audio_format(media_format_mimetype_e mime_type)
+{
+ switch (mime_type) {
+ /* RAW formats */
+ case MEDIA_FORMAT_PCM_S16LE:
+ return GST_AUDIO_FORMAT_S16LE;
+ case MEDIA_FORMAT_PCM_S24LE:
+ return GST_AUDIO_FORMAT_S24_32LE;
+ /* ENCODED formats */
+ case MEDIA_FORMAT_OPUS:
+ case MEDIA_FORMAT_VORBIS:
+ return GST_AUDIO_FORMAT_ENCODED;
+ default:
+ LOG_ERROR("not supported mime_type(0x%x)", mime_type);
+ return GST_AUDIO_FORMAT_UNKNOWN;
+ }
+}
+
static bool __is_supported_mime_type(media_format_mimetype_e mime_type)
{
switch (mime_type) {
if (source->media_types == MEDIA_TYPE_AUDIO) {
int channels;
int samplerate;
+ GstAudioInfo info;
+ GstAudioFormat format;
RET_VAL_IF(media_format_get_audio_info(source->media_format, &mime_type, &channels, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
NULL, "failed to media_format_get_audio_info()");
- caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW,
- "format", G_TYPE_STRING, __get_format_name(mime_type),
- "channels", G_TYPE_INT, channels,
- "rate", G_TYPE_INT, samplerate,
- NULL);
+
+ format = __get_gst_audio_format(mime_type);
+ RET_VAL_IF(format == GST_AUDIO_FORMAT_ENCODED || format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "could not get valid GstAudioFormat for PCM");
+
+ gst_audio_info_set_format(&info, format, samplerate, channels, NULL);
+ caps = gst_audio_info_to_caps(&info);
} else if (source->media_types == MEDIA_TYPE_VIDEO) {
int width;
return WEBRTC_ERROR_INVALID_OPERATION;
}
- g_object_set(G_OBJECT(appsrc), "emit-signals", TRUE, "is-live", TRUE, "format", 3, NULL); /* format 3 for time format of the segment events and seek */
+ g_object_set(G_OBJECT(appsrc), "emit-signals", TRUE, "is-live", TRUE, "format", GST_FORMAT_TIME, NULL);
_connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "need-data", G_CALLBACK(_appsrc_need_data_cb), source);
_connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "enough-data", G_CALLBACK(_appsrc_enough_data_cb), source);