Ignore:
Timestamp:
08/21/10 19:01:58 (14 years ago)
Author:
r2d
Message:

audacious-musepack : updated plugin for audacious 2.3 (ubuntu 10.04)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • audacious-musepack/trunk/libmpc.cpp

    r456 r468  
    4848static Widgets      widgets      = {0};
    4949static MpcDecoder   mpcDecoder   = {0};
    50 static TrackInfo    track        = {0};
     50static mpc_streaminfo   streamInfo      = {0};
    5151
    5252static GThread            *threadHandle;
     
    268268}
    269269
    270 static gint mpcIsOurFD(gchar* p_Filename, VFSFile* file)
     270static gint mpcIsOurFD(const gchar* p_Filename, VFSFile* file)
    271271{
    272272    gchar magic[4];
     
    283283    mpcDecoder.offset   = -1;
    284284    mpcDecoder.isAlive  = true;
    285     mpcDecoder.isOutput = false;
    286285    mpcDecoder.isPause  = false;
    287286    threadHandle = g_thread_self();
     
    292291{
    293292    mpcDecoder.isAlive = false;
    294     if (threadHandle)
    295     {
    296         g_thread_join(threadHandle);
    297         if (mpcDecoder.isOutput)
    298         {
    299             data->output->buffer_free();
    300             data->output->close_audio();
    301             mpcDecoder.isOutput = false;
    302         }
    303     }
    304293}
    305294
     
    424413}
    425414
    426 static Tuple *mpcGetTuple(gchar* p_Filename, VFSFile *input)
     415static Tuple *mpcGetTuple(const gchar* p_Filename, VFSFile *input)
    427416{
    428417        Tuple *tuple = 0;
     
    451440        aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, static_cast<int> (1000 * mpc_streaminfo_get_length(&info)));
    452441
    453 //      gchar *scratch = g_strdup_printf("Musepack v%d (encoder %s)", info.stream_version, info.encoder);
    454 //      aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, scratch);
    455 //      g_free(scratch);
    456 
    457 //      scratch = g_strdup_printf("lossy (%s)", info.profile_name);
    458 //      aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, scratch);
    459 //      g_free(scratch);
     442        gchar *scratch = g_strdup_printf("Musepack v%d (encoder %s)", info.stream_version, info.encoder);
     443        aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, scratch);
     444        g_free(scratch);
     445
     446        scratch = g_strdup_printf("lossy (%s)", info.profile_name);
     447        aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, scratch);
     448        g_free(scratch);
    460449
    461450        aud_tuple_associate_int(tuple, FIELD_BITRATE, NULL, static_cast<int> (info.average_bitrate / 1000));
     
    463452        MpcInfo tags = getTags(p_Filename);
    464453
    465 //      aud_tuple_associate_string(tuple, FIELD_DATE, NULL, tags.date);
    466 //      aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, tags.title);
    467 //      aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, tags.artist);
    468 //      aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, tags.album);
    469 //      aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, tags.track);
    470 //      aud_tuple_associate_int(tuple, FIELD_YEAR, NULL, tags.year);
    471 //      aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, tags.genre);
    472 //      aud_tuple_associate_string(tuple, FIELD_COMMENT, NULL, tags.comment);
     454        aud_tuple_associate_string(tuple, FIELD_DATE, NULL, tags.date);
     455        aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, tags.title);
     456        aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, tags.artist);
     457        aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, tags.album);
     458        aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, tags.track);
     459        aud_tuple_associate_int(tuple, FIELD_YEAR, NULL, tags.year);
     460        aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, tags.genre);
     461        aud_tuple_associate_string(tuple, FIELD_COMMENT, NULL, tags.comment);
    473462
    474463        freeTags(tags);
     
    480469}
    481470
    482 static Tuple *mpcProbeForTuple(gchar* p_Filename, VFSFile *input)
     471static Tuple *mpcProbeForTuple(const gchar* p_Filename, VFSFile *input)
    483472{
    484473    return mpcGetTuple(p_Filename, input);
    485474}
    486475
    487 static Tuple *mpcGetSongTuple(gchar* p_Filename)
     476static Tuple *mpcGetSongTuple(const gchar* p_Filename)
    488477{
    489478        return mpcGetTuple(p_Filename, 0);
    490 }
    491 
    492 static char* mpcGenerateTitle(const MpcInfo& p_Tags, gchar* p_Filename)
    493 {
    494     Tuple* tuple = mpcGetSongTuple(p_Filename);
    495 
    496     gchar* title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
    497 
    498     aud_tuple_free((void *) tuple);
    499     return title;
    500479}
    501480
     
    550529}
    551530
    552 static void mpcFileInfoBox(char* p_Filename)
     531static void mpcFileInfoBox(const gchar* p_Filename)
    553532{
    554533    GtkWidget* infoBox = widgets.infoBox;
     
    737716static void* endThread(gchar* p_FileName, VFSFile * p_FileHandle, bool release)
    738717{
    739     if(release)
     718    if (release)
    740719        lockRelease();
    741     if(mpcDecoder.isError)
     720    if (mpcDecoder.isError)
    742721    {
    743722        perror(mpcDecoder.isError);
     
    748727    if(p_FileHandle)
    749728        aud_vfs_fclose(p_FileHandle);
    750     if(track.display)
    751     {
    752         g_free(track.display);
    753         track.display = NULL;
    754     }
    755729    return 0;
    756730}
     
    766740        if (info.bits == -1) return -1; // end of stream
    767741
    768         copyBuffer(sampleBuffer, xmmsBuffer, info.samples * track.channels);
     742        copyBuffer(sampleBuffer, xmmsBuffer, info.samples * streamInfo.channels);
    769743
    770744    if (pluginConfig.dynamicBitrate)
    771745    {
    772                 track.bitrate = static_cast<int> (info.bits * track.sampleFreq / 1152);
     746                mpcDecoder.dynbitrate = info.bits * streamInfo.sample_freq / 1152;
    773747    }
    774748
    775         playback->pass_audio(playback, FMT_S16_LE, track.channels, info.samples * 2 * track.channels, xmmsBuffer, NULL);
     749        playback->output->write_audio(xmmsBuffer, info.samples * 2 * streamInfo.channels);
    776750        return info.samples;
    777751}
     
    798772        }
    799773
    800     mpc_streaminfo info;
    801         mpc_demux_get_info(demux, &info);
    802 
    803     MpcInfo tags     = getTags(filename);
    804     track.display    = mpcGenerateTitle(tags, filename);
    805     track.length     = static_cast<int> (1000 * mpc_streaminfo_get_length(&info));
    806     track.bitrate    = static_cast<int> (info.average_bitrate);
    807     track.sampleFreq = info.sample_freq;
    808     track.channels   = info.channels;
    809     freeTags(tags);
    810 
    811     data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
     774        mpc_demux_get_info(demux, &streamInfo);
     775
     776        data->set_tuple(data, mpcGetTuple(data->filename, input));
     777        data->set_params(data, 0, 0, static_cast<int> (streamInfo.average_bitrate),
     778                                         streamInfo.sample_freq, streamInfo.channels);
    812779
    813780        mpc_set_replay_level(demux, MPC_OLD_GAIN_REF, pluginConfig.replaygain,
     
    817784    char xmmsBuffer[MPC_DECODER_BUFFER_LENGTH * 4];
    818785
    819     if (!data->output->open_audio(FMT_S16_LE, track.sampleFreq, track.channels))
     786    if (!data->output->open_audio(FMT_S16_LE, streamInfo.sample_freq, streamInfo.channels))
    820787    {
    821788        mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open an audio output");
     
    823790    }
    824791
    825         mpcDecoder.isOutput = true;
    826792    lockRelease();
    827793
     
    829795        data->playing = TRUE;
    830796
    831     gint counter = 2 * track.sampleFreq / 3;
     797    gint counter = 2 * streamInfo.sample_freq / 3;
    832798        int status = 0;
    833799    while (mpcDecoder.isAlive)
     
    837803                if (mpcDecoder.offset != -1)
    838804        {
    839                         mpc_demux_seek_sample(demux, mpcDecoder.offset * track.sampleFreq / 1000);
     805                        mpc_demux_seek_sample(demux, mpcDecoder.offset * streamInfo.sample_freq / 1000);
    840806                        data->output->flush(mpcDecoder.offset);
    841807            mpcDecoder.offset = -1;
    842808        }
    843 
    844         short iPlaying = data->output->buffer_playing()? 1 : 0;
    845         gint iFree = data->output->buffer_free();
    846         if (!mpcDecoder.isPause && iFree >= ((1152 * 4) << iPlaying) && status != -1)
     809                lockRelease();
     810
     811        if (mpcDecoder.isPause == FALSE && status != -1)
    847812        {
    848813            status = processBuffer(data, sampleBuffer, xmmsBuffer, demux);
    849             lockRelease();
    850814
    851815            if(pluginConfig.dynamicBitrate)
     
    854818                if(counter < 0)
    855819                {
    856                     data->set_params(data, track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
    857                     counter = 2 * track.sampleFreq / 3;
     820                                        data->set_params(data, 0, 0, mpcDecoder.dynbitrate, streamInfo.sample_freq, streamInfo.channels);
     821                    counter = 2 * streamInfo.sample_freq / 3;
    858822                }
    859823            }
     
    861825        else
    862826        {
    863             lockRelease();
    864827                        if (mpcDecoder.isPause == FALSE && status == -1 &&
    865828                                                 data->output->buffer_playing() == FALSE)
     
    868831        }
    869832    }
     833        data->output->close_audio();
    870834        mpc_demux_exit(demux);
    871835    return endThread(filename, input, false);
     
    882846    mpcAboutBox, // about : Show About box
    883847    mpcConfigBox, // configure : Show Configure box
    884     TRUE, // enabled
     848    0, // PluginPreferences *settings
     849
     850    0, // gboolean have_subtune : Plugin supports/uses subtunes.
     851    (gchar **)mpc_fmts, // vfs_extensions
     852    0, // GList *(*scan_dir) (gchar * dirname);
    885853        0, // is_our_file
    886         0, // scan_dir
     854    mpcIsOurFD, // is_our_file_from_vfs
     855        mpcProbeForTuple, // Tuple *(*probe_for_tuple)(gchar *uri, VFSFile *fd);
    887856    mpcPlay, // play_file
    888857    mpcStop, // stop
    889858    mpcPause, // pause
    890859    mpcSeek, // seek
     860        mpcSeekm, // void (*mseek) (InputPlayback * playback, gulong millisecond);
    891861        0, // get_time
    892862        0, // get_volume
    893863        0, // set_volume
    894         0, // get_vis_type
    895         0, // add_vis_pcm
    896         0, // set_info
    897         0, // set_info_text
    898         0, // get_song_info : Get Title String callback
    899     mpcFileInfoBox, // file_info_box : Show File Info Box
     864        mpcFileInfoBox, // file_info_box : Show File Info Box
    900865    mpcGetSongTuple, // get_song_tuple : Acquire tuple for song
    901     mpcIsOurFD, // is_our_file_from_vfs
    902     (gchar **)mpc_fmts, // vfs_extensions
    903 
    904     /* Added in Audacious 1.4.0 */
    905         mpcSeekm, // void (*mseek) (InputPlayback * playback, gulong millisecond);
    906         mpcProbeForTuple, // Tuple *(*probe_for_tuple)(gchar *uri, VFSFile *fd);
    907 
    908     /* Added in Audacious 1.4.1 */
    909 //     gboolean have_subtune;
    910 
    911     /* Added in Audacious 1.5.0 */
    912 //     gboolean (*update_song_tuple)(Tuple *tuple, VFSFile *fd);
     866    0, //     gboolean (*update_song_tuple)(Tuple *tuple, VFSFile *fd);
     867    0 //gint priority; /* 0 = first, 10 = last */
    913868};
    914869
Note: See TracChangeset for help on using the changeset viewer.