many many small changes
switched to the new logging here and there some cleanups worked on i2S base class for files id3 parsing
This commit is contained in:
@@ -189,6 +189,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void fill(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) {
|
||||
setAddrWindow(x,y,w,h);
|
||||
modeDATA();
|
||||
const uint32_t entries = uint32_t(w) * uint32_t(h);
|
||||
for (uint32_t i = 0; i < entries; ++i) {
|
||||
writeByte(color>>8); writeByte(color>>0);
|
||||
}
|
||||
}
|
||||
|
||||
/** draw 5-6-5 encoded input data */
|
||||
void draw(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t* data) {
|
||||
setAddrWindow(x,y,w,h);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Types.h"
|
||||
#include "../../Debug.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* wrapper class
|
||||
|
||||
17
ext/sd/File.h
Normal file
17
ext/sd/File.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
class File {
|
||||
|
||||
public:
|
||||
|
||||
virtual uint32_t size() const = 0;
|
||||
|
||||
virtual uint32_t curPos() const = 0;
|
||||
|
||||
virtual void seekTo(uint32_t pos) = 0;
|
||||
|
||||
virtual uint32_t read(uint32_t size, uint8_t* dst) = 0;
|
||||
|
||||
virtual uint32_t write(uint32_t size, const uint8_t* src) = 0;
|
||||
|
||||
};
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
for (uint8_t i = 0; ; ++i) {
|
||||
const R1 res = cmd0();
|
||||
if (res.raw == 1) {break;}
|
||||
if (i == 4) {Log::addError(NAME, "init failed"); return false;}
|
||||
if (i == 8) {Log::addError(NAME, "init failed"); return false;}
|
||||
delay(50);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ private:
|
||||
// NOTE: it is IMPORTANT to send 0xFF to the card while reading its responses!
|
||||
|
||||
// wait for the first byte to arrive and read it
|
||||
for (uint8_t i = 0; i < 8; ++i) {
|
||||
for (uint8_t i = 0; i < 32; ++i) {
|
||||
dst[0] = spi.readWriteByte(0xFF);
|
||||
if ( (dst[0] & 0x80) == 0 ) {break;}
|
||||
}
|
||||
@@ -328,6 +328,8 @@ private:
|
||||
/** most simple read operation: read a single block of 512 bytes, addr = byteAddr/512 */
|
||||
bool readSingleBlock(LBA512 addr, uint8_t* dst) {
|
||||
|
||||
//spi.setSlowdown(0);
|
||||
|
||||
sendCMD(17, addr>>24, addr>>16, addr>>8, addr>>0, 0xFF);
|
||||
R1 res; readResponse(&res.raw, 1);
|
||||
|
||||
@@ -341,7 +343,7 @@ private:
|
||||
uint8_t res = spi.readWriteByte(0xFF);
|
||||
if (res == 0xFE) {break;} // available!
|
||||
if (res != 0xFF) {Log::addError(NAME, "invalid"); endCMD(); return false;} // invalid response
|
||||
if (i > 1024) {Log::addError(NAME, "timeout"); endCMD(); return false;} // timeout
|
||||
if (i > 32768) {Log::addError(NAME, "timeout"); endCMD(); return false;} // timeout
|
||||
}
|
||||
|
||||
// read data
|
||||
@@ -349,6 +351,8 @@ private:
|
||||
dst[i] = spi.readWriteByte(0xFF);
|
||||
}
|
||||
|
||||
//spi.setSlowdown(128);
|
||||
|
||||
// done
|
||||
endCMD();
|
||||
return true;
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace FAT32 {
|
||||
bool hasExtension(const char* ext) const {
|
||||
const size_t len = strlen(ext);
|
||||
if (len > 3) {return false;}
|
||||
for (int i = 0; i < len; ++i) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
if (asciitolower(entry.ext[i]) != asciitolower(ext[i])) {return false;}
|
||||
}
|
||||
for (int i = len; i < 3; ++i) {
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "Structs.h"
|
||||
#include "DirHandle.h"
|
||||
|
||||
#include "../../../Debug.h"
|
||||
|
||||
#include "../File.h"
|
||||
|
||||
// https://www.pjrc.com/tech/8051/ide/fat32.html
|
||||
namespace FAT32 {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class File {
|
||||
class File : public ::File {
|
||||
|
||||
static constexpr const char* NAME = "FAT32_File";
|
||||
static constexpr const uint32_t F_EOF = 0xFFFFFFFF;
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
}
|
||||
|
||||
/** the file's USED size */
|
||||
uint32_t getSize() const {return h.getSize();}
|
||||
uint32_t size() const {return h.getSize();}
|
||||
|
||||
/** the file's ALLOCATED size */
|
||||
uint32_t getAllocatedSize() const {return clusters.size() * fs.tmp.bytesPerCluster;}
|
||||
@@ -124,7 +124,7 @@ private:
|
||||
int32_t _read(uint32_t readSize, uint8_t* dst) {
|
||||
|
||||
// EOF reached?
|
||||
if (curAbsPos >= getSize()) {
|
||||
if (curAbsPos >= size()) {
|
||||
return F_EOF;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ private:
|
||||
curAbsPos += written;
|
||||
|
||||
// adjust the number of bytes used
|
||||
if (this->getSize() < curAbsPos) {this->setSize(curAbsPos);}
|
||||
if (this->size() < curAbsPos) {this->setSize(curAbsPos);}
|
||||
|
||||
return written;
|
||||
|
||||
|
||||
130
ext/sd/main.cpp
130
ext/sd/main.cpp
@@ -15,6 +15,8 @@
|
||||
#include "fat32/FS.h"
|
||||
#include "AccessHelper.h"
|
||||
|
||||
#include "../../data/formats/DataSourcePosixFile.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <fmt/format.h>
|
||||
@@ -76,34 +78,7 @@ 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>
|
||||
|
||||
@@ -117,18 +92,83 @@ public:
|
||||
#include "/apps/ESP8266lib/data/formats/jpeg/JPEGDEC.cpp"
|
||||
//#include "/apps/ESP8266lib/data/formats/jpeg/jpeg.c"
|
||||
|
||||
|
||||
#define MINIMP3_ONLY_MP3
|
||||
#define MINIMP3_NO_SIMD
|
||||
#define MINIMP3_IMPLEMENTATION
|
||||
#include "/apps/ESP8266lib/data/formats/mp3/minimp3.h"
|
||||
|
||||
#include "/apps/ESP8266lib/data/formats/mp3/ID3.h"
|
||||
|
||||
int drawJPEG(JPEGDRAW* pDraw) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ID3v2::Image mp3Image;
|
||||
DataSourcePosixFile mp3DS;
|
||||
|
||||
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
|
||||
if (1==1) {
|
||||
//SimuFile simu("/mnt/ssss/mp3s/TronLegacy/Tron Legacy Remixe/Daft Punk - The Son Of Flynn (Daniel En Test Remix).mp3");
|
||||
//DataSourcePosixFile f("/mnt/ssss/mp3s/grooveshark/2 Sonic feat. Destiny - Straight To The Light (Bass Up Remix).mp3");
|
||||
//DataSourcePosixFile f("/mnt/ssss/mp3s/MP3s/Scooter/Scooter - How Much Is The Fish.mp3");
|
||||
DataSourcePosixFile f("/mnt/ssss/mp3s/newretrowave/Daniel Deluxe - Soul Siphon.mp3");
|
||||
//DataSourcePosixFile f("/mnt/ssss/mp3s/F-777/Kr1z & F-777/ReMotion Vol.2/Kr1z & F-777 - Frozen Words (Kr1z Remix).mp3");
|
||||
|
||||
SimuFile simu("/tmp/ram/1.avi");
|
||||
AVI::Demuxer demux(simu);
|
||||
|
||||
|
||||
ID3v2 id3;
|
||||
ID3v2::Data data = id3.readTags(f, true);
|
||||
|
||||
if (data.img.present) {
|
||||
|
||||
mp3DS = f;
|
||||
mp3Image = data.img;
|
||||
JPEGDEC jpeg;
|
||||
|
||||
auto open = [] (const char* filename, int32_t* size) -> void* {
|
||||
*size = mp3Image.size;
|
||||
mp3DS.seekTo(mp3Image.pos);
|
||||
return (void*)1;
|
||||
};
|
||||
auto close = [] (void*) {
|
||||
return;
|
||||
};
|
||||
auto read = [] (JPEGFILE* pFile, uint8_t* pBuf, int32_t iLen) -> int32_t {
|
||||
const uint32_t got = mp3DS.read(iLen, pBuf);
|
||||
return got;
|
||||
};
|
||||
auto seek = [] (JPEGFILE *pFile, int32_t iPosition) {
|
||||
mp3DS.seekTo(iPosition + mp3Image.pos);
|
||||
return 1;
|
||||
};
|
||||
auto draw = [] (JPEGDRAW *pDraw) {
|
||||
std::cout << pDraw->x << ":" << pDraw->y << " " << pDraw->iWidth << ":" << pDraw->iHeight << std::endl;
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
||||
if (jpeg.open("img", open, close, read, seek, draw)) {
|
||||
jpeg.setPixelType(RGB565_BIG_ENDIAN);
|
||||
jpeg.decode(0, 0, 0);//40, 100, JPEG_SCALE_QUARTER | JPEG_EXIF_THUMBNAIL);
|
||||
jpeg.close();
|
||||
}
|
||||
|
||||
printf("xx");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (0==1) {
|
||||
|
||||
// ffmpeg -i '/mnt/ssss/anime/Toaru Majutsu no Index/[Eclipse] Toaru Majutsu no Index - 07 (1280x720 h264) [0255D83A].mkv' -r 15 -ss 30 -t 30 -vf scale=480x320 -c:v mjpeg -c:a mp3 -ar 44100 /tmp/ram/1.avi
|
||||
|
||||
DataSourcePosixFile f("/tmp/ram/1.avi");
|
||||
AVI::Demuxer demux(f);
|
||||
|
||||
bool valid = demux.isValid();
|
||||
std::cout << "valid: " << valid << std::endl;
|
||||
@@ -136,10 +176,20 @@ int main(int argc, char** argv) {
|
||||
uint8_t buf[64*1024];
|
||||
|
||||
std::ofstream outV("/tmp/ram/1.mjpeg");
|
||||
std::ofstream outA("/tmp/ram/1.mp3");
|
||||
std::ofstream outA1("/tmp/ram/1.mp3");
|
||||
std::ofstream outA2("/tmp/ram/1.pcm");
|
||||
|
||||
JPEGDEC jpeg;
|
||||
|
||||
mp3dec_t mp3d;
|
||||
mp3dec_frame_info_t info;
|
||||
info.frame_bytes = 0;
|
||||
mp3dec_init(&mp3d);
|
||||
short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
|
||||
|
||||
// ffplay /tmp/ram/1.mp3
|
||||
// ffplay -autoexit -f s16le /tmp/ram/1.pcm
|
||||
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
|
||||
AVI::NextChunk nc = demux.getNextChunk();
|
||||
@@ -148,7 +198,8 @@ int main(int argc, char** argv) {
|
||||
demux.read(nc, buf);
|
||||
|
||||
if (nc.type == AVI::NextChunkType::VIDEO) {
|
||||
outV.write((const char*)buf, nc.size);
|
||||
|
||||
//outV.write((const char*)buf, nc.size);
|
||||
|
||||
int res = jpeg.openRAM(buf, nc.size, drawJPEG);
|
||||
std::cout << "jpeg: " << res << std::endl;
|
||||
@@ -159,7 +210,16 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
} else if (nc.type == AVI::NextChunkType::AUDIO) {
|
||||
outA.write((const char*)buf, nc.size);
|
||||
|
||||
outA1.write((const char*)buf, nc.size);
|
||||
|
||||
uint32_t samples = mp3dec_decode_frame(&mp3d, buf, nc.size, pcm, &info);
|
||||
|
||||
std::cout << nc.size << " : " << info.frame_bytes << std::endl;
|
||||
|
||||
outA2.write((const char*)pcm, samples*2*sizeof(int16_t));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +267,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
if (1==0) {
|
||||
uint8_t* bufff = (uint8_t*) malloc(1024*1024);
|
||||
uint32_t read = f.read(f.getSize(), bufff);
|
||||
uint32_t read = f.read(f.size(), bufff);
|
||||
|
||||
std::string name = f.getName();
|
||||
std::ofstream out("/tmp/ram/" + name);
|
||||
|
||||
@@ -52,7 +52,7 @@ TEST (TestCreate, writeRead) {
|
||||
free(data);
|
||||
|
||||
ASSERT_EQ(size, written);
|
||||
ASSERT_EQ(size, f.getSize());
|
||||
ASSERT_EQ(size, f.size());
|
||||
ASSERT_EQ(sizeA, f.getAllocatedSize());
|
||||
|
||||
}
|
||||
@@ -78,7 +78,7 @@ TEST (TestCreate, writeRead) {
|
||||
|
||||
ASSERT_EQ(name, h.getName());
|
||||
ASSERT_EQ(name, f.getName());
|
||||
ASSERT_EQ(size, f.getSize());
|
||||
ASSERT_EQ(size, f.size());
|
||||
ASSERT_EQ(sizeA, f.getAllocatedSize());
|
||||
|
||||
uint8_t* data = (uint8_t*)malloc(128 + i * 512);
|
||||
@@ -159,7 +159,7 @@ TEST (TestCreate, getOrCreateFile) {
|
||||
ASSERT_EQ(size, fs.getSize());
|
||||
|
||||
FS::File f1 = fs.getOrCreateFile("test.txt");
|
||||
ASSERT_EQ(0, f1.getSize());
|
||||
ASSERT_EQ(0, f1.size());
|
||||
ASSERT_EQ(4096, f1.getAllocatedSize());
|
||||
ASSERT_EQ("test.txt", f1.getName());
|
||||
|
||||
@@ -171,7 +171,7 @@ TEST (TestCreate, getOrCreateFile) {
|
||||
|
||||
FS::File f2 = fs.getOrCreateFile("test.txt");
|
||||
|
||||
ASSERT_EQ(128, f2.getSize());
|
||||
ASSERT_EQ(128, f2.size());
|
||||
ASSERT_EQ(128, f2.read(128, d2));
|
||||
for (uint32_t i = 0; i < 128; ++i) {ASSERT_EQ(d1[i], d2[i]);}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user