foobar2000 SDK  2015-08-03
packet_decoder.h
Go to the documentation of this file.
1 
3 class NOVTABLE packet_decoder : public service_base {
4 protected:
7  static bool g_is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) {return false;}
8 
12  void open(const GUID & p_owner,bool p_decode,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) {throw exception_io_data();}
13 public:
14 
15 
19  virtual t_size set_stream_property(const GUID & p_type,t_size p_param1,const void * p_param2,t_size p_param2size) = 0;
20 
21 
24  virtual void get_info(file_info & p_info) = 0;
25 
27  virtual unsigned get_max_frame_dependency()=0;
29  virtual double get_max_frame_dependency_time()=0;
30 
32  virtual void reset_after_seek()=0;
33 
36  virtual void decode(const void * p_buffer,t_size p_bytes,audio_chunk & p_chunk,abort_callback & p_abort)=0;
37 
39  virtual bool analyze_first_frame_supported() = 0;
41  virtual void analyze_first_frame(const void * p_buffer,t_size p_bytes,abort_callback & p_abort) = 0;
42 
44  static void g_open(service_ptr_t<packet_decoder> & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort);
45 
46  static const GUID owner_MP4,owner_matroska,owner_MP3,owner_MP2,owner_MP1,owner_MP4_ALAC,owner_ADTS,owner_ADIF, owner_Ogg, owner_MP4_AMR, owner_MP4_AMR_WB, owner_MP4_AC3;
47 
49  {
50  const char * codec_id;
51  uint32_t sample_rate,sample_rate_output;
52  uint32_t channels;
54  const void * codec_private;
55  };
56  //owner_MP4: param1 - codec ID (MP4 audio type), param2 - MP4 codec initialization data
57  //owner_MP3: raw MP3/MP2 file, parameters ignored
58  //owner_matroska: param2 = matroska_setup struct, param2size size must be equal to sizeof(matroska_setup)
59 
60 
61  //these are used to initialize PCM decoder
62  static const GUID property_samplerate,property_bitspersample,property_channels,property_byteorder,property_signed,property_channelmask, property_bufferpadding, property_eventlogger, property_checkingintegrity, property_samples_per_frame;
63  //property_samplerate : param1 == sample rate in hz
64  //property_bitspersample : param1 == bits per sample
65  //property_channels : param1 == channel count
66  //property_byteorder : if (param1) little_endian; else big_endian;
67  //property_signed : if (param1) signed; else unsigned;
68  //propery_bufferpadding : param1 == padding of each passed buffer in bytes; retval: decoder's preferred padding
69  //property_eventlogger : param2 = event logger ptr, NULL to disable, param2size 0 always
70  //property_checkingintegrity : param1 = checking integrity bool flag
71  //property_samples_per_frame : param1 = samples per frame
72 
73 
74 
75  //property_ogg_header : p_param1 = unused, p_param2 = ogg_packet structure, retval: 0 when more headers are wanted, 1 when done parsing headers
76  //property_ogg_query_sample_rate : returns sample rate, no parameters
77  //property_ogg_packet : p_param1 = unused, p_param2 = ogg_packet strucute
78  //property_ogg_qury_preskip : returns preskip samples (Opus)
79  static const GUID property_ogg_header, property_ogg_query_sample_rate, property_ogg_packet, property_ogg_query_preskip;
80 
81  //property_mp4_esds : p_param2 = MP4 ESDS chunk content as needed by some decoders
82  static const GUID property_mp4_esds;
83 
84  //property_allow_delayed_output : p_param1 = bool flag indicating whether the decoder than delay outputting audio data at will; essential for Apple AQ decoder
86 
87  size_t initPadding();
88  void setEventLogger(event_logger::ptr logger);
89  void setCheckingIntegrity(bool checkingIntegrity);
90  void setAllowDelayed( bool bAllow = true );
91 
92  FB2K_MAKE_SERVICE_INTERFACE(packet_decoder,service_base);
93 };
94 
96 {
97 public:
98  virtual void decode_ex(const void * p_buffer,t_size p_bytes,t_size & p_bytes_processed,audio_chunk & p_chunk,abort_callback & p_abort) = 0;
99  virtual void analyze_first_frame_ex(const void * p_buffer,t_size p_bytes,t_size & p_bytes_processed,abort_callback & p_abort) = 0;
100 
101  FB2K_MAKE_SERVICE_INTERFACE(packet_decoder_streamparse,packet_decoder);
102 };
103 
104 class NOVTABLE packet_decoder_entry : public service_base
105 {
106 public:
107  virtual bool is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) = 0;
108  virtual void open(service_ptr_t<packet_decoder> & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) = 0;
109 
110  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(packet_decoder_entry);
111 };
112 
113 
114 template<class T>
116 {
117 public:
118  bool is_our_setup(const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size) {
119  return T::g_is_our_setup(p_owner,p_param1,p_param2,p_param2size);
120  }
121  void open(service_ptr_t<packet_decoder> & p_out,bool p_decode,const GUID & p_owner,t_size p_param1,const void * p_param2,t_size p_param2size,abort_callback & p_abort) {
122  assert(is_our_setup(p_owner,p_param1,p_param2,p_param2size));
123  service_ptr_t<T> instance = new service_impl_t<T>();
124  instance->open(p_owner,p_decode,p_param1,p_param2,p_param2size,p_abort);
125  p_out = instance.get_ptr();
126  }
127 };
128 
129 template<typename T>
130 class packet_decoder_factory_t : public service_factory_single_t<packet_decoder_entry_impl_t<T> > {};
static const GUID property_ogg_query_sample_rate
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
static const GUID property_allow_delayed_output
static bool g_is_our_setup(const GUID &p_owner, t_size p_param1, const void *p_param2, t_size p_param2size)
Prototype of function that must be implemented by packet_decoder implementation but is not accessible...
Definition: packet_decoder.h:7
Definition: pfc.h:71
T * get_ptr() const
Definition: service.h:117
static const GUID property_mp4_esds
Interface to container of a chunk of audio data. See audio_chunk_impl for an implementation.
Definition: audio_chunk.h:5
void open(const GUID &p_owner, bool p_decode, t_size p_param1, const void *p_param2, t_size p_param2size, abort_callback &p_abort)
Prototype of function that must be implemented by packet_decoder implementation but is not accessible...
Main interface class for information about some playable object.
Definition: file_info.h:73
size_t t_size
Definition: int_types.h:48
Provides interface to decode various audio data types to PCM. Use packet_decoder_factory_t template t...
Definition: packet_decoder.h:3
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
void open(service_ptr_t< packet_decoder > &p_out, bool p_decode, const GUID &p_owner, t_size p_param1, const void *p_param2, t_size p_param2size, abort_callback &p_abort)
static const GUID owner_Ogg
static const GUID property_signed
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool is_our_setup(const GUID &p_owner, t_size p_param1, const void *p_param2, t_size p_param2size)