1bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi/*
2bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project
3bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
4bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
5bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * you may not use this file except in compliance with the License.
6bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * You may obtain a copy of the License at
7bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
8bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
9bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi *
10bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
11bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
12bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * See the License for the specific language governing permissions and
14bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi * limitations under the License.
15bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi */
16bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
17bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#ifndef BUFFERQUEUE_SOURCE_H_
18bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define BUFFERQUEUE_SOURCE_H_
19bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
20bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#include <media/stagefright/DataSource.h>
21bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
22bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// number of SLuint32 fields to store a buffer event message in an item, by mapping each
23bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi//   to the item key (SLuint32), the item size (SLuint32), and the item data (mask on SLuint32)
24bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define NB_BUFFEREVENT_ITEM_FIELDS 3
25bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
26bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivinamespace android {
27bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
28bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// a Stagefright DataSource that pulls data from an AndroidBufferQueue
29bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
30bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviclass BufferQueueSource : public DataSource {
31bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivipublic:
32bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
33bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // store an item structure to indicate a processed buffer
34bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS];
35bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
3670e6a0238597223221a8bf5e506c92acf28aa35fGlenn Kasten    BufferQueueSource(IAndroidBufferQueue *androidBufferQueue);
37bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
38bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual status_t initCheck() const;
39bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
40bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual ssize_t readAt(off64_t offset, void *data, size_t size);
41bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
42bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual status_t getSize(off64_t *size);
43bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
44bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    virtual ~BufferQueueSource();
45bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
46bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviprivate:
47bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // the Android Buffer Queue from which data is consumed
4870e6a0238597223221a8bf5e506c92acf28aa35fGlenn Kasten    IAndroidBufferQueue* const mAndroidBufferQueueSource;
49bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
50bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // a monotonically increasing offset used to translate an offset from the beginning
51bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    // of the stream, to an offset in each buffer from the buffer queue source
52bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    off64_t mStreamToBqOffset;
53bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
54113a9f14ea680a441540436b342f5008605aba27Jean-Michel Trivi    // indicates whether an EOS command has been reached when consuming the buffers in the queue
55113a9f14ea680a441540436b342f5008605aba27Jean-Michel Trivi    bool mEosReached;
56113a9f14ea680a441540436b342f5008605aba27Jean-Michel Trivi
57bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    BufferQueueSource(const BufferQueueSource &);
58bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi    BufferQueueSource &operator=(const BufferQueueSource &);
59bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi};
60bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
61bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi}  // namespace android
62bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
63bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#endif  // BUFFERQUEUE_SOURCE_H_
64bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi
65