Changeset 188
- Timestamp:
- 12/23/06 17:07:21 (18 years ago)
- Location:
- winamp-musepack/trunk/winamp-musepack
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
winamp-musepack/trunk/winamp-musepack/in_mpc.cpp
r186 r188 158 158 // point (seek_needed is -1 when no seek is needed) 159 159 // and the decode thread checks seek_needed. 160 void setoutputtime(int time_in_ms) { 161 player->seek_offset = time_in_ms; 160 void setoutputtime(int time_in_ms) 161 { 162 player->setOutputTime(time_in_ms); 162 163 } 163 164 … … 181 182 void getfileinfo(char *filename, char *title, int *length_in_ms) 182 183 { 183 player->getFileInfo(filename, title, length_in_ms); 184 if (!filename || !*filename) 185 player->getFileInfo(title, length_in_ms); 186 else { 187 mpc_player info_play(filename, &mod); 188 info_play.getFileInfo(title, length_in_ms); 189 } 184 190 } 185 191 -
winamp-musepack/trunk/winamp-musepack/mpc_player.cpp
r186 r188 9 9 mpc_player::mpc_player(In_Module * in_mod) 10 10 { 11 init(in_mod); 12 } 13 14 mpc_player::mpc_player(char * fn, In_Module * in_mod) 15 { 16 init(in_mod); 17 openFile(fn); 18 } 19 20 mpc_player::~mpc_player(void) 21 { 22 closeFile(); 23 } 24 25 void mpc_player::init(In_Module * in_mod) 26 { 11 27 thread_handle=INVALID_HANDLE_VALUE; 12 28 killDecodeThread=0; … … 14 30 demux = 0; 15 31 mod = in_mod; 16 } 17 18 mpc_player::~mpc_player(void) 32 wait_event = 0; 33 } 34 35 int mpc_player::openFile(char * fn) 19 36 { 20 37 closeFile(); 21 } 22 23 int mpc_player::openFile(char * fn) 24 { 25 mpc_status err; 26 27 err = mpc_reader_init_stdio(&reader, fn); 38 39 mpc_status err = mpc_reader_init_stdio(&reader, fn); 28 40 if(err < 0) return 1; 29 41 … … 35 47 36 48 mpc_demux_get_info(demux, &si); 49 strcpy(lastfn, fn); 37 50 return 0; 38 51 } … … 45 58 mpc_reader_exit_stdio(&reader); 46 59 } 60 } 61 62 void mpc_player::setOutputTime(int time_in_ms) 63 { 64 seek_offset = time_in_ms; 65 if (wait_event) SetEvent(wait_event); 47 66 } 48 67 … … 73 92 { 74 93 int done = 0; 94 95 wait_event = CreateEvent(0, FALSE, FALSE, 0); 75 96 76 97 while (!killDecodeThread) … … 92 113 break; 93 114 } 94 Sleep(10); // give a little CPU time back to the system.115 WaitForSingleObject(wait_event, 100); // give a little CPU time back to the system. 95 116 } else if (mod->outMod->CanWrite() >= (MPC_FRAME_LENGTH * sizeof(short) * si.channels)*(mod->dsp_isactive()?2:1)) { 96 117 // CanWrite() returns the number of bytes you can write, so we check that … … 105 126 106 127 if(frame.bits == -1) { 107 done =1;128 done = 1; 108 129 } else { 109 130 short output_buffer[MPC_FRAME_LENGTH * 2]; // default 2 channels … … 124 145 mod->outMod->Write((char*)output_buffer, frame.samples * sizeof(short) * si.channels); 125 146 } 126 } else Sleep(20); 127 } 147 } else WaitForSingleObject(wait_event, 1000); 148 } 149 150 CloseHandle(wait_event); 151 wait_event = 0; 152 128 153 return 0; 129 154 } 130 155 131 void mpc_player::getFileInfo(char *filename, char *title, int *length_in_ms) 132 { 133 if (!filename || !*filename) { 134 if (length_in_ms) *length_in_ms = getLength(); 135 if (title) { 136 char *p = lastfn + strlen(lastfn); 137 while (*p != '\\' && p >= lastfn) p--; 138 strcpy(title,++p); 139 } 140 } else { 141 if (length_in_ms) { 142 if (openFile(filename) == 0) { 143 closeFile(); 144 *length_in_ms = getLength(); 145 } else { 146 *length_in_ms = -1000; // the default is unknown file length (-1000). 147 } 148 } 149 if (title) { 150 char *p = filename + strlen(filename); 151 while (*p != '\\' && p >= filename) p--; 152 strcpy(title,++p); 153 } 156 void mpc_player::getFileInfo(char *title, int *length_in_ms) 157 { 158 if (length_in_ms) *length_in_ms = getLength(); 159 if (title) { 160 char *p = lastfn + strlen(lastfn); 161 while (*p != '\\' && p >= lastfn) p--; 162 strcpy(title,++p); 154 163 } 155 164 } … … 158 167 void mpc_player::stop(void) 159 168 { 160 if (thread_handle != INVALID_HANDLE_VALUE) 161 { 162 killDecodeThread=1; 163 if (WaitForSingleObject(thread_handle,10000) == WAIT_TIMEOUT) 164 { 169 if (thread_handle != INVALID_HANDLE_VALUE) { 170 killDecodeThread = 1; 171 if (wait_event) SetEvent(wait_event); 172 if (WaitForSingleObject(thread_handle,10000) == WAIT_TIMEOUT) { 165 173 MessageBox(mod->hMainWindow,"error asking thread to die!\n", 166 "error killing decode thread", 0);167 TerminateThread(thread_handle, 0);174 "error killing decode thread", 0); 175 TerminateThread(thread_handle, 0); 168 176 } 169 177 CloseHandle(thread_handle); … … 189 197 190 198 if (openFile(fn) != 0) return 1; 191 192 strcpy(lastfn,fn);193 199 194 200 // -1 and -1 are to specify buffer and prebuffer lengths. -
winamp-musepack/trunk/winamp-musepack/mpc_player.h
r186 r188 11 11 public: 12 12 mpc_player(In_Module * in_mod); 13 mpc_player(char * fn, In_Module * in_mod); 13 14 ~mpc_player(void); 14 15 15 16 int play(char *fn); 16 17 void stop(void); 17 void getFileInfo(char *filename, char *title, int *length_in_ms); 18 19 void getFileInfo(char *title, int *length_in_ms); 18 20 int getLength(void) {return si.samples * 1000 / si.sample_freq;} 19 21 int getOutputTime(void) {return decode_pos_sample * 1000 / si.sample_freq;} 20 22 23 void setOutputTime(int time_in_ms); 24 21 25 int paused; // are we paused? 22 volatile int seek_offset; // if != -1, it is the point that the decode23 // thread should seek to, in ms.24 26 25 27 private: … … 31 33 32 34 __int64 decode_pos_sample; // decoding position in samples; 35 volatile int seek_offset; // if != -1, it is the point that the decode 36 // thread should seek to, in ms. 33 37 volatile int killDecodeThread; // the kill switch for the decode thread 34 38 35 39 HANDLE thread_handle; // the handle to the decode thread 40 HANDLE wait_event; 36 41 37 42 In_Module * mod; … … 42 47 void closeFile(void); 43 48 49 void init(In_Module * in_mod); 50 44 51 void scaleSamples(short * buffer, int len); 45 52 }; -
winamp-musepack/trunk/winamp-musepack/winamp-musepack.vcproj
r186 r188 176 176 > 177 177 </File> 178 <File 179 RelativePath=".\out.h" 180 > 181 </File> 178 182 </Filter> 179 183 <Filter
Note: See TracChangeset
for help on using the changeset viewer.