-
Notifications
You must be signed in to change notification settings - Fork 42
/
CompositeSource.h
68 lines (63 loc) · 2.05 KB
/
CompositeSource.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
#ifndef _COMPOSITE_H
#define _COMPOSITE_H
#include "ISource.h"
class CompositeSource: public ISeekableSource, public ITagParser,
public IChapterParser
{
typedef std::shared_ptr<ISeekableSource> source_t;
uint32_t m_cur_file;
int64_t m_position;
uint64_t m_length;
std::vector<source_t> m_sources;
std::map<std::string, std::string> m_tags;
std::vector<misc::chapter_t> m_chapters;
AudioStreamBasicDescription m_asbd;
public:
CompositeSource() : m_cur_file(0), m_position(0), m_length(0) {}
const std::vector<uint32_t> *getChannels() const
{
return first()->getChannels();
}
const AudioStreamBasicDescription &getSampleFormat() const
{
return m_asbd;
}
uint64_t length() const { return m_length; }
int64_t getPosition() { return m_position; }
size_t readSamples(void *buffer, size_t nsamples);
bool isSeekable()
{
for (size_t i = 0; i < m_sources.size(); ++i)
if (!m_sources[i]->isSeekable())
return false;
return true;
}
void seekTo(int64_t pos);
const std::map<std::string, std::string> &getTags() const
{
if (m_tags.size()) return m_tags;
std::shared_ptr<ISource> src = first();
ITagParser *tp = dynamic_cast<ITagParser*>(src.get());
return tp ? tp->getTags() : m_tags;
}
const std::vector<misc::chapter_t> &getChapters() const
{
return m_chapters;
}
void setTags(const std::map<std::string, std::string> &tags)
{
m_tags = tags;
}
void addSource(const std::shared_ptr<ISeekableSource> &src);
void addSourceWithChapter(const std::shared_ptr<ISeekableSource> &src,
const std::wstring &title);
size_t count() const { return m_sources.size(); }
private:
std::shared_ptr<ISeekableSource> first() const { return m_sources[0]; }
void addChapter(std::wstring title, double length)
{
m_chapters.push_back(std::make_pair(title, length));
}
void fetchAlbumTags(ITagParser *parser);
};
#endif