Ejemplo n.º 1
0
 public void flushWriterTest()
 {
     YuvVideoHandler yvh = new YuvVideoHandler();
     YuvVideoInfo info = new YuvVideoInfo(readPath);
     info.width = 352;
     info.height = 240;
     info.yuvFormat = YuvFormat.YUV420_IYUV;
     yvh.setReadContext(readPath, info); // write context cannot be set without a valid read context
     writePath = sampleVideosPath + "\\americanFootball_352x240_125_Copy.yuv";
     YuvVideoInfo writeinfo = new YuvVideoInfo();
     writeinfo.path = writePath;
     writeinfo.width = 352;
     writeinfo.height = 240;
     writeinfo.yuvFormat = YuvFormat.YUV420_IYUV;
     yvh.setWriteContext(writePath, writeinfo);
     int oldFrameByteSize = yvh.frameByteSize;
     yvh.flushWriter();
     Assert.AreEqual(oldFrameByteSize, yvh.frameByteSize);
     Assert.AreEqual(0, yvh.positionReader);
     System.Drawing.Bitmap testframe = yvh.getFrame();
     System.Drawing.Bitmap[] frames = new System.Drawing.Bitmap[1];
     frames[0] = testframe;
     yvh.writeFrames(4, frames);
     yvh.flushWriter();
     yvh.writeFrames(4, frames);
 }
Ejemplo n.º 2
0
 public void flushReaderTest()
 {
     readPath = sampleVideos[2];
     YuvVideoHandler yvh = new YuvVideoHandler();
     yvh.setImportContext(readPath);
     int oldFrameByteSize = yvh.frameByteSize;
     yvh.flushReader();
     Assert.AreEqual(oldFrameByteSize, yvh.frameByteSize);
     Assert.AreEqual(0, yvh.positionReader);
 }
Ejemplo n.º 3
0
        public void clampToByteTest()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            YuvVideoHandler handler = new YuvVideoHandler();
            handler.setVideo(TESTVIDEO_PATH, info);

            PrivateObject param0 = new PrivateObject(handler);
            YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0);

            int[] val = new int[]        { -1, 128, 0, 255, 256, 500, int.MaxValue,  int.MinValue };
            byte[] expected = new byte[] {  0, 128, 0, 255, 255, 255, 255,           0};

            for (int i = 0; i < expected.Length; i++)
            {
                byte actual;
                actual = target.clampToByte(val[i]);
                Assert.AreEqual(expected[i], actual);
            }
        }
Ejemplo n.º 4
0
        public void convertToRGB_Black_Test()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            YuvVideoHandler handler = new YuvVideoHandler();
            handler.setVideo(TESTVIDEO_PATH, info);

            PrivateObject param0 = new PrivateObject(handler);
            YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0);

            //Testing standard colors according to
            //http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104%28v=vs.85%29.aspx
            int y = 16;
            int u = 128;
            int v = 128;
            Color expected = Color.Black;

            Color actual;
            actual = target.convertToRGB(y, u, v);

            Assert.AreEqual(expected.A, actual.A, "A not equal");
            Assert.AreEqual(expected.R, actual.R, "R not equal");
            Assert.AreEqual(expected.G, actual.G, "G not equal");
            Assert.AreEqual(expected.B, actual.B, "B not equal");
        }
Ejemplo n.º 5
0
 public void OnPropertyChangedTest_fpsIndProName()
 {
     Player_Accessor target = new Player_Accessor();
     string expected = "fpsIndicatorValue";
     object sender = new YuvVideoHandler();
     PropertyChangedEventArgs e = new PropertyChangedEventArgs(target.fpsIndProName);
     target.OnPropertyChanged(sender, e);
     Assert.AreEqual(expected, e.PropertyName, "Property name is wrong. ");
 }
