⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface.c

📁 uclinux下mplayer的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * MPlayer GUI for Win32 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de> * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com> * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it> * * This file is part of MPlayer. * * MPlayer is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * MPlayer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MPlayer; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include <windows.h>#include "interface.h"#include "m_option.h"#include "mixer.h"#include "mp_msg.h"#include "help_mp.h"#include "codec-cfg.h"#include "stream/stream.h"#include "libmpdemux/demuxer.h"#include "libmpdemux/stheader.h"#ifdef USE_DVDREAD#include "stream/stream_dvd.h"#endif#include "input/input.h"#include "libvo/video_out.h"#include "libao2/audio_out.h"#include "access_mpcontext.h"#include "gui.h"#include "dialogs.h"#include "wincfg.h"#ifdef HAVE_LIBCDIO#include <cdio/cdio.h>#endifextern int abs_seek_pos;extern float rel_seek_secs;extern int vcd_track;extern af_cfg_t af_cfg;int guiWinID = 0;char *skinName = NULL;char *codecname = NULL;int mplGotoTheNext = 1;static gui_t *mygui = NULL;static int update_subwindow(void);static RECT old_rect;static DWORD style;static HANDLE hThread;static unsigned threadId;ao_functions_t *audio_out = NULL;vo_functions_t *video_out = NULL;mixer_t *mixer = NULL;/* test for playlist files, no need to specify -playlist on the commandline. * add any conceivable playlist extensions here. * - Erik */int parse_filename(char *file, play_tree_t *playtree, m_config_t *mconfig, int clear){    if(clear)        mygui->playlist->clear_playlist(mygui->playlist);    if(strstr(file, ".m3u") || strstr(file, ".pls"))    {        playtree = parse_playlist_file(file);        import_playtree_playlist_into_gui(playtree, mconfig);        return 1;    }    return 0;}/** * \brief this actually creates a new list containing only one element... */void gaddlist( char ***list, const char *entry){    int i;    if (*list)    {        for (i=0; (*list)[i]; i++) free((*list)[i]);        free(*list);    }    *list = malloc(2 * sizeof(char **));    (*list)[0] = gstrdup(entry);    (*list)[1] = NULL;}char *gstrdup(const char *str){    if (!str) return NULL;    return strdup(str);}/** * \brief this replaces a string starting with search by replace. * If not found, replace is appended. */void greplace(char ***list, char *search, char *replace){    int i = 0;    int len = (search) ? strlen(search) : 0;    if (*list)    {        for (i = 0; (*list)[i]; i++)        {            if (search && (!strncmp((*list)[i], search, len)))            {                free((*list)[i]);                (*list)[i] = gstrdup(replace);                return;            }        }    *list = realloc(*list, (i + 2) * sizeof(char *));    }    else        *list = malloc(2 * sizeof(char *));    (*list)[i] = gstrdup(replace);    (*list)[i + 1] = NULL;}/* this function gets called by the gui to update mplayer */static void guiSetEvent(int event){    if(guiIntfStruct.mpcontext)        mixer = mpctx_get_mixer(guiIntfStruct.mpcontext);    switch(event)    {        case evPlay:        case evPlaySwitchToPause:        case evPauseSwitchToPlay:            mplPlay();            break;        case evPause:            mplPause();            break;#ifdef USE_DVDREAD        case evPlayDVD:        {            static char dvdname[MAX_PATH];            guiIntfStruct.DVD.current_title = dvd_title;            guiIntfStruct.DVD.current_chapter = dvd_chapter;            guiIntfStruct.DVD.current_angle = dvd_angle;            guiIntfStruct.DiskChanged = 1;            mplSetFileName(NULL, dvd_device, STREAMTYPE_DVD);            dvdname[0] = 0;            strcat(dvdname, "DVD Movie");            GetVolumeInformation(dvd_device, dvdname, MAX_PATH, NULL, NULL, NULL, NULL, 0);            capitalize(dvdname);            mp_msg(MSGT_GPLAYER, MSGL_V, "Opening DVD %s -> %s\n", dvd_device, dvdname);            guiGetEvent(guiSetParameters, (char *) STREAMTYPE_DVD);            mygui->playlist->clear_playlist(mygui->playlist);            mygui->playlist->add_track(mygui->playlist, filename, NULL, dvdname, 0);            mygui->startplay(mygui);            break;        }#endif#ifdef HAVE_LIBCDIO        case evPlayCD:        {            int i;            char track[10];            char trackname[10];            CdIo_t *p_cdio = cdio_open(NULL, DRIVER_UNKNOWN);            track_t i_tracks;            if(p_cdio == NULL) printf("Couldn't find a driver.\n");            i_tracks = cdio_get_num_tracks(p_cdio);            mygui->playlist->clear_playlist(mygui->playlist);            for(i=0;i<i_tracks;i++)            {                sprintf(track, "cdda://%d", i+1);                sprintf(trackname, "Track %d", i+1);                mygui->playlist->add_track(mygui->playlist, track, NULL, trackname, 0);            }            cdio_destroy(p_cdio);            mygui->startplay(mygui);            break;        }#endif        case evFullScreen:            mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen"));            break;        case evExit:        {            /* We are asking mplayer to exit, later it will ask us after uninit is made               this should be the only safe way to quit */            mygui->activewidget = NULL;            mp_input_queue_cmd(mp_input_parse_cmd("quit"));            break;        }        case evStop:            if(guiIntfStruct.Playing)                guiGetEvent(guiCEvent, (void *) guiSetStop);            break;        case evSetMoviePosition:        {            rel_seek_secs = guiIntfStruct.Position / 100.0f;            abs_seek_pos = 3;            break;        }        case evForward10sec:        {            rel_seek_secs = 10.0f;            abs_seek_pos = 0;            break;        }        case evBackward10sec:        {            rel_seek_secs = -10.0f;            abs_seek_pos = 0;            break;        }        case evSetBalance:        case evSetVolume:        {            float l,r;            if (guiIntfStruct.Playing == 0)                break;            if (guiIntfStruct.Balance == 50.0f)                mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume);            l = guiIntfStruct.Volume * ((100.0f - guiIntfStruct.Balance) / 50.0f);            r = guiIntfStruct.Volume * ((guiIntfStruct.Balance) / 50.0f);            if (l > guiIntfStruct.Volume) l=guiIntfStruct.Volume;            if (r > guiIntfStruct.Volume) r=guiIntfStruct.Volume;            mixer_setvolume(mixer, l, r);            /* Check for balance support on mixer - there is a better way ?? */            if (r != l)            {                mixer_getvolume(mixer, &l, &r);                if (r == l)                {                    mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Mixer doesn't support balanced audio\n");                    mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume);                    guiIntfStruct.Balance = 50.0f;                }            }            break;        }        case evMute:        {            mp_cmd_t * cmd = calloc(1, sizeof(*cmd));            cmd->id=MP_CMD_MUTE;            cmd->name=strdup("mute");            mp_input_queue_cmd(cmd);            break;        }        case evDropFile:        case evLoadPlay:        {            switch(guiIntfStruct.StreamType)            {#ifdef USE_DVDREAD                case STREAMTYPE_DVD:                {                    guiIntfStruct.Title = guiIntfStruct.DVD.current_title;                    guiIntfStruct.Chapter = guiIntfStruct.DVD.current_chapter;                    guiIntfStruct.Angle = guiIntfStruct.DVD.current_angle;                    guiIntfStruct.DiskChanged = 1;                    guiGetEvent(guiCEvent, (void *) guiSetPlay);                    break;                }#endif                default:                {                    guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1;                    update_playlistwindow();                    mplGotoTheNext = guiIntfStruct.Playing? 0 : 1;                    guiGetEvent(guiCEvent, (void *) guiSetStop);                    guiGetEvent(guiCEvent, (void *) guiSetPlay);                    break;               }           }           break;        }        case evNext:            mplNext();            break;        case evPrev:            mplPrev();            break;    }}void mplPlay( void ){   if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0))     return;   if(guiIntfStruct.Playing > 0)   {       mplPause();       return;   }   guiIntfStruct.NewPlay = 1;   guiGetEvent(guiCEvent, (void *) guiSetPlay);}void mplPause( void ){   if(!guiIntfStruct.Playing) return;   if(guiIntfStruct.Playing == 1)   {       mp_cmd_t * cmd = calloc(1, sizeof(*cmd));       cmd->id=MP_CMD_PAUSE;       cmd->name=strdup("pause");       mp_input_queue_cmd(cmd);   } else guiIntfStruct.Playing = 1;}void mplNext(void){    if(guiIntfStruct.Playing == 2) return;    switch(guiIntfStruct.StreamType)    {#ifdef USE_DVDREAD        case STREAMTYPE_DVD:            if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1))                return;            guiIntfStruct.DVD.current_chapter++;            break;#endif        default:            if(mygui->playlist->current == (mygui->playlist->trackcount - 1))                return;            mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename,                           STREAMTYPE_STREAM);            break;    }    mygui->startplay(mygui);}void mplPrev(void){    if(guiIntfStruct.Playing == 2) return;    switch(guiIntfStruct.StreamType)    {#ifdef USE_DVDREAD        case STREAMTYPE_DVD:            if(guiIntfStruct.DVD.current_chapter == 1)                return;            guiIntfStruct.DVD.current_chapter--;            break;#endif        default:            if(mygui->playlist->current == 0)                return;            mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename,                           STREAMTYPE_STREAM);            break;    }    mygui->startplay(mygui);}void mplEnd( void ){    if(!mplGotoTheNext && guiIntfStruct.Playing)    {        mplGotoTheNext = 1;        return;    }    if(mplGotoTheNext && guiIntfStruct.Playing &&      (mygui->playlist->current < (mygui->playlist->trackcount - 1)) &&      guiIntfStruct.StreamType != STREAMTYPE_DVD &&      guiIntfStruct.StreamType != STREAMTYPE_DVDNAV)    {        /* we've finished this file, reset the aspect */        if(movie_aspect >= 0)            movie_aspect = -1;        mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1;        mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM);        //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename);    }    if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay)        return;    guiIntfStruct.TimeSec = 0;    guiIntfStruct.Position = 0;    guiIntfStruct.AudioType = 0;#ifdef USE_DVDREAD    guiIntfStruct.DVD.current_title = 1;    guiIntfStruct.DVD.current_chapter = 1;    guiIntfStruct.DVD.current_angle = 1;#endif    if (mygui->playlist->current == (mygui->playlist->trackcount - 1))        mygui->playlist->current = 0;    fullscreen = 0;    if(style == WS_VISIBLE | WS_POPUP)    {        style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX;        SetWindowLong(mygui->subwindow, GWL_STYLE, style);    }    guiGetEvent(guiCEvent, (void *) guiSetStop);}void mplSetFileName(char *dir, char *name, int type){    if(!name) return;    if(!dir)        guiSetFilename(guiIntfStruct.Filename, name)    else        guiSetDF(guiIntfStruct.Filename, dir, name);    guiIntfStruct.StreamType = type;    free((void **) &guiIntfStruct.AudioFile);    free((void **) &guiIntfStruct.Subtitlename);}void mplFullScreen( void ){    if(!guiIntfStruct.sh_video) return;    if(sub_window)    {        if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow))           GetWindowRect(mygui->subwindow, &old_rect);        if(fullscreen)        {            fullscreen = 0;            style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX;        } else {            fullscreen = 1;            style = WS_VISIBLE | WS_POPUP;        }        SetWindowLong(mygui->subwindow, GWL_STYLE, style);        update_subwindow();    }    video_out->control(VOCTRL_FULLSCREEN, 0);    if(sub_window) ShowWindow(mygui->subwindow, SW_SHOW);}static unsigned __stdcall GuiThread(void* param){    MSG msg;    if(!skinName) skinName = strdup("Blue");    if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent);    if(!mygui) exit_player("Unable to load GUI.");    if(autosync && autosync != gtkAutoSync)    {       gtkAutoSyncOn = 1;       gtkAutoSync = autosync;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -