int PreviewStream::freeBuffers() { status_t ret = NO_ERROR; GraphicBufferMapper& mapper = GraphicBufferMapper::get(); // Give the buffers back to display here - sort of free it if (mNativeWindow) { for (int i = 0; i < mTotalBuffers; i++) { mapper.unlock(mCameraBuffer[i].mBufHandle); ret = mNativeWindow->cancel_buffer(mNativeWindow, &mCameraBuffer[i].mBufHandle); if (ENODEV == ret) { FLOGE("Preview surface abandoned!"); mNativeWindow = NULL; return -ret; } else if (NO_ERROR != ret) { FLOGE("cancel_buffer() failed: %s (%d)", strerror(-ret), -ret); return -ret; } } } else { FLOGE("mNativeWindow is NULL"); } // /Clear the frames with camera adapter map dispatchBuffers(NULL, 0, BUFFER_DESTROY); return ret; }
bool FileUtils::mzExtractFile(unzFile uf, const std::string &directory) { unz_file_info64 fi; std::string filename; if (!mzGetInfo(uf, &fi, &filename)) { return false; } std::string fullPath(directory); fullPath += "/"; fullPath += filename; std::string parentPath = io::dirName(fullPath); if (!io::createDirectories(parentPath)) { FLOGW("%s: Failed to create directory: %s", parentPath.c_str(), io::lastErrorString().c_str()); } io::File file; if (!file.open(fullPath, io::File::OpenWrite)) { FLOGE("%s: Failed to open for writing: %s", fullPath.c_str(), file.errorString().c_str()); return false; } int ret = unzOpenCurrentFile(uf); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to open inner file: %s", mzUnzErrorString(ret).c_str()); return false; } int n; char buf[32768]; uint64_t bytesWritten; while ((n = unzReadCurrentFile(uf, buf, sizeof(buf))) > 0) { if (!file.write(buf, n, &bytesWritten)) { FLOGE("%s: Failed to write file: %s", fullPath.c_str(), file.errorString().c_str()); unzCloseCurrentFile(uf); return false; } } if (n != 0) { FLOGE("miniunz: Finished before reaching inner file's EOF: %s", mzUnzErrorString(n).c_str()); } ret = unzCloseCurrentFile(uf); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to close inner file: %s", mzUnzErrorString(ret).c_str()); return false; } return n == 0; }
/*! \brief Read contents of a file into memory \param path Path to file \param contents Output vector (not modified unless reading succeeds) \return Success or not */ ErrorCode FileUtils::readToMemory(const std::string &path, std::vector<unsigned char> *contents) { io::File file; if (!file.open(path, io::File::OpenRead)) { FLOGE("%s: Failed to open for reading: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileOpenError; } uint64_t size; file.seek(0, io::File::SeekEnd); file.tell(&size); file.seek(0, io::File::SeekBegin); std::vector<unsigned char> data(size); uint64_t bytesRead; if (!file.read(data.data(), data.size(), &bytesRead) || bytesRead != size) { FLOGE("%s: Failed to read file: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileReadError; } data.swap(*contents); return ErrorCode::NoError; }
/*! \brief Read contents of a file into a string \param path Path to file \param contents Output string (not modified unless reading succeeds) \return Success or not */ ErrorCode FileUtils::readToString(const std::string &path, std::string *contents) { io::File file; if (!file.open(path, io::File::OpenRead)) { FLOGE("%s: Failed to open for reading: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileOpenError; } uint64_t size; file.seek(0, io::File::SeekEnd); file.tell(&size); file.seek(0, io::File::SeekBegin); std::string data; data.resize(size); uint64_t bytesRead; if (!file.read(&data[0], size, &bytesRead) || bytesRead != size) { FLOGE("%s: Failed to read file: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileReadError; } data.swap(*contents); return ErrorCode::NoError; }
int ExtractAssets( struct android_app* state , const char* packageDir ) { AAssetManager* assetManager = state->activity->assetManager; LOGI( "Checking for assets to extract" ); // First extract the index file which tells us which other files to extract char* extractionIndexfilePath = GetAssetPath( packageDir, "filestoextract.txt" ); int retValue = ExtractAsset( assetManager, "filestoextract.txt", extractionIndexfilePath ); if ( 0 != retValue ) { LOGI( "Found index of assets to extract" ); // Now go trough the list extraction all files listed. // each line in the index file is a file to extract char entryBuffer[ PATH_MAX ]; FILE* listFptr = fopen( extractionIndexfilePath, "r" ); char* bufferPtr = 0; if ( NULL == listFptr ) { // Abort, unable to open the file FLOGE( "Error %i when opening file %s", errno, extractionIndexfilePath ); free( extractionIndexfilePath ); return 0; } do { // Read the entry bufferPtr = ReadString( listFptr, entryBuffer, PATH_MAX ); if ( NULL != bufferPtr ) { // Create destination path and extract the asset char* destPath = GetAssetPath( packageDir, bufferPtr ); retValue = ExtractAsset( assetManager, entryBuffer, destPath ); if ( 0 == retValue ) { // Failed to extract the current entry, abort FLOGE( "Failed to extract asset to %s", destPath ); free( destPath ); fclose( listFptr ); free( extractionIndexfilePath ); return 0; } free( destPath ); } } while ( NULL != bufferPtr ); fclose( listFptr ); } else { LOGI( "No extraction index is available, no assets will be extracted" ); } free( extractionIndexfilePath ); return 1; }
int PreviewStream::configure(int fps, bool /*videoSnapshot*/) { FLOG_TRACE("PreviewStream %s running", __FUNCTION__); int ret = NO_ERROR; int errCode = 0; fAssert(mDeviceAdapter.get() != NULL); ret = mDeviceAdapter->setDeviceConfig(mWidth, mHeight, mFormat, fps); if (ret != NO_ERROR) { FLOGE("%s setDeviceConfig failed", __FUNCTION__); errCode = CAMERA2_MSG_ERROR_DEVICE; goto fail; } mDeviceAdapter->setCameraBufferProvide(this); ret = allocateBuffers(mWidth, mHeight, mFormat, mMaxProducerBuffers); if (ret != NO_ERROR) { FLOGE("%s allocateBuffers failed", __FUNCTION__); errCode = CAMERA2_MSG_ERROR_REQUEST; goto fail; } mPrepared = true; return NO_ERROR; fail: freeBuffers(); FLOGE("Error occurred, performing cleanup"); if (NULL != mErrorListener) { mErrorListener->handleError(errCode); } return BAD_VALUE; }
/*! * \brief Constructs boot image and writes it to a file * * This is a convenience function that calls BootImage::create() and writes the * data to the specified file. * * \return Whether the file was successfully written * * \sa BootImage::create() */ bool BootImage::createFile(const std::string &path) { io::File file; if (!file.open(path, io::File::OpenWrite)) { FLOGE("%s: Failed to open for writing: %s", path.c_str(), file.errorString().c_str()); m_impl->error = ErrorCode::FileOpenError; return false; } std::vector<unsigned char> data; if (!create(&data)) { return false; } uint64_t bytesWritten; if (!file.write(data.data(), data.size(), &bytesWritten)) { FLOGE("%s: Failed to write file: %s", path.c_str(), file.errorString().c_str()); m_impl->error = ErrorCode::FileWriteError; return false; } return true; }
bool FileUtils::mzGetInfo(unzFile uf, unz_file_info64 *fi, std::string *filename) { unz_file_info64 info; memset(&info, 0, sizeof(info)); // First query to get filename size int ret = unzGetCurrentFileInfo64( uf, // file &info, // pfile_info nullptr, // filename 0, // filename_size nullptr, // extrafield 0, // extrafield_size nullptr, // comment 0 // comment_size ); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to get inner file metadata: %s", mzUnzErrorString(ret).c_str()); return false; } if (filename) { std::vector<char> buf(info.size_filename + 1); ret = unzGetCurrentFileInfo64( uf, // file &info, // pfile_info buf.data(), // filename buf.size(), // filename_size nullptr, // extrafield 0, // extrafield_size nullptr, // comment 0 // comment_size ); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to get inner filename: %s", mzUnzErrorString(ret).c_str()); return false; } *filename = buf.data(); } if (fi) { *fi = info; } return true; }
ErrorCode FileUtils::mzArchiveStats(const std::string &path, FileUtils::ArchiveStats *stats, std::vector<std::string> ignore) { assert(stats != nullptr); MzUnzCtx *ctx = mzOpenInputFile(path); if (!ctx) { FLOGE("miniunz: Failed to open for reading: %s", path.c_str()); return ErrorCode::ArchiveReadOpenError; } uint64_t count = 0; uint64_t totalSize = 0; std::string name; unz_file_info64 fi; memset(&fi, 0, sizeof(fi)); int ret = unzGoToFirstFile(ctx->uf); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to move to first file: %s", mzUnzErrorString(ret).c_str()); mzCloseInputFile(ctx); return ErrorCode::ArchiveReadHeaderError; } do { if (!mzGetInfo(ctx->uf, &fi, &name)) { mzCloseInputFile(ctx); return ErrorCode::ArchiveReadHeaderError; } if (std::find(ignore.begin(), ignore.end(), name) == ignore.end()) { ++count; totalSize += fi.uncompressed_size; } } while ((ret = unzGoToNextFile(ctx->uf)) == UNZ_OK); if (ret != UNZ_END_OF_LIST_OF_FILE) { FLOGE("miniunz: Finished before EOF: %s", mzUnzErrorString(ret).c_str()); mzCloseInputFile(ctx); return ErrorCode::ArchiveReadHeaderError; } mzCloseInputFile(ctx); stats->files = count; stats->totalSize = totalSize; return ErrorCode::NoError; }
bool AndroidFormat::loadHeader(const unsigned char *data, std::size_t size, const std::size_t headerIndex) { // Make sure the file is large enough to contain the header if (size < headerIndex + sizeof(BootImageHeader)) { FLOGE("Boot image header exceeds size by %" PRIzu " bytes", headerIndex + sizeof(BootImageHeader) - size); return false; } // Read the Android boot image header auto hdr = reinterpret_cast<const BootImageHeader *>(&data[headerIndex]); // Read the page size switch (hdr->page_size) { case 2048: case 4096: case 8192: case 16384: case 32768: case 65536: case 131072: break; default: FLOGE("Invalid page size: %u", hdr->page_size); return false; } dumpHeader(hdr); // Save header fields mI10e->kernelAddr = hdr->kernel_addr; mI10e->ramdiskAddr = hdr->ramdisk_addr; mI10e->secondAddr = hdr->second_addr; mI10e->tagsAddr = hdr->tags_addr; mI10e->pageSize = hdr->page_size; mI10e->boardName = StringUtils::toMaxString( reinterpret_cast<const char *>(hdr->name), BOOT_NAME_SIZE); mI10e->cmdline = StringUtils::toMaxString( reinterpret_cast<const char *>(hdr->cmdline), BOOT_ARGS_SIZE); // Raw header fields mI10e->hdrKernelSize = hdr->kernel_size; mI10e->hdrRamdiskSize = hdr->ramdisk_size; mI10e->hdrSecondSize = hdr->second_size; mI10e->hdrDtSize = hdr->dt_size; mI10e->hdrUnused = hdr->unused; for (std::size_t i = 0; i < sizeof(hdr->id) / sizeof(hdr->id[0]); ++i) { mI10e->hdrId[i] = hdr->id[i]; } return true; }
static bool mzGetFileTime(const std::string &filename, tm_zip *tmzip, uLong *dostime) { // Don't fail when building with -Werror (void) filename; (void) tmzip; (void) dostime; #ifdef _WIN32 FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAW ff32; std::wstring wFilename = utf8::utf8ToUtf16(filename); hFind = FindFirstFileW(wFilename.c_str(), &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&ff32.ftLastWriteTime, &ftLocal); FileTimeToDosDateTime(&ftLocal, ((LPWORD) dostime) + 1, ((LPWORD) dostime) + 0); FindClose(hFind); return true; } else { FLOGE("%s: FindFirstFileW() failed: %s", filename.c_str(), win32ErrorToString(GetLastError()).c_str()); } #elif defined unix || defined __APPLE__ || defined __ANDROID__ struct stat sb; struct tm t; if (stat(filename.c_str(), &sb) == 0) { time_t mtime = sb.st_mtime; if (!localtime_r(&mtime, &t)) { LOGE("localtime() failed"); return false; } tmzip->tm_sec = t.tm_sec; tmzip->tm_min = t.tm_min; tmzip->tm_hour = t.tm_hour; tmzip->tm_mday = t.tm_mday; tmzip->tm_mon = t.tm_mon ; tmzip->tm_year = t.tm_year; return true; } else { FLOGE("%s: stat() failed: %s", filename.c_str(), strerror(errno)); } #endif return false; }
ErrorCode FileUtils::mzAddFile(zipFile zf, const std::string &name, const std::vector<unsigned char> &contents) { // Obviously never true, but we'll keep it here just in case bool zip64 = (uint64_t) contents.size() >= ((1ull << 32) - 1); zip_fileinfo zi; memset(&zi, 0, sizeof(zi)); int ret = zipOpenNewFileInZip2_64( zf, // file name.c_str(), // filename &zi, // zip_fileinfo nullptr, // extrafield_local 0, // size_extrafield_local nullptr, // extrafield_global 0, // size_extrafield_global nullptr, // comment Z_DEFLATED, // method Z_DEFAULT_COMPRESSION, // level 0, // raw zip64 // zip64 ); if (ret != ZIP_OK) { FLOGE("minizip: Failed to open inner file: %s", mzZipErrorString(ret).c_str()); return ErrorCode::ArchiveWriteDataError; } // Write data to file ret = zipWriteInFileInZip(zf, contents.data(), contents.size()); if (ret != ZIP_OK) { FLOGE("minizip: Failed to write inner file data: %s", mzZipErrorString(ret).c_str()); zipCloseFileInZip(zf); return ErrorCode::ArchiveWriteDataError; } ret = zipCloseFileInZip(zf); if (ret != ZIP_OK) { FLOGE("minizip: Failed to close inner file: %s", mzZipErrorString(ret).c_str()); return ErrorCode::ArchiveWriteDataError; } return ErrorCode::NoError; }
int ExtractAsset( AAssetManager* assetManager , const char* assetPath , const char* destPath ) { AAsset* asset = AAssetManager_open( assetManager, assetPath, AASSET_MODE_BUFFER ); if ( NULL == asset ) { FLOGE( "Unable to open asset for extraction: %s", assetPath ); return 0; } FLOGI( "Extracting asset: %s", assetPath ); const void* fileBuffer = AAsset_getBuffer( asset ); if ( NULL == fileBuffer ) { AAsset_close( asset ); FLOGE( "Unable to get buffer to asset for extraction: %s", assetPath ); return 0; } off_t bufferSize = AAsset_getLength( asset ); // Make sure the directories exist to put the file in if ( 0 == MakeFileDir( destPath, 00777 ) ) { AAsset_close( asset ); FLOGE( "Unable to make directories for asset extraction: %s", destPath ); return 0; } FILE* destFile = fopen( destPath, "wb" ); if ( NULL == destFile ) { AAsset_close( asset ); FLOGE( "Unable to open destination file for asset: %s", destPath ); return 0; } if ( 1 != fwrite( fileBuffer, bufferSize, 1, destFile ) ) { FLOGE( "Error extracting asset from %s to %s", assetPath, destPath ); fclose( destFile ); AAsset_close( asset ); return 0; } fclose( destFile ); AAsset_close( asset ); FLOGI( "Extracted asset from %s to %s", assetPath, destPath ); return 1; }
bool FileUtils::mzReadToMemory(unzFile uf, std::vector<unsigned char> *output, void (*cb)(uint64_t bytes, void *), void *userData) { unz_file_info64 fi; if (!mzGetInfo(uf, &fi, nullptr)) { return false; } std::vector<unsigned char> data; data.reserve(fi.uncompressed_size); int ret = unzOpenCurrentFile(uf); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to open inner file: %s", mzUnzErrorString(ret).c_str()); return false; } int n; char buf[32768]; while ((n = unzReadCurrentFile(uf, buf, sizeof(buf))) > 0) { if (cb) { cb(data.size() + n, userData); } data.insert(data.end(), buf, buf + n); } if (n != 0) { FLOGE("miniunz: Finished before reaching inner file's EOF: %s", mzUnzErrorString(n).c_str()); } ret = unzCloseCurrentFile(uf); if (ret != UNZ_OK) { FLOGE("miniunz: Failed to close inner file: %s", mzUnzErrorString(ret).c_str()); return false; } if (n != 0) { return false; } data.swap(*output); return true; }
status_t TVINDevice::setSupportedPreviewFormats(int *sfmt, int slen, int *dfmt, int dlen) { if ((sfmt == NULL) || (slen == 0) || (dfmt == NULL) || (dlen == 0)) { FLOGE("setSupportedPreviewFormats invalid parameters"); return BAD_VALUE; } char fmtStr[FORMAT_STRING_LEN]; memset(fmtStr, 0, FORMAT_STRING_LEN); for (int i = 0; i < slen; i++) { for (int j = 0; j < dlen; j++) { // should report VPU support format. if (sfmt[i] == dfmt[j]) { if (sfmt[i] == v4l2_fourcc('Y', 'U', '1', '2')) { strcat(fmtStr, "yuv420p"); strcat(fmtStr, ","); } else if (sfmt[i] == v4l2_fourcc('N', 'V', '1', '2')) { strcat(fmtStr, "yuv420sp"); strcat(fmtStr, ","); } else if (sfmt[i] == v4l2_fourcc('Y', 'U', 'Y', 'V')) { strcat(fmtStr, "yuv422i-yuyv"); strcat(fmtStr, ","); } } } } mParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, fmtStr); return NO_ERROR; }
int convertPixelFormatToV4L2Format(PixelFormat format) { int nFormat = 0; switch (format) { case HAL_PIXEL_FORMAT_YCbCr_420_SP: case HAL_PIXEL_FORMAT_YCrCb_420_SP: nFormat = v4l2_fourcc('N', 'V', '1', '2'); break; case HAL_PIXEL_FORMAT_YCbCr_420_P: nFormat = v4l2_fourcc('Y', 'U', '1', '2'); break; case HAL_PIXEL_FORMAT_YCbCr_422_I: nFormat = v4l2_fourcc('Y', 'U', 'Y', 'V'); break; default: FLOGE("Error: format:0x%x not supported!", format); break; } FLOGI("pixel format: 0x%x", nFormat); return nFormat; }
int PreviewStream::registerBuffers(int num_buffers, buffer_handle_t *buffers) { if (buffers == NULL || num_buffers > MAX_PREVIEW_BUFFER) { FLOGE("%s buffer num %d too large", __FUNCTION__, num_buffers); return BAD_VALUE; } mTotalBuffers = num_buffers; FLOGI("%s total %d buffer", __FUNCTION__, num_buffers); GraphicBufferMapper& mapper = GraphicBufferMapper::get(); Rect bounds; memset(mCameraBuffer, 0, sizeof(mCameraBuffer)); bounds.left = 0; bounds.top = 0; bounds.right = mWidth; bounds.bottom = mHeight; void *pVaddr = NULL; for (int i=0; i < num_buffers; i++) { mapper.lock(buffers[i], mUsage, bounds, &pVaddr); mCameraBuffer[i].initialize(buffers[i], i); mCameraBuffer[i].mWidth = mWidth; mCameraBuffer[i].mHeight = mHeight; mCameraBuffer[i].mFormat = mFormat; mCameraBuffer[i].setState(CameraFrame::BUFS_IN_SERVICE); } return 0; }
PixelFormat TVINDevice::getMatchFormat(int *sfmt, int slen, int *dfmt, int dlen) { if ((sfmt == NULL) || (slen == 0) || (dfmt == NULL) || (dlen == 0)) { FLOGE("setSupportedPreviewFormats invalid parameters"); return 0; } PixelFormat matchFormat = 0; bool live = true; for (int i = 0; i < slen && live; i++) { for (int j = 0; j < dlen; j++) { FLOG_RUNTIME("sfmt[%d]=%c%c%c%c, dfmt[%d]=%c%c%c%c", i, sfmt[i] & 0xFF, (sfmt[i] >> 8) & 0xFF, (sfmt[i] >> 16) & 0xFF, (sfmt[i] >> 24) & 0xFF, j, dfmt[j] & 0xFF, (dfmt[j] >> 8) & 0xFF, (dfmt[j] >> 16) & 0xFF, (dfmt[j] >> 24) & 0xFF); if (sfmt[i] == dfmt[j]) { matchFormat = convertV4L2FormatToPixelFormat(dfmt[j]); live = false; break; } } } return matchFormat; }
ErrorCode FileUtils::writeFromString(const std::string &path, const std::string &contents) { io::File file; if (!file.open(path, io::File::OpenWrite)) { FLOGE("%s: Failed to open for writing: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileOpenError; } uint64_t bytesWritten; if (!file.write(contents.data(), contents.size(), &bytesWritten)) { FLOGE("%s: Failed to write file: %s", path.c_str(), file.errorString().c_str()); return ErrorCode::FileWriteError; } return ErrorCode::NoError; }
PatcherError FileUtils::mzArchiveStats(const std::string &path, FileUtils::ArchiveStats *stats, std::vector<std::string> ignore) { assert(stats != nullptr); unzFile uf = mzOpenInputFile(path); if (!uf) { FLOGE("minizip: Failed to open for reading: {}", path); return PatcherError::createArchiveError( ErrorCode::ArchiveReadOpenError, path); } uint64_t count = 0; uint64_t totalSize = 0; std::string name; unz_file_info64 fi; memset(&fi, 0, sizeof(fi)); int ret = unzGoToFirstFile(uf); if (ret != UNZ_OK) { mzCloseInputFile(uf); return PatcherError::createArchiveError( ErrorCode::ArchiveReadHeaderError, std::string()); } do { if (!mzGetInfo(uf, &fi, &name)) { mzCloseInputFile(uf); return PatcherError::createArchiveError( ErrorCode::ArchiveReadHeaderError, std::string()); } if (std::find(ignore.begin(), ignore.end(), name) == ignore.end()) { ++count; totalSize += fi.uncompressed_size; } } while ((ret = unzGoToNextFile(uf)) == UNZ_OK); if (ret != UNZ_END_OF_LIST_OF_FILE) { mzCloseInputFile(uf); return PatcherError::createArchiveError( ErrorCode::ArchiveReadHeaderError, std::string()); } mzCloseInputFile(uf); stats->files = count; stats->totalSize = totalSize; return PatcherError(); }
int PreviewStream::start() { FLOG_TRACE("PreviewStream %s running", __FUNCTION__); int ret = 0; StreamAdapter::start(); fAssert(mDeviceAdapter.get() != NULL); ret = mDeviceAdapter->startPreview(); if (ret != NO_ERROR) { FLOGE("Couldn't start preview for DeviceAdapter"); return ret; } return NO_ERROR; }
bool MultiBootPatcher::Impl::openInputArchive() { assert(zInput == nullptr); zInput = FileUtils::mzOpenInputFile(info->filename()); if (!zInput) { FLOGE("minizip: Failed to open for reading: {}", info->filename()); error = PatcherError::createArchiveError( ErrorCode::ArchiveReadOpenError, info->filename()); return false; } return true; }
int PreviewStream::processFrame(CameraFrame *frame) { status_t ret = NO_ERROR; if (mShowFps) { showFps(); } ret = renderBuffer(frame); if (ret != NO_ERROR) { FLOGE("%s renderBuffer failed, state %d", __FUNCTION__, frame->getState()); goto err_exit; } //the frame held in service. frame->addReference(); StreamBuffer buffer; ret = requestBuffer(&buffer); if (ret != NO_ERROR) { FLOGE("%s requestBuffer failed", __FUNCTION__); goto err_exit; } for (int i = 0; i < mTotalBuffers; i++) { if (mCameraBuffer[i].mBufHandle == buffer.mBufHandle) { //release frame from service. mCameraBuffer[i].release(); break; } } err_exit: sem_post(&mRespondSem); return ret; }
bool MultiBootPatcher::Impl::openOutputArchive() { assert(zOutput == nullptr); const std::string newPath = m_parent->newFilePath(); zOutput = FileUtils::mzOpenOutputFile(newPath); if (!zOutput) { FLOGE("minizip: Failed to open for writing: {}", newPath); error = PatcherError::createArchiveError( ErrorCode::ArchiveWriteOpenError, newPath); return false; } return true; }
int PreviewStream::getBufferIdx(buffer_handle_t *buf) { if (buf == NULL) { FLOGE("%s invalid param", __FUNCTION__); return -1; } int index = -1; for (int i=0; i < mTotalBuffers; i++) { if (mCameraBuffer[i].mBufHandle == *buf) { index = i; break; } } return index; }
bool PatchFilePatcher::patchFiles(const std::string &directory) { #if defined(__ANDROID__) std::string patch = m_impl->pc->dataDirectory(); patch += "/binaries/android/"; patch += m_impl->info->device()->architecture(); patch += "/patch"; chmod(patch.c_str(), 0755); #elif defined(_WIN32) std::string patch = m_impl->pc->dataDirectory(); patch += "/binaries/windows/hctap.exe"; #else std::string patch = "patch"; #endif std::vector<std::string> args; args.push_back("--no-backup-if-mismatch"); args.push_back("-p1"); args.push_back("-i"); args.push_back(m_impl->patchFile); args.push_back("-d"); args.push_back(directory); std::string output; int exitCode = -1; std::vector<std::string> lines; bool error = !m_impl->runProcess(patch, args, &output, &exitCode) || exitCode != 0; boost::split(lines, output, boost::is_any_of("\n")); for (auto &line : lines) { FLOGE("patch output: {}", line); } if (error) { m_impl->error = PatcherError::createPatchingError( ErrorCode::ApplyPatchFileError); return false; } else { return true; } }
int PhysMemAdapter::freeBuffer() { if (mIonFd <= 0) { FLOGE("try to free buffer from ion in preview or ion invalid"); return BAD_VALUE; } FLOGI("freeBufferToIon buffer num:%d", mBufferCount); for (int i = 0; i < mBufferCount; i++) { struct ion_handle *ionHandle = (struct ion_handle *)mCameraBuffer[i].mBufHandle; ion_free(mIonFd, ionHandle); munmap(mCameraBuffer[i].mVirtAddr, mCameraBuffer[i].mSize); } memset(mCameraBuffer, 0, sizeof(mCameraBuffer)); dispatchBuffers(NULL, 0, BUFFER_DESTROY); return NO_ERROR; }
int convertStringToV4L2Format(const char *pFormat) { if (pFormat == NULL) { return 0; } if (!strcmp(pFormat, "yuv420p")) { return v4l2_fourcc('Y', 'U', '1', '2'); } else if (!strcmp(pFormat, "yuv420sp")) { return v4l2_fourcc('N', 'V', '1', '2'); } else if (!strcmp(pFormat, "yuv422i-yuyv")) { return v4l2_fourcc('Y', 'U', 'Y', 'V'); } else { FLOGE("format %s is not supported", pFormat); return BAD_VALUE; } }
int convertStringToPixelFormat(const char *pFormat) { if (pFormat == NULL) { return 0; } if (!strcmp(pFormat, "yuv420p")) { return HAL_PIXEL_FORMAT_YCbCr_420_P; } else if (!strcmp(pFormat, "yuv420sp")) { return HAL_PIXEL_FORMAT_YCbCr_420_SP; } else if (!strcmp(pFormat, "yuv422i-yuyv")) { return HAL_PIXEL_FORMAT_YCbCr_422_I; } else { FLOGE("format %s is not supported", pFormat); return BAD_VALUE; } }
status_t TVINDevice::setPreviewStringFormat(PixelFormat format) { const char *pformat = NULL; if (format == HAL_PIXEL_FORMAT_YCbCr_420_P) { pformat = "yuv420p"; } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP) { pformat = "yuv420sp"; } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) { pformat = "yuv422i-yuyv"; } else { FLOGE("format %d is not supported", format); return BAD_VALUE; } ALOGI("setPreviewFormat: %s", pformat); mParams.setPreviewFormat(pformat); mParams.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT, pformat); return NO_ERROR; }