Changeset 188


Ignore:
Timestamp:
12/23/06 17:07:21 (17 years ago)
Author:
r2d
Message:
  • removed file info bug
  • improved thread reactivity
Location:
winamp-musepack/trunk/winamp-musepack
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • winamp-musepack/trunk/winamp-musepack/in_mpc.cpp

    r186 r188  
    158158// point (seek_needed is -1 when no seek is needed)
    159159// and the decode thread checks seek_needed.
    160 void setoutputtime(int time_in_ms) {
    161         player->seek_offset = time_in_ms;
     160void setoutputtime(int time_in_ms)
     161{
     162        player->setOutputTime(time_in_ms);
    162163}
    163164
     
    181182void getfileinfo(char *filename, char *title, int *length_in_ms)
    182183{
    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        }
    184190}
    185191
  • winamp-musepack/trunk/winamp-musepack/mpc_player.cpp

    r186 r188  
    99mpc_player::mpc_player(In_Module * in_mod)
    1010{
     11        init(in_mod);
     12}
     13
     14mpc_player::mpc_player(char * fn, In_Module * in_mod)
     15{
     16        init(in_mod);
     17        openFile(fn);
     18}
     19
     20mpc_player::~mpc_player(void)
     21{
     22        closeFile();
     23}
     24
     25void mpc_player::init(In_Module * in_mod)
     26{
    1127        thread_handle=INVALID_HANDLE_VALUE;
    1228        killDecodeThread=0;
     
    1430        demux = 0;
    1531        mod = in_mod;
    16 }
    17 
    18 mpc_player::~mpc_player(void)
     32        wait_event = 0;
     33}
     34
     35int mpc_player::openFile(char * fn)
    1936{
    2037        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);
    2840    if(err < 0) return 1;
    2941
     
    3547
    3648    mpc_demux_get_info(demux,  &si);
     49        strcpy(lastfn, fn);
    3750        return 0;
    3851}
     
    4558                mpc_reader_exit_stdio(&reader);
    4659        }
     60}
     61
     62void mpc_player::setOutputTime(int time_in_ms)
     63{
     64        seek_offset = time_in_ms;
     65        if (wait_event) SetEvent(wait_event);
    4766}
    4867
     
    7392{
    7493        int done = 0;
     94
     95        wait_event = CreateEvent(0, FALSE, FALSE, 0);
    7596
    7697        while (!killDecodeThread)
     
    92113                                break;
    93114                        }
    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.
    95116                } else if (mod->outMod->CanWrite() >= (MPC_FRAME_LENGTH * sizeof(short) * si.channels)*(mod->dsp_isactive()?2:1)) {
    96117                        // CanWrite() returns the number of bytes you can write, so we check that
     
    105126
    106127                        if(frame.bits == -1) {
    107                                 done=1;
     128                                done = 1;
    108129                        } else {
    109130                                short output_buffer[MPC_FRAME_LENGTH * 2]; // default 2 channels
     
    124145                                mod->outMod->Write((char*)output_buffer, frame.samples * sizeof(short) * si.channels);
    125146                        }
    126                 } else Sleep(20);
    127         }
     147                } else WaitForSingleObject(wait_event, 1000);
     148        }
     149
     150        CloseHandle(wait_event);
     151        wait_event = 0;
     152
    128153        return 0;
    129154}
    130155
    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                 }
     156void 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);
    154163        }
    155164}
     
    158167void mpc_player::stop(void)
    159168{
    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) {
    165173                        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);
    168176                }
    169177                CloseHandle(thread_handle);
     
    189197
    190198        if (openFile(fn) != 0) return 1;
    191        
    192         strcpy(lastfn,fn);
    193199
    194200        // -1 and -1 are to specify buffer and prebuffer lengths.
  • winamp-musepack/trunk/winamp-musepack/mpc_player.h

    r186 r188  
    1111public:
    1212        mpc_player(In_Module * in_mod);
     13        mpc_player(char * fn, In_Module * in_mod);
    1314        ~mpc_player(void);
    1415
    1516        int play(char *fn);
    1617        void stop(void);
    17         void getFileInfo(char *filename, char *title, int *length_in_ms);
     18
     19        void getFileInfo(char *title, int *length_in_ms);
    1820        int getLength(void) {return si.samples * 1000 / si.sample_freq;}
    1921        int getOutputTime(void) {return decode_pos_sample * 1000 / si.sample_freq;}
    2022
     23        void setOutputTime(int time_in_ms);
     24
    2125        int paused;                             // are we paused?
    22         volatile int seek_offset; // if != -1, it is the point that the decode
    23                                                           // thread should seek to, in ms.
    2426
    2527private:
     
    3133
    3234        __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.
    3337        volatile int killDecodeThread;  // the kill switch for the decode thread
    3438
    3539        HANDLE thread_handle;   // the handle to the decode thread
     40        HANDLE wait_event;
    3641
    3742        In_Module * mod;
     
    4247        void closeFile(void);
    4348
     49        void init(In_Module * in_mod);
     50
    4451        void scaleSamples(short * buffer, int len);
    4552};
  • winamp-musepack/trunk/winamp-musepack/winamp-musepack.vcproj

    r186 r188  
    176176                                >
    177177                        </File>
     178                        <File
     179                                RelativePath=".\out.h"
     180                                >
     181                        </File>
    178182                </Filter>
    179183                <Filter
Note: See TracChangeset for help on using the changeset viewer.