2014-09-03 18:57:06 -07: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_TRACKBUFFER_H_
|
|
|
|
#define MOZILLA_TRACKBUFFER_H_
|
|
|
|
|
|
|
|
#include "SourceBufferDecoder.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-09-16 23:33:00 -07:00
|
|
|
class ContainerParser;
|
2014-09-03 18:57:06 -07:00
|
|
|
class MediaSourceDecoder;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class TimeRanges;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class TrackBuffer MOZ_FINAL {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TrackBuffer);
|
|
|
|
|
|
|
|
TrackBuffer(MediaSourceDecoder* aParentDecoder, const nsACString& aType);
|
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Append data to the current decoder. Also responsible for calling
|
|
|
|
// NotifyDataArrived on the decoder to keep buffered range computation up
|
|
|
|
// to date. Returns false if the append failed.
|
|
|
|
bool AppendData(const uint8_t* aData, uint32_t aLength);
|
|
|
|
bool EvictData(uint32_t aThreshold);
|
|
|
|
void EvictBefore(double aTime);
|
|
|
|
|
|
|
|
// Returns the highest end time of all of the buffered ranges in the
|
|
|
|
// decoders managed by this TrackBuffer, and returns the union of the
|
2014-11-11 20:50:21 -08:00
|
|
|
// decoders buffered ranges in aRanges. This may be called on any thread.
|
2014-09-03 18:57:06 -07:00
|
|
|
double Buffered(dom::TimeRanges* aRanges);
|
|
|
|
|
|
|
|
// Mark the current decoder's resource as ended, clear mCurrentDecoder and
|
|
|
|
// reset mLast{Start,End}Timestamp.
|
|
|
|
void DiscardDecoder();
|
|
|
|
|
|
|
|
void Detach();
|
|
|
|
|
|
|
|
// Returns true if an init segment has been appended.
|
|
|
|
bool HasInitSegment();
|
|
|
|
|
2014-09-16 23:33:00 -07:00
|
|
|
// Returns true iff mParser->HasInitData() and the decoder using that init
|
2014-09-03 18:57:06 -07:00
|
|
|
// segment has successfully initialized by setting mHas{Audio,Video}..
|
|
|
|
bool IsReady();
|
|
|
|
|
|
|
|
// Returns true if any of the decoders managed by this track buffer
|
|
|
|
// contain aTime in their buffered ranges.
|
2014-09-09 19:27:51 -07:00
|
|
|
bool ContainsTime(int64_t aTime);
|
2014-09-03 18:57:06 -07:00
|
|
|
|
|
|
|
void BreakCycles();
|
|
|
|
|
|
|
|
// Call ResetDecode() on each decoder in mDecoders.
|
|
|
|
void ResetDecode();
|
|
|
|
|
2014-09-04 00:35:01 -07:00
|
|
|
// Returns a reference to mInitializedDecoders, used by MediaSourceReader
|
|
|
|
// to select decoders.
|
|
|
|
// TODO: Refactor to a cleaner interface between TrackBuffer and MediaSourceReader.
|
2014-09-03 18:57:06 -07:00
|
|
|
const nsTArray<nsRefPtr<SourceBufferDecoder>>& Decoders();
|
|
|
|
|
2014-10-13 15:05:00 -07:00
|
|
|
#ifdef MOZ_EME
|
|
|
|
nsresult SetCDMProxy(CDMProxy* aProxy);
|
|
|
|
#endif
|
|
|
|
|
2014-09-11 15:47:06 -07:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Dump(const char* aPath);
|
|
|
|
#endif
|
|
|
|
|
2014-09-03 18:57:06 -07:00
|
|
|
private:
|
2014-11-05 20:09:19 -08:00
|
|
|
friend class DecodersToInitialize;
|
2014-09-03 18:57:06 -07:00
|
|
|
~TrackBuffer();
|
|
|
|
|
2014-11-05 20:09:19 -08:00
|
|
|
// Create a new decoder, set mCurrentDecoder to the new decoder and
|
|
|
|
// returns it. The new decoder must be queued using QueueInitializeDecoder
|
|
|
|
// for initialization.
|
|
|
|
// The decoder is not considered initialized until it is added to
|
|
|
|
// mInitializedDecoders.
|
|
|
|
already_AddRefed<SourceBufferDecoder> NewDecoder();
|
2014-09-16 23:33:00 -07:00
|
|
|
|
|
|
|
// Helper for AppendData, ensures NotifyDataArrived is called whenever
|
|
|
|
// data is appended to the current decoder's SourceBufferResource.
|
|
|
|
bool AppendDataToCurrentResource(const uint8_t* aData, uint32_t aLength);
|
|
|
|
|
2014-09-03 18:57:06 -07:00
|
|
|
// Queue execution of InitializeDecoder on mTaskQueue.
|
2014-10-01 22:04:06 -07:00
|
|
|
bool QueueInitializeDecoder(SourceBufferDecoder* aDecoder);
|
2014-09-03 18:57:06 -07:00
|
|
|
|
|
|
|
// Runs decoder initialization including calling ReadMetadata. Runs as an
|
|
|
|
// event on the decode thread pool.
|
2014-10-01 22:04:06 -07:00
|
|
|
void InitializeDecoder(SourceBufferDecoder* aDecoder);
|
2014-09-03 18:57:06 -07:00
|
|
|
|
|
|
|
// Adds a successfully initialized decoder to mDecoders and (if it's the
|
|
|
|
// first decoder initialized), initializes mHasAudio/mHasVideo. Called
|
2014-09-09 19:21:17 -07:00
|
|
|
// from the decode thread pool. Return true if the decoder was
|
|
|
|
// successfully registered.
|
2014-10-01 22:04:06 -07:00
|
|
|
bool RegisterDecoder(SourceBufferDecoder* aDecoder);
|
2014-09-09 19:21:17 -07:00
|
|
|
|
|
|
|
// Returns true if aInfo is considered a supported or the same format as
|
|
|
|
// the TrackBuffer was initialized as.
|
|
|
|
bool ValidateTrackFormats(const MediaInfo& aInfo);
|
|
|
|
|
|
|
|
// Remove aDecoder from mDecoders and dispatch an event to the main thread
|
|
|
|
// to clean up the decoder. If aDecoder was added to
|
|
|
|
// mInitializedDecoders, it must have been removed before calling this
|
|
|
|
// function.
|
2014-10-01 22:04:06 -07:00
|
|
|
void RemoveDecoder(SourceBufferDecoder* aDecoder);
|
2014-09-03 18:57:06 -07:00
|
|
|
|
2014-09-16 23:33:00 -07:00
|
|
|
nsAutoPtr<ContainerParser> mParser;
|
|
|
|
|
2014-09-03 18:57:06 -07:00
|
|
|
// A task queue using the shared media thread pool. Used exclusively to
|
|
|
|
// initialize (i.e. call ReadMetadata on) decoders as they are created via
|
|
|
|
// NewDecoder.
|
|
|
|
RefPtr<MediaTaskQueue> mTaskQueue;
|
|
|
|
|
2014-09-04 00:35:01 -07:00
|
|
|
// All of the decoders managed by this TrackBuffer. Access protected by
|
|
|
|
// mParentDecoder's monitor.
|
2014-09-03 18:57:06 -07:00
|
|
|
nsTArray<nsRefPtr<SourceBufferDecoder>> mDecoders;
|
|
|
|
|
2014-09-04 00:35:01 -07:00
|
|
|
// Contains only the initialized decoders managed by this TrackBuffer.
|
|
|
|
// Access protected by mParentDecoder's monitor.
|
|
|
|
nsTArray<nsRefPtr<SourceBufferDecoder>> mInitializedDecoders;
|
|
|
|
|
2014-10-13 15:05:00 -07:00
|
|
|
// Decoders which are waiting on a Content Decryption Module to be able to
|
|
|
|
// finish ReadMetadata.
|
|
|
|
nsTArray<nsRefPtr<SourceBufferDecoder>> mWaitingDecoders;
|
|
|
|
|
2014-09-03 18:57:06 -07:00
|
|
|
// The decoder that the owning SourceBuffer is currently appending data to.
|
|
|
|
nsRefPtr<SourceBufferDecoder> mCurrentDecoder;
|
|
|
|
|
|
|
|
nsRefPtr<MediaSourceDecoder> mParentDecoder;
|
|
|
|
const nsCString mType;
|
|
|
|
|
|
|
|
// The last start and end timestamps added to the TrackBuffer via
|
|
|
|
// AppendData. Accessed on the main thread only.
|
2014-09-09 18:26:22 -07:00
|
|
|
int64_t mLastStartTimestamp;
|
|
|
|
int64_t mLastEndTimestamp;
|
2014-09-03 18:57:06 -07:00
|
|
|
|
|
|
|
// Set when the first decoder used by this TrackBuffer is initialized.
|
|
|
|
// Protected by mParentDecoder's monitor.
|
2014-09-09 19:21:17 -07:00
|
|
|
MediaInfo mInfo;
|
2014-09-03 18:57:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif /* MOZILLA_TRACKBUFFER_H_ */
|