|
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 #ifdef MOZILLA_INTERNAL_API |
|
9 #include "mozilla/dom/MediaStreamListBinding.h" |
|
10 #endif |
|
11 #include "nsIScriptGlobalObject.h" |
|
12 #include "PeerConnectionImpl.h" |
|
13 #include "PeerConnectionMedia.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace dom { |
|
17 |
|
18 MediaStreamList::MediaStreamList(sipcc::PeerConnectionImpl* peerConnection, |
|
19 StreamType type) |
|
20 : mPeerConnection(peerConnection), |
|
21 mType(type) |
|
22 { |
|
23 SetIsDOMBinding(); |
|
24 } |
|
25 |
|
26 MediaStreamList::~MediaStreamList() |
|
27 { |
|
28 } |
|
29 |
|
30 #ifdef MOZILLA_INTERNAL_API |
|
31 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaStreamList) |
|
32 #else |
|
33 NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamList) |
|
34 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamList) |
|
35 NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
|
36 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MediaStreamList) |
|
37 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
|
38 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MediaStreamList) |
|
39 NS_IMPL_CYCLE_COLLECTION_TRACE_END |
|
40 #endif |
|
41 |
|
42 NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamList) |
|
43 NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamList) |
|
44 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamList) |
|
45 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
46 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
47 NS_INTERFACE_MAP_END |
|
48 |
|
49 JSObject* |
|
50 MediaStreamList::WrapObject(JSContext* cx) |
|
51 { |
|
52 #ifdef MOZILLA_INTERNAL_API |
|
53 return MediaStreamListBinding::Wrap(cx, this); |
|
54 #else |
|
55 return nullptr; |
|
56 #endif |
|
57 } |
|
58 |
|
59 nsISupports* |
|
60 MediaStreamList::GetParentObject() |
|
61 { |
|
62 return mPeerConnection->GetWindow(); |
|
63 } |
|
64 |
|
65 template<class T> |
|
66 static DOMMediaStream* |
|
67 GetStreamFromInfo(T* info, bool& found) |
|
68 { |
|
69 if (!info) { |
|
70 found = false; |
|
71 return nullptr; |
|
72 } |
|
73 |
|
74 found = true; |
|
75 return info->GetMediaStream(); |
|
76 } |
|
77 |
|
78 DOMMediaStream* |
|
79 MediaStreamList::IndexedGetter(uint32_t index, bool& found) |
|
80 { |
|
81 if (!mPeerConnection->media()) { // PeerConnection closed |
|
82 found = false; |
|
83 return nullptr; |
|
84 } |
|
85 if (mType == Local) { |
|
86 return GetStreamFromInfo(mPeerConnection->media()-> |
|
87 GetLocalStream(index), found); |
|
88 } |
|
89 |
|
90 return GetStreamFromInfo(mPeerConnection->media()-> |
|
91 GetRemoteStream(index), found); |
|
92 } |
|
93 |
|
94 uint32_t |
|
95 MediaStreamList::Length() |
|
96 { |
|
97 if (!mPeerConnection->media()) { // PeerConnection closed |
|
98 return 0; |
|
99 } |
|
100 return mType == Local ? mPeerConnection->media()->LocalStreamsLength() : |
|
101 mPeerConnection->media()->RemoteStreamsLength(); |
|
102 } |
|
103 |
|
104 } // namespace dom |
|
105 } // namespace mozilla |