URIReader support for TS input
This commit is contained in:
parent
1df76eff16
commit
f29d48154f
4 changed files with 191 additions and 173 deletions
|
@ -15,26 +15,34 @@ tthread::recursive_mutex tMutex;
|
|||
|
||||
namespace TS{
|
||||
|
||||
bool Assembler::assemble(Stream & TSStrm, char * ptr, size_t len, bool parse){
|
||||
bool Assembler::assemble(Stream & TSStrm, const char * ptr, size_t len, bool parse, uint64_t bytePos){
|
||||
bool ret = false;
|
||||
size_t offset = 0;
|
||||
size_t amount = 188-leftData.size();
|
||||
if (leftData.size() && len >= amount){
|
||||
//Attempt to re-assemble a packet from the leftovers of last time + current head
|
||||
if (len == amount || ptr[amount] == 0x47){
|
||||
VERYHIGH_MSG("Assembled scrap packet");
|
||||
//Success!
|
||||
leftData.append(ptr, amount);
|
||||
tsBuf.FromPointer(leftData);
|
||||
if (!ret && tsBuf.getUnitStart()){ret = true;}
|
||||
if (parse){
|
||||
TSStrm.parse(tsBuf, 0);
|
||||
}else{
|
||||
TSStrm.add(tsBuf);
|
||||
if (!TSStrm.isDataTrack(tsBuf.getPID())){TSStrm.parse(tsBuf.getPID());}
|
||||
if (leftData.size()){
|
||||
if (len >= amount){
|
||||
//Attempt to re-assemble a packet from the leftovers of last time + current head
|
||||
if (len == amount || ptr[amount] == 0x47){
|
||||
VERYHIGH_MSG("Assembled scrap packet");
|
||||
//Success!
|
||||
bytePos -= leftData.size();
|
||||
leftData.append(ptr, amount);
|
||||
tsBuf.FromPointer(leftData);
|
||||
if (!ret && tsBuf.getUnitStart()){ret = true;}
|
||||
if (parse){
|
||||
TSStrm.parse(tsBuf, bytePos);
|
||||
}else{
|
||||
TSStrm.add(tsBuf);
|
||||
if (!TSStrm.isDataTrack(tsBuf.getPID())){TSStrm.parse(tsBuf.getPID());}
|
||||
}
|
||||
offset = amount;
|
||||
bytePos += 188;
|
||||
leftData.truncate(0);
|
||||
}
|
||||
offset = amount;
|
||||
leftData.assign(0,0);
|
||||
}else{
|
||||
//No way to verify, we'll just append and hope for the best...
|
||||
leftData.append(ptr, len);
|
||||
return ret;
|
||||
}
|
||||
//On failure, hope we might live to succeed another day
|
||||
}
|
||||
|
@ -51,7 +59,7 @@ namespace TS{
|
|||
tsBuf.FromPointer(ptr + offset);
|
||||
if (!ret && tsBuf.getUnitStart()){ret = true;}
|
||||
if (parse){
|
||||
TSStrm.parse(tsBuf, 0);
|
||||
TSStrm.parse(tsBuf, bytePos);
|
||||
}else{
|
||||
TSStrm.add(tsBuf);
|
||||
if (!TSStrm.isDataTrack(tsBuf.getPID())){TSStrm.parse(tsBuf.getPID());}
|
||||
|
@ -59,15 +67,21 @@ namespace TS{
|
|||
}else{
|
||||
leftData.assign(ptr + offset, len - offset);
|
||||
}
|
||||
bytePos += 188;
|
||||
offset += 188;
|
||||
}else{
|
||||
++junk;
|
||||
++offset;
|
||||
++bytePos;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Assembler::clear(){
|
||||
leftData.truncate(0);
|
||||
}
|
||||
|
||||
void ADTSRemainder::setRemainder(const aac::adts &p, const void *source, uint32_t avail, uint64_t bPos){
|
||||
if (!p.getCompleteSize()){return;}
|
||||
|
||||
|
|
|
@ -112,7 +112,8 @@ namespace TS{
|
|||
|
||||
class Assembler{
|
||||
public:
|
||||
bool assemble(Stream & TSStrm, char * ptr, size_t len, bool parse = false);
|
||||
bool assemble(Stream & TSStrm, const char * ptr, size_t len, bool parse = false, uint64_t bytePos = 0);
|
||||
void clear();
|
||||
private:
|
||||
Util::ResizeablePointer leftData;
|
||||
TS::Packet tsBuf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue