bool Simulation::setup(const GLuint windowWidth, const GLuint windowHeight, const GLuint viewportWidth, const GLuint viewportHeight, AssetLoader& assetLoader) { setup_rand(); this->windowWidth = windowWidth; this->windowHeight = windowHeight; this->viewportWidth = viewportWidth; this->viewportHeight = viewportHeight; const char VertexShaderCode[] = "attribute vec4 a_position; \n" "attribute lowp vec4 a_color; \n" "varying lowp vec4 v_color; \n" " \n" "void main() { \n" " gl_Position = a_position; \n" " v_color = a_color; \n" "} \n"; const char FragmentShaderCode[] = "precision mediump float; \n" "varying lowp vec4 v_color; \n" "void main() { \n" " gl_FragColor = v_color; \n" "} \n"; program = createProgram(VertexShaderCode, FragmentShaderCode); if(!program) { LOGE("Could not create program."); return false; } // Load shader attribute locations positionAttribute = glGetAttribLocation(program, "a_position"); checkGlError("glGetAttribLocation"); LOGI("glGetAttribLocation(\"a_position\") = %d\n", positionAttribute); colorAttribute = glGetAttribLocation(program, "a_color"); checkGlError("glGetAttribLocation"); LOGI("glGetAttribLocation(\"a_color\") = %d\n", colorAttribute); // Load triangle currentBuffer glGenBuffers(1, &vboId); checkGlError("glGenBuffers"); glBindBuffer(GL_ARRAY_BUFFER, vboId); checkGlError("glBindBuffer"); // Set the currentBuffer's data glBufferData(GL_ARRAY_BUFFER, Constants::MaximumVertexCount * sizeof(ColorVertex), ¤tVertices[0], GL_DYNAMIC_DRAW); checkGlError("glBufferData"); // Create image buffers const int BufferSize = viewportWidth*viewportHeight*4; /* RGBA format*/ currentBuffer = new unsigned char[BufferSize]; std::fill_n(currentBuffer, BufferSize, 0); targetBuffer = new unsigned char[BufferSize]; std::fill_n(targetBuffer, BufferSize, 0); if(!create_render_target()) { LOGE("Could not create render target!"); return false; } LOGW("Integer Sizes: %d %d", sizeof(unsigned long), sizeof(unsigned long)); LOGI("Success engine_init_display"); if(!load_content(assetLoader)) { LOGE("Could not load content!"); return false; } create_random_triangles(); copy_current_to_best_triangles(); LOGI("Simulation is ready to go."); return true; }
void WiEngineApp::createWindow() { WNDCLASS wc; DWORD flags = 0; DWORD exFlags = 0; ATOM atom; // Grab the window class we have registered on constructor atom = GetClassInfo(m_module, _T("WiEngine"), &wc); if(!atom) { LOGW("WiEngineApp::createWindow: No window class info found, register window class failed?"); return; } // basic flags flags = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; // if has menu if(m_hasMenu) { flags |= WS_POPUP; exFlags |= WS_EX_TOOLWINDOW; } // check border if(!m_borderless) { flags |= WS_OVERLAPPEDWINDOW; } // check resizable if(m_resizable) { flags |= WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; } else { flags ^= WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; } // windows rect wyScreenConfig& sc = wyDirector::getScreenConfig(); wyRect winRect = wyr((m_desktopWidth - sc.winWidth) / 2, (m_desktopHeight - sc.winHeight) / 2, sc.winWidth, sc.winHeight); computeWindowRectFromClientArea(flags, &winRect); // create window m_hWnd = CreateWindowEx( exFlags, _T("WiEngine"), m_title, flags, winRect.x, winRect.y, winRect.width, winRect.height, NULL, NULL, m_module, NULL); if(!m_hWnd) { LOGE("WiEngineApp::createWindow: failed to create window"); return; } // Need to set requested style again, apparently Windows doesn't listen when requesting windows without title bar or borders SetWindowLong(m_hWnd, GWL_STYLE, flags); SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); // Make a menu window always on top if(m_hasMenu) { SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } }
/* * "buf" contains a full JDWP packet, possibly with multiple chunks. We * need to process each, accumulate the replies, and ship the whole thing * back. * * Returns "true" if we have a reply. The reply buffer is newly allocated, * and includes the chunk type/length, followed by the data. * * TODO: we currently assume that the request and reply include a single * chunk. If this becomes inconvenient we will need to adapt. */ bool dvmDdmHandlePacket(const u1* buf, int dataLen, u1** pReplyBuf, int* pReplyLen) { Thread* self = dvmThreadSelf(); const int kChunkHdrLen = 8; ArrayObject* dataArray = NULL; bool result = false; assert(dataLen >= 0); /* * Prep DdmServer. We could throw this in gDvm. */ ClassObject* ddmServerClass; Method* dispatch; ddmServerClass = dvmFindClass("Lorg/apache/harmony/dalvik/ddmc/DdmServer;", NULL); if (ddmServerClass == NULL) { LOGW("Unable to find org.apache.harmony.dalvik.ddmc.DdmServer\n"); goto bail; } dispatch = dvmFindDirectMethodByDescriptor(ddmServerClass, "dispatch", "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;"); if (dispatch == NULL) { LOGW("Unable to find DdmServer.dispatch\n"); goto bail; } /* * Prep Chunk. */ int chunkTypeOff, chunkDataOff, chunkOffsetOff, chunkLengthOff; ClassObject* chunkClass; chunkClass = dvmFindClass("Lorg/apache/harmony/dalvik/ddmc/Chunk;", NULL); if (chunkClass == NULL) { LOGW("Unable to find org.apache.harmony.dalvik.ddmc.Chunk\n"); goto bail; } chunkTypeOff = dvmFindFieldOffset(chunkClass, "type", "I"); chunkDataOff = dvmFindFieldOffset(chunkClass, "data", "[B"); chunkOffsetOff = dvmFindFieldOffset(chunkClass, "offset", "I"); chunkLengthOff = dvmFindFieldOffset(chunkClass, "length", "I"); if (chunkTypeOff < 0 || chunkDataOff < 0 || chunkOffsetOff < 0 || chunkLengthOff < 0) { LOGW("Unable to find all chunk fields\n"); goto bail; } /* * The chunk handlers are written in the Java programming language, so * we need to convert the buffer to a byte array. */ dataArray = dvmAllocPrimitiveArray('B', dataLen, ALLOC_DEFAULT); if (dataArray == NULL) { LOGW("array alloc failed (%d)\n", dataLen); dvmClearException(self); goto bail; } memcpy(dataArray->contents, buf, dataLen); /* * Run through and find all chunks. [Currently just find the first.] */ unsigned int offset, length, type; type = get4BE((u1*)dataArray->contents + 0); length = get4BE((u1*)dataArray->contents + 4); offset = kChunkHdrLen; if (offset+length > (unsigned int) dataLen) { LOGW("WARNING: bad chunk found (len=%u pktLen=%d)\n", length, dataLen); goto bail; } /* * Call the handler. */ JValue callRes; dvmCallMethod(self, dispatch, NULL, &callRes, type, dataArray, offset, length); if (dvmCheckException(self)) { LOGI("Exception thrown by dispatcher for 0x%08x\n", type); dvmLogExceptionStackTrace(); dvmClearException(self); goto bail; } Object* chunk; ArrayObject* replyData; chunk = (Object*) callRes.l; if (chunk == NULL) goto bail; /* * Pull the pieces out of the chunk. We copy the results into a * newly-allocated buffer that the caller can free. We don't want to * continue using the Chunk object because nothing has a reference to it. * (If we do an alloc in here, we need to dvmAddTrackedAlloc it.) * * We could avoid this by returning type/data/offset/length and having * the caller be aware of the object lifetime issues, but that * integrates the JDWP code more tightly into the VM, and doesn't work * if we have responses for multiple chunks. * * So we're pretty much stuck with copying data around multiple times. */ type = dvmGetFieldInt(chunk, chunkTypeOff); replyData = (ArrayObject*) dvmGetFieldObject(chunk, chunkDataOff); offset = dvmGetFieldInt(chunk, chunkOffsetOff); length = dvmGetFieldInt(chunk, chunkLengthOff); LOGV("DDM reply: type=0x%08x data=%p offset=%d length=%d\n", type, replyData, offset, length); if (length == 0 || replyData == NULL) goto bail; if (offset + length > replyData->length) { LOGW("WARNING: chunk off=%d len=%d exceeds reply array len %d\n", offset, length, replyData->length); goto bail; } u1* reply; reply = (u1*) malloc(length + kChunkHdrLen); if (reply == NULL) { LOGW("malloc %d failed\n", length+kChunkHdrLen); goto bail; } set4BE(reply + 0, type); set4BE(reply + 4, length); memcpy(reply+kChunkHdrLen, (const u1*)replyData->contents + offset, length); *pReplyBuf = reply; *pReplyLen = length + kChunkHdrLen; result = true; LOGV("dvmHandleDdm returning type=%.4s buf=%p len=%d\n", (char*) reply, reply, length); bail: dvmReleaseTrackedAlloc((Object*) dataArray, NULL); return result; }
void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, void *param2) { LOGV("ioConfigChanged() event %d", event); OutputDescriptor *desc; uint32_t stream; if (ioHandle == 0) return; Mutex::Autolock _l(AudioSystem::gLock); switch (event) { case STREAM_CONFIG_CHANGED: if (param2 == 0) break; stream = *(uint32_t *)param2; LOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %d", stream, ioHandle); if (gStreamOutputMap.indexOfKey(stream) >= 0) { gStreamOutputMap.replaceValueFor(stream, ioHandle); } break; case OUTPUT_OPENED: { if (gOutputs.indexOfKey(ioHandle) >= 0) { LOGV("ioConfigChanged() opening already existing output! %d", ioHandle); break; } if (param2 == 0) break; desc = (OutputDescriptor *)param2; OutputDescriptor *outputDesc = new OutputDescriptor(*desc); gOutputs.add(ioHandle, outputDesc); LOGV("ioConfigChanged() new output samplingRate %d, format %d channels %d frameCount %d latency %d", outputDesc->samplingRate, outputDesc->format, outputDesc->channels, outputDesc->frameCount, outputDesc->latency); } break; case OUTPUT_CLOSED: { if (gOutputs.indexOfKey(ioHandle) < 0) { LOGW("ioConfigChanged() closing unknow output! %d", ioHandle); break; } LOGV("ioConfigChanged() output %d closed", ioHandle); gOutputs.removeItem(ioHandle); for (int i = gStreamOutputMap.size() - 1; i >= 0 ; i--) { if (gStreamOutputMap.valueAt(i) == ioHandle) { gStreamOutputMap.removeItemsAt(i); } } } break; case OUTPUT_CONFIG_CHANGED: { int index = gOutputs.indexOfKey(ioHandle); if (index < 0) { LOGW("ioConfigChanged() modifying unknow output! %d", ioHandle); break; } if (param2 == 0) break; desc = (OutputDescriptor *)param2; LOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %d frameCount %d latency %d", ioHandle, desc->samplingRate, desc->format, desc->channels, desc->frameCount, desc->latency); OutputDescriptor *outputDesc = gOutputs.valueAt(index); #ifdef STE_HARDWARE uint32_t oldLatency = outputDesc->latency; #endif delete outputDesc; outputDesc = new OutputDescriptor(*desc); gOutputs.replaceValueFor(ioHandle, outputDesc); #ifdef STE_HARDWARE if (oldLatency == outputDesc->latency) { break; } uint32_t newLatency = outputDesc->latency; gLock.unlock(); gLatencyLock.lock(); size_t size = gLatencyNotificationClients.size(); for (size_t i = 0; i < size; i++) { sp<NotificationClient> client = gLatencyNotificationClients.valueAt(i); (*client->mCb)(client->mCookie, ioHandle, newLatency); } gLatencyLock.unlock(); gLock.lock(); #endif } break; case INPUT_OPENED: case INPUT_CLOSED: case INPUT_CONFIG_CHANGED: break; } }
/* * Dump some information about an object. */ void dvmDumpObject(const Object* obj) { ClassObject* clazz; int i; if (obj == NULL || obj->clazz == NULL) { LOGW("Null or malformed object not dumped"); return; } clazz = obj->clazz; LOGD("----- Object dump: %p (%s, %d bytes) -----", obj, clazz->descriptor, (int) clazz->objectSize); //printHexDump(obj, clazz->objectSize); LOGD(" Fields:"); while (clazz != NULL) { LOGD(" -- %s", clazz->descriptor); for (i = 0; i < clazz->ifieldCount; i++) { const InstField* pField = &clazz->ifields[i]; char type = pField->field.signature[0]; if (type == 'F' || type == 'D') { double dval; if (type == 'F') dval = dvmGetFieldFloat(obj, pField->byteOffset); else dval = dvmGetFieldDouble(obj, pField->byteOffset); LOGD(" %2d: '%s' '%s' af=%04x off=%d %.3f", i, pField->field.name, pField->field.signature, pField->field.accessFlags, pField->byteOffset, dval); } else { u8 lval; if (type == 'J') lval = dvmGetFieldLong(obj, pField->byteOffset); else if (type == 'Z') lval = dvmGetFieldBoolean(obj, pField->byteOffset); else lval = dvmGetFieldInt(obj, pField->byteOffset); LOGD(" %2d: '%s' '%s' af=%04x off=%d 0x%08llx", i, pField->field.name, pField->field.signature, pField->field.accessFlags, pField->byteOffset, lval); } } clazz = clazz->super; } if (obj->clazz == gDvm.classJavaLangClass) { LOGD(" Static fields:"); const StaticField* sfields = &((ClassObject *)obj)->sfields[0]; for (i = 0; i < ((ClassObject *)obj)->sfieldCount; ++i) { const StaticField* pField = &sfields[i]; size_t byteOffset = (size_t)pField - (size_t)sfields; char type = pField->field.signature[0]; if (type == 'F' || type == 'D') { double dval; if (type == 'F') dval = pField->value.f; else dval = pField->value.d; LOGD(" %2d: '%s' '%s' af=%04x off=%zd %.3f", i, pField->field.name, pField->field.signature, pField->field.accessFlags, byteOffset, dval); } else { u8 lval; if (type == 'J') lval = pField->value.j; else if (type == 'Z') lval = pField->value.z; else lval = pField->value.i; LOGD(" %2d: '%s' '%s' af=%04x off=%zd 0x%08llx", i, pField->field.name, pField->field.signature, pField->field.accessFlags, byteOffset, lval); } } } }
void* onSuplNiRequest(void *data) { int err; int ignore; char *line; GpsCtrlSuplNiRequest ni_request; GpsCtrlContext *context = get_context(); line = (char *) data; LOGD("%s, %s", __FUNCTION__, line); err = at_tok_start(&line); if (err < 0) { LOGE("%s error parsing data", __FUNCTION__); return NULL; } err = at_tok_nextint(&line, &ignore); if (err < 0) { LOGE("%s error parsing data", __FUNCTION__); return NULL; } err = at_tok_nextint(&line, &ni_request.message_id); if (err < 0) { LOGE("%s error parsing data message id", __FUNCTION__); return NULL; } err = at_tok_nextint(&line, &ni_request.message_type); if (err < 0) { LOGE("%s error parsing data message type", __FUNCTION__); return NULL; } err = at_tok_nextint(&line, &ni_request.requestor_id_type); if (err < 0) { LOGW("%s error parsing data requestor id type", __FUNCTION__); ni_request.requestor_id_type = -1; } err = at_tok_nextstr(&line, &ni_request.requestor_id_text); if (err < 0) { LOGW("%s error parsing data requestor id text", __FUNCTION__); ni_request.requestor_id_text = ""; } err = at_tok_nextint(&line, &ni_request.client_name_type); if (err < 0) { LOGW("%s error parsing data client name type", __FUNCTION__); ni_request.client_name_type = -1; } err = at_tok_nextstr(&line, &ni_request.client_name_text); if (err < 0) { LOGW("%s error parsing data clien name text", __FUNCTION__); ni_request.client_name_text = ""; } context->supl_ni_callback(&ni_request); return NULL; }
bool EventHub::getEvent(RawEvent* outEvent) { outEvent->deviceId = 0; outEvent->type = 0; outEvent->scanCode = 0; outEvent->keyCode = 0; outEvent->flags = 0; outEvent->value = 0; outEvent->when = 0; // Note that we only allow one caller to getEvent(), so don't need // to do locking here... only when adding/removing devices. if (!mOpened) { mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR; mOpened = true; mNeedToSendFinishedDeviceScan = true; } for (;;) { // Report any devices that had last been added/removed. if (mClosingDevices != NULL) { device_t* device = mClosingDevices; LOGV("Reporting device closed: id=0x%x, name=%s\n", device->id, device->path.string()); mClosingDevices = device->next; if (device->id == mFirstKeyboardId) { outEvent->deviceId = 0; } else { outEvent->deviceId = device->id; } outEvent->type = DEVICE_REMOVED; outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC); delete device; mNeedToSendFinishedDeviceScan = true; return true; } if (mOpeningDevices != NULL) { device_t* device = mOpeningDevices; LOGV("Reporting device opened: id=0x%x, name=%s\n", device->id, device->path.string()); mOpeningDevices = device->next; if (device->id == mFirstKeyboardId) { outEvent->deviceId = 0; } else { outEvent->deviceId = device->id; } outEvent->type = DEVICE_ADDED; outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC); mNeedToSendFinishedDeviceScan = true; return true; } if (mNeedToSendFinishedDeviceScan) { mNeedToSendFinishedDeviceScan = false; outEvent->type = FINISHED_DEVICE_SCAN; outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC); return true; } // Grab the next input event. for (;;) { // Consume buffered input events, if any. if (mInputBufferIndex < mInputBufferCount) { const struct input_event& iev = mInputBufferData[mInputBufferIndex++]; const device_t* device = mDevices[mInputDeviceIndex]; LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d", device->path.string(), (int) iev.time.tv_sec, (int) iev.time.tv_usec, iev.type, iev.code, iev.value); if (device->id == mFirstKeyboardId) { outEvent->deviceId = 0; } else { outEvent->deviceId = device->id; } outEvent->type = iev.type; outEvent->scanCode = iev.code; if (iev.type == EV_KEY) { status_t err = device->layoutMap->map(iev.code, & outEvent->keyCode, & outEvent->flags); LOGV("iev.code=%d keyCode=%d flags=0x%08x err=%d\n", iev.code, outEvent->keyCode, outEvent->flags, err); if (err != 0) { outEvent->keyCode = AKEYCODE_UNKNOWN; outEvent->flags = 0; } } else { outEvent->keyCode = iev.code; } outEvent->value = iev.value; // Use an event timestamp in the same timebase as // java.lang.System.nanoTime() and android.os.SystemClock.uptimeMillis() // as expected by the rest of the system. outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC); return true; } // Finish reading all events from devices identified in previous poll(). // This code assumes that mInputDeviceIndex is initially 0 and that the // revents member of pollfd is initialized to 0 when the device is first added. // Since mFDs[0] is used for inotify, we process regular events starting at index 1. mInputDeviceIndex += 1; if (mInputDeviceIndex >= mFDCount) { break; } const struct pollfd& pfd = mFDs[mInputDeviceIndex]; if (pfd.revents & POLLIN) { int32_t readSize = read(pfd.fd, mInputBufferData, sizeof(struct input_event) * INPUT_BUFFER_SIZE); if (readSize < 0) { if (errno != EAGAIN && errno != EINTR) { LOGW("could not get event (errno=%d)", errno); } } else if ((readSize % sizeof(struct input_event)) != 0) { LOGE("could not get event (wrong size: %d)", readSize); } else { mInputBufferCount = readSize / sizeof(struct input_event); mInputBufferIndex = 0; } } } #if HAVE_INOTIFY // readNotify() will modify mFDs and mFDCount, so this must be done after // processing all other events. if(mFDs[0].revents & POLLIN) { readNotify(mFDs[0].fd); mFDs[0].revents = 0; continue; // report added or removed devices immediately } #endif mInputDeviceIndex = 0; // Poll for events. Mind the wake lock dance! // We hold a wake lock at all times except during poll(). This works due to some // subtle choreography. When a device driver has pending (unread) events, it acquires // a kernel wake lock. However, once the last pending event has been read, the device // driver will release the kernel wake lock. To prevent the system from going to sleep // when this happens, the EventHub holds onto its own user wake lock while the client // is processing events. Thus the system can only sleep if there are no events // pending or currently being processed. release_wake_lock(WAKE_LOCK_ID); int pollResult = poll(mFDs, mFDCount, -1); acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); if (pollResult <= 0) { if (errno != EINTR) { LOGW("poll failed (errno=%d)\n", errno); usleep(100000); } } } }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { // no /sdcard? let's assume /data/media if (strstr(path, "/sdcard") == path && is_data_media()) { LOGW("using /data/media, no /sdcard found.\n"); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } int ret = mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); if (strcmp(v->mount_point, "/system") == 0) { // we need /system mounted rw, thank you SE... __system("/sbin/mount -o remount,rw /system"); } return ret; } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->device, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", path); return __system(mount_cmd); } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
int format_volume(const char* volume) { Volume* v = volume_for_path(volume); // Special case for formatting /system if (strcmp(volume, "/system") == 0) { // you can't format the system on xperias, thank you SE... LOGI("Formatting /system ...\n"); ensure_path_mounted("/system"); __system("/sbin/mount -o remount,rw /system"); __system("/sbin/rm -rf /system/*"); ensure_path_unmounted("/system"); return 0; } if (v == NULL) { // no /sdcard? let's assume /data/media if (strstr(volume, "/sdcard") == volume && is_data_media()) { return format_unknown_device(NULL, volume, NULL); } // silent failure for sd-ext if (strcmp(volume, "/sd-ext") == 0) return -1; LOGE("unknown volume \"%s\"\n", volume); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // you can't format the ramdisk. LOGE("can't format_volume \"%s\"", volume); return -1; } if (strcmp(v->mount_point, volume) != 0) { #if 0 LOGE("can't give path \"%s\" to format_volume\n", volume); return -1; #endif return format_unknown_device(v->device, volume, NULL); } if (ensure_path_unmounted(volume) != 0) { LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); return -1; } if (strcmp(v->fs_type, "yaffs2") == 0 || strcmp(v->fs_type, "mtd") == 0) { mtd_scan_partitions(); const MtdPartition* partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("format_volume: no MTD partition \"%s\"\n", v->device); return -1; } MtdWriteContext *write = mtd_write_partition(partition); if (write == NULL) { LOGW("format_volume: can't open MTD \"%s\"\n", v->device); return -1; } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { LOGW("format_volume: can't erase MTD \"%s\"\n", v->device); mtd_write_close(write); return -1; } else if (mtd_write_close(write)) { LOGW("format_volume: can't close MTD \"%s\"\n", v->device); return -1; } return 0; } if (strcmp(v->fs_type, "ext4") == 0) { reset_ext4fs_info(); int result = make_ext4fs(v->device, NULL, NULL, 0, 0, 0); if (result != 0) { LOGE("format_volume: make_extf4fs failed on %s\n", v->device); return -1; } return 0; } #if 0 LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type); return -1; #endif return format_unknown_device(v->device, volume, v->fs_type); }
void show_mount_usb_storage_menu() { int fd; Volume *vol = volume_for_path("/emmc"); if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { LOGE("Unable to open ums lunfile (%s)", strerror(errno)); return -1; } if (write(fd, vol->device, strlen(vol->device)) < 0) { LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); close(fd); return -1; } int fd2; Volume *vol2 = volume_for_path("/sdcard"); if ((fd2 = open(BOARD_UMS_LUN1FILE, O_WRONLY)) >= 0) { if ((write(fd2, vol2->device, strlen(vol2->device)) < 0) && (!vol2->device2 || (write(fd2, vol2->device, strlen(vol2->device2)) < 0))) { LOGW("Unable to write to ums lunfile 2 (%s)", strerror(errno)); close(fd2); //return -1; } } static char* headers[] = { "USB Mass Storage device", "Leaving this menu unmount", "your SD card from your PC.", "", NULL }; static char* list[] = { "Unmount", NULL }; for (;;) { int chosen_item = get_menu_selection(headers, list, 0, 0); if (chosen_item == GO_BACK || chosen_item == 0) break; } char ch = 0; if ((fd2 = open(BOARD_UMS_LUN1FILE, O_WRONLY)) >= 0) { write(fd2, &ch, 1); close(fd2); } if ((fd = open(BOARD_UMS_LUNFILE, O_WRONLY)) < 0) { LOGE("Unable to open ums lunfile (%s)", strerror(errno)); return -1; } if (write(fd, &ch, 1) < 0) { LOGE("Unable to write to ums lunfile (%s)", strerror(errno)); close(fd); return -1; } }
void prepareVertices() { // Load mesh from compressed asset AAsset* asset = AAssetManager_open(app->activity->assetManager, "models/vulkanlogo.obj", AASSET_MODE_STREAMING); assert(asset); size_t size = AAsset_getLength(asset); assert(size > 0); char *assetData = new char[size]; AAsset_read(asset, assetData, size); AAsset_close(asset); std::stringstream assetStream(assetData); std::vector<tinyobj::shape_t> shapes; std::vector<tinyobj::material_t> materials; std::string objerr; tinyobj::MaterialFileReader matFileReader(""); bool ret = tinyobj::LoadObj(shapes, materials, objerr, assetStream, matFileReader, true); LOGW("shapes %d", shapes.size()); // Setup vertices float scale = 0.025f; std::vector<Vertex> vertexBuffer; std::vector<uint32_t> indexBuffer; for (auto& shape : shapes) { // Vertices for (size_t i = 0; i < shape.mesh.positions.size() / 3; i++) { Vertex v; v.pos[0] = shape.mesh.positions[3 * i + 0] * scale; v.pos[1] = -shape.mesh.positions[3 * i + 1] * scale; v.pos[2] = shape.mesh.positions[3 * i + 2] * scale; v.normal[0] = shape.mesh.normals[3 * i + 0]; v.normal[1] = shape.mesh.normals[3 * i + 1]; v.normal[2] = shape.mesh.normals[3 * i + 2]; v.color = glm::vec3(1.0f, 0.0f, 0.0f); vertexBuffer.push_back(v); } // Indices for (size_t i = 0; i < shape.mesh.indices.size() / 3; i++) { indexBuffer.push_back(shape.mesh.indices[3 * i + 0]); indexBuffer.push_back(shape.mesh.indices[3 * i + 1]); indexBuffer.push_back(shape.mesh.indices[3 * i + 2]); } } uint32_t vertexBufferSize = vertexBuffer.size() * sizeof(Vertex); uint32_t indexBufferSize = indexBuffer.size() * sizeof(uint32_t); VkMemoryAllocateInfo memAlloc = {}; memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; memAlloc.pNext = NULL; memAlloc.allocationSize = 0; memAlloc.memoryTypeIndex = 0; VkMemoryRequirements memReqs; VkResult err; void *data; // Generate vertex buffer // Setup VkBufferCreateInfo bufInfo = {}; bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufInfo.pNext = NULL; bufInfo.size = vertexBufferSize; bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; bufInfo.flags = 0; // Copy vertex data to VRAM memset(&vertices, 0, sizeof(vertices)); err = vkCreateBuffer(device, &bufInfo, nullptr, &vertices.buf); assert(!err); vkGetBufferMemoryRequirements(device, vertices.buf, &memReqs); memAlloc.allocationSize = memReqs.size; getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memAlloc.memoryTypeIndex); vkAllocateMemory(device, &memAlloc, nullptr, &vertices.mem); assert(!err); err = vkMapMemory(device, vertices.mem, 0, memAlloc.allocationSize, 0, &data); assert(!err); memcpy(data, vertexBuffer.data(), vertexBufferSize); vkUnmapMemory(device, vertices.mem); assert(!err); err = vkBindBufferMemory(device, vertices.buf, vertices.mem, 0); assert(!err); // Generate index buffer // Setup VkBufferCreateInfo indexbufferInfo = {}; indexbufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; indexbufferInfo.pNext = NULL; indexbufferInfo.size = indexBufferSize; indexbufferInfo.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; indexbufferInfo.flags = 0; // Copy index data to VRAM memset(&indices, 0, sizeof(indices)); err = vkCreateBuffer(device, &bufInfo, nullptr, &indices.buf); assert(!err); vkGetBufferMemoryRequirements(device, indices.buf, &memReqs); memAlloc.allocationSize = memReqs.size; getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memAlloc.memoryTypeIndex); err = vkAllocateMemory(device, &memAlloc, nullptr, &indices.mem); assert(!err); err = vkMapMemory(device, indices.mem, 0, indexBufferSize, 0, &data); assert(!err); memcpy(data, indexBuffer.data(), indexBufferSize); vkUnmapMemory(device, indices.mem); err = vkBindBufferMemory(device, indices.buf, indices.mem, 0); assert(!err); indices.count = indexBuffer.size(); // Binding description vertices.bindingDescriptions.resize(1); vertices.bindingDescriptions[0] = vkTools::initializers::vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX); // Attribute descriptions // Describes memory layout and shader positions vertices.attributeDescriptions.resize(3); // Location 0 : Position vertices.attributeDescriptions[0] = vkTools::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 0, VK_FORMAT_R32G32B32_SFLOAT, 0); // Location 1 : Normal vertices.attributeDescriptions[1] = vkTools::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 1, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 3); // Location 2 : Color vertices.attributeDescriptions[2] = vkTools::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 2, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 6); // Assign to vertex buffer vertices.inputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertices.inputState.pNext = NULL; vertices.inputState.vertexBindingDescriptionCount = vertices.bindingDescriptions.size(); vertices.inputState.pVertexBindingDescriptions = vertices.bindingDescriptions.data(); vertices.inputState.vertexAttributeDescriptionCount = vertices.attributeDescriptions.size(); vertices.inputState.pVertexAttributeDescriptions = vertices.attributeDescriptions.data(); }
BOOL MyApp::InitInstance(void) { // Create the main window. m_pMainWnd = new MainWindow; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); LOGD("Happily in InitInstance!"); /* find our .EXE file */ //HMODULE hModule = ::GetModuleHandle(NULL); WCHAR buf[MAX_PATH]; if (::GetModuleFileName(NULL /*hModule*/, buf, NELEM(buf)) != 0) { LOGD("Module name is '%ls'", buf); fExeFileName = buf; WCHAR* cp = wcsrchr(buf, '\\'); if (cp == NULL) fExeBaseName = L""; else fExeBaseName = fExeFileName.Left(cp - buf +1); } else { LOGW("GLITCH: GetModuleFileName failed (err=%ld)", ::GetLastError()); } LogModuleLocation(L"riched.dll"); LogModuleLocation(L"riched20.dll"); LogModuleLocation(L"riched32.dll"); LogModuleLocation(L"msftedit.dll"); // This causes functions like SetProfileInt to use the registry rather // than a .INI file. The registry key is "usually the name of a company". #ifdef CAN_UPDATE_FILE_ASSOC SetRegistryKey(fRegistry.GetAppRegistryKey()); #else SetRegistryKey(L"faddenSoft"); #endif //LOGI("Registry key is '%ls'", m_pszRegistryKey); //LOGI("Profile name is '%ls'", m_pszProfileName); LOGI("Short command line is '%ls'", m_lpCmdLine); //LOGI("CP app name is '%ls'", m_pszAppName); //LOGI("CP exe name is '%ls'", m_pszExeName); LOGI("CP help file is '%ls'", m_pszHelpFilePath); LOGI("Command line is '%ls'", ::GetCommandLine()); //if (!WriteProfileString("SectionOne", "MyEntry", "test")) // LOGI("WriteProfileString failed"); #ifdef CAN_UPDATE_FILE_ASSOC /* * If we're installing or uninstalling, do what we need to and then * bail immediately. This will hemorrhage memory, but I'm sure the * incredibly robust Windows environment will take it in stride. */ if (wcscmp(m_lpCmdLine, L"-install") == 0) { LOGI("Invoked with INSTALL flag"); fRegistry.OneTimeInstall(); ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); exit(0); } else if (wcscmp(m_lpCmdLine, L"-uninstall") == 0) { LOGI("Invoked with UNINSTALL flag"); fRegistry.OneTimeUninstall(); ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); exit(1); // tell DeployMaster to continue with uninstall } fRegistry.FixBasicSettings(); #endif return TRUE; }
/** * Initialize an EGL context for the current display. */ static int engine_init_display(struct engine *engine, bool p_gl2) { // initialize OpenGL ES and EGL /* * Here specify the attributes of the desired configuration. * Below, we select an EGLConfig with at least 8 bits per color * component compatible with on-screen windows */ const EGLint gl2_attribs[] = { // EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 4, EGL_GREEN_SIZE, 4, EGL_RED_SIZE, 4, EGL_ALPHA_SIZE, 0, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; const EGLint gl1_attribs[] = { // EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 4, EGL_GREEN_SIZE, 4, EGL_RED_SIZE, 4, EGL_ALPHA_SIZE, 0, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_NONE }; const EGLint *attribs = p_gl2 ? gl2_attribs : gl1_attribs; EGLint w, h, dummy, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ eglChooseConfig(display, attribs, &config, 1, &numConfigs); LOGI("Num configs: %i\n", numConfigs); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format); //ANativeWindow_setFlags(engine->app->window, 0, 0, format|); surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; context = eglCreateContext(display, config, EGL_NO_CONTEXT, p_gl2 ? context_attribs : NULL); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGW("Unable to eglMakeCurrent"); return -1; } eglQuerySurface(display, surface, EGL_WIDTH, &w); eglQuerySurface(display, surface, EGL_HEIGHT, &h); print_line("INIT VIDEO MODE: " + itos(w) + "," + itos(h)); //engine->os->set_egl_extensions(eglQueryString(display,EGL_EXTENSIONS)); engine->os->init_video_mode(w, h); engine->display = display; engine->context = context; engine->surface = surface; engine->width = w; engine->height = h; engine->display_active = true; //engine->state.angle = 0; // Initialize GL state. //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glEnable(GL_CULL_FACE); // glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); LOGI("GL Version: %s - %s %s\n", glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER)); return 0; }
int format_volume(const char* volume) { if (is_data_media_volume_path(volume)) { return format_unknown_device(NULL, volume, NULL); } // check to see if /data is being formatted, and if it is /data/media // Note: the /sdcard check is redundant probably, just being safe. if (strstr(volume, "/data") == volume && is_data_media() && !ignore_data_media) { return format_unknown_device(NULL, volume, NULL); } Volume* v = volume_for_path(volume); if (v == NULL) { // silent failure for sd-ext if (strcmp(volume, "/sd-ext") != 0) LOGE("unknown volume '%s'\n", volume); return -1; } // silent failure to format non existing sd-ext when defined in recovery.fstab if (strcmp(volume, "/sd-ext") == 0) { struct stat s; if (0 != stat(v->blk_device, &s)) { LOGI("Skipping format of sd-ext\n"); return -1; } } // Only use vold format for exact matches otherwise /sdcard will be // formatted instead of /storage/sdcard0/.android_secure if (fs_mgr_is_voldmanaged(v) && strcmp(volume, v->mount_point) == 0) { if (ensure_path_unmounted(volume) != 0) { LOGE("format_volume failed to unmount %s", v->mount_point); } return vold_format_volume(v->mount_point, 1) == CommandOkay ? 0 : -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // you can't format the ramdisk. LOGE("can't format_volume \"%s\"", volume); return -1; } if (strcmp(v->mount_point, volume) != 0) { #if 0 LOGE("can't give path \"%s\" to format_volume\n", volume); return -1; #endif return format_unknown_device(v->blk_device, volume, NULL); } if (ensure_path_unmounted(volume) != 0) { LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); return -1; } if (strcmp(v->fs_type, "yaffs2") == 0 || strcmp(v->fs_type, "mtd") == 0) { mtd_scan_partitions(); const MtdPartition* partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("format_volume: no MTD partition \"%s\"\n", v->blk_device); return -1; } MtdWriteContext *write = mtd_write_partition(partition); if (write == NULL) { LOGW("format_volume: can't open MTD \"%s\"\n", v->blk_device); return -1; } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { LOGW("format_volume: can't erase MTD \"%s\"\n", v->blk_device); mtd_write_close(write); return -1; } else if (mtd_write_close(write)) { LOGW("format_volume: can't close MTD \"%s\"\n", v->blk_device); return -1; } return 0; } if (strcmp(v->fs_type, "ext4") == 0) { int result = make_ext4fs(v->blk_device, v->length, volume, sehandle); if (result != 0) { LOGE("format_volume: make_extf4fs failed on %s\n", v->blk_device); return -1; } return 0; } #ifdef USE_F2FS if (strcmp(v->fs_type, "f2fs") == 0) { int result = make_f2fs_main(v->blk_device, v->mount_point); if (result != 0) { LOGE("format_volume: mkfs.f2f2 failed on %s\n", v->blk_device); return -1; } return 0; } #endif #if 0 LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type); return -1; #endif return format_unknown_device(v->blk_device, volume, v->fs_type); }
bool PreviewWindow::onNextFrameAvailableSW(const void* frame, int video_fmt, nsecs_t timestamp, V4L2Camera* camera_dev) { int res; Mutex::Autolock locker(&mObjectLock); V4L2BUF_t * pv4l2_buf = (V4L2BUF_t *)frame; // LOGD("%s, timestamp: %lld", __FUNCTION__, timestamp); if (!isPreviewEnabled() || mPreviewWindow == NULL) { return true; } /* Make sure that preview window dimensions are OK with the camera device */ if (adjustPreviewDimensions(camera_dev) || mShouldAdjustDimensions) { /* Need to set / adjust buffer geometry for the preview window. * Note that in the emulator preview window uses only RGB for pixel * formats. */ LOGD("%s: Adjusting preview windows %p geometry to %dx%d", __FUNCTION__, mPreviewWindow, mPreviewFrameWidth, mPreviewFrameHeight); int format = HAL_PIXEL_FORMAT_YCrCb_420_SP; LOGV("preview format: HAL_PIXEL_FORMAT_YCrCb_420_SP"); res = mPreviewWindow->set_buffers_geometry(mPreviewWindow, mPreviewFrameWidth, mPreviewFrameHeight, format); if (res != NO_ERROR) { LOGE("%s: Error in set_buffers_geometry %d -> %s", __FUNCTION__, -res, strerror(-res)); // return false; } mShouldAdjustDimensions = false; res = mPreviewWindow->set_buffer_count(mPreviewWindow, 3); if (res != 0) { LOGE("native_window_set_buffer_count failed: %s (%d)", strerror(-res), -res); if ( ENODEV == res ) { LOGE("Preview surface abandoned!"); mPreviewWindow = NULL; } return false; } mPreviewWindow->set_crop(mPreviewWindow, mRectCrop.left, mRectCrop.top, mRectCrop.right, mRectCrop.bottom); mNewCrop = false; LOGV("first sw: [%d, %d, %d, %d]", mRectCrop.left, mRectCrop.top, mRectCrop.right, mRectCrop.bottom); } /* * Push new frame to the preview window. */ /* Dequeue preview window buffer for the frame. */ buffer_handle_t* buffer = NULL; int stride = 0; res = mPreviewWindow->dequeue_buffer(mPreviewWindow, &buffer, &stride); if (res != NO_ERROR || buffer == NULL) { LOGE("%s: Unable to dequeue preview window buffer: %d -> %s", __FUNCTION__, -res, strerror(-res)); int undequeued = 0; mPreviewWindow->get_min_undequeued_buffer_count(mPreviewWindow, &undequeued); LOGW("now undequeued: %d", undequeued); return false; } /* Let the preview window to lock the buffer. */ res = mPreviewWindow->lock_buffer(mPreviewWindow, buffer); if (res != NO_ERROR) { LOGE("%s: Unable to lock preview window buffer: %d -> %s", __FUNCTION__, -res, strerror(-res)); mPreviewWindow->cancel_buffer(mPreviewWindow, buffer); return false; } /* Now let the graphics framework to lock the buffer, and provide * us with the framebuffer data address. */ void* img = NULL; const Rect rect(mPreviewFrameWidth, mPreviewFrameHeight); GraphicBufferMapper& grbuffer_mapper(GraphicBufferMapper::get()); res = grbuffer_mapper.lock(*buffer, GRALLOC_USAGE_SW_WRITE_OFTEN, rect, &img); if (res != NO_ERROR) { LOGE("%s: grbuffer_mapper.lock failure: %d -> %s", __FUNCTION__, res, strerror(res)); mPreviewWindow->cancel_buffer(mPreviewWindow, buffer); return false; } if (mNewCrop) { mPreviewWindow->set_crop(mPreviewWindow, mRectCrop.left, mRectCrop.top, mRectCrop.right, mRectCrop.bottom); mNewCrop = false; } if (pv4l2_buf->format == V4L2_PIX_FMT_NV21) { memcpy(img, (void*)pv4l2_buf->addrVirY, mPreviewFrameWidth * mPreviewFrameHeight * 3/2); } else { NV12ToNV21_shift((void*)pv4l2_buf->addrVirY, img, mPreviewFrameWidth, mPreviewFrameHeight); } mPreviewWindow->enqueue_buffer(mPreviewWindow, buffer); grbuffer_mapper.unlock(*buffer); return true; }
NFCSTATUS phLibNfc_Mgt_GetstackCapabilities( phLibNfc_StackCapabilities_t *phLibNfc_StackCapabilities, void *pContext) { NFCSTATUS RetVal = NFCSTATUS_FAILED; /*Check Lib Nfc stack is initilized*/ if((NULL == gpphLibContext)|| (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown)) { RetVal = NFCSTATUS_NOT_INITIALISED; } /*Check application has sent the valid parameters*/ else if((NULL == phLibNfc_StackCapabilities) || (NULL == pContext)) { RetVal= NFCSTATUS_INVALID_PARAMETER; } else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown) { RetVal = NFCSTATUS_SHUTDOWN; } else if(TRUE == gpphLibContext->status.GenCb_pending_status) { /*Previous operation is pending */ RetVal = NFCSTATUS_BUSY; } else { /* Tag Format Capabilities*/ phLibNfc_StackCapabilities->psFormatCapabilities.Desfire = TRUE; phLibNfc_StackCapabilities->psFormatCapabilities.MifareStd = TRUE; phLibNfc_StackCapabilities->psFormatCapabilities.MifareUL = TRUE; phLibNfc_StackCapabilities->psFormatCapabilities.FeliCa = FALSE; phLibNfc_StackCapabilities->psFormatCapabilities.Jewel = FALSE; phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4A = FALSE; phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4B = FALSE; phLibNfc_StackCapabilities->psFormatCapabilities.MifareULC = TRUE; phLibNfc_StackCapabilities->psFormatCapabilities.ISO15693 = FALSE; /* Tag Mapping Capabilities */ phLibNfc_StackCapabilities->psMappingCapabilities.FeliCa = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.Desfire = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4A = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4B = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.MifareStd = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.MifareUL = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.MifareULC = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.Jewel = TRUE; phLibNfc_StackCapabilities->psMappingCapabilities.ISO15693 = FALSE; /*Call Hal4 Get Dev Capabilities to get info about protocols supported by Lib Nfc*/ PHDBG_INFO("LibNfc:Get Stack capabilities "); RetVal= phHal4Nfc_GetDeviceCapabilities( gpphLibContext->psHwReference, &(phLibNfc_StackCapabilities->psDevCapabilities), (void *)gpphLibContext); LIB_NFC_VERSION_SET(phLibNfc_StackCapabilities->psDevCapabilities.hal_version, PH_HAL4NFC_VERSION, PH_HAL4NFC_REVISION, PH_HAL4NFC_PATCH, PH_HAL4NFC_BUILD); phLibNfc_StackCapabilities->psDevCapabilities.fw_version= gpphLibContext->psHwReference->device_info.fw_version; phLibNfc_StackCapabilities->psDevCapabilities.hci_version= gpphLibContext->psHwReference->device_info.hci_version; phLibNfc_StackCapabilities->psDevCapabilities.hw_version= gpphLibContext->psHwReference->device_info.hw_version; phLibNfc_StackCapabilities->psDevCapabilities.model_id= gpphLibContext->psHwReference->device_info.model_id; (void)memcpy(phLibNfc_StackCapabilities->psDevCapabilities.full_version, gpphLibContext->psHwReference->device_info.full_version,NXP_FULL_VERSION_LEN); /* Check the firmware version */ if (nxp_nfc_full_version == NULL) { // Couldn't load firmware, just pretend we're up to date. LOGW("Firmware image not available: this device might be running old NFC firmware!"); phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = 0; } else { phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = memcmp(phLibNfc_StackCapabilities->psDevCapabilities.full_version, nxp_nfc_full_version, NXP_FULL_VERSION_LEN); } if(NFCSTATUS_SUCCESS != RetVal) { RetVal = NFCSTATUS_FAILED; } } return RetVal; }
/** * Initialize an EGL context for the current display. */ static int engine_init_display(struct engine* engine) { // initialize OpenGL ES and EGL /* * Here specify the attributes of the desired configuration. * Below, we select an EGLConfig with at least 8 bits per color * component compatible with on-screen windows */ const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; EGLint w, h, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ eglChooseConfig(display, attribs, &config, 1, &numConfigs); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format); surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); context = eglCreateContext(display, config, NULL, NULL); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGW("Unable to eglMakeCurrent"); return -1; } eglQuerySurface(display, surface, EGL_WIDTH, &w); eglQuerySurface(display, surface, EGL_HEIGHT, &h); engine->display = display; engine->context = context; engine->surface = surface; engine->width = w; engine->height = h; engine->state.angle = 0; // Initialize GL state. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); return 0; }
void QComHardwareRenderer::AverageFPSPrint() { LOGW("========================================================="); LOGW("Average Frames Per Second: %.4f", mFpsSum/mNumFpsSamples); LOGW("========================================================="); }
/* * Load squirrel script from asset */ bool loadScriptFromAsset(const char* fname) { /* * read squirrel script from asset */ AAssetManager* mgr = engine->app->activity->assetManager; if (mgr == NULL) { engine->setLastError(ERR_SCRIPT_LOAD); LOGE("loadScriptFromAsset: failed to load AAssetManager"); return false; } AAsset* asset = AAssetManager_open(mgr, fname, AASSET_MODE_UNKNOWN); if (asset == NULL) { engine->setLastError(ERR_SCRIPT_OPEN); LOGW("loadScriptFromAsset: failed to open main script file"); LOGW(fname); return false; } unsigned short sqtag; bool isByteCode = false; if (AAsset_read(asset, &sqtag, 2) > 0) { if (sqtag == SQ_BYTECODE_STREAM_TAG) { isByteCode = true; } AAsset_seek(asset, 0, SEEK_SET); } else { AAsset_close(asset); return false; } if (isByteCode && SQ_SUCCEEDED(sq_readclosure(engine->sqvm, sq_lexer_bytecode, asset))) { sq_pushroottable(engine->sqvm); if (SQ_FAILED(sq_call(engine->sqvm, 1, SQFalse, SQTrue))) { engine->setLastError(ERR_SCRIPT_CALL_ROOT); LOGW("loadScriptFromAsset: failed to sq_call"); LOGW(fname); AAsset_close(asset); return false; } } else if(!isByteCode && SQ_SUCCEEDED(sq_compile(engine->sqvm, sq_lexer_asset, asset, fname, SQTrue))) { sq_pushroottable(engine->sqvm); if (SQ_FAILED(sq_call(engine->sqvm, 1, SQFalse, SQTrue))) { engine->setLastError(ERR_SCRIPT_CALL_ROOT); LOGW("loadScriptFromAsset: failed to sq_call"); LOGW(fname); AAsset_close(asset); return false; } } else { engine->setLastError(ERR_SCRIPT_COMPILE); LOGW("loadScriptFromAsset: failed to compile squirrel script"); LOGW(fname); AAsset_close(asset); return false; } AAsset_close(asset); return true; }
ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes) { android::AutoMutex lock(mLock); if (!mPowerLock) { acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioOutLock"); mPowerLock = true; } acoustic_device_t *aDev = acoustics(); // For output, we will pass the data on to the acoustics module, but the actual // data is expected to be sent to the audio device directly as well. if (aDev && aDev->write) aDev->write(aDev, buffer, bytes); snd_pcm_sframes_t n; size_t sent = 0; status_t err = 0; do { if (mHandle->mmap) n = snd_pcm_mmap_writei(mHandle->handle, (char *)buffer + sent, snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent)); else n = snd_pcm_writei(mHandle->handle, (char *)buffer + sent, snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent)); if (n == -EBADFD) { LOGW("badstate and do recovery....."); switch(snd_pcm_state(mHandle->handle)){ case SND_PCM_STATE_SETUP: err = snd_pcm_prepare(mHandle->handle); if(err < 0) LOGW("snd_pcm_prepare failed"); break; case SND_PCM_STATE_SUSPENDED: snd_pcm_resume(mHandle->handle); if(err < 0) LOGW("snd_pcm_resume failed"); snd_pcm_prepare(mHandle->handle); if(err < 0) LOGW("snd_pcm_prepare failed"); break; default: // Somehow the stream is in a bad state. The driver probably // has a bug and snd_pcm_recover() doesn't seem to handle this. mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode); break; } if(err < 0 ) mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode); if (aDev && aDev->recover) aDev->recover(aDev, n); } else if (n < 0) { if (mHandle->handle) { LOGW("underrun and do recovery....."); // snd_pcm_recover() will return 0 if successful in recovering from // an error, or -errno if the error was unrecoverable. n = snd_pcm_recover(mHandle->handle, n, 1); if (aDev && aDev->recover) aDev->recover(aDev, n); if (n) return static_cast<ssize_t>(n); } } else { mFrameCount += n; sent += static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n)); } } while (mHandle->handle && sent < bytes); return sent; }
int ensure_path_mounted(const char* path) { if ((DataManager_GetIntValue(TW_HAS_DATA_MEDIA) == 1 || DataManager_GetIntValue(TW_HAS_DUAL_STORAGE) == 0) && strncmp(path, "/sdcard", 7) == 0) return 0; // sdcard is just a symlink Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "ext2") == 0 || strcmp(v->fs_type, "vfat") == 0) { result = mount(v->device, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; if (v->device2) { LOGW("failed to mount %s (%s); trying %s\n", v->device, strerror(errno), v->device2); result = mount(v->device2, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); if (result == 0) return 0; } LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); return -1; } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount) { AutoMutex lock(mLock); int active; status_t result = NO_ERROR; audio_track_cblk_t* cblk = mCblk; uint32_t framesReq = audioBuffer->frameCount; uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS; audioBuffer->frameCount = 0; audioBuffer->size = 0; uint32_t framesAvail = cblk->framesAvailable(); cblk->lock.lock(); if (cblk->flags & CBLK_INVALID_MSK) { goto create_new_track; } cblk->lock.unlock(); if (framesAvail == 0) { cblk->lock.lock(); goto start_loop_here; while (framesAvail == 0) { active = mActive; if (UNLIKELY(!active)) { LOGV("Not active and NO_MORE_BUFFERS"); cblk->lock.unlock(); return NO_MORE_BUFFERS; } if (UNLIKELY(!waitCount)) { cblk->lock.unlock(); return WOULD_BLOCK; } if (!(cblk->flags & CBLK_INVALID_MSK)) { mLock.unlock(); result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs)); cblk->lock.unlock(); mLock.lock(); if (mActive == 0) { return status_t(STOPPED); } cblk->lock.lock(); } if (cblk->flags & CBLK_INVALID_MSK) { goto create_new_track; } if (__builtin_expect(result!=NO_ERROR, false)) { cblk->waitTimeMs += waitTimeMs; if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) { // timing out when a loop has been set and we have already written upto loop end // is a normal condition: no need to wake AudioFlinger up. if (cblk->user < cblk->loopEnd) { LOGW( "obtainBuffer timed out (is the CPU pegged?) %p " "user=%08x, server=%08x", this, cblk->user, cblk->server); //unlock cblk mutex before calling mAudioTrack->start() (see issue #1617140) cblk->lock.unlock(); result = mAudioTrack->start(); cblk->lock.lock(); if (result == DEAD_OBJECT) { android_atomic_or(CBLK_INVALID_ON, &cblk->flags); create_new_track: result = restoreTrack_l(cblk, false); } if (result != NO_ERROR) { LOGW("obtainBuffer create Track error %d", result); cblk->lock.unlock(); return result; } } cblk->waitTimeMs = 0; } if (--waitCount == 0) { cblk->lock.unlock(); return TIMED_OUT; } } // read the server count again start_loop_here: framesAvail = cblk->framesAvailable_l(); } cblk->lock.unlock(); } // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags); LOGW("obtainBuffer() track %p disabled, restarting", this); mAudioTrack->start(); } cblk->waitTimeMs = 0; if (framesReq > framesAvail) { framesReq = framesAvail; } uint32_t u = cblk->user; uint32_t bufferEnd = cblk->userBase + cblk->frameCount; if (u + framesReq > bufferEnd) { framesReq = bufferEnd - u; } audioBuffer->flags = mMuted ? Buffer::MUTE : 0; audioBuffer->channelCount = mChannelCount; audioBuffer->frameCount = framesReq; audioBuffer->size = framesReq * cblk->frameSize; if (audio_is_linear_pcm(mFormat)) { audioBuffer->format = AUDIO_FORMAT_PCM_16_BIT; } else { audioBuffer->format = mFormat; } audioBuffer->raw = (int8_t *)cblk->buffer(u); active = mActive; return active ? status_t(NO_ERROR) : status_t(STOPPED); }
int format_device(const char *device, const char *path, const char *fs_type) { Volume* v = volume_for_path(path); if (v == NULL) { // silent failure for sd-ext if (strcmp(path, "/sd-ext") == 0) return -1; LOGE("unknown volume \"%s\"\n", path); return -1; } if (is_data_media_volume_path(path)) { return format_unknown_device(NULL, path, NULL); } if (strstr(path, "/data") == path && is_data_media()) { return format_unknown_device(NULL, path, NULL); } if (strcmp(fs_type, "ramdisk") == 0) { // you can't format the ramdisk. LOGE("can't format_volume \"%s\"", path); return -1; } if (strcmp(fs_type, "rfs") == 0) { if (ensure_path_unmounted(path) != 0) { LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); return -1; } if (0 != format_rfs_device(device, path)) { LOGE("format_volume: format_rfs_device failed on %s\n", device); return -1; } return 0; } if (strcmp(v->mount_point, path) != 0) { return format_unknown_device(v->device, path, NULL); } if (ensure_path_unmounted(path) != 0) { LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); return -1; } if (strcmp(fs_type, "yaffs2") == 0 || strcmp(fs_type, "mtd") == 0) { mtd_scan_partitions(); const MtdPartition* partition = mtd_find_partition_by_name(device); if (partition == NULL) { LOGE("format_volume: no MTD partition \"%s\"\n", device); return -1; } MtdWriteContext *write = mtd_write_partition(partition); if (write == NULL) { LOGW("format_volume: can't open MTD \"%s\"\n", device); return -1; } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { LOGW("format_volume: can't erase MTD \"%s\"\n", device); mtd_write_close(write); return -1; } else if (mtd_write_close(write)) { LOGW("format_volume: can't close MTD \"%s\"\n",device); return -1; } return 0; } if (strcmp(fs_type, "ext4") == 0) { int length = 0; if (strcmp(v->fs_type, "ext4") == 0) { // Our desired filesystem matches the one in fstab, respect v->length length = v->length; } reset_ext4fs_info(); int result = make_ext4fs(device, length); if (result != 0) { LOGE("format_volume: make_extf4fs failed on %s\n", device); return -1; } return 0; } return format_unknown_device(device, path, fs_type); }
/** KTXファイルを読み込む. */ TexturePtr LoadKTX(const char* filename, GLint minFilter, GLint magFilter) { auto file = Mai::FileSystem::Open(filename); if (!file) { LOGW("cannot open:'%s'", filename); return nullptr; } const size_t size = file->Size(); if (size <= sizeof(KTXHeader)) { LOGW("illegal size:'%s'", filename); return nullptr; } KTXHeader header; int result = file->Read(&header, sizeof(KTXHeader)); if (result < 0 || !IsKTXHeader(header)) { LOGW("illegal header:'%s'", filename); return nullptr; } TexturePtr p = std::make_shared<Texture>(); Texture& tex = static_cast<Texture&>(*p); const Endian endianness = GetEndian(header); const GLenum type = GetValue(&header.glType, endianness); const GLenum format = GetValue(type ? &header.glFormat : &header.glBaseInternalFormat, endianness); const int faceCount = GetValue(&header.numberOfFaces, endianness); const int mipCount = GetValue(&header.numberOfMipmapLevels, endianness); tex.internalFormat = GetValue(type ? &header.glBaseInternalFormat : &header.glInternalFormat, endianness); tex.width = GetValue(&header.pixelWidth, endianness); tex.height = GetValue(&header.pixelHeight, endianness); tex.target = faceCount == 6 ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; const uint32_t off = GetValue(&header.bytesOfKeyValueData, endianness); file->Seek(file->Position() + off); glGenTextures(1, &tex.texId); glBindTexture(tex.Target(), tex.texId); std::vector<uint8_t> data; GLsizei curWidth = tex.Width(); GLsizei curHeight = tex.Height(); for (int mipLevel = 0; mipLevel < (mipCount ? mipCount : 1); ++mipLevel) { uint32_t imageSize; result = file->Read(&imageSize, 4); if (result < 0) { LOGW("can't read(miplevel=%d):'%s'", mipLevel, filename); return nullptr; } imageSize = GetValue(&imageSize, endianness); const uint32_t imageSizeWithPadding = (imageSize + 3) & ~3; data.resize(imageSizeWithPadding * faceCount); result = file->Read(&data[0], data.size()); if (result < 0) { LOGW("can't read(miplevel=%d):'%s'", mipLevel, filename); return nullptr; } const uint8_t* pImage = reinterpret_cast<const uint8_t*>(&data[0]); const GLenum target = tex.Target() == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : GL_TEXTURE_2D; for (int faceIndex = 0; faceIndex < faceCount; ++faceIndex) { if (type == 0) { glCompressedTexImage2D(target + faceIndex, mipLevel, tex.InternalFormat(), curWidth, curHeight, 0, imageSize, pImage); } else { glTexImage2D(target + faceIndex, mipLevel, tex.InternalFormat(), curWidth, curHeight, 0, format, type, pImage); } const GLenum result = glGetError(); switch(result) { case GL_NO_ERROR: break; case GL_INVALID_OPERATION: LOGW("glCompressed/TexImage2D return GL_INVALID_OPERATION"); break; default: LOGW("glCompressed/TexImage2D return error code 0x%04x", result); break; } pImage += imageSizeWithPadding; } curWidth = std::max(1, curWidth / 2); curHeight = std::max(1, curHeight / 2); } glTexParameteri(tex.Target(), GL_TEXTURE_MIN_FILTER, CorrectFilter(mipCount, minFilter)); glTexParameteri(tex.Target(), GL_TEXTURE_MAG_FILTER, CorrectFilter(mipCount, magFilter)); glTexParameteri(tex.Target(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(tex.Target(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(tex.Target(), 0); LOGI("Load %s(ID:%x).", filename, tex.texId); return p; }
status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount) { AutoMutex lock(mLock); int active; status_t result = NO_ERROR; audio_track_cblk_t* cblk = mCblk; uint32_t framesReq = audioBuffer->frameCount; uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS; audioBuffer->frameCount = 0; audioBuffer->size = 0; uint32_t framesReady = cblk->framesReady(); if (framesReady == 0) { cblk->lock.lock(); goto start_loop_here; while (framesReady == 0) { active = mActive; if (UNLIKELY(!active)) { cblk->lock.unlock(); return NO_MORE_BUFFERS; } if (UNLIKELY(!waitCount)) { cblk->lock.unlock(); return WOULD_BLOCK; } if (!(cblk->flags & CBLK_INVALID_MSK)) { mLock.unlock(); result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs)); cblk->lock.unlock(); mLock.lock(); if (mActive == 0) { return status_t(STOPPED); } cblk->lock.lock(); } if (cblk->flags & CBLK_INVALID_MSK) { goto create_new_record; } if (__builtin_expect(result!=NO_ERROR, false)) { cblk->waitTimeMs += waitTimeMs; if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) { LOGW( "obtainBuffer timed out (is the CPU pegged?) " "user=%08x, server=%08x", cblk->user, cblk->server); cblk->lock.unlock(); result = mAudioRecord->start(); cblk->lock.lock(); if (result == DEAD_OBJECT) { android_atomic_or(CBLK_INVALID_ON, &cblk->flags); create_new_record: result = AudioRecord::restoreRecord_l(cblk); } if (result != NO_ERROR) { LOGW("obtainBuffer create Track error %d", result); cblk->lock.unlock(); return result; } cblk->waitTimeMs = 0; } if (--waitCount == 0) { cblk->lock.unlock(); return TIMED_OUT; } } // read the server count again start_loop_here: framesReady = cblk->framesReady(); } cblk->lock.unlock(); } cblk->waitTimeMs = 0; if (framesReq > framesReady) { framesReq = framesReady; } uint32_t u = cblk->user; uint32_t bufferEnd = cblk->userBase + cblk->frameCount; if (u + framesReq > bufferEnd) { framesReq = bufferEnd - u; } audioBuffer->flags = 0; audioBuffer->channelCount= mChannelCount; audioBuffer->format = mFormat; audioBuffer->frameCount = framesReq; audioBuffer->size = framesReq*cblk->frameSize; audioBuffer->raw = (int8_t*)cblk->buffer(u); active = mActive; return active ? status_t(NO_ERROR) : status_t(STOPPED); }
JNIEXPORT void JNICALL Java_com_vmc_ipc_view_VideoStageSurfaceHardware_nativeSetSurfaceView (JNIEnv *env, jobject thiz, jobject surface){ LOGW("%s",__FUNCTION__); ANativeWindow *window = NULL; #if 0 if(g_window) { //ANativeWindow_release(g_window); LOGW("%s err alreay has window %p",__FUNCTION__, g_window); //CloseRTMPConnection(); } #endif javatool::InitEnv(env); javatool::InitJavaMethods(); if(surface) { window = ANativeWindow_fromSurface( env, surface ); LOGW("%s Got window %p",__FUNCTION__, window); } else { LOGW("%s surface is null",__FUNCTION__); } if(window != NULL) { /* static bool bFirst = true; if(bFirst) { bFirst = false; } else { return ; }*/ int width = ANativeWindow_getWidth(window); int height = ANativeWindow_getHeight(window); LOGW("Got window %d %d", width,height); //LOGW("window buffer count %d",window); // H264DecoderSetNativeWindow(window); // g_objVideoSurface = env->NewGlobalRef(thiz); // InitVideoSurfaceJavaMethods(); #if 1 #ifndef SOFT_DECODE_ONLY // H264DecoderStart(window,H264ReadHardDecCallback,H264DecodeDoneCallback,NULL); // VmcSetDecodeStrategy(DECODE_AUTO); #else // VmcSetDecodeStrategy(DECODE_SOFTWARE); #endif //CloseRTMPConnection(); videostream::SetNativeWindow(window); VmcInitSysDecoder(window); //StartSoftDecoder(); //StartRTMPThread(); #else StartRTMPThread(); #endif // ANativeWindow_release(g_window); } else { /*void *result = NULL; g_bThreadRunning = false; CloseRTMPClient(); if(g_tidRTMP) { pthread_join(g_tidRTMP,&result); g_tidRTMP = 0; }*/ /*if(VmcGetAjustedDecodeMode() != DECODE_SOFTWARE) { CloseRTMPConnection(); }*/ VmcCloseSysDecoder(); videostream::SetNativeWindow(NULL); } }
OMX_ERRORTYPE OMXVideoEncoderBase::GetConfigVideoIntraVOPRefresh(OMX_PTR) { LOGW("GetConfigVideoIntraVOPRefresh is not supported."); return OMX_ErrorUnsupportedSetting; }
// generate vertex array object void Mesh::generateVAO(int programId) { GLuint tmpID; if (!vao_dirty_) { return; } obtainDeleter(); if (vertices_.size() == 0 && normals_.size() == 0 && tex_coords_.size() == 0) { std::string error = "no vertex data yet, shouldn't call here. "; throw error; } if (0 != normals_.size() && vertices_.size() != normals_.size()) { LOGW("mesh: number of vertices and normals do not match! vertices %d, normals %d", vertices_.size(), normals_.size()); } GLuint vaoID_; GLuint triangle_vboID_; GLuint static_vboID_; auto it = program_ids_.find(programId); if (it != program_ids_.end()) { GLVaoVboId ids = it->second; vaoID_ = ids.vaoID; triangle_vboID_ = ids.triangle_vboID; static_vboID_ = ids.static_vboID; } else { glGenVertexArrays(1, &vaoID_); glGenBuffers(1, &triangle_vboID_); glGenBuffers(1, &static_vboID_); } glBindVertexArray(vaoID_); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_vboID_); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * indices_.size(), &indices_[0], GL_STATIC_DRAW); numTriangles_ = indices_.size() / 3; attrMapping.clear(); int totalStride; int attrLength; createAttributeMapping(programId, totalStride, attrLength); std::vector<GLfloat> buffer; createBuffer(buffer, attrLength); glBindBuffer(GL_ARRAY_BUFFER, static_vboID_); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * buffer.size(), &buffer[0], GL_STATIC_DRAW); int localCnt = 0; for ( std::vector<GLAttributeMapping>::iterator it = attrMapping.begin(); it != attrMapping.end(); ++it) { GLAttributeMapping currData = *it; glVertexAttribPointer(currData.index, currData.size, currData.type, 0, totalStride * sizeof(GLfloat), (GLvoid*) (currData.offset * sizeof(GLfloat))); glEnableVertexAttribArray(currData.index); } // done generation glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (it == program_ids_.end()) { GLVaoVboId id; id.vaoID = vaoID_; id.static_vboID = static_vboID_; id.triangle_vboID = triangle_vboID_; program_ids_[programId] = id; } vao_dirty_ = false; }
bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType, int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags, int32_t* outValue, nsecs_t* outWhen) { *outDeviceId = 0; *outType = 0; *outScancode = 0; *outKeycode = 0; *outFlags = 0; *outValue = 0; *outWhen = 0; status_t err; fd_set readfds; int maxFd = -1; int cc; int i; int res; int pollres; struct input_event iev; // Note that we only allow one caller to getEvent(), so don't need // to do locking here... only when adding/removing devices. if (!mOpened) { mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR; mOpened = true; } while(1) { // First, report any devices that had last been added/removed. if (mClosingDevices != NULL) { device_t* device = mClosingDevices; LOGV("Reporting device closed: id=0x%x, name=%s\n", device->id, device->path.string()); mClosingDevices = device->next; *outDeviceId = device->id; if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0; *outType = DEVICE_REMOVED; delete device; return true; } if (mOpeningDevices != NULL) { device_t* device = mOpeningDevices; LOGV("Reporting device opened: id=0x%x, name=%s\n", device->id, device->path.string()); mOpeningDevices = device->next; *outDeviceId = device->id; if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0; *outType = DEVICE_ADDED; return true; } release_wake_lock(WAKE_LOCK_ID); pollres = poll(mFDs, mFDCount, -1); acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); if (pollres <= 0) { if (errno != EINTR) { LOGW("select failed (errno=%d)\n", errno); usleep(100000); } continue; } //printf("poll %d, returned %d\n", mFDCount, pollres); // mFDs[0] is used for inotify, so process regular events starting at mFDs[1] for(i = 1; i < mFDCount; i++) { if(mFDs[i].revents) { LOGV("revents for %d = 0x%08x", i, mFDs[i].revents); if(mFDs[i].revents & POLLIN) { res = read(mFDs[i].fd, &iev, sizeof(iev)); if (res == sizeof(iev)) { LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d", mDevices[i]->path.string(), (int) iev.time.tv_sec, (int) iev.time.tv_usec, iev.type, iev.code, iev.value); *outDeviceId = mDevices[i]->id; if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0; *outType = iev.type; *outScancode = iev.code; if (iev.type == EV_KEY) { err = mDevices[i]->layoutMap->map(iev.code, outKeycode, outFlags); LOGV("iev.code=%d outKeycode=%d outFlags=0x%08x err=%d\n", iev.code, *outKeycode, *outFlags, err); if (err != 0) { *outKeycode = 0; *outFlags = 0; } } else { *outKeycode = iev.code; } *outValue = iev.value; *outWhen = s2ns(iev.time.tv_sec) + us2ns(iev.time.tv_usec); return true; } else { if (res<0) { LOGW("could not get event (errno=%d)", errno); } else { LOGE("could not get event (wrong size: %d)", res); } continue; } } } } // read_notify() will modify mFDs and mFDCount, so this must be done after // processing all other events. if(mFDs[0].revents & POLLIN) { read_notify(mFDs[0].fd); } } }
/* * Retrieves the list of networks from Supplicant * and merge them into our current list */ int Supplicant::refreshNetworkList() { char *reply; size_t len = 4096; if (!(reply = (char *) malloc(len))) { errno = ENOMEM; return -1; } if (sendCommand("LIST_NETWORKS", reply, &len)) { free(reply); return -1; } char *linep; char *linep_next = NULL; if (!strtok_r(reply, "\n", &linep_next)) { LOGW("Malformatted network list\n"); free(reply); errno = EIO; return -1; } PropertyManager *pm = NetworkManager::Instance()->getPropMngr(); pthread_mutex_lock(&mNetworksLock); int num_added = 0; int num_refreshed = 0; int num_removed = 0; while((linep = strtok_r(NULL, "\n", &linep_next))) { // TODO: Move the decode into a static method so we // don't create new_wn when we don't have to. WifiNetwork *new_wn = new WifiNetwork(mController, this, linep); WifiNetwork *merge_wn; if ((merge_wn = this->lookupNetwork_UNLOCKED(new_wn->getNetworkId()))) { num_refreshed++; if (merge_wn->refresh()) { LOGW("Error refreshing network %d (%s)", merge_wn->getNetworkId(), strerror(errno)); } delete new_wn; } else { num_added++; char new_ns[20]; snprintf(new_ns, sizeof(new_ns), "wifi.net.%d", new_wn->getNetworkId()); new_wn->attachProperties(pm, new_ns); mNetworks->push_back(new_wn); if (new_wn->refresh()) { LOGW("Unable to refresh network id %d (%s)", new_wn->getNetworkId(), strerror(errno)); } } } if (!mNetworks->empty()) { // TODO: Add support for detecting removed networks WifiNetworkCollection::iterator i; for (i = mNetworks->begin(); i != mNetworks->end(); ++i) { if (0) { num_removed++; char del_ns[20]; snprintf(del_ns, sizeof(del_ns), "wifi.net.%d", (*i)->getNetworkId()); (*i)->detachProperties(pm, del_ns); delete (*i); i = mNetworks->erase(i); } } } LOGD("Networks added %d, refreshed %d, removed %d\n", num_added, num_refreshed, num_removed); pthread_mutex_unlock(&mNetworksLock); free(reply); return 0; }