diff options
author | Zach Jang <zachjang@google.com> | 2016-04-21 16:10:50 -0700 |
---|---|---|
committer | The Android Automerger <android-build@android.com> | 2016-04-21 19:17:47 -0700 |
commit | 45737cb776625f17384540523674761e6313e6d4 (patch) | |
tree | 88e7630fe2dc647ff241349d668dcb9271f57751 /include | |
parent | 2b6f22dc64d456471a1dc6df09d515771d1427c8 (diff) | |
download | frameworks_av-45737cb776625f17384540523674761e6313e6d4.zip frameworks_av-45737cb776625f17384540523674761e6313e6d4.tar.gz frameworks_av-45737cb776625f17384540523674761e6313e6d4.tar.bz2 |
Resolve merge conflict when cp'ing ag/931301 to mnc-mr1-release
Change-Id: I079d1db2d30d126f8aed348bd62451acf741037d
Diffstat (limited to 'include')
-rw-r--r-- | include/media/stagefright/DataSource.h | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h index dcde36f..47c5c34 100644 --- a/include/media/stagefright/DataSource.h +++ b/include/media/stagefright/DataSource.h @@ -19,7 +19,7 @@ #define DATA_SOURCE_H_ #include <sys/types.h> - +#include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/MediaErrors.h> #include <utils/Errors.h> #include <utils/KeyedVector.h> @@ -71,6 +71,20 @@ public: bool getUInt32(off64_t offset, uint32_t *x); bool getUInt64(off64_t offset, uint64_t *x); + // Reads in "count" entries of type T into vector *x. + // Returns true if "count" entries can be read. + // If fewer than "count" entries can be read, return false. In this case, + // the output vector *x will still have those entries that were read. Call + // x->size() to obtain the number of entries read. + // The optional parameter chunkSize specifies how many entries should be + // read from the data source at one time into a temporary buffer. Increasing + // chunkSize can improve the performance at the cost of extra memory usage. + // The default value for chunkSize is set to read at least 4k bytes at a + // time, depending on sizeof(T). + template <typename T> + bool getVector(off64_t offset, Vector<T>* x, size_t count, + size_t chunkSize = (4095 / sizeof(T)) + 1); + // May return ERROR_UNSUPPORTED. virtual status_t getSize(off64_t *size); @@ -121,6 +135,51 @@ private: DataSource &operator=(const DataSource &); }; +template <typename T> +bool DataSource::getVector(off64_t offset, Vector<T>* x, size_t count, + size_t chunkSize) +{ + x->clear(); + if (chunkSize == 0) { + return false; + } + if (count == 0) { + return true; + } + + T tmp[chunkSize]; + ssize_t numBytesRead; + size_t numBytesPerChunk = chunkSize * sizeof(T); + size_t i; + + for (i = 0; i + chunkSize < count; i += chunkSize) { + // This loops is executed when more than chunkSize records need to be + // read. + numBytesRead = this->readAt(offset, (void*)&tmp, numBytesPerChunk); + if (numBytesRead == -1) { // If readAt() returns -1, there is an error. + return false; + } + if (numBytesRead < numBytesPerChunk) { + // This case is triggered when the stream ends before the whole + // chunk is read. + x->appendArray(tmp, (size_t)numBytesRead / sizeof(T)); + return false; + } + x->appendArray(tmp, chunkSize); + offset += numBytesPerChunk; + } + + // There are (count - i) more records to read. + // Right now, (count - i) <= chunkSize. + // We do the same thing as above, but with chunkSize replaced by count - i. + numBytesRead = this->readAt(offset, (void*)&tmp, (count - i) * sizeof(T)); + if (numBytesRead == -1) { + return false; + } + x->appendArray(tmp, (size_t)numBytesRead / sizeof(T)); + return x->size() == count; +} + } // namespace android #endif // DATA_SOURCE_H_ |