Ejemplo n.º 6
0
        public void vidInfoTest()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            info.height = 666;

            YuvVideoHandler target =new YuvVideoHandler();
            target.setVideo(TESTVIDEO_PATH, info);
            IVideoInfo expected = info;
            IVideoInfo actual;
            actual = target.vidInfo;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void readANDwriteFrameTest()
        {
            //init handler to read sample file
            YuvVideoInfo info_r = new YuvVideoInfo();
            info_r.height = 144;
            info_r.width = 176;
            info_r.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler reader = new YuvVideoHandler();
            reader.setVideo(TESTVIDEO_PATH, info_r);

            //init handler to write a copy of sample file
            YuvVideoInfo info_w = new YuvVideoInfo();
            info_w.height = 144;
            info_w.width = 176;
            info_w.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler writer = new YuvVideoHandler();
            writer.setVideo(TESTVIDEO_PATH + "copy", info_w);

            //copy sample file frame by frame
            //REMARK: This part can be commented out to save time once the copy is written to disk
            //          if this test is run several times to tweak parameters and error calculations
            for (int j = 0; j < ((YuvVideoInfo)reader.vidInfo).frameCount; j++)
            {
                Bitmap bmp = reader.getFrame(j);

                writer.writeFrame(j, bmp);
            }

            //
            //compare original file with the copy read and written by the handler
            //
            //TODO: Debug writeFrame() & getFrame() as there are significant differences when a copy of a file is created through YuvVideoHandlers

            //set buffersize to one frame
            int bsize =(int)( info_r.width * info_r.height * (1 + YuvVideoHandler.getLum2Chrom(info_r.yuvFormat)) );

            int error = 0;
            int errorcount = 0;

            FileStream fs1;
            fs1 = new FileStream(TESTVIDEO_PATH, FileMode.Open);
            byte[] data1 = new byte[bsize];
            FileStream fs2;
            fs2 = new FileStream(TESTVIDEO_PATH+"copy", FileMode.Open);
            byte[] data2 = new byte[bsize];

            //log files are written to the log folder with error information about frames and the whole file
            //because an unfulfilled assertion cancels the whole testrun
            StreamWriter log = new StreamWriter("C:/Dokumente und Einstellungen/Sebastian/Eigene Dateien/PSE/Implementierung/YuvVideoHandler/log/log.txt");

            //compare original and copy bytewise
            for (int i = 0; i < fs1.Length; i += bsize)
            {
                int r = fs1.Read(data1, 0, bsize);
                int r2 = fs2.Read(data2, 0, bsize);

                Assert.AreEqual(r, r2, "file read out of sync");

                //init log writer for this frame
                //the logfile of each frame contains the difference in value of original and copy for each byte
                //the diffs are written in the textfile as a matrix according to pixel position
                StreamWriter logdetail = new StreamWriter("C:/Dokumente und Einstellungen/Sebastian/Eigene Dateien/PSE/Implementierung/YuvVideoHandler/log/log"+(i/bsize)+".txt");

                for (int j = 0; j < r; j++)
                {
                    int diff = Math.Abs(data1[j] - data2[j]);

                    int y = j / info_r.width;
                    int x = j % info_r.width;

                    if (j % info_r.width == 0) logdetail.Write(logdetail.NewLine);

                    //Assert.IsTrue(diff < 5, "big difference at "+x+","+y+": "+diff);
                    logdetail.Write(diff+" ");
                    error += diff;
                    if (diff > 5) errorcount++;

                }

                logdetail.Close();

                //the global logfile is written with the accumulated information about this frame
                float errorratio = (((float)errorcount) / bsize);
                log.WriteLine("Frame: "+(i/bsize)+" / errorratio: "+errorratio);
                //Assert.IsTrue(error < 10, i+": error ratio: " + errorratio + " / error count: " + errorcount + " / accumulated error: " + error);

                error = 0;
                errorcount = 0;
            }

            log.Close();

            fs1.Close();
            fs2.Close();

            Assert.Inconclusive("Compare logfiles to determine errorrates");
        }
Ejemplo n.º 8
0
        public void getFrameTest()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            info.height = 144;
            info.width = 176;
            info.yuvFormat = YuvFormat.YUV420_IYUV;
            YuvVideoHandler target = new YuvVideoHandler();
            target.setVideo(TESTVIDEO_PATH, info);

            Bitmap expected = null;
            Bitmap actual;

            TestContext.BeginTimer("frame1");
            actual = target.getFrame(0);
            TestContext.EndTimer("frame1");

            TestContext.BeginTimer("frame2");
            actual = target.getFrame(1);
            TestContext.EndTimer("frame2");

            //TODO: How to compare this?!

            Assert.Inconclusive("Implement some way to check result first.");
        }
Ejemplo n.º 9
0
        public void convertToYUV_White_Test()
        {
            YuvVideoInfo info = new YuvVideoInfo();
            YuvVideoHandler handler = new YuvVideoHandler();
            handler.setVideo(TESTVIDEO_PATH, info);

            PrivateObject param0 = new PrivateObject(handler);
            YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0);

            //Testing standard colors according to
            //http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104%28v=vs.85%29.aspx
            int y = 235;
            int u = 128;
            int v = 128;

            byte[] actual;
            actual = target.convertToYUV(Color.White);

            Assert.AreEqual(y, actual[0], "Y not equal");
            Assert.AreEqual(u, actual[1], "U not equal");
            Assert.AreEqual(v, actual[2], "V not equal");
        }
