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