foobar2000 SDK  2015-08-03
album_art_helpers.h
Go to the documentation of this file.
1 class album_art_data_impl : public album_art_data {
3 public:
4  const void * get_ptr() const {return m_content.get_ptr();}
5  t_size get_size() const {return m_content.get_size();}
6 
7  void * get_ptr() {return m_content.get_ptr();}
8  void set_size(t_size p_size) {m_content.set_size(p_size);}
9 
11  void from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) {
12  set_size(p_bytes); p_stream->read_object(get_ptr(),p_bytes,p_abort);
13  }
14 
16  static album_art_data_ptr g_create(const void * p_buffer,t_size p_bytes) {
18  instance->set_size(p_bytes);
19  memcpy(instance->get_ptr(),p_buffer,p_bytes);
20  return instance;
21  }
23  static album_art_data_ptr g_create(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort) {
25  instance->from_stream(p_stream,p_bytes,p_abort);
26  return instance;
27  }
28 
29 private:
31 };
32 
33 
36 public:
37  void set(const GUID & p_what,album_art_data_ptr p_content) {m_content.set(p_what,p_content);}
38  bool have_item(const GUID & p_what) {return m_content.have_item(p_what);}
39  album_art_data_ptr query(const GUID & p_what,abort_callback & p_abort) {
40  album_art_data_ptr temp;
41  if (!m_content.query(p_what,temp)) throw exception_album_art_not_found();
42  return temp;
43  }
44  bool is_empty() const {return m_content.get_count() == 0;}
45  bool remove(const GUID & p_what) {
46  return m_content.remove(p_what);
47  }
48 private:
50 };
51 
54 public:
56  album_art_extractor_impl_stdtags(const char * exts) {
57  pfc::splitStringSimple_toList(m_extensions,';',exts);
58  }
59 
60  bool is_our_path(const char * p_path,const char * p_extension) {
61  return m_extensions.have_item(p_extension);
62  }
63 
64  album_art_extractor_instance_ptr open(file_ptr p_filehint,const char * p_path,abort_callback & p_abort) {
65  PFC_ASSERT( is_our_path(p_path, pfc::string_extension(p_path) ) );
66  file_ptr l_file ( p_filehint );
67  if (l_file.is_empty()) filesystem::g_open_read(l_file, p_path, p_abort);
68  return static_api_ptr_t<tag_processor_album_art_utils>()->open( l_file, p_abort );
69  }
70 private:
72 };
73 
76 public:
78  album_art_editor_impl_stdtags(const char * exts) {
79  pfc::splitStringSimple_toList(m_extensions,';',exts);
80  }
81 
82  bool is_our_path(const char * p_path,const char * p_extension) {
83  return m_extensions.have_item(p_extension);
84  }
85 
86  album_art_editor_instance_ptr open(file_ptr p_filehint,const char * p_path,abort_callback & p_abort) {
87  PFC_ASSERT( is_our_path(p_path, pfc::string_extension(p_path) ) );
88  file_ptr l_file ( p_filehint );
89  if (l_file.is_empty()) filesystem::g_open(l_file, p_path, filesystem::open_mode_write_existing, p_abort);
90  return static_api_ptr_t<tag_processor_album_art_utils>()->edit( l_file, p_abort );
91  }
92 private:
94 
95 };
96 
99 public:
100  album_art_extractor_instance_fileref(file::ptr f) : m_file(f) {}
101 
102  void set(const GUID & p_what,t_filesize p_offset, t_filesize p_size) {
103  const t_fileref ref = {p_offset, p_size};
104  m_data.set(p_what, ref);
105  m_cache.remove(p_what);
106  }
107 
108  bool have_item(const GUID & p_what) {
109  return m_data.have_item(p_what);
110  }
111 
112  album_art_data_ptr query(const GUID & p_what,abort_callback & p_abort) {
113  album_art_data_ptr item;
114  if (m_cache.query(p_what,item)) return item;
115  t_fileref ref;
116  if (!m_data.query(p_what, ref)) throw exception_album_art_not_found();
117  m_file->seek(ref.m_offset, p_abort);
118  item = album_art_data_impl::g_create(m_file.get_ptr(), pfc::downcast_guarded<t_size>(ref.m_size), p_abort);
119  m_cache.set(p_what, item);
120  return item;
121  }
122  bool is_empty() const {return m_data.get_count() == 0;}
123 private:
124  struct t_fileref {
125  t_filesize m_offset, m_size;
126  };
127  const file::ptr m_file;
130 };
131 
134 public:
135  template<typename t_in> album_art_path_list_impl(const t_in & in) {pfc::list_to_array(m_data, in);}
136  const char * get_path(t_size index) const {return m_data[index];}
137  t_size get_count() const {return m_data.get_size();}
138 private:
140 };
141 
144 public:
145  const char * get_path(t_size index) const {uBugCheck();}
146  t_size get_count() const {return 0;}
147 };
void list_to_array(t_array &p_array, const t_list &p_list)
Definition: primitives.h:796
service_ptr_t< file > file_ptr
Definition: filesystem.h:324
Definition: map.h:16
Helper implementation of album_art_editor - edits album art from arbitrary file formats that comply w...
static album_art_data_ptr g_create(stream_reader *p_stream, t_size p_bytes, abort_callback &p_abort)
Creates an album_art_data object from picture data contained in a stream.
t_size get_size() const
Retrieves size of the memory block containing the picture.
const t_item * get_ptr() const
Definition: array.h:213
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
Class encapsulating access to album art stored in a media file. Use album_art_extractor class obtain ...
Definition: album_art.h:46
album_art_path_list implementation helper
Entrypoint class for accessing album art extraction functionality. Register your own implementation t...
Definition: album_art.h:83
Definition: pfc.h:71
album_art_editor_instance_ptr open(file_ptr p_filehint, const char *p_path, abort_callback &p_abort)
Instantiates album_art_editor_instance providing access to album art stored in a specified media file...
static album_art_data_ptr g_create(const void *p_buffer, t_size p_bytes)
Creates an album_art_data object from picture data contained in a memory buffer.
T * get_ptr() const
Definition: service.h:117
album_art_extractor_instance_ptr open(file_ptr p_filehint, const char *p_path, abort_callback &p_abort)
Instantiates album_art_extractor_instance providing access to album art stored in a specified media f...
bool have_item(const GUID &p_what)
Helper - a more advanced implementation of album_art_extractor_instance.
album_art_data_ptr query(const GUID &p_what, abort_callback &p_abort)
Throws exception_album_art_not_found when the requested album art entry could not be found in the ref...
album_art_data_ptr query(const GUID &p_what, abort_callback &p_abort)
Throws exception_album_art_not_found when the requested album art entry could not be found in the ref...
Common class for handling picture data. Type of contained picture data is unknown and to be determin...
Definition: album_art.h:4
const char * get_path(t_size index) const
const char * get_path(t_size index) const
Helper - simple implementation of album_art_extractor_instance.
album_art_editor_impl_stdtags(const char *exts)
Entrypoint class for accessing album art editing functionality. Register your own implementation to a...
Definition: album_art.h:104
pfc::map_t< GUID, t_fileref > m_data
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
bool is_our_path(const char *p_path, const char *p_extension)
Returns whether the specified file is one of formats supported by our album_art_extractor implementat...
Album art path list - see album_art_extractor_instance_v2.
Definition: album_art.h:143
pfc::avltree_t< pfc::string, pfc::string::comparatorCaseInsensitiveASCII > m_extensions
void set_size(t_size p_size)
Helper implementation of album_art_extractor - reads album art from arbitrary file formats that compl...
t_size get_count() const
Definition: array.h:131
Implements album_art_data.
pfc::array_t< pfc::string8 > m_data
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
album_art_extractor_impl_stdtags(const char *exts)
void from_stream(stream_reader *p_stream, t_size p_bytes, abort_callback &p_abort)
Reads picture data from the specified stream object.
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
void splitStringSimple_toList(t_list &p_output, t_split p_split, const char *p_string, t_size p_stringLen=~0)
Definition: string_base.h:970
const void * get_ptr() const
Retrieves a pointer to a memory block containing the picture.
pfc::map_t< GUID, album_art_data::ptr > m_cache
pfc::map_t< GUID, album_art_data_ptr > m_content
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
album_art_path_list implementation helper
PFC_NORETURN void SHARED_EXPORT uBugCheck()
t_size get_size() const
Definition: array.h:130
album_art_path_list_impl(const t_in &in)
pfc::avltree_t< pfc::string, pfc::string::comparatorCaseInsensitiveASCII > m_extensions
bool is_our_path(const char *p_path, const char *p_extension)
Returns whether the specified file is one of formats supported by our album_art_editor implementation...
pfc::array_t< t_uint8 > m_content