Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 // sp<> capable proxy for AudioTrack
     18 
     19 #include <media/AudioTrack.h>
     20 
     21 namespace android {
     22 
     23 class AudioTrackProxy : public RefBase {
     24 
     25 public:
     26 
     27     AudioTrackProxy(AudioTrack *raw) : mRaw(raw) { assert(raw != NULL); }
     28 
     29     // don't define all methods, just the ones needed
     30 
     31     void setVolume(float left, float right)
     32             { mRaw->setVolume(left, right); }
     33     void stop()
     34             { mRaw->stop(); }
     35     void start()
     36             { mRaw->start(); }
     37     status_t initCheck()
     38             { return mRaw->initCheck(); }
     39     status_t setSampleRate(int sampleRate)
     40             { return mRaw->setSampleRate(sampleRate); }
     41     void pause()
     42             { mRaw->pause(); }
     43     void getPosition(uint32_t *p)
     44             { mRaw->getPosition(p); }
     45     void mute(bool muted)
     46             { mRaw->mute(muted); }
     47     void flush()
     48             { mRaw->flush(); }
     49     void setMarkerPosition(uint32_t marker)
     50             { mRaw->setMarkerPosition(marker); }
     51     void setPositionUpdatePeriod(uint32_t updatePeriod)
     52             { mRaw->setPositionUpdatePeriod(updatePeriod); }
     53     status_t attachAuxEffect(int effectId)
     54             { return mRaw->attachAuxEffect(effectId); }
     55     status_t setAuxEffectSendLevel(float level)
     56             { return mRaw->setAuxEffectSendLevel(level); }
     57 
     58 protected:
     59 
     60     virtual ~AudioTrackProxy()
     61             { }
     62     virtual void onLastStrongRef(const void* id)
     63             {
     64                 assert(mRaw != NULL);
     65                 delete mRaw;
     66                 mRaw = NULL;
     67             }
     68 
     69 private:
     70     android::AudioTrack *mRaw;
     71 
     72     AudioTrackProxy(const AudioTrackProxy &);
     73     AudioTrackProxy &operator=(const AudioTrackProxy &);
     74 };
     75 
     76 }
     77