Home | History | Annotate | Download | only in include
      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 #ifndef AAC_BQ_TO_PCM_H_
     18 #define AAC_BQ_TO_PCM_H_
     19 
     20 #include "android/android_AudioToCbRenderer.h"
     21 #include "android/BufferQueueSource.h"
     22 #include "android/include/AacAdtsExtractor.h"
     23 
     24 //--------------------------------------------------------------------------------------------------
     25 namespace android {
     26 
     27 // Class to receive AAC ADTS data through an Android Buffer Queue, decode it and output
     28 // the PCM samples through a registered callback (just like its superclass, AudioToCbRenderer).
     29 // The implementation mainly overrides AudioSfDecoder::onPrepare() for the specificities
     30 // of the data source creation, but all other behavior remains the same (e.g. PCM format metadata)
     31 
     32 class AacBqToPcmCbRenderer : public AudioToCbRenderer
     33 {
     34 public:
     35 
     36     AacBqToPcmCbRenderer(AudioPlayback_Parameters* params);
     37     virtual ~AacBqToPcmCbRenderer();
     38 
     39     void registerSourceQueueCallback(const void* user, void *context,  const void *caller);
     40 
     41     // verifies the given memory starts and ends on ADTS frame boundaries.
     42     // This is for instance used whenever ADTS data is being enqueued through an
     43     // SL / XA AndroidBufferQueue interface so only parseable ADTS data goes in
     44     // the buffer queue, and no ADTS frame is stored across two buffers.
     45     static SLresult validateBufferStartEndOnFrameBoundaries(void* data, size_t size);
     46 
     47 protected:
     48 
     49     // Async event handlers (called from GenericPlayer's event loop)
     50     virtual void onPrepare();
     51 
     52 
     53 private:
     54     // mutex used to protect mBqSource
     55     Mutex                 mBqSourceLock;
     56     sp<BufferQueueSource> mBqSource;
     57 
     58 private:
     59     DISALLOW_EVIL_CONSTRUCTORS(AacBqToPcmCbRenderer);
     60 
     61 };
     62 
     63 } // namespace android
     64 
     65 #endif //AAC_BQ_TO_PCM_H_
     66