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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -79,14 +79,14 @@ struct AVIMainHeader : AVIChunk {
|
||||
uint32_t height;
|
||||
uint32_t reserved[4];
|
||||
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct AVIRect {
|
||||
uint16_t left;
|
||||
uint16_t top;
|
||||
uint16_t right;
|
||||
uint16_t bottom;
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct AVIStreamHeader : AVIChunk {
|
||||
|
||||
@@ -110,9 +110,10 @@ struct AVIStreamHeader : AVIChunk {
|
||||
bool isVideo() const {return fccType == FOURCC("vids");}
|
||||
bool isAudio() const {return fccType == FOURCC("auds");}
|
||||
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct BitMapInfoHeader {
|
||||
|
||||
uint32_t biSize;
|
||||
int32_t biWidth;
|
||||
int32_t biHeight;
|
||||
@@ -124,22 +125,28 @@ struct BitMapInfoHeader {
|
||||
int32_t biYPelsPerMeter;
|
||||
uint32_t biClrUsed;
|
||||
uint32_t biClrImportant;
|
||||
};
|
||||
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct RGBQUAD {
|
||||
|
||||
uint8_t rgbBlue;
|
||||
uint8_t rgbGreen;
|
||||
uint8_t rgbRed;
|
||||
uint8_t rgbReserved;
|
||||
};
|
||||
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct BitMapInfo : AVIChunk {
|
||||
|
||||
// <data from AVIChunk>
|
||||
BitMapInfoHeader bmi_header;
|
||||
RGBQUAD bmi_colors[1];
|
||||
|
||||
};
|
||||
|
||||
struct WaveFormat : AVIChunk {
|
||||
|
||||
// <data from AVIChunk>
|
||||
uint16_t format_tag;
|
||||
uint16_t channels;
|
||||
@@ -147,21 +154,25 @@ struct WaveFormat : AVIChunk {
|
||||
uint32_t avg_bytes_per_sec;
|
||||
uint16_t block_align;
|
||||
uint16_t size;
|
||||
};
|
||||
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct AVIIndexEntry {
|
||||
|
||||
uint32_t ckid;
|
||||
uint32_t flags;
|
||||
uint32_t chunk_offset;
|
||||
uint32_t chunk_length;
|
||||
};
|
||||
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
|
||||
|
||||
struct ChunkInfo {
|
||||
|
||||
uint32_t offset;
|
||||
uint32_t entry_offset;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
} __attribute__((__packed__));
|
||||
|
||||
Reference in New Issue
Block a user