2011-09-26 20:31:18 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-15 03:53:55 -07:00
|
|
|
/* vim: set sw=2 ts=2 et tw=80 : */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-11-16 20:14:19 -08:00
|
|
|
|
|
|
|
#include "mozilla/dom/AudioChild.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-11-25 20:13:54 -08:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(AudioChild);
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(AudioChild);
|
|
|
|
|
2010-11-16 20:14:19 -08:00
|
|
|
AudioChild::AudioChild()
|
2011-09-26 20:31:18 -07:00
|
|
|
: mLastPosition(-1),
|
|
|
|
mLastPositionTimestamp(0),
|
|
|
|
mMinWriteSize(-2),// Initial value, -2, error on -1
|
2011-05-06 02:03:44 -07:00
|
|
|
mAudioReentrantMonitor("AudioChild.mReentrantMonitor"),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIPCOpen(true),
|
|
|
|
mDrained(false)
|
2010-11-16 20:14:19 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(AudioChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioChild::~AudioChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(AudioChild);
|
|
|
|
}
|
|
|
|
|
2010-11-25 20:13:54 -08:00
|
|
|
void
|
|
|
|
AudioChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mIPCOpen = false;
|
2010-11-25 20:13:54 -08:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:14:19 -08:00
|
|
|
bool
|
2011-09-26 20:31:18 -07:00
|
|
|
AudioChild::RecvPositionInFramesUpdate(const PRInt64& position,
|
|
|
|
const PRInt64& time)
|
2010-11-16 20:14:19 -08:00
|
|
|
{
|
2011-09-26 20:31:18 -07:00
|
|
|
mLastPosition = position;
|
|
|
|
mLastPositionTimestamp = time;
|
2010-11-16 20:14:19 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-29 21:37:32 -08:00
|
|
|
bool
|
|
|
|
AudioChild::RecvDrainDone()
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mAudioReentrantMonitor);
|
2011-10-17 07:59:28 -07:00
|
|
|
mDrained = true;
|
2011-04-29 12:21:57 -07:00
|
|
|
mAudioReentrantMonitor.NotifyAll();
|
2010-11-29 21:37:32 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-15 03:53:55 -07:00
|
|
|
PRInt32
|
2011-09-26 20:31:18 -07:00
|
|
|
AudioChild::WaitForMinWriteSize()
|
2011-05-15 03:53:55 -07:00
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mAudioReentrantMonitor);
|
|
|
|
// -2 : initial value
|
2011-09-26 20:31:18 -07:00
|
|
|
while (mMinWriteSize == -2 && mIPCOpen) {
|
2011-05-15 03:53:55 -07:00
|
|
|
mAudioReentrantMonitor.Wait();
|
2011-09-26 20:31:18 -07:00
|
|
|
}
|
|
|
|
return mMinWriteSize;
|
2011-05-15 03:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-26 20:31:18 -07:00
|
|
|
AudioChild::RecvMinWriteSizeDone(const PRInt32& minFrames)
|
2011-05-15 03:53:55 -07:00
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mAudioReentrantMonitor);
|
2011-09-26 20:31:18 -07:00
|
|
|
mMinWriteSize = minFrames;
|
2011-05-15 03:53:55 -07:00
|
|
|
mAudioReentrantMonitor.NotifyAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-29 21:37:32 -08:00
|
|
|
void
|
|
|
|
AudioChild::WaitForDrain()
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mAudioReentrantMonitor);
|
2010-11-29 21:37:32 -08:00
|
|
|
while (!mDrained && mIPCOpen) {
|
2011-04-29 12:21:57 -07:00
|
|
|
mAudioReentrantMonitor.Wait();
|
2010-11-29 21:37:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 20:14:19 -08:00
|
|
|
PRInt64
|
2011-09-26 20:31:18 -07:00
|
|
|
AudioChild::GetLastKnownPosition()
|
2010-11-16 20:14:19 -08:00
|
|
|
{
|
2011-09-26 20:31:18 -07:00
|
|
|
return mLastPosition;
|
2010-11-16 20:14:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt64
|
2011-09-26 20:31:18 -07:00
|
|
|
AudioChild::GetLastKnownPositionTimestamp()
|
2010-11-16 20:14:19 -08:00
|
|
|
{
|
2011-09-26 20:31:18 -07:00
|
|
|
return mLastPositionTimestamp;
|
2010-11-16 20:14:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|