-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmp3_processor.h
111 lines (96 loc) · 3.2 KB
/
mp3_processor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* mp3chop
*
* (C) 2000-2020 Mike Crowe <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef MP3_PROCESSOR_H
#define MP3_PROCESSOR_H 1
#include <string>
#include <memory>
#include "mp3_timecode.h"
#include "header.h"
#include "buffer.h"
#include "chop.h"
#include "filter.h"
class MalformedID3V2Exception
{
};
class UnsupportedID3V2Version
{
};
class MP3Processor
{
public:
class Exception
{
protected:
virtual ~Exception() {}
public:
virtual void Report() = 0;
};
class InvalidTimeCodeException : public Exception
{
const std::string offender;
public:
virtual ~InvalidTimeCodeException() {}
InvalidTimeCodeException(const std::string &tc) : offender(tc) {}
virtual void Report();
};
class BadFileException : public Exception
{
const std::string m_file;
const std::string m_error;
public:
BadFileException(const std::string &f, const std::string &e)
: m_file(f), m_error(e) {}
virtual ~BadFileException() {}
virtual void Report();
};
private:
std::unique_ptr<Chop> begin_chop;
std::unique_ptr<Chop> end_chop;
std::unique_ptr<SCMSFilter> scms_filter;
int m_files;
char m_mode;
bool m_keep_id3v1;
bool m_keep_id3v2;
static void ParseTimeCode(TimeCode *tc, const std::string &t);
static int ConvertTimeCodeToFrameNumber(MPEGHeader *h, const TimeCode &tc);
static bool IsID3V1Header(const uint8_t *p);
/** Only requires three bytes */
static bool IsID3V2Header(const uint8_t *p);
bool ProcessFile(DataSource *data_source, DataSink *data_sink, Chop *chop, Filter *filter);
void ProcessFrames(InputStreamBuffer *input, OutputStreamBuffer *output, Chop *chop, Filter *filter);
void HandleID3V1Tag(InputStreamBuffer *input, OutputStreamBuffer *output);
bool HandleID3V2Tag(InputStreamBuffer *input, OutputStreamBuffer *output);
bool GetFirstHeader(InputStreamBuffer *input, MPEGHeader *header);
bool DumpFirstHeader(DataSource *data_source);
void CreateSCMSFilter();
public:
MP3Processor() : m_files(0), m_mode('c'), m_keep_id3v1(false) {};
void HandleFile(const std::string &);
void HandleBeginTimeCode(const std::string &);
void HandleEndTimeCode(const std::string &);
void SetKeepID3V1(bool b = true) { m_keep_id3v1 = b; }
void SetKeepID3V2(bool b = true) { m_keep_id3v2 = b; }
void HandleEnd();
void HandleMode(char);
void HandleForceCopyright(bool b);
void HandleForceOriginal(bool b);
};
#endif