TS::Packet FromFile 64-bit support and garbage data recovery improvements
This commit is contained in:
parent
e8db89319a
commit
9be07e5ecb
1 changed files with 29 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
/// \file ts_packet.cpp
|
||||
/// Holds all code for the TS namespace.
|
||||
|
||||
#include "util.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
|
@ -35,18 +36,36 @@ namespace TS {
|
|||
/// It fills the content with the next 188 bytes int he file.
|
||||
/// \param Data The data to be read into the packet.
|
||||
/// \return true if it was possible to read in a full packet, false otherwise.
|
||||
bool Packet::FromFile(FILE * data) {
|
||||
long long int bPos = ftell(data);
|
||||
bool Packet::FromFile(FILE * data){
|
||||
uint64_t bPos = Util::ftell(data);
|
||||
uint16_t retries = 0;
|
||||
while (retries < 256){
|
||||
if (!fread((void *)strBuf, 188, 1, data)) {
|
||||
if (!feof(data)){
|
||||
FAIL_MSG("Could not read 188 bytes from file! %s", strerror(errno));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (strBuf[0] != 0x47){
|
||||
HIGH_MSG("Failed to read a good packet on pos %lld", bPos);
|
||||
if (strBuf[0] == 0x47){
|
||||
pos=188;
|
||||
return true;
|
||||
}
|
||||
for (uint8_t i = 1; i < 188; ++i){
|
||||
if (strBuf[i] == 0x47){
|
||||
INFO_MSG("Shifting %u bytes", i);
|
||||
memmove((void*)strBuf, (void*)(strBuf+i), 188-i);
|
||||
if (!fread((void *)strBuf, i, 1, data)) {
|
||||
return false;
|
||||
}
|
||||
pos=188;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
INFO_MSG("Skipping invalid TS packet...");
|
||||
}
|
||||
FAIL_MSG("Failed to read a good packet @ %lld bytes", bPos);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Packet::FromStream(std::istream & data)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue