OSDN Git Service

Merge 94849a18
[android-x86/system-media.git] / wilhelm / src / android / android_StreamPlayer.h
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 // number of SLuint32 fields to store a buffer event message in an item, by mapping each
20 //   to the item key (SLuint32), the item size (SLuint32), and the item data (mask on SLuint32)
21 #define NB_BUFFEREVENT_ITEM_FIELDS 3
22
23 //--------------------------------------------------------------------------------------------------
24 namespace android {
25
26 //--------------------------------------------------------------------------------------------------
27 class StreamSourceAppProxy : public BnStreamSource {
28 public:
29     StreamSourceAppProxy(
30             const void* user, bool userIsAudioPlayer,
31             void *appContext,
32             const void *caller);
33     virtual ~StreamSourceAppProxy();
34
35     // store an item structure to indicate a processed buffer
36     static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS];
37
38     // IStreamSource implementation
39     virtual void setListener(const sp<IStreamListener> &listener);
40     virtual void setBuffers(const Vector<sp<IMemory> > &buffers);
41     virtual void onBufferAvailable(size_t index);
42
43     // Consumption from ABQ
44     void pullFromBuffQueue();
45
46     void receivedCmd_l(IStreamListener::Command cmd, const sp<AMessage> &msg = NULL);
47     void receivedBuffer_l(size_t buffIndex, size_t buffLength);
48
49 private:
50     // for mListener and mAvailableBuffers
51     Mutex mLock;
52     sp<IStreamListener> mListener;
53     // array of shared memory buffers
54     Vector<sp<IMemory> > mBuffers;
55     // list of available buffers in shared memory, identified by their index
56     List<size_t> mAvailableBuffers;
57
58     const void* mUser;
59     bool mUserIsAudioPlayer;
60     // the Android Buffer Queue from which data is consumed and written to shared memory
61     IAndroidBufferQueue* mAndroidBufferQueue;
62
63     void *mAppContext;
64     const void *mCaller;
65
66     DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy);
67 };
68
69
70 //--------------------------------------------------------------------------------------------------
71 class StreamPlayer : public GenericMediaPlayer
72 {
73 public:
74     StreamPlayer(AudioPlayback_Parameters* params, bool hasVideo);
75     virtual ~StreamPlayer();
76
77     // overridden from GenericPlayer
78     virtual void onMessageReceived(const sp<AMessage> &msg);
79
80     void registerQueueCallback(
81             const void* user, bool userIsAudioPlayer,
82             void *context,
83             const void *caller);
84     void queueRefilled_l();
85     void appClear_l();
86
87 protected:
88
89     enum {
90         // message to asynchronously notify mAppProxy the Android Buffer Queue was refilled
91         kWhatQueueRefilled = 'qrfi'
92     };
93
94     sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source
95
96     // overridden from GenericMediaPlayer
97     virtual void onPrepare();
98
99     void onQueueRefilled();
100
101     Mutex mAppProxyLock;
102
103
104 private:
105     DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer);
106 };
107
108 } // namespace android
109
110
111 //--------------------------------------------------------------------------------------------------
112 /*
113  * xxx_l functions are called with a lock on the CAudioPlayer mObject
114  */
115 extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_cbf_t cbf,
116         void* notifUser);