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
|
/// \file ts_packet.cpp
|
||||||
/// Holds all code for the TS namespace.
|
/// Holds all code for the TS namespace.
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -36,17 +37,35 @@ namespace TS {
|
||||||
/// \param Data The data to be read into the packet.
|
/// \param Data The data to be read into the packet.
|
||||||
/// \return true if it was possible to read in a full packet, false otherwise.
|
/// \return true if it was possible to read in a full packet, false otherwise.
|
||||||
bool Packet::FromFile(FILE * data){
|
bool Packet::FromFile(FILE * data){
|
||||||
long long int bPos = ftell(data);
|
uint64_t bPos = Util::ftell(data);
|
||||||
|
uint16_t retries = 0;
|
||||||
|
while (retries < 256){
|
||||||
if (!fread((void *)strBuf, 188, 1, data)) {
|
if (!fread((void *)strBuf, 188, 1, data)) {
|
||||||
|
if (!feof(data)){
|
||||||
|
FAIL_MSG("Could not read 188 bytes from file! %s", strerror(errno));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strBuf[0] != 0x47){
|
if (strBuf[0] == 0x47){
|
||||||
HIGH_MSG("Failed to read a good packet on pos %lld", bPos);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
pos=188;
|
pos=188;
|
||||||
return true;
|
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)
|
bool Packet::FromStream(std::istream & data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue