tor-browser

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

AppleATDecoder.h (2644B)


      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 mozilla_AppleATDecoder_h
      8 #define mozilla_AppleATDecoder_h
      9 
     10 #include <AudioToolbox/AudioToolbox.h>
     11 
     12 #include "AudioConverter.h"
     13 #include "PlatformDecoderModule.h"
     14 
     15 namespace mozilla {
     16 
     17 class TaskQueue;
     18 
     19 DDLoggedTypeDeclNameAndBase(AppleATDecoder, MediaDataDecoder);
     20 
     21 class AppleATDecoder final : public MediaDataDecoder,
     22                             public DecoderDoctorLifeLogger<AppleATDecoder> {
     23 public:
     24  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AppleATDecoder, final);
     25 
     26  explicit AppleATDecoder(const AudioInfo& aConfig);
     27 
     28  RefPtr<InitPromise> Init() override;
     29  RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
     30  RefPtr<DecodePromise> Drain() override;
     31  RefPtr<FlushPromise> Flush() override;
     32  RefPtr<ShutdownPromise> Shutdown() override;
     33 
     34  nsCString GetDescriptionName() const override {
     35    return "apple coremedia decoder"_ns;
     36  }
     37 
     38  nsCString GetCodecName() const override;
     39 
     40  // Callbacks also need access to the config.
     41  AudioInfo mConfig;
     42 
     43  // Use to extract magic cookie for HE-AAC detection.
     44  nsTArray<uint8_t> mMagicCookie;
     45  // Will be set to true should an error occurred while attempting to retrieve
     46  // the magic cookie property.
     47  bool mFileStreamError;
     48 
     49  nsCOMPtr<nsISerialEventTarget> mThread;
     50 
     51 private:
     52  ~AppleATDecoder();
     53 
     54  AudioConverterRef mConverter;
     55  AudioStreamBasicDescription mOutputFormat;
     56  UInt32 mFormatID;
     57  AudioFileStreamID mStream;
     58  nsTArray<RefPtr<MediaRawData>> mQueuedSamples;
     59  UniquePtr<AudioConfig::ChannelLayout> mChannelLayout;
     60  UniquePtr<AudioConverter> mAudioConverter;
     61  DecodedData mDecodedSamples;
     62 
     63  void ProcessShutdown();
     64  MediaResult DecodeSample(MediaRawData* aSample);
     65  MediaResult GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
     66                                       const nsTArray<uint8_t>& aExtraData);
     67  // Setup AudioConverter once all information required has been gathered.
     68  // Will return NS_ERROR_NOT_INITIALIZED if more data is required.
     69  MediaResult SetupDecoder(MediaRawData* aSample);
     70  nsresult GetImplicitAACMagicCookie(MediaRawData* aSample);
     71  nsresult SetupChannelLayout();
     72  uint32_t mParsedFramesForAACMagicCookie;
     73  uint32_t mEncoderDelay = 0;
     74  uint64_t mTotalMediaFrames = 0;
     75  bool mIsADTS = false;
     76  bool mErrored;
     77 };
     78 
     79 }  // namespace mozilla
     80 
     81 #endif  // mozilla_AppleATDecoder_h