Opus support: Fix all sorts of mistakes

This commit is contained in:
Ilari Liusvaara 2013-02-19 23:43:10 +02:00
parent 0c711d4c6c
commit a88ae3a8a3
2 changed files with 138 additions and 59 deletions

View file

@ -22,7 +22,7 @@ template<typename T> struct generic_eget
{ {
typedef T erettype; typedef T erettype;
T operator()(encoder& e) const; T operator()(encoder& e) const;
T errordefault(); T errordefault() const;
}; };
template<typename T> struct generic_get template<typename T> struct generic_get
@ -31,14 +31,14 @@ template<typename T> struct generic_get
typedef T erettype; typedef T erettype;
T operator()(decoder& e) const; T operator()(decoder& e) const;
T operator()(encoder& e) const; T operator()(encoder& e) const;
T errordefault(); T errordefault() const;
}; };
template<typename T> struct generic_dget template<typename T> struct generic_dget
{ {
typedef T drettype; typedef T drettype;
T operator()(decoder& e) const; T operator()(decoder& e) const;
static T errordefault; T errordefault() const;
}; };
struct samplerate struct samplerate
@ -52,19 +52,19 @@ struct samplerate
operator int32_t() { return fs; } operator int32_t() { return fs; }
typedef samplerate erettype; typedef samplerate erettype;
samplerate operator()(encoder& e) const; samplerate operator()(encoder& e) const;
samplerate errordefault() { return samplerate(0); } samplerate errordefault() const { return samplerate(0); }
private: private:
int32_t fs; int32_t fs;
}; };
struct compexity struct complexity
{ {
compexity(int32_t _c) { c = _c; } complexity(int32_t _c) { c = _c; }
operator int32_t() { return c; } operator int32_t() { return c; }
typedef generic_eget<compexity> get; static generic_eget<complexity> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t c; int32_t c;
}; };
@ -75,10 +75,10 @@ struct bitrate
static bitrate _auto; static bitrate _auto;
static bitrate max; static bitrate max;
operator int32_t() { return b; } operator int32_t() { return b; }
typedef generic_eget<bitrate> get; static generic_eget<bitrate> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t b; int32_t b;
}; };
@ -89,10 +89,10 @@ struct vbr
static vbr cbr; static vbr cbr;
static vbr _vbr; static vbr _vbr;
operator bool() { return v; } operator bool() { return v; }
typedef generic_eget<vbr> get; static generic_eget<vbr> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
bool v; bool v;
}; };
@ -103,10 +103,10 @@ struct vbr_constraint
static vbr_constraint unconstrained; static vbr_constraint unconstrained;
static vbr_constraint constrained; static vbr_constraint constrained;
operator bool() { return c; } operator bool() { return c; }
typedef generic_eget<vbr_constraint> get; static generic_eget<vbr_constraint> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
bool c; bool c;
}; };
@ -118,10 +118,10 @@ struct force_channels
static force_channels mono; static force_channels mono;
static force_channels stereo; static force_channels stereo;
operator int32_t() { return f; } operator int32_t() { return f; }
typedef generic_eget<force_channels> get; static generic_eget<force_channels> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t f; int32_t f;
}; };
@ -135,10 +135,10 @@ struct max_bandwidth
static max_bandwidth superwide; static max_bandwidth superwide;
static max_bandwidth full; static max_bandwidth full;
operator int32_t() { return bw; } operator int32_t() { return bw; }
typedef generic_eget<max_bandwidth> get; static generic_eget<max_bandwidth> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t bw; int32_t bw;
}; };
@ -153,10 +153,10 @@ struct bandwidth
static bandwidth superwide; static bandwidth superwide;
static bandwidth full; static bandwidth full;
operator int32_t() { return bw; } operator int32_t() { return bw; }
typedef generic_get<bandwidth> get; static generic_get<bandwidth> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t bw; int32_t bw;
}; };
@ -168,10 +168,10 @@ struct signal
static signal music; static signal music;
static signal voice; static signal voice;
operator int32_t() { return s; } operator int32_t() { return s; }
typedef generic_eget<signal> get; static generic_eget<signal> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t s; int32_t s;
}; };
@ -183,10 +183,10 @@ struct application
static application voice; static application voice;
static application lowdelay; static application lowdelay;
operator int32_t() { return app; } operator int32_t() { return app; }
typedef generic_eget<application> get; static generic_eget<application> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t app; int32_t app;
}; };
@ -198,7 +198,7 @@ struct _lookahead
operator int32_t() { return l; } operator int32_t() { return l; }
typedef _lookahead erettype; typedef _lookahead erettype;
_lookahead operator()(encoder& e) const; _lookahead operator()(encoder& e) const;
_lookahead errordefault() { return _lookahead(0);} _lookahead errordefault() const { return _lookahead(0);}
private: private:
int32_t l; int32_t l;
}; };
@ -210,10 +210,10 @@ struct fec
static fec disabled; static fec disabled;
static fec enabled; static fec enabled;
operator bool() { return f; } operator bool() { return f; }
typedef generic_eget<fec> get; static generic_eget<fec> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
bool f; bool f;
}; };
@ -222,10 +222,10 @@ struct lossperc
{ {
lossperc(int32_t _loss) { loss = _loss; }; lossperc(int32_t _loss) { loss = _loss; };
operator int32_t() { return loss; } operator int32_t() { return loss; }
typedef generic_eget<lossperc> get; static generic_eget<lossperc> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t loss; int32_t loss;
}; };
@ -236,10 +236,10 @@ struct dtx
static dtx disabled; static dtx disabled;
static dtx enabled; static dtx enabled;
operator bool() { return d; } operator bool() { return d; }
typedef generic_eget<dtx> get; static generic_eget<dtx> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
bool d; bool d;
}; };
@ -251,10 +251,10 @@ struct lsbdepth
static lsbdepth d16; static lsbdepth d16;
static lsbdepth d24; static lsbdepth d24;
operator int32_t() { return depth; } operator int32_t() { return depth; }
typedef generic_eget<lsbdepth> get; static generic_eget<lsbdepth> get;
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t depth; int32_t depth;
}; };
@ -266,7 +266,7 @@ struct _pktduration
operator int32_t() { return d; } operator int32_t() { return d; }
typedef _pktduration erettype; typedef _pktduration erettype;
_pktduration operator()(encoder& e) const; _pktduration operator()(encoder& e) const;
_pktduration errordefault() { return _pktduration(0); } _pktduration errordefault() const { return _pktduration(0); }
private: private:
int32_t d; int32_t d;
}; };
@ -278,7 +278,7 @@ struct _reset
typedef void erettype; typedef void erettype;
void operator()(decoder& e) const; void operator()(decoder& e) const;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void errordefault() {} void errordefault() const {}
}; };
extern _reset reset; extern _reset reset;
@ -291,7 +291,7 @@ struct _finalrange
typedef _finalrange erettype; typedef _finalrange erettype;
_finalrange operator()(decoder& e) const; _finalrange operator()(decoder& e) const;
_finalrange operator()(encoder& e) const; _finalrange operator()(encoder& e) const;
_finalrange errordefault() { return _finalrange(0); } _finalrange errordefault() const { return _finalrange(0); }
private: private:
uint32_t f; uint32_t f;
}; };
@ -306,7 +306,7 @@ struct _pitch
typedef _pitch erettype; typedef _pitch erettype;
_pitch operator()(encoder& e) const; _pitch operator()(encoder& e) const;
_pitch operator()(decoder& e) const; _pitch operator()(decoder& e) const;
_pitch errordefault() { return _pitch(0); } _pitch errordefault() const { return _pitch(0); }
private: private:
int32_t p; int32_t p;
}; };
@ -316,10 +316,10 @@ struct gain
{ {
gain(int32_t _g) { g = _g; }; gain(int32_t _g) { g = _g; };
operator int32_t() { return g; } operator int32_t() { return g; }
typedef generic_dget<gain> get; static generic_dget<gain> get;
typedef void drettype; typedef void drettype;
void operator()(decoder& d) const; void operator()(decoder& d) const;
gain errordefault() { return gain(0); } gain errordefault() const { return gain(0); }
private: private:
int32_t g; int32_t g;
}; };
@ -331,7 +331,7 @@ struct set_control_int
typedef void erettype; typedef void erettype;
void operator()(encoder& e) const; void operator()(encoder& e) const;
void operator()(decoder& e) const; void operator()(decoder& e) const;
void errordefault() {} void errordefault() const {}
private: private:
int32_t ctl; int32_t ctl;
int32_t val; int32_t val;
@ -344,7 +344,7 @@ struct get_control_int
typedef int32_t erettype; typedef int32_t erettype;
int32_t operator()(encoder& e) const; int32_t operator()(encoder& e) const;
int32_t operator()(decoder& e) const; int32_t operator()(decoder& e) const;
int32_t errordefault() { return -1; } int32_t errordefault() const { return -1; }
private: private:
int32_t ctl; int32_t ctl;
}; };

