forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for loading media from a QIODevice.
- Loading branch information
Showing
7 changed files
with
207 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <QtAV/QAVIOContext.h> | ||
#include <QIODevice> | ||
#include <QtAV/QtAV_Compat.h> | ||
#include <QDebug> | ||
|
||
namespace QtAV { | ||
|
||
QAVIOContext::QAVIOContext(QIODevice *io) : m_pIO(io) | ||
{ | ||
m_ucDataBuffer = new unsigned char[IODATA_BUFFER_SIZE]; | ||
} | ||
|
||
QAVIOContext::~QAVIOContext() | ||
{ | ||
delete m_ucDataBuffer; | ||
} | ||
|
||
int QAVIOContext::read(void *opaque, unsigned char *buf, int buf_size) | ||
{ | ||
QAVIOContext* avio = static_cast<QAVIOContext*>(opaque); | ||
//qDebug() << "read" << buf_size << avio->m_pIO->pos() << IODATA_BUFFER_SIZE; | ||
return avio->m_pIO->read((char*)buf,buf_size); | ||
} | ||
|
||
int QAVIOContext::write(void *opaque, unsigned char *buf, int buf_size) | ||
{ | ||
QAVIOContext* avio = static_cast<QAVIOContext*>(opaque); | ||
//qDebug() << "write"; | ||
return avio->m_pIO->write((char*)buf,buf_size); | ||
} | ||
|
||
int64_t QAVIOContext::seek(void *opaque, int64_t offset, int whence) | ||
{ | ||
QAVIOContext* avio = static_cast<QAVIOContext*>(opaque); | ||
//qDebug() << "seek"; | ||
int i = 0; | ||
|
||
if (whence == SEEK_END) | ||
{ | ||
offset = avio->m_pIO->size() - offset; | ||
} | ||
else if (whence == SEEK_CUR) | ||
{ | ||
offset = avio->m_pIO->pos() + offset; | ||
} | ||
else if (whence == AVSEEK_SIZE) | ||
{ | ||
return avio->m_pIO->size(); | ||
} | ||
|
||
if (!avio->m_pIO->seek(offset)) | ||
i=-1; | ||
else | ||
i=offset; | ||
return i; | ||
} | ||
|
||
AVIOContext* QAVIOContext::context() | ||
{ | ||
return avio_alloc_context(m_ucDataBuffer,IODATA_BUFFER_SIZE,0,this,&read,0,&seek); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef AVIOCONTEXT_H | ||
#define AVIOCONTEXT_H | ||
|
||
#include <sys/types.h> | ||
#include <QtAV_Global.h> | ||
|
||
class QIODevice; | ||
struct AVIOContext; | ||
|
||
#define IODATA_BUFFER_SIZE 32768 | ||
|
||
namespace QtAV { | ||
|
||
class QAVIOContext | ||
{ | ||
public: | ||
QAVIOContext(QIODevice* io); | ||
~QAVIOContext(); | ||
static int read(void *opaque, unsigned char *buf, int buf_size); | ||
static int write(void *opaque, unsigned char *buf, int buf_size); | ||
static int64_t seek(void *opaque, int64_t offset, int whence); | ||
|
||
AVIOContext* context(); | ||
|
||
QIODevice* m_pIO; | ||
|
||
//private: | ||
unsigned char* m_ucDataBuffer; | ||
}; | ||
|
||
} | ||
#endif // AVIOCONTEXT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters