Permalink
Browse files

MP1-4928 : Another rework to avoid issue when PostProcessAddAudio is …

…checked a second time.
  • Loading branch information...
Sebastiii committed Oct 15, 2018
1 parent dcbedf3 commit dab1fe07c7903ec773a095cb56b33a3c76d0d5da
@@ -2469,6 +2469,18 @@ protected void DoGraphRebuild()
{
hr = _mediaCtrl.Run();
DsError.ThrowExceptionForHR(hr);

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(_graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
catch (Exception error)
{
@@ -1910,6 +1910,18 @@ public void DoGraphRebuild()
{
var hr = _mediaCtrl.Run();
DsError.ThrowExceptionForHR(hr);

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(_graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
catch (Exception error)
{
@@ -1957,6 +1969,18 @@ public override void AudioRendererRebuild()
}
GUIGraphicsContext.CurrentAudioRendererDone = true;
}

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(_graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
}
catch (Exception ex)
@@ -2356,6 +2380,18 @@ protected void UpdateFilters(string selection)
filterCodec.AudioCodec = null;
}
filterCodec.AudioCodec = DirectShowUtil.AddFilterToGraph(this._graphBuilder, MatchFilters(selection));

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(_graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
}

@@ -713,6 +713,18 @@ public override void AudioRendererRebuild()
_mediaCtrl.Run();
GUIGraphicsContext.CurrentAudioRendererDone = true;
}

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(_graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
}
catch (Exception ex)
@@ -32,19 +32,6 @@ public class LavEngine : IPostProcessingEngine
private bool hasPostProcessing = false;
protected int audiodelayInterval;

#region ISubEngine Members

public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
{
DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVAudio, out _baseFilterLavAudio);
if (_baseFilterLavAudio == null)
return false;

return true;
}

#endregion

#region IPostProcessing Members

public bool EnableDeinterlace { get; set; }
@@ -82,20 +69,49 @@ public int AudioDelayLav
{
get
{
int delay = 0;
bool enable;
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett == null) return delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
return delay;
try
{
int delay = 0;
bool enable;
if (_baseFilterLavAudio != null)
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett == null) return delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
}
return delay;
}
catch (Exception)
{
if (_baseFilterLavAudio != null)
{
DirectShowUtil.ReleaseComObject(_baseFilterLavAudio);
_baseFilterLavAudio = null;
}
}
return 0;
}
set
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett == null) return;
var hr = asett.SetAudioDelay(true, value);
DsError.ThrowExceptionForHR(hr);
try
{
if (_baseFilterLavAudio != null)
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett == null) return;
var hr = asett.SetAudioDelay(true, value);
DsError.ThrowExceptionForHR(hr);
}
}
catch (Exception e)
{
if (_baseFilterLavAudio != null)
{
DirectShowUtil.ReleaseComObject(_baseFilterLavAudio);
_baseFilterLavAudio = null;
}
}
}
}

@@ -109,15 +125,29 @@ public int AudioDelay

public void AudioDelayMinus()
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett != null)
try
{
if (_baseFilterLavAudio != null)
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett != null)
{
bool enable;
int delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
hr = asett.SetAudioDelay(true, delay - AudioDelayInterval);
DsError.ThrowExceptionForHR(hr);
}
}
}
catch (Exception)
{
bool enable;
int delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
hr = asett.SetAudioDelay(true, delay - AudioDelayInterval);
DsError.ThrowExceptionForHR(hr);
if (_baseFilterLavAudio != null)
{
DirectShowUtil.ReleaseComObject(_baseFilterLavAudio);
_baseFilterLavAudio = null;
}
}
}

@@ -133,15 +163,29 @@ public void FreePostProcess()

public void AudioDelayPlus()
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett != null)
try
{
if (_baseFilterLavAudio != null)
{
ILAVAudioSettings asett = _baseFilterLavAudio as ILAVAudioSettings;
if (asett != null)
{
bool enable;
int delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
hr = asett.SetAudioDelay(true, delay + AudioDelayInterval);
DsError.ThrowExceptionForHR(hr);
}
}
}
catch (Exception)
{
bool enable;
int delay;
var hr = asett.GetAudioDelay(out enable, out delay);
DsError.ThrowExceptionForHR(hr);
hr = asett.SetAudioDelay(true, delay + AudioDelayInterval);
DsError.ThrowExceptionForHR(hr);
if (_baseFilterLavAudio != null)
{
DirectShowUtil.ReleaseComObject(_baseFilterLavAudio);
_baseFilterLavAudio = null;
}
}
}

@@ -1020,15 +1020,17 @@ protected override void DoGraphRebuild()
UpdateFilters("Video");
break;*/
}

IPostProcessingEngine postengine;
if (iChangedMediaTypes != 1 && VideoChange)
{
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(graphBuilder))
postengine = PostProcessingEngine.GetInstance(true);
if (postengine != null && !postengine.LoadPostProcessing(graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
@@ -1095,6 +1097,18 @@ protected override void DoGraphRebuild()
}
Log.Info("VideoPlayer9: Reconfigure graph done");
}*/

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
postengine = PostProcessingEngine.GetInstance(true);
if (postengine != null && !postengine.LoadPostProcessing(graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
}

@@ -1259,6 +1273,18 @@ public override void AudioRendererRebuild()
mediaCtrl.Run();
GUIGraphicsContext.CurrentAudioRendererDone = true;
}

// When using LAV Audio
//Release and init Post Process Filter
if (PostProcessingEngine.engine != null)
{
PostProcessingEngine.GetInstance().FreePostProcess();
}
IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);
if (!postengine.LoadPostProcessing(graphBuilder))
{
PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
}
}
}
catch (Exception ex)

0 comments on commit dab1fe0

Please sign in to comment.