Exemple #1
0
void PlayerGst::timerUpdate()
{
	GstMessage* message;
	while(!usePlaybin && (message = gst_bus_pop(bus), message)) {
		switch (GST_MESSAGE_TYPE (message)) {
		case GST_MESSAGE_ERROR: {
			GError *err;
			gchar *debug;
			gst_message_parse_error (message, &err, &debug);
			QString str;
			str = "Error #"+QString::number(err->code)+" in module "+QString::number(err->domain)+"\n"+QString::fromUtf8(err->message);
			if(err->code == 6 && err->domain == 851) {
				str += "\nMay be you should to install gstreamer0.10-plugins-ugly or gstreamer0.10-plugins-bad";
			}
			QMessageBox::warning(0, "Gstreamer error", str);
			g_error_free (err);
			g_free (debug);
			break;
		}
		case GST_MESSAGE_EOS:
			need_finish();
			//QMessageBox::information(0, "", "EOS");
			return;
		default:
			break;
		}
	}
    if(playing()) {
		gint64 p;
		GstFormat fmt = GST_FORMAT_TIME;
		gst_element_query_position(pipeline, &fmt, &p);
		emit position((double)(p - Gstart) / Glength);
    }
}
Exemple #2
0
void TrackAnalyser::messageReceived(GstMessage *message)
{
        switch (GST_MESSAGE_TYPE (message)) {
        case GST_MESSAGE_ERROR: {
                GError *err;
                gchar *debug;
                gst_message_parse_error (message, &err, &debug);
                QString str;
                str = "Error #"+QString::number(err->code)+" in module "+QString::number(err->domain)+"\n"+QString::fromUtf8(err->message);
                if(err->code == 6 && err->domain == 851) {
                        str += "\nMay be you should to install gstreamer0.10-plugins-ugly or gstreamer0.10-plugins-bad";
                }
                qDebug()<< "Gstreamer error:"<< str;
                g_error_free (err);
                g_free (debug);
                need_finish();
                break;
        }
        case GST_MESSAGE_EOS:{
                qDebug() << __PRETTY_FUNCTION__ <<":"<<parentWidget()->objectName()<<" End of track reached";
                need_finish();
                break;
        }
        case GST_MESSAGE_ELEMENT:{
                GstClockTime timestamp;

                const GstStructure *s = gst_message_get_structure (message);
                const gchar *name = gst_structure_get_name (s);

                if (strcmp (name, "cutter") == 0) {
                    gst_structure_get_clock_time (s, "timestamp", &timestamp);
                    const GValue *value;
                    value=gst_structure_get_value (s, "above");
                    bool isSilent=!g_value_get_boolean(value);

                    //if we detect a falling edge, set EndPostion to this
                    if (isSilent)
                        m_EndPosition=QTime(0,0).addMSecs( static_cast<uint>( ( timestamp / GST_MSECOND ) )); // nanosec -> msec
                    else
                    {
                        //if this is the first rising edge, set StartPosition
                        if (m_StartPosition==QTime(0,0) && m_EndPosition==m_MaxPosition)
                            m_StartPosition=QTime(0,0).addMSecs( static_cast<uint>( ( timestamp / GST_MSECOND ) )); // nanosec -> msec

                        //if we detect a rising edge, set EndPostion to track end
                        m_EndPosition=m_MaxPosition;
                    }
                    //qDebug() << __PRETTY_FUNCTION__ <<QTime(0,0).addMSecs( static_cast<uint>( ( timestamp / GST_MSECOND ) ))<< " silent:" << isSilent;
                }
            break;
          }

        case GST_MESSAGE_TAG:{

                const GstStructure *s = gst_message_get_structure (message);
                const GValue *value;
                value=gst_structure_get_value (s, "replaygain-track-gain");
                if (value){
                    m_GainDB = g_value_get_double (value);
                    //qDebug() << "Gain-db:" << gain_db;
                    //qDebug() << "Gain-norm:" << pow (10, m_GainDB / 20);
                }
            }

        default:
                break;
        }

}