mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 19:55:39 +00:00
f17dd305d6
Continuing the work of replacing MIME strings with MediaContainerType, starting from MediaResource and following the dependencies. Most changes are mechanical: Just change ns*String into MediaContainerType, and MIME string literals into MEDIAMIMETYPE("a/b"). Some checks for empty/invalid strings and lowercase comparisons can go, thanks to the always-valid always-lowercase-MIME invariants of MediaContainerType. One special case in is MediaSourceResource, which used to have an empty string as its type (because its own type is not relevant, but its SourceBuffers carry types). Because the inherited GetContentType *must* be overridden, and must return a MediaContainerType, we needed a valid type even though it should not be seen in the real world. I've chosen "application/x.mediasource" for that. MozReview-Commit-ID: 1aCH75Kh2e6 --HG-- extra : rebase_source : 0d9cd9b69c264e5dcfc3845f80ee107f4bcbcd9a
161 lines
5.2 KiB
C++
161 lines
5.2 KiB
C++
/* -*- 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_SOURCEBUFFERRESOURCE_H_
|
|
#define MOZILLA_SOURCEBUFFERRESOURCE_H_
|
|
|
|
#include "MediaCache.h"
|
|
#include "MediaResource.h"
|
|
#include "ResourceQueue.h"
|
|
#include "mozilla/Attributes.h"
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsError.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsTArray.h"
|
|
#include "nscore.h"
|
|
#include "mozilla/Logging.h"
|
|
|
|
#define UNIMPLEMENTED() { /* Logging this is too spammy to do by default */ }
|
|
|
|
class nsIStreamListener;
|
|
|
|
namespace mozilla {
|
|
|
|
class MediaDecoder;
|
|
class MediaByteBuffer;
|
|
|
|
namespace dom {
|
|
|
|
class SourceBuffer;
|
|
|
|
} // namespace dom
|
|
|
|
class SourceBufferResource final : public MediaResource
|
|
{
|
|
public:
|
|
explicit SourceBufferResource(const MediaContainerType& aType);
|
|
nsresult Close() override;
|
|
void Suspend(bool aCloseImmediately) override { UNIMPLEMENTED(); }
|
|
void Resume() override { UNIMPLEMENTED(); }
|
|
already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override { UNIMPLEMENTED(); return nullptr; }
|
|
already_AddRefed<MediaResource> CloneData(MediaResourceCallback*) override { UNIMPLEMENTED(); return nullptr; }
|
|
void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
|
|
void SetPlaybackRate(uint32_t aBytesPerSecond) override { UNIMPLEMENTED(); }
|
|
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override;
|
|
int64_t Tell() override { return mOffset; }
|
|
void Pin() override { UNIMPLEMENTED(); }
|
|
void Unpin() override { UNIMPLEMENTED(); }
|
|
double GetDownloadRate(bool* aIsReliable) override { UNIMPLEMENTED(); *aIsReliable = false; return 0; }
|
|
int64_t GetLength() override { return mInputBuffer.GetLength(); }
|
|
int64_t GetNextCachedData(int64_t aOffset) override {
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
MOZ_ASSERT(aOffset >= 0);
|
|
if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
|
|
return mInputBuffer.GetOffset();
|
|
} else if (aOffset == GetLength()) {
|
|
return -1;
|
|
}
|
|
return aOffset;
|
|
}
|
|
int64_t GetCachedDataEnd(int64_t aOffset) override { UNIMPLEMENTED(); return -1; }
|
|
bool IsDataCachedToEndOfResource(int64_t aOffset) override { return false; }
|
|
bool IsSuspendedByCache() override { UNIMPLEMENTED(); return false; }
|
|
bool IsSuspended() override { UNIMPLEMENTED(); return false; }
|
|
nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) override;
|
|
bool IsTransportSeekable() override { UNIMPLEMENTED(); return true; }
|
|
nsresult Open(nsIStreamListener** aStreamListener) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
|
|
|
|
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
if (mInputBuffer.GetLength()) {
|
|
aRanges += MediaByteRange(mInputBuffer.GetOffset(),
|
|
mInputBuffer.GetLength());
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
const MediaContainerType& GetContentType() const override { return mType; }
|
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
|
|
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
|
size += mType.SizeOfExcludingThis(aMallocSizeOf);
|
|
size += mInputBuffer.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return size;
|
|
}
|
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
|
|
{
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
}
|
|
|
|
bool IsExpectingMoreData() override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Used by SourceBuffer.
|
|
void AppendData(MediaByteBuffer* aData);
|
|
void Ended();
|
|
bool IsEnded()
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
return mEnded;
|
|
}
|
|
// Remove data from resource if it holds more than the threshold reduced by
|
|
// the given number of bytes. Returns amount evicted.
|
|
uint32_t EvictData(uint64_t aPlaybackOffset, int64_t aThresholdReduct,
|
|
ErrorResult& aRv);
|
|
|
|
// Remove data from resource before the given offset.
|
|
void EvictBefore(uint64_t aOffset, ErrorResult& aRv);
|
|
|
|
// Remove all data from the resource
|
|
uint32_t EvictAll();
|
|
|
|
// Returns the amount of data currently retained by this resource.
|
|
int64_t GetSize() {
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
return mInputBuffer.GetLength() - mInputBuffer.GetOffset();
|
|
}
|
|
|
|
#if defined(DEBUG)
|
|
void Dump(const char* aPath) {
|
|
mInputBuffer.Dump(aPath);
|
|
}
|
|
#endif
|
|
|
|
private:
|
|
virtual ~SourceBufferResource();
|
|
nsresult ReadAtInternal(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes, bool aMayBlock);
|
|
|
|
const MediaContainerType mType;
|
|
|
|
// Provides synchronization between SourceBuffers and InputAdapters.
|
|
// Protects all of the member variables below. Read() will await a
|
|
// Notify() (from Seek, AppendData, Ended, or Close) when insufficient
|
|
// data is available in mData.
|
|
mutable ReentrantMonitor mMonitor;
|
|
|
|
// The buffer holding resource data.
|
|
ResourceQueue mInputBuffer;
|
|
|
|
uint64_t mOffset;
|
|
bool mClosed;
|
|
bool mEnded;
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#undef UNIMPLEMENTED
|
|
|
|
#endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */
|