Bug 902003: Dispatch getStats to STS thread and back. r=jesup

This commit is contained in:
Byron Campen [:bwc] 2013-10-11 17:13:09 -07:00
Родитель b04d27e132
Коммит 04ecca00f8
2 изменённых файлов: 70 добавлений и 1 удалений

Просмотреть файл

@ -53,10 +53,12 @@
#include "nsNetUtil.h"
#include "nsIDOMDataChannel.h"
#include "mozilla/dom/RTCConfigurationBinding.h"
#include "mozilla/dom/RTCStatsReportBinding.h"
#include "mozilla/dom/RTCPeerConnectionBinding.h"
#include "mozilla/dom/PeerConnectionImplBinding.h"
#include "mozilla/dom/DataChannelBinding.h"
#include "MediaStreamList.h"
#include "MediaStreamTrack.h"
#include "nsIScriptGlobalObject.h"
#include "jsapi.h"
#include "DOMMediaStream.h"
@ -1127,7 +1129,20 @@ NS_IMETHODIMP
PeerConnectionImpl::GetStats(mozilla::dom::MediaStreamTrack *aSelector) {
PC_AUTO_ENTER_API_CALL(true);
// TODO: Insert dispatch to STS here.
#ifdef MOZILLA_INTERNAL_API
uint32_t track = aSelector ? aSelector->GetTrackID() : 0;
DOMHighResTimeStamp now;
nsresult rv = GetTimeSinceEpoch(&now);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<PeerConnectionImpl> pc(this);
RUN_ON_THREAD(mSTSThread,
WrapRunnable(pc,
&PeerConnectionImpl::GetStats_s,
track,
now),
NS_DISPATCH_NORMAL);
#endif
return NS_OK;
}
@ -1630,6 +1645,48 @@ PeerConnectionImpl::IceStateChange_m(PCImplIceState aState)
return NS_OK;
}
#ifdef MOZILLA_INTERNAL_API
void PeerConnectionImpl::GetStats_s(
uint32_t trackId,
DOMHighResTimeStamp now) {
nsresult result = NS_OK;
nsAutoPtr<RTCStatsReportInternal> report(new RTCStatsReportInternal);
if (!report) {
result = NS_ERROR_FAILURE;
}
nsRefPtr<PeerConnectionImpl> pc(this);
RUN_ON_THREAD(mThread,
WrapRunnable(pc,
&PeerConnectionImpl::OnStatsReport_m,
trackId,
result,
report),
NS_DISPATCH_NORMAL);
}
void PeerConnectionImpl::OnStatsReport_m(
uint32_t trackId,
nsresult result,
nsAutoPtr<mozilla::dom::RTCStatsReportInternal> report) {
PeerConnectionObserver* pco = mPCObserver.MayGet();
if (pco) {
JSErrorResult rv;
if (NS_SUCCEEDED(result)) {
pco->OnGetStatsSuccess(*report, rv);
} else {
pco->OnGetStatsError(kInternalError,
ObString("Failed to fetch statistics"),
rv);
}
if (rv.Failed()) {
CSFLogError(logTag, "Error firing stats observer callback");
}
}
}
#endif
void
PeerConnectionImpl::IceStreamReady(NrIceMediaStream *aStream)
{

Просмотреть файл

@ -61,6 +61,7 @@ namespace dom {
class RTCConfiguration;
class MediaConstraintsInternal;
class MediaStreamTrack;
class RTCStatsReportInternal;
#ifdef USE_FAKE_PCOBSERVER
typedef test::AFakePCObserver PeerConnectionObserver;
@ -476,6 +477,17 @@ private:
// ICE callbacks run on the right thread.
nsresult IceStateChange_m(mozilla::dom::PCImplIceState aState);
#ifdef MOZILLA_INTERNAL_API
// Fills in an RTCStatsReportInternal. Must be run on STS.
void GetStats_s(uint32_t trackId,
DOMHighResTimeStamp now);
// Sends an RTCStatsReport to JS. Must run on main thread.
void OnStatsReport_m(uint32_t trackId,
nsresult result,
nsAutoPtr<mozilla::dom::RTCStatsReportInternal> report);
#endif
// Timecard used to measure processing time. This should be the first class
// attribute so that we accurately measure the time required to instantiate
// any other attributes of this class.