ChromiumHTTPDataSource.h revision 6511c9755c3a3360ba869772600c7aae048a7ffc
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 CHROME_HTTP_DATA_SOURCE_H_ 18 19#define CHROME_HTTP_DATA_SOURCE_H_ 20 21#include <media/stagefright/foundation/AString.h> 22#include <utils/threads.h> 23 24#include "HTTPBase.h" 25 26namespace android { 27 28struct SfDelegate; 29 30struct ChromiumHTTPDataSource : public HTTPBase { 31 ChromiumHTTPDataSource(uint32_t flags = 0); 32 33 virtual status_t connect( 34 const char *uri, 35 const KeyedVector<String8, String8> *headers = NULL, 36 off64_t offset = 0); 37 38 virtual void disconnect(); 39 40 virtual status_t initCheck() const; 41 42 virtual ssize_t readAt(off64_t offset, void *data, size_t size); 43 virtual status_t getSize(off64_t *size); 44 virtual uint32_t flags(); 45 46 virtual bool estimateBandwidth(int32_t *bandwidth_bps); 47 48 virtual sp<DecryptHandle> DrmInitialization(); 49 50 virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client); 51 52 virtual String8 getUri(); 53 54 virtual String8 getMIMEType() const; 55 56protected: 57 virtual ~ChromiumHTTPDataSource(); 58 59private: 60 friend struct SfDelegate; 61 62 enum State { 63 DISCONNECTED, 64 CONNECTING, 65 CONNECTED, 66 READING, 67 DISCONNECTING 68 }; 69 70 struct BandwidthEntry { 71 int64_t mDelayUs; 72 size_t mNumBytes; 73 }; 74 75 const uint32_t mFlags; 76 77 mutable Mutex mLock; 78 Condition mCondition; 79 80 State mState; 81 82 SfDelegate *mDelegate; 83 84 AString mURI; 85 KeyedVector<String8, String8> mHeaders; 86 87 off64_t mCurrentOffset; 88 89 // Any connection error or the result of a read operation 90 // (for the lattter this is the number of bytes read, if successful). 91 ssize_t mIOResult; 92 93 int64_t mContentSize; 94 95 String8 mContentType; 96 97 List<BandwidthEntry> mBandwidthHistory; 98 size_t mNumBandwidthHistoryItems; 99 int64_t mTotalTransferTimeUs; 100 size_t mTotalTransferBytes; 101 102 sp<DecryptHandle> mDecryptHandle; 103 DrmManagerClient *mDrmManagerClient; 104 105 void disconnect_l(); 106 107 status_t connect_l( 108 const char *uri, 109 const KeyedVector<String8, String8> *headers, 110 off64_t offset); 111 112 static void InitiateRead( 113 ChromiumHTTPDataSource *me, void *data, size_t size); 114 115 void initiateRead(void *data, size_t size); 116 117 void onConnectionEstablished( 118 int64_t contentSize, const char *contentType); 119 120 void onConnectionFailed(status_t err); 121 void onReadCompleted(ssize_t size); 122 void onDisconnectComplete(); 123 124 void addBandwidthMeasurement_l(size_t numBytes, int64_t delayUs); 125 126 void clearDRMState_l(); 127 128 DISALLOW_EVIL_CONSTRUCTORS(ChromiumHTTPDataSource); 129}; 130 131} // namespace android 132 133#endif // CHROME_HTTP_DATA_SOURCE_H_ 134