android_StreamPlayer.h revision 262059f71a68edc5e510427c63f5f1623d3672a8
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 AVPlayer
53{
54public:
55    StreamPlayer(AudioPlayback_Parameters* params);
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 AVPlayer
67    virtual void onPrepare();
68
69private:
70    DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer);
71};
72
73} // namespace android
74
75
76//--------------------------------------------------------------------------------------------------
77/*
78 * xxx_l functions are called with a lock on the CAudioPlayer mObject
79 */
80extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_client_t cbf,
81        void* notifUser);
82extern void android_StreamPlayer_destroy(CAudioPlayer *ap);
83extern void android_StreamPlayer_androidBufferQueue_registerCallback(
84        android::StreamPlayer *splr,
85        slAndroidBufferQueueCallback callback, void* context, const void* callerItf);
86extern void android_StreamPlayer_enqueue_l(CAudioPlayer *ap,
87        SLuint32 bufferId, SLuint32 length, SLAbufferQueueEvent event, void *pData);
88extern void android_StreamPlayer_clear_l(CAudioPlayer *ap);
89