11156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber/* 21156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * Copyright (C) 2011 The Android Open Source Project 31156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * 41156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 51156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * you may not use this file except in compliance with the License. 61156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * You may obtain a copy of the License at 71156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * 81156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 91156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * 101156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * Unless required by applicable law or agreed to in writing, software 111156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 121156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * See the License for the specific language governing permissions and 141156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber * limitations under the License. 151156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber */ 161156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 171156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#ifndef HTTP_BASE_H_ 181156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 191156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#define HTTP_BASE_H_ 201156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 211156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#include <media/stagefright/foundation/ABase.h> 221156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#include <media/stagefright/DataSource.h> 235b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong#include <media/stagefright/MediaErrors.h> 245b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong#include <utils/threads.h> 251156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 261156dc913a5ba7b2bc86489468d4914430f03d14Andreas Hubernamespace android { 271156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 281156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huberstruct HTTPBase : public DataSource { 291156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber enum Flags { 301156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber // Don't log any URLs. 311156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber kFlagIncognito = 1 321156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber }; 331156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 341156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber HTTPBase(); 351156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 361156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber virtual status_t connect( 371156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber const char *uri, 381156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber const KeyedVector<String8, String8> *headers = NULL, 391156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber off64_t offset = 0) = 0; 401156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 411156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber virtual void disconnect() = 0; 421156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 431156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber // Returns true if bandwidth could successfully be estimated, 441156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber // false otherwise. 455b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong virtual bool estimateBandwidth(int32_t *bandwidth_bps); 465b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 475b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong virtual status_t getEstimatedBandwidthKbps(int32_t *kbps); 485b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 495b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong virtual status_t setBandwidthStatCollectFreq(int32_t freqMs); 501156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 51a93fd2be99d21629bed504b9b7df035fc2f54562Leena Winterrowd virtual void setBandwidthHistorySize(size_t numHistoryItems); 52a93fd2be99d21629bed504b9b7df035fc2f54562Leena Winterrowd 53a23456b306f35b9ecf973bf5818ca39295e9e029Ashish Sharma static void RegisterSocketUserTag(int sockfd, uid_t uid, uint32_t kTag); 54a23456b306f35b9ecf973bf5818ca39295e9e029Ashish Sharma static void UnRegisterSocketUserTag(int sockfd); 55dab718bba3945332dc75e268e1e7f0fe2eb91c4aAndreas Huber 565908f88a7e45380a9b0d71a3b1ea535d76c420b3Chad Brubaker static void RegisterSocketUserMark(int sockfd, uid_t uid); 575908f88a7e45380a9b0d71a3b1ea535d76c420b3Chad Brubaker static void UnRegisterSocketUserMark(int sockfd); 585908f88a7e45380a9b0d71a3b1ea535d76c420b3Chad Brubaker 595b1b8a93a07326f1cbc627f09e02988375189e0aJames Dongprotected: 60a93fd2be99d21629bed504b9b7df035fc2f54562Leena Winterrowd virtual void addBandwidthMeasurement(size_t numBytes, int64_t delayUs); 615b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 621156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huberprivate: 635b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong struct BandwidthEntry { 645b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong int64_t mDelayUs; 655b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong size_t mNumBytes; 665b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong }; 675b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 685b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong Mutex mLock; 695b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 705b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong List<BandwidthEntry> mBandwidthHistory; 715b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong size_t mNumBandwidthHistoryItems; 725b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong int64_t mTotalTransferTimeUs; 735b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong size_t mTotalTransferBytes; 74a93fd2be99d21629bed504b9b7df035fc2f54562Leena Winterrowd size_t mMaxBandwidthHistoryItems; 755b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 765b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong enum { 775b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong kMinBandwidthCollectFreqMs = 1000, // 1 second 785b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong kMaxBandwidthCollectFreqMs = 60000, // one minute 795b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong }; 805b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 815b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong int64_t mPrevBandwidthMeasureTimeUs; 825b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong int32_t mPrevEstimatedBandWidthKbps; 835b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong int32_t mBandWidthCollectFreqMs; 845b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong 851156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber DISALLOW_EVIL_CONSTRUCTORS(HTTPBase); 861156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber}; 871156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 881156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber} // namespace android 891156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber 901156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#endif // HTTP_BASE_H_ 91