зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1425901: Use nsITimerCallback for DTMF timers. r=drno
MozReview-Commit-ID: 2IlDknNhlAG --HG-- extra : rebase_source : 3c51e468c2285b5714372108c6ef5f41f8ba00d5
This commit is contained in:
Родитель
208554ebe1
Коммит
a6bb393781
|
@ -2336,8 +2336,8 @@ PeerConnectionImpl::RemoveTrack(MediaStreamTrack& aTrack) {
|
||||||
if (transceiver->HasSendTrack(&aTrack)) {
|
if (transceiver->HasSendTrack(&aTrack)) {
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
for (size_t i = 0; i < mDTMFStates.Length(); ++i) {
|
for (size_t i = 0; i < mDTMFStates.Length(); ++i) {
|
||||||
if (mDTMFStates[i].mTransceiver.get() == transceiver.get()) {
|
if (mDTMFStates[i]->mTransceiver.get() == transceiver.get()) {
|
||||||
mDTMFStates[i].mSendTimer->Cancel();
|
mDTMFStates[i]->mSendTimer->Cancel();
|
||||||
mDTMFStates.RemoveElementAt(i);
|
mDTMFStates.RemoveElementAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2439,17 +2439,17 @@ PeerConnectionImpl::InsertDTMF(TransceiverImpl& transceiver,
|
||||||
|
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
// Attempt to locate state for the DTMFSender
|
// Attempt to locate state for the DTMFSender
|
||||||
DTMFState* state = nullptr;
|
RefPtr<DTMFState> state;
|
||||||
for (auto& dtmfState : mDTMFStates) {
|
for (auto& dtmfState : mDTMFStates) {
|
||||||
if (dtmfState.mTransceiver.get() == &transceiver) {
|
if (dtmfState->mTransceiver.get() == &transceiver) {
|
||||||
state = &dtmfState;
|
state = dtmfState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No state yet, create a new one
|
// No state yet, create a new one
|
||||||
if (!state) {
|
if (!state) {
|
||||||
state = mDTMFStates.AppendElement();
|
state = *mDTMFStates.AppendElement(new DTMFState);
|
||||||
state->mPCObserver = mPCObserver;
|
state->mPCObserver = mPCObserver;
|
||||||
state->mTransceiver = &transceiver;
|
state->mTransceiver = &transceiver;
|
||||||
state->mSendTimer = NS_NewTimer();
|
state->mSendTimer = NS_NewTimer();
|
||||||
|
@ -2460,9 +2460,7 @@ PeerConnectionImpl::InsertDTMF(TransceiverImpl& transceiver,
|
||||||
state->mDuration = duration;
|
state->mDuration = duration;
|
||||||
state->mInterToneGap = interToneGap;
|
state->mInterToneGap = interToneGap;
|
||||||
if (!state->mTones.IsEmpty()) {
|
if (!state->mTones.IsEmpty()) {
|
||||||
state->mSendTimer->InitWithNamedFuncCallback(DTMFSendTimerCallback_m, state, 0,
|
state->mSendTimer->InitWithCallback(state, 0, nsITimer::TYPE_ONE_SHOT);
|
||||||
nsITimer::TYPE_ONE_SHOT,
|
|
||||||
"DTMFSendTimerCallback_m");
|
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -2485,8 +2483,8 @@ PeerConnectionImpl::GetDTMFToneBuffer(mozilla::dom::RTCRtpSender& sender,
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
// Attempt to locate state for the DTMFSender
|
// Attempt to locate state for the DTMFSender
|
||||||
for (auto& dtmfState : mDTMFStates) {
|
for (auto& dtmfState : mDTMFStates) {
|
||||||
if (dtmfState.mTransceiver->HasSendTrack(mst)) {
|
if (dtmfState->mTransceiver->HasSendTrack(mst)) {
|
||||||
outToneBuffer = dtmfState.mTones;
|
outToneBuffer = dtmfState->mTones;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2514,8 +2512,8 @@ PeerConnectionImpl::ReplaceTrackNoRenegotiation(TransceiverImpl& aTransceiver,
|
||||||
|
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
for (size_t i = 0; i < mDTMFStates.Length(); ++i) {
|
for (size_t i = 0; i < mDTMFStates.Length(); ++i) {
|
||||||
if (mDTMFStates[i].mTransceiver.get() == &aTransceiver) {
|
if (mDTMFStates[i]->mTransceiver.get() == &aTransceiver) {
|
||||||
mDTMFStates[i].mSendTimer->Cancel();
|
mDTMFStates[i]->mSendTimer->Cancel();
|
||||||
mDTMFStates.RemoveElementAt(i);
|
mDTMFStates.RemoveElementAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2804,7 +2802,7 @@ PeerConnectionImpl::CloseInt()
|
||||||
|
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
for (auto& dtmfState : mDTMFStates) {
|
for (auto& dtmfState : mDTMFStates) {
|
||||||
dtmfState.mSendTimer->Cancel();
|
dtmfState->mSendTimer->Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do this at the end of the call because we want to make sure we've waited
|
// We do this at the end of the call because we want to make sure we've waited
|
||||||
|
@ -3798,55 +3796,53 @@ PeerConnectionImpl::startCallTelem() {
|
||||||
Telemetry::Accumulate(Telemetry::WEBRTC_CALL_COUNT_2, 1);
|
Telemetry::Accumulate(Telemetry::WEBRTC_CALL_COUNT_2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
nsresult
|
||||||
PeerConnectionImpl::DTMFSendTimerCallback_m(nsITimer* timer, void* closure)
|
PeerConnectionImpl::DTMFState::Notify(nsITimer* timer)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
auto state = static_cast<DTMFState*>(closure);
|
|
||||||
|
|
||||||
nsString eventTone;
|
nsString eventTone;
|
||||||
if (!state->mTones.IsEmpty()) {
|
if (!mTones.IsEmpty()) {
|
||||||
uint16_t toneChar = state->mTones.CharAt(0);
|
uint16_t toneChar = mTones.CharAt(0);
|
||||||
int tone = GetDTMFToneCode(toneChar);
|
int tone = GetDTMFToneCode(toneChar);
|
||||||
|
|
||||||
eventTone.Assign(toneChar);
|
eventTone.Assign(toneChar);
|
||||||
|
|
||||||
state->mTones.Cut(0, 1);
|
mTones.Cut(0, 1);
|
||||||
|
|
||||||
if (tone == -1) {
|
if (tone == -1) {
|
||||||
state->mSendTimer->InitWithNamedFuncCallback(DTMFSendTimerCallback_m, state,
|
mSendTimer->InitWithCallback(this, 2000, nsITimer::TYPE_ONE_SHOT);
|
||||||
2000, nsITimer::TYPE_ONE_SHOT,
|
|
||||||
"DTMFSendTimerCallback_m");
|
|
||||||
} else {
|
} else {
|
||||||
// Reset delay if necessary
|
// Reset delay if necessary
|
||||||
state->mSendTimer->InitWithNamedFuncCallback(DTMFSendTimerCallback_m, state,
|
mSendTimer->InitWithCallback(this,
|
||||||
state->mDuration + state->mInterToneGap,
|
mDuration + mInterToneGap,
|
||||||
nsITimer::TYPE_ONE_SHOT,
|
nsITimer::TYPE_ONE_SHOT);
|
||||||
"DTMFSendTimerCallback_m");
|
|
||||||
|
|
||||||
state->mTransceiver->InsertDTMFTone(tone, state->mDuration);
|
mTransceiver->InsertDTMFTone(tone, mDuration);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state->mSendTimer->Cancel();
|
mSendTimer->Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(state->mPCObserver);
|
RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
|
||||||
if (!pco) {
|
if (!pco) {
|
||||||
NS_WARNING("Failed to dispatch the RTCDTMFToneChange event!");
|
NS_WARNING("Failed to dispatch the RTCDTMFToneChange event!");
|
||||||
return;
|
return NS_OK; // Return is ignored anyhow
|
||||||
}
|
}
|
||||||
|
|
||||||
JSErrorResult jrv;
|
JSErrorResult jrv;
|
||||||
pco->OnDTMFToneChange(*state->mTransceiver->GetSendTrack(), eventTone, jrv);
|
pco->OnDTMFToneChange(*mTransceiver->GetSendTrack(), eventTone, jrv);
|
||||||
|
|
||||||
if (jrv.Failed()) {
|
if (jrv.Failed()) {
|
||||||
NS_WARNING("Failed to dispatch the RTCDTMFToneChange event!");
|
NS_WARNING("Failed to dispatch the RTCDTMFToneChange event!");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerConnectionImpl::DTMFState::DTMFState() = default;
|
PeerConnectionImpl::DTMFState::DTMFState() = default;
|
||||||
PeerConnectionImpl::DTMFState::~DTMFState() = default;
|
PeerConnectionImpl::DTMFState::~DTMFState() = default;
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(PeerConnectionImpl::DTMFState, nsITimerCallback)
|
||||||
|
|
||||||
} // end mozilla namespace
|
} // end mozilla namespace
|
||||||
|
|
|
@ -827,22 +827,24 @@ private:
|
||||||
uint16_t mMaxSending[SdpMediaSection::kMediaTypes];
|
uint16_t mMaxSending[SdpMediaSection::kMediaTypes];
|
||||||
|
|
||||||
// DTMF
|
// DTMF
|
||||||
struct DTMFState {
|
class DTMFState : public nsITimerCallback {
|
||||||
DTMFState();
|
virtual ~DTMFState();
|
||||||
~DTMFState();
|
public:
|
||||||
nsWeakPtr mPCObserver;
|
DTMFState();
|
||||||
RefPtr<TransceiverImpl> mTransceiver;
|
|
||||||
nsCOMPtr<nsITimer> mSendTimer;
|
NS_DECL_NSITIMERCALLBACK
|
||||||
nsString mTones;
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
uint32_t mDuration;
|
|
||||||
uint32_t mInterToneGap;
|
nsWeakPtr mPCObserver;
|
||||||
|
RefPtr<TransceiverImpl> mTransceiver;
|
||||||
|
nsCOMPtr<nsITimer> mSendTimer;
|
||||||
|
nsString mTones;
|
||||||
|
uint32_t mDuration;
|
||||||
|
uint32_t mInterToneGap;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
DTMFSendTimerCallback_m(nsITimer* timer, void*);
|
|
||||||
|
|
||||||
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
// TODO(bug 1401983): Move DTMF stuff to TransceiverImpl
|
||||||
nsTArray<DTMFState> mDTMFStates;
|
nsTArray<RefPtr<DTMFState>> mDTMFStates;
|
||||||
|
|
||||||
std::vector<unsigned> mSendPacketDumpFlags;
|
std::vector<unsigned> mSendPacketDumpFlags;
|
||||||
std::vector<unsigned> mRecvPacketDumpFlags;
|
std::vector<unsigned> mRecvPacketDumpFlags;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче