Fixes for 1.4.6
This commit is contained in:
@@ -40,12 +40,12 @@ namespace tc {
|
||||
/**
|
||||
* @return number of bytes written on success
|
||||
*/
|
||||
virtual ssize_t encode(std::string& /* error */, const void* /* source */, void* /* destination */, size_t /* destination byte length */) = 0;
|
||||
virtual ssize_t encode(std::string& /* error */, const void* /* source */, void* /* destination */, size_t /* destination byte length */, bool /* head package */) = 0;
|
||||
|
||||
/**
|
||||
* @return number of samples on success
|
||||
*/
|
||||
virtual ssize_t decode(std::string& /* error */, const void* /* source */, size_t /* source byte length */, void* /* destination */) = 0;
|
||||
virtual ssize_t decode(std::string& /* error */, const void* /* source */, size_t /* source byte length */, void* /* destination */, bool /* fec decoding */) = 0;
|
||||
virtual ssize_t decode_lost(std::string& /* error */, size_t /* packets */) = 0;
|
||||
|
||||
virtual size_t expected_encoded_length(size_t /* sample count */) = 0;
|
||||
|
||||
@@ -29,7 +29,7 @@ bool OpusConverter::initialize(std::string &error, int application_type) {
|
||||
void OpusConverter::reset_encoder() {
|
||||
lock_guard lock(this->coder_lock);
|
||||
|
||||
|
||||
log_info(category::audio, tr("Resetting encoder"));
|
||||
auto result = opus_encoder_ctl(this->encoder, OPUS_RESET_STATE);
|
||||
if(result != OPUS_OK)
|
||||
log_warn(category::audio, tr("Failed to reset opus encoder. Opus result: {}"), result);
|
||||
@@ -38,9 +38,11 @@ void OpusConverter::reset_encoder() {
|
||||
void OpusConverter::reset_decoder() {
|
||||
lock_guard lock(this->coder_lock);
|
||||
|
||||
log_info(category::audio, tr("Resetting decoder"));
|
||||
auto result = opus_decoder_ctl(this->decoder, OPUS_RESET_STATE);
|
||||
if(result != OPUS_OK)
|
||||
log_warn(category::audio, tr("Failed to reset opus decoder. Opus result: {}"), result);
|
||||
this->fec_decoder_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +56,10 @@ void OpusConverter::finalize() {
|
||||
this->decoder = nullptr;
|
||||
}
|
||||
|
||||
ssize_t OpusConverter::encode(std::string &error, const void *source, void *target, size_t target_length) {
|
||||
ssize_t OpusConverter::encode(std::string &error, const void *source, void *target, size_t target_length, bool head_package) {
|
||||
lock_guard lock(this->coder_lock);
|
||||
|
||||
opus_encoder_ctl(encoder, OPUS_SET_PACKET_LOSS_PERC(head_package ? 100 : 15));
|
||||
auto result = opus_encode_float(this->encoder, (float*) source, (int) this->_frame_size, (uint8_t*) target, (opus_int32) target_length);
|
||||
if(result < OPUS_OK) {
|
||||
error = to_string(result) + "|" + opus_strerror(result);
|
||||
@@ -65,10 +68,10 @@ ssize_t OpusConverter::encode(std::string &error, const void *source, void *targ
|
||||
return result;
|
||||
}
|
||||
|
||||
ssize_t OpusConverter::decode(std::string &error, const void *source, size_t source_length, void *target) {
|
||||
ssize_t OpusConverter::decode(std::string &error, const void *source, size_t source_length, void *target, bool use_fec) {
|
||||
lock_guard lock(this->coder_lock);
|
||||
|
||||
auto result = opus_decode_float(this->decoder, (uint8_t*) source, (opus_int32) source_length, (float*) target, (int) this->_frame_size, 0);
|
||||
auto result = opus_decode_float(this->decoder, (uint8_t*) source, (opus_int32) source_length, (float*) target, (int) this->_frame_size, use_fec ? 1 : 0);
|
||||
if(result < OPUS_OK) {
|
||||
error = to_string(result) + "|" + opus_strerror(result);
|
||||
return -1;
|
||||
@@ -85,6 +88,7 @@ ssize_t OpusConverter::decode_lost(std::string &error, size_t packets) {
|
||||
if(result < OPUS_OK)
|
||||
log_warn(category::audio, tr("Opus decode lost resulted in error: {}"), result);
|
||||
}
|
||||
this->fec_decoder_ = true;
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
@@ -123,6 +127,19 @@ bool OpusConverter::_initialize_encoder(std::string &error) {
|
||||
error = "failed to set bitrate (" + to_string(error_id) + ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
error_id = opus_encoder_ctl(encoder, OPUS_SET_INBAND_FEC(1));
|
||||
if(error_id) {
|
||||
error = "failed to enable fec (" + to_string(error_id) + ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
error_id = opus_encoder_ctl(encoder, OPUS_SET_PACKET_LOSS_PERC(15));
|
||||
if(error_id) {
|
||||
error = "failed to assume a 15% packet loss (" + to_string(error_id) + ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace tc {
|
||||
void reset_encoder() override;
|
||||
void reset_decoder() override;
|
||||
|
||||
ssize_t encode(std::string & /* error */, const void * /* source */, void * /* target */, size_t /* target size */) override;
|
||||
ssize_t decode(std::string & /* error */, const void * /* source */, size_t /* source size */, void *pVoid1) override;
|
||||
ssize_t encode(std::string & /* error */, const void * /* source */, void * /* target */, size_t /* target size */, bool /* head package */) override;
|
||||
ssize_t decode(std::string & /* error */, const void * /* source */, size_t /* source size */, void *pVoid1, bool /* use fec */) override;
|
||||
|
||||
ssize_t decode_lost(std::string &string, size_t /* packets */) override;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace tc {
|
||||
OpusDecoder* decoder = nullptr;
|
||||
OpusEncoder* encoder = nullptr;
|
||||
|
||||
bool fec_decoder_{false};
|
||||
int _application_type = 0;
|
||||
|
||||
bool _finalize_encoder(std::string& /* error */);
|
||||
|
||||
Reference in New Issue
Block a user