Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #include "CSFLog.h"
6 : #include "base/basictypes.h"
7 : #include "MediaStreamList.h"
8 : #include "mozilla/dom/MediaStreamListBinding.h"
9 : #include "nsIScriptGlobalObject.h"
10 : #include "PeerConnectionImpl.h"
11 : #include "PeerConnectionMedia.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 0 : MediaStreamList::MediaStreamList(PeerConnectionImpl* peerConnection,
17 0 : StreamType type)
18 : : mPeerConnection(peerConnection),
19 0 : mType(type)
20 : {
21 0 : }
22 :
23 0 : MediaStreamList::~MediaStreamList()
24 : {
25 0 : }
26 :
27 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaStreamList)
28 :
29 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamList)
30 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamList)
31 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamList)
32 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
33 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
34 0 : NS_INTERFACE_MAP_END
35 :
36 : JSObject*
37 0 : MediaStreamList::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
38 : {
39 0 : return MediaStreamListBinding::Wrap(cx, this, aGivenProto);
40 : }
41 :
42 : nsISupports*
43 0 : MediaStreamList::GetParentObject()
44 : {
45 0 : return mPeerConnection->GetWindow();
46 : }
47 :
48 : template<class T>
49 : static DOMMediaStream*
50 0 : GetStreamFromInfo(T* info, bool& found)
51 : {
52 0 : if (!info) {
53 0 : found = false;
54 0 : return nullptr;
55 : }
56 :
57 0 : found = true;
58 0 : return info->GetMediaStream();
59 : }
60 :
61 : DOMMediaStream*
62 0 : MediaStreamList::IndexedGetter(uint32_t index, bool& found)
63 : {
64 0 : if (!mPeerConnection->media()) { // PeerConnection closed
65 0 : found = false;
66 0 : return nullptr;
67 : }
68 0 : if (mType == Local) {
69 0 : return GetStreamFromInfo(mPeerConnection->media()->
70 0 : GetLocalStreamByIndex(index), found);
71 : }
72 :
73 0 : return GetStreamFromInfo(mPeerConnection->media()->
74 0 : GetRemoteStreamByIndex(index), found);
75 : }
76 :
77 : uint32_t
78 0 : MediaStreamList::Length()
79 : {
80 0 : if (!mPeerConnection->media()) { // PeerConnection closed
81 0 : return 0;
82 : }
83 0 : return mType == Local ? mPeerConnection->media()->LocalStreamsLength() :
84 0 : mPeerConnection->media()->RemoteStreamsLength();
85 : }
86 :
87 : } // namespace dom
88 : } // namespace mozilla
|