diff options
Diffstat (limited to 'rotord/src/graph.cpp')
| -rw-r--r-- | rotord/src/graph.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp index 7ca8879..e6c0e3f 100644 --- a/rotord/src/graph.cpp +++ b/rotord/src/graph.cpp @@ -1,4 +1,4 @@ -#include "rotor.h" +#include "graph.h" using namespace Rotor; using Poco::Logger; @@ -507,4 +507,64 @@ bool Graph::parseXml(string media_path){ } loaded=true; return true; -}
\ No newline at end of file +} +bool Graph::load_audio(const string &filename,vector<Audio_processor*> processors){ + Logger& logger = Logger::get("Rotor"); + logger.information("Analysing "+filename); + + libav::audioloader loader; + loader.setup(filename); + + duration=((float)loader.formatContext->duration)/AV_TIME_BASE; + + int rate = loader.codecContext->sample_rate; + int samples = ((loader.formatContext->duration + 5000)*rate)/AV_TIME_BASE; //why 5000 more? + int channels= loader.codecContext->channels; + int bits = 16; //???why can't we read this loader.codecContext->bits_per_raw_sample; + + for (auto p: processors) { + if(!p->init(channels,bits,samples,rate) ){ + logger.error("ERROR: Audio plugin failed to initialse"); + return false; + } + } + + AVFrame* frame=loader.get_frame(); + int sample_processed=0; + + while (frame) + { + //now we can pass the data to the processor(s) + for (auto p: processors) { + p->process_frame(frame->data[0],frame->nb_samples); + } + sample_processed+=frame->nb_samples; + //mutex.lock(); + progress=((float)sample_processed)/samples; //atomic on 64 bit? + //mutex.unlock(); + + frame=loader.get_frame(); + } + + loader.close(); + + for (auto p: processors) { + p->cleanup(); + p->print_summary(); + } + + logger.information("Finished audio analysis"); + return true; +} +bool Graph::load_video(const string &nodeID,const string &filename){ + //this is a good standard example of how to find + //a node of a specific type by ID and do something + if (nodes.find(nodeID)!=nodes.end()){ + if (nodes[nodeID]->type=="video_loader") { + if (((Video_loader*)nodes[nodeID])->load(filename)) { + return true; + } + } + } + return false; +} |
