Skip to content

Commit

Permalink
Bug 1846191 assert that a cubeb_mock_stream is not used after it is d…
Browse files Browse the repository at this point in the history
…estroyed r=padenot,pehrsons

while it may still be alive as a MockCubebStream.

Differential Revision: https://phabricator.services.mozilla.com/D185026
  • Loading branch information
karlt committed Aug 23, 2023
1 parent 4eff4b1 commit d5e671a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions dom/media/gtest/MockCubeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ void MockCubebStream::Destroy() {
// This provides an extra STOPPED state callback as with audioipc.
// It also ensures that this stream is removed from MockCubeb::mLiveStreams.
Stop();
MockCubeb::AsMock(context)->StreamDestroy(AsCubebStream());
mDestroyed = true;
MockCubeb::AsMock(context)->StreamDestroy(this);
}

int MockCubebStream::RegisterDeviceChangedCallback(
Expand All @@ -257,11 +258,14 @@ int MockCubebStream::RegisterDeviceChangedCallback(
}

cubeb_stream* MockCubebStream::AsCubebStream() {
MOZ_ASSERT(!mDestroyed);
return reinterpret_cast<cubeb_stream*>(this);
}

MockCubebStream* MockCubebStream::AsMock(cubeb_stream* aStream) {
return reinterpret_cast<MockCubebStream*>(aStream);
auto* mockStream = reinterpret_cast<MockCubebStream*>(aStream);
MOZ_ASSERT(!mockStream->mDestroyed);
return mockStream;
}

cubeb_devid MockCubebStream::GetInputDeviceID() const { return mInputDeviceID; }
Expand Down Expand Up @@ -591,9 +595,8 @@ int MockCubeb::StreamInit(cubeb* aContext, cubeb_stream** aStream,
return CUBEB_OK;
}

void MockCubeb::StreamDestroy(cubeb_stream* aStream) {
RefPtr<SmartMockCubebStream> mockStream =
dont_AddRef(MockCubebStream::AsMock(aStream)->mSelf);
void MockCubeb::StreamDestroy(MockCubebStream* aStream) {
RefPtr<SmartMockCubebStream> mockStream = dont_AddRef(aStream->mSelf);
mStreamDestroyEvent.Notify(mockStream);
}

Expand Down
3 changes: 2 additions & 1 deletion dom/media/gtest/MockCubeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class MockCubebStream {
std::atomic_bool mFastMode{false};
std::atomic_bool mForceErrorState{false};
std::atomic_bool mForceDeviceChanged{false};
std::atomic_bool mDestroyed{false};
std::atomic<uint64_t> mPosition{0};
AudioGenerator<AudioDataValue> mAudioGenerator;
AudioVerifier<AudioDataValue> mAudioVerifier;
Expand Down Expand Up @@ -367,7 +368,7 @@ class MockCubeb {
cubeb_data_callback aDataCallback,
cubeb_state_callback aStateCallback, void* aUserPtr);

void StreamDestroy(cubeb_stream* aStream);
void StreamDestroy(MockCubebStream* aStream);

void GoFaster();
void DontGoFaster();
Expand Down

0 comments on commit d5e671a

Please sign in to comment.