Bug 1062666 - Add a debug-only dump method to MediaSource for debugging issues with appended data.

This commit is contained in:
Matthew Gregan 2014-09-09 17:58:18 +12:00
parent 09e4e096d1
commit fb4f149b1f
11 changed files with 101 additions and 1 deletions

View File

@ -28,6 +28,11 @@
#include "nsThreadUtils.h"
#include "prlog.h"
#if defined(DEBUG)
#include <sys/stat.h>
#include <sys/types.h>
#endif
struct JSContext;
class JSObject;
@ -507,6 +512,20 @@ MediaSource::InitializationEvent()
}
}
#if defined(DEBUG)
void
MediaSource::Dump(const char* aPath)
{
char buf[255];
PR_snprintf(buf, sizeof(buf), "%s/mediasource-%p", aPath, this);
mkdir(buf, 0700);
if (mSourceBuffers) {
mSourceBuffers->Dump(buf);
}
}
#endif
nsPIDOMWindow*
MediaSource::GetParentObject() const
{

View File

@ -98,6 +98,12 @@ public:
// initialization.
void QueueInitializationEvent();
#if defined(DEBUG)
// Dump the contents of each SourceBuffer to a series of files under aPath.
// aPath must exist. Debug only, invoke from your favourite debugger.
void Dump(const char* aPath);
#endif
private:
~MediaSource();

View File

@ -134,6 +134,23 @@ public:
return size;
}
#if defined(DEBUG)
void Dump(const char* aPath) {
for (uint32_t i = 0; i < uint32_t(GetSize()); ++i) {
ResourceItem* item = ResourceAt(i);
char buf[255];
PR_snprintf(buf, sizeof(buf), "%s/%08u.bin", aPath, i);
FILE* fp = fopen(buf, "wb");
if (!fp) {
return;
}
fwrite(item->mData.Elements(), item->mData.Length(), 1, fp);
fclose(fp);
}
}
#endif
private:
ResourceItem* ResourceAt(uint32_t aIndex) const {
return static_cast<ResourceItem*>(ObjectAt(aIndex));
@ -173,6 +190,5 @@ private:
uint64_t mOffset;
};
} // namespace mozilla
#endif /* MOZILLA_RESOURCEQUEUE_H_ */

View File

@ -1,3 +1,4 @@
/* -*- 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
@ -687,6 +688,16 @@ SourceBuffer::Evict(double aStart, double aEnd)
mTrackBuffer->EvictBefore(evictTime);
}
#if defined(DEBUG)
void
SourceBuffer::Dump(const char* aPath)
{
if (mTrackBuffer) {
mTrackBuffer->Dump(aPath);
}
}
#endif
NS_IMPL_CYCLE_COLLECTION_INHERITED(SourceBuffer, DOMEventTargetHelper,
mMediaSource)

View File

@ -109,6 +109,10 @@ public:
double GetBufferedStart();
double GetBufferedEnd();
#if defined(DEBUG)
void Dump(const char* aPath);
#endif
private:
~SourceBuffer();

View File

@ -1,3 +1,4 @@
/* -*- 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

View File

@ -167,6 +167,16 @@ SourceBufferList::QueueAsyncSimpleEvent(const char* aName)
NS_DispatchToMainThread(event);
}
#if defined(DEBUG)
void
SourceBufferList::Dump(const char* aPath)
{
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
mSourceBuffers[i]->Dump(aPath);
}
}
#endif
SourceBufferList::SourceBufferList(MediaSource* aMediaSource)
: DOMEventTargetHelper(aMediaSource->GetParentObject())
, mMediaSource(aMediaSource)

View File

@ -79,6 +79,10 @@ public:
// Returns the highest end time of any of the Sourcebuffers.
double GetHighestBufferedEndTime();
#if defined(DEBUG)
void Dump(const char* aPath);
#endif
private:
~SourceBufferList();

View File

@ -120,6 +120,12 @@ public:
// Remove data from resource before the given offset.
void EvictBefore(uint64_t aOffset);
#if defined(DEBUG)
void Dump(const char* aPath) {
mInputBuffer.Dump(aPath);
}
#endif
private:
~SourceBufferResource();
nsresult SeekInternal(int64_t aOffset);

View File

@ -1,3 +1,4 @@
/* -*- 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
@ -349,4 +350,22 @@ TrackBuffer::Decoders()
return mInitializedDecoders;
}
#if defined(DEBUG)
void
TrackBuffer::Dump(const char* aPath)
{
char path[255];
PR_snprintf(path, sizeof(path), "%s/trackbuffer-%p", aPath, this);
mkdir(path, 0700);
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
char buf[255];
PR_snprintf(buf, sizeof(buf), "%s/reader-%p", path, mDecoders[i]->GetReader());
mkdir(buf, 0700);
mDecoders[i]->GetResource()->Dump(buf);
}
}
#endif
} // namespace mozilla

View File

@ -82,6 +82,10 @@ public:
// TODO: Refactor to a cleaner interface between TrackBuffer and MediaSourceReader.
const nsTArray<nsRefPtr<SourceBufferDecoder>>& Decoders();
#if defined(DEBUG)
void Dump(const char* aPath);
#endif
private:
~TrackBuffer();