2017-06-19 10:50:09 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 ChannelMediaDecoder_h_
|
|
|
|
#define ChannelMediaDecoder_h_
|
|
|
|
|
|
|
|
#include "MediaDecoder.h"
|
2017-06-20 13:10:56 +03:00
|
|
|
#include "MediaResourceCallback.h"
|
2017-06-19 10:50:09 +03:00
|
|
|
|
2017-06-21 12:30:56 +03:00
|
|
|
class nsIChannel;
|
2017-06-23 09:12:41 +03:00
|
|
|
class nsIStreamListener;
|
2017-06-21 12:30:56 +03:00
|
|
|
|
2017-06-19 10:50:09 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-08-04 09:52:22 +03:00
|
|
|
class BaseMediaResource;
|
|
|
|
|
2017-06-19 10:50:09 +03:00
|
|
|
class ChannelMediaDecoder : public MediaDecoder
|
|
|
|
{
|
2017-06-20 13:10:56 +03:00
|
|
|
// Used to register with MediaResource to receive notifications which will
|
|
|
|
// be forwarded to MediaDecoder.
|
|
|
|
class ResourceCallback : public MediaResourceCallback
|
|
|
|
{
|
|
|
|
// Throttle calls to MediaDecoder::NotifyDataArrived()
|
|
|
|
// to be at most once per 500ms.
|
|
|
|
static const uint32_t sDelay = 500;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ResourceCallback(AbstractThread* aMainThread);
|
|
|
|
// Start to receive notifications from ResourceCallback.
|
|
|
|
void Connect(ChannelMediaDecoder* aDecoder);
|
|
|
|
// Called upon shutdown to stop receiving notifications.
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* MediaResourceCallback functions */
|
2017-09-06 10:12:34 +03:00
|
|
|
AbstractThread* AbstractMainThread() const override;
|
2017-06-20 13:10:56 +03:00
|
|
|
MediaDecoderOwner* GetMediaOwner() const override;
|
|
|
|
void NotifyNetworkError() override;
|
|
|
|
void NotifyDataArrived() override;
|
|
|
|
void NotifyDataEnded(nsresult aStatus) override;
|
|
|
|
void NotifyPrincipalChanged() override;
|
2017-08-23 09:32:51 +03:00
|
|
|
void NotifySuspendedStatusChanged(bool aSuspendedByCache) override;
|
2017-06-20 13:10:56 +03:00
|
|
|
void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) override;
|
|
|
|
|
|
|
|
static void TimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
|
|
|
// The decoder to send notifications. Main-thread only.
|
|
|
|
ChannelMediaDecoder* mDecoder = nullptr;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
bool mTimerArmed = false;
|
|
|
|
const RefPtr<AbstractThread> mAbstractMainThread;
|
|
|
|
};
|
|
|
|
|
2017-06-30 05:11:42 +03:00
|
|
|
protected:
|
2017-08-07 08:23:43 +03:00
|
|
|
void OnPlaybackEvent(MediaEventType aEvent) override;
|
|
|
|
void DurationChanged() override;
|
|
|
|
void DownloadProgressed() override;
|
2017-08-09 06:06:29 +03:00
|
|
|
void MetadataLoaded(UniquePtr<MediaInfo> aInfo,
|
|
|
|
UniquePtr<MetadataTags> aTags,
|
|
|
|
MediaDecoderEventVisibility aEventVisibility) override;
|
|
|
|
|
2017-06-20 13:10:56 +03:00
|
|
|
RefPtr<ResourceCallback> mResourceCallback;
|
2017-08-04 09:52:22 +03:00
|
|
|
RefPtr<BaseMediaResource> mResource;
|
2017-06-20 13:10:56 +03:00
|
|
|
|
2017-06-19 10:50:09 +03:00
|
|
|
public:
|
|
|
|
explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
|
2017-06-20 13:10:27 +03:00
|
|
|
|
2017-06-20 13:10:56 +03:00
|
|
|
void Shutdown() override;
|
|
|
|
|
2017-08-04 10:29:55 +03:00
|
|
|
bool CanClone();
|
|
|
|
|
2017-06-20 13:10:27 +03:00
|
|
|
// Create a new decoder of the same type as this one.
|
2017-08-03 12:39:55 +03:00
|
|
|
already_AddRefed<ChannelMediaDecoder> Clone(MediaDecoderInit& aInit);
|
2017-06-21 12:30:56 +03:00
|
|
|
|
2017-08-03 12:48:26 +03:00
|
|
|
nsresult Load(nsIChannel* aChannel,
|
|
|
|
bool aIsPrivateBrowsing,
|
|
|
|
nsIStreamListener** aStreamListener);
|
2017-06-23 09:12:41 +03:00
|
|
|
|
2017-08-24 12:35:24 +03:00
|
|
|
void AddSizeOfResources(ResourceSizes* aSizes) override;
|
2017-08-24 11:58:06 +03:00
|
|
|
already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
|
2017-08-23 19:06:23 +03:00
|
|
|
bool IsTransportSeekable() override;
|
2017-08-07 13:09:56 +03:00
|
|
|
void SetLoadInBackground(bool aLoadInBackground) override;
|
|
|
|
void Suspend() override;
|
|
|
|
void Resume() override;
|
|
|
|
|
2017-06-23 09:12:41 +03:00
|
|
|
private:
|
2017-08-24 13:08:37 +03:00
|
|
|
void PinForSeek() override;
|
|
|
|
void UnpinForSeek() override;
|
2017-08-17 10:41:22 +03:00
|
|
|
|
2017-08-15 07:37:00 +03:00
|
|
|
// Create a new state machine to run this decoder.
|
|
|
|
MediaDecoderStateMachine* CreateStateMachine();
|
|
|
|
|
2017-08-04 09:52:22 +03:00
|
|
|
nsresult Load(BaseMediaResource* aOriginal);
|
2017-08-04 11:02:40 +03:00
|
|
|
|
|
|
|
// Called by MediaResource when the download has ended.
|
|
|
|
// Called on the main thread only. aStatus is the result from OnStopRequest.
|
|
|
|
void NotifyDownloadEnded(nsresult aStatus);
|
|
|
|
|
|
|
|
// Called by the MediaResource to keep track of the number of bytes read
|
|
|
|
// from the resource. Called on the main by an event runner dispatched
|
|
|
|
// by the MediaResource read functions.
|
|
|
|
void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset);
|
|
|
|
|
|
|
|
void SeekingChanged();
|
|
|
|
|
2017-08-07 06:48:43 +03:00
|
|
|
bool CanPlayThroughImpl() override final;
|
|
|
|
|
2017-08-17 10:20:40 +03:00
|
|
|
bool IsLiveStream() override final;
|
|
|
|
|
2017-08-07 08:23:43 +03:00
|
|
|
// The actual playback rate computation.
|
|
|
|
void ComputePlaybackRate();
|
|
|
|
|
|
|
|
// Something has changed that could affect the computed playback rate,
|
|
|
|
// so recompute it.
|
|
|
|
void UpdatePlaybackRate();
|
|
|
|
|
|
|
|
// Return statistics. This is used for progress events and other things.
|
|
|
|
// This can be called from any thread. It's only a snapshot of the
|
|
|
|
// current state, since other threads might be changing the state
|
|
|
|
// at any time.
|
|
|
|
MediaStatistics GetStatistics();
|
|
|
|
|
|
|
|
bool ShouldThrottleDownload();
|
|
|
|
|
2017-08-04 11:02:40 +03:00
|
|
|
WatchManager<ChannelMediaDecoder> mWatchManager;
|
|
|
|
|
|
|
|
// True when seeking or otherwise moving the play position around in
|
|
|
|
// such a manner that progress event data is inaccurate. This is set
|
|
|
|
// during seek and duration operations to prevent the progress indicator
|
|
|
|
// from jumping around. Read/Write on the main thread only.
|
|
|
|
bool mIgnoreProgressData = false;
|
2017-08-07 08:23:43 +03:00
|
|
|
|
|
|
|
// Data needed to estimate playback data rate. The timeline used for
|
|
|
|
// this estimate is "decode time" (where the "current time" is the
|
|
|
|
// time of the last decoded video frame).
|
|
|
|
MediaChannelStatistics mPlaybackStatistics;
|
|
|
|
|
|
|
|
// Estimate of the current playback rate (bytes/second).
|
|
|
|
double mPlaybackBytesPerSecond = 0;
|
|
|
|
|
|
|
|
// True if mPlaybackBytesPerSecond is a reliable estimate.
|
|
|
|
bool mPlaybackRateReliable = true;
|
2017-08-24 13:08:37 +03:00
|
|
|
|
|
|
|
// True when our media stream has been pinned. We pin the stream
|
|
|
|
// while seeking.
|
|
|
|
bool mPinnedForSeek = false;
|
2017-06-19 10:50:09 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // ChannelMediaDecoder_h_
|