View file

@ -110,9 +110,9 @@ int32_t throwex(int32_t ret)
throw std::runtime_error(s.str()); throw std::runtime_error(s.str());
} }
template<typename T> struct get_ctlnum { const static int32_t num; }; template<typename T> struct get_ctlnum { const static int32_t num; static T errordefault(); };
template<> const int32_t get_ctlnum<compexity>::num = OPUS_GET_COMPLEXITY_REQUEST; template<> const int32_t get_ctlnum<complexity>::num = OPUS_GET_COMPLEXITY_REQUEST;
template<> const int32_t get_ctlnum<bitrate>::num = OPUS_GET_BITRATE_REQUEST; template<> const int32_t get_ctlnum<bitrate>::num = OPUS_GET_BITRATE_REQUEST;
template<> const int32_t get_ctlnum<vbr>::num = OPUS_GET_VBR_REQUEST; template<> const int32_t get_ctlnum<vbr>::num = OPUS_GET_VBR_REQUEST;
template<> const int32_t get_ctlnum<vbr_constraint>::num = OPUS_GET_VBR_CONSTRAINT_REQUEST; template<> const int32_t get_ctlnum<vbr_constraint>::num = OPUS_GET_VBR_CONSTRAINT_REQUEST;
@ -127,6 +127,22 @@ template<> const int32_t get_ctlnum<dtx>::num = OPUS_GET_DTX_REQUEST;
template<> const int32_t get_ctlnum<lsbdepth>::num = OPUS_GET_LSB_DEPTH_REQUEST; template<> const int32_t get_ctlnum<lsbdepth>::num = OPUS_GET_LSB_DEPTH_REQUEST;
template<> const int32_t get_ctlnum<gain>::num = OPUS_GET_GAIN_REQUEST; template<> const int32_t get_ctlnum<gain>::num = OPUS_GET_GAIN_REQUEST;
template<> complexity get_ctlnum<complexity>::errordefault() { return complexity(10); }
template<> bitrate get_ctlnum<bitrate>::errordefault() { return bitrate::_auto; }
template<> vbr get_ctlnum<vbr>::errordefault() { return vbr::_vbr; }
template<> vbr_constraint get_ctlnum<vbr_constraint>::errordefault() { return vbr_constraint::unconstrained; }
template<> force_channels get_ctlnum<force_channels>::errordefault() { return force_channels::_auto; }
template<> max_bandwidth get_ctlnum<max_bandwidth>::errordefault() { return max_bandwidth::full; }
template<> bandwidth get_ctlnum<bandwidth>::errordefault() { return bandwidth::_auto; }
template<> signal get_ctlnum<signal>::errordefault() { return signal::_auto; }
template<> application get_ctlnum<application>::errordefault() { return application::audio; }
template<> fec get_ctlnum<fec>::errordefault() { return fec::disabled; }
template<> lossperc get_ctlnum<lossperc>::errordefault() { return lossperc(0); }
template<> dtx get_ctlnum<dtx>::errordefault() { return dtx::disabled; }
template<> lsbdepth get_ctlnum<lsbdepth>::errordefault() { return lsbdepth(24); }
template<> gain get_ctlnum<gain>::errordefault() { return gain(0); }
OpusEncoder* E(encoder& e) { return reinterpret_cast<OpusEncoder*>(e.getmem()); } OpusEncoder* E(encoder& e) { return reinterpret_cast<OpusEncoder*>(e.getmem()); }
OpusDecoder* D(decoder& d) { return reinterpret_cast<OpusDecoder*>(d.getmem()); } OpusDecoder* D(decoder& d) { return reinterpret_cast<OpusDecoder*>(d.getmem()); }
OpusRepacketizer* R(repacketizer& r) { return reinterpret_cast<OpusRepacketizer*>(r.getmem()); } OpusRepacketizer* R(repacketizer& r) { return reinterpret_cast<OpusRepacketizer*>(r.getmem()); }
@ -186,56 +202,90 @@ template<typename T> T generic_get<T>::operator()(encoder& e) const
return do_generic_get<T>(e); return do_generic_get<T>(e);
} }
template<typename T> T generic_eget<T>::errordefault() const
{
return get_ctlnum<T>::errordefault();
}
template<typename T> T generic_dget<T>::errordefault() const
{
return get_ctlnum<T>::errordefault();
}
template<typename T> T generic_get<T>::errordefault() const
{
return get_ctlnum<T>::errordefault();
}
samplerate samplerate::operator()(encoder& e) const samplerate samplerate::operator()(encoder& e) const
{ {
return samplerate(generic_ctl<int32_t>(e, OPUS_GET_SAMPLE_RATE_REQUEST)); return samplerate(generic_ctl<int32_t>(e, OPUS_GET_SAMPLE_RATE_REQUEST));
} }
void compexity::operator()(encoder& e) const void complexity::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_COMPLEXITY_REQUEST, c); generic_ctl(e, OPUS_SET_COMPLEXITY_REQUEST, c);
} }
generic_eget<complexity> complexity::get;
void bitrate::operator()(encoder& e) const void bitrate::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_BITRATE_REQUEST, b); generic_ctl(e, OPUS_SET_BITRATE_REQUEST, b);
} }
generic_eget<bitrate> bitrate::get;
void vbr::operator()(encoder& e) const void vbr::operator()(encoder& e) const
{ {
generic_ctl<int32_t>(e, OPUS_SET_VBR_REQUEST, v ? 1 : 0); generic_ctl<int32_t>(e, OPUS_SET_VBR_REQUEST, v ? 1 : 0);
} }
generic_eget<vbr> vbr::get;
void vbr_constraint::operator()(encoder& e) const void vbr_constraint::operator()(encoder& e) const
{ {
generic_ctl<int32_t>(e, OPUS_SET_VBR_CONSTRAINT_REQUEST, c ? 1 : 0); generic_ctl<int32_t>(e, OPUS_SET_VBR_CONSTRAINT_REQUEST, c ? 1 : 0);
} }
generic_eget<vbr_constraint> vbr_constraint::get;
void force_channels::operator()(encoder& e) const void force_channels::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_FORCE_CHANNELS_REQUEST, f); generic_ctl(e, OPUS_SET_FORCE_CHANNELS_REQUEST, f);
} }
generic_eget<force_channels> force_channels::get;
void max_bandwidth::operator()(encoder& e) const void max_bandwidth::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_MAX_BANDWIDTH_REQUEST, bw); generic_ctl(e, OPUS_SET_MAX_BANDWIDTH_REQUEST, bw);
} }
generic_eget<max_bandwidth> max_bandwidth::get;
void bandwidth::operator()(encoder& e) const void bandwidth::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_BANDWIDTH_REQUEST, bw); generic_ctl(e, OPUS_SET_BANDWIDTH_REQUEST, bw);
} }
generic_get<bandwidth> bandwidth::get;
void signal::operator()(encoder& e) const void signal::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_SIGNAL_REQUEST, s); generic_ctl(e, OPUS_SET_SIGNAL_REQUEST, s);
} }
generic_eget<signal> signal::get;
void application::operator()(encoder& e) const void application::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_APPLICATION_REQUEST, app); generic_ctl(e, OPUS_SET_APPLICATION_REQUEST, app);
} }
generic_eget<application> application::get;
_lookahead _lookahead::operator()(encoder& e) const _lookahead _lookahead::operator()(encoder& e) const
{ {
return _lookahead(generic_ctl<int32_t>(e, OPUS_GET_LOOKAHEAD_REQUEST)); return _lookahead(generic_ctl<int32_t>(e, OPUS_GET_LOOKAHEAD_REQUEST));
@ -246,21 +296,29 @@ void fec::operator()(encoder& e) const
generic_ctl<int32_t>(e, OPUS_SET_INBAND_FEC_REQUEST, f ? 1 : 0); generic_ctl<int32_t>(e, OPUS_SET_INBAND_FEC_REQUEST, f ? 1 : 0);
} }
generic_eget<fec> fec::get;
void lossperc::operator()(encoder& e) const void lossperc::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_PACKET_LOSS_PERC_REQUEST, loss); generic_ctl(e, OPUS_SET_PACKET_LOSS_PERC_REQUEST, loss);
} }
generic_eget<lossperc> lossperc::get;
void dtx::operator()(encoder& e) const void dtx::operator()(encoder& e) const
{ {
generic_ctl<int32_t>(e, OPUS_SET_DTX_REQUEST, d ? 1 : 0); generic_ctl<int32_t>(e, OPUS_SET_DTX_REQUEST, d ? 1 : 0);
} }
generic_eget<dtx> dtx::get;
void lsbdepth::operator()(encoder& e) const void lsbdepth::operator()(encoder& e) const
{ {
generic_ctl(e, OPUS_SET_LSB_DEPTH_REQUEST, depth); generic_ctl(e, OPUS_SET_LSB_DEPTH_REQUEST, depth);
} }
generic_eget<lsbdepth> lsbdepth::get;
_pktduration _pktduration::operator()(encoder& e) const _pktduration _pktduration::operator()(encoder& e) const
{ {
return _pktduration(generic_ctl<int32_t>(e, OPUS_GET_LAST_PACKET_DURATION_REQUEST)); return _pktduration(generic_ctl<int32_t>(e, OPUS_GET_LAST_PACKET_DURATION_REQUEST));
@ -301,6 +359,8 @@ void gain::operator()(decoder& d) const
generic_ctl(d, OPUS_SET_GAIN_REQUEST, g); generic_ctl(d, OPUS_SET_GAIN_REQUEST, g);
} }
generic_dget<gain> gain::get;
void set_control_int::operator()(encoder& e) const void set_control_int::operator()(encoder& e) const
{ {
generic_ctl(e, ctl, val); generic_ctl(e, ctl, val);
@ -325,21 +385,40 @@ void force_instantiate()
{ {
encoder e(samplerate::r48k, true, application::audio); encoder e(samplerate::r48k, true, application::audio);
decoder d(samplerate::r48k, true); decoder d(samplerate::r48k, true);
compexity::get()(e); complexity::get(e);
bitrate::get()(e); bitrate::get(e);
vbr::get()(e); vbr::get(e);
vbr_constraint::get()(e); vbr_constraint::get(e);
force_channels::get()(e); force_channels::get(e);
max_bandwidth::get()(e); max_bandwidth::get(e);
bandwidth::get()(e); bandwidth::get(e);
bandwidth::get()(d); bandwidth::get(d);
signal::get()(e); signal::get(e);
application::get()(e); application::get(e);
fec::get()(e); fec::get(e);
lossperc::get()(e); lossperc::get(e);
dtx::get()(e); dtx::get(e);
lsbdepth::get()(e); lsbdepth::get(e);
gain::get()(d); gain::get(d);
complexity::get.errordefault();
bitrate::get.errordefault();
vbr::get.errordefault();
vbr_constraint::get.errordefault();
force_channels::get.errordefault();
max_bandwidth::get.errordefault();
bandwidth::get.errordefault();
signal::get.errordefault();
application::get.errordefault();
fec::get.errordefault();
lossperc::get.errordefault();
dtx::get.errordefault();
lsbdepth::get.errordefault();
gain::get.errordefault();
e.ctl_quiet(opus::reset);
e.ctl_quiet(opus::finalrange);
e.ctl_quiet(opus::signal::get);
} }
encoder::~encoder() encoder::~encoder()