Exemplo n.º 1
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");
        }