summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/include
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-06-10 15:15:29 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-06-10 15:15:29 -0700
commit61ea6c1bc242841663cb6f3601f89fd929882d0b (patch)
tree8d520cc017cc8f899064db22551147f6aae752be /media/libstagefright/include
parent80737bac407a36e99267f65fe162b8e282822af4 (diff)
parent5994b4798b01f3dd340577c9ea9657f09093a770 (diff)
downloadframeworks_av-61ea6c1bc242841663cb6f3601f89fd929882d0b.zip
frameworks_av-61ea6c1bc242841663cb6f3601f89fd929882d0b.tar.gz
frameworks_av-61ea6c1bc242841663cb6f3601f89fd929882d0b.tar.bz2
Merge "Initial check-in of new caching/prefetching data source implementation." into kraken
Diffstat (limited to 'media/libstagefright/include')
-rw-r--r--media/libstagefright/include/NuCachedSource2.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h
new file mode 100644
index 0000000..c30f029
--- /dev/null
+++ b/media/libstagefright/include/NuCachedSource2.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NU_CACHED_SOURCE_2_H_
+
+#define NU_CACHED_SOURCE_2_H_
+
+#include <media/stagefright/foundation/ABase.h>
+#include <media/stagefright/foundation/AHandlerReflector.h>
+#include <media/stagefright/DataSource.h>
+
+namespace android {
+
+struct ALooper;
+struct PageCache;
+
+struct NuCachedSource2 : public DataSource {
+ NuCachedSource2(const sp<DataSource> &source);
+
+ virtual status_t initCheck() const;
+
+ virtual ssize_t readAt(off_t offset, void *data, size_t size);
+
+ virtual status_t getSize(off_t *size);
+ virtual uint32_t flags();
+
+ ////////////////////////////////////////////////////////////////////////////
+
+ size_t cachedSize();
+ size_t approxDataRemaining(bool *eos);
+
+protected:
+ virtual ~NuCachedSource2();
+
+private:
+ friend struct AHandlerReflector<NuCachedSource2>;
+
+ enum {
+ kPageSize = 16384,
+ kHighWaterThreshold = 3 * 1024 * 1024,
+ kLowWaterThreshold = 512 * 1024,
+ };
+
+ enum {
+ kWhatFetchMore = 'fetc',
+ kWhatRead = 'read',
+ };
+
+ sp<DataSource> mSource;
+ sp<AHandlerReflector<NuCachedSource2> > mReflector;
+ sp<ALooper> mLooper;
+
+ Mutex mSerializer;
+ Mutex mLock;
+ Condition mCondition;
+
+ PageCache *mCache;
+ off_t mCacheOffset;
+ status_t mFinalStatus;
+ off_t mLastAccessPos;
+ sp<AMessage> mAsyncResult;
+ bool mFetching;
+
+ void onMessageReceived(const sp<AMessage> &msg);
+ void onFetch();
+ void onRead(const sp<AMessage> &msg);
+
+ void fetchInternal();
+ ssize_t readInternal(off_t offset, void *data, size_t size);
+ status_t seekInternal_l(off_t offset);
+
+ size_t approxDataRemaining_l(bool *eos);
+ void restartPrefetcherIfNecessary_l();
+
+ DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
+};
+
+} // namespace android
+
+#endif // NU_CACHED_SOURCE_2_H_