Make gstreamer pipeline detect filetype

This commit is contained in:
Jonas Kvinge 2019-09-09 22:11:13 +02:00
parent 4496760340
commit c66c1e17d3
3 changed files with 68 additions and 20 deletions

View File

@ -601,7 +601,48 @@ bool Song::IsFileLossless() const {
}
}
Song::FileType Song::FiletypeByExtension(QString ext) {
Song::FileType Song::FiletypeByMimetype(const QString &mimetype) {
if (mimetype.toLower() == "audio/wav" || mimetype.toLower() == "audio/x-wav") return Song::FileType_WAV;
else if (mimetype.toLower() == "audio/x-flac") return Song::FileType_FLAC;
else if (mimetype.toLower() == "audio/x-wavpack") return Song::FileType_WavPack;
else if (mimetype.toLower() == "audio/x-vorbis") return Song::FileType_OggVorbis;
else if (mimetype.toLower() == "audio/x-opus") return Song::FileType_OggOpus;
else if (mimetype.toLower() == "audio/x-speex") return Song::FileType_OggSpeex;
// Gstreamer returns audio/mpeg for both MP3 and MP4/AAC.
// else if (mimetype.toLower() == "audio/mpeg") return Song::FileType_MPEG;
else if (mimetype.toLower() == "audio/aac") return Song::FileType_MP4;
else if (mimetype.toLower() == "audio/x-wma") return Song::FileType_ASF;
else if (mimetype.toLower() == "audio/aiff" || mimetype.toLower() == "audio/x-aiff") return Song::FileType_AIFF;
else if (mimetype.toLower() == "application/x-project") return Song::FileType_MPC;
else if (mimetype.toLower() == "audio/x-dsf") return Song::FileType_DSF;
else if (mimetype.toLower() == "audio/x-dsd") return Song::FileType_DSDIFF;
else if (mimetype.toLower() == "audio/x-ape" || mimetype.toLower() == "application/x-ape" || mimetype.toLower() == "audio/x-ffmpeg-parsed-ape") return Song::FileType_APE;
else return Song::FileType_Unknown;
}
Song::FileType Song::FiletypeByDescription(const QString &text) {
if (text == "WAV") return Song::FileType_WAV;
else if (text == "Free Lossless Audio Codec (FLAC)") return Song::FileType_FLAC;
else if (text == "Wavpack") return Song::FileType_WavPack;
else if (text == "Vorbis") return Song::FileType_OggVorbis;
else if (text == "Opus") return Song::FileType_OggOpus;
else if (text == "Speex") return Song::FileType_OggSpeex;
else if (text == "MPEG-1 Layer 3 (MP3)") return Song::FileType_MPEG;
else if (text == "MPEG-4 AAC") return Song::FileType_MP4;
else if (text == "WMA") return Song::FileType_ASF;
else if (text == "Audio Interchange File Format") return Song::FileType_AIFF;
else if (text == "MPC") return Song::FileType_MPC;
else if (text == "audio/x-dsf") return Song::FileType_DSF;
else if (text == "audio/x-dsd") return Song::FileType_DSDIFF;
else if (text == "audio/x-ffmpeg-parsed-ape") return Song::FileType_APE;
else return Song::FileType_Unknown;
}
Song::FileType Song::FiletypeByExtension(const QString &ext) {
if (ext.toLower() == "wav" || ext.toLower() == "wave") return Song::FileType_WAV;
else if (ext.toLower() == "flac") return Song::FileType_FLAC;

View File

@ -143,7 +143,9 @@ class Song {
QIcon IconForFiletype() const { return IconForFiletype(filetype()); }
bool IsFileLossless() const;
static FileType FiletypeByExtension(QString ext);
static FileType FiletypeByMimetype(const QString &mimetype);
static FileType FiletypeByDescription(const QString &text);
static FileType FiletypeByExtension(const QString &ext);
// Sort songs alphabetically using their pretty title
static void SortSongsListAlphabetically(QList<Song> *songs);

View File

@ -1182,21 +1182,31 @@ void GstEnginePipeline::StreamDiscovered(GstDiscoverer *discoverer, GstDiscovere
bundle.bitdepth = gst_discoverer_audio_info_get_depth(GST_DISCOVERER_AUDIO_INFO(stream_info));
bundle.bitrate = gst_discoverer_audio_info_get_bitrate(GST_DISCOVERER_AUDIO_INFO(stream_info));
GstCaps *stream_caps = gst_discoverer_stream_info_get_caps(stream_info);
gchar *decoder_description = gst_pb_utils_get_codec_description(stream_caps);
QString filetype_description = (decoder_description ? QString(decoder_description) : QString("Unknown"));
GstCaps *caps = gst_discoverer_stream_info_get_caps(stream_info);
gchar *codec_description = gst_pb_utils_get_codec_description(caps);
QString filetype_description = (codec_description ? QString(codec_description) : QString("Unknown"));
g_free(codec_description);
gst_caps_unref(stream_caps);
g_free(decoder_description);
gchar *caps_gchar = gst_caps_to_string(caps);
QString caps_str(caps_gchar);
g_free (caps_gchar);
gst_caps_unref(caps);
gst_discoverer_stream_info_list_free(audio_streams);
qLog(Info) << QString("Got stream info for %1: %2").arg(discovered_url).arg(filetype_description);
int i = caps_str.indexOf(',');
QString mimetype = (i > 1 ? caps_str.left(i) : caps_str);
bundle.filetype = Song::FiletypeByMimetype(mimetype);
if (bundle.filetype == Song::FileType_Unknown) {
bundle.filetype = Song::FiletypeByDescription(filetype_description);
}
qLog(Info) << "Got stream info for" << discovered_url + ":" << mimetype << filetype_description;
emit instance->MetadataFound(instance->id(), bundle);
}
else {
qLog(Error) << QString("Could not detect an audio stream in %1").arg(discovered_url);
qLog(Error) << "Could not detect an audio stream in" << discovered_url;
}
}
@ -1208,17 +1218,12 @@ void GstEnginePipeline::StreamDiscoveryFinished(GstDiscoverer *discoverer, gpoin
QString GstEnginePipeline::GSTdiscovererErrorMessage(GstDiscovererResult result) {
switch (result) {
case (GST_DISCOVERER_URI_INVALID):
return tr("Invalid URL");
case (GST_DISCOVERER_TIMEOUT):
return tr("Connection timed out");
case (GST_DISCOVERER_BUSY):
return tr("The discoverer is busy");
case (GST_DISCOVERER_MISSING_PLUGINS):
return tr("Missing plugins");
case (GST_DISCOVERER_ERROR):
default:
return tr("Could not get details");
case GST_DISCOVERER_URI_INVALID: return "The URI is invalid";
case GST_DISCOVERER_TIMEOUT: return "The discovery timed-out";
case GST_DISCOVERER_BUSY: return "The discoverer was already discovering a file";
case GST_DISCOVERER_MISSING_PLUGINS: return "Some plugins are missing for full discovery";
case GST_DISCOVERER_ERROR:
default: return "An error happened and the GError is set";
}
}