mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
e1776c67f8
- Bug 1199885 - Part 2: Add AsyncDragMetrics. r=kats (220a4f445e)
- Bug 1149482 - Localize the 'none' string for APZ in about:support. r=dvander (3e0128f62e)
- Bug 1199885 - Part 3: Add 'apz.drag.enabled' preference for async scrollbars. r=kats (5133061d3f)
- Bug 1199885 - Part 4: Let the hit testing tree know about the scroll thumb. r=kats (26a9a69443)
- Bug 1199885 - Part 5: Make mRootLayerTreeID const to prove that there's no data races. r=kats (88e2eb80f1)
- Bug 1199885 - Part 8: Add FindScrollNode to locate the scrollbar thumb. r=kats (a545ec9569)
- Bug 1199885 - Part 9: Let APZC handle the drag events. r=kats (4cc0f88153)
- Bug 1199885 - Part 9.5: Make the mouse events APZC aware. r=kats (69bd4caf94)
- Bug 1199885 - Part 10: Add APZTeeManager API to start an async scroll. r=kats (e212ee2750)
- Bug 1199885 - Part 12: Add StartScrollbarDrag IPC message. r=kats (705af3b233)
- Bug 1199885 - Part 13: Let nsSliderFrame trigger async scrolling via StartScrollbarDrag. r=kats (d31b5a790d)
- put in gstreamer as of 2015-10-05 Bug 1146482 (7cca45858c)
- pointer style (f8041af438)
- Bug 1197097 - Don't use a context-wide cycle-detection mechanism for detecting cycles during JSON.stringify. This prevents nested (yet separate) JSON.stringify, and it causes that algorithm to be affected by specification-unrelated operations like toSource. r=jonco (09652471c1)
- align to ugly grammaer of 1114782 (c760693693)
- remove space (7158a0c2bf)
- align to FF/TFF (27138a55bb)
- Bug 1205887 - Verify that MOZILLA_VERSION was set correctly, r=glandium (2269e8f31b)
- Bug 1205012 - Allow rust source code in SpiderMonkey; r=mshal (9ebca9ed28)
- Bug 1197281 - Use MOZ_FIND_WINSDK_VERSION for MOZ_WINSDK_MAXVER on mingw. r=glandium (2910b2160e)
- Bug 1207893 - Refactor how build backend execution is summarized. r=gps (56d8fecbc2)
- Bug 1207893 - Allow to create multiple build backends at once. r=gps (d8cba87d2b)
- Bug 1207897 - Add a configure option to build multiple build backends. r=gps (f9c7851d02)
- Bug 1188555 - part 1 - remove write-only configure.in variable NO_LD_ARCHIVE_FLAGS; r=mshal (461958b100)
- Bug 1188555 - part 2 - remove write-only configure.in variables MKSHLIB_{UN,}FORCE_ALL; r=mshal (1813210dda)
- Bug 1207882 - Ensure chrome manifests are created in a directory that exists when processing jar manifests. r=gps (59165a64cb)
- Bug 1204712 - Handle wildcards properly for localized content in jar manifests. r=gps (54dfb632c7)
- Bug 1188551: treat assertion failures as bad mozconfig; r=mshal (e307769de7)
- Bug 1181040 - Set ${var}_IS_SET variables for mk_add_options-defined variables. r=gps (19f169556b)
- Bug 1193015 - Require MOZ_GLX_USE_SURFACE_SHARING to enable WebGL surface sharing on GLX. r=jgilbert (9aa4fa8f41)
- Bug 1211324 (part 1) - Remove BILINEAR and GAUSSIAN filter constants. (3d9290ef02)
- Bug 1211324 (part 2) - Make gfx::FILTER::GOOD convert to GraphicsFilter::FILTER_GOOD. r=mattwoodrow. (16e7607c70)
- Bug 1208365 (part 1) - Remove unused EXTEND_PAD_EDGE. r=Bas. (10920e2bb6)
- Bug 1208365 (part 2) - Remove gfxPattern::Extend(). r=bas. (3703b9748a)
- Bug 1208365 (part 3) - Change gfxPattern::mExtend from a GraphicsExtend to a gfx::ExtendMode. r=bas. (b105d06e91)
- Bug 1208365 (part 4) - Remove gfxPattern::GraphicsExtend. r=bas. (7a16d48995)
- Bug 1211324 (part 3) - Remove GraphicsFilter::FILTER_FAST and replace it with FILTER_BEST. r=mattwoodrow. (b5101e049f)
- Bug 1211324 (part 4) - Replace GraphicsFilter constants with gfx::Filter equivalents. r=mattwoodrow. (c19b6b030e)
- Bug 1190117 - Track mLastProducerID and mLastFrameID explicitly in ImageLayerProperties. r=roc (ed9a5c777f)
- Bug 1211324 (part 5) - Remove GraphicsFilter and gfxGraphicsFilter. r=mattwoodrow. (0bd4ce7160)
- Bug 1194954 - Fix -Wunreachable-code warnings in gfx/layers and gfx/thebes. r=BenWa (1a3d68c490)
- Bug 1180509 - Fix judder of icons in Australis doorhanger menu at the end of its scale-in animation. r=roc (9b4df470fa)
- Bug 1206915 - Make paint dumping to a file e10s-friendly. r=mattwoodrow (87d2e12c2b)
- Bug 1206915 - Handle nested PaintFrame() calls correctly during paint dumping. r=mattwoodrow,BenWa (d30f77fbdd)
- Fix max texture size handling in displayport clamping. (bug 1135907 follow-up, r=kats) (a791894332)
- Fix bogus assertion in nsLayoutUtils::SetDisplayPortMargins. (bug 1156409, r=botond, a=philor) (b635b21c34)
- Bug 1169879 - Use only the critical displayport when computing image visibility. r=tn (9ec91c9527)
- Bug 1169881 - Recompute image visibility when display port margins change. r=tn (35a5bd3a51)
- Bug 1197765 - Compare text content inside frame instead of the content node for ruby autohiding. r=dbaron (00cf5b7674)
- Bug 1173580 - Record content descriptions in APZ test data. r=kats (7a72d1ac0a)
- Bug 1178971 - Changed line snapping behaviour depending on even/odd-ness of stroke width. r=mstange (495b32dc23)
- Bug 1208953: [mp3] Don't parse data we've already parsed. r=cpearce (72eed4309f)
- Bug 1137151: Marked destructor of |android::MediaCodecReader| as protected, r=sotaro (0632b34bc5)
- Bug 1205351 - Replace nsBaseHashtable::Enumerate() calls in dom/media/ with iterators r=cpearce (45976c24c0)
- Bug 1133624 - Add lang-specific ruby rules to ua.css. r=dbaron (46788cc220)
- Bug 1133624 - followup add fuzzy maxdiff on CLOSED TREE (1b6b62aded)
- Bug 1180443 - Consider whitespace collapse when calculating intrinsic isize of ruby. r=dbaron (3862184acd)
- Bug 1153764 - Avoid explicitly doing break before when there is ruby span. r=roc (71b4ec7749)
- add gstreamer parts (7e562556be)
- some preferences aligned to FF (b26d0b389c)
- Bug 1166301 - If APZ is enabled, clip fixed background images at the layer level rather than the display item level. r=mattwoodrow (5644e22090)
- Bug 1144990 - Dump display items with class id and name, r=roc (aa2e227e35)
- Bug 1205087 - Remove LayerManager parameter for ShouldFixToViewport. r=roc (00a1f2e36f)
- Bug 1205087 - Make nsSVGIntegrationUtils paint frame continuations manually since combining them meant that our reference frame wasn't an ancestor of all painted frames. r=roc (e40f6b7b81)
- Bug 1195400 - Check ancestor geometry roots when determining scrollability of a layer. r=mattwoodrow (4699b7e935)
- Bug 1205087 - Cache the AnimatedGeometryRoot on DisplayItem. r=roc (06bba311c3)
- Back out the bits of bug 1205087 that cache the AnimatedGeometryRoot on DisplayItem. r=backout (254057a6b6)
- Bug 1203190 - Don't intersect with the visible rect for fixed background images. r=mattwoodrow (1c5a432459)
- Bug 1208438 - Don't allow layers with scrolling clips to occlusion-cull layers behind them. r=mattwoodrow (c3d77a9846)
- Bug 1205630 - Translate a fixed background display item's clip rect correctly when setting it on the layer. r=mstange (49039f0e2d)
- Bug 1205630 - Reftest. r=mstange (a8db59eaee)
- Bug 1105832 - Also dump inactive layer managers when display list dumping is enabled. r=mattwoodrow (564fe5fcbc)
- Bug 1208661 - Move Dump() up from ContentClient to CompositableClient. r=BenWa (37915312b3)
544 lines
17 KiB
C++
544 lines
17 KiB
C++
/* 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/. */
|
|
|
|
#include "AppleMP3Reader.h"
|
|
|
|
#include "nsISeekableStream.h"
|
|
#include "MediaDecoder.h"
|
|
|
|
// Number of bytes we will read and pass to the audio parser in each
|
|
// |DecodeAudioData| call.
|
|
#define AUDIO_READ_BYTES 4096
|
|
|
|
// Maximum number of audio frames we will accept from the audio decoder in one
|
|
// go. Carefully select this to work well with both the mp3 1152 max frames
|
|
// per block and power-of-2 allocation sizes. Since we must pre-allocate the
|
|
// buffer we cannot use AudioCompactor without paying for an additional
|
|
// allocation and copy. Therefore, choosing a value that divides exactly into
|
|
// 1152 is most memory efficient.
|
|
#define MAX_AUDIO_FRAMES 128
|
|
|
|
using namespace mozilla::media;
|
|
|
|
namespace mozilla {
|
|
|
|
extern PRLogModuleInfo* gMediaDecoderLog;
|
|
#define LOGE(...) MOZ_LOG(gMediaDecoderLog, mozilla::LogLevel::Error, (__VA_ARGS__))
|
|
#define LOGW(...) MOZ_LOG(gMediaDecoderLog, mozilla::LogLevel::Warning, (__VA_ARGS__))
|
|
#define LOGD(...) MOZ_LOG(gMediaDecoderLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
|
|
|
#define PROPERTY_ID_FORMAT "%c%c%c%c"
|
|
#define PROPERTY_ID_PRINT(x) ((x) >> 24), \
|
|
((x) >> 16) & 0xff, \
|
|
((x) >> 8) & 0xff, \
|
|
(x) & 0xff
|
|
|
|
AppleMP3Reader::AppleMP3Reader(AbstractMediaDecoder *aDecoder)
|
|
: MediaDecoderReader(aDecoder)
|
|
, mStreamReady(false)
|
|
, mAudioFramesPerCompressedPacket(0)
|
|
, mCurrentAudioFrame(0)
|
|
, mAudioChannels(0)
|
|
, mAudioSampleRate(0)
|
|
, mAudioFileStream(nullptr)
|
|
, mAudioConverter(nullptr)
|
|
, mMP3FrameParser(mDecoder->GetResource()->GetLength())
|
|
, mResource(mDecoder->GetResource())
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread");
|
|
}
|
|
|
|
AppleMP3Reader::~AppleMP3Reader()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread");
|
|
}
|
|
|
|
|
|
/*
|
|
* The Apple audio decoding APIs are very callback-happy. When the parser has
|
|
* some metadata, it will call back to here.
|
|
*/
|
|
static void _AudioMetadataCallback(void *aThis,
|
|
AudioFileStreamID aFileStream,
|
|
AudioFileStreamPropertyID aPropertyID,
|
|
UInt32 *aFlags)
|
|
{
|
|
((AppleMP3Reader*)aThis)->AudioMetadataCallback(aFileStream, aPropertyID,
|
|
aFlags);
|
|
}
|
|
|
|
/*
|
|
* Similar to above, this is called when the parser has enough data to parse
|
|
* one or more samples.
|
|
*/
|
|
static void _AudioSampleCallback(void *aThis,
|
|
UInt32 aNumBytes, UInt32 aNumPackets,
|
|
const void *aData,
|
|
AudioStreamPacketDescription *aPackets)
|
|
{
|
|
((AppleMP3Reader*)aThis)->AudioSampleCallback(aNumBytes, aNumPackets,
|
|
aData, aPackets);
|
|
}
|
|
|
|
|
|
/*
|
|
* If we're not at end of stream, read |aNumBytes| from the media resource,
|
|
* put it in |aData|, and return true.
|
|
* Otherwise, put as much data as is left into |aData|, set |aNumBytes| to the
|
|
* amount of data we have left, and return false.
|
|
*/
|
|
nsresult
|
|
AppleMP3Reader::Read(uint32_t *aNumBytes, char *aData)
|
|
{
|
|
nsresult rv = mResource.Read(aData, *aNumBytes, aNumBytes);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
*aNumBytes = 0;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// XXX Maybe return a better value than NS_ERROR_FAILURE?
|
|
return *aNumBytes ? NS_OK : NS_ERROR_FAILURE;
|
|
}
|
|
|
|
nsresult
|
|
AppleMP3Reader::Init(MediaDecoderReader* aCloneDonor)
|
|
{
|
|
AudioFileTypeID fileType = kAudioFileMP3Type;
|
|
|
|
OSStatus rv = AudioFileStreamOpen(this,
|
|
_AudioMetadataCallback,
|
|
_AudioSampleCallback,
|
|
fileType,
|
|
&mAudioFileStream);
|
|
|
|
if (rv) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
struct PassthroughUserData {
|
|
AppleMP3Reader *mReader;
|
|
UInt32 mNumPackets;
|
|
UInt32 mDataSize;
|
|
const void *mData;
|
|
AudioStreamPacketDescription *mPacketDesc;
|
|
bool mDone;
|
|
};
|
|
|
|
// Error value we pass through the decoder to signal that nothing has gone wrong
|
|
// during decoding, but more data is needed.
|
|
const UInt32 kNeedMoreData = 'MOAR';
|
|
|
|
/*
|
|
* This function is called from |AudioConverterFillComplexBuffer|, which is
|
|
* called from |AudioSampleCallback| below, which in turn is called by
|
|
* |AudioFileStreamParseBytes|, which is called by |DecodeAudioData|.
|
|
*
|
|
* Mercifully, this is all synchronous.
|
|
*
|
|
* This callback is run when the AudioConverter (decoder) wants more MP3 packets
|
|
* to decode.
|
|
*/
|
|
/* static */ OSStatus
|
|
AppleMP3Reader::PassthroughInputDataCallback(AudioConverterRef aAudioConverter,
|
|
UInt32 *aNumDataPackets /* in/out */,
|
|
AudioBufferList *aData /* in/out */,
|
|
AudioStreamPacketDescription **aPacketDesc,
|
|
void *aUserData)
|
|
{
|
|
if (!aPacketDesc) {
|
|
return kAudioFileStreamError_UnspecifiedError;
|
|
}
|
|
|
|
PassthroughUserData *userData = (PassthroughUserData *)aUserData;
|
|
if (userData->mDone) {
|
|
// We make sure this callback is run _once_, with all the data we received
|
|
// from |AudioFileStreamParseBytes|. When we return an error, the decoder
|
|
// simply passes the return value on to the calling method,
|
|
// |AudioSampleCallback|; and flushes all of the audio frames it had
|
|
// buffered. It does not change the decoder's state.
|
|
LOGD("requested too much data; returning\n");
|
|
*aNumDataPackets = 0;
|
|
return kNeedMoreData;
|
|
}
|
|
|
|
userData->mDone = true;
|
|
|
|
LOGD("AudioConverter wants %u packets of audio data\n", *aNumDataPackets);
|
|
|
|
*aNumDataPackets = userData->mNumPackets;
|
|
*aPacketDesc = userData->mPacketDesc;
|
|
|
|
aData->mBuffers[0].mNumberChannels = userData->mReader->mAudioChannels;
|
|
aData->mBuffers[0].mDataByteSize = userData->mDataSize;
|
|
aData->mBuffers[0].mData = const_cast<void *>(userData->mData);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* This callback is called when |AudioFileStreamParseBytes| has enough data to
|
|
* extract one or more MP3 packets.
|
|
*/
|
|
void
|
|
AppleMP3Reader::AudioSampleCallback(UInt32 aNumBytes,
|
|
UInt32 aNumPackets,
|
|
const void *aData,
|
|
AudioStreamPacketDescription *aPackets)
|
|
{
|
|
LOGD("got %u bytes, %u packets\n", aNumBytes, aNumPackets);
|
|
|
|
// 1 frame per packet * num channels * 32-bit float
|
|
uint32_t decodedSize = MAX_AUDIO_FRAMES * mAudioChannels *
|
|
sizeof(AudioDataValue);
|
|
|
|
// descriptions for _decompressed_ audio packets. ignored.
|
|
nsAutoArrayPtr<AudioStreamPacketDescription>
|
|
packets(new AudioStreamPacketDescription[MAX_AUDIO_FRAMES]);
|
|
|
|
// This API insists on having MP3 packets spoon-fed to it from a callback.
|
|
// This structure exists only to pass our state and the result of the parser
|
|
// on to the callback above.
|
|
PassthroughUserData userData = { this, aNumPackets, aNumBytes, aData, aPackets, false };
|
|
|
|
do {
|
|
// Decompressed audio buffer
|
|
nsAutoArrayPtr<uint8_t> decoded(new uint8_t[decodedSize]);
|
|
|
|
AudioBufferList decBuffer;
|
|
decBuffer.mNumberBuffers = 1;
|
|
decBuffer.mBuffers[0].mNumberChannels = mAudioChannels;
|
|
decBuffer.mBuffers[0].mDataByteSize = decodedSize;
|
|
decBuffer.mBuffers[0].mData = decoded.get();
|
|
|
|
// in: the max number of packets we can handle from the decoder.
|
|
// out: the number of packets the decoder is actually returning.
|
|
UInt32 numFrames = MAX_AUDIO_FRAMES;
|
|
|
|
OSStatus rv = AudioConverterFillComplexBuffer(mAudioConverter,
|
|
PassthroughInputDataCallback,
|
|
&userData,
|
|
&numFrames /* in/out */,
|
|
&decBuffer,
|
|
packets.get());
|
|
|
|
if (rv && rv != kNeedMoreData) {
|
|
LOGE("Error decoding audio stream: %x\n", rv);
|
|
break;
|
|
}
|
|
|
|
// If we decoded zero frames then AudiOConverterFillComplexBuffer is out
|
|
// of data to provide. We drained its internal buffer completely on the
|
|
// last pass.
|
|
if (numFrames == 0 && rv == kNeedMoreData) {
|
|
LOGD("FillComplexBuffer out of data exactly\n");
|
|
break;
|
|
}
|
|
|
|
int64_t time = FramesToUsecs(mCurrentAudioFrame, mAudioSampleRate).value();
|
|
int64_t duration = FramesToUsecs(numFrames, mAudioSampleRate).value();
|
|
|
|
LOGD("pushed audio at time %lfs; duration %lfs\n",
|
|
(double)time / USECS_PER_S, (double)duration / USECS_PER_S);
|
|
|
|
AudioData *audio = new AudioData(mResource.Tell(),
|
|
time, duration, numFrames,
|
|
reinterpret_cast<AudioDataValue *>(decoded.forget()),
|
|
mAudioChannels, mAudioSampleRate);
|
|
mAudioQueue.Push(audio);
|
|
|
|
mCurrentAudioFrame += numFrames;
|
|
|
|
if (rv == kNeedMoreData) {
|
|
// No error; we just need more data.
|
|
LOGD("FillComplexBuffer out of data\n");
|
|
break;
|
|
}
|
|
} while (true);
|
|
}
|
|
|
|
bool
|
|
AppleMP3Reader::DecodeAudioData()
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
// Read AUDIO_READ_BYTES if we can
|
|
char bytes[AUDIO_READ_BYTES];
|
|
uint32_t numBytes = AUDIO_READ_BYTES;
|
|
|
|
nsresult readrv = Read(&numBytes, bytes);
|
|
|
|
// This function calls |AudioSampleCallback| above, synchronously, when it
|
|
// finds compressed MP3 frame.
|
|
OSStatus rv = AudioFileStreamParseBytes(mAudioFileStream,
|
|
numBytes,
|
|
bytes,
|
|
0 /* flags */);
|
|
|
|
if (NS_FAILED(readrv)) {
|
|
mAudioQueue.Finish();
|
|
return false;
|
|
}
|
|
|
|
// DataUnavailable just means there wasn't enough data to demux anything.
|
|
// We should have more to push into the demuxer next time we're called.
|
|
if (rv && rv != kAudioFileStreamError_DataUnavailable) {
|
|
LOGE("AudioFileStreamParseBytes returned unknown error %x", rv);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AppleMP3Reader::DecodeVideoFrame(bool &aKeyframeSkip,
|
|
int64_t aTimeThreshold)
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
return false;
|
|
}
|
|
|
|
|
|
bool
|
|
AppleMP3Reader::HasAudio()
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
return mStreamReady;
|
|
}
|
|
|
|
bool
|
|
AppleMP3Reader::HasVideo()
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
AppleMP3Reader::IsMediaSeekable()
|
|
{
|
|
// not used
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Query the MP3 parser for a piece of metadata.
|
|
*/
|
|
static nsresult
|
|
GetProperty(AudioFileStreamID aAudioFileStream,
|
|
AudioFileStreamPropertyID aPropertyID, void *aData)
|
|
{
|
|
UInt32 size;
|
|
Boolean writeable;
|
|
OSStatus rv = AudioFileStreamGetPropertyInfo(aAudioFileStream, aPropertyID,
|
|
&size, &writeable);
|
|
|
|
if (rv) {
|
|
LOGW("Couldn't get property " PROPERTY_ID_FORMAT "\n",
|
|
PROPERTY_ID_PRINT(aPropertyID));
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
rv = AudioFileStreamGetProperty(aAudioFileStream, aPropertyID,
|
|
&size, aData);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
nsresult
|
|
AppleMP3Reader::ReadMetadata(MediaInfo* aInfo,
|
|
MetadataTags** aTags)
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
*aTags = nullptr;
|
|
|
|
/*
|
|
* Feed bytes into the parser until we have all the metadata we need to
|
|
* set up the decoder. When the parser has enough data, it will
|
|
* synchronously call back to |AudioMetadataCallback| below.
|
|
*/
|
|
OSStatus rv;
|
|
nsresult readrv;
|
|
uint32_t offset = 0;
|
|
do {
|
|
char bytes[AUDIO_READ_BYTES];
|
|
uint32_t numBytes = AUDIO_READ_BYTES;
|
|
readrv = Read(&numBytes, bytes);
|
|
|
|
rv = AudioFileStreamParseBytes(mAudioFileStream,
|
|
numBytes,
|
|
bytes,
|
|
0 /* flags */);
|
|
|
|
mMP3FrameParser.Parse(reinterpret_cast<uint8_t*>(bytes), numBytes, offset);
|
|
|
|
offset += numBytes;
|
|
|
|
// We have to do our decoder setup from the callback. When it's done it will
|
|
// set mStreamReady.
|
|
} while (!mStreamReady && !rv && NS_SUCCEEDED(readrv));
|
|
|
|
if (rv) {
|
|
LOGE("Error decoding audio stream metadata\n");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!mAudioConverter) {
|
|
LOGE("Failed to setup the AudioToolbox audio decoder\n");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!mMP3FrameParser.IsMP3()) {
|
|
LOGE("Frame parser failed to parse MP3 stream\n");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (mStreamReady) {
|
|
aInfo->mAudio.mRate = mAudioSampleRate;
|
|
aInfo->mAudio.mChannels = mAudioChannels;
|
|
}
|
|
|
|
// This reader doesn't seem to set *aInfo = mInfo like all the others. :/
|
|
mDuration = mMP3FrameParser.GetDuration();
|
|
mInfo.mMetadataDuration.emplace(TimeUnit::FromMicroseconds(mDuration));
|
|
aInfo->mMetadataDuration.emplace(TimeUnit::FromMicroseconds(mDuration));
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
void
|
|
AppleMP3Reader::AudioMetadataCallback(AudioFileStreamID aFileStream,
|
|
AudioFileStreamPropertyID aPropertyID,
|
|
UInt32 *aFlags)
|
|
{
|
|
if (aPropertyID == kAudioFileStreamProperty_ReadyToProducePackets) {
|
|
/*
|
|
* The parser is ready to send us packets of MP3 audio.
|
|
*
|
|
* We need to set the decoder up here, because if
|
|
* |AudioFileStreamParseBytes| has enough audio data, then it will call
|
|
* |AudioSampleCallback| before we get back to |ReadMetadata|.
|
|
*/
|
|
SetupDecoder();
|
|
mStreamReady = true;
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
AppleMP3Reader::SetupDecoder()
|
|
{
|
|
// Get input format description from demuxer
|
|
AudioStreamBasicDescription inputFormat, outputFormat;
|
|
GetProperty(mAudioFileStream, kAudioFileStreamProperty_DataFormat, &inputFormat);
|
|
|
|
memset(&outputFormat, 0, sizeof(outputFormat));
|
|
|
|
// Set output format
|
|
#if defined(MOZ_SAMPLE_TYPE_FLOAT32)
|
|
outputFormat.mBitsPerChannel = 32;
|
|
outputFormat.mFormatFlags =
|
|
kLinearPCMFormatFlagIsFloat |
|
|
0;
|
|
#else
|
|
#error Unknown audio sample type
|
|
#endif
|
|
|
|
mAudioSampleRate = outputFormat.mSampleRate = inputFormat.mSampleRate;
|
|
mAudioChannels
|
|
= outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
|
mAudioFramesPerCompressedPacket = inputFormat.mFramesPerPacket;
|
|
|
|
outputFormat.mFormatID = kAudioFormatLinearPCM;
|
|
|
|
// Set up the decoder so it gives us one sample per frame; this way, it will
|
|
// pass us all the samples it has in one go. Also makes it much easier to
|
|
// deinterlace.
|
|
outputFormat.mFramesPerPacket = 1;
|
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame
|
|
= outputFormat.mChannelsPerFrame * outputFormat.mBitsPerChannel / 8;
|
|
|
|
OSStatus rv = AudioConverterNew(&inputFormat,
|
|
&outputFormat,
|
|
&mAudioConverter);
|
|
|
|
if (rv) {
|
|
LOGE("Error constructing audio format converter: %x\n", rv);
|
|
mAudioConverter = nullptr;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
nsRefPtr<MediaDecoderReader::SeekPromise>
|
|
AppleMP3Reader::Seek(int64_t aTime, int64_t aEndTime)
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
// Find the exact frame/packet that contains |aTime|.
|
|
mCurrentAudioFrame = aTime * mAudioSampleRate / USECS_PER_S;
|
|
SInt64 packet = mCurrentAudioFrame / mAudioFramesPerCompressedPacket;
|
|
|
|
// |AudioFileStreamSeek| will pass back through |byteOffset| the byte offset
|
|
// into the stream it expects next time it reads.
|
|
SInt64 byteOffset;
|
|
UInt32 flags = 0;
|
|
|
|
OSStatus rv = AudioFileStreamSeek(mAudioFileStream,
|
|
packet,
|
|
&byteOffset,
|
|
&flags);
|
|
|
|
if (rv) {
|
|
LOGE("Couldn't seek demuxer. Error code %x\n", rv);
|
|
return SeekPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
|
}
|
|
|
|
LOGD("computed byte offset = %lld; estimated = %s\n",
|
|
byteOffset,
|
|
(flags & kAudioFileStreamSeekFlag_OffsetIsEstimated) ? "YES" : "NO");
|
|
|
|
mResource.Seek(nsISeekableStream::NS_SEEK_SET, byteOffset);
|
|
|
|
ResetDecode();
|
|
|
|
return SeekPromise::CreateAndResolve(aTime, __func__);
|
|
}
|
|
|
|
void
|
|
AppleMP3Reader::NotifyDataArrivedInternal(uint32_t aLength, int64_t aOffset)
|
|
{
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
if (!mMP3FrameParser.NeedsData()) {
|
|
return;
|
|
}
|
|
|
|
IntervalSet<int64_t> intervals = mFilter.NotifyDataArrived(aLength, aOffset);
|
|
for (const auto& interval : intervals) {
|
|
nsRefPtr<MediaByteBuffer> bytes =
|
|
mResource.MediaReadAt(interval.mStart, interval.Length());
|
|
NS_ENSURE_TRUE_VOID(bytes);
|
|
mMP3FrameParser.Parse(bytes->Elements(), interval.Length(), interval.mStart);
|
|
if (!mMP3FrameParser.IsMP3()) {
|
|
return;
|
|
}
|
|
|
|
uint64_t duration = mMP3FrameParser.GetDuration();
|
|
if (duration != mDuration) {
|
|
LOGD("Updating media duration to %lluus\n", duration);
|
|
MOZ_ASSERT(mDecoder);
|
|
mDuration = duration;
|
|
mDecoder->DispatchUpdateEstimatedMediaDuration(duration);
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|