//end void PhononItem::setTotalTime(qint64 tt) { QTime duration(0,0,0,0); duration = duration.addMSecs(tt); setTrackTime(duration); // qDebug() << "setTotalTime: " << duration; m_timeSet = true; if (m_loaded) { emit fetched(); } }
void TransCoder::pipeRun(int ind) { GstElement *source, *dec, *conv, *encoder, *muxer, *fileout, *tagger, *volume; GstBus *bus; GstState state; GstPad *audiopad;//, *encoderpad; numTrack = ind; bool preenc; int vbr = 0; loop = g_main_loop_new (NULL, FALSE); pipeline = gst_pipeline_new ("audio-transcoder"); // Входной файл source = gst_element_factory_make ("filesrc", "file-source"); g_object_set (source, "location", localFileNamesEncoder->fromUnicode(refparser->getSoundFile()).data(), NULL); dec = gst_element_factory_make ("decodebin", "decoder"); g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL); gst_bin_add_many (GST_BIN (pipeline), source, dec, NULL); gst_element_link (source, dec); audio = gst_bin_new ("audiobin"); conv = gst_element_factory_make ("audioconvert", "aconv"); volume = gst_element_factory_make ("volume", "vol"); audiopad = gst_element_get_static_pad (conv, "sink"); fileout = gst_element_factory_make ("filesink", "file-out"); // Выходной файл QRegExp rxFileSlash("/"); QRegExp rxTilda("^~(.*)"); QString filename; QTextStream out(stdout); QString comment = trUtf8("CuePlayer ") + qApp->applicationVersion(); QString trackName = refparser->getTrackTitle(ind); QString title = refparser->getTitle(); trackName.replace(rxFileSlash, trUtf8("⁄")); title.replace(rxFileSlash, trUtf8("⁄")); if (rxTilda.indexIn(lineEdit->text()) != -1) lineEdit->setText(QDir::homePath() + rxTilda.cap(1)); QDir updir(lineEdit->text()); if (!updir.exists()) updir.mkdir(lineEdit->text()); QString dirname = lineEdit->text() + "/" + title; QDir dir(dirname); if (!dir.exists()) dir.mkdir(dirname); if (ind < 10) filename = dirname + "/" + "0" + QString::number(ind,10) + " - " + trackName + "." + containerBox->currentText(); else filename = dirname + "/" + QString::number(ind,10) + " - " + trackName + "." + containerBox->currentText(); g_object_set (fileout, "location", localFileNamesEncoder->fromUnicode(filename).data(), NULL); tmpfile.setFileName(dirname + "/" + QString::number(ind,10) + " - " + trackName + ".tmp"); switch (codecBox->currentIndex()) { case CODEC_VORBIS: if (tmpfile.exists()) { g_object_set (source, "location", localFileNamesEncoder->fromUnicode(tmpfile.fileName()).data(), NULL); encoder = gst_element_factory_make ("vorbisenc", "audio-encoder"); tagger = gst_element_factory_make ("vorbistag", "tagger"); muxer = gst_element_factory_make ("oggmux", "audio-muxer"); gst_bin_add_many (GST_BIN (audio), conv, encoder, tagger, muxer, fileout, NULL); gst_element_link_many (conv, encoder, tagger, muxer, fileout, NULL); if (!settings.value("preferences/vorbisquality").isNull()) { g_object_set (encoder, "max-bitrate", settings.value("preferences/vorbismaxbitrate").toInt(), "bitrate", settings.value("preferences/vorbisbitrate").toInt(), "min-bitrate", settings.value("preferences/vorbisminbitrate").toInt(), "quality", settings.value("preferences/vorbisquality").toDouble()/10, "managed", settings.value("preferences/vorbismanaged").toBool(), NULL); } gst_tag_setter_add_tags (GST_TAG_SETTER (tagger), GST_TAG_MERGE_REPLACE_ALL, GST_TAG_TITLE, refparser->getTrackTitle(ind).toUtf8().data(), GST_TAG_ARTIST, refparser->getPerformer().toUtf8().data(), GST_TAG_TRACK_NUMBER, ind, GST_TAG_TRACK_COUNT, refparser->getTrackNumber(), GST_TAG_ALBUM, refparser->getAlbum().toUtf8().data(), GST_TAG_ENCODER, APPNAME, GST_TAG_ENCODER_VERSION, qApp->applicationVersion().toUtf8().data(), GST_TAG_COMMENT, comment.toUtf8().data(), GST_TAG_CODEC, "vorbis", NULL); containerBox->setCurrentIndex(CODEC_VORBIS); } else { preenc = true; encoder = gst_element_factory_make ("flacenc", "audio-encoder"); g_object_set(encoder, "quality", 0, NULL); gst_bin_add_many (GST_BIN (audio), conv, volume, encoder, fileout, NULL); gst_element_link_many (conv, volume, encoder, fileout, NULL); g_object_set (volume, "mute", true, NULL); g_object_set (fileout, "location", localFileNamesEncoder->fromUnicode(tmpfile.fileName()).data(), NULL); } break; case CODEC_LAME: encoder = gst_element_factory_make ("lame", "audio-encoder"); muxer = gst_element_factory_make ("id3v2mux", "audio-muxer"); gst_bin_add_many (GST_BIN (audio), conv, encoder, muxer, fileout, NULL); gst_element_link_many (conv, encoder, muxer, fileout, NULL); if (settings.value("preferences/lamevbr").toInt()) vbr = settings.value("preferences/lamevbr").toInt() + 1; if (!settings.value("preferences/lamequality").isNull()) { g_object_set (encoder, "bitrate", bitrateList.at(settings.value("preferences/lamebitrate").toInt()), //"compression-ratio", settings.value("preferences/lamecompressionratio").toInt(), // Баг. Перекрывает VBR "quality", settings.value("preferences/lamequality").toInt(), "mode", settings.value("preferences/lamemode").toInt(), "force-ms", settings.value("preferences/lameforcems").toBool(), "free-format", settings.value("preferences/lamefreeformat").toBool(), "copyright", settings.value("preferences/lamecopyright").toBool(), "original", settings.value("preferences/lameoriginal").toBool(), "error-protection", settings.value("preferences/lameerrprot").toBool(), "padding-type", settings.value("preferences/lamepaddingtype").toInt(), "extension", settings.value("preferences/lameextension").toBool(), "strict-iso", settings.value("preferences/lamestrictiso").toBool(), "vbr", vbr, "disable-reservoir", settings.value("preferences/lamedisrese").toBool(), NULL); } gst_tag_setter_add_tags (GST_TAG_SETTER (muxer), GST_TAG_MERGE_REPLACE_ALL, GST_TAG_TITLE, refparser->getTrackTitle(ind).toUtf8().data(), GST_TAG_ARTIST, refparser->getPerformer().toUtf8().data(), GST_TAG_TRACK_NUMBER, ind, GST_TAG_TRACK_COUNT, refparser->getTrackNumber(), GST_TAG_ALBUM, refparser->getAlbum().toUtf8().data(), GST_TAG_ENCODER, APPNAME, GST_TAG_ENCODER_VERSION, qApp->applicationVersion().toUtf8().data(), GST_TAG_COMMENT, comment.toUtf8().data(), GST_TAG_CODEC, "lame", NULL); containerBox->setCurrentIndex(CODEC_LAME); break; case CODEC_FLAC: encoder = gst_element_factory_make ("flacenc", "audio-encoder"); tagger = gst_element_factory_make ("flactag", "tagger"); if (!settings.value("preferences/flacquality").isNull()) { g_object_set (encoder, "quality", settings.value("preferences/flacquality").toInt(), "streamable-subset", settings.value("preferences/flacstreamablesubset").toBool(), "mid-side-stereo", settings.value("preferences/flacmidsidestereo").toBool(), "loose-mid-side-stereo", settings.value("preferences/flacloosemidsidestereo").toBool(), "blocksize", settings.value("preferences/flacblocksize").toInt(), "max-lpc-order", settings.value("preferences/flacmaxlpcorder").toInt(), "qlp-coeff-precision", settings.value("preferences/flacqlpcoeffprecision").toInt(), "qlp-coeff-prec-search", settings.value("preferences/flacqlpcoeffprecsearch").toBool(), "escape-coding", settings.value("preferences/flacescapecoding").toBool(), "exhaustive-model-search", settings.value("preferences/flacexhaustivemodelsearch").toBool(), "min-residual-partition-order", settings.value("preferences/flacminresidualpartitionorder").toInt(), "max-residual-partition-order", settings.value("preferences/flacmaxresidualpartitionorder").toInt(), "rice-parameter-search-dist", settings.value("preferences/flacriceparametersearchdist").toInt(), NULL); } gst_bin_add_many (GST_BIN (audio), conv, encoder, tagger, fileout, NULL); gst_element_link_many (conv, encoder, tagger, fileout, NULL); gst_tag_setter_add_tags (GST_TAG_SETTER (tagger), GST_TAG_MERGE_REPLACE_ALL, GST_TAG_TITLE, refparser->getTrackTitle(ind).toUtf8().data(), GST_TAG_ARTIST, refparser->getPerformer().toUtf8().data(), GST_TAG_TRACK_NUMBER, ind, GST_TAG_TRACK_COUNT, refparser->getTrackNumber(), GST_TAG_ALBUM, refparser->getAlbum().toUtf8().data(), GST_TAG_ENCODER, APPNAME, GST_TAG_ENCODER_VERSION, qApp->applicationVersion().toUtf8().data(), GST_TAG_COMMENT, comment.toUtf8().data(), GST_TAG_CODEC, "flac", NULL); containerBox->setCurrentIndex(CODEC_FLAC); break; case CODEC_FAAC: encoder = gst_element_factory_make ("faac", "audio-encoder"); gst_bin_add_many (GST_BIN (audio), conv, encoder, fileout, NULL); gst_element_link_many (conv, encoder, fileout, NULL); if (!settings.value("preferences/faacprofile").isNull()) { g_object_set(encoder, "outputformat", settings.value("preferences/faacoutputformat").toInt(), "bitrate", settings.value("preferences/faacbitrate").toInt(), "profile", settings.value("preferences/faacprofile").toInt()+1, "tns", settings.value("preferences/faactns").toBool(), "midside", settings.value("preferences/faacmidside").toBool(), "shortctl", settings.value("preferences/faacshortctl").toInt(), NULL); } containerBox->setCurrentIndex(CODEC_FAAC); break; case CODEC_NO: default: break; } gst_element_add_pad (audio, gst_ghost_pad_new ("sink", audiopad)); gst_object_unref (audiopad); gst_bin_add (GST_BIN (pipeline), audio); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); //g_signal_connect (pipeline, "deep-notify", G_CALLBACK (gst_object_default_deep_notify), NULL); // Дебаг! out << trUtf8("Кодируется: ") << refparser->getSoundFile() << endl; gst_element_set_state (pipeline, GST_STATE_PLAYING); gst_element_get_state( GST_ELEMENT(pipeline), &state, NULL, GST_MSECOND * 300); if (state == GST_STATE_PLAYING) { timer->start(TIME); if (ind == refparser->getTrackNumber()) setTrackTime(refparser->getTrackIndex(ind),saveTotalTime); else setTrackTime(refparser->getTrackIndex(ind),refparser->getTrackIndex(ind+1)); if (preenc) g_object_set (volume, "mute", false, NULL); g_print ("Запущено...\n"); g_main_loop_run (loop); } else { out << trUtf8("Ошибка перехода в PLAYING\n"); transcode = false; stopAll(); } }