tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaBufferDecoder.h (2148B)


      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/. */
      6 
      7 #ifndef MediaBufferDecoder_h_
      8 #define MediaBufferDecoder_h_
      9 
     10 #include "AudioSegment.h"
     11 #include "mozilla/Attributes.h"
     12 #include "mozilla/MemoryReporting.h"
     13 #include "mozilla/dom/TypedArray.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsString.h"
     16 #include "nsTArray.h"
     17 #include "nsWrapperCache.h"
     18 
     19 namespace mozilla {
     20 
     21 class ThreadSharedFloatArrayBufferList;
     22 
     23 namespace dom {
     24 class AudioBuffer;
     25 class AudioContext;
     26 class DecodeErrorCallback;
     27 class DecodeSuccessCallback;
     28 class Promise;
     29 }  // namespace dom
     30 
     31 struct WebAudioDecodeJob final {
     32  // You may omit both the success and failure callback, or you must pass both.
     33  // The callbacks are only necessary for asynchronous operation.
     34  WebAudioDecodeJob(dom::AudioContext* aContext, dom::Promise* aPromise,
     35                    dom::DecodeSuccessCallback* aSuccessCallback = nullptr,
     36                    dom::DecodeErrorCallback* aFailureCallback = nullptr);
     37  ~WebAudioDecodeJob();
     38 
     39  enum ErrorCode {
     40    NoError,
     41    UnknownContent,
     42    UnknownError,
     43    InvalidContent,
     44    NoAudio
     45  };
     46 
     47  typedef void (WebAudioDecodeJob::*ResultFn)(ErrorCode);
     48 
     49  MOZ_CAN_RUN_SCRIPT void OnSuccess(ErrorCode /* ignored */);
     50  MOZ_CAN_RUN_SCRIPT void OnFailure(ErrorCode aErrorCode);
     51 
     52  bool AllocateBuffer();
     53 
     54  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
     55  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
     56 
     57  AudioChunk mBuffer;
     58  RefPtr<dom::AudioContext> mContext;
     59  RefPtr<dom::Promise> mPromise;
     60  RefPtr<dom::DecodeSuccessCallback> mSuccessCallback;
     61  RefPtr<dom::DecodeErrorCallback> mFailureCallback;  // can be null
     62  RefPtr<dom::AudioBuffer> mOutput;
     63 };
     64 
     65 void AsyncDecodeWebAudio(const char* aContentType, uint8_t* aBuffer,
     66                         uint32_t aLength, WebAudioDecodeJob& aDecodeJob);
     67 
     68 }  // namespace mozilla
     69 
     70 #endif