2013-09-27 05:22:37 +00: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 MOZILLA_MEDIASOURCEDECODER_H_
|
|
|
|
#define MOZILLA_MEDIASOURCEDECODER_H_
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsError.h"
|
2014-08-13 12:22:00 +00:00
|
|
|
#include "MediaDecoder.h"
|
2014-12-09 19:43:21 +00:00
|
|
|
#include "MediaSourceReader.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
|
|
|
|
class nsIStreamListener;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-14 11:24:00 +00:00
|
|
|
class MediaResource;
|
2013-09-27 05:22:37 +00:00
|
|
|
class MediaDecoderStateMachine;
|
2014-08-22 02:14:36 +00:00
|
|
|
class SourceBufferDecoder;
|
2014-09-04 01:57:06 +00:00
|
|
|
class TrackBuffer;
|
2015-01-16 12:49:02 +00:00
|
|
|
enum MSRangeRemovalAction : uint8_t;
|
2013-09-27 05:22:37 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLMediaElement;
|
|
|
|
class MediaSource;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class MediaSourceDecoder : public MediaDecoder
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 03:50:23 +00:00
|
|
|
explicit MediaSourceDecoder(dom::HTMLMediaElement* aElement);
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual MediaDecoder* Clone() override;
|
|
|
|
virtual MediaDecoderStateMachine* CreateStateMachine() override;
|
|
|
|
virtual nsresult Load(nsIStreamListener**, MediaDecoder*) override;
|
|
|
|
virtual nsresult GetSeekable(dom::TimeRanges* aSeekable) override;
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void Shutdown() override;
|
2014-08-25 04:09:44 +00:00
|
|
|
|
2014-10-15 01:17:03 +00:00
|
|
|
static already_AddRefed<MediaResource> CreateResource(nsIPrincipal* aPrincipal = nullptr);
|
2014-04-14 11:24:00 +00:00
|
|
|
|
2013-11-18 04:22:47 +00:00
|
|
|
void AttachMediaSource(dom::MediaSource* aMediaSource);
|
2013-09-27 05:22:37 +00:00
|
|
|
void DetachMediaSource();
|
|
|
|
|
2015-01-07 23:58:55 +00:00
|
|
|
already_AddRefed<SourceBufferDecoder> CreateSubDecoder(const nsACString& aType,
|
|
|
|
int64_t aTimestampOffset /* microseconds */);
|
2014-09-04 01:57:06 +00:00
|
|
|
void AddTrackBuffer(TrackBuffer* aTrackBuffer);
|
|
|
|
void RemoveTrackBuffer(TrackBuffer* aTrackBuffer);
|
|
|
|
void OnTrackBufferConfigured(TrackBuffer* aTrackBuffer, const MediaInfo& aInfo);
|
2014-02-28 00:54:48 +00:00
|
|
|
|
2014-08-26 07:25:09 +00:00
|
|
|
void Ended();
|
2015-03-21 16:28:04 +00:00
|
|
|
bool IsExpectingMoreData() override;
|
2014-08-26 07:25:09 +00:00
|
|
|
|
2015-02-12 07:52:12 +00:00
|
|
|
// Return the duration of the video in seconds.
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual double GetDuration() override;
|
2015-02-12 07:52:12 +00:00
|
|
|
|
2015-02-04 09:20:15 +00:00
|
|
|
void SetInitialDuration(int64_t aDuration);
|
2015-01-16 12:49:02 +00:00
|
|
|
void SetMediaSourceDuration(double aDuration, MSRangeRemovalAction aAction);
|
2014-11-12 04:11:33 +00:00
|
|
|
double GetMediaSourceDuration();
|
|
|
|
void DurationChanged(double aOldDuration, double aNewDuration);
|
2014-08-25 04:09:44 +00:00
|
|
|
|
2014-09-07 11:54:00 +00:00
|
|
|
// Called whenever a TrackBuffer has new data appended or a new decoder
|
|
|
|
// initializes. Safe to call from any thread.
|
|
|
|
void NotifyTimeRangesChanged();
|
2014-08-25 04:09:44 +00:00
|
|
|
|
2014-09-05 00:04:54 +00:00
|
|
|
// Indicates the point in time at which the reader should consider
|
|
|
|
// registered TrackBuffers essential for initialization.
|
|
|
|
void PrepareReaderInitialization();
|
|
|
|
|
2014-10-13 22:05:00 +00:00
|
|
|
#ifdef MOZ_EME
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult SetCDMProxy(CDMProxy* aProxy) override;
|
2014-10-13 22:05:00 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-09 19:43:21 +00:00
|
|
|
MediaSourceReader* GetReader() { return mReader; }
|
|
|
|
|
2015-01-16 03:14:56 +00:00
|
|
|
// Returns true if aReader is a currently active audio or video
|
|
|
|
// reader in this decoders MediaSourceReader.
|
|
|
|
bool IsActiveReader(MediaDecoderReader* aReader);
|
|
|
|
|
2015-02-13 05:52:42 +00:00
|
|
|
// Return a decoder from the set available in aTrackDecoders that has data
|
|
|
|
// available in the range requested by aTarget.
|
|
|
|
already_AddRefed<SourceBufferDecoder> SelectDecoder(int64_t aTarget /* microseconds */,
|
|
|
|
int64_t aTolerance /* microseconds */,
|
|
|
|
const nsTArray<nsRefPtr<SourceBufferDecoder>>& aTrackDecoders);
|
|
|
|
|
2015-01-29 02:35:58 +00:00
|
|
|
// Returns a string describing the state of the MediaSource internal
|
|
|
|
// buffered data. Used for debugging purposes.
|
|
|
|
void GetMozDebugReaderData(nsAString& aString);
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
private:
|
2015-01-16 12:49:02 +00:00
|
|
|
void DoSetMediaSourceDuration(double aDuration);
|
|
|
|
void ScheduleDurationChange(double aOldDuration,
|
|
|
|
double aNewDuration,
|
|
|
|
MSRangeRemovalAction aAction);
|
|
|
|
|
2014-04-21 13:30:00 +00:00
|
|
|
// The owning MediaSource holds a strong reference to this decoder, and
|
|
|
|
// calls Attach/DetachMediaSource on this decoder to set and clear
|
|
|
|
// mMediaSource.
|
2013-11-18 04:22:47 +00:00
|
|
|
dom::MediaSource* mMediaSource;
|
2014-08-17 11:29:00 +00:00
|
|
|
nsRefPtr<MediaSourceReader> mReader;
|
2014-11-12 04:11:33 +00:00
|
|
|
|
|
|
|
// Protected by GetReentrantMonitor()
|
|
|
|
double mMediaSourceDuration;
|
2013-09-27 05:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* MOZILLA_MEDIASOURCEDECODER_H_ */
|