1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #ifndef PVMF_PROTOCOLENGINE_NODE_PROGRESSIVE_DOWNLOAD_H_INCLUDED 20 #define PVMF_PROTOCOLENGINE_NODE_PROGRESSIVE_DOWNLOAD_H_INCLUDED 21 22 #ifndef PVMF_PROTOCOLENGINE_NODE_DOWNLOAD_COMMON_H_INCLUDED 23 #include "pvmf_protocol_engine_node_download_common.h" 24 #endif 25 26 #define DEFAULT_STATE_NUMBER_FOR_DOWNLOAD_GET_REQUEST 1 // for progressive streaming or shoutcast 27 28 29 //////////////////////////////////////////////////////////////////////////////////// 30 ////// ProgressiveDownloadContainer 31 //////////////////////////////////////////////////////////////////////////////////// 32 class ProgressiveDownloadContainer : public DownloadContainer 33 { 34 public: 35 OSCL_IMPORT_REF bool createProtocolObjects(); 36 OSCL_IMPORT_REF bool needSocketReconnect(); needCheckExtraDataComeIn()37 bool needCheckExtraDataComeIn() 38 { 39 return ((++iNumCheckExtraDataComeIn) == 1); 40 } needCheckEOSAfterDisconnectSocket()41 bool needCheckEOSAfterDisconnectSocket() 42 { 43 bool needCheck = ((++iNumCheckEOSAfterDisconnectSocket) == 1); 44 if (needCheck && iNumCheckExtraDataComeIn == 0) 45 { 46 // if EOS happens after socket disconnect, then disable checking any extra data after this EOS 47 // no need to send unexpected data event after server disconnect event gets sent 48 iNumCheckExtraDataComeIn = 1; 49 } 50 return needCheck; 51 } 52 53 // constructor 54 OSCL_IMPORT_REF ProgressiveDownloadContainer(PVMFProtocolEngineNode *aNode = NULL); 55 56 protected: 57 OSCL_IMPORT_REF PVMFStatus initImpl(); 58 OSCL_IMPORT_REF bool initProtocol_SetConfigInfo(); 59 60 protected: 61 uint32 iNumCheckExtraDataComeIn; 62 uint32 iNumCheckEOSAfterDisconnectSocket; 63 }; 64 65 //////////////////////////////////////////////////////////////////////////////////// 66 ////// progressiveDownloadControl 67 //////////////////////////////////////////////////////////////////////////////////// 68 class progressiveDownloadControl : public pvDownloadControl 69 { 70 protected: 71 OSCL_IMPORT_REF bool isDlAlgoPreConditionMet(const uint32 aDownloadRate, 72 const uint32 aDurationMsec, 73 const uint32 aCurrDownloadSize, 74 const uint32 aFileSize); 75 76 // ret_val: 0 success, 1 playback rate is not close to clip bitrate, but the information is all available 77 // -1, related information, e.g. duration=0, size2time conversion is not available, is not available 78 // called by isDlAlgoPreConditionMet() 79 OSCL_IMPORT_REF virtual int32 isPlaybackRateCloseToClipBitrate(const uint32 aDurationMsec, 80 const uint32 aCurrDownloadSize, 81 const uint32 aFileSize); 82 83 // called by isPlaybackRateCloseToClipBitrate, using clip bitrate to do buffer time calculation 84 OSCL_IMPORT_REF bool isBufferingEnoughTime(const uint32 aCurrDownloadSize, 85 const uint32 aBufferTimeLimitInSec, 86 const uint32 aNPTInMS = 0xFFFFFFFF); 87 88 // update duration by new playback rate, called by checkAutoResumeAlgoWithConstraint 89 OSCL_IMPORT_REF bool checkNewDuration(const uint32 aCurrDurationMsec, uint32 &aNewDurationMsec); 90 91 // extra 4 sec buffering time 92 OSCL_IMPORT_REF bool approveAutoResumeDecisionShortCut(const uint32 aCurrDownloadSize, 93 const uint32 aDurationMsec, 94 const uint32 aPlaybackTimeMsec, 95 uint32 &aPlaybackRemainingTimeMsec); 96 97 // No constraint: for file size/clip duration/clip bitrate(i.e. playback rate), one of them must be unavailable, except 98 // file size and clip duration are available, but clip bitrate is unavailable. This only applies on PDL 99 OSCL_IMPORT_REF bool checkAutoResumeAlgoNoConstraint(const uint32 aCurrDownloadSize, 100 const uint32 aFileSize, 101 uint32 &aDurationMsec); 102 103 OSCL_IMPORT_REF bool checkEstDurationAvailable(const uint32 aFileSize, 104 uint32 &aDurationMsec); 105 106 // updata download clock 107 OSCL_IMPORT_REF bool updateDownloadClock(); 108 isOutputBufferOverflow()109 bool isOutputBufferOverflow() 110 { 111 if (!iNodeOutput) return false; 112 return (iNodeOutput->getAvailableOutputSize() == 0); 113 } 114 }; 115 116 //////////////////////////////////////////////////////////////////////////////////// 117 ////// ProgressiveDownloadProgress 118 //////////////////////////////////////////////////////////////////////////////////// 119 class PVDlCfgFileContainer; 120 class ProgressiveDownloadProgress : public DownloadProgress 121 { 122 public: 123 // constructor and destructor ProgressiveDownloadProgress()124 ProgressiveDownloadProgress() 125 { 126 reset(); 127 } ~ProgressiveDownloadProgress()128 ~ProgressiveDownloadProgress() 129 { 130 reset(); 131 } 132 OSCL_IMPORT_REF void setSupportObject(OsclAny *aDLSupportObject, DownloadControlSupportObjectType aType); 133 134 // set download progress mode, time-based or byte-based 135 void setDownloadProgressMode(DownloadProgressMode aMode = DownloadProgressMode_TimeBased) 136 { 137 iDownloadProgressMode = (uint32)aMode; 138 if (aMode == DownloadProgressMode_TimeBased) iTimeBasedDownloadPercent = true; 139 } 140 141 protected: 142 OSCL_IMPORT_REF virtual bool calculateDownloadPercent(uint32 &aDownloadProgressPercent); 143 OSCL_IMPORT_REF bool updateDownloadClock(const bool aDownloadComplete); 144 OSCL_IMPORT_REF bool calculateDownloadPercentBody(uint32 &aDownloadProgressPercent, const uint32 aFileSize); 145 // determine if download percent is time-based or byte-based 146 OSCL_IMPORT_REF bool checkDownloadPercentModeAndUpdateDLClock(); 147 OSCL_IMPORT_REF uint32 getDownloadBytePercent(const uint32 aDownloadSize, const uint32 aFileSize); 148 OSCL_IMPORT_REF void reset(); 149 150 151 protected: 152 PVDlCfgFileContainer *iCfgFileContainer; 153 PVMFFormatProgDownloadSupportInterface *iProgDownloadSI; 154 155 // user-specified download progress mode, 0 - time-based, 1 - byte-based 156 uint32 iDownloadProgressMode; 157 bool iTimeBasedDownloadPercent; // false means byte-based download percent 158 uint32 iDownloadSize; 159 }; 160 161 //////////////////////////////////////////////////////////////////////////////////// 162 ////// UserAgentField and its derived class definition 163 //////////////////////////////////////////////////////////////////////////////////// 164 class UserAgentFieldForProgDownload : public UserAgentField 165 { 166 public: 167 // constructor UserAgentFieldForProgDownload()168 UserAgentFieldForProgDownload() 169 { 170 ; 171 } 172 OSCL_IMPORT_REF UserAgentFieldForProgDownload(OSCL_wString &aUserAgent, const bool isOverwritable = false); 173 OSCL_IMPORT_REF UserAgentFieldForProgDownload(OSCL_String &aUserAgent, const bool isOverwritable = false); 174 175 private: 176 OSCL_IMPORT_REF void getDefaultUserAgent(OSCL_String &aUserAgent); 177 }; 178 179 //////////////////////////////////////////////////////////////////////////////////// 180 ////// PVProgressiveDownloadCfgFileContainer 181 //////////////////////////////////////////////////////////////////////////////////// 182 class PVProgressiveDownloadCfgFileContainer : public PVDlCfgFileContainer 183 { 184 public: PVProgressiveDownloadCfgFileContainer(PVMFDownloadDataSourceContainer * aDataSource)185 PVProgressiveDownloadCfgFileContainer(PVMFDownloadDataSourceContainer *aDataSource) : PVDlCfgFileContainer(aDataSource) 186 { 187 ; 188 } 189 190 private: 191 OSCL_IMPORT_REF PVMFStatus configCfgFile(OSCL_String &aUrl); 192 OSCL_IMPORT_REF PVDlCfgFile::TPVDLPlaybackMode convertToConfigFilePlaybackMode(PVMFDownloadDataSourceHTTP::TPVPlaybackControl aPlaybackMode); 193 }; 194 195 #endif 196 197