media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "CSFLog.h"
     1.9 +#include "base/basictypes.h"
    1.10 +#include "MediaStreamList.h"
    1.11 +#ifdef MOZILLA_INTERNAL_API
    1.12 +#include "mozilla/dom/MediaStreamListBinding.h"
    1.13 +#endif
    1.14 +#include "nsIScriptGlobalObject.h"
    1.15 +#include "PeerConnectionImpl.h"
    1.16 +#include "PeerConnectionMedia.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace dom {
    1.20 +
    1.21 +MediaStreamList::MediaStreamList(sipcc::PeerConnectionImpl* peerConnection,
    1.22 +                                 StreamType type)
    1.23 +  : mPeerConnection(peerConnection),
    1.24 +    mType(type)
    1.25 +{
    1.26 +  SetIsDOMBinding();
    1.27 +}
    1.28 +
    1.29 +MediaStreamList::~MediaStreamList()
    1.30 +{
    1.31 +}
    1.32 +
    1.33 +#ifdef MOZILLA_INTERNAL_API
    1.34 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaStreamList)
    1.35 +#else
    1.36 +NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamList)
    1.37 +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamList)
    1.38 +NS_IMPL_CYCLE_COLLECTION_UNLINK_END
    1.39 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MediaStreamList)
    1.40 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
    1.41 +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MediaStreamList)
    1.42 +NS_IMPL_CYCLE_COLLECTION_TRACE_END
    1.43 +#endif
    1.44 +
    1.45 +NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamList)
    1.46 +NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamList)
    1.47 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamList)
    1.48 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1.49 +  NS_INTERFACE_MAP_ENTRY(nsISupports)
    1.50 +NS_INTERFACE_MAP_END
    1.51 +
    1.52 +JSObject*
    1.53 +MediaStreamList::WrapObject(JSContext* cx)
    1.54 +{
    1.55 +#ifdef MOZILLA_INTERNAL_API
    1.56 +  return MediaStreamListBinding::Wrap(cx, this);
    1.57 +#else
    1.58 +  return nullptr;
    1.59 +#endif
    1.60 +}
    1.61 +
    1.62 +nsISupports*
    1.63 +MediaStreamList::GetParentObject()
    1.64 +{
    1.65 +  return mPeerConnection->GetWindow();
    1.66 +}
    1.67 +
    1.68 +template<class T>
    1.69 +static DOMMediaStream*
    1.70 +GetStreamFromInfo(T* info, bool& found)
    1.71 +{
    1.72 +  if (!info) {
    1.73 +    found = false;
    1.74 +    return nullptr;
    1.75 +  }
    1.76 +
    1.77 +  found = true;
    1.78 +  return info->GetMediaStream();
    1.79 +}
    1.80 +
    1.81 +DOMMediaStream*
    1.82 +MediaStreamList::IndexedGetter(uint32_t index, bool& found)
    1.83 +{
    1.84 +  if (!mPeerConnection->media()) { // PeerConnection closed
    1.85 +    found = false;
    1.86 +    return nullptr;
    1.87 +  }
    1.88 +  if (mType == Local) {
    1.89 +    return GetStreamFromInfo(mPeerConnection->media()->
    1.90 +      GetLocalStream(index), found);
    1.91 +  }
    1.92 +
    1.93 +  return GetStreamFromInfo(mPeerConnection->media()->
    1.94 +    GetRemoteStream(index), found);
    1.95 +}
    1.96 +
    1.97 +uint32_t
    1.98 +MediaStreamList::Length()
    1.99 +{
   1.100 +  if (!mPeerConnection->media()) { // PeerConnection closed
   1.101 +    return 0;
   1.102 +  }
   1.103 +  return mType == Local ? mPeerConnection->media()->LocalStreamsLength() :
   1.104 +      mPeerConnection->media()->RemoteStreamsLength();
   1.105 +}
   1.106 +
   1.107 +} // namespace dom
   1.108 +} // namespace mozilla

mercurial