1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-28 10:09:24 +01:00

Set appsrc's flow control callbacks, and throttle data from libspotify when the buffer gets full.

This commit is contained in:
David Sansome 2011-11-28 18:28:28 +00:00
parent 05460f9975
commit 86363d8b63
3 changed files with 39 additions and 0 deletions

View File

@ -27,6 +27,7 @@
MediaPipeline::MediaPipeline(int port, quint64 length_msec)
: port_(port),
length_msec_(length_msec),
accepting_data_(true),
pipeline_(NULL),
appsrc_(NULL),
byte_rate_(1),
@ -70,8 +71,17 @@ bool MediaPipeline::Init(int sample_rate, int channels) {
g_object_set(G_OBJECT(tcpsink_), "host", "127.0.0.1", NULL);
g_object_set(G_OBJECT(tcpsink_), "port", port_, NULL);
// We know the time of each buffer
g_object_set(G_OBJECT(appsrc_), "format", GST_FORMAT_TIME, NULL);
// Set callbacks for when to start/stop pushing data
GstAppSrcCallbacks callbacks;
callbacks.enough_data = EnoughDataCallback;
callbacks.need_data = NeedDataCallback;
callbacks.seek_data = SeekDataCallback;
gst_app_src_set_callbacks(appsrc_, &callbacks, this, NULL);
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
const int endianness = G_BIG_ENDIAN;
#elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN
@ -126,3 +136,20 @@ void MediaPipeline::EndStream() {
gst_app_src_end_of_stream(appsrc_);
}
void MediaPipeline::NeedDataCallback(GstAppSrc* src, guint length, void* data) {
MediaPipeline* me = reinterpret_cast<MediaPipeline*>(data);
me->accepting_data_ = true;
}
void MediaPipeline::EnoughDataCallback(GstAppSrc* src, void* data) {
MediaPipeline* me = reinterpret_cast<MediaPipeline*>(data);
me->accepting_data_ = false;
}
gboolean MediaPipeline::SeekDataCallback(GstAppSrc* src, guint64 offset, void * data) {
//MediaPipeline* me = reinterpret_cast<MediaPipeline*>(data);
qLog(Debug) << "Gstreamer wants seek to" << offset;
return false;
}

View File

@ -32,17 +32,25 @@ public:
~MediaPipeline();
bool is_initialised() const { return pipeline_; }
bool is_accepting_data() const { return accepting_data_; }
bool Init(int sample_rate, int channels);
void WriteData(const char* data, qint64 length);
void EndStream();
private:
static void NeedDataCallback(GstAppSrc* src, guint length, void* data);
static void EnoughDataCallback(GstAppSrc* src, void* data);
static gboolean SeekDataCallback(GstAppSrc* src, guint64 offset, void* data);
private:
Q_DISABLE_COPY(MediaPipeline)
const int port_;
const quint64 length_msec_;
bool accepting_data_;
GstElement* pipeline_;
GstAppSrc* appsrc_;
GstElement* tcpsink_;

View File

@ -651,6 +651,10 @@ int SpotifyClient::MusicDeliveryCallback(
}
}
if (!me->media_pipeline_->is_accepting_data()) {
return 0;
}
me->media_pipeline_->WriteData(
reinterpret_cast<const char*>(frames),
num_frames * format->channels * 2);