-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontainer_matroska.h
99 lines (85 loc) · 3.83 KB
/
container_matroska.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
#ifndef _CONTAINER_MATROSKA_H_
#define _CONTAINER_MATROSKA_H_
namespace foobar2000_io {
namespace matroska {
class attachment;
typedef pfc::list_base_const_t<attachment> attachment_list;
}
class NOVTABLE container_matroska : public service_base {
public:
virtual void open(const char * p_path, bool p_info_only, abort_callback & p_abort)=0;
virtual void open_file(service_ptr_t<file> & p_out, const filesystem::t_open_mode p_mode = filesystem::open_mode_read) const =0;
virtual void get_display_path(pfc::string_base & p_out) const =0;
virtual bool is_our_path(const char * p_path) const =0;
virtual const matroska::attachment_list * get_attachment_list() const =0;
public:
static void g_open(service_ptr_t<container_matroska> & p_out, const char * p_path, bool p_info_only, abort_callback & p_abort) {
service_enum_t<container_matroska> e;
service_ptr_t<container_matroska> ptr;
while(e.next(ptr)) {
if (ptr->is_our_path(p_path)) {
ptr->open(p_path, p_info_only, p_abort);
p_out = ptr;
return;
}
}
throw exception_io_unsupported_format();
}
static bool g_is_our_path(const char * p_path) {
service_enum_t<container_matroska> e;
service_ptr_t<container_matroska> ptr;
while(e.next(ptr)) {
if (ptr->is_our_path(p_path)) {
return true;
}
}
return false;
}
FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(container_matroska);
};
typedef service_ptr_t<container_matroska> container_matroska_ptr;
namespace matroska {
class attachment {
private:
container_matroska * m_owner;
abort_callback * m_abort;
pfc::string8 m_name, m_mime_type, m_description;
t_size m_size;
t_sfilesize m_position;
public:
attachment() : m_owner(0), m_abort(0) {};
attachment(const container_matroska_ptr & p_owner, abort_callback & p_abort, const char * p_name, const char * p_mime_type,
const char * p_description, const t_size p_size, const t_sfilesize p_position)
: m_name(p_name), m_mime_type(p_mime_type), m_description(p_description), m_size(p_size), m_position(p_position)
{
m_owner = p_owner.get_ptr();
m_abort = &p_abort;
};
~attachment() {};
void get_name(pfc::string_base & p_out) const { p_out = m_name; };
void get_mime_type(pfc::string_base & p_out) const { p_out = m_mime_type; };
void get_description(pfc::string_base & p_out) const { p_out = m_description; };
t_size get_size() const { return m_size; };
t_sfilesize get_position() const { return m_position; };
void get(void * p_buffer, t_sfilesize p_position, t_size p_size) const {
service_ptr_t<file> file_ptr;
m_owner->open_file(file_ptr);
file_ptr->seek_ex(p_position, file::seek_from_beginning, *m_abort);
file_ptr->read(p_buffer, p_size, *m_abort);
};
void get(void * p_buffer, t_size p_size = 0) const {
if (!p_size) {
p_size = get_size();
}
get(p_buffer, get_position(), p_size);
};
};
};
};
using namespace foobar2000_io;
template<typename T>
class container_matroska_factory_t : public service_factory_t<T> {};
// {32491C6C-F941-42cf-8519-EBF5061BB088}
FOOGUIDDECL const GUID container_matroska::class_guid =
{ 0x32491c6c, 0xf941, 0x42cf, { 0x85, 0x19, 0xeb, 0xf5, 0x6, 0x1b, 0xb0, 0x88 } };
#endif // _CONTAINER_MATROSKA_H_