working on avi parsers
This commit is contained in:
@@ -31,22 +31,21 @@ public:
|
||||
uint32_t written = 0;
|
||||
LBA512 addrLBA = addr / SEC_SIZE; // LBA address
|
||||
uint16_t offset = (addr - addrLBA*SEC_SIZE);// 0 when addr is SEC_SIZE-byte aligned
|
||||
uint8_t buf[SEC_SIZE];
|
||||
|
||||
while(size) {
|
||||
|
||||
if (offset || size < SEC_SIZE) { // non-aligned / non-full-block write
|
||||
|
||||
// read the whole sector
|
||||
if (!readBlock(addrLBA, buf)) {return written;}
|
||||
if (!readBlockToCache(addrLBA)) {return written;}
|
||||
|
||||
// merge in the new data
|
||||
const uint32_t toModify = min(SEC_SIZE-offset, size);
|
||||
for (uint16_t i = 0; i < toModify; ++i) {buf[i+offset] = src[i+written];}
|
||||
for (uint16_t i = 0; i < toModify; ++i) {cache.buf[i+offset] = src[i+written];}
|
||||
offset = 0;
|
||||
|
||||
// write back the modified sector
|
||||
if (!writeBlock(addrLBA, buf)) {return written;}
|
||||
if (!writeBlock(addrLBA, cache.buf)) {return written;}
|
||||
|
||||
++addrLBA;
|
||||
size -= toModify;
|
||||
@@ -57,6 +56,9 @@ public:
|
||||
// write a full block
|
||||
if (!writeBlock(addrLBA, &src[written])) {return written;}
|
||||
|
||||
// written block was in cache? -> drop
|
||||
if (addrLBA == cache.lba) {cache.lba = 0xFFFFFFFF;}
|
||||
|
||||
++addrLBA;
|
||||
size -= SEC_SIZE;
|
||||
written += SEC_SIZE;
|
||||
@@ -92,7 +94,9 @@ public:
|
||||
|
||||
} else { // full block read
|
||||
|
||||
if (!readBlock(addrLBA, &dst[read])) {return read;}
|
||||
//if (!readBlock(addrLBA, &dst[read])) {return read;}
|
||||
if (!readBlockToCache(addrLBA)) {return read;}
|
||||
memcpy(&dst[read], cache.buf, SEC_SIZE);
|
||||
++addrLBA;
|
||||
size -= SEC_SIZE;
|
||||
read += SEC_SIZE;
|
||||
@@ -105,17 +109,27 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** read a single block of SEC_SIZE bytes. addr = byteAddr/512 */
|
||||
bool readBlock(LBA512 addr, uint8_t* dst) {
|
||||
return dev.readBlock(addr, dst);
|
||||
struct Cache {
|
||||
LBA512 lba = 0xFFFFFFFF;
|
||||
uint8_t buf[SEC_SIZE];
|
||||
} cache;
|
||||
|
||||
/** read a single block of SEC_SIZE bytes into the CACHE. addr = byteAddr/512 */
|
||||
bool readBlockToCache(LBA512 addr) {
|
||||
if (cache.lba == addr) {return true;} // already cached
|
||||
if (dev.readBlock(addr, cache.buf)) {
|
||||
cache.lba = addr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** read a single block of SEC_SIZE bytes. addr = byteAddr/512, write only a fraction of the 512 bytes into dst (skip+len) */
|
||||
bool readBlock(LBA512 addr, uint8_t* dst, uint16_t skip, uint16_t len) {
|
||||
uint8_t buf[SEC_SIZE];
|
||||
if (!dev.readBlock(addr, buf)) {return false;}
|
||||
|
||||
if (!readBlockToCache(addr)) {return false;}
|
||||
for (int i = 0; i < len; ++i) {
|
||||
*dst = buf[i+skip];
|
||||
*dst = cache.buf[i+skip];
|
||||
++dst;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -19,6 +19,9 @@ INCLUDE_DIRECTORIES(
|
||||
FILE(GLOB HEADERS
|
||||
./*.h
|
||||
./*/*.h
|
||||
|
||||
/apps/ESP8266lib/data/formats/avi/Demuxer.h
|
||||
/apps/ESP8266lib/data/formats/avi/structs.h
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -81,8 +81,25 @@ public:
|
||||
|
||||
//#define logInfo(fmt, ...) std::string s = fmt::format(FMT_STRING(fmt), __VA_ARGS__);
|
||||
|
||||
#include "/apps/ESP8266lib/data/formats/avi/Demuxer.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
{
|
||||
|
||||
// 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);
|
||||
|
||||
bool valid = demux.isValid();
|
||||
std::cout << valid << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//logInfo("{:s}", "I am not a number")
|
||||
//std::string s = fmt::format(FMT_STRING("{:s}"), "I am not a number");
|
||||
|
||||
Reference in New Issue
Block a user