am d72b67cd: Add getError and setError to propagate error code from WVMMediaExtractor up to player.
* commit 'd72b67cdeb4f0293769fa8faeb9d5f7fc976f087': Add getError and setError to propagate error code from WVMMediaExtractor up to player.
This commit is contained in:
@@ -48,15 +48,17 @@ static int _cb2(char *in, char *out, int length, char *iv)
|
|||||||
DrmBuffer *decryptedDrmBufferPtr = &decryptedDrmBuffer;
|
DrmBuffer *decryptedDrmBufferPtr = &decryptedDrmBuffer;
|
||||||
|
|
||||||
char ivout[AES_BLOCK_SIZE];
|
char ivout[AES_BLOCK_SIZE];
|
||||||
if (in && length)
|
if (in && length) {
|
||||||
memcpy(ivout, in + length - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
memcpy(ivout, in + length - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
status = sDrmManagerClient->decrypt(sDecryptHandle, 0,
|
status = sDrmManagerClient->decrypt(sDecryptHandle, 0,
|
||||||
&encryptedDrmBuffer, &decryptedDrmBufferPtr,
|
&encryptedDrmBuffer, &decryptedDrmBufferPtr,
|
||||||
&ivBuffer);
|
&ivBuffer);
|
||||||
|
|
||||||
if (iv)
|
if (iv) {
|
||||||
memcpy(iv, ivout, AES_BLOCK_SIZE);
|
memcpy(iv, ivout, AES_BLOCK_SIZE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -100,6 +102,7 @@ WVMExtractorImpl::WVMExtractorImpl(sp<DataSource> dataSource)
|
|||||||
mIsLiveStream(false),
|
mIsLiveStream(false),
|
||||||
mSession(NULL),
|
mSession(NULL),
|
||||||
mDuration(0),
|
mDuration(0),
|
||||||
|
mError(OK),
|
||||||
mSetupStatus(OK)
|
mSetupStatus(OK)
|
||||||
{
|
{
|
||||||
dataSource->getDrmInfo(sDecryptHandle, &sDrmManagerClient);
|
dataSource->getDrmInfo(sDecryptHandle, &sDrmManagerClient);
|
||||||
@@ -114,8 +117,9 @@ WVMExtractorImpl::WVMExtractorImpl(sp<DataSource> dataSource)
|
|||||||
if (sDecryptHandle->status != RightsStatus::RIGHTS_VALID) {
|
if (sDecryptHandle->status != RightsStatus::RIGHTS_VALID) {
|
||||||
mSetupStatus = ERROR_DRM_NO_LICENSE;
|
mSetupStatus = ERROR_DRM_NO_LICENSE;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
mSetupStatus = ERROR_DRM_NO_LICENSE;
|
mSetupStatus = ERROR_DRM_NO_LICENSE;
|
||||||
|
}
|
||||||
|
|
||||||
// Set an info listener to handle messages from the drm plugin
|
// Set an info listener to handle messages from the drm plugin
|
||||||
mInfoListener = new WVMInfoListener();
|
mInfoListener = new WVMInfoListener();
|
||||||
@@ -129,6 +133,11 @@ void WVMExtractorImpl::Initialize()
|
|||||||
WVCredentials credentials;
|
WVCredentials credentials;
|
||||||
WVStatus result;
|
WVStatus result;
|
||||||
|
|
||||||
|
if (mSetupStatus != OK) {
|
||||||
|
setError(mSetupStatus);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mDataSource->getUri().size() > 0 && getAdaptiveStreamingMode()) {
|
if (mDataSource->getUri().size() > 0 && getAdaptiveStreamingMode()) {
|
||||||
mIsLiveStream = (mDataSource->getUri().getPathExtension().find(".m3u8") == 0);
|
mIsLiveStream = (mDataSource->getUri().getPathExtension().find(".m3u8") == 0);
|
||||||
}
|
}
|
||||||
@@ -179,6 +188,10 @@ void WVMExtractorImpl::Initialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mSetupStatus != OK) {
|
||||||
|
setError(mSetupStatus);
|
||||||
|
}
|
||||||
|
|
||||||
WV_SetWarningToErrorMS(10000);
|
WV_SetWarningToErrorMS(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,13 +240,15 @@ void WVMExtractorImpl::SocketInfoCallback(int fd, int closing, void *context)
|
|||||||
//
|
//
|
||||||
status_t WVMExtractorImpl::readMetaData()
|
status_t WVMExtractorImpl::readMetaData()
|
||||||
{
|
{
|
||||||
if (mHaveMetaData)
|
if (mHaveMetaData) {
|
||||||
return OK;
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
if (mSetupStatus != OK)
|
if (mSetupStatus != OK) {
|
||||||
return mSetupStatus;
|
return mSetupStatus;
|
||||||
|
}
|
||||||
|
|
||||||
// Get Video Configuration
|
// Get Video Configuration
|
||||||
WVVideoType videoType;
|
WVVideoType videoType;
|
||||||
@@ -247,8 +262,9 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
WVStatus result = WV_Info_GetVideoConfiguration(mSession, &videoType, &videoStreamID,
|
WVStatus result = WV_Info_GetVideoConfiguration(mSession, &videoType, &videoStreamID,
|
||||||
&videoProfile, &level, &width, &height,
|
&videoProfile, &level, &width, &height,
|
||||||
&aspect, &frameRate, &videoBitRate);
|
&aspect, &frameRate, &videoBitRate);
|
||||||
if (result != WV_Status_OK)
|
if (result != WV_Status_OK) {
|
||||||
return ERROR_MALFORMED;
|
return ERROR_MALFORMED;
|
||||||
|
}
|
||||||
|
|
||||||
// Get Audio Configuration
|
// Get Audio Configuration
|
||||||
WVAudioType audioType;
|
WVAudioType audioType;
|
||||||
@@ -260,8 +276,9 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
|
|
||||||
result = WV_Info_GetAudioConfiguration(mSession, &audioType, &audioStreamID, &audioProfile,
|
result = WV_Info_GetAudioConfiguration(mSession, &audioType, &audioStreamID, &audioProfile,
|
||||||
&numChannels, &sampleRate, &audioBitRate);
|
&numChannels, &sampleRate, &audioBitRate);
|
||||||
if (result != WV_Status_OK)
|
if (result != WV_Status_OK) {
|
||||||
return ERROR_MALFORMED;
|
return ERROR_MALFORMED;
|
||||||
|
}
|
||||||
|
|
||||||
if (numChannels == 0) {
|
if (numChannels == 0) {
|
||||||
ALOGD("numChannels is 0!");
|
ALOGD("numChannels is 0!");
|
||||||
@@ -272,10 +289,11 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
if (durationString == "") {
|
if (durationString == "") {
|
||||||
// We won't have a duration for live streams, and Stagefright doesn't seem to
|
// We won't have a duration for live streams, and Stagefright doesn't seem to
|
||||||
// have a way to represent that. Give a default duration of 1 hour for now.
|
// have a way to represent that. Give a default duration of 1 hour for now.
|
||||||
if (mIsLiveStream)
|
if (mIsLiveStream) {
|
||||||
durationString = "3600";
|
durationString = "3600";
|
||||||
else
|
} else {
|
||||||
return ERROR_MALFORMED;
|
return ERROR_MALFORMED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mDuration = (int64_t)(strtod(durationString.c_str(), NULL) * 1000000);
|
mDuration = (int64_t)(strtod(durationString.c_str(), NULL) * 1000000);
|
||||||
@@ -328,8 +346,9 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
status = readESDSMetaData(audioMetaData);
|
status = readESDSMetaData(audioMetaData);
|
||||||
if (status != OK)
|
if (status != OK) {
|
||||||
return status;
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
if (mIsLiveStream) {
|
if (mIsLiveStream) {
|
||||||
result = WV_Pause(mSession, "");
|
result = WV_Pause(mSession, "");
|
||||||
@@ -347,8 +366,9 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
|
|
||||||
// Since the WVExtractor goes away soon after this, we delegate ownership of some resources
|
// Since the WVExtractor goes away soon after this, we delegate ownership of some resources
|
||||||
// to the constructed media source
|
// to the constructed media source
|
||||||
if (mFileSource.get())
|
if (mFileSource.get()) {
|
||||||
mVideoSource->delegateFileSource(mFileSource);
|
mVideoSource->delegateFileSource(mFileSource);
|
||||||
|
}
|
||||||
|
|
||||||
mVideoSource->delegateDataSource(mDataSource);
|
mVideoSource->delegateDataSource(mDataSource);
|
||||||
|
|
||||||
@@ -411,8 +431,9 @@ status_t WVMExtractorImpl::readESDSMetaData(sp<MetaData> audioMetaData)
|
|||||||
bytesRead, auStart, dts, pts, sync);
|
bytesRead, auStart, dts, pts, sync);
|
||||||
|
|
||||||
result = WV_Info_GetCodecConfig(mSession, WV_CodecConfigType_ESDS, config, size);
|
result = WV_Info_GetCodecConfig(mSession, WV_CodecConfigType_ESDS, config, size);
|
||||||
if (result != WV_Status_OK)
|
if (result != WV_Status_OK) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
}
|
||||||
} while (result == WV_Status_Warning_Not_Available && limit-- > 0);
|
} while (result == WV_Status_Warning_Not_Available && limit-- > 0);
|
||||||
|
|
||||||
if (result != WV_Status_OK) {
|
if (result != WV_Status_OK) {
|
||||||
@@ -423,9 +444,9 @@ status_t WVMExtractorImpl::readESDSMetaData(sp<MetaData> audioMetaData)
|
|||||||
#if 0
|
#if 0
|
||||||
char *filename = "/data/wvm/esds";
|
char *filename = "/data/wvm/esds";
|
||||||
FILE *f = fopen(filename, "w");
|
FILE *f = fopen(filename, "w");
|
||||||
if (!f)
|
if (!f) {
|
||||||
ALOGD("Failed to open %s", filename);
|
ALOGD("Failed to open %s", filename);
|
||||||
else {
|
} else {
|
||||||
fwrite(config, size, 1, f);
|
fwrite(config, size, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
@@ -437,6 +458,7 @@ status_t WVMExtractorImpl::readESDSMetaData(sp<MetaData> audioMetaData)
|
|||||||
size_t WVMExtractorImpl::countTracks() {
|
size_t WVMExtractorImpl::countTracks() {
|
||||||
status_t err;
|
status_t err;
|
||||||
if ((err = readMetaData()) != OK) {
|
if ((err = readMetaData()) != OK) {
|
||||||
|
setError(err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,6 +469,7 @@ sp<MediaSource> WVMExtractorImpl::getTrack(size_t index)
|
|||||||
{
|
{
|
||||||
status_t err;
|
status_t err;
|
||||||
if ((err = readMetaData()) != OK) {
|
if ((err = readMetaData()) != OK) {
|
||||||
|
setError(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,18 +493,21 @@ sp<MetaData> WVMExtractorImpl::getTrackMetaData(size_t index, uint32_t flags)
|
|||||||
{
|
{
|
||||||
status_t err;
|
status_t err;
|
||||||
if ((err = readMetaData()) != OK) {
|
if ((err = readMetaData()) != OK) {
|
||||||
|
setError(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<MetaData> result;
|
sp<MetaData> result;
|
||||||
switch(index) {
|
switch(index) {
|
||||||
case 0:
|
case 0:
|
||||||
if (mVideoSource != NULL)
|
if (mVideoSource != NULL) {
|
||||||
result = mVideoSource->getFormat();
|
result = mVideoSource->getFormat();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (mAudioSource != NULL)
|
if (mAudioSource != NULL) {
|
||||||
result = mAudioSource->getFormat();
|
result = mAudioSource->getFormat();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -553,7 +579,6 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return durationUs;
|
return durationUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,4 +629,33 @@ size_t WVMExtractorImpl::getStreamCacheSize() const
|
|||||||
return atol(value);
|
return atol(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t WVMExtractorImpl::getError() {
|
||||||
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
|
status_t err = mError;
|
||||||
|
mError = OK;
|
||||||
|
|
||||||
|
//
|
||||||
|
// MediaPlayer.java documents these MEDIA_ERROR codes for applications:
|
||||||
|
// MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_SERVER_DIED, MEDIA_ERROR_IO,
|
||||||
|
// MEDIA_ERROR_MALFORMED, MEDIA_ERROR_UNSUPPORTED and MEDIA_ERROR_TIMED_OUT.
|
||||||
|
// In order to not change the behavior of WVMExtractorImpl.cpp,
|
||||||
|
// we return all ERROR_ codes used by the WVMExtractor in addition to
|
||||||
|
// those documented in MediaPlayer.java.
|
||||||
|
//
|
||||||
|
if (err == ERROR_DRM_NO_LICENSE || err == ERROR_END_OF_STREAM ||
|
||||||
|
err == ERROR_IO || err == ERROR_MALFORMED || err == OK ||
|
||||||
|
err == ERROR_UNSUPPORTED) {
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WVMExtractorImpl::setError(status_t err) {
|
||||||
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
|
mError = err;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <media/stagefright/DataSource.h>
|
#include <media/stagefright/DataSource.h>
|
||||||
#include <utils/RefBase.h>
|
#include <utils/RefBase.h>
|
||||||
|
|
||||||
|
|
||||||
// DLL entry - given a data source, instantiate a WVMExtractor object
|
// DLL entry - given a data source, instantiate a WVMExtractor object
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
@@ -52,11 +51,17 @@ public:
|
|||||||
static void SocketInfoCallback(int fd, int op, void *context);
|
static void SocketInfoCallback(int fd, int op, void *context);
|
||||||
static void cleanup();
|
static void cleanup();
|
||||||
|
|
||||||
|
status_t getError() ;
|
||||||
|
|
||||||
|
void setError(status_t err);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~WVMExtractorImpl();
|
virtual ~WVMExtractorImpl();
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mutex mLock;
|
||||||
|
|
||||||
status_t readAVCCMetaData(sp<MetaData> videoMetaData);
|
status_t readAVCCMetaData(sp<MetaData> videoMetaData);
|
||||||
status_t readESDSMetaData(sp<MetaData> audioMetaData);
|
status_t readESDSMetaData(sp<MetaData> audioMetaData);
|
||||||
|
|
||||||
@@ -77,6 +82,8 @@ private:
|
|||||||
|
|
||||||
int64_t mDuration; // usec.
|
int64_t mDuration; // usec.
|
||||||
|
|
||||||
|
status_t mError;
|
||||||
|
|
||||||
status_t mSetupStatus;
|
status_t mSetupStatus;
|
||||||
|
|
||||||
status_t readMetaData();
|
status_t readMetaData();
|
||||||
|
|||||||
Reference in New Issue
Block a user