content/media/webaudio/MediaBufferDecoder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef MediaBufferDecoder_h_
michael@0 8 #define MediaBufferDecoder_h_
michael@0 9
michael@0 10 #include "nsWrapperCache.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "nsAutoPtr.h"
michael@0 13 #include "nsIThreadPool.h"
michael@0 14 #include "nsString.h"
michael@0 15 #include "nsTArray.h"
michael@0 16 #include "mozilla/dom/TypedArray.h"
michael@0 17 #include "mozilla/MemoryReporting.h"
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20
michael@0 21 namespace dom {
michael@0 22 class AudioBuffer;
michael@0 23 class AudioContext;
michael@0 24 class DecodeErrorCallback;
michael@0 25 class DecodeSuccessCallback;
michael@0 26 }
michael@0 27
michael@0 28 struct WebAudioDecodeJob MOZ_FINAL
michael@0 29 {
michael@0 30 // You may omit both the success and failure callback, or you must pass both.
michael@0 31 // The callbacks are only necessary for asynchronous operation.
michael@0 32 WebAudioDecodeJob(const nsACString& aContentType,
michael@0 33 dom::AudioContext* aContext,
michael@0 34 dom::DecodeSuccessCallback* aSuccessCallback = nullptr,
michael@0 35 dom::DecodeErrorCallback* aFailureCallback = nullptr);
michael@0 36 ~WebAudioDecodeJob();
michael@0 37
michael@0 38 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebAudioDecodeJob)
michael@0 39 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebAudioDecodeJob)
michael@0 40
michael@0 41 enum ErrorCode {
michael@0 42 NoError,
michael@0 43 UnknownContent,
michael@0 44 UnknownError,
michael@0 45 InvalidContent,
michael@0 46 NoAudio
michael@0 47 };
michael@0 48
michael@0 49 typedef void (WebAudioDecodeJob::*ResultFn)(ErrorCode);
michael@0 50 typedef nsAutoArrayPtr<float> ChannelBuffer;
michael@0 51
michael@0 52 void OnSuccess(ErrorCode /* ignored */);
michael@0 53 void OnFailure(ErrorCode aErrorCode);
michael@0 54
michael@0 55 bool AllocateBuffer();
michael@0 56
michael@0 57 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 58
michael@0 59 nsCString mContentType;
michael@0 60 uint32_t mWriteIndex;
michael@0 61 nsRefPtr<dom::AudioContext> mContext;
michael@0 62 nsRefPtr<dom::DecodeSuccessCallback> mSuccessCallback;
michael@0 63 nsRefPtr<dom::DecodeErrorCallback> mFailureCallback; // can be null
michael@0 64 nsRefPtr<dom::AudioBuffer> mOutput;
michael@0 65 FallibleTArray<ChannelBuffer> mChannelBuffers;
michael@0 66 };
michael@0 67
michael@0 68 /**
michael@0 69 * This class is used to decode media buffers on a dedicated threadpool.
michael@0 70 *
michael@0 71 * This class manages the resources that it uses internally (such as the
michael@0 72 * thread-pool) and provides a clean external interface.
michael@0 73 */
michael@0 74 class MediaBufferDecoder
michael@0 75 {
michael@0 76 public:
michael@0 77 void AsyncDecodeMedia(const char* aContentType, uint8_t* aBuffer,
michael@0 78 uint32_t aLength, WebAudioDecodeJob& aDecodeJob);
michael@0 79
michael@0 80 ~MediaBufferDecoder() { Shutdown(); }
michael@0 81 void Shutdown();
michael@0 82
michael@0 83 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
michael@0 84 {
michael@0 85 return 0;
michael@0 86 }
michael@0 87
michael@0 88 private:
michael@0 89 bool EnsureThreadPoolInitialized();
michael@0 90
michael@0 91 private:
michael@0 92 nsCOMPtr<nsIThreadPool> mThreadPool;
michael@0 93 };
michael@0 94
michael@0 95 }
michael@0 96
michael@0 97 #endif
michael@0 98

mercurial