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.

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

mercurial