From 10f50e4a6b8cbe83cf8c9bee238afe93a5958053 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 16 Aug 2013 14:29:23 +0100 Subject: finished render log --- rotord/src/libavwrapper.cpp | 18 ++++++++--------- rotord/src/libavwrapper.h | 10 +++++----- rotord/src/rendercontext.cpp | 19 ++++++++++-------- rotord/src/rendercontext.h | 46 ++++++++++++++++++++++++++++++++++++++++++-- rotord/src/rotor.h | 11 ----------- rotord/src/rotord.cpp | 37 +++++++++++++++++++++++++++++++++++ rotord/src/rotord.h | 1 + 7 files changed, 107 insertions(+), 35 deletions(-) (limited to 'rotord/src') 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 #include #include -#include -#include +//#include +//#include #include //? } @@ -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 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"< 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 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: "< work_queue; + std::deque work_queue; + std::unordered_map 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)task)->get_render_status(r.first); + //cerr<<"render "<)task)->session_command(SC,XML,status); if (XML.tagExists("render_id")){ //cerr<<"render started: "< context; + std::unordered_map renders; Poco::UUIDGenerator idGen; Poco::TaskManager manager; }; -- cgit v1.2.3