Bug 1272225. Part 1 - add assertions to make thread constraints clear. r=jya.
MozReview-Commit-ID: I3YCiHtsLWv
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -60,16 +60,17 @@ AppleATDecoder::Init()
}
return InitPromise::CreateAndResolve(TrackType::kAudioTrack, __func__);
}
nsresult
AppleATDecoder::Input(MediaRawData* aSample)
{
+ MOZ_ASSERT(mCallback->OnReaderTaskQueue());
LOG("mp4 input sample %p %lld us %lld pts%s %llu bytes audio",
aSample,
aSample->mDuration,
aSample->mTime,
aSample->mKeyframe ? " keyframe" : "",
(unsigned long long)aSample->Size());
// Queue a task to perform the actual decoding on a separate thread.
@@ -81,39 +82,43 @@ AppleATDecoder::Input(MediaRawData* aSam
mTaskQueue->Dispatch(runnable.forget());
return NS_OK;
}
nsresult
AppleATDecoder::Flush()
{
+ MOZ_ASSERT(mCallback->OnReaderTaskQueue());
LOG("Flushing AudioToolbox AAC decoder");
mTaskQueue->Flush();
mQueuedSamples.Clear();
OSStatus rv = AudioConverterReset(mConverter);
if (rv) {
LOG("Error %d resetting AudioConverter", rv);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
AppleATDecoder::Drain()
{
+ MOZ_ASSERT(mCallback->OnReaderTaskQueue());
LOG("Draining AudioToolbox AAC decoder");
mTaskQueue->AwaitIdle();
mCallback->DrainComplete();
return Flush();
}
nsresult
AppleATDecoder::Shutdown()
{
+ MOZ_ASSERT(mCallback->OnReaderTaskQueue());
+
LOG("Shutdown: Apple AudioToolbox AAC decoder");
mQueuedSamples.Clear();
OSStatus rv = AudioConverterDispose(mConverter);
if (rv) {
LOG("error %d disposing of AudioConverter", rv);
return NS_ERROR_FAILURE;
}
mConverter = nullptr;
@@ -168,16 +173,18 @@ static OSStatus
userData->mDataSize = 0;
return noErr;
}
void
AppleATDecoder::SubmitSample(MediaRawData* aSample)
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
nsresult rv = NS_OK;
if (!mConverter) {
rv = SetupDecoder(aSample);
if (rv != NS_OK && rv != NS_ERROR_NOT_INITIALIZED) {
mCallback->Error();
return;
}
}
@@ -198,16 +205,18 @@ AppleATDecoder::SubmitSample(MediaRawDat
if (mTaskQueue->IsEmpty()) {
mCallback->InputExhausted();
}
}
nsresult
AppleATDecoder::DecodeSample(MediaRawData* aSample)
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
// Array containing the queued decoded audio frames, about to be output.
nsTArray<AudioDataValue> outputData;
UInt32 channels = mOutputFormat.mChannelsPerFrame;
// Pick a multiple of the frame size close to a power of two
// for efficient allocation.
const uint32_t MAX_AUDIO_FRAMES = 128;
const uint32_t maxDecodedSamples = MAX_AUDIO_FRAMES * channels;
@@ -303,16 +312,18 @@ AppleATDecoder::DecodeSample(MediaRawDat
mCallback->Output(audio);
return NS_OK;
}
nsresult
AppleATDecoder::GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
const nsTArray<uint8_t>& aExtraData)
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
// Request the properties from CoreAudio using the codec magic cookie
AudioFormatInfo formatInfo;
PodZero(&formatInfo.mASBD);
formatInfo.mASBD.mFormatID = mFormatID;
if (mFormatID == kAudioFormatMPEG4AAC) {
formatInfo.mASBD.mFormatFlags = mConfig.mExtendedProfile;
}
formatInfo.mMagicCookieSize = aExtraData.Length();
@@ -406,16 +417,18 @@ ConvertChannelLabel(AudioChannelLabel id
}
}
// Will set mChannelLayout if a channel layout could properly be identified
// and is supported.
nsresult
AppleATDecoder::SetupChannelLayout()
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
// Determine the channel layout.
UInt32 propertySize;
UInt32 size;
OSStatus status =
AudioConverterGetPropertyInfo(mConverter,
kAudioConverterOutputChannelLayout,
&propertySize, NULL);
if (status || !propertySize) {
@@ -505,16 +518,18 @@ AppleATDecoder::SetupChannelLayout()
MakeUnique<AudioConfig::ChannelLayout>(mOutputFormat.mChannelsPerFrame,
channels);
return NS_OK;
}
nsresult
AppleATDecoder::SetupDecoder(MediaRawData* aSample)
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
if (mFormatID == kAudioFormatMPEG4AAC &&
mConfig.mExtendedProfile == 2) {
// Check for implicit SBR signalling if stream is AAC-LC
// This will provide us with an updated magic cookie for use with
// GetInputAudioDescription.
if (NS_SUCCEEDED(GetImplicitAACMagicCookie(aSample)) &&
!mMagicCookie.Length()) {
// nothing found yet, will try again later
@@ -610,16 +625,18 @@ static void
const void* aData,
AudioStreamPacketDescription* aPackets)
{
}
nsresult
AppleATDecoder::GetImplicitAACMagicCookie(const MediaRawData* aSample)
{
+ MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+
// Prepend ADTS header to AAC audio.
RefPtr<MediaRawData> adtssample(aSample->Clone());
if (!adtssample) {
return NS_ERROR_OUT_OF_MEMORY;
}
int8_t frequency_index =
mp4_demuxer::Adts::GetFrequencyIndex(mConfig.mRate);