1bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/*
2bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project
3bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
4bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
5bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * you may not use this file except in compliance with the License.
6bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * You may obtain a copy of the License at
7bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
8bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
9bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
10bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
11bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
12bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * See the License for the specific language governing permissions and
14bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * limitations under the License.
15bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */
16bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
17bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#ifndef AAC_BQ_TO_PCM_H_
18bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define AAC_BQ_TO_PCM_H_
19bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
20bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include "android/android_AudioToCbRenderer.h"
21bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include "android/BufferQueueSource.h"
22bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include "android/include/AacAdtsExtractor.h"
23bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
24bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//--------------------------------------------------------------------------------------------------
25bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivinamespace android {
26bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
27bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// Class to receive AAC ADTS data through an Android Buffer Queue, decode it and output
28bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// the PCM samples through a registered callback (just like its superclass, AudioToCbRenderer).
29bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// The implementation mainly overrides AudioSfDecoder::onPrepare() for the specificities
30bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// of the data source creation, but all other behavior remains the same (e.g. PCM format metadata)
31bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
32bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviclass AacBqToPcmCbRenderer : public AudioToCbRenderer
33bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi{
34bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivipublic:
35bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
3670e6a0238597223221a8bf5e506c92acf28aa35fGlenn Kasten    AacBqToPcmCbRenderer(const AudioPlayback_Parameters* params,
3770e6a0238597223221a8bf5e506c92acf28aa35fGlenn Kasten            IAndroidBufferQueue *androidBufferQueue);
38bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual ~AacBqToPcmCbRenderer();
39bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
40bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // verifies the given memory starts and ends on ADTS frame boundaries.
41bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // This is for instance used whenever ADTS data is being enqueued through an
42bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // SL / XA AndroidBufferQueue interface so only parseable ADTS data goes in
43bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // the buffer queue, and no ADTS frame is stored across two buffers.
44677c76347d9aaca4cf3746b3dbfc8a741281066bGlenn Kasten    static SLresult validateBufferStartEndOnFrameBoundaries(void* data, size_t size);
45bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
46bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviprotected:
47bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
48bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // Async event handlers (called from GenericPlayer's event loop)
49bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual void onPrepare();
50bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
51bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
52bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviprivate:
5370e6a0238597223221a8bf5e506c92acf28aa35fGlenn Kasten    const sp<BufferQueueSource> mBqSource;
54bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
55bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviprivate:
56bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    DISALLOW_EVIL_CONSTRUCTORS(AacBqToPcmCbRenderer);
57bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
58bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi};
59bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
60bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi} // namespace android
61bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
62bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#endif //AAC_BQ_TO_PCM_H_
63