file seek support, new test cases, AVI use file seek
This commit is contained in:
@@ -32,6 +32,16 @@ public:
|
||||
std::string getName() const {return h.getName();}
|
||||
|
||||
|
||||
/** current position within the file */
|
||||
uint32_t curPos() const {
|
||||
return curAbsPos;
|
||||
}
|
||||
|
||||
/** seek to a new position within the file */
|
||||
void seekTo(uint32_t pos) {
|
||||
_seekTo(pos);
|
||||
}
|
||||
|
||||
/** read x bytes from the file */
|
||||
uint32_t read(uint32_t size, uint8_t* dst) {
|
||||
|
||||
@@ -105,6 +115,12 @@ private:
|
||||
|
||||
}
|
||||
|
||||
void _seekTo(uint32_t pos) {
|
||||
this->curAbsPos = pos;
|
||||
this->iCurCluster = pos / fs.tmp.bytesPerCluster;
|
||||
this->posInCluster = pos - (this->iCurCluster * fs.tmp.bytesPerCluster);
|
||||
}
|
||||
|
||||
int32_t _read(uint32_t readSize, uint8_t* dst) {
|
||||
|
||||
// EOF reached?
|
||||
|
||||
@@ -45,13 +45,13 @@
|
||||
//};
|
||||
|
||||
|
||||
class Simu {
|
||||
class SimuBlockDev {
|
||||
|
||||
uint8_t* data;
|
||||
|
||||
public:
|
||||
|
||||
Simu(const char* image) {
|
||||
SimuBlockDev(const char* image) {
|
||||
FILE* f = fopen(image, "rw");
|
||||
if (!f) {throw std::runtime_error("failed to open");}
|
||||
fseek(f, 0L, SEEK_END);
|
||||
@@ -76,26 +76,96 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class SimuFile {
|
||||
|
||||
FILE* f;
|
||||
|
||||
public:
|
||||
|
||||
SimuFile(const char* image) {
|
||||
f = fopen(image, "rw");
|
||||
if (!f) {throw std::runtime_error("failed to open");}
|
||||
}
|
||||
|
||||
uint32_t curPos() const {
|
||||
return ftell(f);
|
||||
}
|
||||
|
||||
void seekTo(uint32_t pos) {
|
||||
fseek(f, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
uint32_t read(uint32_t bytes, uint8_t* dst) {
|
||||
return fread(dst, bytes, 1, f) * bytes;
|
||||
}
|
||||
|
||||
uint32_t write(uint32_t bytes, const uint8_t* src) {
|
||||
return fwrite(src, bytes, 1, f) * bytes;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
//#define logInfo(fmt, ...) std::string s = fmt::format(FMT_STRING(fmt), __VA_ARGS__);
|
||||
|
||||
|
||||
#include "/apps/ESP8266lib/data/formats/avi/Demuxer.h"
|
||||
#define __LINUX__
|
||||
#include "/apps/ESP8266lib/data/formats/jpeg/JPEGDEC.h"
|
||||
#include "/apps/ESP8266lib/data/formats/jpeg/JPEGDEC.cpp"
|
||||
//#include "/apps/ESP8266lib/data/formats/jpeg/jpeg.c"
|
||||
|
||||
int drawJPEG(JPEGDRAW* pDraw) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
{
|
||||
if (1==0) {
|
||||
|
||||
// ffmpeg -i '/mnt/ssss/anime/Toaru Majutsu no Index/[Eclipse] Toaru Majutsu no Index - 07 (1280x720 h264) [0255D83A].mkv' -r 15 -ss 30 -vf scale=480x320 -c:v mjpeg -c:a mp3 -ar 44100 /tmp/ram/1.avi
|
||||
|
||||
Simu simu("/tmp/ram/1.avi");
|
||||
AccessHelper<Simu> ah(simu);
|
||||
AVI::Demuxer demux(ah);
|
||||
SimuFile simu("/tmp/ram/1.avi");
|
||||
AVI::Demuxer demux(simu);
|
||||
|
||||
bool valid = demux.isValid();
|
||||
std::cout << "valid: " << valid << std::endl;
|
||||
|
||||
uint8_t buf[64*1024];
|
||||
|
||||
std::ofstream outV("/tmp/ram/1.mjpeg");
|
||||
std::ofstream outA("/tmp/ram/1.mp3");
|
||||
|
||||
JPEGDEC jpeg;
|
||||
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
|
||||
AVI::NextChunk nc = demux.getNextChunk();
|
||||
std::cout << (int)nc.type << " : " << nc.size << std::endl;
|
||||
|
||||
demux.read(nc, buf);
|
||||
|
||||
if (nc.type == AVI::NextChunkType::VIDEO) {
|
||||
outV.write((const char*)buf, nc.size);
|
||||
|
||||
int res = jpeg.openRAM(buf, nc.size, drawJPEG);
|
||||
std::cout << "jpeg: " << res << std::endl;
|
||||
if (res) {
|
||||
jpeg.setPixelType(RGB565_BIG_ENDIAN);
|
||||
jpeg.decode(0, 0, 0);//40, 100, JPEG_SCALE_QUARTER | JPEG_EXIF_THUMBNAIL);
|
||||
jpeg.close();
|
||||
}
|
||||
|
||||
} else if (nc.type == AVI::NextChunkType::AUDIO) {
|
||||
outA.write((const char*)buf, nc.size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -106,15 +176,15 @@ int main(int argc, char** argv) {
|
||||
//std::string s = fmt::format(FMT_STRING("{:s}"), "I am not a number");
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::GTEST_FLAG(filter) = "*TestCreate*";
|
||||
::testing::GTEST_FLAG(filter) = "*TestSeek*";
|
||||
return RUN_ALL_TESTS();
|
||||
|
||||
// diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb
|
||||
|
||||
Simu simu("/tmp/ram/1.dat");
|
||||
AccessHelper<Simu> ah(simu);
|
||||
SimuBlockDev simu("/tmp/ram/1.dat");
|
||||
AccessHelper<SimuBlockDev> ah(simu);
|
||||
|
||||
MBR<AccessHelper<Simu>> mbr(ah);
|
||||
MBR<AccessHelper<SimuBlockDev>> mbr(ah);
|
||||
|
||||
if (mbr.isPresent() && mbr.isValid()) {
|
||||
|
||||
@@ -122,7 +192,7 @@ int main(int argc, char** argv) {
|
||||
std::cout << (int) mbr.getPartition(i).getType() << " - " << mbr.getPartition(i).getFirstSector() << " - " << mbr.getPartition(i).getNumSectors() << std::endl;
|
||||
}
|
||||
|
||||
using FAT32FS = FAT32::FS<AccessHelper<Simu>>;
|
||||
using FAT32FS = FAT32::FS<AccessHelper<SimuBlockDev>>;
|
||||
|
||||
FAT32FS fat(ah, mbr.getPartition(0).getFirstSector() * 512);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ TEST(TestCreate, structure) {
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreat, writeRead) {
|
||||
TEST (TestCreate, writeRead) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
@@ -96,7 +96,7 @@ TEST (TestCreat, writeRead) {
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreat, init) {
|
||||
TEST (TestCreate, init) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
@@ -135,7 +135,7 @@ TEST (TestCreat, init) {
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreat, getOrCreateFile) {
|
||||
TEST (TestCreate, getOrCreateFile) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
|
||||
55
ext/sd/tests/TestSeek.cpp
Normal file
55
ext/sd/tests/TestSeek.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
#include "../AccessHelper.h"
|
||||
#include "../fat32/FS.h"
|
||||
|
||||
|
||||
TEST (TestSeek, seek1) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
using FS = FAT32::FS<BlockDev>;
|
||||
|
||||
size_t size = 32*1024*1024;
|
||||
TestDevice dev(size);
|
||||
BlockDev bDev(dev);
|
||||
|
||||
FS fs(bDev, 0);
|
||||
ASSERT_FALSE(fs.isValid()); // filesystem must not be considered valid, header contains only zeros
|
||||
fs.setup(size, true); // initialize the filesystem
|
||||
ASSERT_TRUE(fs.isValid()); // must be considered valid now
|
||||
|
||||
auto testData = [] (const uint32_t pos) {
|
||||
return (uint8_t) (pos * 21 + 13);
|
||||
};
|
||||
|
||||
// create a file
|
||||
FS::File f1 = fs.getOrCreateFile("test.txt");
|
||||
static constexpr uint32_t testSize = 16*1024;
|
||||
uint8_t d1[testSize];
|
||||
for (int i = 0; i < testSize; ++i) {
|
||||
d1[i] = testData(i);
|
||||
}
|
||||
ASSERT_EQ(testSize, f1.write(testSize, d1));
|
||||
|
||||
// re-open the file
|
||||
FS::File f2 = fs.getOrCreateFile("test.txt");
|
||||
|
||||
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
uint8_t tmp = 0;
|
||||
f2.read(1, &tmp);
|
||||
ASSERT_EQ(testData(i), tmp);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
uint32_t pos = rand() % testSize;
|
||||
f2.seekTo(pos);
|
||||
uint8_t tmp = 0;
|
||||
f2.read(1, &tmp);
|
||||
uint8_t expected = testData(pos);
|
||||
ASSERT_EQ(expected, tmp);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user