2013-06-21 07:14:42 +04: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/. */
|
|
|
|
|
|
|
|
#include "SourceBufferList.h"
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "AsyncEventRunner.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-06-21 07:14:42 +04:00
|
|
|
#include "mozilla/dom/SourceBufferListBinding.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIRunnable.h"
|
2014-08-20 12:14:00 +04:00
|
|
|
#include "nsString.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern mozilla::LogModule* GetMediaSourceLog();
|
|
|
|
extern mozilla::LogModule* GetMediaSourceAPILog();
|
2015-02-28 01:37:52 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBufferList(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
|
|
|
|
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBufferList(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2015-02-12 10:52:13 +03:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
namespace mozilla {
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
SourceBufferList::~SourceBufferList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
SourceBuffer*
|
|
|
|
SourceBufferList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
aFound = aIndex < mSourceBuffers.Length();
|
2015-08-13 15:22:48 +03:00
|
|
|
|
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mSourceBuffers[aIndex];
|
2013-06-21 07:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SourceBufferList::Length()
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
return mSourceBuffers.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBufferList::Append(SourceBuffer* aSourceBuffer)
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
mSourceBuffers.AppendElement(aSourceBuffer);
|
|
|
|
QueueAsyncSimpleEvent("addsourcebuffer");
|
|
|
|
}
|
|
|
|
|
2015-03-18 06:10:56 +03:00
|
|
|
void
|
|
|
|
SourceBufferList::AppendSimple(SourceBuffer* aSourceBuffer)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mSourceBuffers.AppendElement(aSourceBuffer);
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
void
|
|
|
|
SourceBufferList::Remove(SourceBuffer* aSourceBuffer)
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
MOZ_ALWAYS_TRUE(mSourceBuffers.RemoveElement(aSourceBuffer));
|
2013-09-27 09:22:37 +04:00
|
|
|
aSourceBuffer->Detach();
|
2013-06-21 07:14:42 +04:00
|
|
|
QueueAsyncSimpleEvent("removesourcebuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SourceBufferList::Contains(SourceBuffer* aSourceBuffer)
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
return mSourceBuffers.Contains(aSourceBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBufferList::Clear()
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-09-27 09:22:37 +04:00
|
|
|
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
|
|
|
|
mSourceBuffers[i]->Detach();
|
|
|
|
}
|
2013-06-21 07:14:42 +04:00
|
|
|
mSourceBuffers.Clear();
|
|
|
|
QueueAsyncSimpleEvent("removesourcebuffer");
|
|
|
|
}
|
|
|
|
|
2015-03-18 06:10:56 +03:00
|
|
|
void
|
|
|
|
SourceBufferList::ClearSimple()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mSourceBuffers.Clear();
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
bool
|
|
|
|
SourceBufferList::IsEmpty()
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
return mSourceBuffers.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SourceBufferList::AnyUpdating()
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 07:14:42 +04:00
|
|
|
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
|
|
|
|
if (mSourceBuffers[i]->Updating()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-19 07:16:41 +03:00
|
|
|
SourceBufferList::RangeRemoval(double aStart, double aEnd)
|
2013-06-21 07:14:42 +04:00
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 10:52:13 +03:00
|
|
|
MSE_DEBUG("RangeRemoval(aStart=%f, aEnd=%f)", aStart, aEnd);
|
2013-06-21 07:14:42 +04:00
|
|
|
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
|
2014-11-19 07:16:41 +03:00
|
|
|
mSourceBuffers[i]->RangeRemoval(aStart, aEnd);
|
2013-06-21 07:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
void
|
|
|
|
SourceBufferList::Ended()
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-09-27 09:22:37 +04:00
|
|
|
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
|
|
|
|
mSourceBuffers[i]->Ended();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 05:21:18 +04:00
|
|
|
double
|
|
|
|
SourceBufferList::GetHighestBufferedEndTime()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-08-20 12:07:00 +04:00
|
|
|
double highestEndTime = 0;
|
2014-08-11 05:21:18 +04:00
|
|
|
for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
|
2014-08-20 12:07:00 +04:00
|
|
|
highestEndTime = std::max(highestEndTime, mSourceBuffers[i]->GetBufferedEnd());
|
2014-08-11 05:21:18 +04:00
|
|
|
}
|
2014-08-20 12:07:00 +04:00
|
|
|
return highestEndTime;
|
2014-08-11 05:21:18 +04:00
|
|
|
}
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
void
|
|
|
|
SourceBufferList::DispatchSimpleEvent(const char* aName)
|
|
|
|
{
|
2014-08-11 05:21:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 10:52:13 +03:00
|
|
|
MSE_API("Dispatch event '%s'", aName);
|
2013-06-21 07:14:42 +04:00
|
|
|
DispatchTrustedEvent(NS_ConvertUTF8toUTF16(aName));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBufferList::QueueAsyncSimpleEvent(const char* aName)
|
|
|
|
{
|
2015-02-12 10:52:13 +03:00
|
|
|
MSE_DEBUG("Queue event '%s'", aName);
|
2013-09-27 09:22:37 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event = new AsyncEventRunner<SourceBufferList>(this, aName);
|
2014-05-23 23:53:17 +04:00
|
|
|
NS_DispatchToMainThread(event);
|
2013-06-21 07:14:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceBufferList::SourceBufferList(MediaSource* aMediaSource)
|
2014-04-01 10:13:50 +04:00
|
|
|
: DOMEventTargetHelper(aMediaSource->GetParentObject())
|
2013-06-21 07:14:42 +04:00
|
|
|
, mMediaSource(aMediaSource)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aMediaSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaSource*
|
|
|
|
SourceBufferList::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mMediaSource;
|
|
|
|
}
|
|
|
|
|
2016-07-15 16:38:33 +03:00
|
|
|
double
|
|
|
|
SourceBufferList::HighestStartTime()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
double highestStartTime = 0;
|
|
|
|
for (auto& sourceBuffer : mSourceBuffers) {
|
|
|
|
highestStartTime =
|
|
|
|
std::max(sourceBuffer->HighestStartTime(), highestStartTime);
|
|
|
|
}
|
|
|
|
return highestStartTime;
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
SourceBufferList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-06-21 07:14:42 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return SourceBufferListBinding::Wrap(aCx, this, aGivenProto);
|
2013-06-21 07:14:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SourceBufferList, DOMEventTargetHelper,
|
|
|
|
mMediaSource, mSourceBuffers)
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SourceBufferList, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SourceBufferList, DOMEventTargetHelper)
|
2013-06-21 07:14:42 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SourceBufferList)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2015-02-12 10:52:13 +03:00
|
|
|
#undef MSE_API
|
|
|
|
#undef MSE_DEBUG
|
2013-06-21 07:14:42 +04:00
|
|
|
} // namespace dom
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
} // namespace mozilla
|