ThrottledSource.h revision bd9c9a80fd487b3e83861c32b388eac146f8a299
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
24namespace android {
25
26struct 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    virtual String8 getMIMEType() const {
39        return mSource->getMIMEType();
40    }
41
42
43private:
44    Mutex mLock;
45
46    sp<DataSource> mSource;
47    int32_t mBandwidthLimitBytesPerSecond;
48    int64_t mStartTimeUs;
49    size_t mTotalTransferred;
50
51    ThrottledSource(const ThrottledSource &);
52    ThrottledSource &operator=(const ThrottledSource &);
53};
54
55}  // namespace android
56
57#endif  // THROTTLED_SOURCE_H_
58