1 /*
   2  * Copyright (c) 2014, 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 "AUEffectBase.h"
  30 
  31 
  32 /*
  33  * Instead of writing N components that all basically function the same (at the
  34  * component level), we'll skip the complexity and just write one component that
  35  * handles everything by use of a abstract base class.
  36  */
  37 
  38 /*
  39  * Abstract base class used by the common AudioUnit to manage kernels. All
  40  * processing states must be managed in this class, rather than using properties
  41  * or parameters of the AudioUnit (since this is all private and in-process)
  42  */
  43 class AVFKernelProcessor {
  44 public:
  45     AVFKernelProcessor() :
  46         mAudioUnit(NULL)
  47     {}
  48 
  49     virtual ~AVFKernelProcessor() {}
  50 
  51     // This is used internally, do not call directly
  52     virtual void SetAudioUnit(AUEffectBase *audioUnit) {
  53         mAudioUnit = audioUnit;
  54     }
  55 
  56     virtual void Reset() {}
  57 
  58     /*
  59      * Create a new processing kernel. This is called by the AudioUnit to create
  60      * a kernel that will be called to process audio data. The audioUnit parameter
  61      * is supplied by the component, generally you do not have to do anything with
  62      * it, but it's needed for the AUKernelBase class.
  63      */
  64     virtual AUKernelBase *NewKernel() {
  65         return NULL;
  66     }
  67 
  68     virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags& ioActionFlags,
  69                                         const AudioBufferList& inBuffer,
  70                                         AudioBufferList& outBuffer,
  71                                         UInt32 inFramesToProcess) {
  72         return noErr;
  73     }
  74 
  75 
  76     virtual void StreamFormatChanged(const CAStreamBasicDescription &newFormat) {}
  77 
  78 protected:
  79     AUEffectBase *mAudioUnit;
  80 };
  81 
  82 /*
  83  * Returns an instance of our common AudioUnit set up to use the given kernel
  84  */
  85 extern AudioUnit NewKernelProcessorUnit(AVFKernelProcessor *kernel);
  86 
  87 #endif /* defined(__JFXMedia__AVFKernelProcessor__) */