00001 /** 00002 * @file LogPlayer.h 00003 * 00004 * Definition of class LogPlayer 00005 * 00006 * @author Martin Lötzsch 00007 */ 00008 00009 #ifndef __LogPlayer_h_ 00010 #define __LogPlayer_h_ 00011 00012 #include "MessageQueue.h" 00013 00014 /** 00015 * @class LogPlayer 00016 * 00017 * A message queue that can record and play logfiles. 00018 * The messages are played in the same time sequence as they were recorded. 00019 * 00020 * @author Martin Lötzsch 00021 */ 00022 class LogPlayer : protected MessageQueue 00023 { 00024 public: 00025 /** 00026 * Constructor 00027 * @param targetQueue The queue into that messages from played logfiles shall be stored. 00028 */ 00029 LogPlayer(MessageQueue& targetQueue); 00030 00031 /** different states of the logplayer */ 00032 enum LogPlayerState 00033 { 00034 initial, recording, paused, playing 00035 }; 00036 00037 /** Returns the state of the queue */ 00038 LogPlayerState getState(); 00039 00040 /** Deletes all messages from the queue */ 00041 void _new(); 00042 00043 /** 00044 * Opens a log file and reads all messages into the queue. 00045 * @param fileName the name of the file to open 00046 * @return if the reading was successful 00047 */ 00048 bool open(const char* fileName); 00049 00050 /** 00051 * Playes the queue. 00052 * Note that you have to call onIdle() regularely if you want to use that function 00053 */ 00054 void play(); 00055 00056 /** Pauses playing the queue. */ 00057 void pause(); 00058 00059 /** Stops playing the queue, resets the position in the queue to the first message */ 00060 void stop(); 00061 00062 /** Plays the next message in the queue */ 00063 void stepForward(); 00064 00065 /** Plays the previous message in the queue */ 00066 void stepBackward(); 00067 00068 /** repeats the current message in the queue */ 00069 void stepRepeat(); 00070 00071 /** jumps to given message-number in the queue */ 00072 void jumpFrame(int frame); 00073 00074 /** 00075 * Starts / Stops recording. 00076 * Note that you have to notify the queue on new messages with handleMessage(). 00077 */ 00078 void record(); 00079 00080 /** Activates/deactivates jpeg image smoothing */ 00081 void smooth(); 00082 00083 /** 00084 * Writes all messages in the log player queue to a log file. 00085 * @param fileName the name of the file to write 00086 * @return if the writing was successful 00087 */ 00088 bool save(const char* fileName); 00089 00090 /** 00091 * Writes all messages in the log player queue to an AIBOVision compatibile movie file. 00092 * Images are encoded in a raw YUV format. 00093 * @param fileName the name of the file to write 00094 * @return if the writing was successful 00095 */ 00096 bool saveAMV(const char* fileName); 00097 00098 /** 00099 * Writes an row of doubles to an comma separated value file. 00100 * @param file the open file to write to 00101 * @param row a row containing the doubles to be written 00102 * @param rowLen number of entries in row 00103 */ 00104 void saveCSVrow(OutTextRawFile& file, double* row, unsigned int rowLen); 00105 00106 /** 00107 * Writes a couple of message types in the log player queue to an comma separated value file with a common time line. 00108 * @param fileName the name of the file to write 00109 * @return if the writing was successful 00110 */ 00111 bool saveCSV(const char* fileName); 00112 00113 /** 00114 * Writes all images in the log player queue to a bunch of files (*.bmp or *.jpg). 00115 * @param fileName the name of one file to write, all files will be enumerated by appending a 3 digit number to the filename. 00116 * @return if the writing of all files was successful 00117 */ 00118 bool saveImages(const char* fileName); 00119 00120 /** 00121 * Sets the playing speed of the log player. 00122 * "2" playes the messages double as fast as they were recorded, 00123 * "0.5" plays the messages with the half speed. 00124 */ 00125 void setPlaySpeed(double speed); 00126 00127 /** 00128 * Adds the message to the queue depending on isRecording. 00129 * That function should be called for every message in the queue that the 00130 * log player shall work on. 00131 */ 00132 void handleMessage(InMessage& message); 00133 00134 /** 00135 * If playing a log file, that function checks if it is time to release the next 00136 * message dependend on the time stamp. Call that function whenever there is some 00137 * processing time left. 00138 */ 00139 void onIdle(); 00140 00141 /** Returns the number of stored messages */ 00142 int getNumberOfMessages() const; 00143 00144 /** Returns the number of the current message */ 00145 int getCurrentMessageNumber() const; 00146 00147 /** Returns the type of the current message */ 00148 MessageID getCurrentMessageID() const; 00149 00150 /** Returns the status of the smoothing flag */ 00151 inline bool isSmoothingEnabled() const 00152 { 00153 return smoothingEnabled; 00154 }; 00155 00156 private: 00157 00158 /** the state of the log player */ 00159 LogPlayerState state; 00160 00161 /* The queue into that messages from played logfiles shall be stored. */ 00162 MessageQueue& targetQueue; 00163 00164 /** little routine to convert an integer into C style string*/ 00165 void convertIntString(char* str, int value); 00166 00167 /** 00168 * A factor, how fast the messages are played. 00169 * "2" playes the messages double as fast as they were recorded, 00170 * "0.5" plays the messages with the half speed. 00171 */ 00172 double playSpeed; 00173 00174 /** 00175 * Returns the time stamp of a given message. 00176 * @param message The number of the message 00177 * @return The time stamp 00178 */ 00179 unsigned long getTimeStamp(int message); 00180 00181 protected: 00182 /** The number of the current message */ 00183 int currentMessageNumber; 00184 private: 00185 00186 /** The time when the first message was played */ 00187 unsigned long timeWhenFirstMessageWasPlayed; 00188 00189 /** The time stamp of the first played message */ 00190 unsigned long timeOfFirstPlayedMessage; 00191 00192 /** Flag which triggers smoothing of jpeg compressed images */ 00193 bool smoothingEnabled; 00194 00195 }; 00196 00197 00198 #endif //__LogPlayer_h_ 00199 00200 /* 00201 * Change Log: 00202 * 00203 * $Log: LogPlayer.h,v $ 00204 * Revision 1.1.1.1 2004/05/22 17:37:17 cvsadm 00205 * created new repository GT2004_WM 00206 * 00207 * Revision 1.7 2004/05/19 07:58:15 dueffert 00208 * saving to CSV implemented 00209 * 00210 * Revision 1.6 2004/03/26 16:33:57 thomas 00211 * added field in logplayer to jump directly to a given frame-number 00212 * 00213 * Revision 1.5 2004/03/24 12:55:42 risler 00214 * added logplayer repeat button 00215 * 00216 * Revision 1.4 2004/02/16 12:26:41 nistico 00217 * Added noise reduction functionality for jpeg images in log file player 00218 * 00219 * Revision 1.3 2004/01/20 12:40:09 nistico 00220 * - Added support for ColorTable32K (65K elements in packed format) 00221 * - RobotControl can now convert GT *.log files into AIBOVision (external ColorTable32K calibration tool) *.amv file format 00222 * 00223 * Revision 1.2 2003/12/25 13:13:54 hamerla 00224 * Logplayer extension to LogPlayerWithSync 00225 * 00226 * Revision 1.1 2003/10/07 10:13:24 cvsadm 00227 * Created GT2004 (M.J.) 00228 * 00229 * Revision 1.1.1.1 2003/07/02 09:40:28 cvsadm 00230 * created new repository for the competitions in Padova from the 00231 * tamara CVS (Tuesday 2:00 pm) 00232 * 00233 * removed unused solutions 00234 * 00235 * Revision 1.4 2002/12/15 23:34:13 dueffert 00236 * saving images from logfiles added 00237 * 00238 * Revision 1.3 2002/10/04 10:27:33 loetzsch 00239 * Added functionality to adjust the speed of playing log files. 00240 * 00241 * Revision 1.2 2002/10/02 15:50:41 juengel 00242 * Added getCurrentMessageID. 00243 * 00244 * Revision 1.1 2002/09/10 15:53:59 cvsadm 00245 * Created new project GT2003 (M.L.) 00246 * - Cleaned up the /Src/DataTypes directory 00247 * - Removed challenge related source code 00248 * - Removed processing of incoming audio data 00249 * - Renamed AcousticMessage to SoundRequest 00250 * 00251 * Revision 1.1 2002/08/08 16:40:30 loetzsch 00252 * added class LogPlayer and redesigned RobotControl's Logplayer GUI 00253 * 00254 */