bool MP3TrackDemuxer::Init() { Reset(); FastSeek(TimeUnit()); // Read the first frame to fetch sample rate and other meta data. nsRefPtr<MediaRawData> frame(GetNextFrame(FindNextFrame())); MP3DEMUXER_LOG("Init StreamLength()=%" PRId64 " first-frame-found=%d", StreamLength(), !!frame); if (!frame) { return false; } // Rewind back to the stream begin to avoid dropping the first frame. FastSeek(TimeUnit()); if (!mInfo) { mInfo = MakeUnique<AudioInfo>(); } mInfo->mRate = mSamplesPerSecond; mInfo->mChannels = mChannels; mInfo->mBitDepth = 16; mInfo->mMimeType = "audio/mpeg"; mInfo->mDuration = Duration().ToMicroseconds(); MP3DEMUXER_LOG("Init mInfo={mRate=%d mChannels=%d mBitDepth=%d mDuration=%" PRId64 "}", mInfo->mRate, mInfo->mChannels, mInfo->mBitDepth, mInfo->mDuration); return mSamplesPerSecond && mChannels; }
TimeIntervals MP3TrackDemuxer::GetBuffered() { // TODO: bug 1169485. MP3DEMUXER_LOG("MP3TrackDemuxer::GetBuffered()"); NS_WARNING("Unimplemented function GetBuffered"); return TimeIntervals(); }
TimeUnit MP3TrackDemuxer::FastSeek(TimeUnit aTime) { MP3DEMUXER_LOG("FastSeek(%" PRId64 ") avgFrameLen=%f mNumParsedFrames=%" PRIu64 " mFrameIndex=%" PRId64 " mOffset=%" PRIu64, aTime, AverageFrameLength(), mNumParsedFrames, mFrameIndex, mOffset); if (!aTime.ToMicroseconds()) { // Quick seek to the beginning of the stream. mOffset = mFirstFrameOffset; mFrameIndex = 0; mParser.EndFrameSession(); return TimeUnit(); } if (!mSamplesPerFrame || !mNumParsedFrames) { return TimeUnit::FromMicroseconds(-1); } const int64_t numFrames = aTime.ToSeconds() * mSamplesPerSecond / mSamplesPerFrame; mOffset = mFirstFrameOffset + numFrames * AverageFrameLength(); mFrameIndex = numFrames; MP3DEMUXER_LOG("FastSeek mSamplesPerSecond=%d mSamplesPerFrame=%d " "numFrames=%" PRId64, mSamplesPerSecond, mSamplesPerFrame, numFrames); mParser.EndFrameSession(); return Duration(mFrameIndex); }
void MediaSourceTrackDemuxer::Reset() { MOZ_ASSERT(mParent, "Called after BreackCycle()"); RefPtr<MediaSourceTrackDemuxer> self = this; nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([self] () { self->mManager->Seek(self->mType, TimeUnit(), TimeUnit()); { MonitorAutoLock mon(self->mMonitor); self->mNextRandomAccessPoint = self->mManager->GetNextRandomAccessPoint(self->mType); } }); mParent->GetTaskQueue()->Dispatch(task.forget()); }
TimeUnit MP3TrackDemuxer::FastSeek(TimeUnit aTime) { if (!aTime.ToMicroseconds()) { // Quick seek to the beginning of the stream. mOffset = mFirstFrameOffset; mFrameIndex = 0; mParser.EndFrameSession(); return TimeUnit(); } if (!mSamplesPerFrame || !mNumParsedFrames) { return TimeUnit::FromMicroseconds(-1); } const int64_t numFrames = aTime.ToSeconds() * mSamplesPerSecond / mSamplesPerFrame; mOffset = mFirstFrameOffset + numFrames * AverageFrameLength(); mFrameIndex = numFrames; mParser.EndFrameSession(); return Duration(mFrameIndex); }