1 /* 2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef __JFXMedia__AVFKernelProcessor__ 27 #define __JFXMedia__AVFKernelProcessor__ 28 29 #include <memory> 30 31 #include "AUEffectBase.h" 32 33 34 /* 35 * Instead of writing N components that all basically function the same (at the 36 * component level), we'll skip the complexity and just write one component that 37 * handles everything by use of a abstract base class. 38 */ 39 40 /* 41 * Abstract base class used by the common AudioUnit to manage kernels. All 42 * processing states must be managed in this class, rather than using properties 43 * or parameters of the AudioUnit (since this is all private and in-process) 44 */ 45 class AVFKernelProcessor { 46 public: 47 AVFKernelProcessor() : 48 mAudioUnit(NULL) 49 {} 50 51 virtual ~AVFKernelProcessor() {} 52 53 // This is used internally, do not call directly 54 virtual void SetAudioUnit(AUEffectBase *audioUnit) { 55 mAudioUnit = audioUnit; 56 } 57 58 virtual void Reset() {} 59 60 /* 61 * Create a new processing kernel. This is called by the AudioUnit to create 62 * a kernel that will be called to process audio data. The audioUnit parameter 63 * is supplied by the component, generally you do not have to do anything with 64 * it, but it's needed for the AUKernelBase class. 65 */ 66 virtual AUKernelBase *NewKernel() { 67 return NULL; 68 } 69 70 virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags& ioActionFlags, 71 const AudioBufferList& inBuffer, 72 AudioBufferList& outBuffer, 73 UInt32 inFramesToProcess) { 74 return noErr; 75 } 76 77 78 virtual void StreamFormatChanged(const CAStreamBasicDescription &newFormat) {} 79 80 protected: 81 AUEffectBase *mAudioUnit; 82 }; 83 84 /* 85 * Shared pointer that handles deleting the kernel when it's no longer in use. 86 * Please use this instead of raw pointers. 87 */ 88 89 typedef std::shared_ptr<AVFKernelProcessor> AVFKernelProcessorPtr; 90 91 /* 92 * Returns an instance of our common AudioUnit set up to use the given kernel. 93 * Use static_pointer_cast<AVFKernelProcessor>(kernelPtr) when passing a subclass 94 */ 95 AudioUnit NewKernelProcessorUnit(AVFKernelProcessorPtr kernel); 96 97 #endif /* defined(__JFXMedia__AVFKernelProcessor__) */