240 lines
5.7 KiB
C++
240 lines
5.7 KiB
C++
#include <stdexcept>
|
|
#include <iostream>
|
|
|
|
//#define debugMod(module, str) {printf("i[%-10s] ", module); printf(str); printf("\n");}
|
|
//#define debugMod1(module, str, v1) {printf("i[%-10s] ", module); printf(str, v1); printf("\n");}
|
|
//#define debugMod2(module, str, v1, v2) {printf("i[%-10s] ", module); printf(str, v1, v2); printf("\n");}
|
|
//#define debugMod3(module, str, v1, v2, v3) {printf("i[%-10s] ", module); printf(str, v1, v2, v3); printf("\n");}
|
|
//#define debugMod4(module, str, v1, v2, v3, v4) {printf("i[%-10s] ", module); printf(str, v1, v2, v3, v4); printf("\n");}
|
|
//#define debugMod5(module, str, v1, v2, v3, v4, v5) {printf("i[%-10s] ", module); printf(str, v1, v2, v3, v4, v5); printf("\n");}
|
|
|
|
#define PLATFORM DESKTOP
|
|
|
|
#include "../../Debug.h"
|
|
#include "MBR.h"
|
|
#include "fat32/FS.h"
|
|
#include "AccessHelper.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
//class Simu {
|
|
|
|
// FILE* f;
|
|
|
|
//public:
|
|
|
|
// Simu(const char* image) {
|
|
// f = fopen(image, "rw");
|
|
// if (!f) {throw std::runtime_error("failed to open");}
|
|
// }
|
|
|
|
// uint32_t readSingleBlock(LBA512 addr, uint8_t* dst) {
|
|
// Log::addInfo("SD", "read512(%d*512)", addr);
|
|
// fseek(f, addr*512, SEEK_SET);
|
|
// return fread(dst, 512, 1, f) * 512;
|
|
// }
|
|
|
|
// uint32_t writeSingleBlock(LBA512 addr, const uint8_t* src) {
|
|
// Log::addInfo("SD", "write512(%d*512)", addr);
|
|
// fseek(f, addr*512, SEEK_SET);
|
|
// return fwrite(src, 512, 1, f) * 512;
|
|
// }
|
|
|
|
//};
|
|
|
|
|
|
class SimuBlockDev {
|
|
|
|
uint8_t* data;
|
|
|
|
public:
|
|
|
|
SimuBlockDev(const char* image) {
|
|
FILE* f = fopen(image, "rw");
|
|
if (!f) {throw std::runtime_error("failed to open");}
|
|
fseek(f, 0L, SEEK_END);
|
|
size_t size = ftell(f);
|
|
fseek(f, 0L, SEEK_SET);
|
|
data = (uint8_t*) malloc(size);
|
|
fread(data, size, 1, f);
|
|
fclose(f);
|
|
}
|
|
|
|
uint32_t readBlock(LBA512 addr, uint8_t* dst) {
|
|
Log::addInfo("SD", "read512(%d*512)", addr);
|
|
memcpy(dst, data+addr*512, 512);
|
|
return 512;
|
|
}
|
|
|
|
uint32_t writeBlock(LBA512 addr, const uint8_t* src) {
|
|
Log::addInfo("SD", "write512(%d*512)", addr);
|
|
memcpy(data+addr*512, src, 512);
|
|
return 512;
|
|
}
|
|
|
|
};
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
//logInfo("{:s}", "I am not a number")
|
|
//std::string s = fmt::format(FMT_STRING("{:s}"), "I am not a number");
|
|
//std::string s = fmt::format(FMT_STRING("{:s}"), "I am not a number");
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
::testing::GTEST_FLAG(filter) = "*TestSeek*";
|
|
return RUN_ALL_TESTS();
|
|
|
|
// diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb
|
|
|
|
SimuBlockDev simu("/tmp/ram/1.dat");
|
|
AccessHelper<SimuBlockDev> ah(simu);
|
|
|
|
MBR<AccessHelper<SimuBlockDev>> mbr(ah);
|
|
|
|
if (mbr.isPresent() && mbr.isValid()) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
std::cout << (int) mbr.getPartition(i).getType() << " - " << mbr.getPartition(i).getFirstSector() << " - " << mbr.getPartition(i).getNumSectors() << std::endl;
|
|
}
|
|
|
|
using FAT32FS = FAT32::FS<AccessHelper<SimuBlockDev>>;
|
|
|
|
FAT32FS fat(ah, mbr.getPartition(0).getFirstSector() * 512);
|
|
|
|
FAT32FS::DirIterator dir = fat.getRoot();
|
|
while(false) {
|
|
|
|
FAT32::DirHandle h = dir.nextUsable();
|
|
if (!h.isValid()) {break;}
|
|
|
|
if (1==0) {
|
|
FAT32FS::File f = fat.open(h);
|
|
|
|
if (1==0) {
|
|
uint8_t* bufff = (uint8_t*) malloc(1024*1024);
|
|
uint32_t read = f.read(f.getSize(), bufff);
|
|
|
|
std::string name = f.getName();
|
|
std::ofstream out("/tmp/ram/" + name);
|
|
out.write((char*)bufff, read);
|
|
out.close();
|
|
|
|
free(bufff);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// //FAT32::DirEntryAt root = fat.getRoot().cur();
|
|
// FAT32FS::File file = fat.getOrCreateFile("tmp1.txt");
|
|
|
|
// uint8_t src[128];
|
|
// file.write(128, src);
|
|
|
|
// diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb
|
|
// diff /tmp/ram/KIRBY1.GB /apps/workspace/gbemu/tests/Kirby\'s\ Dream\ Land\ \(USA\,\ Europe\).gb
|
|
|
|
}
|
|
|
|
|
|
}
|