Bug 1426718 - Assert that we append at most once per stream per iteration. r?padenot
MozReview-Commit-ID: 3bNTZRhv839
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -358,16 +358,28 @@ private:
/**
* Representation of data tied to an AllocationHandle rather than to the source.
*/
struct Allocation {
Allocation() = delete;
explicit Allocation(const RefPtr<AllocationHandle>& aHandle);
~Allocation();
+#ifdef DEBUG
+ /**
+ * We call this every time we append data to the track for this Allocation.
+ * It asserts that we only append once per iteration at most.
+ */
+ void RegisterLastAppendTime(MediaStreamGraphImpl* aGraph);
+
+ // The MSGImpl::IterationEnd() of the last time we appended data.
+ // Graph thread only.
+ GraphTime mLastAppendTime = 0;
+#endif
+
const RefPtr<AllocationHandle> mHandle;
RefPtr<SourceMediaStream> mStream;
TrackID mTrackID = TRACK_NONE;
PrincipalHandle mPrincipal = PRINCIPAL_HANDLE_NONE;
bool mEnabled = false;
};
/**
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -50,16 +50,29 @@ LogModule* AudioLogModule() {
}
Allocation::Allocation(const RefPtr<AllocationHandle>& aHandle)
: mHandle(aHandle)
{}
Allocation::~Allocation() = default;
+#ifdef DEBUG
+void
+Allocation::RegisterLastAppendTime(
+ MediaStreamGraphImpl* aGraph)
+{
+ aGraph->AssertOnGraphThreadOrNotRunning();
+ MOZ_ASSERT((aGraph->IterationEnd() == 0 && mLastAppendTime == 0) ||
+ aGraph->IterationEnd() > mLastAppendTime,
+ "Iteration time didn't advance since last append");
+ mLastAppendTime = aGraph->IterationEnd();
+}
+#endif
+
void
WebRTCAudioDataListener::NotifyOutputData(MediaStreamGraph* aGraph,
AudioDataValue* aBuffer,
size_t aFrames,
TrackRate aRate,
uint32_t aChannels)
{
MutexAutoLock lock(mMutex);
@@ -878,16 +891,31 @@ MediaEngineWebRTCMicrophoneSource::Pull(
{
LOG_FRAMES(("NotifyPull, desired = %" PRId64, (int64_t) aDesiredTime));
StreamTime delta = aDesiredTime - aStream->GetEndOfAppendedData(aTrackID);
if (delta <= 0) {
return;
}
+ {
+ MutexAutoLock lock(mMutex);
+ size_t i = mAllocations.IndexOf(aHandle, 0, AllocationHandleComparator());
+ if (i == mAllocations.NoIndex) {
+ // This handle must have been deallocated. That's fine, and its track
+ // will already be ended. No need to do anything.
+ return;
+ }
+
+#ifdef DEBUG
+ mAllocations[i].RegisterLastAppendTime(
+ static_cast<MediaStreamGraphImpl*>(aStream->Graph()));
+#endif
+ }
+
// Not enough data has been pushed so we fill it with silence.
// This could be due to underruns or because we have been stopped.
AudioSegment audio;
audio.AppendNullData(delta);
aStream->AppendToTrack(aTrackID, &audio);
}
@@ -1153,16 +1181,20 @@ MediaEngineWebRTCMicrophoneSource::Inser
}
}
for (Allocation& allocation : mAllocations) {
if (!allocation.mStream) {
continue;
}
+#ifdef DEBUG
+ allocation.RegisterLastAppendTime(allocation.mStream->GraphImpl());
+#endif
+
TimeStamp insertTime;
// Make sure we include the stream and the track.
// The 0:1 is a flag to note when we've done the final insert for a given input block.
LogTime(AsyncLatencyLogger::AudioTrackInsertion,
LATENCY_STREAM_ID(allocation.mStream.get(), allocation.mTrackID),
(&allocation != &mAllocations.LastElement()) ? 0 : 1, insertTime);
// Bug 971528 - Support stereo capture in gUM