annotate data/fileio/MP3FileReader.h @ 748:c8ab5f63360d

Fixes to copyright notes
author Chris Cannam
date Mon, 03 Sep 2012 11:08:45 +0100
parents a4b8ad0f1a8f
children f3cda3280398 59e7fe1b1003
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@392 28 class ProgressReporter;
Chris@148 29
Chris@148 30 class MP3FileReader : public CodedAudioFileReader
Chris@148 31 {
Chris@392 32 Q_OBJECT
Chris@392 33
Chris@148 34 public:
Chris@263 35 enum DecodeMode {
Chris@392 36 DecodeAtOnce, // decode the file on construction, with progress
Chris@263 37 DecodeThreaded // decode in a background thread after construction
Chris@263 38 };
Chris@263 39
Chris@317 40 MP3FileReader(FileSource source,
Chris@297 41 DecodeMode decodeMode,
Chris@297 42 CacheMode cacheMode,
Chris@392 43 size_t targetRate = 0,
Chris@392 44 ProgressReporter *reporter = 0);
Chris@148 45 virtual ~MP3FileReader();
Chris@148 46
Chris@290 47 virtual QString getError() const { return m_error; }
Chris@290 48
Chris@345 49 virtual QString getLocation() const { return m_source.getLocation(); }
Chris@290 50 virtual QString getTitle() const { return m_title; }
Chris@334 51 virtual QString getMaker() const { return m_maker; }
Chris@632 52 virtual TagMap getTags() const { return m_tags; }
Chris@271 53
Chris@290 54 static void getSupportedExtensions(std::set<QString> &extensions);
Chris@316 55 static bool supportsExtension(QString ext);
Chris@316 56 static bool supportsContentType(QString type);
Chris@317 57 static bool supports(FileSource &source);
Chris@316 58
Chris@265 59 virtual int getDecodeCompletion() const { return m_completion; }
Chris@265 60
Chris@263 61 virtual bool isUpdating() const {
Chris@263 62 return m_decodeThread && m_decodeThread->isRunning();
Chris@263 63 }
Chris@263 64
Chris@392 65 public slots:
Chris@392 66 void cancelled();
Chris@392 67
Chris@148 68 protected:
Chris@317 69 FileSource m_source;
Chris@290 70 QString m_path;
Chris@290 71 QString m_error;
Chris@290 72 QString m_title;
Chris@333 73 QString m_maker;
Chris@632 74 TagMap m_tags;
Chris@148 75 size_t m_fileSize;
Chris@148 76 double m_bitrateNum;
Chris@148 77 size_t m_bitrateDenom;
Chris@265 78 int m_completion;
Chris@263 79 bool m_done;
Chris@263 80
Chris@263 81 unsigned char *m_filebuffer;
Chris@297 82 float **m_samplebuffer;
Chris@297 83 size_t m_samplebuffersize;
Chris@148 84
Chris@392 85 ProgressReporter *m_reporter;
Chris@148 86 bool m_cancelled;
Chris@148 87
Chris@148 88 struct DecoderData
Chris@148 89 {
Chris@148 90 unsigned char const *start;
Chris@148 91 unsigned long length;
Chris@148 92 MP3FileReader *reader;
Chris@148 93 };
Chris@148 94
Chris@148 95 bool decode(void *mm, size_t sz);
Chris@148 96 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
Chris@148 97
Chris@148 98 static enum mad_flow input(void *, struct mad_stream *);
Chris@148 99 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
Chris@148 100 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
Chris@263 101
Chris@263 102 class DecodeThread : public Thread
Chris@263 103 {
Chris@263 104 public:
Chris@263 105 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
Chris@263 106 virtual void run();
Chris@263 107
Chris@263 108 protected:
Chris@263 109 MP3FileReader *m_reader;
Chris@263 110 };
Chris@263 111
Chris@263 112 DecodeThread *m_decodeThread;
Chris@271 113
Chris@271 114 void loadTags();
Chris@333 115 QString loadTag(void *vtag, const char *name);
Chris@148 116 };
Chris@148 117
Chris@148 118 #endif
Chris@148 119
Chris@148 120 #endif