1 /* 2 * Strawberry Music Player 3 * This file was part of Clementine. 4 * Copyright 2012, David Sansome <me@davidsansome.com> 5 * Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net> 6 * 7 * Strawberry is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Strawberry is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Strawberry. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef CHROMAPRINTER_H 23 #define CHROMAPRINTER_H 24 25 #include "config.h" 26 27 #include <glib.h> 28 #include <gst/gst.h> 29 #include <gst/app/gstappsink.h> 30 31 #include <QBuffer> 32 #include <QString> 33 34 class Chromaprinter { 35 // Creates a Chromaprint fingerprint from a song. 36 // Uses GStreamer to open and decode the file as PCM data and passes this to Chromaprint's code generator. 37 // The generated code can be used to identify a song via Acoustid. 38 // You should create one Chromaprinter for each file you want to fingerprint. 39 // This class works well with QtConcurrentMap. 40 41 public: 42 explicit Chromaprinter(const QString &filename); 43 44 // Creates a fingerprint from the song. 45 // This method is blocking, so you want to call it in another thread. 46 // Returns an empty string if no fingerprint could be created. 47 QString CreateFingerprint(); 48 49 private: 50 static GstElement *CreateElement(const QString &factory_name, GstElement *bin = nullptr); 51 52 static void NewPadCallback(GstElement*, GstPad *pad, gpointer data); 53 static GstFlowReturn NewBufferCallback(GstAppSink *app_sink, gpointer self); 54 55 private: 56 QString filename_; 57 58 GstElement *convert_element_; 59 60 QBuffer buffer_; 61 62 }; 63 64 #endif // CHROMAPRINTER_H 65