bool DataBlock::DecodeFromString(const std::string &str) { if (compression_ != NULL) { std::string uncompressed; if (!compression_->Uncompress(str.c_str(), str.size(), &uncompressed)) { LOG(ERROR)<< "uncompress failed!"; return false; } return DecodeInternal(uncompressed); } return DecodeInternal(str); }
NS_IMETHODIMP nsJSON::LegacyDecode(const nsAString& json, JSContext* cx, JS::Value* aRetval) { const PRUnichar *data; uint32_t len = NS_StringGetData(json, &data); nsCOMPtr<nsIInputStream> stream; nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), (const char*) data, len * sizeof(PRUnichar), NS_ASSIGNMENT_DEPEND); NS_ENSURE_SUCCESS(rv, rv); return DecodeInternal(cx, stream, len, false, aRetval, LEGACY); }
NS_IMETHODIMP nsJSON::Decode(const nsAString& json) { const PRUnichar *data; PRUint32 len = NS_StringGetData(json, &data); nsCOMPtr<nsIInputStream> stream; nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), (const char*) data, len * sizeof(PRUnichar), NS_ASSIGNMENT_DEPEND); NS_ENSURE_SUCCESS(rv, rv); return DecodeInternal(stream, len, PR_FALSE); }
NS_IMETHODIMP nsJSON::Decode(const nsAString& json, JSContext* cx, JS::Value* aRetval) { nsresult rv = WarnDeprecatedMethod(DecodeWarning); if (NS_FAILED(rv)) return rv; const PRUnichar *data; uint32_t len = NS_StringGetData(json, &data); nsCOMPtr<nsIInputStream> stream; rv = NS_NewByteInputStream(getter_AddRefs(stream), reinterpret_cast<const char*>(data), len * sizeof(PRUnichar), NS_ASSIGNMENT_DEPEND); NS_ENSURE_SUCCESS(rv, rv); return DecodeInternal(cx, stream, len, false, aRetval); }
DWORD CDecodeThread::ThreadProc() { HRESULT hr; DWORD cmd; BOOL bEOS = FALSE; BOOL bReinit = FALSE; SetThreadName(-1, "LAVVideo Decode Thread"); HANDLE hWaitEvents[2] = { GetRequestHandle(), m_evInput }; while(1) { if (!bEOS && !bReinit) { // Wait for either an input sample, or an request WaitForMultipleObjects(2, hWaitEvents, FALSE, INFINITE); } if (CheckRequest(&cmd)) { switch (cmd) { case CMD_CREATE_DECODER: { CAutoLock lock(&m_ThreadCritSec); hr = CreateDecoderInternal(m_ThreadCallContext.pmt, m_ThreadCallContext.codec); Reply(hr); m_ThreadCallContext.pmt = nullptr; } break; case CMD_CLOSE_DECODER: { ClearQueues(); SAFE_DELETE(m_pDecoder); Reply(S_OK); } break; case CMD_FLUSH: { ClearQueues(); m_pDecoder->Flush(); Reply(S_OK); } break; case CMD_EOS: { bEOS = TRUE; m_evEOSDone.Reset(); Reply(S_OK); } break; case CMD_EXIT: { Reply(S_OK); return 0; } break; case CMD_INIT_ALLOCATOR: { CAutoLock lock(&m_ThreadCritSec); hr = m_pDecoder->InitAllocator(m_ThreadCallContext.allocator); Reply(hr); m_ThreadCallContext.allocator = nullptr; } break; case CMD_POST_CONNECT: { CAutoLock lock(&m_ThreadCritSec); hr = PostConnectInternal(m_ThreadCallContext.pin); Reply(hr); m_ThreadCallContext.pin = nullptr; } break; case CMD_REINIT: { CMediaType &mt = m_pLAVVideo->GetInputMediaType(); CreateDecoderInternal(&mt, m_Codec); m_TempSample[1] = m_NextSample; m_NextSample = m_FailedSample; m_FailedSample = nullptr; bReinit = TRUE; m_evEOSDone.Reset(); Reply(S_OK); m_bDecoderNeedsReInit = FALSE; } break; default: ASSERT(0); } } if (m_bDecoderNeedsReInit) { m_evInput.Reset(); continue; } if (bReinit && !m_NextSample) { if (m_TempSample[0]) { m_NextSample = m_TempSample[0]; m_TempSample[0] = nullptr; } else if (m_TempSample[1]) { m_NextSample = m_TempSample[1]; m_TempSample[1] = nullptr; } else { bReinit = FALSE; m_evEOSDone.Set(); m_evSample.Set(); continue; } } IMediaSample *pSample = GetSample(); if (!pSample) { // Process the EOS now that the sample queue is empty if (bEOS) { bEOS = FALSE; m_pDecoder->EndOfStream(); m_evEOSDone.Set(); m_evSample.Set(); } continue; } DecodeInternal(pSample); // Release the sample SafeRelease(&pSample); // Indicates we're done decoding this sample m_evDecodeDone.Set(); // Set the Sample Event to unblock any waiting threads m_evSample.Set(); } return 0; }
NS_IMETHODIMP nsJSON::LegacyDecodeFromStream(nsIInputStream *aStream, int32_t aContentLength, JSContext* cx, JS::Value* aRetval) { return DecodeInternal(cx, aStream, aContentLength, true, aRetval, LEGACY); }
NS_IMETHODIMP nsJSON::DecodeFromStream(nsIInputStream *aStream, PRInt32 aContentLength, JSContext* cx, JS::Value* aRetval) { return DecodeInternal(cx, aStream, aContentLength, true, aRetval); }
NS_IMETHODIMP nsJSON::DecodeFromStream(nsIInputStream *aStream, PRInt32 aContentLength) { return DecodeInternal(aStream, aContentLength, PR_TRUE); }