author Paul Adenot <paul@paul.cx>
Mon, 05 Mar 2018 13:31:00 +0100
changeset 409024 408c4c89868db0f7659bd7d79d380ae9675491e2
parent 301025 42ff71805e2b67d5dabcd6b49ff0f737074bb91b
child 448947 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1437366 - Set the correct (possibly clamped) rate on the MediaStreamTrack when the MSG runs at a rate not compatible with the webrtc.org code, and fix interval calculation. r=jya,pehrsons MozReview-Commit-ID: HOPjfdUJBSU

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/WidgetTraceEvent.h"

#include <glib.h>
#include <mozilla/CondVar.h>
#include <mozilla/Mutex.h>
#include <stdio.h>

using mozilla::CondVar;
using mozilla::Mutex;
using mozilla::MutexAutoLock;

namespace {

Mutex* sMutex = nullptr;
CondVar* sCondVar = nullptr;
bool sTracerProcessed = false;

// This function is called from the main (UI) thread.
gboolean TracerCallback(gpointer data)
  return FALSE;

} // namespace

namespace mozilla {

bool InitWidgetTracing()
  sMutex = new Mutex("Event tracer thread mutex");
  sCondVar = new CondVar(*sMutex, "Event tracer thread condvar");
  return true;

void CleanUpWidgetTracing()
  delete sMutex;
  delete sCondVar;
  sMutex = nullptr;
  sCondVar = nullptr;

// This function is called from the background tracer thread.
bool FireAndWaitForTracerEvent()
  MOZ_ASSERT(sMutex && sCondVar, "Tracing not initialized!");

  // Send a default-priority idle event through the
  // event loop, and wait for it to finish.
  MutexAutoLock lock(*sMutex);
  MOZ_ASSERT(!sTracerProcessed, "Tracer synchronization state is wrong");
  while (!sTracerProcessed)
  sTracerProcessed = false;
  return true;

void SignalTracerThread()
  if (!sMutex || !sCondVar)
  MutexAutoLock lock(*sMutex);
  if (!sTracerProcessed) {
    sTracerProcessed = true;

} // namespace mozilla