file seek support, new test cases, AVI use file seek
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "structs.h"
|
||||
#include <iostream>
|
||||
//#include <iostream>
|
||||
|
||||
// https://docs.microsoft.com/en-us/previous-versions//ms779636(v=vs.85)?redirectedfrom=MSDN
|
||||
// basically, everything is a CHUNK and a chunk has a type (4 bytes) and a length (4 bytes)
|
||||
@@ -61,7 +61,7 @@ namespace AVI {
|
||||
AVIList hdrl;
|
||||
read(hdrl);
|
||||
if (hdrl.type != FOURCC("LIST") || hdrl.content != FOURCC("hdrl")) {return;}
|
||||
uint32_t posAfterStreams = pos + (hdrl.size - 4);
|
||||
uint32_t posAfterStreams = curPos() + (hdrl.size - 4);
|
||||
|
||||
AVIMainHeader avih;
|
||||
read(avih);
|
||||
@@ -75,7 +75,7 @@ namespace AVI {
|
||||
if (strl.type != "LIST" || strl.content != FOURCC("strl")) {return;}
|
||||
|
||||
// determine where the next entry will start
|
||||
const uint32_t startOfNextStream = pos + (strl.size - 4);
|
||||
const uint32_t startOfNextStream = curPos() + (strl.size - 4);
|
||||
|
||||
AVIStreamHeader strh;
|
||||
read(strh);
|
||||
@@ -103,7 +103,7 @@ namespace AVI {
|
||||
|
||||
}
|
||||
|
||||
dumpState();
|
||||
//dumpState();
|
||||
|
||||
// continue reading after hdrl
|
||||
seek(posAfterStreams);
|
||||
@@ -112,10 +112,7 @@ namespace AVI {
|
||||
|
||||
AVIList movi = readUntilList("movi");
|
||||
|
||||
std::cout << "movi data: " << movi.size << " bytes" << std::endl;
|
||||
|
||||
|
||||
printf("nn");
|
||||
//std::cout << "movi data: " << movi.size << " bytes" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -136,12 +133,12 @@ namespace AVI {
|
||||
|
||||
// if this is a list, dive INTO it (do not skip it! it has meaningful content!)
|
||||
if (chunk.type == "LIST") {
|
||||
seek(pos + sizeof(AVIList) - sizeof(AVIChunk));
|
||||
seek(curPos() + sizeof(AVIList) - sizeof(AVIChunk));
|
||||
continue;
|
||||
}
|
||||
|
||||
// just ignore unknown chunks
|
||||
seek(pos + chunk.size);
|
||||
seek(curPos() + chunk.size);
|
||||
continue;
|
||||
|
||||
}
|
||||
@@ -151,9 +148,7 @@ namespace AVI {
|
||||
void read(NextChunk nc, uint8_t* dst) {
|
||||
//seek(pos + nc.size);
|
||||
read(nc.size, dst);
|
||||
if ((nc.size % 2) != 0) {seek(pos+1);}
|
||||
|
||||
printf("xx");
|
||||
if ((nc.size % 2) != 0) {seek(curPos()+1);}
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
@@ -164,6 +159,10 @@ namespace AVI {
|
||||
|
||||
//uint32_t pos = 0;
|
||||
|
||||
uint32_t curPos() const {
|
||||
return src.curPos();
|
||||
}
|
||||
|
||||
void seek(uint32_t newPos) {
|
||||
//pos = newPos;
|
||||
src.seekTo(newPos);
|
||||
@@ -191,13 +190,13 @@ namespace AVI {
|
||||
|
||||
while(true) {
|
||||
|
||||
const uint32_t startOfChunk = pos;
|
||||
const uint32_t startOfChunk = curPos();
|
||||
read(chunk);
|
||||
|
||||
|
||||
// skip non-list chunks
|
||||
if (chunk.type != FOURCC("LIST")) {
|
||||
seek(pos + chunk.size);
|
||||
seek(curPos() + chunk.size);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -212,7 +211,7 @@ namespace AVI {
|
||||
}
|
||||
|
||||
// skip this list
|
||||
seek(pos + list.getPayloadSize());
|
||||
seek(curPos() + list.getPayloadSize());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user