mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1199032: [webm] P1. Explicitly differentiate WebM usage for mediasource. r=kinetik
Relying on the data being fully buffered or not turned out to not be such a great idea.
This commit is contained in:
parent
c10803aa80
commit
7447908c34
@ -42,23 +42,17 @@ static int webmdemux_read(void* aBuffer, size_t aLength, void* aUserData)
|
||||
MOZ_ASSERT(aUserData);
|
||||
MOZ_ASSERT(aLength < UINT32_MAX);
|
||||
WebMDemuxer* demuxer = reinterpret_cast<WebMDemuxer*>(aUserData);
|
||||
int64_t length = demuxer->GetEndDataOffset();
|
||||
uint32_t count = aLength;
|
||||
int64_t position = demuxer->GetResource()->Tell();
|
||||
if (position >= length) {
|
||||
// GetLastBlockOffset was calculated after we had read past it.
|
||||
// This condition can only occurs with plain webm, as with MSE,
|
||||
// EnsureUpdateIndex would have been called first.
|
||||
// Continue reading to the end instead.
|
||||
length = demuxer->GetResource()->GetLength();
|
||||
if (demuxer->IsMediaSource()) {
|
||||
int64_t length = demuxer->GetEndDataOffset();
|
||||
int64_t position = demuxer->GetResource()->Tell();
|
||||
MOZ_ASSERT(position <= demuxer->GetResource()->GetLength());
|
||||
MOZ_ASSERT(position <= length);
|
||||
if (length >= 0 && count + position > length) {
|
||||
count = length - position;
|
||||
}
|
||||
MOZ_ASSERT(count <= aLength);
|
||||
}
|
||||
MOZ_ASSERT(position <= demuxer->GetResource()->GetLength());
|
||||
MOZ_ASSERT(position <= length);
|
||||
if (length >= 0 && count + position > length) {
|
||||
count = length - position;
|
||||
}
|
||||
MOZ_ASSERT(count <= aLength);
|
||||
|
||||
uint32_t bytes = 0;
|
||||
nsresult rv =
|
||||
demuxer->GetResource()->Read(static_cast<char*>(aBuffer), count, &bytes);
|
||||
@ -125,6 +119,11 @@ static void webmdemux_log(nestegg* aContext,
|
||||
|
||||
|
||||
WebMDemuxer::WebMDemuxer(MediaResource* aResource)
|
||||
: WebMDemuxer(aResource, false)
|
||||
{
|
||||
}
|
||||
|
||||
WebMDemuxer::WebMDemuxer(MediaResource* aResource, bool aIsMediaSource)
|
||||
: mResource(aResource)
|
||||
, mBufferedState(nullptr)
|
||||
, mInitData(nullptr)
|
||||
@ -140,7 +139,7 @@ WebMDemuxer::WebMDemuxer(MediaResource* aResource)
|
||||
, mHasAudio(false)
|
||||
, mNeedReIndex(true)
|
||||
, mLastWebMBlockOffset(-1)
|
||||
, mIsExpectingMoreData(true)
|
||||
, mIsMediaSource(aIsMediaSource)
|
||||
{
|
||||
if (!gNesteggLog) {
|
||||
gNesteggLog = PR_NewLogModule("Nestegg");
|
||||
@ -454,10 +453,13 @@ WebMDemuxer::EnsureUpToDateIndex()
|
||||
if (!mInitData && mBufferedState->GetInitEndOffset() != -1) {
|
||||
mInitData = mResource.MediaReadAt(0, mBufferedState->GetInitEndOffset());
|
||||
}
|
||||
mLastWebMBlockOffset = mBufferedState->GetLastBlockOffset();
|
||||
mIsExpectingMoreData = mResource.GetResource()->IsExpectingMoreData();
|
||||
MOZ_ASSERT(mLastWebMBlockOffset <= mResource.GetLength());
|
||||
mNeedReIndex = false;
|
||||
|
||||
if (!mIsMediaSource) {
|
||||
return;
|
||||
}
|
||||
mLastWebMBlockOffset = mBufferedState->GetLastBlockOffset();
|
||||
MOZ_ASSERT(mLastWebMBlockOffset <= mResource.GetLength());
|
||||
}
|
||||
|
||||
void
|
||||
@ -483,7 +485,9 @@ WebMDemuxer::GetCrypto()
|
||||
bool
|
||||
WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType, MediaRawDataQueue *aSamples)
|
||||
{
|
||||
EnsureUpToDateIndex();
|
||||
if (mIsMediaSource) {
|
||||
EnsureUpToDateIndex();
|
||||
}
|
||||
|
||||
nsRefPtr<NesteggPacketHolder> holder(NextPacket(aType));
|
||||
|
||||
|
@ -54,7 +54,10 @@ class WebMDemuxer : public MediaDataDemuxer
|
||||
{
|
||||
public:
|
||||
explicit WebMDemuxer(MediaResource* aResource);
|
||||
|
||||
// Indicate if the WebMDemuxer is to be used with MediaSource. In which
|
||||
// case the demuxer will stop reads to the last known complete block.
|
||||
WebMDemuxer(MediaResource* aResource, bool aIsMediaSource);
|
||||
|
||||
nsRefPtr<InitPromise> Init() override;
|
||||
|
||||
already_AddRefed<MediaDataDemuxer> Clone() const override;
|
||||
@ -91,11 +94,15 @@ public:
|
||||
return &mResource;
|
||||
}
|
||||
|
||||
int64_t GetEndDataOffset()
|
||||
int64_t GetEndDataOffset() const
|
||||
{
|
||||
return mLastWebMBlockOffset < 0 || mIsExpectingMoreData
|
||||
return (!mIsMediaSource || mLastWebMBlockOffset < 0)
|
||||
? mResource.GetLength() : mLastWebMBlockOffset;
|
||||
}
|
||||
int64_t IsMediaSource() const
|
||||
{
|
||||
return mIsMediaSource;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class WebMTrackDemuxer;
|
||||
@ -169,7 +176,7 @@ private:
|
||||
// We cache those values rather than retrieving them for performance reasons
|
||||
// as nestegg only performs 1-byte read at a time.
|
||||
int64_t mLastWebMBlockOffset;
|
||||
bool mIsExpectingMoreData;
|
||||
const bool mIsMediaSource;
|
||||
};
|
||||
|
||||
class WebMTrackDemuxer : public MediaTrackDemuxer
|
||||
|
Loading…
Reference in New Issue
Block a user