MediaFile: Rework to support BUrl sources
This commit is contained in:
@@ -26,6 +26,7 @@ namespace BPrivate {
|
|||||||
class BMediaTrack;
|
class BMediaTrack;
|
||||||
class BMessage;
|
class BMessage;
|
||||||
class BParameterWeb;
|
class BParameterWeb;
|
||||||
|
class BUrl;
|
||||||
class BView;
|
class BView;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,10 +70,21 @@ public:
|
|||||||
int32 flags = 0);
|
int32 flags = 0);
|
||||||
// set file later using SetTo()
|
// set file later using SetTo()
|
||||||
|
|
||||||
|
// Additional constructors used to stream data from protocols
|
||||||
|
// supported by the Streamer API
|
||||||
|
BMediaFile(BUrl* url);
|
||||||
|
BMediaFile(BUrl* url, int32 flags);
|
||||||
|
// Read-Write streaming constructor
|
||||||
|
BMediaFile(BUrl* destination,
|
||||||
|
const media_file_format* mfi,
|
||||||
|
int32 flags = 0);
|
||||||
|
|
||||||
virtual ~BMediaFile();
|
virtual ~BMediaFile();
|
||||||
|
|
||||||
status_t SetTo(const entry_ref* ref);
|
status_t SetTo(const entry_ref* ref);
|
||||||
status_t SetTo(BDataIO* destination);
|
status_t SetTo(BDataIO* destination);
|
||||||
|
// The streaming equivalent of SetTo
|
||||||
|
status_t SetTo(BUrl* url);
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
@@ -167,8 +179,9 @@ private:
|
|||||||
|
|
||||||
void _Init();
|
void _Init();
|
||||||
void _UnInit();
|
void _UnInit();
|
||||||
void _InitReader(BDataIO* source, int32 flags = 0);
|
void _InitReader(BDataIO* source, BUrl* url = NULL,
|
||||||
void _InitWriter(BDataIO* target,
|
int32 flags = 0);
|
||||||
|
void _InitWriter(BDataIO* target, BUrl* url,
|
||||||
const media_file_format* fileFormat,
|
const media_file_format* fileFormat,
|
||||||
int32 flags);
|
int32 flags);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <MediaTrack.h>
|
#include <MediaTrack.h>
|
||||||
|
#include <Url.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ BMediaFile::BMediaFile(const entry_ref* ref, int32 flags)
|
|||||||
CALLED();
|
CALLED();
|
||||||
_Init();
|
_Init();
|
||||||
fDeleteSource = true;
|
fDeleteSource = true;
|
||||||
_InitReader(new(std::nothrow) BFile(ref, O_RDONLY), flags);
|
_InitReader(new(std::nothrow) BFile(ref, O_RDONLY), NULL, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ BMediaFile::BMediaFile(BDataIO* source, int32 flags)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
_Init();
|
_Init();
|
||||||
_InitReader(source, flags);
|
_InitReader(source, NULL, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ BMediaFile::BMediaFile(const entry_ref* ref, const media_file_format* mfi,
|
|||||||
_Init();
|
_Init();
|
||||||
fDeleteSource = true;
|
fDeleteSource = true;
|
||||||
_InitWriter(new(std::nothrow) BFile(ref, B_CREATE_FILE | B_ERASE_FILE
|
_InitWriter(new(std::nothrow) BFile(ref, B_CREATE_FILE | B_ERASE_FILE
|
||||||
| B_WRITE_ONLY), mfi, flags);
|
| B_WRITE_ONLY), NULL, mfi, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ BMediaFile::BMediaFile(BDataIO* destination, const media_file_format* mfi,
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
_Init();
|
_Init();
|
||||||
_InitWriter(destination, mfi, flags);
|
_InitWriter(destination, NULL, mfi, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +82,31 @@ BMediaFile::BMediaFile(const media_file_format* mfi, int32 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMediaFile::BMediaFile(BUrl* url)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
_Init();
|
||||||
|
_InitReader(NULL, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMediaFile::BMediaFile(BUrl* url, int32 flags)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
_Init();
|
||||||
|
_InitReader(NULL, url, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMediaFile::BMediaFile(BUrl* destination, const media_file_format* mfi,
|
||||||
|
int32 flags)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
_Init();
|
||||||
|
_InitWriter(NULL, destination, mfi, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BMediaFile::SetTo(const entry_ref* ref)
|
BMediaFile::SetTo(const entry_ref* ref)
|
||||||
{
|
{
|
||||||
@@ -436,24 +462,25 @@ BMediaFile::_UnInit()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaFile::_InitReader(BDataIO* source, int32 flags)
|
BMediaFile::_InitReader(BDataIO* source, BUrl* url, int32 flags)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL && url == NULL) {
|
||||||
fErr = B_NO_MEMORY;
|
fErr = B_NO_MEMORY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fSource = source;
|
if (source != NULL) {
|
||||||
|
if (BFile* file = dynamic_cast<BFile*>(source)) {
|
||||||
|
fErr = file->InitCheck();
|
||||||
|
if (fErr != B_OK)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fExtractor = new(std::nothrow) MediaExtractor(source, flags);
|
||||||
|
} else
|
||||||
|
fExtractor = new(std::nothrow) MediaExtractor(url, flags);
|
||||||
|
|
||||||
if (BFile* file = dynamic_cast<BFile*>(source)) {
|
|
||||||
fErr = file->InitCheck();
|
|
||||||
if (fErr != B_OK)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fExtractor = new(std::nothrow) MediaExtractor(fSource, flags);
|
|
||||||
if (fExtractor == NULL)
|
if (fExtractor == NULL)
|
||||||
fErr = B_NO_MEMORY;
|
fErr = B_NO_MEMORY;
|
||||||
else
|
else
|
||||||
@@ -461,6 +488,9 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags)
|
|||||||
if (fErr != B_OK)
|
if (fErr != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Get the actual source from the extractor
|
||||||
|
fSource = fExtractor->Source();
|
||||||
|
|
||||||
fExtractor->GetFileFormatInfo(&fMFI);
|
fExtractor->GetFileFormatInfo(&fMFI);
|
||||||
fTrackNum = fExtractor->StreamCount();
|
fTrackNum = fExtractor->StreamCount();
|
||||||
fTrackList = (BMediaTrack**)malloc(fTrackNum * sizeof(BMediaTrack*));
|
fTrackList = (BMediaTrack**)malloc(fTrackNum * sizeof(BMediaTrack*));
|
||||||
@@ -473,8 +503,8 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaFile::_InitWriter(BDataIO* target, const media_file_format* fileFormat,
|
BMediaFile::_InitWriter(BDataIO* target, BUrl* url,
|
||||||
int32 flags)
|
const media_file_format* fileFormat, int32 flags)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
@@ -483,15 +513,18 @@ BMediaFile::_InitWriter(BDataIO* target, const media_file_format* fileFormat,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == NULL) {
|
if (target == NULL && url == NULL) {
|
||||||
fErr = B_NO_MEMORY;
|
fErr = B_NO_MEMORY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fMFI = *fileFormat;
|
fMFI = *fileFormat;
|
||||||
fSource = target;
|
|
||||||
|
|
||||||
fWriter = new(std::nothrow) MediaWriter(fSource, fMFI);
|
if (target != NULL)
|
||||||
|
fWriter = new(std::nothrow) MediaWriter(target, fMFI);
|
||||||
|
else
|
||||||
|
fWriter = new(std::nothrow) MediaWriter(url, fMFI);
|
||||||
|
|
||||||
if (fWriter == NULL)
|
if (fWriter == NULL)
|
||||||
fErr = B_NO_MEMORY;
|
fErr = B_NO_MEMORY;
|
||||||
else
|
else
|
||||||
@@ -499,6 +532,8 @@ BMediaFile::_InitWriter(BDataIO* target, const media_file_format* fileFormat,
|
|||||||
if (fErr != B_OK)
|
if (fErr != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Get the actual source from the writer
|
||||||
|
fSource = fWriter->Target();
|
||||||
fTrackNum = 0;
|
fTrackNum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user