diff options
Diffstat (limited to 'rotord')
| -rw-r--r-- | rotord/Makefile | 17 | ||||
| -rw-r--r-- | rotord/rotor.cpp | 94 | ||||
| -rwxr-xr-x | rotord/rotor.h | 23 |
3 files changed, 128 insertions, 6 deletions
diff --git a/rotord/Makefile b/rotord/Makefile index 2edfbca..34de47a 100644 --- a/rotord/Makefile +++ b/rotord/Makefile @@ -2,7 +2,22 @@ MY_CFLAGS = -I ../ffmpeg -fpermissive -std=c++11 # The linker options. -MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -lavcodec +MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L libs -lavcodec -lavutil -lavformat -lavfilter -lavdevice + +FFMPEG_LIBS= libavdevice \ + libavformat \ + libavfilter \ + libavcodec \ + libswresample \ + libswscale \ + libavutil \ + +#MY_CFLAGS += $(shell pkg-config --cflags $(FFMPEG_LIBS)) +#MY_LIBS += -L libs $(shell pkg-config --libs $(FFMPEG_LIBS)) + +#-lavcodec -lavutil -lavformat -lavfilter -lavdevice +#ffmpeg version hell! + # The pre-processor options used by the cpp (man cpp for more). CPPFLAGS = -Wall diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 28dab1e..83fff6f 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -286,8 +286,100 @@ Command_response Render_context::session_command(const std::vector<std::string>& //get all attributes of node and pass them as creation parameters? //could just pass them all as strings, let the object choose what to do itself? //YES +bool Render_context::load_audio(string &filename){ + //load audio into memory and create thumbnail + AVCodec *codec; + AVCodecContext *c= NULL; + int len; + FILE *f; + uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; + AVPacket avpkt; + AVFrame *decoded_frame = NULL; -bool Render_context::load_graph(string filename){ + av_init_packet(&avpkt); + + // http://stackoverflow.com/questions/9799560/decode-audio-using-libavcodec-and-play-using-libao + + /* find the mpeg audio decoder */ + codec = avcodec_find_decoder(AV_CODEC_ID_MP2); + if (!codec) { + fprintf(stderr, "Codec not found\n"); + return false; + } + + c = avcodec_alloc_context3(codec); + if (!c) { + fprintf(stderr, "Could not allocate audio codec context\n"); + return false; + } + + /* open it */ + if (avcodec_open2(c, codec, NULL) < 0) { + fprintf(stderr, "Could not open codec\n"); + return false; + } + + f = fopen(filename.c_str(), "rb"); + if (!f) { + fprintf(stderr, "Could not open %s\n", filename.c_str()); + return false; + } + + /* decode until eof */ + avpkt.data = inbuf; + avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); + + while (avpkt.size > 0) { + int got_frame = 0; + + if (!decoded_frame) { + if (!(decoded_frame = avcodec_alloc_frame())) { + printf("Could not allocate audio frame\n"); + return false; + } + } else + avcodec_get_frame_defaults(decoded_frame); + + len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); + if (len < 0) { + fprintf(stderr, "Error while decoding\n"); + return false; + } + if (got_frame) { + /* if a frame has been decoded, output it */ + int data_size = av_samples_get_buffer_size(NULL, c->channels,decoded_frame->nb_samples,c->sample_fmt, 1); + //fwrite(decoded_frame->data[0], 1, data_size, outfile); + + //here is where we do something with the data + + } + avpkt.size -= len; + avpkt.data += len; + avpkt.dts = + avpkt.pts = AV_NOPTS_VALUE; + if (avpkt.size < AUDIO_REFILL_THRESH) { + /* Refill the input buffer, to avoid trying to decode + * incomplete frames. Instead of this, one could also use + * a parser, or use a proper container format through + * libavformat. */ + memmove(inbuf, avpkt.data, avpkt.size); + avpkt.data = inbuf; + len = fread(avpkt.data + avpkt.size, 1, + AUDIO_INBUF_SIZE - avpkt.size, f); + if (len > 0) + avpkt.size += len; + } + } + + fclose(f); + + avcodec_close(c); + av_free(c); + avcodec_free_frame(&decoded_frame); + + return true; +} +bool Render_context::load_graph(string &filename){ printf("loading %s\n",filename.c_str()); if(xml.loadFile(filename) ){ graph=Graph(xml.getAttribute("patchbay","ID","",0),xml.getValue("patchbay","",0)); diff --git a/rotord/rotor.h b/rotord/rotor.h index c4f5c38..546e6f5 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -63,9 +63,24 @@ using Poco::UUID; using Poco::UUIDGenerator; using Poco::Net::HTTPResponse; + +extern "C" { + #include "libavcodec/avcodec.h" + #include "libavutil/opt.h" + #include "libavutil/channel_layout.h" + #include "libavutil/common.h" + #include "libavutil/imgutils.h" + #include "libavutil/mathematics.h" + #include "libavutil/samplefmt.h" +} + +#define AUDIO_INBUF_SIZE 20480 +#define AUDIO_REFILL_THRESH 4096 + #include "vampHost.h" #include "xmlIO.h" - +#include "avCodec.h" + namespace Rotor { #define IDLE 0 #define ANALYSING_AUDIO 1 @@ -292,11 +307,11 @@ namespace Rotor { void cancel(); //interrupt locking process int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve? int load_graph(Poco::UUID uid); - bool load_graph(string graph_filename); //should eventually be as above + bool load_graph(string &graph_filename); //should eventually be as above UUID save_graph(); //returns UUID of saved graph - int load_audio(string filename); + bool load_audio(string &filename); Render_requirements get_requirements(); - int load_video(int num,string filename); //can be performance or clip + int load_video(int num,string &filename); //can be performance or clip private: int state; |
