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 LIVE_DATA_SOURCE_H_
18 
19 #define LIVE_DATA_SOURCE_H_
20 
21 #include <media/DataSource.h>
22 #include <media/stagefright/foundation/ABase.h>
23 #include <utils/threads.h>
24 #include <utils/List.h>
25 
26 namespace android {
27 
28 struct ABuffer;
29 
30 struct LiveDataSource : public DataSource {
31     LiveDataSource();
32 
33     virtual status_t initCheck() const;
34 
35     virtual ssize_t readAt(off64_t offset, void *data, size_t size);
36     ssize_t readAtNonBlocking(off64_t offset, void *data, size_t size);
37 
38     void queueBuffer(const sp<ABuffer> &buffer);
39     void queueEOS(status_t finalResult);
40     void reset();
41 
42     size_t countQueuedBuffers();
43 
44 protected:
45     virtual ~LiveDataSource();
46 
47 private:
48     Mutex mLock;
49     Condition mCondition;
50 
51     off64_t mOffset;
52     List<sp<ABuffer> > mBufferQueue;
53     status_t mFinalResult;
54 
55     FILE *mBackupFile;
56 
57     ssize_t readAt_l(off64_t offset, void *data, size_t size);
58 
59     DISALLOW_EVIL_CONSTRUCTORS(LiveDataSource);
60 };
61 
62 }  // namespace android
63 
64 #endif  // LIVE_DATA_SOURCE_H_
65