private void DecodeSample()
        {
            MediaSample2D sample;

            lock (this)
            {
                sample = m_sample;
            }
            if (sample == null)
            {
                return;
            }

            Logger.Events.VideoBarcodeReader_DecodeSampleStart();

            int scale = (int)Math.Round(Math.Max(sample.Width / 640.0, sample.Height / 480.0));

            var e = new SampleDecodedEventArgs();

            using (sample)
                using (var scaledSample = m_processor.Convert(sample, MediaSample2DFormat.Bgra8, sample.Width / scale, sample.Height / scale))
                    using (var buffer = scaledSample.LockBuffer(BufferAccessMode.Read))
                    {
                        var plane  = buffer.Planes[0];
                        var result = m_barcodeReader.Decode(
                            plane.Buffer.ToArray(),
                            buffer.Width,
                            buffer.Height,
                            BitmapFormat.BGR32
                            );

                        if (result != null)
                        {
                            e.Text = result.Text;
                            for (int n = 0; n < result.ResultPoints.Length; n++)
                            {
                                e.Points.Add(new Point(result.ResultPoints[n].X / scaledSample.Width, result.ResultPoints[n].Y / scaledSample.Height));
                            }
                        }
                    }

            Logger.Events.VideoBarcodeReader_DecodeSampleStop(e.Text);

            lock (this)
            {
                m_sample = null;
            }

            if (SampleDecoded != null)
            {
                SampleDecoded(this, e);
            }
        }
        void barcodeReader_SampleDecoded(VideoBarcodeReader sender, SampleDecodedEventArgs e)
        {
            var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (e.Text == null)
                {
                    BarcodeOutline.Points.Clear();
                    TextLog.Text = "No barcode";
                }
                else
                {
                    TextLog.Text = e.Text;

                    BarcodeOutline.Points.Clear();
                    foreach (var point in e.Points)
                    {
                        BarcodeOutline.Points.Add(new Point(point.X * BarcodeOutline.Width, point.Y * BarcodeOutline.Height));
                    }
                }
            });
        }