OSDN Git Service

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