summaryrefslogtreecommitdiff
path: root/dom/media
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media')
-rw-r--r--dom/media/GraphDriver.cpp82
-rw-r--r--dom/media/GraphDriver.h5
-rw-r--r--dom/media/eme/MediaKeySystemAccessManager.cpp3
-rw-r--r--dom/media/gmp/GMPChild.cpp6
-rw-r--r--dom/media/gmp/rlz/GMPDeviceBinding.cpp48
-rw-r--r--dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp9
-rw-r--r--dom/media/standalone/moz.build3
-rw-r--r--dom/media/systemservices/LoadMonitor.cpp27
-rw-r--r--dom/media/systemservices/OSXRunLoopSingleton.cpp44
-rw-r--r--dom/media/systemservices/OSXRunLoopSingleton.h25
-rw-r--r--dom/media/systemservices/moz.build4
-rwxr-xr-xdom/media/webaudio/AudioContext.cpp2
-rw-r--r--dom/media/webrtc/MediaEngineCameraVideoSource.cpp7
-rw-r--r--dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerModule.cpp56
-rw-r--r--dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.h43
-rw-r--r--dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm498
-rw-r--r--dom/media/webspeech/synth/cocoa/moz.build11
-rw-r--r--dom/media/webspeech/synth/moz.build3
18 files changed, 2 insertions, 874 deletions
diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp
index e8b71a2318..90680d8c69 100644
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -14,10 +14,6 @@
#include "webrtc/MediaEngineWebRTC.h"
#endif
-#ifdef XP_MACOSX
-#include <sys/sysctl.h>
-#endif
-
extern mozilla::LazyLogModule gMediaStreamGraphLog;
#define STREAM_LOG(type, msg) MOZ_LOG(gMediaStreamGraphLog, type, msg)
@@ -586,32 +582,6 @@ AudioCallbackDriver::~AudioCallbackDriver()
MOZ_ASSERT(mPromisesForOperation.IsEmpty());
}
-bool IsMacbookOrMacbookAir()
-{
-#ifdef XP_MACOSX
- size_t len = 0;
- sysctlbyname("hw.model", NULL, &len, NULL, 0);
- if (len) {
- UniquePtr<char[]> model(new char[len]);
- // This string can be
- // MacBook%d,%d for a normal MacBook
- // MacBookPro%d,%d for a MacBook Pro
- // MacBookAir%d,%d for a Macbook Air
- sysctlbyname("hw.model", model.get(), &len, NULL, 0);
- char* substring = strstr(model.get(), "MacBook");
- if (substring) {
- const size_t offset = strlen("MacBook");
- if (strncmp(model.get() + offset, "Air", len - offset) ||
- isdigit(model[offset + 1])) {
- return true;
- }
- }
- return false;
- }
-#endif
- return false;
-}
-
void
AudioCallbackDriver::Init()
{
@@ -648,13 +618,6 @@ AudioCallbackDriver::Init()
}
}
- // Macbook and MacBook air don't have enough CPU to run very low latency
- // MediaStreamGraphs, cap the minimal latency to 512 frames int this case.
- if (IsMacbookOrMacbookAir()) {
- latency_frames = std::max((uint32_t) 512, latency_frames);
- }
-
-
input = output;
input.channels = mInputChannels; // change to support optional stereo capture
@@ -1068,44 +1031,6 @@ AudioCallbackDriver::MixerCallback(AudioDataValue* aMixedBuffer,
NS_WARNING_ASSERTION(written == aFrames - toWrite, "Dropping frames.");
};
-void AudioCallbackDriver::PanOutputIfNeeded(bool aMicrophoneActive)
-{
-#ifdef XP_MACOSX
- cubeb_device* out;
- int rv;
- char name[128];
- size_t length = sizeof(name);
-
- rv = sysctlbyname("hw.model", name, &length, NULL, 0);
- if (rv) {
- return;
- }
-
- if (!strncmp(name, "MacBookPro", 10)) {
- if (cubeb_stream_get_current_device(mAudioStream, &out) == CUBEB_OK) {
- // Check if we are currently outputing sound on external speakers.
- if (!strcmp(out->output_name, "ispk")) {
- // Pan everything to the right speaker.
- if (aMicrophoneActive) {
- if (cubeb_stream_set_panning(mAudioStream, 1.0) != CUBEB_OK) {
- NS_WARNING("Could not pan audio output to the right.");
- }
- } else {
- if (cubeb_stream_set_panning(mAudioStream, 0.0) != CUBEB_OK) {
- NS_WARNING("Could not pan audio output to the center.");
- }
- }
- } else {
- if (cubeb_stream_set_panning(mAudioStream, 0.0) != CUBEB_OK) {
- NS_WARNING("Could not pan audio output to the center.");
- }
- }
- cubeb_stream_device_destroy(mAudioStream, out);
- }
- }
-#endif
-}
-
void
AudioCallbackDriver::DeviceChangedCallback() {
// Tell the audio engine the device has changed, it might want to reset some
@@ -1114,9 +1039,6 @@ AudioCallbackDriver::DeviceChangedCallback() {
if (mAudioInput) {
mAudioInput->DeviceChanged();
}
-#ifdef XP_MACOSX
- PanOutputIfNeeded(mMicrophoneActive);
-#endif
}
void
@@ -1125,10 +1047,6 @@ AudioCallbackDriver::SetMicrophoneActive(bool aActive)
MonitorAutoLock mon(mGraphImpl->GetMonitor());
mMicrophoneActive = aActive;
-
-#ifdef XP_MACOSX
- PanOutputIfNeeded(mMicrophoneActive);
-#endif
}
uint32_t
diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h
index bb4f2689b8..f2a514b328 100644
--- a/dom/media/GraphDriver.h
+++ b/dom/media/GraphDriver.h
@@ -457,11 +457,6 @@ public:
void CompleteAudioContextOperations(AsyncCubebOperation aOperation);
private:
/**
- * On certain MacBookPro, the microphone is located near the left speaker.
- * We need to pan the sound output to the right speaker if we are using the
- * mic and the built-in speaker, or we will have terrible echo. */
- void PanOutputIfNeeded(bool aMicrophoneActive);
- /**
* This is called when the output device used by the cubeb stream changes. */
void DeviceChangedCallback();
/* Start the cubeb stream */
diff --git a/dom/media/eme/MediaKeySystemAccessManager.cpp b/dom/media/eme/MediaKeySystemAccessManager.cpp
index ed31059e22..a1e1254ad4 100644
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -14,9 +14,6 @@
#ifdef XP_WIN
#include "mozilla/WindowsVersion.h"
#endif
-#ifdef XP_MACOSX
-#include "nsCocoaFeatures.h"
-#endif
#include "nsPrintfCString.h"
namespace mozilla {
diff --git a/dom/media/gmp/GMPChild.cpp b/dom/media/gmp/GMPChild.cpp
index fa6f2f4c83..eb18037364 100644
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -112,14 +112,12 @@ GetPluginFile(const nsAString& aPluginPath,
nsAutoString baseName;
GetFileBase(aPluginPath, aLibDirectory, aLibFile, baseName);
-#if defined(XP_MACOSX)
- nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".dylib");
-#elif defined(OS_POSIX)
+#if defined(OS_POSIX)
nsAutoString binaryName = NS_LITERAL_STRING("lib") + baseName + NS_LITERAL_STRING(".so");
#elif defined(XP_WIN)
nsAutoString binaryName = baseName + NS_LITERAL_STRING(".dll");
#else
-#error not defined
+#error Unsupported O.S.
#endif
aLibFile->AppendRelativePath(binaryName);
return true;
diff --git a/dom/media/gmp/rlz/GMPDeviceBinding.cpp b/dom/media/gmp/rlz/GMPDeviceBinding.cpp
index 04def8e8e0..0871d2e4ee 100644
--- a/dom/media/gmp/rlz/GMPDeviceBinding.cpp
+++ b/dom/media/gmp/rlz/GMPDeviceBinding.cpp
@@ -32,14 +32,6 @@
#include "windows.h"
#endif
-#ifdef XP_MACOSX
-#include <assert.h>
-#ifdef HASH_NODE_ID_WITH_DEVICE_ID
-#include <unistd.h>
-#include <mach/mach.h>
-#include <mach/mach_vm.h>
-#endif
-#endif
#endif // HASH_NODE_ID_WITH_DEVICE_ID
@@ -83,46 +75,6 @@ GetStackAfterCurrentFrame(uint8_t** aOutTop, uint8_t** aOutBottom)
}
#endif
-#if defined(XP_MACOSX) && defined(HASH_NODE_ID_WITH_DEVICE_ID)
-static mach_vm_address_t
-RegionContainingAddress(mach_vm_address_t aAddress)
-{
- mach_port_t task;
- kern_return_t kr = task_for_pid(mach_task_self(), getpid(), &task);
- if (kr != KERN_SUCCESS) {
- return 0;
- }
-
- mach_vm_address_t address = aAddress;
- mach_vm_size_t size;
- vm_region_basic_info_data_64_t info;
- mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
- mach_port_t object_name;
- kr = mach_vm_region(task, &address, &size, VM_REGION_BASIC_INFO_64,
- reinterpret_cast<vm_region_info_t>(&info), &count,
- &object_name);
- if (kr != KERN_SUCCESS || size == 0
- || address > aAddress || address + size <= aAddress) {
- // mach_vm_region failed, or couldn't find region at given address.
- return 0;
- }
-
- return address;
-}
-
-MOZ_NEVER_INLINE
-static bool
-GetStackAfterCurrentFrame(uint8_t** aOutTop, uint8_t** aOutBottom)
-{
- mach_vm_address_t stackFrame =
- reinterpret_cast<mach_vm_address_t>(__builtin_frame_address(0));
- *aOutTop = reinterpret_cast<uint8_t*>(stackFrame);
- // Kernel code shows that stack is always a single region.
- *aOutBottom = reinterpret_cast<uint8_t*>(RegionContainingAddress(stackFrame));
- return *aOutBottom && (*aOutBottom < *aOutTop);
-}
-#endif
-
#ifdef HASH_NODE_ID_WITH_DEVICE_ID
static void SecureMemset(void* start, uint8_t value, size_t size)
{
diff --git a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
index 4671499e5d..513a8998b8 100644
--- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
@@ -26,14 +26,6 @@ public:
static FFmpegLibWrapper sLibAV;
static const char* sLibs[] = {
-#if defined(XP_DARWIN)
- "libavcodec.58.dylib",
- "libavcodec.57.dylib",
- "libavcodec.56.dylib",
- "libavcodec.55.dylib",
- "libavcodec.54.dylib",
- "libavcodec.53.dylib",
-#else
"libavcodec.so.58",
"libavcodec-ffmpeg.so.58",
"libavcodec-ffmpeg.so.57",
@@ -43,7 +35,6 @@ static const char* sLibs[] = {
"libavcodec.so.55",
"libavcodec.so.54",
"libavcodec.so.53",
-#endif
};
/* static */ bool
diff --git a/dom/media/standalone/moz.build b/dom/media/standalone/moz.build
index 7ef15adaa9..5ec7e82c20 100644
--- a/dom/media/standalone/moz.build
+++ b/dom/media/standalone/moz.build
@@ -13,9 +13,6 @@ SOURCES += [
'../VideoSegment.cpp',
]
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
- UNIFIED_SOURCES += ['../systemservices/OSXRunLoopSingleton.cpp']
-
LOCAL_INCLUDES += [
'/caps',
'/dom/base',
diff --git a/dom/media/systemservices/LoadMonitor.cpp b/dom/media/systemservices/LoadMonitor.cpp
index 7a64c4fb0b..ef8d1a0cc7 100644
--- a/dom/media/systemservices/LoadMonitor.cpp
+++ b/dom/media/systemservices/LoadMonitor.cpp
@@ -31,12 +31,6 @@
#include <unistd.h>
#endif
-#ifdef XP_MACOSX
-#include <mach/mach_host.h>
-#include <mach/mach_init.h>
-#include <mach/host_info.h>
-#endif
-
#if defined(__DragonFly__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
@@ -415,27 +409,6 @@ nsresult RTCLoadInfo::UpdateSystemLoad()
cpu_times,
&mSystemLoad);
return NS_OK;
-#elif defined(XP_MACOSX)
- mach_msg_type_number_t info_cnt = HOST_CPU_LOAD_INFO_COUNT;
- host_cpu_load_info_data_t load_info;
- kern_return_t rv = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO,
- (host_info_t)(&load_info), &info_cnt);
-
- if (rv != KERN_SUCCESS || info_cnt != HOST_CPU_LOAD_INFO_COUNT) {
- LOG(("Error from mach/host_statistics call"));
- return NS_ERROR_FAILURE;
- }
-
- const uint64_t cpu_times = load_info.cpu_ticks[CPU_STATE_NICE]
- + load_info.cpu_ticks[CPU_STATE_SYSTEM]
- + load_info.cpu_ticks[CPU_STATE_USER];
- const uint64_t total_times = cpu_times + load_info.cpu_ticks[CPU_STATE_IDLE];
-
- UpdateCpuLoad(mTicksPerInterval,
- total_times,
- cpu_times,
- &mSystemLoad);
- return NS_OK;
#elif defined(__DragonFly__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__)
#if defined(__NetBSD__)
diff --git a/dom/media/systemservices/OSXRunLoopSingleton.cpp b/dom/media/systemservices/OSXRunLoopSingleton.cpp
deleted file mode 100644
index 6211d5c127..0000000000
--- a/dom/media/systemservices/OSXRunLoopSingleton.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
-/* 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 "OSXRunLoopSingleton.h"
-#include <mozilla/StaticMutex.h>
-
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/AudioHardware.h>
-#include <CoreAudio/HostTime.h>
-#include <CoreFoundation/CoreFoundation.h>
-
-static bool gRunLoopSet = false;
-static mozilla::StaticMutex gMutex;
-
-void mozilla_set_coreaudio_notification_runloop_if_needed()
-{
- mozilla::StaticMutexAutoLock lock(gMutex);
- if (gRunLoopSet) {
- return;
- }
-
- /* This is needed so that AudioUnit listeners get called on this thread, and
- * not the main thread. If we don't do that, they are not called, or a crash
- * occur, depending on the OSX version. */
- AudioObjectPropertyAddress runloop_address = {
- kAudioHardwarePropertyRunLoop,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster
- };
-
- CFRunLoopRef run_loop = nullptr;
-
- OSStatus r;
- r = AudioObjectSetPropertyData(kAudioObjectSystemObject,
- &runloop_address,
- 0, NULL, sizeof(CFRunLoopRef), &run_loop);
- if (r != noErr) {
- NS_WARNING("Could not make global CoreAudio notifications use their own thread.");
- }
-
- gRunLoopSet = true;
-}
diff --git a/dom/media/systemservices/OSXRunLoopSingleton.h b/dom/media/systemservices/OSXRunLoopSingleton.h
deleted file mode 100644
index d06365e146..0000000000
--- a/dom/media/systemservices/OSXRunLoopSingleton.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
-/* 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/. */
-
-#ifndef OSXRUNLOOPSINGLETON_H_
-#define OSXRUNLOOPSINGLETON_H_
-
-#include <mozilla/Types.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* This function tells CoreAudio to use its own thread for device change
- * notifications, and can be called from any thread without external
- * synchronization. */
-void MOZ_EXPORT
-mozilla_set_coreaudio_notification_runloop_if_needed();
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif // OSXRUNLOOPSINGLETON_H_
diff --git a/dom/media/systemservices/moz.build b/dom/media/systemservices/moz.build
index aa07b291a9..7d566c42ce 100644
--- a/dom/media/systemservices/moz.build
+++ b/dom/media/systemservices/moz.build
@@ -38,10 +38,6 @@ if CONFIG['OS_TARGET'] == 'Android':
'OpenSLESProvider.cpp',
]
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
- SOURCES += ['OSXRunLoopSingleton.cpp']
- EXPORTS += ['OSXRunLoopSingleton.h']
-
if CONFIG['_MSC_VER']:
DEFINES['__PRETTY_FUNCTION__'] = '__FUNCSIG__'
diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp
index 75f57a630b..3c7958349b 100755
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -873,7 +873,6 @@ AudioContext::OnStateChanged(void* aPromise, AudioContextState aNewState)
}
#ifndef WIN32 // Bug 1170547
-#ifndef XP_MACOSX
#ifdef DEBUG
if (!((mAudioContextState == AudioContextState::Suspended &&
@@ -892,7 +891,6 @@ AudioContext::OnStateChanged(void* aPromise, AudioContextState aNewState)
}
#endif // DEBUG
-#endif // XP_MACOSX
#endif // WIN32
MOZ_ASSERT(
diff --git a/dom/media/webrtc/MediaEngineCameraVideoSource.cpp b/dom/media/webrtc/MediaEngineCameraVideoSource.cpp
index e1e572724f..e63a9afded 100644
--- a/dom/media/webrtc/MediaEngineCameraVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineCameraVideoSource.cpp
@@ -339,13 +339,6 @@ MediaEngineCameraVideoSource::SetName(nsString aName)
facingMode = VideoFacingModeEnum::User;
}
#endif // ANDROID
-#ifdef XP_MACOSX
- // Kludge to test user-facing cameras on OSX.
- if (aName.Find(NS_LITERAL_STRING("Face")) != -1) {
- hasFacingMode = true;
- facingMode = VideoFacingModeEnum::User;
- }
-#endif
#ifdef XP_WIN
// The cameras' name of Surface book are "Microsoft Camera Front" and
// "Microsoft Camera Rear" respectively.
diff --git a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerModule.cpp b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerModule.cpp
deleted file mode 100644
index ef69170003..0000000000
--- a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerModule.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/ModuleUtils.h"
-#include "nsIClassInfoImpl.h"
-
-#include "OSXSpeechSynthesizerService.h"
-
-using namespace mozilla::dom;
-
-#define OSXSPEECHSYNTHESIZERSERVICE_CID \
- {0x914e73b4, 0x6337, 0x4bef, {0x97, 0xf3, 0x4d, 0x06, 0x9e, 0x05, 0x3a, 0x12}}
-
-#define OSXSPEECHSYNTHESIZERSERVICE_CONTRACTID "@mozilla.org/synthsystem;1"
-
-// Defines OSXSpeechSynthesizerServiceConstructor
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(OSXSpeechSynthesizerService,
- OSXSpeechSynthesizerService::GetInstanceForService)
-
-// Defines kOSXSERVICE_CID
-NS_DEFINE_NAMED_CID(OSXSPEECHSYNTHESIZERSERVICE_CID);
-
-static const mozilla::Module::CIDEntry kCIDs[] = {
- { &kOSXSPEECHSYNTHESIZERSERVICE_CID, true, nullptr, OSXSpeechSynthesizerServiceConstructor },
- { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kContracts[] = {
- { OSXSPEECHSYNTHESIZERSERVICE_CONTRACTID, &kOSXSPEECHSYNTHESIZERSERVICE_CID },
- { nullptr }
-};
-
-static const mozilla::Module::CategoryEntry kCategories[] = {
- { "speech-synth-started", "OSX Speech Synth", OSXSPEECHSYNTHESIZERSERVICE_CONTRACTID },
- { nullptr }
-};
-
-static void
-UnloadOSXSpeechSynthesizerModule()
-{
- OSXSpeechSynthesizerService::Shutdown();
-}
-
-static const mozilla::Module kModule = {
- mozilla::Module::kVersion,
- kCIDs,
- kContracts,
- kCategories,
- nullptr,
- nullptr,
- UnloadOSXSpeechSynthesizerModule
-};
-
-NSMODULE_DEFN(osxsynth) = &kModule;
diff --git a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.h b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.h
deleted file mode 100644
index ba04f0fecb..0000000000
--- a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_OsxSpeechSynthesizerService_h
-#define mozilla_dom_OsxSpeechSynthesizerService_h
-
-#include "nsISpeechService.h"
-#include "nsIObserver.h"
-#include "mozilla/StaticPtr.h"
-
-namespace mozilla {
-namespace dom {
-
-class OSXSpeechSynthesizerService final : public nsISpeechService
- , public nsIObserver
-{
-public:
- NS_DECL_THREADSAFE_ISUPPORTS
- NS_DECL_NSISPEECHSERVICE
- NS_DECL_NSIOBSERVER
-
- bool Init();
-
- static OSXSpeechSynthesizerService* GetInstance();
- static already_AddRefed<OSXSpeechSynthesizerService> GetInstanceForService();
- static void Shutdown();
-
-private:
- OSXSpeechSynthesizerService();
- virtual ~OSXSpeechSynthesizerService();
-
- bool RegisterVoices();
-
- bool mInitialized;
- static mozilla::StaticRefPtr<OSXSpeechSynthesizerService> sSingleton;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif
diff --git a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm
deleted file mode 100644
index ec752e00f0..0000000000
--- a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm
+++ /dev/null
@@ -1,498 +0,0 @@
-/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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 "nsISupports.h"
-#include "nsServiceManagerUtils.h"
-#include "nsObjCExceptions.h"
-#include "nsCocoaUtils.h"
-#include "nsThreadUtils.h"
-#include "mozilla/dom/nsSynthVoiceRegistry.h"
-#include "mozilla/dom/nsSpeechTask.h"
-#include "mozilla/Preferences.h"
-#include "mozilla/Assertions.h"
-#include "OSXSpeechSynthesizerService.h"
-
-#import <Cocoa/Cocoa.h>
-
-// We can escape the default delimiters ("[[" and "]]") by temporarily
-// changing the delimiters just before they appear, and changing them back
-// just after.
-#define DLIM_ESCAPE_START "[[dlim (( ))]]"
-#define DLIM_ESCAPE_END "((dlim [[ ]]))"
-
-using namespace mozilla;
-
-class SpeechTaskCallback final : public nsISpeechTaskCallback
-{
-public:
- SpeechTaskCallback(nsISpeechTask* aTask,
- NSSpeechSynthesizer* aSynth,
- const nsTArray<size_t>& aOffsets)
- : mTask(aTask)
- , mSpeechSynthesizer(aSynth)
- , mOffsets(aOffsets)
- {
- mStartingTime = TimeStamp::Now();
- }
-
- NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(SpeechTaskCallback, nsISpeechTaskCallback)
-
- NS_DECL_NSISPEECHTASKCALLBACK
-
- void OnWillSpeakWord(uint32_t aIndex);
- void OnError(uint32_t aIndex);
- void OnDidFinishSpeaking();
-
-private:
- virtual ~SpeechTaskCallback()
- {
- [mSpeechSynthesizer release];
- }
-
- float GetTimeDurationFromStart();
-
- nsCOMPtr<nsISpeechTask> mTask;
- NSSpeechSynthesizer* mSpeechSynthesizer;
- TimeStamp mStartingTime;
- uint32_t mCurrentIndex;
- nsTArray<size_t> mOffsets;
-};
-
-NS_IMPL_CYCLE_COLLECTION(SpeechTaskCallback, mTask);
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechTaskCallback)
- NS_INTERFACE_MAP_ENTRY(nsISpeechTaskCallback)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISpeechTaskCallback)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechTaskCallback)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechTaskCallback)
-
-NS_IMETHODIMP
-SpeechTaskCallback::OnCancel()
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- [mSpeechSynthesizer stopSpeaking];
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-NS_IMETHODIMP
-SpeechTaskCallback::OnPause()
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- [mSpeechSynthesizer pauseSpeakingAtBoundary:NSSpeechImmediateBoundary];
- if (!mTask) {
- // When calling pause() on child porcess, it may not receive end event
- // from chrome process yet.
- return NS_ERROR_FAILURE;
- }
- mTask->DispatchPause(GetTimeDurationFromStart(), mCurrentIndex);
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-NS_IMETHODIMP
-SpeechTaskCallback::OnResume()
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- [mSpeechSynthesizer continueSpeaking];
- if (!mTask) {
- // When calling resume() on child porcess, it may not receive end event
- // from chrome process yet.
- return NS_ERROR_FAILURE;
- }
- mTask->DispatchResume(GetTimeDurationFromStart(), mCurrentIndex);
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-NS_IMETHODIMP
-SpeechTaskCallback::OnVolumeChanged(float aVolume)
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- [mSpeechSynthesizer setObject:[NSNumber numberWithFloat:aVolume]
- forProperty:NSSpeechVolumeProperty error:nil];
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-float
-SpeechTaskCallback::GetTimeDurationFromStart()
-{
- TimeDuration duration = TimeStamp::Now() - mStartingTime;
- return duration.ToMilliseconds();
-}
-
-void
-SpeechTaskCallback::OnWillSpeakWord(uint32_t aIndex)
-{
- mCurrentIndex = aIndex < mOffsets.Length() ? mOffsets[aIndex] : mCurrentIndex;
- if (!mTask) {
- return;
- }
- mTask->DispatchBoundary(NS_LITERAL_STRING("word"),
- GetTimeDurationFromStart(), mCurrentIndex);
-}
-
-void
-SpeechTaskCallback::OnError(uint32_t aIndex)
-{
- if (!mTask) {
- return;
- }
- mTask->DispatchError(GetTimeDurationFromStart(), aIndex);
-}
-
-void
-SpeechTaskCallback::OnDidFinishSpeaking()
-{
- mTask->DispatchEnd(GetTimeDurationFromStart(), mCurrentIndex);
- // no longer needed
- [mSpeechSynthesizer setDelegate:nil];
- mTask = nullptr;
-}
-
-@interface SpeechDelegate : NSObject<NSSpeechSynthesizerDelegate>
-{
-@private
- SpeechTaskCallback* mCallback;
-}
-
- - (id)initWithCallback:(SpeechTaskCallback*)aCallback;
-@end
-
-@implementation SpeechDelegate
-- (id)initWithCallback:(SpeechTaskCallback*)aCallback
-{
- [super init];
- mCallback = aCallback;
- return self;
-}
-
-- (void)speechSynthesizer:(NSSpeechSynthesizer *)aSender
- willSpeakWord:(NSRange)aRange ofString:(NSString*)aString
-{
- mCallback->OnWillSpeakWord(aRange.location);
-}
-
-- (void)speechSynthesizer:(NSSpeechSynthesizer *)aSender
- didFinishSpeaking:(BOOL)aFinishedSpeaking
-{
- mCallback->OnDidFinishSpeaking();
-}
-
-- (void)speechSynthesizer:(NSSpeechSynthesizer*)aSender
- didEncounterErrorAtIndex:(NSUInteger)aCharacterIndex
- ofString:(NSString*)aString
- message:(NSString*)aMessage
-{
- mCallback->OnError(aCharacterIndex);
-}
-@end
-
-namespace mozilla {
-namespace dom {
-
-struct OSXVoice
-{
- OSXVoice() : mIsDefault(false)
- {
- }
-
- nsString mUri;
- nsString mName;
- nsString mLocale;
- bool mIsDefault;
-};
-
-class RegisterVoicesRunnable final : public Runnable
-{
-public:
- RegisterVoicesRunnable(OSXSpeechSynthesizerService* aSpeechService,
- nsTArray<OSXVoice>& aList)
- : mSpeechService(aSpeechService)
- , mVoices(aList)
- {
- }
-
- NS_IMETHOD Run() override;
-
-private:
- ~RegisterVoicesRunnable()
- {
- }
-
- // This runnable always use sync mode. It is unnecesarry to reference object
- OSXSpeechSynthesizerService* mSpeechService;
- nsTArray<OSXVoice>& mVoices;
-};
-
-NS_IMETHODIMP
-RegisterVoicesRunnable::Run()
-{
- nsresult rv;
- nsCOMPtr<nsISynthVoiceRegistry> registry =
- do_GetService(NS_SYNTHVOICEREGISTRY_CONTRACTID, &rv);
- if (!registry) {
- return rv;
- }
-
- for (OSXVoice voice : mVoices) {
- rv = registry->AddVoice(mSpeechService, voice.mUri, voice.mName, voice.mLocale, true, false);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- continue;
- }
-
- if (voice.mIsDefault) {
- registry->SetDefaultVoice(voice.mUri, true);
- }
- }
-
- registry->NotifyVoicesChanged();
-
- return NS_OK;
-}
-
-class EnumVoicesRunnable final : public Runnable
-{
-public:
- explicit EnumVoicesRunnable(OSXSpeechSynthesizerService* aSpeechService)
- : mSpeechService(aSpeechService)
- {
- }
-
- NS_IMETHOD Run() override;
-
-private:
- ~EnumVoicesRunnable()
- {
- }
-
- RefPtr<OSXSpeechSynthesizerService> mSpeechService;
-};
-
-NS_IMETHODIMP
-EnumVoicesRunnable::Run()
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- AutoTArray<OSXVoice, 64> list;
-
- NSArray* voices = [NSSpeechSynthesizer availableVoices];
- NSString* defaultVoice = [NSSpeechSynthesizer defaultVoice];
-
- for (NSString* voice in voices) {
- OSXVoice item;
-
- NSDictionary* attr = [NSSpeechSynthesizer attributesForVoice:voice];
-
- nsAutoString identifier;
- nsCocoaUtils::GetStringForNSString([attr objectForKey:NSVoiceIdentifier],
- identifier);
-
- nsCocoaUtils::GetStringForNSString([attr objectForKey:NSVoiceName], item.mName);
-
- nsCocoaUtils::GetStringForNSString(
- [attr objectForKey:NSVoiceLocaleIdentifier], item.mLocale);
- item.mLocale.ReplaceChar('_', '-');
-
- item.mUri.AssignLiteral("urn:moz-tts:osx:");
- item.mUri.Append(identifier);
-
- if ([voice isEqualToString:defaultVoice]) {
- item.mIsDefault = true;
- }
-
- list.AppendElement(item);
- }
-
- RefPtr<RegisterVoicesRunnable> runnable = new RegisterVoicesRunnable(mSpeechService, list);
- NS_DispatchToMainThread(runnable, NS_DISPATCH_SYNC);
-
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-StaticRefPtr<OSXSpeechSynthesizerService> OSXSpeechSynthesizerService::sSingleton;
-
-NS_INTERFACE_MAP_BEGIN(OSXSpeechSynthesizerService)
- NS_INTERFACE_MAP_ENTRY(nsISpeechService)
- NS_INTERFACE_MAP_ENTRY(nsIObserver)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISpeechService)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(OSXSpeechSynthesizerService)
-NS_IMPL_RELEASE(OSXSpeechSynthesizerService)
-
-OSXSpeechSynthesizerService::OSXSpeechSynthesizerService()
- : mInitialized(false)
-{
-}
-
-OSXSpeechSynthesizerService::~OSXSpeechSynthesizerService()
-{
-}
-
-bool
-OSXSpeechSynthesizerService::Init()
-{
- if (Preferences::GetBool("media.webspeech.synth.test") ||
- !Preferences::GetBool("media.webspeech.synth.enabled")) {
- // When test is enabled, we shouldn't add OS backend (Bug 1160844)
- return false;
- }
-
- nsCOMPtr<nsIThread> thread;
- if (NS_FAILED(NS_NewNamedThread("SpeechWorker", getter_AddRefs(thread)))) {
- return false;
- }
-
- // Get all the voices and register in the SynthVoiceRegistry
- nsCOMPtr<nsIRunnable> runnable = new EnumVoicesRunnable(this);
- thread->Dispatch(runnable, NS_DISPATCH_NORMAL);
-
- mInitialized = true;
- return true;
-}
-
-NS_IMETHODIMP
-OSXSpeechSynthesizerService::Speak(const nsAString& aText,
- const nsAString& aUri,
- float aVolume,
- float aRate,
- float aPitch,
- nsISpeechTask* aTask)
-{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
- MOZ_ASSERT(StringBeginsWith(aUri, NS_LITERAL_STRING("urn:moz-tts:osx:")),
- "OSXSpeechSynthesizerService doesn't allow this voice URI");
-
- NSSpeechSynthesizer* synth = [[NSSpeechSynthesizer alloc] init];
- // strlen("urn:moz-tts:osx:") == 16
- NSString* identifier = nsCocoaUtils::ToNSString(Substring(aUri, 16));
- [synth setVoice:identifier];
-
- // default rate is 180-220
- [synth setObject:[NSNumber numberWithInt:aRate * 200]
- forProperty:NSSpeechRateProperty error:nil];
- // volume allows 0.0-1.0
- [synth setObject:[NSNumber numberWithFloat:aVolume]
- forProperty:NSSpeechVolumeProperty error:nil];
- // Use default pitch value to calculate this
- NSNumber* defaultPitch =
- [synth objectForProperty:NSSpeechPitchBaseProperty error:nil];
- if (defaultPitch) {
- int newPitch = [defaultPitch intValue] * (aPitch / 2 + 0.5);
- [synth setObject:[NSNumber numberWithInt:newPitch]
- forProperty:NSSpeechPitchBaseProperty error:nil];
- }
-
- nsAutoString escapedText;
- // We need to map the the offsets from the given text to the escaped text.
- // The index of the offsets array is the position in the escaped text,
- // the element value is the position in the user-supplied text.
- nsTArray<size_t> offsets;
- offsets.SetCapacity(aText.Length());
-
- // This loop looks for occurances of "[[" or "]]", escapes them, and
- // populates the offsets array to supply a map to the original offsets.
- for (size_t i = 0; i < aText.Length(); i++) {
- if (aText.Length() > i + 1 &&
- ((aText[i] == ']' && aText[i+1] == ']') ||
- (aText[i] == '[' && aText[i+1] == '['))) {
- escapedText.AppendLiteral(DLIM_ESCAPE_START);
- offsets.AppendElements(strlen(DLIM_ESCAPE_START));
- escapedText.Append(aText[i]);
- offsets.AppendElement(i);
- escapedText.Append(aText[++i]);
- offsets.AppendElement(i);
- escapedText.AppendLiteral(DLIM_ESCAPE_END);
- offsets.AppendElements(strlen(DLIM_ESCAPE_END));
- } else {
- escapedText.Append(aText[i]);
- offsets.AppendElement(i);
- }
- }
-
- RefPtr<SpeechTaskCallback> callback = new SpeechTaskCallback(aTask, synth, offsets);
- nsresult rv = aTask->Setup(callback, 0, 0, 0);
- NS_ENSURE_SUCCESS(rv, rv);
-
- SpeechDelegate* delegate = [[SpeechDelegate alloc] initWithCallback:callback];
- [synth setDelegate:delegate];
- [delegate release ];
-
- NSString* text = nsCocoaUtils::ToNSString(escapedText);
- BOOL success = [synth startSpeakingString:text];
- NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
-
- aTask->DispatchStart();
- return NS_OK;
-
- NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-NS_IMETHODIMP
-OSXSpeechSynthesizerService::GetServiceType(SpeechServiceType* aServiceType)
-{
- *aServiceType = nsISpeechService::SERVICETYPE_INDIRECT_AUDIO;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-OSXSpeechSynthesizerService::Observe(nsISupports* aSubject, const char* aTopic,
- const char16_t* aData)
-{
- return NS_OK;
-}
-
-OSXSpeechSynthesizerService*
-OSXSpeechSynthesizerService::GetInstance()
-{
- MOZ_ASSERT(NS_IsMainThread());
- if (XRE_GetProcessType() != GeckoProcessType_Default) {
- return nullptr;
- }
-
- if (!sSingleton) {
- RefPtr<OSXSpeechSynthesizerService> speechService =
- new OSXSpeechSynthesizerService();
- if (speechService->Init()) {
- sSingleton = speechService;
- }
- }
- return sSingleton;
-}
-
-already_AddRefed<OSXSpeechSynthesizerService>
-OSXSpeechSynthesizerService::GetInstanceForService()
-{
- RefPtr<OSXSpeechSynthesizerService> speechService = GetInstance();
- return speechService.forget();
-}
-
-void
-OSXSpeechSynthesizerService::Shutdown()
-{
- if (!sSingleton) {
- return;
- }
- sSingleton = nullptr;
-}
-
-} // namespace dom
-} // namespace mozilla
diff --git a/dom/media/webspeech/synth/cocoa/moz.build b/dom/media/webspeech/synth/cocoa/moz.build
deleted file mode 100644
index 6953a81e95..0000000000
--- a/dom/media/webspeech/synth/cocoa/moz.build
+++ /dev/null
@@ -1,11 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# 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/.
-
-SOURCES += [
- 'OSXSpeechSynthesizerModule.cpp',
- 'OSXSpeechSynthesizerService.mm'
-]
-
-FINAL_LIBRARY = 'xul'
diff --git a/dom/media/webspeech/synth/moz.build b/dom/media/webspeech/synth/moz.build
index 6603689261..9784686dfe 100644
--- a/dom/media/webspeech/synth/moz.build
+++ b/dom/media/webspeech/synth/moz.build
@@ -32,9 +32,6 @@ SOURCES += [
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
DIRS += ['windows']
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
- DIRS += ['cocoa']
-
if CONFIG['MOZ_SYNTH_SPEECHD']:
DIRS += ['speechd']