Rent-A-Codec: Reference count the shared iSAC bandwidth estimation state

Now that the Rent-A-Codec no longer owns the encoders and decoders it
produces, they may outlive it. It's thus no longer correct for the
Rent-A-Codec to own the bandwidth estimation state; all of the
involved objects need to share ownership.

BUG=webrtc:5028

Review URL: https://codereview.webrtc.org/1821513003

Cr-Commit-Position: refs/heads/master@{#12159}
This commit is contained in:
kwiberg
2016-03-30 04:10:11 -07:00
committed by Commit bot
parent 4cdbd57fe3
commit 0d05da7ee6
8 changed files with 47 additions and 27 deletions

View File

@ -40,6 +40,10 @@
#include "webrtc/modules/audio_coding/acm2/acm_codec_database.h"
#include "webrtc/modules/audio_coding/acm2/acm_common_defs.h"
#if defined(WEBRTC_CODEC_ISACFX) || defined(WEBRTC_CODEC_ISAC)
#include "webrtc/modules/audio_coding/codecs/isac/locked_bandwidth_info.h"
#endif
namespace webrtc {
namespace acm2 {
@ -145,8 +149,9 @@ namespace {
// Returns a new speech encoder, or null on error.
// TODO(kwiberg): Don't handle errors here (bug 5033)
std::unique_ptr<AudioEncoder> CreateEncoder(const CodecInst& speech_inst,
LockedIsacBandwidthInfo* bwinfo) {
std::unique_ptr<AudioEncoder> CreateEncoder(
const CodecInst& speech_inst,
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) {
#if defined(WEBRTC_CODEC_ISACFX)
if (STR_CASE_CMP(speech_inst.plname, "isac") == 0)
return std::unique_ptr<AudioEncoder>(
@ -221,7 +226,7 @@ std::unique_ptr<AudioEncoder> CreateCngEncoder(
}
std::unique_ptr<AudioDecoder> CreateIsacDecoder(
LockedIsacBandwidthInfo* bwinfo) {
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) {
#if defined(WEBRTC_CODEC_ISACFX)
return std::unique_ptr<AudioDecoder>(new AudioDecoderIsacFix(bwinfo));
#elif defined(WEBRTC_CODEC_ISAC)
@ -234,12 +239,16 @@ std::unique_ptr<AudioDecoder> CreateIsacDecoder(
} // namespace
RentACodec::RentACodec() = default;
RentACodec::RentACodec() {
#if defined(WEBRTC_CODEC_ISACFX) || defined(WEBRTC_CODEC_ISAC)
isac_bandwidth_info_ = new LockedIsacBandwidthInfo;
#endif
}
RentACodec::~RentACodec() = default;
std::unique_ptr<AudioEncoder> RentACodec::RentEncoder(
const CodecInst& codec_inst) {
return CreateEncoder(codec_inst, &isac_bandwidth_info_);
return CreateEncoder(codec_inst, isac_bandwidth_info_);
}
RentACodec::StackParameters::StackParameters() {
@ -295,7 +304,7 @@ std::unique_ptr<AudioEncoder> RentACodec::RentEncoderStack(
}
std::unique_ptr<AudioDecoder> RentACodec::RentIsacDecoder() {
return CreateIsacDecoder(&isac_bandwidth_info_);
return CreateIsacDecoder(isac_bandwidth_info_);
}
} // namespace acm2

View File

@ -18,23 +18,16 @@
#include "webrtc/base/array_view.h"
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/optional.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/typedefs.h"
#if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
#include "webrtc/modules/audio_coding/codecs/isac/locked_bandwidth_info.h"
#else
// Dummy implementation, for when we don't have iSAC.
namespace webrtc {
class LockedIsacBandwidthInfo {};
}
#endif
namespace webrtc {
struct CodecInst;
class LockedIsacBandwidthInfo;
namespace acm2 {
@ -229,7 +222,7 @@ class RentACodec {
std::unique_ptr<AudioEncoder> speech_encoder_;
std::unique_ptr<AudioEncoder> cng_encoder_;
std::unique_ptr<AudioEncoder> red_encoder_;
LockedIsacBandwidthInfo isac_bandwidth_info_;
rtc::scoped_refptr<LockedIsacBandwidthInfo> isac_bandwidth_info_;
RTC_DISALLOW_COPY_AND_ASSIGN(RentACodec);
};