Commit 5fade698 authored by Kehuang Li's avatar Kehuang Li Committed by Commit Bot

[Chromecast] Fix CastAudioInputStream doesn't release itself

Input stream needs to release itself from AudioManager by calling
ReleaseInputStream after closing, but CastAudioInputStream didn't, and
thus will not be able to create new streams after open/close 16 times.

Bug: internal: 144114606
Test: Compile.
Change-Id: Ic2ee3e8e5110bee3597380620f06e48731786199
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954450Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Kehuang Li <kehuangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722563}
parent 7cece554
......@@ -6,14 +6,16 @@
#include "base/logging.h"
#include "chromecast/media/audio/capture_service/capture_service_receiver.h"
#include "media/audio/audio_manager_base.h"
namespace chromecast {
namespace media {
CastAudioInputStream::CastAudioInputStream(
::media::AudioManagerBase* audio_manager,
const ::media::AudioParameters& audio_params,
const std::string& device_id)
: audio_params_(audio_params) {
: audio_manager_(audio_manager), audio_params_(audio_params) {
DETACH_FROM_THREAD(audio_thread_checker_);
LOG(INFO) << __func__ << " " << this
<< " created from device_id = " << device_id
......@@ -67,6 +69,9 @@ void CastAudioInputStream::Close() {
DCHECK_CALLED_ON_VALID_THREAD(audio_thread_checker_);
LOG(INFO) << __func__ << " " << this << ".";
capture_service_receiver_.reset();
if (audio_manager_) {
audio_manager_->ReleaseInputStream(this);
}
}
double CastAudioInputStream::GetMaxVolume() {
......
......@@ -13,6 +13,10 @@
#include "media/audio/audio_io.h"
#include "media/base/audio_parameters.h"
namespace media {
class AudioManagerBase;
} // namespace media
namespace chromecast {
namespace media {
......@@ -21,7 +25,8 @@ class CastAudioManager;
class CastAudioInputStream : public ::media::AudioInputStream {
public:
CastAudioInputStream(const ::media::AudioParameters& audio_params,
CastAudioInputStream(::media::AudioManagerBase* audio_manager,
const ::media::AudioParameters& audio_params,
const std::string& device_id);
~CastAudioInputStream() override;
......@@ -39,6 +44,9 @@ class CastAudioInputStream : public ::media::AudioInputStream {
void SetOutputDeviceForAec(const std::string& output_device_id) override;
private:
// Hold a raw pointer to audio manager to inform releasing |this|. The pointer
// may be null, if |this| is not created by audio manager, e.g., in unit test.
::media::AudioManagerBase* const audio_manager_;
const ::media::AudioParameters audio_params_;
std::unique_ptr<CaptureServiceReceiver> capture_service_receiver_;
......
......@@ -167,7 +167,7 @@ void CastAudioManagerAlsa::GetAudioInputDeviceNames(
NOTIMPLEMENTED() << "Capture Service is not enabled, return nullptr.";
return nullptr;
#endif // BUILDFLAG(ENABLE_AUDIO_CAPTURE_SERVICE)
return new CastAudioInputStream(params, device_name);
return new CastAudioInputStream(this, params, device_name);
}
return new ::media::AlsaPcmInputStream(this, device_name, params,
wrapper_.get());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment