Bug 1349485. P1 - devirtualize DecodedAudioDataSink. r=kikuo

MozReview-Commit-ID: 7c24rJDaMwX

--HG--
extra : rebase_source : 669539ed8390bef8bcf0402b8b05b251ffc9346e
This commit is contained in:
JW Wang 2017-03-22 14:48:00 +08:00
Родитель 9513b01c69
Коммит eb619f72b5
4 изменённых файлов: 29 добавлений и 25 удалений

Просмотреть файл

@ -4,8 +4,8 @@
* 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 "AudioSink.h"
#include "AudioSinkWrapper.h"
#include "DecodedAudioDataSink.h"
namespace mozilla {
namespace media {

Просмотреть файл

@ -22,7 +22,7 @@ template <class T> class MediaQueue;
namespace media {
class AudioSink;
class DecodedAudioDataSink;
/**
* A wrapper around AudioSink to provide the interface of MediaSink.
@ -32,7 +32,7 @@ class AudioSinkWrapper : public MediaSink {
class Creator {
public:
virtual ~Creator() {}
virtual AudioSink* Create() = 0;
virtual DecodedAudioDataSink* Create() = 0;
};
// Wrap around a function object which creates AudioSinks.
@ -40,7 +40,7 @@ class AudioSinkWrapper : public MediaSink {
class CreatorImpl : public Creator {
public:
explicit CreatorImpl(const Function& aFunc) : mFunction(aFunc) {}
AudioSink* Create() override { return mFunction(); }
DecodedAudioDataSink* Create() override { return mFunction(); }
private:
Function mFunction;
};
@ -89,7 +89,7 @@ private:
const RefPtr<AbstractThread> mOwnerThread;
UniquePtr<Creator> mCreator;
RefPtr<AudioSink> mAudioSink;
RefPtr<DecodedAudioDataSink> mAudioSink;
RefPtr<GenericPromise> mEndPromise;
bool mIsStarted;

Просмотреть файл

@ -38,8 +38,7 @@ DecodedAudioDataSink::DecodedAudioDataSink(AbstractThread* aThread,
int64_t aStartTime,
const AudioInfo& aInfo,
dom::AudioChannel aChannel)
: AudioSink(aAudioQueue)
, mStartTime(aStartTime)
: mStartTime(aStartTime)
, mLastGoodPosition(0)
, mInfo(aInfo)
, mChannel(aChannel)
@ -53,6 +52,7 @@ DecodedAudioDataSink::DecodedAudioDataSink(AbstractThread* aThread,
, mFramesParsed(0)
, mLastEndTime(0)
, mIsAudioDataAudible(false)
, mAudioQueue(aAudioQueue)
{
bool resampling = MediaPrefs::AudioSinkResampling();
@ -385,10 +385,10 @@ DecodedAudioDataSink::NotifyAudioNeeded()
// Always ensure we have two processed frames pending to allow for processing
// latency.
while (AudioQueue().GetSize() && (AudioQueue().IsFinished() ||
while (mAudioQueue.GetSize() && (mAudioQueue.IsFinished() ||
mProcessedQueueLength < LOW_AUDIO_USECS ||
mProcessedQueue.GetSize() < 2)) {
RefPtr<AudioData> data = AudioQueue().PopFront();
RefPtr<AudioData> data = mAudioQueue.PopFront();
// Ignore the element with 0 frames and try next.
if (!data->mFrames) {
@ -491,7 +491,7 @@ DecodedAudioDataSink::NotifyAudioNeeded()
}
}
if (AudioQueue().IsFinished()) {
if (mAudioQueue.IsFinished()) {
// We have reached the end of the data, drain the resampler.
DrainConverter();
mProcessedQueue.Finish();

Просмотреть файл

@ -6,19 +6,19 @@
#if !defined(DecodedAudioDataSink_h__)
#define DecodedAudioDataSink_h__
#include "AudioSink.h"
#include "AudioStream.h"
#include "MediaEventSource.h"
#include "MediaQueue.h"
#include "MediaInfo.h"
#include "mozilla/RefPtr.h"
#include "nsISupportsImpl.h"
#include "MediaSink.h"
#include "mozilla/dom/AudioChannelBinding.h"
#include "mozilla/Atomics.h"
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h"
#include "mozilla/Monitor.h"
#include "mozilla/RefPtr.h"
#include "nsISupportsImpl.h"
namespace mozilla {
@ -26,8 +26,10 @@ class AudioConverter;
namespace media {
class DecodedAudioDataSink : public AudioSink,
private AudioStream::DataSource {
class DecodedAudioDataSink : private AudioStream::DataSource {
using PlaybackParams = MediaSink::PlaybackParams;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodedAudioDataSink)
public:
DecodedAudioDataSink(AbstractThread* aThread,
MediaQueue<AudioData>& aAudioQueue,
@ -37,26 +39,26 @@ public:
// Return a promise which will be resolved when DecodedAudioDataSink
// finishes playing, or rejected if any error.
RefPtr<GenericPromise> Init(const PlaybackParams& aParams) override;
RefPtr<GenericPromise> Init(const PlaybackParams& aParams);
/*
* All public functions are not thread-safe.
* Called on the task queue of MDSM only.
*/
int64_t GetPosition() override;
int64_t GetEndTime() const override;
int64_t GetPosition();
int64_t GetEndTime() const;
// Check whether we've pushed more frames to the audio hardware than it has
// played.
bool HasUnplayedFrames() override;
bool HasUnplayedFrames();
// Shut down the DecodedAudioDataSink's resources.
void Shutdown() override;
void Shutdown();
void SetVolume(double aVolume) override;
void SetPlaybackRate(double aPlaybackRate) override;
void SetPreservesPitch(bool aPreservesPitch) override;
void SetPlaying(bool aPlaying) override;
void SetVolume(double aVolume);
void SetPlaybackRate(double aPlaybackRate);
void SetPreservesPitch(bool aPreservesPitch);
void SetPlaying(bool aPlaying);
MediaEventSource<bool>& AudibleEvent() {
return mAudibleEvent;
@ -143,7 +145,7 @@ private:
MediaEventListener mAudioQueueListener;
MediaEventListener mAudioQueueFinishListener;
MediaEventListener mProcessedQueueListener;
// Number of frames processed from AudioQueue(). Used to determine gaps in
// Number of frames processed from mAudioQueue. Used to determine gaps in
// the input stream. It indicates the time in frames since playback started
// at the current input framerate.
int64_t mFramesParsed;
@ -157,6 +159,8 @@ private:
bool mIsAudioDataAudible;
MediaEventProducer<bool> mAudibleEvent;
MediaQueue<AudioData>& mAudioQueue;
};
} // namespace media