Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8242530: [macos] Some audio files miss spectrum data when another aud…
…io file plays first

Reviewed-by: kcr, arapte
  • Loading branch information
Alexander Matveev committed Apr 16, 2020
1 parent 7044cef commit e82046e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Expand Up @@ -270,6 +270,7 @@ gst_spectrum_init (GstSpectrum * spectrum)
spectrum->bps_user = 0;
spectrum->bpf_user = 0;
spectrum->user_data = NULL;
spectrum->post_message_callback = NULL;
#endif // GSTREAMER_LITE and OSX

g_mutex_init (&spectrum->lock);
Expand Down Expand Up @@ -1060,7 +1061,15 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
m = gst_spectrum_message_new (spectrum, spectrum->message_ts,
spectrum->interval);

#if defined (GSTREAMER_LITE) && defined (OSX)
if (spectrum->post_message_callback != NULL) {
spectrum->post_message_callback(GST_ELEMENT (spectrum), m);
} else {
gst_element_post_message (GST_ELEMENT (spectrum), m);
}
#else // GSTREAMER_LITE && OSX
gst_element_post_message (GST_ELEMENT (spectrum), m);
#endif // GSTREAMER_LITE && OSX
#ifndef GSTREAMER_LITE
}
#endif // GSTREAMER_LITE
Expand Down
Expand Up @@ -40,6 +40,15 @@ typedef struct _GstSpectrumChannel GstSpectrumChannel;
typedef void (*GstSpectrumInputData)(const guint8 * in, gfloat * out,
guint len, guint channels, gfloat max_value, guint op, guint nfft);

#if defined (GSTREAMER_LITE) && defined (OSX)
// Used to overwrite post_message callback to get spectrum messages in OSXPlatform.
// We cannot use GST_ELEMENT_GET_CLASS(spectrum)->post_message, since it will
// change callback for all instances of spectrum elements and it will conflict
// with GStreamer platform.
typedef gboolean (*PostMessageCallbackProc)(GstElement * element,
GstMessage * message);
#endif // GSTREAMER_LITE and OSX

struct _GstSpectrumChannel
{
gfloat *input;
Expand Down Expand Up @@ -86,6 +95,7 @@ struct _GstSpectrum
guint bps_user; // User provided values to avoid more complex spectrum initialization
guint bpf_user;
void *user_data;
PostMessageCallbackProc post_message_callback;
#endif // GSTREAMER_LITE and OSX
};

Expand Down
Expand Up @@ -272,10 +272,10 @@ void AVFAudioSpectrumUnit::SetupSpectralProcessor() {
mSpectrum = GST_SPECTRUM(mSpectrumElement);
mSpectrum->user_data = (void*)this;

// Set our own callback for post message
GstElementClass *klass;
klass = GST_ELEMENT_GET_CLASS(mSpectrumElement);
klass->post_message = PostMessageCallback;
// Set our own callback for post message, do not use
// GST_ELEMENT_GET_CLASS(mSpectrumElement)->post_message, since it will change
// callback for all instances of spectrum element.
mSpectrum->post_message_callback = PostMessageCallback;

// Configure spectrum element
// Do send magnitude and phase information, off by default
Expand Down

0 comments on commit e82046e

Please sign in to comment.