📄 gme.cpp
字号:
snprintf( psz_temp, 511, "%s (%s)", header.song, header.game ); vlc_meta_SetTitle( p_meta, psz_temp ); vlc_meta_SetArtist( p_meta, header.author ); p_sys->i_tracks = p_emu->track_count(); } } break; case EMU_GYM: { INIT_EMU(Gym) if (p_error == NULL) { snprintf( psz_temp, 511, "%s (%s)", header.song, header.game ); vlc_meta_SetTitle( p_meta, psz_temp ); vlc_meta_SetCopyright( p_meta, header.copyright ); p_sys->i_tracks = p_emu->track_count(); } } break; } if( p_error != NULL ) { msg_Err( p_demux, "failed to understand the file : %s", p_error ); /* 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; } /* init time */ p_sys->i_time = 1; p_sys->i_length = 314 * (int64_t)1000; msg_Dbg( p_demux, "GME loaded type=%s title=%s tracks=%i", type_str[p_sys->i_type], vlc_meta_GetValue( p_sys->p_meta, VLC_META_TITLE ), p_sys->i_tracks ); p_sys->p_musicemu->start_track( 0 );#ifdef WORDS_BIGENDIAN es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 't', 'w', 'o', 's' ) );#else es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 'a', 'r', 'a', 'w' ) );#endif p_sys->fmt.audio.i_rate = 44100; p_sys->fmt.audio.i_channels = 2; p_sys->fmt.audio.i_bitspersample = 16; p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt ); return VLC_SUCCESS;}/***************************************************************************** * Close *****************************************************************************/static void Close( vlc_object_t *p_this ){ demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; delete p_sys->p_musicemu; delete p_sys->p_reader; free( p_sys->p_data ); free( p_sys );}/***************************************************************************** * Demux: *****************************************************************************/static int Demux( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; block_t *p_frame; int i_bk = ( p_sys->fmt.audio.i_bitspersample / 8 ) * p_sys->fmt.audio.i_channels; const unsigned int i_buf = p_sys->fmt.audio.i_rate / 10 * i_bk; const unsigned int i_emubuf = i_buf / sizeof(Music_Emu::sample_t); const char * p_error; Music_Emu::sample_t p_emubuf [i_emubuf]; p_frame = block_New( p_demux, i_buf ); p_sys->p_musicemu->play( i_emubuf, p_emubuf ); /* if( p_error != NULL ) { msg_Dbg( p_demux, "stop playing : %s", p_error ); block_Release( p_frame ); return 0; } */ /* Copy emulator output to frame */ for (int i = 0; i<i_buf; i++) p_frame->p_buffer[i] = ((uint8_t *)p_emubuf)[i]; /* Set PCR */ es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_time ); /* We should use p_frame->i_buffer */ p_sys->i_time += (int64_t)1000000 * p_frame->i_buffer / i_bk / p_sys->fmt.audio.i_rate; /* Send data */ p_frame->i_dts = p_frame->i_pts = p_sys->i_time; es_out_Send( p_demux->out, p_sys->es, p_frame ); return 1;}/***************************************************************************** * Control: *****************************************************************************/static int Control( demux_t *p_demux, int i_query, va_list args ){ demux_sys_t *p_sys = p_demux->p_sys; double f, *pf; int64_t i64, *pi64; int i_idx; vlc_meta_t **pp_meta;switch( i_query ) { case DEMUX_GET_META: pp_meta = (vlc_meta_t **)va_arg( args, vlc_meta_t** ); if( p_sys->p_meta ) *pp_meta = vlc_meta_Duplicate( p_sys->p_meta ); else *pp_meta = NULL; return VLC_SUCCESS; case DEMUX_GET_POSITION: pf = (double*) va_arg( args, double* ); if( p_sys->i_length > 0 ) { *pf = (double)p_sys->i_time / (double)p_sys->i_length; return VLC_SUCCESS; } return VLC_EGENERIC;/* case DEMUX_SET_POSITION: f = (double) va_arg( args, double ); i64 = f * p_sys->i_length; if( i64 >= 0 && i64 <= p_sys->i_length ) { ModPlug_Seek( p_sys->f, i64 / 1000 ); p_sys->i_time = i64 + 1; es_out_Control( p_demux->out, ES_OUT_RESET_PCR ); return VLC_SUCCESS; } return VLC_EGENERIC;*/ case DEMUX_GET_TIME: pi64 = (int64_t*)va_arg( args, int64_t * ); *pi64 = p_sys->i_time; return VLC_SUCCESS; case DEMUX_GET_LENGTH: pi64 = (int64_t*)va_arg( args, int64_t * ); *pi64 = p_sys->i_length; return VLC_SUCCESS;/* case DEMUX_SET_TIME: i64 = (int64_t)va_arg( args, int64_t ); if( i64 >= 0 && i64 <= p_sys->i_length ) { ModPlug_Seek( p_sys->f, i64 / 1000 ); p_sys->i_time = i64 + 1; es_out_Control( p_demux->out, ES_OUT_RESET_PCR ); return VLC_SUCCESS; } return VLC_EGENERIC;*/ case DEMUX_GET_TITLE_INFO: if( p_sys->i_tracks > 1 ) { input_title_t ***ppp_title = (input_title_t***)va_arg( args, input_title_t*** ); int *pi_int = (int*)va_arg( args, int* ); *pi_int = p_sys->i_tracks; *ppp_title = (input_title_t**)malloc( sizeof( input_title_t**) * p_sys->i_tracks ); for( int i = 0; i < p_sys->i_tracks; i++ ) { char psz_temp[16]; snprintf(psz_temp, 15, "Track %i", i); (*ppp_title)[i] = vlc_input_title_New(); (*ppp_title)[i]->psz_name = strdup(psz_temp); } return VLC_SUCCESS; } return VLC_EGENERIC; case DEMUX_SET_TITLE: i_idx = (int)va_arg( args, int ); p_sys->p_musicemu->start_track( i_idx ); p_demux->info.i_title = i_idx; p_demux->info.i_update = INPUT_UPDATE_TITLE; msg_Dbg( p_demux, "set title %i", i_idx); return VLC_SUCCESS; case DEMUX_GET_FPS: /* meaningless */ default: return VLC_EGENERIC; }}#ifdef HAVE_ZLIB_Hstatic void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuffer, size_t * pi_osize){ z_stream z_str; int err; size_t offset, out_size; uint8_t * out_buffer; (*pp_obuffer) = NULL; (*pi_osize) = 0; memset(&z_str, 0, sizeof(z_str)); out_size = i_size * 2; out_buffer = (uint8_t*)malloc(out_size); z_str.next_in = (unsigned char*)p_buffer; z_str.avail_in = i_size; z_str.next_out = out_buffer; z_str.avail_out = out_size; if ((err = inflateInit2(&z_str, 31)) != Z_OK) /* gzip format */ { free(out_buffer); return; } while ((err = inflate(&z_str, Z_FINISH)) != Z_STREAM_END) { switch(err) { case Z_OK: break; case Z_BUF_ERROR: offset = z_str.next_out - out_buffer; out_size *= 2; out_buffer = (uint8_t *)realloc(out_buffer, out_size); z_str.next_out = out_buffer + offset; z_str.avail_out = out_size - offset; break; default: inflateEnd(&z_str); free(out_buffer); return; } } (*pi_osize) = out_size - z_str.avail_out; inflateEnd(&z_str); out_buffer = (uint8_t *)realloc(out_buffer, *pi_osize); (*pp_obuffer) = out_buffer;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -