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//--------------------------------------------------------------------------------------------------
25namespace 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
32class AacBqToPcmCbRenderer : public AudioToCbRenderer
33{
34public:
35
36    AacBqToPcmCbRenderer(const AudioPlayback_Parameters* params,
37            IAndroidBufferQueue *androidBufferQueue);
38    virtual ~AacBqToPcmCbRenderer();
39
40    // verifies the given memory starts and ends on ADTS frame boundaries.
41    // This is for instance used whenever ADTS data is being enqueued through an
42    // SL / XA AndroidBufferQueue interface so only parseable ADTS data goes in
43    // the buffer queue, and no ADTS frame is stored across two buffers.
44    static SLresult validateBufferStartEndOnFrameBoundaries(void* data, size_t size);
45
46protected:
47
48    // Async event handlers (called from GenericPlayer's event loop)
49    virtual void onPrepare();
50
51
52private:
53    const sp<BufferQueueSource> mBqSource;
54
55private:
56    DISALLOW_EVIL_CONSTRUCTORS(AacBqToPcmCbRenderer);
57
58};
59
60} // namespace android
61
62#endif //AAC_BQ_TO_PCM_H_
63