Ejemplo n.º 10
0
        public void writeContextTest()
        {
            YuvVideoHandler yvh = new YuvVideoHandler();
            YuvVideoInfo info = new YuvVideoInfo(readPath);
            info.width = 352;
            info.height = 240;
            info.yuvFormat = YuvFormat.YUV420_IYUV;

            yvh.setWriteContext(readPath, info);

            yvh.setReadContext(readPath, info);
            yvh.setWriteContext(readPath, info);
            Assert.AreEqual(info, yvh.writeVidInfo);
            Assert.IsTrue(yvh.consistent);
            string falsePath = "\\bla_cif.yuv";
            YuvVideoInfo falseInfo = new YuvVideoInfo();
            falseInfo.path = falsePath;
            try
            {
                yvh.setWriteContext(falsePath, falseInfo);
                Assert.Fail("no exception thrown");
            }
            catch (Exception )
            {

            }
            try
            {
                yvh.setWriteContext(falsePath, info);
                Assert.Fail("no exception thrown");
            }
            catch (Exception )
            {

            }
            try
            {
                yvh.setWriteContext(readPath, falseInfo);
                Assert.Fail("no exception thrown");
            }
            catch (Exception)
            {

            }
        }
Ejemplo n.º 11
0
        public void readContextTest()
        {
            YuvVideoHandler yvh = new YuvVideoHandler();
            Assert.AreEqual("yuvVideoHandler", yvh.namePlugin);
            Assert.AreEqual(PluginType.IVideoHandler, yvh.type);
            YuvVideoInfo info = new YuvVideoInfo(readPath);
            info.width = 352;
            info.height = 240;
            info.yuvFormat = YuvFormat.YUV420_IYUV;
            yvh.setReadContext(readPath, info);
            Assert.AreEqual(info, yvh.readVidInfo);
            Assert.IsNotNull(yvh.frameByteSize);
            //Assert.IsTrue(yvh.consistent);
            string falsePath = "\\bla_cif.yuv";
            YuvVideoInfo falseInfo = new YuvVideoInfo();
            falseInfo.path = falsePath;
            try
            {
                yvh.setReadContext(falsePath, falseInfo);
                Assert.Fail("no exception thrown");
            }
            catch (Exception)
            {

            }
            try
            {
                yvh.setReadContext(falsePath, info);
                Assert.Fail("no exception thrown");
            }
            catch (Exception)
            {

            }
            try
            {
                yvh.setReadContext(readPath, falseInfo);
                Assert.Fail("no exception thrown");
            }
            catch (Exception)
            {

            }
        }
Ejemplo n.º 12
0
 public void mementoTest()
 {
     YuvVideoHandler yvh = new YuvVideoHandler();
     Memento mem = yvh.getMemento();
     yvh.setMemento(mem); // nothing is supposed to happen after calling this
     Assert.IsNull(mem.state);
     Assert.AreEqual("MementoStub", mem.name);
 }
Ejemplo n.º 13
0
        public void importContextTest()
        {
            YuvVideoHandler yvh = new YuvVideoHandler();
            readPath = sampleVideos[2];
            YuvVideoInfo info = new YuvVideoInfo(readPath);
            yvh.setImportContext(readPath);
            Assert.AreEqual(info, yvh.readVidInfo);
            Assert.IsNotNull(yvh.frameByteSize);
            Assert.IsTrue(yvh.consistent);
            string falsePath = "\\bla_cif.yuv";
            try
            {
                yvh.setImportContext(falsePath);
                Assert.Fail("no exception thrown");
            }
            catch (Exception )
            {

            }
        }
Ejemplo n.º 14
0
        public void getVideoHandlerTest()
        {
            Thread.Sleep(30000); // pluginmanager needs time for consistency check
            YuvVideoInfo info = new YuvVideoInfo(sampleVideos[2]);
            Video target = new Video(false, sampleVideos[2], info, null);
            IVideoHandler expected = new YuvVideoHandler();
            expected.setReadContext(sampleVideos[2], info);
            IVideoHandler actual = target.handler;
            Assert.AreEqual(expected.readPath, actual.readPath);
            Assert.AreEqual(expected.readVidInfo, actual.readVidInfo);
            IVideoHandler extra = target.getExtraHandler();
            Assert.AreEqual(extra.readPath, actual.readPath);
            Assert.AreEqual(extra.readVidInfo, actual.readVidInfo);
            Video target2 = new Video(false, sampleVideos[2], null, null);
            IVideoHandler actual2 = target2.handler;
            string falsePath
                = "D:\\Documents and Settings\\fenix1\\OQAT\\Implementierung\\OQAT_Tests\\TestData\\sampleVideos\\about.txt";
            Video fakeVideo = new Video(false, falsePath, null, null);
            try
            {
                IVideoHandler noHandler = fakeVideo.handler;
                Assert.Fail("no exception thrown");
            }
            catch (Exception)
            {

            }
        }