< prev index next >
modules/media/src/main/native/jfxmedia/platform/osx/avf/AVFKernelProcessor.cpp
Print this page
rev 9506 : 8156563: JavaFX Ensemble8 media sample hang and crash
Reviewed-by: almatvee, kcr
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -33,19 +33,19 @@
class AVFKernelComponent : AUEffectBase {
public:
AVFKernelComponent(AudioComponentInstance audioUnit, bool inProcessesInPlace = true)
: AUEffectBase(audioUnit, inProcessesInPlace),
mUsesKernel(false),
- mProcessor(NULL)
+ mProcessor(nullptr)
{}
virtual ~AVFKernelComponent() {
- // Don't do anything with mProcessor as it could have been deleted already
+ mProcessor = nullptr;
}
virtual AUKernelBase *NewKernel() {
- if (mProcessor) {
+ if (mProcessor != nullptr) {
AUKernelBase *kernel = mProcessor->NewKernel();
mUsesKernel = (kernel != NULL);
return kernel;
}
mUsesKernel = false;
@@ -58,11 +58,11 @@
const CAStreamBasicDescription &inNewFormat) {
OSStatus status = this->AUEffectBase::ChangeStreamFormat(inScope,
inElement,
inPrevFormat,
inNewFormat);
- if (inScope == kAudioUnitScope_Input && inElement == 0) {
+ if (mProcessor != nullptr && inScope == kAudioUnitScope_Input && inElement == 0) {
mProcessor->StreamFormatChanged(inNewFormat);
}
return status;
}
@@ -76,11 +76,11 @@
inBuffer,
outBuffer,
inFramesToProcess);
}
// Otherwise call ProcessBufferLists
- if (mProcessor) {
+ if (mProcessor != nullptr) {
return mProcessor->ProcessBufferLists(ioActionFlags,
inBuffer,
outBuffer,
inFramesToProcess);
}
@@ -94,19 +94,20 @@
UInt32 inDataSize) {
if (inID == kAVFProperty_KernelProcessor &&
inScope == kAudioUnitScope_Global &&
inElement == 0) {
if (inDataSize == sizeof(AVFKernelProcessor*)) {
- AVFKernelProcessor *processor = *((AVFKernelProcessor **)inData);
+ AVFKernelProcessorPtr processor = *((AVFKernelProcessorPtr*)inData);
+ // this compares the raw pointers, not the shared_ptr itself
if (mProcessor != processor) {
- if (mProcessor) {
+ if (mProcessor != nullptr) {
mProcessor->SetAudioUnit(NULL);
- mProcessor = NULL;
+ mProcessor = nullptr;
}
mProcessor = processor;
- if (mProcessor) {
+ if (mProcessor != nullptr) {
mProcessor->SetAudioUnit(this);
const AudioStreamBasicDescription& format =
GetStreamFormat(kAudioUnitScope_Input, 0);
mProcessor->StreamFormatChanged(format);
}
@@ -117,11 +118,11 @@
}
return this->AUEffectBase::SetProperty(inID, inScope, inElement, inData, inDataSize);
}
private:
bool mUsesKernel;
- AVFKernelProcessor *mProcessor;
+ AVFKernelProcessorPtr mProcessor;
};
// Synchronize registration of the component
volatile AudioComponent gAVFComponent = NULL;
pthread_mutex_t gAVFComponentLock = PTHREAD_MUTEX_INITIALIZER;
@@ -142,11 +143,11 @@
pthread_mutex_unlock(&gAVFComponentLock);
return component;
}
-AudioUnit NewKernelProcessorUnit(AVFKernelProcessor *kernel) {
+AudioUnit NewKernelProcessorUnit(AVFKernelProcessorPtr kernel) {
OSStatus status = noErr;
AudioUnit unit = NULL;
AudioComponent ac = GetAVFComponent();
if (!ac) {
@@ -158,11 +159,11 @@
status = AudioUnitSetProperty(unit,
kAVFProperty_KernelProcessor,
kAudioUnitScope_Global,
0,
&kernel,
- sizeof(AVFKernelProcessor**));
+ sizeof(AVFKernelProcessorPtr*));
}
if (noErr != status) {
if (unit) {
AudioComponentInstanceDispose(unit);
< prev index next >