EBML library, input and output, supports MKV and WebM.
This commit is contained in:
parent
105b1677d1
commit
a762932c45
11 changed files with 2141 additions and 0 deletions
49
src/analysers/analyser_ebml.cpp
Normal file
49
src/analysers/analyser_ebml.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "analyser_ebml.h"
|
||||
#include <iostream>
|
||||
#include <mist/ebml.h>
|
||||
|
||||
void AnalyserEBML::init(Util::Config &conf){
|
||||
Analyser::init(conf);
|
||||
}
|
||||
|
||||
AnalyserEBML::AnalyserEBML(Util::Config &conf) : Analyser(conf){
|
||||
curPos = prePos = 0;
|
||||
}
|
||||
|
||||
bool AnalyserEBML::parsePacket(){
|
||||
prePos = curPos;
|
||||
// Read in smart bursts until we have enough data
|
||||
while (isOpen() && dataBuffer.size() < neededBytes()){
|
||||
uint64_t needed = neededBytes();
|
||||
dataBuffer.reserve(needed);
|
||||
for (uint64_t i = dataBuffer.size(); i < needed; ++i){
|
||||
dataBuffer += std::cin.get();
|
||||
++curPos;
|
||||
if (!std::cin.good()){dataBuffer.erase(dataBuffer.size() - 1, 1);}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataBuffer.size() < neededBytes()){return false;}
|
||||
|
||||
EBML::Element E(dataBuffer.data(), true);
|
||||
HIGH_MSG("Read an element at position %d", prePos);
|
||||
if (detail >= 2){std::cout << E.toPrettyString(depthStash.size() * 2, detail);}
|
||||
if (depthStash.size()){
|
||||
depthStash.front() -= E.getOuterLen();
|
||||
}
|
||||
if (E.getType() == EBML::ELEM_MASTER){
|
||||
depthStash.push_front(E.getPayloadLen());
|
||||
}
|
||||
while (depthStash.size() && !depthStash.front()){
|
||||
depthStash.pop_front();
|
||||
}
|
||||
///\TODO update mediaTime with the current timestamp
|
||||
dataBuffer.erase(0, E.getOuterLen());
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Calculates how many bytes we need to read a whole box.
|
||||
uint64_t AnalyserEBML::neededBytes(){
|
||||
return EBML::Element::needBytes(dataBuffer.data(), dataBuffer.size(), true);
|
||||
}
|
||||
|
17
src/analysers/analyser_ebml.h
Normal file
17
src/analysers/analyser_ebml.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "analyser.h"
|
||||
#include <deque>
|
||||
|
||||
class AnalyserEBML : public Analyser{
|
||||
public:
|
||||
AnalyserEBML(Util::Config &conf);
|
||||
static void init(Util::Config &conf);
|
||||
bool parsePacket();
|
||||
|
||||
private:
|
||||
uint64_t neededBytes();
|
||||
std::string dataBuffer;
|
||||
uint64_t curPos;
|
||||
uint64_t prePos;
|
||||
std::deque<uint64_t> depthStash;///<Contains bytes to read to go up a level in the element depth.
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue