android_StreamPlayer.h revision 68d56b8ebaf60184a3aef988e3d2b09ed8b88c05
1/*
2 * Copyright (C) 2010 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#include <binder/IServiceManager.h>
18
19
20//--------------------------------------------------------------------------------------------------
21namespace android {
22
23
24class StreamSourceAppProxy : public BnStreamSource {
25public:
26    StreamSourceAppProxy(slAndroidBufferQueueCallback callback, void *appContext,
27            const void *caller);
28    virtual ~StreamSourceAppProxy();
29
30    // IStreamSource implementation
31    virtual void setListener(const sp<IStreamListener> &listener);
32    virtual void setBuffers(const Vector<sp<IMemory> > &buffers);
33    virtual void onBufferAvailable(size_t index);
34
35    void receivedFromAppCommand(IStreamListener::Command cmd);
36    void receivedFromAppBuffer(size_t buffIndex, size_t buffLength);
37
38private:
39    Mutex mListenerLock;
40    sp<IStreamListener> mListener;
41    Vector<sp<IMemory> > mBuffers;
42
43    slAndroidBufferQueueCallback mCallback;
44    void *mAppContext;
45    const void *mCaller;
46
47    DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy);
48};
49
50
51//--------------------------------------------------------------------------------------------------
52class StreamPlayer : public GenericMediaPlayer
53{
54public:
55    StreamPlayer(AudioPlayback_Parameters* params, bool hasVideo);
56    virtual ~StreamPlayer();
57
58    void registerQueueCallback(slAndroidBufferQueueCallback callback, void *context,
59            const void *caller);
60    void appEnqueue(SLuint32 bufferId, SLuint32 length, SLAbufferQueueEvent event, void *pData);
61    void appClear();
62
63protected:
64    sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source
65
66    // overridden from GenericMediaPlayer
67    virtual void onPrepare();
68
69    Mutex mAppProxyLock;
70
71private:
72    DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer);
73};
74
75} // namespace android
76
77
78//--------------------------------------------------------------------------------------------------
79/*
80 * xxx_l functions are called with a lock on the CAudioPlayer mObject
81 */
82extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_cbf_t cbf,
83        void* notifUser);
84extern void android_StreamPlayer_destroy(CAudioPlayer *ap);
85extern void android_StreamPlayer_androidBufferQueue_registerCallback(
86        android::StreamPlayer *splr,
87        slAndroidBufferQueueCallback callback, void* context, const void* callerItf);
88extern void android_StreamPlayer_enqueue_l(CAudioPlayer *ap,
89        SLuint32 bufferId, SLuint32 length, SLAbufferQueueEvent event, void *pData);
90extern void android_StreamPlayer_clear_l(CAudioPlayer *ap);
91