2014-07-25 03:30:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_AppleATDecoder_h
|
|
|
|
#define mozilla_AppleATDecoder_h
|
|
|
|
|
|
|
|
#include <AudioToolbox/AudioToolbox.h>
|
|
|
|
#include "PlatformDecoderModule.h"
|
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2014-11-28 13:13:18 +03:00
|
|
|
#include "mozilla/Vector.h"
|
2014-07-25 03:30:00 +04:00
|
|
|
#include "nsIThread.h"
|
2016-04-05 01:24:16 +03:00
|
|
|
#include "AudioConverter.h"
|
2014-07-25 03:30:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-05-12 11:02:56 +03:00
|
|
|
class TaskQueue;
|
2014-07-25 03:30:00 +04:00
|
|
|
class MediaDataDecoderCallback;
|
|
|
|
|
|
|
|
class AppleATDecoder : public MediaDataDecoder {
|
|
|
|
public:
|
2015-04-14 08:16:32 +03:00
|
|
|
AppleATDecoder(const AudioInfo& aConfig,
|
2016-05-12 11:02:56 +03:00
|
|
|
TaskQueue* aTaskQueue,
|
2014-07-25 03:30:00 +04:00
|
|
|
MediaDataDecoderCallback* aCallback);
|
2014-12-23 06:39:22 +03:00
|
|
|
virtual ~AppleATDecoder();
|
2014-07-25 03:30:00 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InitPromise> Init() override;
|
2015-09-21 07:35:18 +03:00
|
|
|
nsresult Input(MediaRawData* aSample) override;
|
|
|
|
nsresult Flush() override;
|
|
|
|
nsresult Drain() override;
|
|
|
|
nsresult Shutdown() override;
|
2014-07-25 03:30:00 +04:00
|
|
|
|
2016-01-22 04:29:51 +03:00
|
|
|
const char* GetDescriptionName() const override
|
|
|
|
{
|
|
|
|
return "apple CoreMedia decoder";
|
|
|
|
}
|
|
|
|
|
2014-07-25 03:30:00 +04:00
|
|
|
// Callbacks also need access to the config.
|
2015-04-14 08:16:32 +03:00
|
|
|
const AudioInfo& mConfig;
|
2014-07-25 03:30:00 +04:00
|
|
|
|
2014-11-28 13:13:18 +03:00
|
|
|
// Use to extract magic cookie for HE-AAC detection.
|
2014-12-23 06:36:09 +03:00
|
|
|
nsTArray<uint8_t> mMagicCookie;
|
2014-11-28 13:13:18 +03:00
|
|
|
// Will be set to true should an error occurred while attempting to retrieve
|
|
|
|
// the magic cookie property.
|
|
|
|
bool mFileStreamError;
|
|
|
|
|
2014-07-25 03:30:00 +04:00
|
|
|
private:
|
2016-05-12 11:02:56 +03:00
|
|
|
const RefPtr<TaskQueue> mTaskQueue;
|
2014-07-25 03:30:00 +04:00
|
|
|
MediaDataDecoderCallback* mCallback;
|
|
|
|
AudioConverterRef mConverter;
|
2014-08-11 09:27:00 +04:00
|
|
|
AudioStreamBasicDescription mOutputFormat;
|
2014-11-19 17:03:30 +03:00
|
|
|
UInt32 mFormatID;
|
2014-11-28 13:13:18 +03:00
|
|
|
AudioFileStreamID mStream;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<MediaRawData>> mQueuedSamples;
|
2016-04-05 01:24:16 +03:00
|
|
|
UniquePtr<AudioConfig::ChannelLayout> mChannelLayout;
|
|
|
|
UniquePtr<AudioConverter> mAudioConverter;
|
2016-05-12 11:02:50 +03:00
|
|
|
Atomic<bool> mIsFlushing;
|
2014-07-25 03:30:00 +04:00
|
|
|
|
2016-05-12 11:02:50 +03:00
|
|
|
void ProcessFlush();
|
2015-04-09 14:14:55 +03:00
|
|
|
void SubmitSample(MediaRawData* aSample);
|
|
|
|
nsresult DecodeSample(MediaRawData* aSample);
|
2014-11-28 13:13:18 +03:00
|
|
|
nsresult GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
|
2014-12-23 06:36:09 +03:00
|
|
|
const nsTArray<uint8_t>& aExtraData);
|
2014-11-28 13:13:18 +03:00
|
|
|
// Setup AudioConverter once all information required has been gathered.
|
|
|
|
// Will return NS_ERROR_NOT_INITIALIZED if more data is required.
|
2015-04-09 14:14:55 +03:00
|
|
|
nsresult SetupDecoder(MediaRawData* aSample);
|
|
|
|
nsresult GetImplicitAACMagicCookie(const MediaRawData* aSample);
|
2016-04-05 01:24:16 +03:00
|
|
|
nsresult SetupChannelLayout();
|
2014-07-25 03:30:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_AppleATDecoder_h
|