diff options
Diffstat (limited to 'rotord')
| -rwxr-xr-x | rotord/libavwrapper.cpp | 131 | ||||
| -rwxr-xr-x | rotord/libavwrapper.h | 1 | ||||
| -rwxr-xr-x | rotord/rotor.h | 4 |
3 files changed, 10 insertions, 126 deletions
diff --git a/rotord/libavwrapper.cpp b/rotord/libavwrapper.cpp index be61ae9..5e767e0 100755 --- a/rotord/libavwrapper.cpp +++ b/rotord/libavwrapper.cpp @@ -1,23 +1,14 @@ -#include "libavwrapper_guarded.h" +#include "libavwrapper.h" extern Poco::Mutex mutex; //application wide mutex static Poco::Mutex mutex; -///this seems to create a long pause and finally crash extern "C" { #include <libswscale/swscale.h> } -/* -#include <QNetworkReply> -#include <QNetworkRequest> -#include <QEventLoop> -#include <QFileInfo> -#include <QMutexLocker> -#include <QDebug> -*/ #include <stdexcept> #include <iostream> @@ -28,28 +19,13 @@ using namespace std; // Translated to C++ by Christopher Bruns May 2012 // from ffmeg_adapt.c in whisk package by Nathan Clack, Mark Bolstadt, Michael Meeuwisse -//QMutex decoder::mutex; // Avoid link error on some macs #ifdef __APPLE__ extern "C" { #include <stdlib.h> #include <errno.h> -// #include "compiler/compiler.h" - -/* - * Darwin doesn't have posix_memalign(), provide a private - * weak alternative - */ - /* -int __weak posix_memalign(void **ptr, size_t align, size_t size) -{ - if (*ptr) - return 0; - return ENOMEM; -} -*/ } #endif @@ -148,19 +124,10 @@ libav::decoder::decoder(PixelFormat pixelFormat) mutex.unlock(); } -/* -decoder::decoder(QUrl url, PixelFormat pixelFormat) - : isOpen(false) -{ - //QMutexLocker lock(&decoder::mutex); - initialize(); - format = pixelFormat; - isOpen = open(url, pixelFormat); -} -*/ + void libav::decoder::cleanup(){ - //QMutexLocker lock(&decoder::mutex); + mutex.lock(); if (NULL != Sctx) { sws_freeContext(Sctx); @@ -197,11 +164,6 @@ void libav::decoder::cleanup(){ avioContext = NULL; } */ - //QNetworkreply - //if (reply != NULL) { - // reply->deleteLater(); - // reply = NULL; - //} // Don't need to free pCodec? } @@ -211,80 +173,8 @@ libav::decoder::~decoder() { cleanup(); } -/* -bool decoder::open(QUrl url, enum PixelFormat formatParam) -{ - if (url.isEmpty()) - return false; - - // Is the movie source a local file? - if (url.host() == "localhost") - url.setHost(""); - QString fileName = url.toLocalFile(); - if ( (! fileName.isEmpty()) - && (QFileInfo(fileName).exists()) ) - { - // return open(fileName, formatParam); // for testing only - - // Yes, the source is a local file - fileStream.setFileName(fileName); - // qDebug() << fileName; - if (! fileStream.open(QIODevice::ReadOnly)) - return false; - return open(fileStream, fileName, formatParam); - } - - // ...No, the source is not a local file - if (url.host() == "") - url.setHost("localhost"); - fileName = url.path(); - - // http://stackoverflow.com/questions/9604633/reading-a-file-located-in-memory-with-libavformat - // Load from URL - QEventLoop loop; // for synchronous url fetch http://stackoverflow.com/questions/5486090/qnetworkreply-wait-for-finished - QObject::connect(&networkManager, SIGNAL(finished(QNetworkReply*)), - &loop, SLOT(quit())); - QNetworkRequest request = QNetworkRequest(url); - // qDebug() << "networkManager" << __FILE__ << __LINE__; - reply = networkManager.get(request); - loop.exec(); - if (reply->error() != QNetworkReply::NoError) { - // qDebug() << reply->error(); - reply->deleteLater(); - reply = NULL; - return false; - } - QIODevice * stream = reply; - // Mpeg needs seekable device, so create in-memory buffer if necessary - if (stream->isSequential()) { - byteArray = stream->readAll(); - fileBuffer.setBuffer(&byteArray); - fileBuffer.open(QIODevice::ReadOnly); - if (! fileBuffer.seek(0)) - return false; - stream = &fileBuffer; - assert(! stream->isSequential()); - } - bool result = open(*stream, fileName, formatParam); - return result; -} -bool decoder::open(QIODevice& fileStream, QString& fileName, enum PixelFormat formatParam) -{ - // http://stackoverflow.com/questions/9604633/reading-a-file-located-in-memory-with-libavformat - // I think AVIOContext is the trick used to redivert the input stream - ioBuffer = (unsigned char *)av_malloc(ioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav - avioContext = avio_alloc_context(ioBuffer, ioBufferSize, 0, (void*)(&fileStream), &readFunction, NULL, &seekFunction); - container = avformat_alloc_context(); - container->pb = avioContext; - // Open file, check usability - std::string fileNameStd = fileName.toStdString(); - if (!avtry( avformat_open_input(&container, fileNameStd.c_str(), NULL, NULL), fileNameStd )) - return false; - return openUsingInitializedContainer(formatParam); -} -*/ // file name based method for historical continuity bool libav::decoder::open(char* fileName, enum PixelFormat formatParam){ @@ -730,17 +620,8 @@ libav::encoder::encoder(const char * file_name, int width, int height, float _fr if (aCtx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) audio_input_frame_size = 10000; else - audio_input_frame_size = aCtx->frame_size; //is coming out at 0? - - cerr<<"audio codec frame size is "<<audio_input_frame_size<<endl; - - //if (audio_input_frame_size ==0) { can't do this - // audio_input_frame_size =10000; - //} + audio_input_frame_size = aCtx->frame_size; - // [mpeg4 @ 0x7f02f00200e0] nb_samples (10000) != frame_size (0) (avcodec_encode_audio2) - quits thread - // why is frame size 0? - // should there be a seperate pCtx for audio? if (container->oformat->flags & AVFMT_GLOBALHEADER) aCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; @@ -1502,6 +1383,8 @@ bool libav::audioloader::setup(const std::string &filename){ return false; } + //use the first audio stream found + audioStream = NULL; for (unsigned int i = 0; i < formatContext->nb_streams; ++i) { @@ -1551,6 +1434,8 @@ bool libav::audioloader::setup(const std::string &filename){ std::cout << "This stream has " << codecContext->channels << " channels, a sample rate of " << codecContext->sample_rate << "Hz and "<<samples <<" samples" << std::endl; std::cout << "The data is in format " <<codecContext->sample_fmt<< " (aka "<< av_get_sample_fmt_name(codecContext->sample_fmt) << ") "<<std::endl; + if(av_sample_fmt_is_planar(codecContext->sample_fmt)) cerr<<"found planar audio"<<endl; + av_init_packet(&packet); //sample_processed=0; ready=true; diff --git a/rotord/libavwrapper.h b/rotord/libavwrapper.h index faa4a2e..e48dfa5 100755 --- a/rotord/libavwrapper.h +++ b/rotord/libavwrapper.h @@ -41,6 +41,7 @@ extern "C" { #include <libavutil/pixfmt.h> #include <libavutil/opt.h> #include <libavutil/imgutils.h> +#include <libavutil/samplefmt.h> #include <libswscale/swscale.h> //? } diff --git a/rotord/rotor.h b/rotord/rotor.h index 9494094..f27d99d 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -60,10 +60,8 @@ extern "C" { #include "vampHost.h" #include "xmlIO.h" -//#include "libavaudioloader.h" -//#include "libavexporter.h" #include "utils.h" //fequal -#include "libavwrapper_guarded.h" +#include "libavwrapper.h" namespace Rotor { #define IDLE 0 |
