diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-08-16 14:29:23 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-08-16 14:29:23 +0100 |
| commit | 10f50e4a6b8cbe83cf8c9bee238afe93a5958053 (patch) | |
| tree | f0ca9b48ca702878f6c7d2b5492acaace7df5038 /rotord/src | |
| parent | 1af93fbfe4c8cfa214331d2d96327637ffe749bf (diff) | |
finished render log
Diffstat (limited to 'rotord/src')
| -rwxr-xr-x | rotord/src/libavwrapper.cpp | 18 | ||||
| -rwxr-xr-x | rotord/src/libavwrapper.h | 10 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 19 | ||||
| -rw-r--r-- | rotord/src/rendercontext.h | 46 | ||||
| -rwxr-xr-x | rotord/src/rotor.h | 11 | ||||
| -rwxr-xr-x | rotord/src/rotord.cpp | 37 | ||||
| -rwxr-xr-x | rotord/src/rotord.h | 1 |
7 files changed, 107 insertions, 35 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index c21d077..1b18769 100755 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -518,7 +518,7 @@ bool libav::decoder::avtry(int result, const std::string& msg) { // encoder methods // /////////////////////////// - +/* libav::encoder::encoder(const char * file_name, int width, int height, float _framerate,enum AVCodecID codec_id) : picture_yuv(NULL) , picture_rgb(NULL) @@ -632,13 +632,13 @@ libav::encoder::encoder(const char * file_name, int width, int height, float _fr mutex.unlock(); } - /* Get framebuffers */ + // Get framebuffers // if (! (picture_yuv = avcodec_alloc_frame()) ) // final frame format throw std::runtime_error(""); if (! (picture_rgb = avcodec_alloc_frame()) ) // rgb version I can understand easily throw std::runtime_error(""); - /* the image can be allocated by any means and av_image_alloc() is - * just the most convenient way if av_malloc() is to be used */ + // the image can be allocated by any means and av_image_alloc() is + // just the most convenient way if av_malloc() is to be used // if ( av_image_alloc(picture_yuv->data, picture_yuv->linesize, pCtx->width, pCtx->height, pCtx->pix_fmt, 1) < 0 ) throw std::runtime_error("Error allocating YUV frame buffer"); @@ -646,7 +646,7 @@ libav::encoder::encoder(const char * file_name, int width, int height, float _fr pCtx->width, pCtx->height, PIX_FMT_RGB24, 1) < 0 ) throw std::runtime_error("Error allocating RGB frame buffer"); - /* Init scale & convert */ + // Init scale & convert // if (! (Sctx=sws_getContext( width, height, @@ -704,7 +704,7 @@ libav::encoder::encoder(const char * file_name, int width, int height, float _fr // are we supposed to use the same codeccontext? // - /* open the output file */ + // open the output file // if (!(fmt->flags & AVFMT_NOFILE)) { //QMutexLocker lock(&decoder::mutex); @@ -735,7 +735,7 @@ void libav::encoder::write_frame(float seconds,uint8_t *rgbdata) picture_yuv->data, // dst picture_yuv->linesize ); // dst stride - /* encode the image */ + // encode the image // // use non-deprecated avcodec_encode_video2(...) AVPacket packet={0}; av_init_packet(&packet); @@ -812,7 +812,7 @@ void libav::encoder::write_frame(float seconds,uint16_t *audiodata){ avcodec_free_frame(&audio_frame); } -/* virtual */ +// virtual // libav::encoder::~encoder() { @@ -853,7 +853,7 @@ libav::encoder::~encoder() picture_rgb = NULL; } - +*/ bool libav::exporter::setup(int w,int h, int bitRate, int frameRate, std::string container){ maybeInitFFMpegLib(); diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h index ebe47c1..ea2e0c6 100755 --- a/rotord/src/libavwrapper.h +++ b/rotord/src/libavwrapper.h @@ -44,8 +44,8 @@ extern "C" { #include <libavformat/avformat.h> #include <libavutil/pixfmt.h> #include <libavutil/opt.h> -#include <libavutil/imgutils.h> -#include <libavutil/samplefmt.h> +//#include <libavutil/imgutils.h> +//#include <libavutil/samplefmt.h> #include <libswscale/swscale.h> //? } @@ -150,7 +150,7 @@ namespace libav { }; - +/* // TODO - finish refactoring based on // http://svn.gnumonks.org/trunk/21c3-video/ffmpeg/ffmpeg-0.4.9-pre1/output_example.c class encoder @@ -182,7 +182,7 @@ namespace libav { int audio_input_frame_size; float audiostep; }; - +*/ class exporter { public: @@ -197,7 +197,7 @@ namespace libav { int get_audio_framesize(){return audioframesize;}; float get_audio_step(){return audiostep;}; - AVStream *add_stream(AVFormatContext *oc, AVCodec **codec,enum AVCodecID codec_id); + AVStream *add_stream(AVFormatContext *oc, AVCodec **codec,enum AVCodecID codec_id); //AVCodecID void open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st); int open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st); diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index e028773..4825b96 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -6,14 +6,14 @@ using Poco::Logger; void Render_context::runTask() { while (!isCancelled()) { - int cmd=0; + Session_task cmd; mutex.lock(); if (work_queue.size()){ cmd=work_queue[0]; work_queue.pop_front(); } mutex.unlock(); - if(cmd==ANALYSE_AUDIO) { + if(cmd.task==ANALYSE_AUDIO) { state=ANALYSING_AUDIO; vector<Audio_processor*> processors; processors.push_back(audio_thumb); @@ -31,22 +31,25 @@ void Render_context::runTask() { state=IDLE; } } - if(cmd==RENDER) { + if(cmd.task==RENDER) { state=RENDERING; + renders[cmd.uid]=Render_status(RENDERING); if(graph.video_render(output_filename,audio_filename,output_framerate,progress)){ state=IDLE; + renders[cmd.uid].status=RENDER_READY; } else { //an error occurred: TODO have to clean up allocated data. autoptr? cerr<<"Rotor: render failed"<<endl; state=IDLE; + renders[cmd.uid].status=FAILED; } } sleep(100); } printf("Rotor: stopping thread\n"); } -void Render_context::add_queue(int item) { +void Render_context::add_queue(Session_task item) { mutex.lock(); work_queue.push_back(item); mutex.unlock(); @@ -97,7 +100,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H Poco::File f=Poco::File(audio_filename); if (f.exists()) { //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? - add_queue(ANALYSE_AUDIO); + add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Starting audio analysis: "+command.body); XML.addValue("status","Starting audio analysis: "+command.body); @@ -172,7 +175,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H logger.information("Loaded graph from http PUT body"); XML.addValue("status","Loaded graph from PUT body"); if (audio_loaded) { - add_queue(ANALYSE_AUDIO); + add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Starting audio analysis for graph: "+command.id); XML.addValue("status","Starting audio analysis for graph: "+command.id); @@ -192,7 +195,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //the graph or the audio could load first- have to analyse the audio with vamp after the graph is loaded //for now the graph must load 1st if (audio_loaded) { - add_queue(ANALYSE_AUDIO); + add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Starting audio analysis for graph: "+command.id); XML.addValue("status","Starting audio analysis for graph: "+command.id); @@ -311,7 +314,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H if (command.body!="") { // output_framerate=ofToFloat(command.body); } - add_queue(RENDER); + add_queue(Session_task(command.uid,RENDER)); status=HTTPResponse::HTTP_OK; logger.information("Starting render: "+command.body); XML.addValue("status","Starting render: "+command.body); diff --git a/rotord/src/rendercontext.h b/rotord/src/rendercontext.h index 26b39fa..d28cd82 100644 --- a/rotord/src/rendercontext.h +++ b/rotord/src/rendercontext.h @@ -8,6 +8,20 @@ #include "rotor.h" namespace Rotor { + #define IDLE 0 + #define ANALYSING_AUDIO 1 + #define AUDIO_READY 2 + #define CREATING_PREVIEW 3 + #define PREVIEW_READY 4 + #define RENDERING 5 + #define RENDER_READY 6 + #define FAILED 7 + #define NOT_FOUND 8 + + #define ANALYSE_AUDIO 1 + #define PREVIEW 2 + #define RENDER 3 + class Session_command { public: Session_command(){body="";}; @@ -15,6 +29,21 @@ namespace Rotor { string uid,method,id,body; vector<string> commands; }; + class Session_task { + public: + Session_task():uid(""),task(0){}; + Session_task(const string &_uid,int _task):uid(_uid),task(_task) {}; + string uid; + int task; + + }; + class Render_status { + public: + Render_status():status(0),progress(0.0f){}; + Render_status(int _status):status(_status),progress(0.0f){}; + int status; + float progress; + }; class Render_context: public Poco::Task { //Poco task object //manages a 'patchbay' //high level interfaces for the wizard @@ -37,17 +66,30 @@ namespace Rotor { }; ~Render_context(){delete audio_thumb;}; void runTask(); - void add_queue(int item); + void add_queue(Session_task item); void session_command(const Session_command& command,xmlIO& XML,Poco::Net::HTTPResponse::HTTPStatus& status); void cancel(); //interrupt locking process int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve? bool load_audio(const string &filename,vector<Audio_processor*> processors); bool load_video(const string &nodeID,const string &filename);//can be performance or clip + Render_status get_render_status(const string &uid){ + + //cerr<<"render status requested: "<<uid<<" status: "<<renders[uid].status<<endl; + + if (renders.find(uid)!=renders.end()){ + if (renders[uid].status==RENDERING){ + renders[uid].progress=progress; + } + return renders[uid]; + } + else return Render_status(NOT_FOUND); + }; private: int state; float progress; //for a locking process: audio analysis or rendering //thread only does one thing at once - std::deque<int> work_queue; + std::deque<Session_task> work_queue; + std::unordered_map<string,Render_status> renders; Poco::Mutex mutex; //lock for access from parent thread std::string audio_filename; std::string output_filename; diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index 1f345d1..e1d4c9e 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -21,17 +21,6 @@ #include "libavwrapper.h" namespace Rotor { - #define IDLE 0 - #define ANALYSING_AUDIO 1 - #define AUDIO_READY 2 - #define CREATING_PREVIEW 3 - #define PREVIEW_READY 4 - #define RENDERING 5 - #define RENDER_READY 6 - - #define ANALYSE_AUDIO 1 - #define PREVIEW 2 - #define RENDER 3 //forward declarations class Node; class Signal_node; diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index 33031e7..6130cfc 100755 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -108,6 +108,42 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS status=HTTPResponse::HTTP_OK; } } + else if (command[0]=="listrenders") { + XML.pushTag("rotor"); + if (request.getMethod()=="GET") { + int i=0; + for (auto r: renders){ + XML.addTag("render"); + XML.addAttribute("render","ID",r.first,i); + bool context_found=false; + for (auto& task: manager.taskList()) { + if(task->name()==r.second) { + Render_status status=((Poco::AutoPtr<Rotor::Render_context>)task)->get_render_status(r.first); + //cerr<<"render "<<r.first<<" found, context "<<r.second<<", status: "<<status.status<<endl; + switch (status.status) { + case RENDERING: + XML.addAttribute("render","status","rendering",i); + XML.addAttribute("render","progress",status.progress,i); + break; + case RENDER_READY: + XML.addAttribute("render","status","render complete",i); + break; + case FAILED: + XML.addAttribute("render","status","render failed",i); + break; + case NOT_FOUND: + XML.addAttribute("render","status","error - not found",i); + break; + } + context_found=true; + } + } + if (!context_found) XML.addAttribute("render","status","context unavailable",i); + i++; + } + status=HTTPResponse::HTTP_OK; + } + } else if (command[0]=="exit") { logger.information("exiting"); exit(0); @@ -154,6 +190,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS ((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(SC,XML,status); if (XML.tagExists("render_id")){ //cerr<<"render started: "<<SC.uid<<" in context: "<<command[0]<<endl; + renders[SC.uid]=command[0]; } } } diff --git a/rotord/src/rotord.h b/rotord/src/rotord.h index 5d4398b..ea065c0 100755 --- a/rotord/src/rotord.h +++ b/rotord/src/rotord.h @@ -88,6 +88,7 @@ class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory private: std::unordered_map<std::string,Rotor::Render_context> context; + std::unordered_map<std::string,std::string> renders; Poco::UUIDGenerator idGen; Poco::TaskManager manager; }; |
