foobar2000 SDK  2015-08-03
input_impl.h
Go to the documentation of this file.
5 };
6 
12 void input_open_file_helper(service_ptr_t<file> & p_file,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort);
13 
14 
17 {
18 public:
28  void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort);
29 
31  unsigned get_subsong_count();
33  t_uint32 get_subsong(unsigned p_index);
35  void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort);
37  t_filestats get_file_stats(abort_callback & p_abort);
38 
40  void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort);
42  bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort);
44  void decode_seek(double p_seconds,abort_callback & p_abort);
46  bool decode_can_seek();
48  bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta);
50  bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta);
52  void decode_on_idle(abort_callback & p_abort);
53 
55  void retag_set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort);
57  void retag_commit(abort_callback & p_abort);
58 
60  static bool g_is_our_content_type(const char * p_content_type);
62  static bool g_is_our_path(const char * p_path,const char * p_extension);
63 
64 
66  bool decode_run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort);
67 
69  void set_logger(event_logger::ptr ptr);
70 protected:
73 };
74 
77 {
78 public:
88  void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort);
89 
92  void get_info(file_info & p_info,abort_callback & p_abort);
95  t_filestats get_file_stats(abort_callback & p_abort);
96 
98  void decode_initialize(unsigned p_flags,abort_callback & p_abort);
100  bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort);
102  void decode_seek(double p_seconds,abort_callback & p_abort);
104  bool decode_can_seek();
106  bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta);
108  bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta);
110  void decode_on_idle(abort_callback & p_abort);
111 
113  void retag(const file_info & p_info,abort_callback & p_abort);
114 
116  static bool g_is_our_content_type(const char * p_content_type);
118  static bool g_is_our_path(const char * p_path,const char * p_extension);
119 
120 protected:
123 };
124 
125 
127 template<typename I, typename t_base>
128 class input_impl_interface_wrapper_t : public t_base
129 {
130 public:
131  void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) {
132  m_instance.open(p_filehint,p_path,p_reason,p_abort);
133  }
134 
135  // input_info_reader methods
136 
138  return m_instance.get_subsong_count();
139  }
140 
142  return m_instance.get_subsong(p_index);
143  }
144 
145 
146  void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) {
147  m_instance.get_info(p_subsong,p_info,p_abort);
148  }
149 
150  t_filestats get_file_stats(abort_callback & p_abort) {
151  return m_instance.get_file_stats(p_abort);
152  }
153 
154  // input_decoder methods
155 
156  void initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) {
157  m_instance.decode_initialize(p_subsong,p_flags,p_abort);
158  }
159 
160  bool run(audio_chunk & p_chunk,abort_callback & p_abort) {
161  return m_instance.decode_run(p_chunk,p_abort);
162  }
163 
164  bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) {
165  return m_instance.decode_run_raw(p_chunk, p_raw, p_abort);
166  }
167 
168  void seek(double p_seconds,abort_callback & p_abort) {
169  m_instance.decode_seek(p_seconds,p_abort);
170  }
171 
172  bool can_seek() {
173  return m_instance.decode_can_seek();
174  }
175 
176  bool get_dynamic_info(file_info & p_out, double & p_timestamp_delta) {
177  return m_instance.decode_get_dynamic_info(p_out,p_timestamp_delta);
178  }
179 
180  bool get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) {
181  return m_instance.decode_get_dynamic_info_track(p_out,p_timestamp_delta);
182  }
183 
184  void on_idle(abort_callback & p_abort) {
185  m_instance.decode_on_idle(p_abort);
186  }
187 
188  void set_logger(event_logger::ptr ptr) {
189  m_instance.set_logger(ptr);
190  }
191 
192  void set_pause(bool paused) {
193  m_instance.set_pause(paused);
194  }
195  bool flush_on_pause() {
196  return m_instance.flush_on_pause();
197  }
198 
199 
200  // input_info_writer methods
201 
202  void set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) {
203  m_instance.retag_set_info(p_subsong,p_info,p_abort);
204  }
205 
206  void commit(abort_callback & p_abort) {
207  m_instance.retag_commit(p_abort);
208  }
209  void remove_tags(abort_callback & p_abort) {
210  m_instance.remove_tags(p_abort);
211  }
212 
213 private:
215 };
216 
218 template<typename I>
220 {
221 public:
223 
224  void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) {
225  m_instance.open(p_filehint,p_path,p_reason,p_abort);
226  }
227 
228  void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort) {
229  if (p_subsong != 0) throw exception_io_data();
230  m_instance.get_info(p_info,p_abort);
231  }
232 
234  return 1;
235  }
236 
238  assert(p_index == 0);
239  return 0;
240  }
241 
242  t_filestats get_file_stats(abort_callback & p_abort) {
243  return m_instance.get_file_stats(p_abort);
244  }
245 
246  void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) {
247  if (p_subsong != 0) throw exception_io_data();
248  m_instance.decode_initialize(p_flags,p_abort);
249  }
250 
251  bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort) {return m_instance.decode_run(p_chunk,p_abort);}
252  void decode_seek(double p_seconds,abort_callback & p_abort) {m_instance.decode_seek(p_seconds,p_abort);}
253  bool decode_can_seek() {return m_instance.decode_can_seek();}
254  bool decode_get_dynamic_info(file_info & p_out, double & p_timestamp_delta) {return m_instance.decode_get_dynamic_info(p_out,p_timestamp_delta);}
255  bool decode_get_dynamic_info_track(file_info & p_out, double & p_timestamp_delta) {return m_instance.decode_get_dynamic_info_track(p_out,p_timestamp_delta);}
256  void decode_on_idle(abort_callback & p_abort) {m_instance.decode_on_idle(p_abort);}
257 
258  void retag_set_info(t_uint32 p_subsong,const file_info & p_info,abort_callback & p_abort) {
259  if (p_subsong != 0) throw exception_io_data();
260  m_instance.retag(p_info,p_abort);
261  }
262 
263  bool decode_run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) {
264  return m_instance.decode_run_raw(p_chunk, p_raw, p_abort);
265  }
266 
267  void set_logger(event_logger::ptr ptr) {m_instance.set_logger(ptr);}
268 
269  void set_pause(bool paused) {
270  m_instance.set_pause(paused);
271  }
272  bool flush_on_pause() {
273  return m_instance.flush_on_pause();
274  }
275 
276  void retag_commit(abort_callback & p_abort) {}
277 
278  void remove_tags(abort_callback & p_abort) {
279  m_instance.remove_tags(p_abort);
280  }
281 
282  static bool g_is_our_content_type(const char * p_content_type) {return I::g_is_our_content_type(p_content_type);}
283  static bool g_is_our_path(const char * p_path,const char * p_extension) {return I::g_is_our_path(p_path,p_extension);}
284 
285 
286 private:
288 };
289 
291 template<typename I,unsigned t_flags, typename t_decoder = input_decoder, typename t_inforeader = input_info_reader, typename t_infowriter = input_info_writer>
293 {
294 private:
295 
296  template<typename T, typename out>
297  void instantiate_t(service_ptr_t<out> & p_instance,service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort)
298  {
301  temp->open(p_filehint,p_path,p_reason,p_abort);
302  p_instance = temp.get_ptr();
303  }
304 public:
305  bool is_our_content_type(const char * p_type) {return I::g_is_our_content_type(p_type);}
306  bool is_our_path(const char * p_full_path,const char * p_extension) {return I::g_is_our_path(p_full_path,p_extension);}
307 
308  void open_for_decoding(service_ptr_t<input_decoder> & p_instance,service_ptr_t<file> p_filehint,const char * p_path,abort_callback & p_abort) {
309  instantiate_t<t_decoder>(p_instance,p_filehint,p_path,input_open_decode,p_abort);
310  }
311 
312  void open_for_info_read(service_ptr_t<input_info_reader> & p_instance,service_ptr_t<file> p_filehint,const char * p_path,abort_callback & p_abort) {
313  instantiate_t<t_inforeader>(p_instance,p_filehint,p_path,input_open_info_read,p_abort);
314  }
315 
316  void open_for_info_write(service_ptr_t<input_info_writer> & p_instance,service_ptr_t<file> p_filehint,const char * p_path,abort_callback & p_abort) {
317  instantiate_t<t_infowriter>(p_instance,p_filehint,p_path,input_open_info_write,p_abort);
318  }
319 
320  void get_extended_data(service_ptr_t<file> p_filehint,const playable_location & p_location,const GUID & p_guid,mem_block_container & p_out,abort_callback & p_abort) {
321  p_out.reset();
322  }
323 
324  unsigned get_flags() {return t_flags;}
325 };
326 
327 
329 template<typename T>
330 class input_factory_t : public service_factory_single_t<input_entry_impl_t<T,0> > {};
331 
333 template<typename T>
334 class input_singletrack_factory_t : public service_factory_single_t<input_entry_impl_t<input_wrapper_singletrack_t<T>,0> > {};
335 
337 template<typename T,unsigned t_flags = 0, typename t_decoder = input_decoder, typename t_inforeader = input_info_reader, typename t_infowriter = input_info_writer>
338 class input_factory_ex_t : public service_factory_single_t<input_entry_impl_t<T,t_flags, t_decoder, t_inforeader, t_infowriter> > {};
339 
341 template<typename T,unsigned t_flags = 0, typename t_decoder = input_decoder, typename t_inforeader = input_info_reader, typename t_infowriter = input_info_writer>
342 class input_singletrack_factory_ex_t : public service_factory_single_t<input_entry_impl_t<input_wrapper_singletrack_t<T>,t_flags, t_decoder, t_inforeader, t_infowriter> > {};
void instantiate_t(service_ptr_t< out > &p_instance, service_ptr_t< file > p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
Definition: input_impl.h:297
bool decode_can_seek()
See: input_decoder::can_seek(). Valid after decode_initialize().
void initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort)
Definition: input_impl.h:156
static bool g_is_our_content_type(const char *p_content_type)
Definition: input_impl.h:282
bool decode_run_raw(audio_chunk &p_chunk, mem_block_container &p_raw, abort_callback &p_abort)
See: input_decoder_v2::run_raw(). Relevant only when implementing input_decoder_v2. Valid after decode_initialize().
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
Extended version of input_factory_t, with non-default flags and supported interfaces. See: input_factory_t, input_entry::get_flags().
Definition: input_impl.h:338
unsigned get_subsong_count()
See: input_info_reader::get_subsong_count(). Valid after open() with any reason.
void on_idle(abort_callback &p_abort)
Definition: input_impl.h:184
void retag_set_info(t_uint32 p_subsong, const file_info &p_info, abort_callback &p_abort)
See: input_info_writer::set_info(). Valid after open() with input_open_info_write reason...
Definition: pfc.h:71
bool decode_get_dynamic_info_track(file_info &p_out, double &p_timestamp_delta)
Definition: input_impl.h:255
T * get_ptr() const
Definition: service.h:117
void retag_commit(abort_callback &p_abort)
See: input_info_writer::commit(). Valid after open() with input_open_info_write reason.
void decode_seek(double p_seconds, abort_callback &p_abort)
Definition: input_impl.h:252
bool decode_get_dynamic_info_track(file_info &p_out, double &p_timestamp_delta)
See: input_decoder::get_dynamic_info_track(). Valid after decode_initialize().
bool is_our_content_type(const char *p_type)
Determines whether specified content type can be handled by this input.
Definition: input_impl.h:305
void set_pause(bool paused)
Definition: input_impl.h:192
void decode_on_idle(abort_callback &p_abort)
See: input_decoder::on_idle(). Valid after decode_initialize().
Used internally by standard input_entry implementation; do not use directly. Translates input_decoder...
Definition: input_impl.h:128
void decode_seek(double p_seconds, abort_callback &p_abort)
See: input_decoder::seek(). Valid after decode_initialize().
void open_for_info_read(service_ptr_t< input_info_reader > &p_instance, service_ptr_t< file > p_filehint, const char *p_path, abort_callback &p_abort)
Opens specified file for reading info.
Definition: input_impl.h:312
Non-multitrack-enabled input factory (helper) - hides multitrack management functions from input impl...
Definition: input_impl.h:334
void get_info(t_uint32 p_subsong, file_info &p_info, abort_callback &p_abort)
Definition: input_impl.h:228
t_filestats get_file_stats(abort_callback &p_abort)
See: input_info_reader::get_file_stats(). Valid after open() with any reason.
bool decode_run(audio_chunk &p_chunk, abort_callback &p_abort)
See: input_decoder::run(). Valid after decode_initialize().
Interface to container of a chunk of audio data. See audio_chunk_impl for an implementation.
Definition: audio_chunk.h:5
t_filestats get_file_stats(abort_callback &p_abort)
Definition: input_impl.h:242
void open_for_info_write(service_ptr_t< input_info_writer > &p_instance, service_ptr_t< file > p_filehint, const char *p_path, abort_callback &p_abort)
Opens specified file for writing info.
Definition: input_impl.h:316
bool decode_run(audio_chunk &p_chunk, abort_callback &p_abort)
Definition: input_impl.h:251
t_input_open_reason
Definition: input_impl.h:1
bool get_dynamic_info(file_info &p_out, double &p_timestamp_delta)
Definition: input_impl.h:176
void set_logger(event_logger::ptr ptr)
See: input_decoder::set_logger(). Relevant only when implementing input_decoder_v2. Valid after any open().
void open(service_ptr_t< file > p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
Opens specified file for info read / decoding / info write. This is called only once, immediately after object creation, before any other methods, and no other methods are called if open() fails.
t_uint32 get_subsong(t_uint32 p_index)
Definition: input_impl.h:237
void set_logger(event_logger::ptr ptr)
Definition: input_impl.h:188
void decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort)
See: input_decoder::initialize(). Valid after open() with input_open_decode reason.
void seek(double p_seconds, abort_callback &p_abort)
Definition: input_impl.h:168
bool decode_get_dynamic_info(file_info &p_out, double &p_timestamp_delta)
See: input_decoder::get_dynamic_info(). Valid after decode_initialize().
bool run_raw(audio_chunk &p_chunk, mem_block_container &p_raw, abort_callback &p_abort)
Definition: input_impl.h:164
static bool g_is_our_path(const char *p_path, const char *p_extension)
See: input_entry::is_our_path().
Main interface class for information about some playable object.
Definition: file_info.h:73
bool is_our_path(const char *p_full_path, const char *p_extension)
Determines whether specified file type can be handled by this input. This must not use any kind of fi...
Definition: input_impl.h:306
void commit(abort_callback &p_abort)
Definition: input_impl.h:206
bool decode_get_dynamic_info(file_info &p_out, double &p_timestamp_delta)
Definition: input_impl.h:254
void decode_on_idle(abort_callback &p_abort)
Definition: input_impl.h:256
void input_open_file_helper(service_ptr_t< file > &p_file, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
Helper function for input implementation use; ensures that file is open with relevant access mode...
Definition: input.cpp:231
void decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort)
Definition: input_impl.h:246
void retag_set_info(t_uint32 p_subsong, const file_info &p_info, abort_callback &p_abort)
Definition: input_impl.h:258
bool decode_run_raw(audio_chunk &p_chunk, mem_block_container &p_raw, abort_callback &p_abort)
Definition: input_impl.h:263
void open(service_ptr_t< file > p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
Definition: input_impl.h:224
void remove_tags(abort_callback &p_abort)
Definition: input_impl.h:209
t_uint32 get_subsong(unsigned p_index)
See: input_info_reader::get_subsong(). Valid after open() with any reason.
bool get_dynamic_info_track(file_info &p_out, double &p_timestamp_delta)
Definition: input_impl.h:180
void remove_tags(abort_callback &p_abort)
Definition: input_impl.h:278
static bool g_is_our_path(const char *p_path, const char *p_extension)
Definition: input_impl.h:283
void open_for_decoding(service_ptr_t< input_decoder > &p_instance, service_ptr_t< file > p_filehint, const char *p_path, abort_callback &p_abort)
Opens specified resource for decoding.
Definition: input_impl.h:308
bool run(audio_chunk &p_chunk, abort_callback &p_abort)
Definition: input_impl.h:160
This is a class that just declares prototypes of functions that each input needs to implement...
Definition: input_impl.h:16
t_filestats get_file_stats(abort_callback &p_abort)
Definition: input_impl.h:150
void get_info(t_uint32 p_subsong, file_info &p_info, abort_callback &p_abort)
Definition: input_impl.h:146
Extended version of input_singletrack_factory_t, with non-default flags and supported interfaces...
Definition: input_impl.h:342
void set_logger(event_logger::ptr ptr)
Definition: input_impl.h:267
Definition: input.h:147
t_uint32 get_subsong(t_uint32 p_index)
Definition: input_impl.h:141
Stardard input factory. For reference of functions that must be supported by registered class...
Definition: input_impl.h:330
Generic interface for a memory block; used by various other interfaces to return memory blocks while ...
void get_extended_data(service_ptr_t< file > p_filehint, const playable_location &p_location, const GUID &p_guid, mem_block_container &p_out, abort_callback &p_abort)
Reserved for future use. Do nothing and return until specifications are finalized.
Definition: input_impl.h:320
static bool g_is_our_content_type(const char *p_content_type)
See: input_entry::is_our_content_type().
void set_info(t_uint32 p_subsong, const file_info &p_info, abort_callback &p_abort)
Definition: input_impl.h:202
void open(service_ptr_t< file > p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
Definition: input_impl.h:131
void set_pause(bool paused)
Definition: input_impl.h:269
This is a class that just declares prototypes of functions that each non-multitrack-enabled input nee...
Definition: input_impl.h:76
Helper; standard input_entry implementation. Do not instantiate this directly, use input_factory_t or...
Definition: input_impl.h:292
unsigned get_flags()
See flag_* enums.
Definition: input_impl.h:324
void get_info(t_uint32 p_subsong, file_info &p_info, abort_callback &p_abort)
See: input_info_reader::get_info(). Valid after open() with any reason.
uint32_t t_uint32
Definition: int_types.h:5
Helper used by input_singletrack_factory_t, do not use directly. Translates input_impl calls to input...
Definition: input_impl.h:219
void retag_commit(abort_callback &p_abort)
Definition: input_impl.h:276