Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
CostFunction.hpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: CostFunction.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef PS_PROXY_COSTFUNCTION 00045 #define PS_PROXY_COSTFUNCTION 00046 #include "metadata/UserPreferences.hpp" 00047 struct Request; 00048 00049 typedef struct ResourceUsage{ 00050 double network; 00051 double disk; 00052 double cpu; 00053 ResourceUsage(double n,double d, double c) 00054 { 00055 network=n; 00056 disk=d; 00057 cpu=c; 00058 } 00059 ResourceUsage() 00060 { 00061 network=0.0; 00062 disk=0.0; 00063 cpu=0.0; 00064 } 00065 ResourceUsage(const ResourceUsage* u) 00066 { 00067 network=u->network; 00068 disk=u->disk; 00069 cpu=u->cpu; 00070 } 00071 void print(FILE* fp=stdout) { 00072 fprintf(fp,"N=%.2lfD=%.2lfC=%.2lf\n",network,disk,cpu); 00073 } 00074 void subtract(const ResourceUsage* u) 00075 { 00076 network-=u->network; 00077 disk-=u->disk; 00078 cpu-=u->cpu; 00079 } 00080 void add(const ResourceUsage* u) 00081 { 00082 network+=u->network; 00083 disk+=u->disk; 00084 cpu+=u->cpu; 00085 } 00086 } ResourceUsage, ResourcePrices; 00087 00088 typedef struct ResourceLimit { 00090 int network; 00092 int disk; 00094 int cpu; 00095 ResourceLimit() 00096 { 00097 network=disk=cpu=0; 00098 }; 00099 ResourceLimit(int net,int dsk,int cpU) 00100 { 00101 network=net; 00102 disk=dsk; 00103 cpu=cpU; 00104 } 00105 ResourceLimit(const ResourceLimit* l){ 00106 network=l->network; 00107 disk=l->disk; 00108 cpu=l->cpu; 00109 } 00110 } ResourceLimit; 00111 00112 class CostFunction { 00113 public: 00114 static int baseCosts; 00115 static bool checkTranscoding(const Feature* origVideo, const Feature* target); 00116 static ResourceUsage* calcResourceUsage(const Feature* origVideo, 00117 const Feature* targetVideo, const ResourceLimit* r); 00118 00119 static double calcWeightedMonetaryCosts( 00120 const ResourceUsage* systemLoad, 00121 const ResourceUsage* req, 00122 const ResourcePrices* prices, 00123 int baseCosts, 00124 int contentCosts, 00125 int startUpDelayInMS, 00126 int maximumDelayInMS); 00127 00128 static double calcFairMonetaryCosts( 00129 const ResourceUsage* req, 00130 const ResourcePrices* priceInCent, 00131 int baseCosts, 00132 int contentCosts, 00133 double videoduration); 00134 00135 static double calcFinalCosts(double quality, double pay, double weightedcosts); 00136 static double calcFinalCosts( 00137 const Request* origVideo, 00138 const Feature* targetVideo, 00139 const ResourceLimit* r, 00140 const ResourceUsage* systemLoad, 00141 const ResourcePrices* prices,int startupdelay); 00142 /* returns a newly allocated Feature. If the originl one is th best, 00143 * originalBest is set to true and a copy of the req->sourceVideo is returned */ 00144 static Feature* findBestVariation( 00145 const Request* req, 00146 const ResourceUsage* systemLoad, 00147 const ResourceLimit* r, 00148 const ResourcePrices* prices, double* finalCosts, int delayToServer,bool* originalBest); 00149 00152 static void cleanUserPreferences(UserPreferences* u, const Video* source); 00153 00154 static int cpuCostDecoding(int dimX,int dimY, double fps) 00155 { 00156 return (int)(dimX*dimY*fps); 00157 } 00158 00159 static int cpuCostEncoding(int dimX, int dimY, double fps) 00160 { 00161 return (int)(2*dimX*dimY*fps); 00162 }; 00163 static int cpuCostResizing(int targetDimX, int targetDimY, double fps) 00164 { 00165 return (int)(targetDimX*targetDimY*fps*3.72); 00166 }; 00167 static int cpuCostGreyscaling(int targetDimX, int targetDimY, double fps) 00168 { 00169 return (int)(targetDimX*targetDimY*fps*0.008); 00170 }; 00171 }; 00172 00173 #endif 00174 00175