From 622425a6c8db4d668925b3d7d3240f23034d963e Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sun, 20 May 2018 00:48:57 +0300 Subject: VLC Plugin: Added supports for VLC 3+! --- utils/vlc_codec/libadlmidi.c | 161 ++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 108 deletions(-) (limited to 'utils/vlc_codec') diff --git a/utils/vlc_codec/libadlmidi.c b/utils/vlc_codec/libadlmidi.c index 5f85a4d..eb20227 100644 --- a/utils/vlc_codec/libadlmidi.c +++ b/utils/vlc_codec/libadlmidi.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -67,7 +68,11 @@ static void Close (vlc_object_t *); vlc_module_begin () set_description (N_("ADLMIDI OPL3 Synth MIDI synthesizer")) +#if (LIBVLC_VERSION_MAJOR >= 3) + set_capability ("audio decoder", 150) +#else set_capability ("decoder", 150) +#endif set_shortname (N_("ADLMIDI")) set_category (CAT_INPUT) set_subcategory (SUBCAT_INPUT_ACODEC) @@ -105,7 +110,11 @@ static const struct ADLMIDI_AudioFormat g_output_format = }; //static int DecodeBlock (decoder_t *p_dec, block_t *p_block); //For different version +#if (LIBVLC_VERSION_MAJOR >= 3) +static int DecodeBlock (decoder_t *p_dec, block_t *p_block); +#else static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block); +#endif static void Flush (decoder_t *); static int Open (vlc_object_t *p_this) @@ -149,10 +158,12 @@ static int Open (vlc_object_t *p_this) date_Set (&p_sys->end_date, 0); p_dec->p_sys = p_sys; - //==For different version== - //p_dec->pf_decode = DecodeBlock; - //p_dec->pf_flush = Flush; +#if (LIBVLC_VERSION_MAJOR >= 3) + p_dec->pf_decode = DecodeBlock; + p_dec->pf_flush = Flush; +#else p_dec->pf_decode_audio = DecodeBlock; +#endif return VLC_SUCCESS;//VLCDEC_SUCCESS } @@ -174,128 +185,53 @@ static void Flush (decoder_t *p_dec) } +#if (LIBVLC_VERSION_MAJOR >= 3) +static int DecodeBlock (decoder_t *p_dec, block_t *p_block) +{ + decoder_sys_t *p_sys = p_dec->p_sys; + block_t *p_out = NULL; +#else static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block) { block_t *p_block; decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_out = NULL; - if (pp_block == NULL) return NULL; p_block = *pp_block; - if (p_block == NULL) - return NULL; - *pp_block = NULL; - - if (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) - { - date_Set (&p_sys->end_date, 0); - adl_panic(p_sys->synth); - } - - if (p_block->i_pts > VLC_TS_INVALID && !date_Get (&p_sys->end_date)) - date_Set (&p_sys->end_date, p_block->i_pts); - else - if (p_block->i_pts < date_Get (&p_sys->end_date)) - { - msg_Warn (p_dec, "MIDI message in the past?"); - goto drop; - } - - if (p_block->i_buffer < 1) - goto drop; - - uint8_t event = p_block->p_buffer[0]; - uint8_t channel = p_block->p_buffer[0] & 0xf; - event &= 0xF0; - - if (event == 0xF0) - switch (channel) - { - case 0: - if (p_block->p_buffer[p_block->i_buffer - 1] != 0xF7) - { - case 7: - msg_Warn (p_dec, "fragmented SysEx not implemented"); - goto drop; - } - //fluid_synth_sysex (p_sys->synth, (char *)p_block->p_buffer + 1, - // p_block->i_buffer - 2, NULL, NULL, NULL, 0); - break; - case 0xF: - adl_rt_resetState(p_sys->synth); - break; - } - - uint8_t p1 = (p_block->i_buffer > 1) ? (p_block->p_buffer[1] & 0x7f) : 0; - uint8_t p2 = (p_block->i_buffer > 2) ? (p_block->p_buffer[2] & 0x7f) : 0; +#endif - switch (event & 0xF0) + if (p_block == NULL) { - case 0x80: - adl_rt_noteOff(p_sys->synth, channel, p1); - break; - case 0x90: - adl_rt_noteOn(p_sys->synth, channel, p1, p2); - break; - /*case 0xA0: note aftertouch not implemented */ - case 0xB0: - adl_rt_controllerChange(p_sys->synth, channel, p1, p2); - break; - case 0xC0: - adl_rt_patchChange(p_sys->synth, channel, p1); - break; - case 0xD0: - adl_rt_channelAfterTouch(p_sys->synth, channel, p1); - break; - case 0xE0: - adl_rt_pitchBendML(p_sys->synth, channel, p2, p1); - break; +#if (LIBVLC_VERSION_MAJOR >= 3) + return VLCDEC_SUCCESS; +#else + return p_out; +#endif } - unsigned samples = - (p_block->i_pts - date_Get (&p_sys->end_date)) * 441 / 10000; - if (samples == 0) - goto drop; - - p_out = decoder_NewAudioBuffer (p_dec, samples); - if (p_out == NULL) - goto drop; - - p_out->i_pts = date_Get (&p_sys->end_date ); - samples = adl_generateFormat(p_sys->synth, (int)samples * 2, - (ADL_UInt8*)p_out->p_buffer, - (ADL_UInt8*)(p_out->p_buffer + g_output_format.containerSize), - &g_output_format); - samples /= 2; - p_out->i_length = date_Increment (&p_sys->end_date, samples) - p_out->i_pts; - -drop: - block_Release (p_block); - return p_out; -} - -#if 0 -static int DecodeBlock (decoder_t *p_dec, block_t *p_block) -{ - decoder_sys_t *p_sys = p_dec->p_sys; - block_t *p_out = NULL; - - if (p_block == NULL) /* No Drain */ - return VLC_SUCCESS;//VLCDEC_SUCCESS +#if (LIBVLC_VERSION_MAJOR < 3) + *pp_block = NULL; +#endif if (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) { +#if (LIBVLC_VERSION_MAJOR >= 3) Flush (p_dec); if (p_block->i_flags & BLOCK_FLAG_CORRUPTED) { block_Release(p_block); - return VLC_SUCCESS;//VLCDEC_SUCCESS + return VLCDEC_SUCCESS; } +#else + date_Set (&p_sys->end_date, 0); + adl_panic(p_sys->synth); +#endif } - if (p_block->i_pts > VLC_TS_INVALID && !date_Get (&p_sys->end_date)) + if (p_block->i_pts > VLC_TS_INVALID + && !date_Get (&p_sys->end_date)) date_Set (&p_sys->end_date, p_block->i_pts); else if (p_block->i_pts < date_Get (&p_sys->end_date)) @@ -360,21 +296,30 @@ static int DecodeBlock (decoder_t *p_dec, block_t *p_block) if (samples == 0) goto drop; +#if (LIBVLC_VERSION_MAJOR >= 3) if (decoder_UpdateAudioFormat (p_dec)) goto drop; +#endif + p_out = decoder_NewAudioBuffer (p_dec, samples); if (p_out == NULL) goto drop; p_out->i_pts = date_Get (&p_sys->end_date ); - p_out->i_length = date_Increment (&p_sys->end_date, samples) - - p_out->i_pts; - adl_generate(p_sys->synth, samples * 2, p_out->p_buffer); + samples = adl_generateFormat(p_sys->synth, (int)samples * 2, + (ADL_UInt8*)p_out->p_buffer, + (ADL_UInt8*)(p_out->p_buffer + g_output_format.containerSize), + &g_output_format); + samples /= 2; + p_out->i_length = date_Increment (&p_sys->end_date, samples) - p_out->i_pts; + drop: block_Release (p_block); +#if (LIBVLC_VERSION_MAJOR >= 3) if (p_out != NULL) decoder_QueueAudio (p_dec, p_out); - return VLC_SUCCESS;//VLCDEC_SUCCESS -} - + return VLCDEC_SUCCESS; +#else + return p_out; #endif +} -- cgit v1.2.3