Revert "Change the read method of ffmpeg from filename to buffer". This bug was only affecting the load of photos and that usage was removed.

This commit is contained in:
codestation
2014-01-18 21:26:05 -04:30
parent bafae021ed
commit ca2e0a4b0c
2 changed files with 3 additions and 55 deletions

View File

@@ -28,70 +28,28 @@
AVDecoder::AvInit init; AVDecoder::AvInit init;
AVDecoder::AVDecoder() : AVDecoder::AVDecoder() :
pFormatCtx(NULL), file(NULL) pFormatCtx(NULL)
{ {
} }
AVDecoder::~AVDecoder() AVDecoder::~AVDecoder()
{ {
if(pFormatCtx) { if(pFormatCtx) {
av_free(pFormatCtx->pb->buffer);
av_free(pFormatCtx->pb);
avformat_close_input(&pFormatCtx); avformat_close_input(&pFormatCtx);
} }
if(file) {
file->close();
delete file;
}
}
int AVDecoder::readFunction(void* opaque, uint8_t* buf, int buf_size)
{
QIODevice* stream = (QIODevice*)opaque;
int numBytes = stream->read((char*)buf, buf_size);
return numBytes;
}
int64_t AVDecoder::seekFunction(void* opaque, int64_t offset, int whence)
{
if (whence == AVSEEK_SIZE) {
return -1; // I don't know "size of my handle in bytes"
}
QIODevice* stream = (QIODevice*)opaque;
if (stream->isSequential()) {
return -1; // cannot seek a sequential stream
}
if (! stream->seek(offset) ) {
return -1;
}
return stream->pos();
} }
bool AVDecoder::open(const QString filename) bool AVDecoder::open(const QString filename)
{ {
file = new QFile(filename); if(avformat_open_input(&pFormatCtx, QFile::encodeName(filename).constData(), NULL, NULL) != 0) {
if(!file->open(QIODevice::ReadOnly)) {
return false;
}
const int ioBufferSize = 32768;
unsigned char *ioBuffer = (unsigned char *)av_malloc(ioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE);
AVIOContext *avioContext = avio_alloc_context(ioBuffer, ioBufferSize, 0, (void*)(file), &AVDecoder::readFunction, NULL, &AVDecoder::seekFunction);
pFormatCtx = avformat_alloc_context();
pFormatCtx->pb = avioContext;
if(avformat_open_input(&pFormatCtx, "dummy", NULL, NULL) != 0) {
av_free(avioContext->buffer);
av_free(avioContext);
return false; return false;
} }
if(avformat_find_stream_info(pFormatCtx, NULL) < 0) { if(avformat_find_stream_info(pFormatCtx, NULL) < 0) {
av_free(avioContext->buffer);
av_free(avioContext);
avformat_close_input(&pFormatCtx); avformat_close_input(&pFormatCtx);
return false; return false;
} }
return true; return true;
} }
@@ -302,10 +260,6 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
void AVDecoder::close() void AVDecoder::close()
{ {
av_free(pFormatCtx->pb->buffer);
av_free(pFormatCtx->pb);
avformat_close_input(&pFormatCtx); avformat_close_input(&pFormatCtx);
pFormatCtx = NULL; pFormatCtx = NULL;
file->close();
file = NULL;
} }

View File

@@ -20,7 +20,6 @@
#ifndef AVDECODER_H #ifndef AVDECODER_H
#define AVDECODER_H #define AVDECODER_H
#include <QFile>
#include <QImage> #include <QImage>
#include <QString> #include <QString>
@@ -59,14 +58,9 @@ public:
static AvInit init; static AvInit init;
private: private:
void AVFrameToQImage(AVFrame &frame, QImage &image, int width, int height);
AVFrame *getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index); AVFrame *getDecodedFrame(AVCodecContext *pCodecCtx, int stream_index);
static int readFunction(void* opaque, uint8_t* buf, int buf_size);
static int64_t seekFunction(void* opaque, int64_t offset, int whence);
AVFormatContext *pFormatCtx; AVFormatContext *pFormatCtx;
QFile *file;
}; };
#endif // AVDECODER_H #endif // AVDECODER_H