ffmpeg: Initial switch to BMediaIO
This commit is contained in:
@@ -126,7 +126,7 @@ avdictionary_to_message(AVDictionary* dictionary, BMessage* message)
|
|||||||
|
|
||||||
class StreamBase {
|
class StreamBase {
|
||||||
public:
|
public:
|
||||||
StreamBase(BPositionIO* source,
|
StreamBase(BMediaIO* source,
|
||||||
BLocker* sourceLock, BLocker* streamLock);
|
BLocker* sourceLock, BLocker* streamLock);
|
||||||
virtual ~StreamBase();
|
virtual ~StreamBase();
|
||||||
|
|
||||||
@@ -156,17 +156,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// I/O hooks for libavformat, cookie will be a Stream instance.
|
// I/O hooks for libavformat, cookie will be a Stream instance.
|
||||||
// Since multiple StreamCookies use the same BPositionIO source, they
|
// Since multiple StreamCookies use the same BMediaIO source, they
|
||||||
// maintain the position individually, and may need to seek the source
|
// maintain the position individually, and may need to seek the source
|
||||||
// if it does not match anymore in _Read().
|
// if it does not match anymore in _Read().
|
||||||
// TODO: This concept prevents the use of a plain BDataIO that is not
|
|
||||||
// seekable. There is a version of AVFormatReader in the SVN history
|
|
||||||
// which implements packet buffering for other streams when reading
|
|
||||||
// packets. To support non-seekable network streams for example, this
|
|
||||||
// code should be resurrected. It will make handling seekable streams,
|
|
||||||
// especially from different threads that read from totally independent
|
|
||||||
// positions in the stream (aggressive pre-buffering perhaps), a lot
|
|
||||||
// more difficult with potentially large memory overhead.
|
|
||||||
static int _Read(void* cookie, uint8* buffer,
|
static int _Read(void* cookie, uint8* buffer,
|
||||||
int bufferSize);
|
int bufferSize);
|
||||||
static off_t _Seek(void* cookie, off_t offset, int whence);
|
static off_t _Seek(void* cookie, off_t offset, int whence);
|
||||||
@@ -177,7 +169,7 @@ protected:
|
|||||||
bigtime_t _ConvertFromStreamTimeBase(int64_t time) const;
|
bigtime_t _ConvertFromStreamTimeBase(int64_t time) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BPositionIO* fSource;
|
BMediaIO* fSource;
|
||||||
off_t fPosition;
|
off_t fPosition;
|
||||||
// Since different threads may read from the source,
|
// Since different threads may read from the source,
|
||||||
// we need to protect the file position and I/O by a lock.
|
// we need to protect the file position and I/O by a lock.
|
||||||
@@ -201,7 +193,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
StreamBase::StreamBase(BPositionIO* source, BLocker* sourceLock,
|
StreamBase::StreamBase(BMediaIO* source, BLocker* sourceLock,
|
||||||
BLocker* streamLock)
|
BLocker* streamLock)
|
||||||
:
|
:
|
||||||
fSource(source),
|
fSource(source),
|
||||||
@@ -474,8 +466,10 @@ StreamBase::Seek(uint32 flags, int64* frame, bigtime_t* time)
|
|||||||
|
|
||||||
BAutolock _(fSourceLock);
|
BAutolock _(fSourceLock);
|
||||||
int64_t fileSize;
|
int64_t fileSize;
|
||||||
|
|
||||||
if (fSource->GetSize(&fileSize) != B_OK)
|
if (fSource->GetSize(&fileSize) != B_OK)
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
|
|
||||||
int64_t duration = Duration();
|
int64_t duration = Duration();
|
||||||
if (duration == 0)
|
if (duration == 0)
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
@@ -762,11 +756,13 @@ StreamBase::_Read(void* cookie, uint8* buffer, int bufferSize)
|
|||||||
|
|
||||||
BAutolock _(stream->fSourceLock);
|
BAutolock _(stream->fSourceLock);
|
||||||
|
|
||||||
TRACE_IO("StreamBase::_Read(%p, %p, %d) position: %lld/%lld\n",
|
TRACE_IO("StreamBase::_Read(%p, %p, %d) position: %lld\n",
|
||||||
cookie, buffer, bufferSize, stream->fPosition,
|
cookie, buffer, bufferSize, stream->fPosition);
|
||||||
stream->fSource->Position());
|
|
||||||
|
|
||||||
if (stream->fPosition != stream->fSource->Position()) {
|
if (stream->fPosition != stream->fSource->Position()) {
|
||||||
|
TRACE_IO("StreamBase::_Read fSource position: %lld\n",
|
||||||
|
stream->fSource->Position());
|
||||||
|
|
||||||
off_t position
|
off_t position
|
||||||
= stream->fSource->Seek(stream->fPosition, SEEK_SET);
|
= stream->fSource->Seek(stream->fPosition, SEEK_SET);
|
||||||
if (position != stream->fPosition)
|
if (position != stream->fPosition)
|
||||||
@@ -887,7 +883,7 @@ StreamBase::_ConvertFromStreamTimeBase(int64_t time) const
|
|||||||
|
|
||||||
class AVFormatReader::Stream : public StreamBase {
|
class AVFormatReader::Stream : public StreamBase {
|
||||||
public:
|
public:
|
||||||
Stream(BPositionIO* source,
|
Stream(BMediaIO* source,
|
||||||
BLocker* streamLock);
|
BLocker* streamLock);
|
||||||
virtual ~Stream();
|
virtual ~Stream();
|
||||||
|
|
||||||
@@ -924,7 +920,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AVFormatReader::Stream::Stream(BPositionIO* source, BLocker* streamLock)
|
AVFormatReader::Stream::Stream(BMediaIO* source, BLocker* streamLock)
|
||||||
:
|
:
|
||||||
StreamBase(source, streamLock, &fLock),
|
StreamBase(source, streamLock, &fLock),
|
||||||
fLock("stream lock"),
|
fLock("stream lock"),
|
||||||
@@ -1472,9 +1468,9 @@ AVFormatReader::Sniff(int32* _streamCount)
|
|||||||
{
|
{
|
||||||
TRACE("AVFormatReader::Sniff\n");
|
TRACE("AVFormatReader::Sniff\n");
|
||||||
|
|
||||||
BPositionIO* source = dynamic_cast<BPositionIO*>(Source());
|
BMediaIO* source = dynamic_cast<BMediaIO*>(Source());
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
TRACE(" not a BPositionIO, but we need it to be one.\n");
|
TRACE(" not a BMediaIO, but we need it to be one.\n");
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1647,9 +1643,9 @@ AVFormatReader::AllocateCookie(int32 streamIndex, void** _cookie)
|
|||||||
Stream* cookie = fStreams[streamIndex];
|
Stream* cookie = fStreams[streamIndex];
|
||||||
if (cookie == NULL) {
|
if (cookie == NULL) {
|
||||||
// Allocate the cookie
|
// Allocate the cookie
|
||||||
BPositionIO* source = dynamic_cast<BPositionIO*>(Source());
|
BMediaIO* source = dynamic_cast<BMediaIO*>(Source());
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
TRACE(" not a BPositionIO, but we need it to be one.\n");
|
TRACE(" not a BMediaIO, but we need it to be one.\n");
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -640,19 +640,20 @@ AVFormatWriter::_Seek(void* cookie, off_t offset, int whence)
|
|||||||
|
|
||||||
AVFormatWriter* writer = reinterpret_cast<AVFormatWriter*>(cookie);
|
AVFormatWriter* writer = reinterpret_cast<AVFormatWriter*>(cookie);
|
||||||
|
|
||||||
BPositionIO* positionIO = dynamic_cast<BPositionIO*>(writer->fTarget);
|
BMediaIO* mediaIO = dynamic_cast<BMediaIO*>(writer->fTarget);
|
||||||
if (positionIO == NULL)
|
if (mediaIO == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Support for special file size retrieval API without seeking anywhere:
|
// Support for special file size retrieval API without seeking anywhere:
|
||||||
if (whence == AVSEEK_SIZE) {
|
if (whence == AVSEEK_SIZE) {
|
||||||
off_t size;
|
off_t size;
|
||||||
if (positionIO->GetSize(&size) == B_OK)
|
if (mediaIO->GetSize(&size) == B_OK)
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t position = positionIO->Seek(offset, whence);
|
off_t position = mediaIO->Seek(offset, whence);
|
||||||
TRACE_IO(" position: %lld\n", position);
|
TRACE_IO(" position: %lld\n", position);
|
||||||
if (position < 0)
|
if (position < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user