annotate data/fileio/MP3FileReader.h @ 342:4175a4930186

* Fixes for handling of DOS paths (C:\blah) -- not an unknown URL scheme!
author Chris Cannam
date Mon, 26 Nov 2007 15:05:51 +0000
parents aa8dbac62024
children 700cd3350391
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@148 16 #ifndef _MP3_FILE_READER_H_
Chris@148 17 #define _MP3_FILE_READER_H_
Chris@148 18
Chris@148 19 #ifdef HAVE_MAD
Chris@148 20
Chris@148 21 #include "CodedAudioFileReader.h"
Chris@148 22
Chris@263 23 #include "base/Thread.h"
Chris@148 24 #include <mad.h>
Chris@148 25
Chris@157 26 #include <set>
Chris@157 27
Chris@148 28 class QProgressDialog;
Chris@148 29
Chris@148 30 class MP3FileReader : public CodedAudioFileReader
Chris@148 31 {
Chris@148 32 public:
Chris@263 33 enum DecodeMode {
Chris@263 34 DecodeAtOnce, // decode the file on construction, with progress dialog
Chris@263 35 DecodeThreaded // decode in a background thread after construction
Chris@263 36 };
Chris@263 37
Chris@317 38 MP3FileReader(FileSource source,
Chris@297 39 DecodeMode decodeMode,
Chris@297 40 CacheMode cacheMode,
Chris@297 41 size_t targetRate = 0);
Chris@148 42 virtual ~MP3FileReader();
Chris@148 43
Chris@290 44 virtual QString getError() const { return m_error; }
Chris@290 45
Chris@290 46 virtual QString getTitle() const { return m_title; }
Chris@334 47 virtual QString getMaker() const { return m_maker; }
Chris@271 48
Chris@290 49 static void getSupportedExtensions(std::set<QString> &extensions);
Chris@316 50 static bool supportsExtension(QString ext);
Chris@316 51 static bool supportsContentType(QString type);
Chris@317 52 static bool supports(FileSource &source);
Chris@316 53
Chris@265 54 virtual int getDecodeCompletion() const { return m_completion; }
Chris@265 55
Chris@263 56 virtual bool isUpdating() const {
Chris@263 57 return m_decodeThread && m_decodeThread->isRunning();
Chris@263 58 }
Chris@263 59
Chris@148 60 protected:
Chris@317 61 FileSource m_source;
Chris@290 62 QString m_path;
Chris@290 63 QString m_error;
Chris@290 64 QString m_title;
Chris@333 65 QString m_maker;
Chris@148 66 size_t m_fileSize;
Chris@148 67 double m_bitrateNum;
Chris@148 68 size_t m_bitrateDenom;
Chris@265 69 int m_completion;
Chris@263 70 bool m_done;
Chris@263 71
Chris@263 72 unsigned char *m_filebuffer;
Chris@297 73 float **m_samplebuffer;
Chris@297 74 size_t m_samplebuffersize;
Chris@148 75
Chris@148 76 QProgressDialog *m_progress;
Chris@148 77 bool m_cancelled;
Chris@148 78
Chris@148 79 struct DecoderData
Chris@148 80 {
Chris@148 81 unsigned char const *start;
Chris@148 82 unsigned long length;
Chris@148 83 MP3FileReader *reader;
Chris@148 84 };
Chris@148 85
Chris@148 86 bool decode(void *mm, size_t sz);
Chris@148 87 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
Chris@148 88
Chris@148 89 static enum mad_flow input(void *, struct mad_stream *);
Chris@148 90 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
Chris@148 91 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
Chris@263 92
Chris@263 93 class DecodeThread : public Thread
Chris@263 94 {
Chris@263 95 public:
Chris@263 96 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
Chris@263 97 virtual void run();
Chris@263 98
Chris@263 99 protected:
Chris@263 100 MP3FileReader *m_reader;
Chris@263 101 };
Chris@263 102
Chris@263 103 DecodeThread *m_decodeThread;
Chris@271 104
Chris@271 105 void loadTags();
Chris@333 106 QString loadTag(void *vtag, const char *name);
Chris@148 107 };
Chris@148 108
Chris@148 109 #endif
Chris@148 110
Chris@148 111 #endif