diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-13 12:57:49 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-13 12:57:49 -0800 |
commit | 2d1d80bacda4e15f797552917442f92330d33571 (patch) | |
tree | e66d1cb47170a902566fafe268480717b0d5448c | |
parent | 4170b2688824896bd659e66afe41c4e65f8a9c8b (diff) | |
download | opencore-2d1d80bacda4e15f797552917442f92330d33571.tar.gz |
auto import from //branches/cupcake/...@131421
-rw-r--r-- | android/author/PVMediaRecorder.cpp | 21 | ||||
-rw-r--r-- | android/author/authordriver.cpp | 27 | ||||
-rw-r--r-- | android/author/authordriver.h | 7 | ||||
-rw-r--r-- | android/metadatadriver.cpp | 56 | ||||
-rw-r--r-- | android/metadatadriver.h | 10 | ||||
-rw-r--r-- | nodes/pvmp3ffparsernode/src/pvmf_mp3ffparser_node.cpp | 36 | ||||
-rw-r--r-- | nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp | 23 | ||||
-rw-r--r-- | oscl/oscl/osclio/src/oscl_file_native.cpp | 240 | ||||
-rw-r--r-- | oscl/oscl/osclio/src/oscl_file_native.h | 1 |
9 files changed, 208 insertions, 213 deletions
diff --git a/android/author/PVMediaRecorder.cpp b/android/author/PVMediaRecorder.cpp index 652d67f75..c0fcd9969 100644 --- a/android/author/PVMediaRecorder.cpp +++ b/android/author/PVMediaRecorder.cpp @@ -108,15 +108,30 @@ status_t PVMediaRecorder::setOutputFile(const char *path) LOGV("setOutputFile(%s)", path); if (mAuthorDriverWrapper == NULL) { LOGE("author driver wrapper is not initialized yet"); - return UNKNOWN_ERROR; + return NO_INIT; + } + + // use file descriptor interface + int fd = open(path, O_RDWR | O_CREAT ); + if (-1 == fd) { + LOGE("Ln %d open() error %d", __LINE__, fd); + return -errno; } + return setOutputFile(fd, 0, 0); +} +status_t PVMediaRecorder::setOutputFile(int fd, int64_t offset, int64_t length) +{ + LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length); set_output_file_command *ac = new set_output_file_command(); if (ac == NULL) { LOGE("failed to construct an author command"); - return UNKNOWN_ERROR; + return NO_MEMORY; } - ac->path = strdup(path); + + ac->fd = fd; + ac->offset = offset; + ac->length = length; return mAuthorDriverWrapper->enqueueCommand(ac, 0, 0); } diff --git a/android/author/authordriver.cpp b/android/author/authordriver.cpp index eed79964a..581cfb4c9 100644 --- a/android/author/authordriver.cpp +++ b/android/author/authordriver.cpp @@ -95,8 +95,6 @@ AuthorDriver::AuthorDriver() mComposerConfig(NULL), mVideoEncoderConfig(NULL), mAudioEncoderConfig(NULL), - mOutputFileName(NULL), - mKeepOutputFile(false), mVideoWidth(DEFAULT_FRAME_WIDTH), mVideoHeight(DEFAULT_FRAME_HEIGHT), mVideoFrameRate((int)DEFAULT_FRAME_RATE), @@ -502,21 +500,14 @@ void AuthorDriver::handleSetOutputFile(set_output_file_command *ac) PVMFStatus ret = PVMFFailure; PvmfFileOutputNodeConfigInterface *config = NULL; FILE *ifpOutput = NULL; - int handle = -1; if (!mComposerConfig) goto exit; config = OSCL_STATIC_CAST(PvmfFileOutputNodeConfigInterface*, mComposerConfig); if (!config) goto exit; - handle = open(ac->path, O_RDWR | O_CREAT ); - if(-1 == handle) { - LOGE("Ln %d open() error %d", __LINE__, handle); - goto exit; - } - - ifpOutput = fdopen(handle, "wb"); - if(NULL == ifpOutput) { + ifpOutput = fdopen(ac->fd, "wb"); + if (NULL == ifpOutput) { LOGE("Ln %d fopen() error", __LINE__); goto exit; } @@ -536,14 +527,12 @@ void AuthorDriver::handleSetOutputFile(set_output_file_command *ac) exit: - free(ac->path); if (ret == PVMFSuccess) { - mOutputFileName = ac->path; FinishNonAsyncCommand(ac); } else { LOGE("Ln %d SetOutputFile() error", __LINE__); - fclose(ifpOutput); + if (ifpOutput) fclose(ifpOutput); commandFailed(ac); } } @@ -568,8 +557,6 @@ void AuthorDriver::handleStop(author_command *ac) int error = 0; OSCL_TRY(error, mAuthor->Stop(ac)); OSCL_FIRST_CATCH_ANY(error, commandFailed(ac)); - - mKeepOutputFile = true; } void AuthorDriver::handleClose(author_command *ac) @@ -618,14 +605,6 @@ void AuthorDriver::handleRemoveAudioSource(author_command *ac) void AuthorDriver::removeConfigRefs(author_command *ac) { LOGV("removeConfigRefs"); - if (mOutputFileName) { - if (!mKeepOutputFile) { - LOGV("remove output file(%s)", mOutputFileName); - unlink(mOutputFileName); - } - free(mOutputFileName); - mOutputFileName = NULL; - } if (mComposerConfig) { mComposerConfig->removeRef(); diff --git a/android/author/authordriver.h b/android/author/authordriver.h index 9de4f432b..3b03b1e8b 100644 --- a/android/author/authordriver.h +++ b/android/author/authordriver.h @@ -143,7 +143,9 @@ struct set_video_encoder_command : author_command struct set_output_file_command : author_command { set_output_file_command() : author_command(AUTHOR_SET_OUTPUT_FILE) {}; - char *path; + int fd; + int64_t offset; + int64_t length; }; struct set_video_size_command : author_command @@ -253,9 +255,6 @@ private: PVInterface *mVideoEncoderConfig; PVInterface *mAudioEncoderConfig; - char *mOutputFileName; - bool mKeepOutputFile; - int mVideoWidth; int mVideoHeight; int mVideoFrameRate; diff --git a/android/metadatadriver.cpp b/android/metadatadriver.cpp index 6ef6b311f..99d97e8f8 100644 --- a/android/metadatadriver.cpp +++ b/android/metadatadriver.cpp @@ -76,6 +76,7 @@ MetadataDriver::MetadataDriver(uint32 mode): OsclActiveObject(OsclActiveObject:: mContextObjectRefValue = 0x5C7A; // Some random number mContextObject = mContextObjectRefValue; mMediaAlbumArt = NULL; + mSharedFd = -1; mVideoFrame = NULL; for (uint32 i = 0; i < NUM_METADATA_KEYS; ++i) { mMetadataValues[i][0] = '\0'; @@ -114,10 +115,10 @@ int MetadataDriver::retrieverThread() return 0; } - MetadataDriver::~MetadataDriver() { LOGV("destructor"); + mCmdId = 0; delete mVideoFrame; mVideoFrame = NULL; @@ -125,6 +126,8 @@ MetadataDriver::~MetadataDriver() mMediaAlbumArt = NULL; delete mSyncSem; mSyncSem = NULL; + + closeSharedFdIfNecessary(); } const char* MetadataDriver::extractMetadata(int keyCode) @@ -361,14 +364,43 @@ void MetadataDriver::clearCache() } } +status_t MetadataDriver::setDataSourceFd( + int fd, int64_t offset, int64_t length) { + LOGV("setDataSourceFd"); + + closeSharedFdIfNecessary(); + + if (offset < 0 || length < 0) { + if (offset < 0) { + LOGE("negative offset (%lld)", offset); + } + if (length < 0) { + LOGE("negative length (%lld)", length); + } + return INVALID_OPERATION; + } + + mSharedFd = dup(fd); + + char url[80]; + sprintf(url, "sharedfd://%d:%lld:%lld", mSharedFd, offset, length); + + clearCache(); + return doSetDataSource(url); +} + status_t MetadataDriver::setDataSource(const char* srcUrl) { LOGV("setDataSource"); + + closeSharedFdIfNecessary(); + // Don't let somebody trick us in to reading some random block of memory. if (strncmp("sharedfd://", srcUrl, 11) == 0) { LOGE("setDataSource: Invalid url (%s).", srcUrl); return UNKNOWN_ERROR; } + if (oscl_strlen(srcUrl) > MAX_STRING_LENGTH) { LOGE("setDataSource: Data source url length (%d) is too long.", oscl_strlen(srcUrl)); return UNKNOWN_ERROR; @@ -687,6 +719,13 @@ void MetadataDriver::HandleInformationalEvent(const PVAsyncInformationalEvent& a } +void MetadataDriver::closeSharedFdIfNecessary() { + if (mSharedFd >= 0) { + close(mSharedFd); + mSharedFd = -1; + } +} + //------------------------------------------------------------------------------ #include <media/PVMetadataRetriever.h> @@ -707,6 +746,7 @@ PVMetadataRetriever::PVMetadataRetriever() PVMetadataRetriever::~PVMetadataRetriever() { LOGV("destructor"); + Mutex::Autolock lock(mLock); delete mMetadataDriver; } @@ -714,6 +754,7 @@ PVMetadataRetriever::~PVMetadataRetriever() status_t PVMetadataRetriever::setDataSource(const char *url) { LOGV("setDataSource (%s)", url); + Mutex::Autolock lock(mLock); if (mMetadataDriver == 0) { LOGE("No MetadataDriver available"); @@ -729,21 +770,14 @@ status_t PVMetadataRetriever::setDataSource(const char *url) status_t PVMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length) { LOGV("setDataSource fd(%d), offset(%lld), length(%lld)", fd, offset, length); + Mutex::Autolock lock(mLock); if (mMetadataDriver == 0) { LOGE("No MetadataDriver available"); return INVALID_OPERATION; } - if (offset < 0 || length < 0) { - if (offset < 0) { - LOGE("negative offset (%lld)", offset); - } - if (length < 0) { - LOGE("negative length (%lld)", length); - } - return INVALID_OPERATION; - } - return NO_ERROR; + + return mMetadataDriver->setDataSourceFd(fd, offset, length); } status_t PVMetadataRetriever::setMode(int mode) diff --git a/android/metadatadriver.h b/android/metadatadriver.h index 301d5c436..0600e4fd2 100644 --- a/android/metadatadriver.h +++ b/android/metadatadriver.h @@ -81,6 +81,11 @@ public: // Returns OK if no operation failed; otherwise, it returns UNKNOWN_ERROR. status_t setDataSource(const char* srcUrl); + // This call may be time consuming. + // Returns OK if no operation failed; otherwise, it returns UNKNOWN_ERROR. + // The caller _retains_ ownership of "fd". + status_t setDataSourceFd(int fd, int64_t offset, int64_t length); + // Captures a representative frame. Returns NULL if failure. VideoFrame *captureFrame(); @@ -145,6 +150,7 @@ private: status_t extractMetadata(const char* key, char* value, uint32 valueLength); static int startDriverThread(void *cookie); int retrieverThread(); + void closeSharedFdIfNecessary(); OsclSemaphore* mSyncSem; @@ -180,6 +186,10 @@ private: // get these out of mMetadataValueList char mMetadataValues[NUM_METADATA_KEYS][MAX_METADATA_STRING_LENGTH]; MediaAlbumArt *mMediaAlbumArt; + + // If sourcing from a file descriptor, this holds a dup of it to prevent + // it from going away while we pass around the sharedfd: URI. + int mSharedFd; }; }; // namespace android diff --git a/nodes/pvmp3ffparsernode/src/pvmf_mp3ffparser_node.cpp b/nodes/pvmp3ffparsernode/src/pvmf_mp3ffparser_node.cpp index 55fa0aec0..25b6eb88c 100644 --- a/nodes/pvmp3ffparsernode/src/pvmf_mp3ffparser_node.cpp +++ b/nodes/pvmp3ffparsernode/src/pvmf_mp3ffparser_node.cpp @@ -3547,29 +3547,31 @@ PVMFStatus PVMFCPMContainerMp3::IssueCommand(int32 aCmd) case ECPMCheckUsage: iContainer->oWaitingOnLicense = false; - PVMFStatus status; - //Check for usage approval, and if approved, parse the file. - if ((iCPMContentType == PVMF_CPM_FORMAT_OMA1) || - (iCPMContentType == PVMF_CPM_FORMAT_AUTHORIZE_BEFORE_ACCESS)) { - status = CheckApprovedUsage(); - if (status != PVMFSuccess) - { - return status; - } - if (!iCPMContentAccessFactory) + PVMFStatus status = PVMFFailure; + //Check for usage approval, and if approved, parse the file. + if ((iCPMContentType == PVMF_CPM_FORMAT_OMA1) || + (iCPMContentType == PVMF_CPM_FORMAT_AUTHORIZE_BEFORE_ACCESS)) { - return PVMFFailure;//unexpected, since ApproveUsage succeeded. + status = CheckApprovedUsage(); + if (status != PVMFSuccess) + { + return status; + } + if (!iCPMContentAccessFactory) + { + return PVMFFailure;//unexpected, since ApproveUsage succeeded. + } } - } - if (status == PVMFSuccess) - { - if (PVMFSuccess == iContainer->CheckForMP3HeaderAvailability()) + if (status == PVMFSuccess) { - iContainer->CompleteInit(status); + if (PVMFSuccess == iContainer->CheckForMP3HeaderAvailability()) + { + iContainer->CompleteInit(status); + } } + return status; } - return status; case ECPMUsageComplete: diff --git a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp index 32d815ecd..a7ff697eb 100644 --- a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp +++ b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp @@ -1931,6 +1931,16 @@ PVMFStatus PVMp4FFComposerNode::AddMemFragToTrack(Oscl_Vector<OsclMemoryFragment aPort->SetLastTS(aTimestamp); } + // FIXME: + // + // First of all, this parsing logic should not be here, since composer does not need + // to parse the output stream and encoder should tell composer what type of picture + // is coming + // + // Second, this parsing code is looking for the PTYPE or PLUSPTYPE field through + // all the bits in the output picture, and there is no error handling here + // + // The big assumption is that anything is not marked as I-frame, it is a P-frame. switch (aFormat) { case PVMF_H264_MP4: @@ -1940,7 +1950,7 @@ PVMFStatus PVMp4FFComposerNode::AddMemFragToTrack(Oscl_Vector<OsclMemoryFragment } break; case PVMF_M4V: - for (i = 0;i < aFrame.size();i++) + for (i = 0; i < aFrame.size(); i++) { data = OSCL_REINTERPRET_CAST(uint8*, aFrame[i].ptr); if (data[4] <= 0x3F) @@ -1949,11 +1959,16 @@ PVMFStatus PVMp4FFComposerNode::AddMemFragToTrack(Oscl_Vector<OsclMemoryFragment break; case PVMF_H263: - for (i = 0;i < aFrame.size();i++) + for (i = 0; i < aFrame.size(); i++) { data = OSCL_REINTERPRET_CAST(uint8*, aFrame[i].ptr); - if (!(data[4] & 0x02)) - codeType = 0; // I-frame + bool isIFrameFromPTypeField = ((data[4] & 0x02) == 0x00); // PTYPE field must contain a single 0 bit + bool isExtendedPicCodingType = ((data[4] & 0x1C) == 0x1C) && ((data[5] & 0x80) == 0x80); + bool isIFrameFromPlusPTypeField = ((data[7] & 0x1C) == 0x00); // PLUSPTYPE field must contain three 0 bits + if ((isExtendedPicCodingType && isIFrameFromPlusPTypeField) || + (!isExtendedPicCodingType && isIFrameFromPTypeField)) { + codeType = 0; // I-frame + } } break; } diff --git a/oscl/oscl/osclio/src/oscl_file_native.cpp b/oscl/oscl/osclio/src/oscl_file_native.cpp index 6367088a1..11dcab422 100644 --- a/oscl/oscl/osclio/src/oscl_file_native.cpp +++ b/oscl/oscl/osclio/src/oscl_file_native.cpp @@ -70,187 +70,127 @@ int32 OsclNativeFile::Open(const OsclFileHandle& aHandle, uint32 mode return 0; } -int32 OsclNativeFile::Open(const oscl_wchar *filename, uint32 mode - , const OsclNativeFileParams& params - , Oscl_FileServer& fileserv) -{ - iMode = mode; - iOpenFileHandle = false; +static void OpenModeToString(uint32 mode, char mode_str[4]) { + uint32 index = 0; + if (mode & Oscl_File::MODE_READWRITE) { - OSCL_UNUSED_ARG(fileserv); - OSCL_UNUSED_ARG(params); - - char openmode[4]; - uint32 index = 0; - - if (mode & Oscl_File::MODE_READWRITE) - { - if (mode & Oscl_File::MODE_APPEND) - { - openmode[index++] = 'a'; - openmode[index++] = '+'; - } - else - { - openmode[index++] = 'w'; - openmode[index++] = '+'; - } - } - else if (mode & Oscl_File::MODE_APPEND) - { - openmode[index++] = 'a'; - openmode[index++] = '+'; - } - else if (mode & Oscl_File::MODE_READ) + if (mode & Oscl_File::MODE_APPEND) { - openmode[index++] = 'r'; - } - else if (mode & Oscl_File::MODE_READ_PLUS) - { - openmode[index++] = 'r'; - openmode[index++] = '+'; - } - - - - if (mode & Oscl_File::MODE_TEXT) - { - openmode[index++] = 't'; + mode_str[index++] = 'a'; + mode_str[index++] = '+'; } else { - openmode[index++] = 'b'; + mode_str[index++] = 'w'; + mode_str[index++] = '+'; } + } + else if (mode & Oscl_File::MODE_APPEND) + { + mode_str[index++] = 'a'; + mode_str[index++] = '+'; + } + else if (mode & Oscl_File::MODE_READ) + { + mode_str[index++] = 'r'; + } + else if (mode & Oscl_File::MODE_READ_PLUS) + { + mode_str[index++] = 'r'; + mode_str[index++] = '+'; + } - openmode[index++] = '\0'; + if (mode & Oscl_File::MODE_TEXT) + { + mode_str[index++] = 't'; + } + else + { + mode_str[index++] = 'b'; + } -#ifdef _UNICODE - oscl_wchar convopenmode[4]; - if (0 == oscl_UTF8ToUnicode(openmode, oscl_strlen(openmode), convopenmode, 4)) - { - return -1; - } + mode_str[index++] = '\0'; +} - if ((iFile = _wfopen(filename, convopenmode)) == NULL) - { - return -1; - } -#else - //Convert to UTF8 - char convfilename[OSCL_IO_FILENAME_MAXLEN]; - if (0 == oscl_UnicodeToUTF8(filename, oscl_strlen(filename), convfilename, OSCL_IO_FILENAME_MAXLEN)) - { - return -1; - } +int32 OsclNativeFile::OpenFileOrSharedFd( + const char *filename, const char *openmode) { #ifdef ENABLE_SHAREDFD_PLAYBACK - int fd; - long long offset; - long long len; - if (sscanf(convfilename, "sharedfd://%d:%lld:%lld", &fd, &offset, &len) == 3) - { - iSharedFd = fd; - iSharedFilePosition = 0; - iSharedFileOffset = offset; - long long size = lseek64(iSharedFd, 0, SEEK_END); - lseek64(iSharedFd, 0, SEEK_SET); - size -= offset; - iSharedFileSize = size < len ? size : len; - } - else + int fd; + long long offset; + long long len; + if (sscanf(filename, "sharedfd://%d:%lld:%lld", &fd, &offset, &len) == 3) + { + iSharedFd = fd; + iSharedFilePosition = 0; + iSharedFileOffset = offset; + long long size = lseek64(iSharedFd, 0, SEEK_END); + lseek64(iSharedFd, 0, SEEK_SET); + size -= offset; + iSharedFileSize = size < len ? size : len; + } + else #endif + { + if ((iFile = fopen(filename, openmode)) == NULL) { - if ((iFile = fopen(convfilename, openmode)) == NULL) - { - return -1; - } + return -1; } -#endif - - return 0; } + return 0; } -int32 OsclNativeFile::Open(const char *filename, uint32 mode +int32 OsclNativeFile::Open(const oscl_wchar *filename, uint32 mode , const OsclNativeFileParams& params , Oscl_FileServer& fileserv) { iMode = mode; iOpenFileHandle = false; - { - OSCL_UNUSED_ARG(fileserv); - OSCL_UNUSED_ARG(params); + OSCL_UNUSED_ARG(fileserv); + OSCL_UNUSED_ARG(params); - char openmode[4]; - uint32 index = 0; + char openmode[4]; + OpenModeToString(mode, openmode); - if (mode & Oscl_File::MODE_READWRITE) - { - if (mode & Oscl_File::MODE_APPEND) - { - openmode[index++] = 'a'; - openmode[index++] = '+'; - } - else - { - openmode[index++] = 'w'; - openmode[index++] = '+'; - - } - } - else if (mode & Oscl_File::MODE_APPEND) - { - openmode[index++] = 'a'; - openmode[index++] = '+'; - } - else if (mode & Oscl_File::MODE_READ) - { - openmode[index++] = 'r'; - } - else if (mode & Oscl_File::MODE_READ_PLUS) - { - openmode[index++] = 'r'; - openmode[index++] = '+'; - } +#ifdef _UNICODE + oscl_wchar convopenmode[4]; + if (0 == oscl_UTF8ToUnicode(openmode, oscl_strlen(openmode), convopenmode, 4)) + { + return -1; + } - if (mode & Oscl_File::MODE_TEXT) - { - openmode[index++] = 't'; - } - else - { - openmode[index++] = 'b'; - } + if ((iFile = _wfopen(filename, convopenmode)) == NULL) + { + return -1; + } +#else + //Convert to UTF8 + char convfilename[OSCL_IO_FILENAME_MAXLEN]; + if (0 == oscl_UnicodeToUTF8(filename, oscl_strlen(filename), convfilename, OSCL_IO_FILENAME_MAXLEN)) + { + return -1; + } - openmode[index++] = '\0'; -#ifdef ENABLE_SHAREDFD_PLAYBACK - int fd; - long long offset; - long long len; - if (sscanf(filename, "sharedfd://%d:%lld:%lld", &fd, &offset, &len) == 3) - { - iSharedFd = fd; - iSharedFilePosition = 0; - iSharedFileOffset = offset; - long long size = lseek64(iSharedFd, 0, SEEK_END); - lseek64(iSharedFd, 0, SEEK_SET); - size -= offset; - iSharedFileSize = size < len ? size : len; - } - else + return OpenFileOrSharedFd(convfilename, openmode); #endif - { - if ((iFile = fopen(filename, openmode)) == NULL) - { - return -1; - } - } +} - return 0; - } +int32 OsclNativeFile::Open(const char *filename, uint32 mode + , const OsclNativeFileParams& params + , Oscl_FileServer& fileserv) +{ + iMode = mode; + iOpenFileHandle = false; + + OSCL_UNUSED_ARG(fileserv); + OSCL_UNUSED_ARG(params); + + char openmode[4]; + OpenModeToString(mode, openmode); + return OpenFileOrSharedFd(filename, openmode); } int32 OsclNativeFile::Size() diff --git a/oscl/oscl/osclio/src/oscl_file_native.h b/oscl/oscl/osclio/src/oscl_file_native.h index 94d4a290c..4d744352b 100644 --- a/oscl/oscl/osclio/src/oscl_file_native.h +++ b/oscl/oscl/osclio/src/oscl_file_native.h @@ -118,6 +118,7 @@ class OsclNativeFile : public HeapBase bool HasAsyncRead(); private: + int32 OpenFileOrSharedFd(const char *filename, const char *openmode); //current open mode uint32 iMode; |