michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "CSFLog.h" michael@0: #include "base/basictypes.h" michael@0: #include "MediaStreamList.h" michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: #include "mozilla/dom/MediaStreamListBinding.h" michael@0: #endif michael@0: #include "nsIScriptGlobalObject.h" michael@0: #include "PeerConnectionImpl.h" michael@0: #include "PeerConnectionMedia.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: MediaStreamList::MediaStreamList(sipcc::PeerConnectionImpl* peerConnection, michael@0: StreamType type) michael@0: : mPeerConnection(peerConnection), michael@0: mType(type) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: MediaStreamList::~MediaStreamList() michael@0: { michael@0: } michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaStreamList) michael@0: #else michael@0: NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamList) michael@0: NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamList) michael@0: NS_IMPL_CYCLE_COLLECTION_UNLINK_END michael@0: NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MediaStreamList) michael@0: NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END michael@0: NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MediaStreamList) michael@0: NS_IMPL_CYCLE_COLLECTION_TRACE_END michael@0: #endif michael@0: michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamList) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamList) michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamList) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: JSObject* michael@0: MediaStreamList::WrapObject(JSContext* cx) michael@0: { michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: return MediaStreamListBinding::Wrap(cx, this); michael@0: #else michael@0: return nullptr; michael@0: #endif michael@0: } michael@0: michael@0: nsISupports* michael@0: MediaStreamList::GetParentObject() michael@0: { michael@0: return mPeerConnection->GetWindow(); michael@0: } michael@0: michael@0: template michael@0: static DOMMediaStream* michael@0: GetStreamFromInfo(T* info, bool& found) michael@0: { michael@0: if (!info) { michael@0: found = false; michael@0: return nullptr; michael@0: } michael@0: michael@0: found = true; michael@0: return info->GetMediaStream(); michael@0: } michael@0: michael@0: DOMMediaStream* michael@0: MediaStreamList::IndexedGetter(uint32_t index, bool& found) michael@0: { michael@0: if (!mPeerConnection->media()) { // PeerConnection closed michael@0: found = false; michael@0: return nullptr; michael@0: } michael@0: if (mType == Local) { michael@0: return GetStreamFromInfo(mPeerConnection->media()-> michael@0: GetLocalStream(index), found); michael@0: } michael@0: michael@0: return GetStreamFromInfo(mPeerConnection->media()-> michael@0: GetRemoteStream(index), found); michael@0: } michael@0: michael@0: uint32_t michael@0: MediaStreamList::Length() michael@0: { michael@0: if (!mPeerConnection->media()) { // PeerConnection closed michael@0: return 0; michael@0: } michael@0: return mType == Local ? mPeerConnection->media()->LocalStreamsLength() : michael@0: mPeerConnection->media()->RemoteStreamsLength(); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla