static gboolean gst_wavenc_sink_setcaps (GstPad * pad, GstCaps * caps) { GstWavEnc *wavenc; GstStructure *structure; const gchar *name; gint chans, rate; GstCaps *ccaps; wavenc = GST_WAVENC (gst_pad_get_parent (pad)); ccaps = gst_pad_get_current_caps (pad); if (wavenc->sent_header && ccaps && !gst_caps_can_intersect (caps, ccaps)) { gst_caps_unref (ccaps); GST_WARNING_OBJECT (wavenc, "cannot change format in middle of stream"); goto fail; } if (ccaps) gst_caps_unref (ccaps); GST_DEBUG_OBJECT (wavenc, "got caps: %" GST_PTR_FORMAT, caps); structure = gst_caps_get_structure (caps, 0); name = gst_structure_get_name (structure); if (!gst_structure_get_int (structure, "channels", &chans) || !gst_structure_get_int (structure, "rate", &rate)) { GST_WARNING_OBJECT (wavenc, "caps incomplete"); goto fail; } if (strcmp (name, "audio/x-raw") == 0) { GstAudioInfo info; if (!gst_audio_info_from_caps (&info, caps)) goto fail; if (GST_AUDIO_INFO_IS_INTEGER (&info)) wavenc->format = GST_RIFF_WAVE_FORMAT_PCM; else if (GST_AUDIO_INFO_IS_FLOAT (&info)) wavenc->format = GST_RIFF_WAVE_FORMAT_IEEE_FLOAT; else goto fail; wavenc->width = GST_AUDIO_INFO_WIDTH (&info); } else if (strcmp (name, "audio/x-alaw") == 0) { wavenc->format = GST_RIFF_WAVE_FORMAT_ALAW; wavenc->width = 8; } else if (strcmp (name, "audio/x-mulaw") == 0) { wavenc->format = GST_RIFF_WAVE_FORMAT_MULAW; wavenc->width = 8; } else { GST_WARNING_OBJECT (wavenc, "Unsupported format %s", name); goto fail; } wavenc->channels = chans; wavenc->rate = rate; GST_LOG_OBJECT (wavenc, "accepted caps: format=0x%04x chans=%u width=%u rate=%u", wavenc->format, wavenc->channels, wavenc->width, wavenc->rate); gst_object_unref (wavenc); return TRUE; fail: gst_object_unref (wavenc); return FALSE; }
static gboolean gst_osx_audio_ring_buffer_acquire (GstAudioRingBuffer * buf, GstAudioRingBufferSpec * spec) { gboolean ret = FALSE, is_passthrough = FALSE; GstOsxAudioRingBuffer *osxbuf; AudioStreamBasicDescription format; osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf); if (RINGBUFFER_IS_SPDIF (spec->type)) { format.mFormatID = kAudioFormat60958AC3; format.mSampleRate = (double) GST_AUDIO_INFO_RATE (&spec->info); format.mChannelsPerFrame = 2; format.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonMixable; format.mBytesPerFrame = 0; format.mBitsPerChannel = 16; format.mBytesPerPacket = 6144; format.mFramesPerPacket = 1536; format.mReserved = 0; spec->segsize = 6144; spec->segtotal = 10; is_passthrough = TRUE; } else { int width, depth; /* Fill out the audio description we're going to be using */ format.mFormatID = kAudioFormatLinearPCM; format.mSampleRate = (double) GST_AUDIO_INFO_RATE (&spec->info); format.mChannelsPerFrame = GST_AUDIO_INFO_CHANNELS (&spec->info); if (GST_AUDIO_INFO_IS_FLOAT (&spec->info)) { format.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; width = depth = GST_AUDIO_INFO_WIDTH (&spec->info); } else { format.mFormatFlags = kAudioFormatFlagIsSignedInteger; width = GST_AUDIO_INFO_WIDTH (&spec->info); depth = GST_AUDIO_INFO_DEPTH (&spec->info); if (width == depth) { format.mFormatFlags |= kAudioFormatFlagIsPacked; } else { format.mFormatFlags |= kAudioFormatFlagIsAlignedHigh; } } if (GST_AUDIO_INFO_IS_BIG_ENDIAN (&spec->info)) { format.mFormatFlags |= kAudioFormatFlagIsBigEndian; } format.mBytesPerFrame = GST_AUDIO_INFO_BPF (&spec->info); format.mBitsPerChannel = depth; format.mBytesPerPacket = GST_AUDIO_INFO_BPF (&spec->info); format.mFramesPerPacket = 1; format.mReserved = 0; spec->segsize = (spec->latency_time * GST_AUDIO_INFO_RATE (&spec->info) / G_USEC_PER_SEC) * GST_AUDIO_INFO_BPF (&spec->info); spec->segtotal = spec->buffer_time / spec->latency_time; is_passthrough = FALSE; } GST_DEBUG_OBJECT (osxbuf, "Format: " CORE_AUDIO_FORMAT, CORE_AUDIO_FORMAT_ARGS (format)); /* gst_audio_ring_buffer_set_channel_positions is not called * since the AUs perform channel reordering themselves. * (see gst_core_audio_set_channel_layout) */ buf->size = spec->segtotal * spec->segsize; buf->memory = g_malloc0 (buf->size); ret = gst_core_audio_initialize (osxbuf->core_audio, format, spec->caps, is_passthrough); if (!ret) { g_free (buf->memory); buf->memory = NULL; buf->size = 0; } osxbuf->segoffset = 0; return ret; }