Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 HTTP_BASE_H_ |
| 18 | |
| 19 | #define HTTP_BASE_H_ |
| 20 | |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 21 | #include <media/DataSource.h> |
Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 22 | #include <media/stagefright/foundation/ABase.h> |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 23 | #include <media/stagefright/MediaErrors.h> |
Dongwon Kang | 49ce671 | 2018-01-24 10:16:25 -0800 | [diff] [blame] | 24 | #include <utils/List.h> |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 25 | #include <utils/threads.h> |
Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | struct HTTPBase : public DataSource { |
| 30 | enum Flags { |
| 31 | // Don't log any URLs. |
| 32 | kFlagIncognito = 1 |
| 33 | }; |
| 34 | |
| 35 | HTTPBase(); |
| 36 | |
| 37 | virtual status_t connect( |
| 38 | const char *uri, |
| 39 | const KeyedVector<String8, String8> *headers = NULL, |
| 40 | off64_t offset = 0) = 0; |
| 41 | |
| 42 | virtual void disconnect() = 0; |
| 43 | |
| 44 | // Returns true if bandwidth could successfully be estimated, |
| 45 | // false otherwise. |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 46 | virtual bool estimateBandwidth(int32_t *bandwidth_bps); |
| 47 | |
| 48 | virtual status_t getEstimatedBandwidthKbps(int32_t *kbps); |
| 49 | |
| 50 | virtual status_t setBandwidthStatCollectFreq(int32_t freqMs); |
Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 51 | |
Leena Winterrowd | a93fd2b | 2014-12-04 14:03:03 -0800 | [diff] [blame] | 52 | virtual void setBandwidthHistorySize(size_t numHistoryItems); |
| 53 | |
Marco Nelissen | 69d3d8a | 2016-03-07 13:20:01 -0800 | [diff] [blame] | 54 | virtual String8 toString() { |
| 55 | return mName; |
| 56 | } |
| 57 | |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 58 | protected: |
Leena Winterrowd | a93fd2b | 2014-12-04 14:03:03 -0800 | [diff] [blame] | 59 | virtual void addBandwidthMeasurement(size_t numBytes, int64_t delayUs); |
Marco Nelissen | 69d3d8a | 2016-03-07 13:20:01 -0800 | [diff] [blame] | 60 | String8 mName; |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 61 | |
Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 62 | private: |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 63 | struct BandwidthEntry { |
| 64 | int64_t mDelayUs; |
| 65 | size_t mNumBytes; |
| 66 | }; |
| 67 | |
| 68 | Mutex mLock; |
| 69 | |
| 70 | List<BandwidthEntry> mBandwidthHistory; |
| 71 | size_t mNumBandwidthHistoryItems; |
| 72 | int64_t mTotalTransferTimeUs; |
| 73 | size_t mTotalTransferBytes; |
Leena Winterrowd | a93fd2b | 2014-12-04 14:03:03 -0800 | [diff] [blame] | 74 | size_t mMaxBandwidthHistoryItems; |
James Dong | 5b1b8a9 | 2011-05-25 19:37:03 -0700 | [diff] [blame] | 75 | |
| 76 | enum { |
| 77 | kMinBandwidthCollectFreqMs = 1000, // 1 second |
| 78 | kMaxBandwidthCollectFreqMs = 60000, // one minute |
| 79 | }; |
| 80 | |
| 81 | int64_t mPrevBandwidthMeasureTimeUs; |
| 82 | int32_t mPrevEstimatedBandWidthKbps; |
| 83 | int32_t mBandWidthCollectFreqMs; |
| 84 | |
Andreas Huber | 1156dc9 | 2011-03-08 15:59:28 -0800 | [diff] [blame] | 85 | DISALLOW_EVIL_CONSTRUCTORS(HTTPBase); |
| 86 | }; |
| 87 | |
| 88 | } // namespace android |
| 89 | |
| 90 | #endif // HTTP_BASE_H_ |