File indexing completed on 2024-05-12 04:55:36
0001 /** 0002 * \file gstfingerprintdecoder.h 0003 * Chromaprint fingerprint decoder using GStreamer. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 15 Feb 2013 0008 * 0009 * Copyright (C) 2013-2018 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <gst/gst.h> 0030 #include "abstractfingerprintdecoder.h" 0031 #include "fingerprintcalculator.h" 0032 0033 /** 0034 * Chromaprint fingerprint decoder using GStreamer. 0035 */ 0036 class GstFingerprintDecoder : public AbstractFingerprintDecoder { 0037 public: 0038 /** 0039 * Constructor. 0040 * @param parent parent object 0041 */ 0042 explicit GstFingerprintDecoder(QObject* parent = 0); 0043 0044 /** 0045 * Destructor. 0046 */ 0047 virtual ~GstFingerprintDecoder(); 0048 0049 /** 0050 * Run decoder on audio file. 0051 * @param filePath path to audio file 0052 */ 0053 virtual void start(const QString& filePath); 0054 0055 /** 0056 * Stop decoder. 0057 * Can be used to stop the decoder when an error is found after 0058 * getting bufferReady() data. 0059 */ 0060 virtual void stop(); 0061 0062 private: 0063 static const int BUFFER_SIZE = 10; 0064 static const gint64 MAX_LENGTH_NS = 120000000000; 0065 static const guint TIMEOUT_MS = 5000; 0066 0067 void raiseError(FingerprintCalculator::Error error); 0068 static gboolean cb_timeout(gpointer data); 0069 static void cb_message(GstBus* bus, GstMessage* message, 0070 GstFingerprintDecoder* self); 0071 static void cb_pad_added(GstElement* dec, GstPad* pad, 0072 GstFingerprintDecoder* self); 0073 static void cb_no_more_pads(GstElement* dec, GstFingerprintDecoder* self); 0074 static void cb_notify_caps(GstPad *pad, GParamSpec* spec, 0075 GstFingerprintDecoder* self); 0076 static void cb_unknown_type(GstElement* dec, GstPad* pad, GstCaps* caps, 0077 GstFingerprintDecoder* self); 0078 static void cb_new_buffer(GstElement* sink, GstFingerprintDecoder* self); 0079 0080 GMainLoop* m_loop; 0081 GstElement* m_pipeline; 0082 GstElement* m_dec; 0083 GstElement* m_conv; 0084 FingerprintCalculator::Error m_error; 0085 int m_duration; 0086 gint m_channels; 0087 gint m_rate; 0088 bool m_gotPad; 0089 };