diff options
Diffstat (limited to 'rotord/rotor.cpp')
| -rw-r--r-- | rotord/rotor.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 931bfa9..0a3a502 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -32,9 +32,10 @@ void Render_context::runTask() { //audio_analyser.process(audio_filename); //vampHost::runPlugin("","qm-vamp-plugins","qm-tempotracker", "",0, audio_filename, cerr,true); vector<base_audio_processor*> proc; - load_audio(audio_filename,proc); - - state=AUDIO_READY; + if (load_audio(audio_filename,proc)) { + state=AUDIO_READY; + } + else state=IDLE; } sleep(100); } @@ -269,7 +270,7 @@ Command_response Render_context::session_command(const std::vector<std::string>& //http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/ //great to use c++11 features -bool Render_context::load_audio(string &filename,vector<base_audio_processor*> processors){ +bool Render_context::load_audio(const string &filename,vector<base_audio_processor*> processors){ //load audio data from file //what's the best way to use this? the model is background processing, and we want to update a progress bar //could pass a function pointer to call when each chunk of data becomes available? @@ -279,7 +280,17 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p //there could even be an array of audio analysis functions to perform simultaneously? //how about a vector of objects that subclass the base audio processor class? - av_register_all(); + //1st get parameters and initialise the processors + //then begin data loop locking progress variable after each frame + + // + // + //the example in ffmpeg works, but it isn't one that identifies a codec- it is hard coded to look for a codec for AV_CODEC_ID_MP2 + //it also doesn't load through libavformat - which opens containers- it just loads a naked .mp2 stream + // + // + + av_register_all(); std::shared_ptr<AVFormatContext> avFormat(avformat_alloc_context(), &avformat_free_context); @@ -294,7 +305,7 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p return false; } - av_dump_format(avFormat.get(), 0, 0, false); + av_dump_format(avFormat.get(), 0, 0, false); //avformat.h line 1256 AVStream* stream = nullptr; for (unsigned int i = 0; i < avFormat->nb_streams; ++i) { @@ -337,7 +348,6 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p //avcodec.h line 1026 - cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<" ,channels: "<<audioCodec->channels<<" ,sample format: "<<audioCodec->sample_fmt<<endl; Packet packet(avFormat.get()); if (packet.packet.data == nullptr) { @@ -345,6 +355,9 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p return true; } + cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl; + + do { packet.reset(avFormat.get()); if (packet.packet.stream_index != stream->index) @@ -360,18 +373,25 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p size_t offsetInData = 0; - - /* + bool foundPacket=false; + // the decoding loop, running until EOF while (true) { // reading a packet using libavformat if (offsetInData >= packet.packet.size) { do { packet.reset(avFormat.get()); - if (packet.stream_index != videoStream->index) + if (packet.packet.stream_index != stream->index) continue; } while(0); + if (!foundPacket){ + cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl; + foundPacket=true; + } + } + + // preparing the packet that we will send to libavcodec AVPacket packetToSend; @@ -380,13 +400,17 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p // sending data to libavcodec int isFrameAvailable = 0; - const auto processedLength = avcodec_decode_video2(avVideoCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend); + //const auto processedLength = avcodec_decode_video2(avVideoCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend); + const auto processedLength = avcodec_decode_audio4(audioCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend); + + if (processedLength < 0) { av_free_packet(&packet); throw std::runtime_error("Error while processing the data"); } offsetInData += processedLength; + /* // processing the image if available if (isFrameAvailable) { // display image on the screen @@ -395,8 +419,10 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p const auto msToWait = avVideoContext->ticks_per_frame * 1000 * avVideoContext->time_base.num / avVideoContext->time_base.den; std::this_thread::sleep(std::chrono::milliseconds(msToWait)); } + */ + } - */ + return true; } |
