Some small changes to the test program to get sound working and fast display using opengl . I watch TV from my dstv decoder on my PC at home now while working..

Jun 4, 2015 at 4:06 PM
I have made some small changes to the original test program and have the sound working as well as using opengl to show video.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio;
using NAudio.Wave;
using Tao.OpenGl;

namespace HdmiExtenderLib
{
    public partial class MainForm : Form
    {
        System.Windows.Forms.Timer timer;
        HdmiExtenderReceiver receiver;
        float zoomx, zoomy = 1.0F;
        int ix = 1280;
        int iy = 540;

        byte[] previousImage;
        byte[] currentImage;
        int fpsCalc = 0;
        DateTime nextFpsSecond = DateTime.Now;
        public static ConcurrentQueue<byte[]> qaud = new ConcurrentQueue<byte[]>();
        public BufferedWaveProvider bwp;
        public IWavePlayer iwp;
        public WaveOut waveOut;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
           ogl.InitializeContexts();
           Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
           Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
        }
        public static byte[] ImageToByte(Image img)
        {
            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }

        public static byte[] ImageToByte2(Image img)
        {

            byte[] byteArray = new byte[0];
            using (MemoryStream stream = new MemoryStream())
            {
                img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                byteArray = stream.ToArray();

            }
            return byteArray;
        }
        void timer_Tick(object sender, EventArgs e)
        {
            byte[] adata;
            currentImage = receiver.LatestImage;
            if(currentImage != previousImage)
            {
                fpsCalc++;
                previousImage = currentImage;
                MemoryStream ms = new MemoryStream(currentImage);
                Image img = Bitmap.FromStream(ms);
                Gl.glRasterPos2i(0, 0);
                Gl.glDrawPixels(img.Width, img.Height, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, ImageToByte2(img));
                ogl.Refresh();
                
               lblVideoData.Text = img.Width + "x" + img.Height;
            }
            if (nextFpsSecond < DateTime.Now)
            {
                lblFrameRate.Text = fpsCalc.ToString();
                fpsCalc = 0;
                nextFpsSecond = DateTime.Now.AddSeconds(1);
                oglheight.Text = zoomx.ToString(); 
                oglwidth.Text = zoomy.ToString();
                qcnt.Text = qaud.Count().ToString();
                if (qaud.Count() > 20) // attempt to keep audio in sync after a resize.
                {
                    while(qaud.Count>0)
                    {
                        qaud.TryDequeue(out adata);
                    }
                }
            }
            while (qaud.Count > 0)
            {

                qaud.TryDequeue(out adata);
                for (int i = 0; i < adata.Length; i += 4)
                {
                    Array.Reverse(adata, i, 4);
                }
                bwp.AddSamples(adata, 0, adata.Length);                               
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            receiver.Stop();
        }

        private void Startbutton_Click(object sender, EventArgs e)
        {
            waveOut = new WaveOut();
            var waveFormat = new WaveFormat(48000, 32,2); // Same format.
            bwp = new BufferedWaveProvider(waveFormat);
            waveOut.Init(bwp);
            waveOut.Volume = 1.0F;
            waveOut.Play();
            timer = new System.Windows.Forms.Timer();
            timer.Interval = 1;
            timer.Tick += timer_Tick;
            timer.Start();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            receiver = new HdmiExtenderReceiver("192.168.168.55", Convert.ToInt16(interfaceeno.Value));
            receiver.RegisterAudioListener(qaud);
            receiver.Start();
        }

        private void oglheight_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            zoomx += 0.2f;
            zoomy += 0.2F;
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            Gl.glPixelZoom(zoomx, zoomy);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            zoomx -= 0.2f;
            zoomy -= 0.2F;
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            Gl.glPixelZoom(zoomx, zoomy);
        }

        private void ogl_Resize(object sender, EventArgs e)
        {
            zoomx = ogl.Width / (float)ix;
            zoomy = ogl.Height / (float)iy;
            Gl.glPixelZoom(zoomx, zoomy);
        }
    }
}