[Solved] Using combination of Bass_Dshow, BassFx, BassMix and SyncProc in VB.NET

Started by GuzzP770,

GuzzP770

I will update the working Codes later :) stay tuned.

Here is my questions before it solved ::

Hi everyones, this is my first post, sorry if my english is bad,

anyway I'm creating my own media player in VB.NET (VS2010 - Win7) using BASS, BASS_DSHOW, BASS MIX and BASS FX, I often search for the right way to code by searching this forum, but it seems that I can't get it "right" until now..

Current Condition :
~ I have 2 screens, and I want to show the video on the 2nd screen
~ I need to implement Pitch control, Volume, Balance and Playlist
~ my Form concept is :
   Home > Player_ButtonClick() > Show my custom UserControl inside Home form + Create a maximized blank form on 2nd screen + Init BASS

Current Problems :
~ 1 of 10 mpg video files having this weird behavior : the video doesn't show, but I can heard the audio playing, Some video only visible after playing another video files (after I press Next button which only consist of ChannelStop and StreamFree).
   Note : I can see the video if I drag the VideoForm from 2nd screen to 1st screen (where the Home Form is), but when I drag it back to 2nd screen, It become black screen but the audio still playing.
~ I have this Flickering when playing flv files (but the weird thing is It doesn't flicker when I tested it on a simple single form)
~ I have a feeling that my FreeSource method doesn't free all BASS resources including plugins (it get weird when we close the Player and reopen it again, video wont show)
~ I'm still searching the right way to use SYNCPROC in my code for Playlist

so here's my codes inside my PlayerControl (not in HomeForm) ::

OnLoad Event, Before I call InitBASS() I create a new Form for Video display and put it to 2nd screen, then I add PBox (Picture Box) inside this Video Form.
Private Sub InitBASS()
        Bass.BASS_PluginLoad("bass_dshow.dll")
        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
        BassDShow.BASS_DSHOW_Init(PBox.Handle, BASSDSHOWInit.BASS_DSHOW_Default)

        If SrcChannel <> 0 Then Bass.BASS_StreamFree(SrcChannel)

End Sub

Freesource is triggered when Player's Form Closing event
Private Sub FreeSource()
        Bass.BASS_Stop()
        BassDShow.BASS_DSHOW_Free()
        Bass.BASS_Free()
End Sub

This is my Playsub, triggered when user press the Play Button
Private Sub PlaySub(ByVal song As Song)

        Bass.BASS_GetInfo(di) ' get device info for speaker count

        SrcChannel = BassDShow.BASS_DSHOW_StreamCreateFile(song.Path, 0, IntPtr.Zero, BASSFlag.BASS_STREAM_DECODE)
        If SrcChannel = 0 Then MsgBox("Fail to create Source = " & Bass.BASS_ErrorGetCode.ToString) : Return

        Bass.BASS_ChannelGetInfo(SrcChannel, ci) ' get source info for sample rate

        ' create mixer with source sample rate and device speaker count
        MixChannel = BassMix.BASS_Mixer_StreamCreate(ci.freq, min(di.speakers, 8), BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_AUTOFREE)
        If MixChannel = 0 Then MsgBox("Fail to create Mixer = " & Bass.BASS_ErrorGetCode.ToString) : Return

        ' Load the BassFX '
        SrcChannel = AddOn.Fx.BassFx.BASS_FX_TempoCreate(SrcChannel, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_FX_FREESOURCE)

        ' add the source to the mix with matrix-mixing enabled
        BassMix.BASS_Mixer_StreamAddChannel(MixChannel, SrcChannel, BASSFlag.BASS_MIXER_MATRIX)

        BassMix.BASS_Mixer_ChannelSetMatrix(SrcChannel, GetAutoMix_Matrix_v2(di.speakers, ci.chans, "Stereo")

        Bass.BASS_ChannelPlay(MixChannel, False)
        SongPicker_PitchChange(SongPicker.GetPitch)
        SongPicker_VolChange(SongPicker.GetVolume)

End Sub

Something must be wrong in the Flags that causing all the problems above, I hope someone can help me.

Update :
~ Everything played nicely if I display the video on 1st monitor, but when I drag it to the 2nd monitor, the whole channel stopped

GuzzP770

Up..

 :'( anyone ..?

or maybe a link to samples, or topic to the same question?

SoundMike

I don't use BASS_DSHOW but do have some experience with xVideo. What you may need to do regarding the second monitor is change the video renderer. By default, my app uses 'VMR9 Windowless', but for users who find the video doesn't play on the second screen then changing the renderer to 'VMR7 Windowed' usually solves the problem (although not always). In xVideo you set the renderer using a 'set config' option, so I guess that will be similar in BASS_DSHOW.

Something else I've found useful with video files that don't play is to convert them using the NCH Prism Video Converter. Even if you 'convert' them to the same format (eg mpg to mpg) then Prism seems to 'clean up' any non-standard formats. However, I've also found that mpg and mpeg files seem to give more problems than other common formats, such as avi and wmv.

GuzzP770

Hi Mike, thanks for responding my post ! :)

the only Flag that works in VideoRenderer for my second monitor is NULLAudio !

for now I got it working by Removing ALL MIX and FX, so I just simply do :
1. BASS_DSHOW_StreamCreateFile
2. Set NullAudio Config on Video Renderer
BassDShow.BASS_DSHOW_SetConfig(BASSDSHOWConfig.BASS_DSHOW_CONFIG_VideoRenderer, BASSDSHOWConfigFlag.BASS_DSHOW_NULLAudio)3. BASS_ChannelPlay

I will try to implement it with MIX and FX tomorrow .. my head got dizzy after hours testing, well thanks again Mike!

Ionut Cristea

  I recommand using xVideo .NET wrapper. Its more complete then the BASS.NET one.

GuzzP770

Quote from: Ionut CristeaI recommand using xVideo .NET wrapper. Its more complete then the BASS.NET one.

finally, thanks for showing up here Ionut.
well, where I can find this xVideo .NET wrapper ? Can I still using bassmix (for matrix mixing) and bassfx (for pitch & tempo control) when using this wrapper?

honestly it's a bit hard for me to find some .NET tutorial for BASS_Dshow or an up-to-date ones, so I decided that I will update this thread regularly for a standard usage in 'xVideo, Mix and Fx' when I successfully implements everything.

smoodilo

Quote from: GuzzP770
Quote from: Ionut CristeaI recommand using xVideo .NET wrapper. Its more complete then the BASS.NET one.

finally, thanks for showing up here Ionut.
well, where I can find this xVideo .NET wrapper ? Can I still using bassmix (for matrix mixing) and bassfx (for pitch & tempo control) when using this wrapper?

honestly it's a bit hard for me to find some .NET tutorial for BASS_Dshow or an up-to-date ones, so I decided that I will update this thread regularly for a standard usage in 'xVideo, Mix and Fx' when I successfully implements everything.

Then maybe you can help me out? How did you set the video window? I only get video on my main form. (Ionut is not willing to help. I requested here, mailed him personally, but he does not respond). So maybe you figured it out? Do you know the syntax for ChannelSetWindow?






SoundMike

For xVideo:

QuotexVideo_ChannelSetWindow

--------------------------------------------------------------------------------

Set video window handle.

void xVideo_ChannelSetWindow(HSTREAM chan,DWORD window,HWND handle) 

Parameters:

chan a valid HSTREAM 
window a valid video window handle that is returned by xVideo_ChannelAddWindow function or 0(zero) for main video window 
handle a valid window handle 

Return value:
Check xVideo_ErrorGetCode to get error code.

Usage:
Set main video window handle.

xVideo_ChannelSetWindow(chan,0,myHWND); // set main video window handle

In my app I always use 0 for the second parameter (window) and the relevant handle for the third parameter.

Don't know about BASS_DSHOW equivalent.

GuzzP770

Quote from: smoodiloThen maybe you can help me out? How did you set the video window? I only get video on my main form. (Ionut is not willing to help. I requested here, mailed him personally, but he does not respond). So maybe you figured it out? Do you know the syntax for ChannelSetWindow?

oh hi smoodilo,
well here is my code for now,
~ Do Bass init and dshow init with me.handle (which is my control on 1st monitor)
~ in my play sub, the PboxFrame is placed on 2nd Monitor
SrcChannel = BassDShow.BASS_DSHOW_StreamCreateFile(song.Path, 0, PboxFrame.Handle, BASSFlag.BASS_SAMPLE_FLOAT)~ in my case it works when i put this line before BASS_ChannelPlay
BassDShow.BASS_DSHOW_SetConfig(BASSDSHOWConfig.BASS_DSHOW_CONFIG_VideoRenderer, BASSDSHOWConfigFlag.BASS_DSHOW_NULLAudio)~ I didn't use ChannelSetWindow or ChannelAddWindow, it caused error...something like PinvokeStackImbalance  ???

btw, at first I thought you did found solution for that, but I can't track your post because you are not registered (guest account?), maybe create an account in this forum is not a bad idea :) just saying..

Can you show me how you clear resources when you close your form? (something like bass_stop or bass_free or UnloadMe .. which one is the right method to free all resources, including the loaded plugins)

GuzzP770

... F A I L ...

I tried to include BassMix and BassFX then the problem returns,
It played fine on 1st monitor, but It doesn't play on 2nd monitor, VideoRenderer Config doesn't work this time..