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 THROTTLED_SOURCE_H_ 18 19 #define THROTTLED_SOURCE_H_ 20 21 #include <media/stagefright/DataSource.h> 22 #include <utils/threads.h> 23 24 namespace android { 25 26 struct ThrottledSource : public DataSource { 27 ThrottledSource( 28 const sp<DataSource> &source, 29 int32_t bandwidthLimitBytesPerSecond); 30 31 virtual status_t initCheck() const; 32 33 virtual ssize_t readAt(off64_t offset, void *data, size_t size); 34 35 virtual status_t getSize(off64_t *size); 36 virtual uint32_t flags(); 37 38 private: 39 Mutex mLock; 40 41 sp<DataSource> mSource; 42 int32_t mBandwidthLimitBytesPerSecond; 43 int64_t mStartTimeUs; 44 size_t mTotalTransferred; 45 46 ThrottledSource(const ThrottledSource &); 47 ThrottledSource &operator=(const ThrottledSource &); 48 }; 49 50 } // namespace android 51 52 #endif // THROTTLED_SOURCE_H_ 53