Codereview comments from r637
This commit is contained in:
parent
031752823c
commit
1b0b8979df
|
@ -68,7 +68,7 @@ GstEngine::~GstEngine() {
|
|||
gst_object_unref(GST_OBJECT(can_decode_pipeline_));
|
||||
|
||||
// Destroy scope delay queue
|
||||
ClearScopeQ();
|
||||
ClearScopeBuffers();
|
||||
g_queue_free(delayq_);
|
||||
|
||||
// Save configuration
|
||||
|
@ -147,7 +147,7 @@ bool GstEngine::CanDecode(const QUrl &url) {
|
|||
}
|
||||
|
||||
void GstEngine::CanDecodeNewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer self) {
|
||||
GstEngine* instance = static_cast<GstEngine*>(self);
|
||||
GstEngine* instance = reinterpret_cast<GstEngine*>(self);
|
||||
|
||||
GstCaps* caps = gst_pad_get_caps(pad);
|
||||
if (gst_caps_get_size(caps) > 0) {
|
||||
|
@ -159,7 +159,7 @@ void GstEngine::CanDecodeNewPadCallback(GstElement*, GstPad* pad, gboolean, gpoi
|
|||
}
|
||||
|
||||
void GstEngine::CanDecodeLastCallback(GstElement*, gpointer self) {
|
||||
GstEngine* instance = static_cast<GstEngine*>(self);
|
||||
GstEngine* instance = reinterpret_cast<GstEngine*>(self);
|
||||
instance->can_decode_last_ = true;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ Engine::State GstEngine::state() const {
|
|||
}
|
||||
}
|
||||
|
||||
void GstEngine::NewBuffer(GstBuffer* buf) {
|
||||
void GstEngine::AddBufferToScope(GstBuffer* buf) {
|
||||
g_queue_push_tail(delayq_, buf);
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ bool GstEngine::Load(const QUrl& url) {
|
|||
void GstEngine::StartFadeout() {
|
||||
fadeout_pipeline_ = current_pipeline_;
|
||||
disconnect(fadeout_pipeline_.get(), 0, 0, 0);
|
||||
ClearScopeQ();
|
||||
ClearScopeBuffers();
|
||||
|
||||
fadeout_pipeline_->StartFader(fadeout_duration_, QTimeLine::Backward);
|
||||
connect(fadeout_pipeline_.get(), SIGNAL(FaderFinished()), SLOT(FadeoutFinished()));
|
||||
|
@ -380,7 +380,7 @@ void GstEngine::Seek(uint ms) {
|
|||
return;
|
||||
|
||||
if (current_pipeline_->Seek(ms * GST_MSECOND))
|
||||
ClearScopeQ();
|
||||
ClearScopeBuffers();
|
||||
else
|
||||
qDebug() << "Seek failed";
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ void GstEngine::timerEvent( QTimerEvent* ) {
|
|||
}
|
||||
|
||||
void GstEngine::HandlePipelineError(const QString& message) {
|
||||
qDebug() << "Gstreamer error:" << message;
|
||||
qWarning() << "Gstreamer error:" << message;
|
||||
|
||||
current_pipeline_.reset();
|
||||
}
|
||||
|
@ -493,11 +493,11 @@ shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline(const QUrl& url) {
|
|||
ret->set_output_device(sink_, device_);
|
||||
|
||||
connect(ret.get(), SIGNAL(EndOfStreamReached()), SLOT(EndOfStreamReached()));
|
||||
connect(ret.get(), SIGNAL(BufferFound(GstBuffer*)), SLOT(NewBuffer(GstBuffer*)));
|
||||
connect(ret.get(), SIGNAL(BufferFound(GstBuffer*)), SLOT(AddBufferToScope(GstBuffer*)));
|
||||
connect(ret.get(), SIGNAL(Error(QString)), SLOT(HandlePipelineError(QString)));
|
||||
connect(ret.get(), SIGNAL(MetadataFound(Engine::SimpleMetaBundle)),
|
||||
SLOT(NewMetaData(Engine::SimpleMetaBundle)));
|
||||
connect(ret.get(), SIGNAL(destroyed()), SLOT(ClearScopeQ()));
|
||||
connect(ret.get(), SIGNAL(destroyed()), SLOT(ClearScopeBuffers()));
|
||||
|
||||
if (!ret->Init(url))
|
||||
ret.reset();
|
||||
|
@ -510,7 +510,7 @@ qint64 GstEngine::PruneScope() {
|
|||
return 0;
|
||||
|
||||
// get the position playing in the audio device
|
||||
gint64 pos = current_pipeline_->position();
|
||||
qint64 pos = current_pipeline_->position();
|
||||
|
||||
GstBuffer *buf = 0;
|
||||
quint64 etime;
|
||||
|
@ -538,7 +538,7 @@ qint64 GstEngine::PruneScope() {
|
|||
return pos;
|
||||
}
|
||||
|
||||
void GstEngine::ClearScopeQ() {
|
||||
void GstEngine::ClearScopeBuffers() {
|
||||
// just free them all
|
||||
while (g_queue_get_length(delayq_)) {
|
||||
GstBuffer* buf = reinterpret_cast<GstBuffer *>( g_queue_pop_head(delayq_) );
|
||||
|
|
|
@ -99,8 +99,8 @@ class GstEngine : public Engine::Base {
|
|||
void EndOfStreamReached();
|
||||
void HandlePipelineError(const QString& message);
|
||||
void NewMetaData(const Engine::SimpleMetaBundle& bundle);
|
||||
void NewBuffer(GstBuffer* buf);
|
||||
void ClearScopeQ();
|
||||
void AddBufferToScope(GstBuffer* buf);
|
||||
void ClearScopeBuffers();
|
||||
void FadeoutFinished();
|
||||
|
||||
private:
|
||||
|
|
|
@ -48,6 +48,15 @@ void GstEnginePipeline::set_output_device(const QString &sink, const QString &de
|
|||
bool GstEnginePipeline::Init(const QUrl &url) {
|
||||
pipeline_ = gst_pipeline_new("pipeline");
|
||||
|
||||
// Here we create all the parts of the gstreamer pipeline - from the source
|
||||
// to the sink. The parts of the pipeline are split up into bins:
|
||||
// source -> decode bin -> audio bin
|
||||
// The decode bin is a gstreamer builtin that automatically picks the right
|
||||
// decoder for the file.
|
||||
// The audio bin gets created here and contains:
|
||||
// audioconvert -> equalizer -> volume -> audioscale -> audioconvert ->
|
||||
// audiosink
|
||||
|
||||
// Source
|
||||
src_ = GstEngine::CreateElement("giosrc");
|
||||
if (!src_)
|
||||
|
@ -60,13 +69,14 @@ bool GstEnginePipeline::Init(const QUrl &url) {
|
|||
if (!(decodebin_ = GstEngine::CreateElement("decodebin", pipeline_))) { return false; }
|
||||
g_signal_connect(G_OBJECT(decodebin_), "new-decoded-pad", G_CALLBACK(NewPadCallback), this);
|
||||
|
||||
// Does some stuff with ghost pads
|
||||
GstPad* pad = gst_element_get_pad(decodebin_, "sink");
|
||||
if (pad) {
|
||||
event_cb_id_ = gst_pad_add_event_probe (pad, G_CALLBACK(EventCallback), this);
|
||||
gst_object_unref(pad);
|
||||
}
|
||||
|
||||
// The link from decodebin to audioconvert will be made in the newPad-callback
|
||||
// The link from decodebin to audioconvert will be made in NewPadCallback
|
||||
gst_element_link(src_, decodebin_);
|
||||
|
||||
// Audio bin
|
||||
|
@ -90,8 +100,8 @@ bool GstEnginePipeline::Init(const QUrl &url) {
|
|||
gst_element_add_pad(audiobin_, gst_ghost_pad_new("sink", pad));
|
||||
gst_object_unref(pad);
|
||||
|
||||
// add a data probe on the src pad if the audioconvert element for our scope
|
||||
// we do it here because we want pre-equalized and pre-volume samples
|
||||
// Add a data probe on the src pad of the audioconvert element for our scope.
|
||||
// We do it here because we want pre-equalized and pre-volume samples
|
||||
// so that our visualization are not affected by them
|
||||
pad = gst_element_get_pad(audioconvert_, "src");
|
||||
gst_pad_add_buffer_probe(pad, G_CALLBACK(HandoffCallback), this);
|
||||
|
@ -134,7 +144,7 @@ GstEnginePipeline::~GstEnginePipeline() {
|
|||
|
||||
|
||||
gboolean GstEnginePipeline::BusCallback(GstBus*, GstMessage* msg, gpointer self) {
|
||||
GstEnginePipeline* instance = static_cast<GstEnginePipeline*>(self);
|
||||
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
|
||||
|
||||
switch ( GST_MESSAGE_TYPE(msg)) {
|
||||
case GST_MESSAGE_ERROR: {
|
||||
|
@ -142,40 +152,40 @@ gboolean GstEnginePipeline::BusCallback(GstBus*, GstMessage* msg, gpointer self)
|
|||
gchar* debugs;
|
||||
|
||||
gst_message_parse_error(msg, &error, &debugs);
|
||||
qDebug() << "ERROR RECEIVED IN BUS_CB <" << error->message << ">" ;
|
||||
qWarning() << "ERROR RECEIVED IN BUS_CB <" << error->message << ">" ;
|
||||
|
||||
emit instance->Error(QString::fromAscii(error->message));
|
||||
break;
|
||||
}
|
||||
|
||||
case GST_MESSAGE_TAG: {
|
||||
gchar* string=NULL;
|
||||
gchar* data = NULL;
|
||||
Engine::SimpleMetaBundle bundle;
|
||||
GstTagList* taglist;
|
||||
gst_message_parse_tag(msg,&taglist);
|
||||
bool success = false;
|
||||
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_TITLE, &string ) && string ) {
|
||||
qDebug() << "received tag 'Title': " << QString( string ) ;
|
||||
bundle.title = string;
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_TITLE, &data ) && data ) {
|
||||
qDebug() << "received tag 'Title': " << QString( data ) ;
|
||||
bundle.title = data;
|
||||
success = true;
|
||||
}
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_ARTIST, &string ) && string ) {
|
||||
qDebug() << "received tag 'Artist': " << QString( string ) ;
|
||||
bundle.artist = string;
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_ARTIST, &data ) && data ) {
|
||||
qDebug() << "received tag 'Artist': " << QString( data ) ;
|
||||
bundle.artist = data;
|
||||
success = true;
|
||||
}
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_COMMENT, &string ) && string ) {
|
||||
qDebug() << "received tag 'Comment': " << QString( string ) ;
|
||||
bundle.comment = string;
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_COMMENT, &data ) && data ) {
|
||||
qDebug() << "received tag 'Comment': " << QString( data ) ;
|
||||
bundle.comment = data;
|
||||
success = true;
|
||||
}
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_ALBUM, &string ) && string ) {
|
||||
qDebug() << "received tag 'Album': " << QString( string ) ;
|
||||
bundle.album = string;
|
||||
if ( gst_tag_list_get_string( taglist, GST_TAG_ALBUM, &data ) && data ) {
|
||||
qDebug() << "received tag 'Album': " << QString( data ) ;
|
||||
bundle.album = data;
|
||||
success = true;
|
||||
}
|
||||
g_free(string);
|
||||
g_free(data);
|
||||
gst_tag_list_free(taglist);
|
||||
if (success)
|
||||
emit instance->MetadataFound(bundle);
|
||||
|
@ -189,7 +199,7 @@ gboolean GstEnginePipeline::BusCallback(GstBus*, GstMessage* msg, gpointer self)
|
|||
}
|
||||
|
||||
GstBusSyncReply GstEnginePipeline::BusCallbackSync(GstBus*, GstMessage* msg, gpointer self) {
|
||||
GstEnginePipeline* instance = static_cast<GstEnginePipeline*>(self);
|
||||
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
|
||||
switch (GST_MESSAGE_TYPE(msg)) {
|
||||
case GST_MESSAGE_EOS:
|
||||
emit instance->EndOfStreamReached();
|
||||
|
@ -204,7 +214,7 @@ GstBusSyncReply GstEnginePipeline::BusCallbackSync(GstBus*, GstMessage* msg, gpo
|
|||
|
||||
|
||||
void GstEnginePipeline::NewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer self) {
|
||||
GstEnginePipeline* instance = static_cast<GstEnginePipeline*>(self);
|
||||
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
|
||||
GstPad* const audiopad = gst_element_get_pad(instance->audiobin_, "sink");
|
||||
|
||||
if (GST_PAD_IS_LINKED(audiopad)) {
|
||||
|
@ -219,7 +229,7 @@ void GstEnginePipeline::NewPadCallback(GstElement*, GstPad* pad, gboolean, gpoin
|
|||
|
||||
|
||||
void GstEnginePipeline::HandoffCallback(GstPad*, GstBuffer* buf, gpointer self) {
|
||||
GstEnginePipeline* instance = static_cast<GstEnginePipeline*>(self);
|
||||
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
|
||||
|
||||
if (instance->forwards_buffers_) {
|
||||
gst_buffer_ref(buf);
|
||||
|
@ -228,9 +238,9 @@ void GstEnginePipeline::HandoffCallback(GstPad*, GstBuffer* buf, gpointer self)
|
|||
}
|
||||
|
||||
void GstEnginePipeline::EventCallback(GstPad*, GstEvent* event, gpointer self) {
|
||||
GstEnginePipeline* instance = static_cast<GstEnginePipeline*>(self);
|
||||
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
|
||||
|
||||
switch(static_cast<int>(event->type)) {
|
||||
switch(event->type) {
|
||||
case GST_EVENT_EOS:
|
||||
emit instance->EndOfStreamReached();
|
||||
break;
|
||||
|
@ -260,7 +270,7 @@ qint64 GstEnginePipeline::length() const {
|
|||
|
||||
GstState GstEnginePipeline::state() const {
|
||||
GstState s, sp;
|
||||
if (gst_element_get_state(pipeline_, &s, &sp, kGstStateTimeout) ==
|
||||
if (gst_element_get_state(pipeline_, &s, &sp, kGstStateTimeoutNanosecs) ==
|
||||
GST_STATE_CHANGE_FAILURE)
|
||||
return GST_STATE_NULL;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class GstEnginePipeline : public QObject {
|
|||
void UpdateVolume();
|
||||
|
||||
private:
|
||||
static const int kGstStateTimeout = 10000000;
|
||||
static const int kGstStateTimeoutNanosecs = 10000000;
|
||||
|
||||
bool valid_;
|
||||
QString sink_;
|
||||
|
|
Loading…
Reference in New Issue