📄 gme.cpp
字号:
/***************************************************************************** * gme.cpp: Game Music files demuxer (using Game_Music_Emu) ***************************************************************************** * Copyright (C) 2006 the VideoLAN team * $Id$ * * Authors: Jean Sreng <fox@videolan.org> * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include "Nsf_Emu.h"#include "Gbs_Emu.h"#include "Vgm_Emu.h"#include "Spc_Emu.h"#include "Gym_Emu.h"#ifdef HAVE_ZLIB_H #include "zlib.h"#endifusing namespace std;/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close ( vlc_object_t * );vlc_module_begin(); set_shortname( "GME"); set_description( N_("GME demuxer (Game_Music_Emu)" ) ); set_capability( "demux", 10 ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_DEMUX ); set_callbacks( Open, Close ); add_shortcut( "gme" );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/enum EmuType_e{ EMU_NSF = 0, EMU_GBS = 1, EMU_VGM = 2, EMU_SPC = 3, EMU_GYM = 4};static const char* type_str[] ={ "NSF (Nes)", "GBS (Gameboy)", "VGM (Master System/Game Gear/Genesis)", "SPC (Super Nes)", "GYM (Genesis)"};struct demux_sys_t{ es_format_t fmt; es_out_id_t *es; int64_t i_time; int64_t i_length; int i_data; uint8_t *p_data; int i_type; int i_tracks; Music_Emu *p_musicemu; Emu_Mem_Reader *p_reader; vlc_meta_t *p_meta;};static int Demux ( demux_t *p_demux );static int Control( demux_t *p_demux, int i_query, va_list args );#ifdef HAVE_ZLIB_Hstatic void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuffer, size_t * pi_osize);#endifstatic const char* gme_ext[] ={ "nsf", "nsfe", "gbs", "vgm", "vgz", "spc", "gym", NULL};/***************************************************************************** * Open *****************************************************************************/static int Open( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; char *ext; int i; vlc_value_t val; /* We accept file based on extention match */ if( !p_demux->b_force ) { if( ( ext = strrchr( p_demux->psz_path, '.' ) ) == NULL || stream_Size( p_demux->s ) == 0 ) return VLC_EGENERIC; ext++; /* skip . */ for( i = 0; gme_ext[i] != NULL; i++ ) { if( !strcasecmp( ext, gme_ext[i] ) ) { break; } } if( gme_ext[i] == NULL ) return VLC_EGENERIC; msg_Dbg( p_demux, "running GME demuxer (ext=%s)", gme_ext[i] ); }#ifndef HAVE_ZLIB_H if (i == 4) /* gzipped vgm */ { msg_Dbg( p_demux, "zlib unvailable, unable to read gzipped vgz file" ); return VLC_EGENERIC; }#endif /* Fill p_demux field */ p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = (demux_sys_t *)malloc( sizeof( demux_sys_t ) ); msg_Dbg( p_demux, "loading complete file (could be long)" ); p_sys->i_data = stream_Size( p_demux->s ); p_sys->p_data = (uint8_t *)malloc( p_sys->i_data ); p_sys->i_data = stream_Read( p_demux->s, p_sys->p_data, p_sys->i_data ); if( p_sys->i_data <= 0 ) { msg_Err( p_demux, "failed to read the complete file" ); free( p_sys->p_data ); free( p_sys ); return VLC_EGENERIC; } /* Prepare emulator */ #ifdef HAVE_ZLIB_H if (i == 4) /* gzipped vgm */ { uint8_t * p_outbuffer; size_t i_outsize; inflate_gzbuf( p_sys->p_data, p_sys->i_data, &p_outbuffer, &i_outsize ); if (p_outbuffer == NULL) { msg_Err( p_demux, "failed to understand the file : unable to inflate vgz file" ); /* we try to seek to recover for other plugin */ stream_Seek( p_demux->s, 0 ); free( p_sys->p_data ); free( p_sys ); return VLC_EGENERIC; } free(p_sys->p_data); p_sys->p_data = p_outbuffer; p_sys->i_data = i_outsize; }#endif p_sys->p_reader = new Emu_Mem_Reader( p_sys->p_data, p_sys->i_data ); switch(i) { case 0: case 1: p_sys->i_type = EMU_NSF; break; case 2: p_sys->i_type = EMU_GBS; break; case 3: case 4: p_sys->i_type = EMU_VGM; break; case 5: p_sys->i_type = EMU_SPC; break; case 6: p_sys->i_type = EMU_GYM; break; } /* Emulator specific initialization */#define INIT_EMU(type) \ type##_Emu::header_t header; \ type##_Emu * p_emu = new type##_Emu; \ p_emu->init( 44100 ); \ p_sys->p_musicemu = p_emu; \ p_sys->p_reader->read( &header, sizeof(header) ); \ p_error = p_emu->load( header, *(p_sys->p_reader) ); p_sys->p_meta = vlc_meta_New(); char psz_temp[512]; /// \todo Reinstate meta codec name //SET_META( VLC_META_CODEC_NAME, type_str[p_sys->i_type]) const char * p_error; switch(p_sys->i_type) { case EMU_NSF: { INIT_EMU(Nsf) if (p_error == NULL) { vlc_meta_SetTitle( p_meta, header.game ); vlc_meta_SetArtist( p_meta, header.author ); vlc_meta_SetCopyright( p_meta, header.copyright ); p_sys->i_tracks = p_emu->track_count(); } } break; case EMU_GBS: { INIT_EMU(Gbs) if (p_error == NULL) { vlc_meta_SetTitle( p_meta, header.game ); vlc_meta_SetArtist( p_meta, header.author ); vlc_meta_SetCopyright( p_meta, header.copyright ); p_sys->i_tracks = p_emu->track_count(); } } break; case EMU_VGM: { INIT_EMU(Vgm) if (p_error == NULL) { p_sys->i_tracks = p_emu->track_count(); } } break; case EMU_SPC: { INIT_EMU(Spc) if (p_error == NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -