Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Problem adding a IBasicVideoEffect #4

Open
ratishphilip opened this issue Oct 22, 2016 · 4 comments
Open

Problem adding a IBasicVideoEffect #4

ratishphilip opened this issue Oct 22, 2016 · 4 comments

Comments

@ratishphilip
Copy link

ratishphilip commented Oct 22, 2016

Hi,
First of all, nice project.

I added a Windows Runtime Component (UWP) project to this solution and within this I added a class GrayscaleVideoEffect.cs which has the following code

public sealed class GrayscaleVideoEffect : IBasicVideoEffect
{
    CanvasDevice canvasDevice;

    public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
    {
        if (device != null)
        {
            canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device);
        }
        else
        {
            canvasDevice = CanvasDevice.GetSharedDevice(false);
        }
    }

    public void ProcessFrame(ProcessVideoFrameContext context)
    {
        var inputSurface = context.InputFrame.Direct3DSurface;
        var outputSurface = context.OutputFrame.Direct3DSurface;

        if ((inputSurface == null) || (outputSurface == null))
            return;

        using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, inputSurface))
        using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, outputSurface))
        using (var ds = renderTarget.CreateDrawingSession())
        {
            var grayscale = new GrayscaleEffect() { Source = inputBitmap };
            ds.DrawImage(grayscale);
        }
    }

    public void SetProperties(IPropertySet configuration)
    {

    }

    public void Close(MediaEffectClosedReason reason)
    {
        canvasDevice?.Dispose();
    }

    public void DiscardQueuedFrames()
    {

    }

    public bool IsReadOnly => false;

    public IReadOnlyList<VideoEncodingProperties> SupportedEncodingProperties => new List<VideoEncodingProperties>();

    public MediaMemoryTypes SupportedMemoryTypes => MediaMemoryTypes.Gpu;

    public bool TimeIndependent => true;
}

After adding a reference to this project in the AdventureWorks project, I added the following line in the Camera.cs file just before await _mediaCapture.StartPreviewAsync();

await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(GrayscaleVideoEffect).FullName), MediaStreamType.VideoPreview);

Upon running the app, I get the following exception
videoeffecterror

How do I fix this error?

@nmetulev
Copy link
Member

Hey @ratishphilip , take a look at this sample project that has a similar effect that you are going for.

@ratishphilip
Copy link
Author

@nmetulev
When I run your example, I get a black screen. But when I comment the following line in the code

var effect = await _mediaCapture.AddVideoEffectAsync(
                new VideoEffectDefinition(typeof(TheEffect).FullName),
                                            MediaStreamType.VideoPreview);

then the preview is shown (without any effect). Uncommenting the above code results in a black screen.

I am wondering if it is an issue with my mobile.

I am using a Lumia 640 having the build 14951.

Also, I am currently on Build 14955, SDK 14393 and Visual Studio 2015 update 3.

@nmetulev
Copy link
Member

nmetulev commented Dec 7, 2016

Hey @ratishphilip, is this issue still happening on latest build?

@ratishphilip
Copy link
Author

@nmetulev Yes this is still happening in the latest build (14977).

According to this, the bug is yet to be fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants