/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentWriter() * @brief Set current writer * @param pContext (IN/OUT) VSS context. * @param mediaType (IN) Media type. * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) * @return M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED: Media type not supported ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentWriter( M4VSS3GPP_MediaAndCodecCtxt *pC, M4VIDEOEDITING_FileType mediaType ) { M4WRITER_OutputFileType writerType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); switch( mediaType ) { case M4VIDEOEDITING_kFileType_3GPP: writerType = M4WRITER_k3GPP; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE, "Writer type not supported"); return M4VSS3GPP_ERR_INVALID_FILE_TYPE; } pC->pWriterGlobalFcts = pC->WriterInterface[writerType].pGlobalFcts; pC->pWriterDataFcts = pC->WriterInterface[writerType].pDataFcts; if( pC->pWriterGlobalFcts == M4OSA_NULL || pC->pWriterDataFcts == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE, "Writer type not supported"); M4OSA_TRACE1_0("Writer type not supported"); return M4VSS3GPP_ERR_INVALID_FILE_TYPE; } pC->pWriterDataFcts->pWriterContext = M4OSA_NULL; return M4NO_ERROR; }
/****************************************************************************** * M4OSA_ERR M4WRITER_3GP_openWrite(M4WRITER_Context* pContext, void* pWhat, * M4OSA_FileWriterPointer* pFileWriterPointer) * @brief Open a writer session. * @note * @param pContext: (OUT) Execution context of the 3GP writer, allocated by this function. * @param outputFileDescriptor (IN) Descriptor of the output file to create. * @param fileWriterFunction (IN) Pointer to structure containing the set of OSAL * file write functions. * @param tempFileDescriptor (IN) Descriptor of the temporary file to open * (NULL if not used) * @param fileReaderFunction (IN) Pointer to structure containing the set of OSAL file read * functions (NULL if not used) * @return M4NO_ERROR: there is no error * @return M4ERR_ALLOC: there is no more available memory * @return M4ERR_PARAMETER: pContext or pFilePtrFct is M4OSA_NULL (debug only) * @return any error returned by the MP4 core writer openWrite (Its coreID is M4MP4_WRITER) ****************************************************************************** */ M4OSA_ERR M4WRITER_3GP_openWrite( M4WRITER_Context* pContext, void* outputFileDescriptor, M4OSA_FileWriterPointer* pFileWriterPointer, void* tempFileDescriptor, M4OSA_FileReadPointer* pFileReaderPointer ) { M4WRITER_3GP_InternalContext* apContext; M4OSA_ERR err; M4OSA_TRACE1_0("M4WRITER_3GP_openWrite"); /** * Check input parameters */ M4OSA_DEBUG_IF2((M4OSA_NULL == pContext),M4ERR_PARAMETER, "M4WRITER_3GP_openWrite: pContext is M4OSA_NULL"); M4OSA_DEBUG_IF2((M4OSA_NULL == pFileWriterPointer),M4ERR_PARAMETER, "M4WRITER_3GP_openWrite: pFileWriterPointer is M4OSA_NULL"); /** * Allocate memory for the context */ *pContext=M4OSA_NULL; apContext = (M4WRITER_3GP_InternalContext*)M4OSA_32bitAlignedMalloc( sizeof(M4WRITER_3GP_InternalContext), M4WRITER_3GP, (M4OSA_Char *)"M4WRITER_3GP_InternalContext"); if (M4OSA_NULL == apContext) { M4OSA_TRACE1_0("M4WRITER_3GP_openWrite:\ unable to allocate context, returning M4ERR_ALLOC"); return (M4OSA_ERR)M4ERR_ALLOC; }
/** ************************************************************************ * @brief Creates an instance of the null decoder * @note Allocates the context * * @param pContext: (OUT) Context of the decoder * @param pStreamHandler: (IN) Pointer to an audio stream description * @param pUserData: (IN) Pointer to User data * * @return M4NO_ERROR there is no error * @return M4ERR_STATE State automaton is not applied * @return M4ERR_ALLOC a memory allocation has failed * @return M4ERR_PARAMETER at least one parameter is not properly set (in DEBUG only) ************************************************************************ */ M4OSA_ERR M4AD_NULL_create( M4AD_Context* pContext, M4_AudioStreamHandler *pStreamHandler, void* pUserData) { M4AD_NullContext* pC; M4OSA_DEBUG_IF1((pContext == 0), M4ERR_PARAMETER, "M4AD_NULL_create: invalid context pointer"); M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER, "M4AD_NULL_create: invalid pointer pStreamHandler"); pC = (M4AD_NullContext*)M4OSA_32bitAlignedMalloc(sizeof(M4AD_NullContext), M4DECODER_AUDIO, (M4OSA_Char *)"M4AD_NullContext"); if (pC == (M4AD_NullContext*)0) { M4OSA_TRACE1_0("Can not allocate null decoder context"); return M4ERR_ALLOC; } *pContext = pC; pC->m_pAudioStreamhandler = pStreamHandler; return M4NO_ERROR; }
/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentAudioDecoder() * @brief Set an audio decoder * @param context (IN/OUT) VSS context. * @param decoderType (IN) Decoder type * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentAudioDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC, M4_StreamType mediaType ) { M4AD_Type decoderType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioDecoder: pC=0x%x, mediaType=0x%x", pC, mediaType); switch( mediaType ) { case M4DA_StreamTypeAudioAmrNarrowBand: decoderType = M4AD_kTypeAMRNB; break; case M4DA_StreamTypeAudioAac: case M4DA_StreamTypeAudioAacADTS: case M4DA_StreamTypeAudioAacADIF: decoderType = M4AD_kTypeAAC; break; case M4DA_StreamTypeAudioMp3: decoderType = M4AD_kTypeMP3; break; case M4DA_StreamTypeAudioPcm: decoderType = M4AD_kTypePCM; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT, "Audio decoder type not supported"); return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT; } pC->m_pAudioDecoder = pC->m_pAudioDecoderItTable[decoderType]; pC->pCurrentAudioDecoderUserData = pC->pAudioDecoderUserDataTable[decoderType]; if( pC->m_pAudioDecoder == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT, "Audio decoder type not supported"); M4OSA_TRACE1_0("Audio decoder type not supported"); return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT; } return M4NO_ERROR; }
/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentAudioEncoder() * @brief Set an audio encoder * @param context (IN/OUT) VSS context. * @param MediaType (IN) Encoder type * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentAudioEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC, M4SYS_StreamType mediaType ) { M4ENCODER_AudioFormat encoderType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioEncoder: pC=0x%x, mediaType=0x%x", pC, mediaType); switch( mediaType ) { case M4SYS_kAMR: M4OSA_TRACE3_0( "M4VSS3GPP_setCurrentAudioEncoder: encoder type AMR"); encoderType = M4ENCODER_kAMRNB; break; case M4SYS_kAAC: M4OSA_TRACE3_0( "M4VSS3GPP_setCurrentAudioEncoder: encoder type AAC"); encoderType = M4ENCODER_kAAC; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT, "Audio encoder type not supported"); return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT; } pC->pAudioEncoderGlobalFcts = pC->pAudioEncoderInterface[encoderType]; pC->pCurrentAudioEncoderUserData = pC->pAudioEncoderUserDataTable[encoderType]; M4OSA_TRACE3_3( "M4VSS3GPP_setCurrentAudioEncoder: pC->pAudioEncoderInterface[0x%x]=0x%x,\ pC->pAudioEncoderGlobalFcts = 0x%x", encoderType, pC->pAudioEncoderInterface[encoderType], pC->pAudioEncoderGlobalFcts); if( pC->pAudioEncoderGlobalFcts == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT, "Audio encoder type not supported"); M4OSA_TRACE1_0("Audio encoder type not supported"); return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT; } return M4NO_ERROR; }
/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentVideoDecoder() * @brief Set a video decoder * @param pContext (IN/OUT) VSS context. * @param decoderType (IN) Decoder type * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) * @return M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED: Media type not supported ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentVideoDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC, M4_StreamType mediaType ) { M4DECODER_VideoType decoderType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoDecoder: pC=0x%x, mediaType=0x%x", pC, mediaType); switch( mediaType ) { case M4DA_StreamTypeVideoMpeg4: case M4DA_StreamTypeVideoH263: decoderType = M4DECODER_kVideoTypeMPEG4; break; case M4DA_StreamTypeVideoMpeg4Avc: decoderType = M4DECODER_kVideoTypeAVC; break; case M4DA_StreamTypeVideoARGB8888: decoderType = M4DECODER_kVideoTypeYUV420P; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT, "Video decoder type not supported"); return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT; } pC->m_pVideoDecoder = pC->m_pVideoDecoderItTable[decoderType]; #ifdef M4VSS_ENABLE_EXTERNAL_DECODERS pC->m_pCurrentVideoDecoderUserData = pC->m_pVideoDecoderUserDataTable[decoderType]; #endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */ if( pC->m_pVideoDecoder == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT, "Video decoder type not supported"); M4OSA_TRACE1_0("Video decoder type not supported"); return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT; } return M4NO_ERROR; }
/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentVideoEncoder() * @brief Set a video encoder * @param pContext (IN/OUT) VSS context. * @param MediaType (IN) Encoder type * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) * @return M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED: Media type not supported ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentVideoEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC, M4SYS_StreamType mediaType ) { M4ENCODER_Format encoderType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoEncoder: pC=0x%x, mediaType=0x%x", pC, mediaType); switch( mediaType ) { case M4SYS_kH263: encoderType = M4ENCODER_kH263; break; case M4SYS_kMPEG_4: encoderType = M4ENCODER_kMPEG4; break; case M4SYS_kH264: encoderType = M4ENCODER_kH264; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT, "Video encoder type not supported"); return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT; } pC->pVideoEncoderGlobalFcts = pC->pVideoEncoderInterface[encoderType]; pC->pCurrentVideoEncoderExternalAPI = pC->pVideoEncoderExternalAPITable[encoderType]; pC->pCurrentVideoEncoderUserData = pC->pVideoEncoderUserDataTable[encoderType]; if( pC->pVideoEncoderGlobalFcts == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT, "Video encoder type not supported"); M4OSA_TRACE1_0("Video encoder type not supported"); return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT; } return M4NO_ERROR; }
/** ************************************************************************ * M4OSA_ERR M4VSS3GPP_setCurrentReader() * @brief Set current reader * @param pContext (IN/OUT) VSS context. * @param mediaType (IN) Media type. * @return M4NO_ERROR: No error * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) * @return M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED: Media type not supported ************************************************************************ */ M4OSA_ERR M4VSS3GPP_setCurrentReader( M4VSS3GPP_MediaAndCodecCtxt *pC, M4VIDEOEDITING_FileType mediaType ) { M4READER_MediaType readerType; M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); switch( mediaType ) { case M4VIDEOEDITING_kFileType_3GPP: case M4VIDEOEDITING_kFileType_MP4: case M4VIDEOEDITING_kFileType_M4V: readerType = M4READER_kMediaType3GPP; break; case M4VIDEOEDITING_kFileType_AMR: readerType = M4READER_kMediaTypeAMR; break; case M4VIDEOEDITING_kFileType_MP3: readerType = M4READER_kMediaTypeMP3; break; case M4VIDEOEDITING_kFileType_PCM: readerType = M4READER_kMediaTypePCM; break; default: M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE, "Reader type not supported"); return M4VSS3GPP_ERR_INVALID_FILE_TYPE; } pC->m_pReader = pC->m_pReaderGlobalItTable[readerType]; pC->m_pReaderDataIt = pC->m_pReaderDataItTable[readerType]; if( pC->m_pReader == M4OSA_NULL || pC->m_pReaderDataIt == M4OSA_NULL ) { M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE, "Reader type not supported"); M4OSA_TRACE1_0("Reader type not supported"); return M4VSS3GPP_ERR_INVALID_FILE_TYPE; } return M4NO_ERROR; }
/** ************************************************************************ * @brief This function opens the provided URL and returns its context. * If an error occured, the context is set to NULL. * @param core_id: (IN) Core ID of the caller (M4OSA_FILE_READER or M4OSA_FILE_WRITER) * @param context: (OUT) Context of the core file reader * @param url: (IN) URL of the input file * @param fileModeAccess: (IN) File mode access * @return M4NO_ERROR: there is no error * @return M4ERR_PARAMETER: at least one parameter is NULL * @return M4ERR_ALLOC: there is no more memory available * @return M4ERR_NOT_IMPLEMENTED: the URL does not match with the supported * file * @return M4ERR_FILE_NOT_FOUND: the file cannot be found * @return M4ERR_FILE_LOCKED: the file is locked by an other * application/process * @return M4ERR_FILE_BAD_MODE_ACCESS: the file mode access is not correct ************************************************************************ */ M4OSA_ERR M4OSA_fileCommonOpen(M4OSA_UInt16 core_id, M4OSA_Context* pContext, M4OSA_Char* pUrl, M4OSA_FileModeAccess fileModeAccess) { M4OSA_Int32 i = 0; M4OSA_Int32 iMode = 0; M4OSA_Int32 iSize = 0; M4OSA_Int32 iSavePos = 0; M4OSA_Char mode[4] = ""; M4OSA_Char* pReadString = (M4OSA_Char*)"r"; M4OSA_Char* pWriteString = (M4OSA_Char*)"w"; M4OSA_Char* pAppendString = (M4OSA_Char*)"a"; M4OSA_Char* pBinaryString = (M4OSA_Char*)"b"; M4OSA_Char* pPlusString = (M4OSA_Char*)"+"; M4OSA_ERR err = M4NO_ERROR; FILE* pFileHandler = M4OSA_NULL; M4OSA_FileContext *pFileContext = M4OSA_NULL; #ifdef UTF_CONVERSION /*FB: to test the UTF16->UTF8 conversion into Video Artist*/ /*Convert the URL from UTF16 to UTF8*/ M4OSA_Void* tempConversionBuf; M4OSA_UInt32 tempConversionSize = 1000; tempConversionBuf = (M4OSA_Char*)M4OSA_32bitAlignedMalloc(tempConversionSize +1, 0, "conversion buf"); if(tempConversionBuf == M4OSA_NULL) { M4OSA_TRACE1_0("Error when allocating conversion buffer\n"); return M4ERR_PARAMETER; } M4OSA_ToUTF8_OSAL(pUrl, tempConversionBuf, &tempConversionSize); ((M4OSA_Char*)tempConversionBuf)[tempConversionSize ] = '\0'; printf("file open %s\n", tempConversionBuf); #endif /*UTF CONVERSION*/ M4OSA_TRACE3_4("M4OSA_fileCommonOpen\t\tM4OSA_UInt16 %d\tM4OSA_Context* 0x%x\t" "M4OSA_Char* %s\tfileModeAccess %d", core_id, pContext, pUrl, fileModeAccess); M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER, "M4OSA_fileCommonOpen: pContext is M4OSA_NULL"); M4OSA_DEBUG_IF2(M4OSA_NULL == pUrl, M4ERR_PARAMETER, "M4OSA_fileCommonOpen: pUrl is M4OSA_NULL"); M4OSA_DEBUG_IF2(0 == fileModeAccess, M4ERR_PARAMETER, "M4OSA_fileCommonOpen: fileModeAccess is 0"); /* Read mode not set for the reader */ M4OSA_DEBUG_IF1((M4OSA_FILE_READER == core_id) && !(fileModeAccess & M4OSA_kFileRead), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileRead"); /* Read mode not set for the reader */ M4OSA_DEBUG_IF1((M4OSA_FILE_READER == core_id) && !(fileModeAccess & M4OSA_kFileRead), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileRead"); /* M4OSAfileReadOpen cannot be used with Write file mode access */ M4OSA_DEBUG_IF1((M4OSA_FILE_READER == core_id) && (fileModeAccess & M4OSA_kFileWrite), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileWrite"); /* Append and Create flags cannot be used with Read */ M4OSA_DEBUG_IF1((M4OSA_FILE_READER == core_id) && (fileModeAccess & M4OSA_kFileAppend), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileAppend"); M4OSA_DEBUG_IF1((M4OSA_FILE_READER == core_id) && (fileModeAccess & M4OSA_kFileCreate), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileCreate"); /* Write mode not set for the writer */ M4OSA_DEBUG_IF1((M4OSA_FILE_WRITER == core_id) && !(fileModeAccess & M4OSA_kFileWrite), M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: M4OSA_kFileWrite"); /* Create flag necessary for opening file */ if ((fileModeAccess & M4OSA_kFileRead) && (fileModeAccess & M4OSA_kFileWrite)&&(fileModeAccess & M4OSA_kFileCreate)) { strncat((char *)mode, (const char *)pWriteString, (size_t)1); strncat((char *)mode, (const char *)pPlusString, (size_t)1); } else { if(fileModeAccess & M4OSA_kFileAppend) { strncat((char *)mode, (const char *)pAppendString, (size_t)1); } else if(fileModeAccess & M4OSA_kFileRead) { strncat((char *)mode, (const char *)pReadString, (size_t)1); } else if(fileModeAccess & M4OSA_kFileWrite) { strncat((char *)mode, (const char *)pWriteString, (size_t)1); } if((fileModeAccess & M4OSA_kFileRead)&&(fileModeAccess & M4OSA_kFileWrite)) { strncat((char *)mode,(const char *)pPlusString, (size_t)1); } } if(!(fileModeAccess & M4OSA_kFileIsTextMode)) { strncat((char *)mode, (const char *)pBinaryString,(size_t)1); } /*Open the file*/ #ifdef UTF_CONVERSION /*Open the converted path*/ pFileHandler = fopen((const char *)tempConversionBuf, (const char *)mode); /*Free the temporary decoded buffer*/ free(tempConversionBuf); #else /* UTF_CONVERSION */ pFileHandler = fopen((const char *)pUrl, (const char *)mode); #endif /* UTF_CONVERSION */ if (M4OSA_NULL == pFileHandler) { switch(errno) { case ENOENT: { M4OSA_DEBUG(M4ERR_FILE_NOT_FOUND, "M4OSA_fileCommonOpen: No such file or directory"); M4OSA_TRACE1_1("File not found: %s", pUrl); return M4ERR_FILE_NOT_FOUND; } case EACCES: { M4OSA_DEBUG(M4ERR_FILE_LOCKED, "M4OSA_fileCommonOpen: Permission denied"); return M4ERR_FILE_LOCKED; } case EINVAL: { M4OSA_DEBUG(M4ERR_FILE_BAD_MODE_ACCESS, "M4OSA_fileCommonOpen: Invalid Argument"); return M4ERR_FILE_BAD_MODE_ACCESS; } case EMFILE: case ENOSPC: case ENOMEM: { M4OSA_DEBUG(M4ERR_ALLOC, "M4OSA_fileCommonOpen: Too many open files"); return M4ERR_ALLOC; } default: { M4OSA_DEBUG(M4ERR_NOT_IMPLEMENTED, "M4OSA_fileCommonOpen"); return M4ERR_NOT_IMPLEMENTED; } } } /* Allocate the file context */ pFileContext = (M4OSA_FileContext*) M4OSA_32bitAlignedMalloc(sizeof(M4OSA_FileContext), core_id, (M4OSA_Char*)"M4OSA_fileCommonOpen: file context"); if (M4OSA_NULL == pFileContext) { fclose(pFileHandler); M4OSA_DEBUG(M4ERR_ALLOC, "M4OSA_fileCommonOpen"); return M4ERR_ALLOC; } pFileContext->file_desc = pFileHandler; #ifndef ANDROID_DEFAULT_CODE M4OSA_TRACE1_2("open file %s:%x", (char*)pUrl, pFileHandler); #endif pFileContext->access_mode = fileModeAccess; pFileContext->current_seek = SeekNone; pFileContext->b_is_end_of_file = M4OSA_FALSE; /** * Note: Never use this expression "i = (value1 == value2) ? x: y;" * because that doens't compile on other platforms (ADS for example) * Use: if(value1 == value2) * { i= x; ..etc */ pFileContext->coreID_write = 0; pFileContext->coreID_read = 0; pFileContext->m_DescrModeAccess = M4OSA_kDescNoneAccess; if (M4OSA_FILE_READER == core_id) { pFileContext->coreID_read = core_id; pFileContext->m_DescrModeAccess = M4OSA_kDescReadAccess; } else if (M4OSA_FILE_WRITER == core_id) { pFileContext->coreID_write = core_id; pFileContext->m_DescrModeAccess = M4OSA_kDescWriteAccess; } pFileContext->read_position = 0; pFileContext->write_position = 0; /* Allocate the memory to store the URL string */ pFileContext->url_name = (M4OSA_Char*) M4OSA_32bitAlignedMalloc(strlen((const char *)pUrl)+1, core_id, (M4OSA_Char*)"M4OSA_fileCommonOpen: URL name"); if (M4OSA_NULL == pFileContext->url_name) { fclose(pFileHandler); free(pFileContext); M4OSA_DEBUG(M4ERR_ALLOC, "M4OSA_fileCommonOpen"); return M4ERR_ALLOC; } M4OSA_chrNCopy(pFileContext->url_name, pUrl, strlen((const char *)pUrl)+1); /* Get the file name */ err = M4OSA_fileCommonGetFilename(pUrl, &pFileContext->file_name); if(M4NO_ERROR != err) { fclose(pFileHandler); free(pFileContext->url_name); free(pFileContext); M4OSA_DEBUG(err, "M4OSA_fileCommonOpen"); return err; } #ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE M4OSA_semaphoreOpen(&(pFileContext->semaphore_context), 1); /* Allocate the semaphore */ #endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */ #ifdef USE_STAGEFRIGHT_CODECS // Workaround for file system bug on Stingray/Honeycomb where a file re-created will keep // the original file's size filled with 0s. Do not seek to the end to avoid ill effects if(fileModeAccess & M4OSA_kFileAppend) { /* Get the file size */ iSavePos = ftell(pFileHandler); /* 1- Check the first position */ fseek(pFileHandler, 0, SEEK_END); /* 2- Go to the end of the file*/ iSize = ftell(pFileHandler); /* 3- Check the file size */ fseek(pFileHandler, iSavePos, SEEK_SET);/* 4- go to the first position */ } else { iSize = 0; } #else /* USE_STAGEFRIGHT_CODECS */ /* Get the file size */ iSavePos = ftell(pFileHandler); /* 1- Check the first position */ fseek(pFileHandler, 0, SEEK_END); /* 2- Go to the end of the file*/ iSize = ftell(pFileHandler); /* 3- Check the file size */ fseek(pFileHandler, iSavePos, SEEK_SET);/* 4- go to the first position */ #endif /* USE_STAGEFRIGHT_CODECS */ /* Warning possible overflow if the file is higher than 2GBytes */ pFileContext->file_size = iSize; *pContext = pFileContext; return M4NO_ERROR; }
M4OSA_ERR M4OSA_fileReadSeek(M4OSA_Context pContext, M4OSA_FileSeekAccessMode seekMode, M4OSA_FilePosition* pPosition) { M4OSA_FileContext* pFileContext = (M4OSA_FileContext*)pContext; M4OSA_ERR err; M4OSA_TRACE2_2("M4OSA_fileReadSeek : mode = %d pos = %lu", seekMode, (pPosition != M4OSA_NULL) ? (*pPosition) : 0); M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER, "M4OSA_fileReadSeek: pContext is M4OSA_NULL"); M4OSA_DEBUG_IF2(0 == seekMode, M4ERR_PARAMETER, "M4OSA_fileReadSeek: seekMode is 0"); M4OSA_DEBUG_IF2(M4OSA_NULL == pPosition, M4ERR_PARAMETER, "M4OSA_fileReadSeek: pPosition is M4OSA_NULL"); #ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context, M4ERR_BAD_CONTEXT, "M4OSA_fileReadSeek: semaphore_context is M4OSA_NULL"); #endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */ if (M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess) { M4OSA_UInt32 SeekModeOption; /* Go to the desired position */ if (M4OSA_kFileSeekBeginning == seekMode) { SeekModeOption = SEEK_SET; } else if (M4OSA_kFileSeekEnd == seekMode) { SeekModeOption = SEEK_END; } else if (M4OSA_kFileSeekCurrent == seekMode) { SeekModeOption = SEEK_CUR; } else { M4OSA_TRACE1_0("M4OSA_fileReadSeek: END WITH ERROR !!! (CONVERION ERROR FOR THE SEEK MODE)"); return M4ERR_PARAMETER; } /** * Go to the desired position */ err = fseek(pFileContext->file_desc, *pPosition, SeekModeOption); if(err != 0) { /* converts the error to PSW format*/ err=((M4OSA_UInt32)(M4_ERR)<<30)+(((M4OSA_FILE_WRITER)&0x003FFF)<<16)+(M4OSA_Int16)(err); M4OSA_TRACE1_1("M4OSA_FileReadSeek error:%x",err); } else { return M4NO_ERROR; } /* Return without error */ return err; } #ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER); #endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */ if(pFileContext->current_seek != SeekRead) { /* fseek to the last read position */ err = M4OSA_fileCommonSeek(pContext, M4OSA_kFileSeekBeginning, &(pFileContext->read_position)); if(M4OSA_ERR_IS_ERROR(err)) { M4OSA_DEBUG(err, "M4OSA_fileReadData: M4OSA_fileCommonSeek"); #ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE M4OSA_semaphorePost(pFileContext->semaphore_context); #endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */ return err; } pFileContext->current_seek = SeekRead; } err = M4OSA_fileCommonSeek(pContext, seekMode, pPosition); if(M4OSA_ERR_IS_ERROR(err)) { M4OSA_DEBUG(err, "M4OSA_fileReadData: M4OSA_fileCommonSeek"); } else { pFileContext->read_position = *pPosition; } #ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE M4OSA_semaphorePost(pFileContext->semaphore_context); #endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */ return err; }
/** ****************************************************************************** * M4OSA_ERR M4AIR_configure_NV12(M4OSA_Context pContext, M4AIR_Params* pParams) * @brief This function will configure the AIR. * @note It will set the input and output coordinates and sizes, * and indicates if we will proceed in stripe or not. * In case a M4AIR_get in stripe mode was on going, it will cancel this previous * processing and reset the get process. * @param pContext: (IN) Context identifying the instance * @param pParams->m_bOutputStripe:(IN) Stripe mode. * @param pParams->m_inputCoord: (IN) X,Y coordinates of the first valid pixel in input. * @param pParams->m_inputSize: (IN) input ROI size. * @param pParams->m_outputSize: (IN) output size. * @return M4NO_ERROR: there is no error * @return M4ERR_ALLOC: No more memory space to add a new effect. * @return M4ERR_PARAMETER: pContext is M4OSA_NULL (debug only). * @return M4ERR_AIR_FORMAT_NOT_SUPPORTED: the requested input format is not supported. ****************************************************************************** */ M4OSA_ERR M4AIR_configure_NV12(M4OSA_Context pContext, M4AIR_Params* pParams) { M4AIR_InternalContext* pC = (M4AIR_InternalContext*)pContext ; M4OSA_UInt32 i,u32_width_in, u32_width_out, u32_height_in, u32_height_out; M4OSA_UInt32 nb_planes; M4OSA_TRACE1_0("M4AIR_configure_NV12 start"); M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext); if(M4AIR_kNV12P == pC->m_inputFormat) { nb_planes = 2; } else { nb_planes = 3; } /**< Check state */ if((M4AIR_kCreated != pC->m_state)&&(M4AIR_kConfigured != pC->m_state)) { return M4ERR_STATE; } /** Save parameters */ pC->m_params = *pParams; /* Check for the input&output width and height are even */ if(((pC->m_params.m_inputSize.m_height)&0x1) || ((pC->m_params.m_outputSize.m_height)&0x1)) { return M4ERR_AIR_ILLEGAL_FRAME_SIZE; } if(((pC->m_params.m_inputSize.m_width)&0x1)|| ((pC->m_params.m_outputSize.m_width)&0x1)) { return M4ERR_AIR_ILLEGAL_FRAME_SIZE; } if(((pC->m_params.m_inputSize.m_width) == (pC->m_params.m_outputSize.m_width)) &&((pC->m_params.m_inputSize.m_height) == (pC->m_params.m_outputSize.m_height))) { /**< No resize in this case, we will just copy input in output */ pC->m_bOnlyCopy = M4OSA_TRUE; } else { pC->m_bOnlyCopy = M4OSA_FALSE; /**< Initialize internal variables used for resize filter */ for(i=0;i<nb_planes;i++) { M4OSA_TRACE1_1("Plane %d", i); u32_width_in = pC->m_params.m_inputSize.m_width; u32_height_in = ((i==0)||(i==2))?pC->m_params.m_inputSize.m_height:\ (pC->m_params.m_inputSize.m_height+1)>>1; u32_width_out = pC->m_params.m_outputSize.m_width; u32_height_out = ((i==0)||(i==2))?pC->m_params.m_outputSize.m_height:\ (pC->m_params.m_outputSize.m_height+1)>>1; M4OSA_TRACE1_4("u32_width_in =%d, u32_height_in = %d, u32_width_out = %d, u32_height_out = %d",\ u32_width_in, u32_height_in, u32_width_out, u32_height_out); /* Compute horizontal ratio between src and destination width.*/ if (u32_width_out >= u32_width_in) { if (i == 1) { pC->u32_x_inc[i] = ((u32_width_in-2) * 0x10000) / (u32_width_out-2); } else { pC->u32_x_inc[i] = ((u32_width_in-1) * 0x10000) / (u32_width_out-1); } } else { pC->u32_x_inc[i] = (u32_width_in * 0x10000) / (u32_width_out); } /* Compute vertical ratio between src and destination height.*/ if (u32_height_out >= u32_height_in) { pC->u32_y_inc[i] = ((u32_height_in - 1) * 0x10000) / (u32_height_out-1); } else { pC->u32_y_inc[i] = (u32_height_in * 0x10000) / (u32_height_out); } /* Calculate initial accumulator value : u32_y_accum_start. u32_y_accum_start is coded on 15 bits, and represents a value between 0 and 0.5 */ if (pC->u32_y_inc[i] >= 0x10000) { /* Keep the fractionnal part, assimung that integer part is coded on the 16 high bits and the fractionnal on the 15 low bits */ pC->u32_y_accum_start[i] = pC->u32_y_inc[i] & 0xffff; if (!pC->u32_y_accum_start[i]) { pC->u32_y_accum_start[i] = 0x10000; } pC->u32_y_accum_start[i] >>= 1; } else { pC->u32_y_accum_start[i] = 0; } /**< Take into account that Y coordinate can be odd in this case we have to put a 0.5 offset for U and V plane as there a 2 times sub-sampled vs Y*/ if((pC->m_params.m_inputCoord.m_y&0x1)&&(i==1)) { pC->u32_y_accum_start[i] += 0x8000; } /* Calculate initial accumulator value : u32_x_accum_start. u32_x_accum_start is coded on 15 bits, and represents a value between 0 and 0.5 */ if (pC->u32_x_inc[i] >= 0x10000) { pC->u32_x_accum_start[i] = pC->u32_x_inc[i] & 0xffff; if (!pC->u32_x_accum_start[i]) { pC->u32_x_accum_start[i] = 0x10000; } pC->u32_x_accum_start[i] >>= 1; }