bool GMPRemoveTest::CreateVideoDecoder(nsCString aNodeId) { GMPVideoHost* host; GMPVideoDecoderProxy* decoder = nullptr; mGMPThread->Dispatch(NewNonOwningRunnableMethod<nsCString, GMPVideoDecoderProxy**, GMPVideoHost**>( "GMPRemoveTest::gmp_GetVideoDecoder", this, &GMPRemoveTest::gmp_GetVideoDecoder, aNodeId, &decoder, &host), NS_DISPATCH_NORMAL); mTestMonitor.AwaitFinished(); if (!decoder) { return false; } GMPVideoCodec codec; memset(&codec, 0, sizeof(codec)); codec.mGMPApiVersion = 33; nsTArray<uint8_t> empty; mGMPThread->Dispatch( NewNonOwningRunnableMethod<const GMPVideoCodec&, const nsTArray<uint8_t>&, GMPVideoDecoderCallbackProxy*, int32_t>("GMPVideoDecoderProxy::InitDecode", decoder, &GMPVideoDecoderProxy::InitDecode, codec, empty, this, 1 /* core count */), NS_DISPATCH_SYNC); if (mDecoder) { CloseVideoDecoder(); } mDecoder = decoder; mHost = host; return true; }
void AudioSendAndReceive::Start() { eventStartCapture = new AudioStartCaptureEvent(this); mAudioCaptureThread->Dispatch(eventStartCapture,0); eventStartRender = new AudioStartRenderEvent(this); mAudioRenderThread->Dispatch(eventStartRender,0); //let's wait till test ends while(!amIDone) { std::cout << " Waating for the events to end " << std::endl; sleep(2); } }
void Dispatch() { MOZ_ASSERT(NS_IsMainThread()); mEventTarget = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ENSURE_TRUE_VOID(mEventTarget); nsresult rv = mEventTarget->Dispatch(this, NS_DISPATCH_NORMAL); NS_ENSURE_SUCCESS_VOID(rv); }
GMPErr GMPRemoveTest::Decode() { mGMPThread->Dispatch( NS_NewNonOwningRunnableMethod(this, &GMPRemoveTest::gmp_Decode), NS_DISPATCH_NORMAL); mTestMonitor.AwaitFinished(); return mDecodeResult; }
void GMPRemoveTest::CloseVideoDecoder() { mGMPThread->Dispatch( NS_NewNonOwningRunnableMethod(mDecoder, &GMPVideoDecoderProxy::Close), NS_DISPATCH_SYNC); mDecoder = nullptr; mHost = nullptr; }
void nsFileCopyEvent::DoCopy() { // We'll copy in chunks this large by default. This size affects how // frequently we'll check for interrupts. const int32_t chunk = nsIOService::gDefaultSegmentSize * nsIOService::gDefaultSegmentCount; nsresult rv = NS_OK; int64_t len = mLen, progress = 0; while (len) { // If we've been interrupted, then stop copying. rv = mInterruptStatus; if (NS_FAILED(rv)) break; int32_t num = std::min((int32_t) len, chunk); uint32_t result; rv = mSource->ReadSegments(NS_CopySegmentToStream, mDest, num, &result); if (NS_FAILED(rv)) break; if (result != (uint32_t) num) { rv = NS_ERROR_FILE_DISK_FULL; // stopped prematurely (out of disk space) break; } // Dispatch progress notification if (mSink) { progress += num; mSink->OnTransportStatus(nullptr, NS_NET_STATUS_WRITING, progress, mLen); } len -= num; } if (NS_FAILED(rv)) mStatus = rv; // Close the output stream before notifying our callback so that others may // freely "play" with the file. mDest->Close(); // Notify completion if (mCallback) { mCallbackTarget->Dispatch(mCallback, NS_DISPATCH_NORMAL); // Release the callback on the target thread to avoid destroying stuff on // the wrong thread. nsIRunnable *doomed = nullptr; mCallback.swap(doomed); NS_ProxyRelease(mCallbackTarget, doomed); } }
static void PipelineDetachTransport_s(RefPtr<MediaPipeline> pipeline, nsCOMPtr<nsIThread> mainThread) { pipeline->DetachTransport_s(); mainThread->Dispatch( // Make sure we let go of our reference before dispatching // If the dispatch fails, well, we're hosed anyway. WrapRunnableNM(PipelineReleaseRef_m, pipeline.forget()), NS_DISPATCH_NORMAL); }
nsresult Logger::Shutdown() { MOZ_ASSERT(NS_IsMainThread()); nsresult rv = mThread->Dispatch(NewNonOwningRunnableMethod(this, &Logger::CloseFile), NS_DISPATCH_NORMAL); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Dispatch failed"); rv = mThread->Shutdown(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Shutdown failed"); return NS_OK; }
static void EncodedCallback(GMPVideoEncoderCallbackProxy* aCallback, GMPVideoEncodedFrame* aEncodedFrame, nsTArray<uint8_t>* aCodecSpecificInfo, nsCOMPtr<nsIThread> aThread) { aCallback->Encoded(aEncodedFrame, *aCodecSpecificInfo); delete aCodecSpecificInfo; // Ugh. Must destroy the frame on GMPThread. // XXX add locks to the ShmemManager instead? aThread->Dispatch(WrapRunnable(aEncodedFrame, &GMPVideoEncodedFrame::Destroy), NS_DISPATCH_NORMAL); }
nsresult nsInputStreamTee::TeeSegment(const char* aBuf, uint32_t aCount) { if (!mSink) { return NS_OK; // nothing to do } if (mLock) { // asynchronous case NS_ASSERTION(mEventTarget, "mEventTarget is null, mLock is not null."); if (!SinkIsValid()) { return NS_OK; // nothing to do } nsCOMPtr<nsIRunnable> event = new nsInputStreamTeeWriteEvent(aBuf, aCount, mSink, this); LOG(("nsInputStreamTee::TeeSegment [%p] dispatching write %u bytes\n", this, aCount)); return mEventTarget->Dispatch(event, NS_DISPATCH_NORMAL); } else { // synchronous case NS_ASSERTION(!mEventTarget, "mEventTarget is not null, mLock is null."); nsresult rv; uint32_t totalBytesWritten = 0; while (aCount) { uint32_t bytesWritten = 0; rv = mSink->Write(aBuf + totalBytesWritten, aCount, &bytesWritten); if (NS_FAILED(rv)) { // ok, this is not a fatal error... just drop our reference to mSink // and continue on as if nothing happened. NS_WARNING("Write failed (non-fatal)"); // catch possible misuse of the input stream tee NS_ASSERTION(rv != NS_BASE_STREAM_WOULD_BLOCK, "sink must be a blocking stream"); mSink = 0; break; } totalBytesWritten += bytesWritten; NS_ASSERTION(bytesWritten <= aCount, "wrote too much"); aCount -= bytesWritten; } return NS_OK; } }
void Logger::LogQI(HRESULT aResult, IUnknown* aTarget, REFIID aIid, IUnknown* aInterface) { if (FAILED(aResult)) { return; } double elapsed = GetElapsedTime(); nsPrintfCString line("%fus\t0x%0p\tIUnknown::QueryInterface\t([in] ", elapsed, aTarget); WCHAR buf[39] = {0}; if (StringFromGUID2(aIid, buf, mozilla::ArrayLength(buf))) { line.AppendPrintf("%S", buf); } else { line.AppendLiteral("(IID Conversion Failed)"); } line.AppendPrintf(", [out] 0x%p)\t0x%08X\n", aInterface, aResult); MutexAutoLock lock(mMutex); mEntries.AppendElement(line); mThread->Dispatch(NewNonOwningRunnableMethod(this, &Logger::Flush), NS_DISPATCH_NORMAL); }
NS_IMETHODIMP nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport, nsresult status, PRUint64 progress, PRUint64 progressMax) { nsresult rv = NS_OK; nsRefPtr<nsTransportStatusEvent> event; { MutexAutoLock lock(mLock); // try to coalesce events! ;-) if (mLastEvent && (mCoalesceAll || mLastEvent->mStatus == status)) { mLastEvent->mStatus = status; mLastEvent->mProgress = progress; mLastEvent->mProgressMax = progressMax; } else { event = new nsTransportStatusEvent(this, transport, status, progress, progressMax); if (!event) rv = NS_ERROR_OUT_OF_MEMORY; mLastEvent = event; // weak ref } } if (event) { rv = mTarget->Dispatch(event, NS_DISPATCH_NORMAL); if (NS_FAILED(rv)) { NS_WARNING("unable to post transport status event"); MutexAutoLock lock(mLock); // cleanup.. don't reference anymore! mLastEvent = nsnull; } } return rv; }
void Logger::LogEvent(ICallFrame* aCallFrame, IUnknown* aTargetInterface) { // (1) Gather info about the call double elapsed = GetElapsedTime(); CALLFRAMEINFO callInfo; HRESULT hr = aCallFrame->GetInfo(&callInfo); if (FAILED(hr)) { return; } PWSTR interfaceName = nullptr; PWSTR methodName = nullptr; hr = aCallFrame->GetNames(&interfaceName, &methodName); if (FAILED(hr)) { return; } // (2) Serialize the call nsPrintfCString line("%fus\t0x%p\t%S::%S\t(", elapsed, aTargetInterface, interfaceName, methodName); CoTaskMemFree(interfaceName); interfaceName = nullptr; CoTaskMemFree(methodName); methodName = nullptr; // Check for supplemental array data const ArrayData* arrayData = FindArrayData(callInfo.iid, callInfo.iMethod); for (ULONG paramIndex = 0; paramIndex < callInfo.cParams; ++paramIndex) { CALLFRAMEPARAMINFO paramInfo; hr = aCallFrame->GetParamInfo(paramIndex, ¶mInfo); if (SUCCEEDED(hr)) { line.AppendLiteral("["); if (paramInfo.fIn) { line.AppendLiteral("in"); } if (paramInfo.fOut) { line.AppendLiteral("out"); } line.AppendLiteral("] "); } VARIANT paramValue; hr = aCallFrame->GetParam(paramIndex, ¶mValue); if (SUCCEEDED(hr)) { if (arrayData && paramIndex == arrayData->mArrayParamIndex) { VARIANT lengthParam; hr = aCallFrame->GetParam(arrayData->mLengthParamIndex, &lengthParam); if (SUCCEEDED(hr)) { line.AppendLiteral("{ "); for (LONG i = 0; i < *lengthParam.plVal; ++i) { VariantToString(paramValue, line, i); if (i < *lengthParam.plVal - 1) { line.AppendLiteral(", "); } } line.AppendLiteral(" }"); } else { line.AppendPrintf("(GetParam failed with HRESULT 0x%08X)", hr); } } else { VariantToString(paramValue, line); } } else { line.AppendPrintf("(GetParam failed with HRESULT 0x%08X)", hr); } if (paramIndex < callInfo.cParams - 1) { line.AppendLiteral(", "); } } line.AppendLiteral(")\t"); HRESULT callResult = aCallFrame->GetReturnValue(); line.AppendPrintf("0x%08X\n", callResult); // (3) Enqueue event for logging MutexAutoLock lock(mMutex); mEntries.AppendElement(line); mThread->Dispatch(NewNonOwningRunnableMethod(this, &Logger::Flush), NS_DISPATCH_NORMAL); }
NS_IMETHODIMP ParentRunnable::Run() { nsresult rv; // All success/failure paths must eventually call Finish() to avoid leaving // the parser hanging. switch (mState) { case eInitial: { MOZ_ASSERT(NS_IsMainThread()); rv = InitOnMainThread(); if (NS_FAILED(rv)) { FailOnNonOwningThread(); return NS_OK; } mState = eWaitingToFinishInit; MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL)); return NS_OK; } case eWaitingToFinishInit: { AssertIsOnOwningThread(); if (QuotaManager::IsShuttingDown()) { Fail(); return NS_OK; } if (QuotaManager::Get()) { OpenDirectory(); return NS_OK; } mState = eWaitingToOpenDirectory; QuotaManager::GetOrCreate(this); return NS_OK; } case eWaitingToOpenDirectory: { AssertIsOnOwningThread(); if (NS_WARN_IF(!QuotaManager::Get())) { Fail(); return NS_OK; } OpenDirectory(); return NS_OK; } case eReadyToReadMetadata: { AssertIsOnIOThread(); rv = ReadMetadata(); if (NS_FAILED(rv)) { FailOnNonOwningThread(); return NS_OK; } if (mOpenMode == eOpenForRead) { mState = eSendingMetadataForRead; MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL)); return NS_OK; } rv = OpenCacheFileForWrite(); if (NS_FAILED(rv)) { FailOnNonOwningThread(); return NS_OK; } mState = eSendingCacheFile; MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL)); return NS_OK; } case eSendingMetadataForRead: { AssertIsOnOwningThread(); MOZ_ASSERT(mOpenMode == eOpenForRead); mState = eWaitingToOpenCacheFileForRead; // Metadata is now open. if (!SendOnOpenMetadataForRead(mMetadata)) { Fail(); return NS_OK; } return NS_OK; } case eReadyToOpenCacheFileForRead: { AssertIsOnIOThread(); MOZ_ASSERT(mOpenMode == eOpenForRead); rv = OpenCacheFileForRead(); if (NS_FAILED(rv)) { FailOnNonOwningThread(); return NS_OK; } mState = eSendingCacheFile; MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL)); return NS_OK; } case eSendingCacheFile: { AssertIsOnOwningThread(); mState = eOpened; // The entry is now open. MOZ_ASSERT(!mOpened); mOpened = true; FileDescriptor::PlatformHandleType handle = FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFileDesc)); if (!SendOnOpenCacheFile(mFileSize, FileDescriptor(handle))) { Fail(); return NS_OK; } return NS_OK; } case eFailing: { AssertIsOnOwningThread(); Fail(); return NS_OK; } case eWaitingToOpenMetadata: case eWaitingToOpenCacheFileForRead: case eOpened: case eFinished: { MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Shouldn't Run() in this state"); } } MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Corrupt state"); return NS_OK; }
/* * CallStateChanged will be called whenever call status is changed, and it * also means we need to notify HS about the change. For more information, * please refer to 4.13 ~ 4.15 in Bluetooth hands-free profile 1.6. */ void BluetoothHfpManager::CallStateChanged(int aCallIndex, int aCallState, const char* aNumber, bool aIsActive) { nsRefPtr<nsRunnable> sendRingTask; switch (aCallState) { case nsIRadioInterfaceLayer::CALL_STATE_INCOMING: // Send "CallSetup = 1" SendLine("+CIEV: 5,1"); // Start sending RING indicator to HF sStopSendingRingFlag = false; sendRingTask = new SendRingIndicatorTask(); if (NS_FAILED(sHfpCommandThread->Dispatch(sendRingTask, NS_DISPATCH_NORMAL))) { NS_WARNING("Cannot dispatch ring task!"); return; }; break; case nsIRadioInterfaceLayer::CALL_STATE_DIALING: // Send "CallSetup = 2" SendLine("+CIEV: 5,2"); break; case nsIRadioInterfaceLayer::CALL_STATE_ALERTING: // Send "CallSetup = 3" if (mCurrentCallIndex == nsIRadioInterfaceLayer::CALL_STATE_DIALING) { SendLine("+CIEV: 5,3"); } else { #ifdef DEBUG NS_WARNING("Not handling state changed"); #endif } break; case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED: switch (mCurrentCallState) { case nsIRadioInterfaceLayer::CALL_STATE_INCOMING: sStopSendingRingFlag = true; // Continue executing, no break case nsIRadioInterfaceLayer::CALL_STATE_DIALING: // Send "Call = 1, CallSetup = 0" SendLine("+CIEV: 4,1"); SendLine("+CIEV: 5,0"); break; default: #ifdef DEBUG NS_WARNING("Not handling state changed"); #endif break; } break; case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED: switch (mCurrentCallState) { case nsIRadioInterfaceLayer::CALL_STATE_INCOMING: sStopSendingRingFlag = true; // Continue executing, no break case nsIRadioInterfaceLayer::CALL_STATE_DIALING: case nsIRadioInterfaceLayer::CALL_STATE_ALERTING: // Send "CallSetup = 0" SendLine("+CIEV: 5,0"); break; case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED: // Send "Call = 0" SendLine("+CIEV: 4,0"); break; default: #ifdef DEBUG NS_WARNING("Not handling state changed"); #endif break; } break; default: #ifdef DEBUG NS_WARNING("Not handling state changed"); #endif break; } mCurrentCallIndex = aCallIndex; mCurrentCallState = aCallState; }