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 #ifndef NUPLAYER_STREAM_LISTENER_H_
18 
19 #define NUPLAYER_STREAM_LISTENER_H_
20 
21 #include "NuPlayer.h"
22 
23 #include <media/IStreamSource.h>
24 
25 namespace android {
26 
27 class MemoryDealer;
28 
29 struct NuPlayer::NuPlayerStreamListener : public BnStreamListener {
30     NuPlayerStreamListener(
31             const sp<IStreamSource> &source,
32             const sp<AHandler> &targetHandler);
33 
34     virtual void queueBuffer(size_t index, size_t size);
35 
36     virtual void issueCommand(
37             Command cmd, bool synchronous, const sp<AMessage> &extra);
38 
39     void start();
40     ssize_t read(void *data, size_t size, sp<AMessage> *extra);
41 
42 private:
43     enum {
44         kNumBuffers = 8,
45         kBufferSize = 188 * 10
46     };
47 
48     struct QueueEntry {
49         bool mIsCommand;
50 
51         size_t mIndex;
52         size_t mSize;
53         size_t mOffset;
54 
55         Command mCommand;
56         sp<AMessage> mExtra;
57     };
58 
59     Mutex mLock;
60 
61     sp<IStreamSource> mSource;
62     sp<AHandler> mTargetHandler;
63     sp<MemoryDealer> mMemoryDealer;
64     Vector<sp<IMemory> > mBuffers;
65     List<QueueEntry> mQueue;
66     bool mEOS;
67     bool mSendDataNotification;
68 
69     DISALLOW_EVIL_CONSTRUCTORS(NuPlayerStreamListener);
70 };
71 
72 }  // namespace android
73 
74 #endif // NUPLAYER_STREAM_LISTENER_H_
75