static gboolean settings_changed (GstFFMpegAudDec * ffmpegdec, AVFrame * frame) { GstAudioFormat format; gint channels = av_get_channel_layout_nb_channels (av_frame_get_channel_layout (frame)); format = gst_ffmpeg_smpfmt_to_audioformat (frame->format); if (format == GST_AUDIO_FORMAT_UNKNOWN) return TRUE; return !(ffmpegdec->info.rate == av_frame_get_sample_rate (frame) && ffmpegdec->info.channels == channels && ffmpegdec->info.finfo->format == format); }
static gboolean gst_ffmpegauddec_negotiate (GstFFMpegAudDec * ffmpegdec, AVCodecContext * context, AVFrame * frame, gboolean force) { GstFFMpegAudDecClass *oclass; GstAudioFormat format; gint channels; GstAudioChannelPosition pos[64] = { 0, }; oclass = (GstFFMpegAudDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec)); format = gst_ffmpeg_smpfmt_to_audioformat (frame->format); if (format == GST_AUDIO_FORMAT_UNKNOWN) goto no_caps; channels = av_get_channel_layout_nb_channels (av_frame_get_channel_layout (frame)); if (channels == 0) channels = av_frame_get_channels (frame); if (channels == 0) goto no_caps; if (!force && !settings_changed (ffmpegdec, frame)) return TRUE; GST_DEBUG_OBJECT (ffmpegdec, "Renegotiating audio from %dHz@%dchannels (%d) to %dHz@%dchannels (%d)", ffmpegdec->info.rate, ffmpegdec->info.channels, ffmpegdec->info.finfo->format, av_frame_get_sample_rate (frame), channels, format); gst_ffmpeg_channel_layout_to_gst (av_frame_get_channel_layout (frame), channels, pos); memcpy (ffmpegdec->ffmpeg_layout, pos, sizeof (GstAudioChannelPosition) * channels); /* Get GStreamer channel layout */ gst_audio_channel_positions_to_valid_order (pos, channels); ffmpegdec->needs_reorder = memcmp (pos, ffmpegdec->ffmpeg_layout, sizeof (pos[0]) * channels) != 0; gst_audio_info_set_format (&ffmpegdec->info, format, av_frame_get_sample_rate (frame), channels, pos); if (!gst_audio_decoder_set_output_format (GST_AUDIO_DECODER (ffmpegdec), &ffmpegdec->info)) goto caps_failed; return TRUE; /* ERRORS */ no_caps: { #ifdef HAVE_LIBAV_UNINSTALLED /* using internal ffmpeg snapshot */ GST_ELEMENT_ERROR (ffmpegdec, CORE, NEGOTIATION, ("Could not find GStreamer caps mapping for libav codec '%s'.", oclass->in_plugin->name), (NULL)); #else /* using external ffmpeg */ GST_ELEMENT_ERROR (ffmpegdec, CORE, NEGOTIATION, ("Could not find GStreamer caps mapping for libav codec '%s', and " "you are using an external libavcodec. This is most likely due to " "a packaging problem and/or libavcodec having been upgraded to a " "version that is not compatible with this version of " "gstreamer-libav. Make sure your gstreamer-libav and libavcodec " "packages come from the same source/repository.", oclass->in_plugin->name), (NULL)); #endif return FALSE; } caps_failed: { GST_ELEMENT_ERROR (ffmpegdec, CORE, NEGOTIATION, (NULL), ("Could not set caps for libav decoder (%s), not fixed?", oclass->in_plugin->name)); memset (&ffmpegdec->info, 0, sizeof (ffmpegdec->info)); return FALSE; } }
int AudioSamples::sampleRate() const { return m_raw ? av_frame_get_sample_rate(m_raw) : 0; }