michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MediaBufferDecoder_h_ michael@0: #define MediaBufferDecoder_h_ michael@0: michael@0: #include "nsWrapperCache.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsIThreadPool.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "mozilla/dom/TypedArray.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace dom { michael@0: class AudioBuffer; michael@0: class AudioContext; michael@0: class DecodeErrorCallback; michael@0: class DecodeSuccessCallback; michael@0: } michael@0: michael@0: struct WebAudioDecodeJob MOZ_FINAL michael@0: { michael@0: // You may omit both the success and failure callback, or you must pass both. michael@0: // The callbacks are only necessary for asynchronous operation. michael@0: WebAudioDecodeJob(const nsACString& aContentType, michael@0: dom::AudioContext* aContext, michael@0: dom::DecodeSuccessCallback* aSuccessCallback = nullptr, michael@0: dom::DecodeErrorCallback* aFailureCallback = nullptr); michael@0: ~WebAudioDecodeJob(); michael@0: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebAudioDecodeJob) michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebAudioDecodeJob) michael@0: michael@0: enum ErrorCode { michael@0: NoError, michael@0: UnknownContent, michael@0: UnknownError, michael@0: InvalidContent, michael@0: NoAudio michael@0: }; michael@0: michael@0: typedef void (WebAudioDecodeJob::*ResultFn)(ErrorCode); michael@0: typedef nsAutoArrayPtr ChannelBuffer; michael@0: michael@0: void OnSuccess(ErrorCode /* ignored */); michael@0: void OnFailure(ErrorCode aErrorCode); michael@0: michael@0: bool AllocateBuffer(); michael@0: michael@0: size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: nsCString mContentType; michael@0: uint32_t mWriteIndex; michael@0: nsRefPtr mContext; michael@0: nsRefPtr mSuccessCallback; michael@0: nsRefPtr mFailureCallback; // can be null michael@0: nsRefPtr mOutput; michael@0: FallibleTArray mChannelBuffers; michael@0: }; michael@0: michael@0: /** michael@0: * This class is used to decode media buffers on a dedicated threadpool. michael@0: * michael@0: * This class manages the resources that it uses internally (such as the michael@0: * thread-pool) and provides a clean external interface. michael@0: */ michael@0: class MediaBufferDecoder michael@0: { michael@0: public: michael@0: void AsyncDecodeMedia(const char* aContentType, uint8_t* aBuffer, michael@0: uint32_t aLength, WebAudioDecodeJob& aDecodeJob); michael@0: michael@0: ~MediaBufferDecoder() { Shutdown(); } michael@0: void Shutdown(); michael@0: michael@0: size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: private: michael@0: bool EnsureThreadPoolInitialized(); michael@0: michael@0: private: michael@0: nsCOMPtr mThreadPool; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif michael@0: