const char* CameraProperties::Properties::get(const char * prop) { String8 value = mProperties->valueFor(String8(prop)); return value.string(); }
status_t CameraService::dump(int fd, const Vector<String16>& args) { static const char* kDeadlockedString = "CameraService may be deadlocked\n"; const size_t SIZE = 256; char buffer[SIZE]; String8 result; if (checkCallingPermission(String16("android.permission.DUMP")) == false) { snprintf(buffer, SIZE, "Permission Denial: " "can't dump CameraService from pid=%d, uid=%d\n", getCallingPid(), getCallingUid()); result.append(buffer); write(fd, result.string(), result.size()); } else { bool locked = tryLock(mServiceLock); // failed to lock - CameraService is probably deadlocked if (!locked) { String8 result(kDeadlockedString); write(fd, result.string(), result.size()); } bool hasClient = false; for (int i = 0; i < mNumberOfCameras; i++) { sp<Client> client = mClient[i].promote(); if (client == 0) continue; hasClient = true; sprintf(buffer, "Client[%d] (%p) PID: %d\n", i, client->getCameraClient()->asBinder().get(), client->mClientPid); result.append(buffer); write(fd, result.string(), result.size()); client->mHardware->dump(fd, args); } if (!hasClient) { result.append("No camera client yet.\n"); write(fd, result.string(), result.size()); } if (locked) mServiceLock.unlock(); // change logging level int n = args.size(); for (int i = 0; i + 1 < n; i++) { if (args[i] == String16("-v")) { String8 levelStr(args[i+1]); int level = atoi(levelStr.string()); sprintf(buffer, "Set Log Level to %d", level); result.append(buffer); setLogLevel(level); } } } return NO_ERROR; }
status_t CameraService::dump(int fd, const Vector<String16>& args) { String8 result; if (checkCallingPermission(String16("android.permission.DUMP")) == false) { result.appendFormat("Permission Denial: " "can't dump CameraService from pid=%d, uid=%d\n", getCallingPid(), getCallingUid()); write(fd, result.string(), result.size()); } else { bool locked = tryLock(mServiceLock); // failed to lock - CameraService is probably deadlocked if (!locked) { result.append("CameraService may be deadlocked\n"); write(fd, result.string(), result.size()); } bool hasClient = false; if (!mModule) { result = String8::format("No camera module available!\n"); write(fd, result.string(), result.size()); return NO_ERROR; } result = String8::format("Camera module HAL API version: 0x%x\n", mModule->common.hal_api_version); result.appendFormat("Camera module API version: 0x%x\n", mModule->common.module_api_version); result.appendFormat("Camera module name: %s\n", mModule->common.name); result.appendFormat("Camera module author: %s\n", mModule->common.author); result.appendFormat("Number of camera devices: %d\n\n", mNumberOfCameras); write(fd, result.string(), result.size()); for (int i = 0; i < mNumberOfCameras; i++) { result = String8::format("Camera %d static information:\n", i); camera_info info; status_t rc = mModule->get_camera_info(i, &info); if (rc != OK) { result.appendFormat(" Error reading static information!\n"); write(fd, result.string(), result.size()); } else { result.appendFormat(" Facing: %s\n", info.facing == CAMERA_FACING_BACK ? "BACK" : "FRONT"); result.appendFormat(" Orientation: %d\n", info.orientation); int deviceVersion; if (mModule->common.module_api_version < CAMERA_MODULE_API_VERSION_2_0) { deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; } else { deviceVersion = info.device_version; } result.appendFormat(" Device version: 0x%x\n", deviceVersion); if (deviceVersion >= CAMERA_DEVICE_API_VERSION_2_0) { result.appendFormat(" Device static metadata:\n"); write(fd, result.string(), result.size()); dump_indented_camera_metadata(info.static_camera_characteristics, fd, 2, 4); } else { write(fd, result.string(), result.size()); } } sp<Client> client = mClient[i].promote(); if (client == 0) { result = String8::format(" Device is closed, no client instance\n"); write(fd, result.string(), result.size()); continue; } hasClient = true; result = String8::format(" Device is open. Client instance dump:\n"); write(fd, result.string(), result.size()); client->dump(fd, args); } if (!hasClient) { result = String8::format("\nNo active camera clients yet.\n"); write(fd, result.string(), result.size()); } if (locked) mServiceLock.unlock(); // change logging level int n = args.size(); for (int i = 0; i + 1 < n; i++) { String16 verboseOption("-v"); if (args[i] == verboseOption) { String8 levelStr(args[i+1]); int level = atoi(levelStr.string()); result = String8::format("\nSetting log level to %d.\n", level); setLogLevel(level); write(fd, result.string(), result.size()); } } } return NO_ERROR; }
status_t AudioStreamInMotorola::dump(int fd, const Vector<String16>& args) { const size_t SIZE = 256; char buffer[SIZE]; String8 result; result.append("AudioStreamInMotorola::dump\n"); snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); result.append(buffer); snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); result.append(buffer); snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); result.append(buffer); snprintf(buffer, SIZE, "\tformat: %d\n", format()); result.append(buffer); snprintf(buffer, SIZE, "\tmHardware: %p\n", mHardware); result.append(buffer); snprintf(buffer, SIZE, "\tmFd count: %d\n", mFd); result.append(buffer); snprintf(buffer, SIZE, "\tmStandby: %d\n", mStandby); result.append(buffer); snprintf(buffer, SIZE, "\tmRetryCount: %d\n", mRetryCount); result.append(buffer); ::write(fd, result.string(), result.size()); return NO_ERROR; }
status_t StagefrightRecorder::setParameter( const String8 &key, const String8 &value) { LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); if (key == "max-duration") { int64_t max_duration_ms; if (safe_strtoi64(value.string(), &max_duration_ms)) { return setParamMaxFileDurationUs(1000LL * max_duration_ms); } } else if (key == "max-filesize") { int64_t max_filesize_bytes; if (safe_strtoi64(value.string(), &max_filesize_bytes)) { return setParamMaxFileSizeBytes(max_filesize_bytes); } } else if (key == "interleave-duration-us") { int32_t durationUs; if (safe_strtoi32(value.string(), &durationUs)) { return setParamInterleaveDuration(durationUs); } } else if (key == "param-movie-time-scale") { int32_t timeScale; if (safe_strtoi32(value.string(), &timeScale)) { return setParamMovieTimeScale(timeScale); } } else if (key == "param-use-64bit-offset") { int32_t use64BitOffset; if (safe_strtoi32(value.string(), &use64BitOffset)) { return setParam64BitFileOffset(use64BitOffset != 0); } } else if (key == "param-track-time-status") { int64_t timeDurationUs; if (safe_strtoi64(value.string(), &timeDurationUs)) { return setParamTrackTimeStatus(timeDurationUs); } } else if (key == "audio-param-sampling-rate") { int32_t sampling_rate; if (safe_strtoi32(value.string(), &sampling_rate)) { return setParamAudioSamplingRate(sampling_rate); } } else if (key == "audio-param-number-of-channels") { int32_t number_of_channels; if (safe_strtoi32(value.string(), &number_of_channels)) { return setParamAudioNumberOfChannels(number_of_channels); } } else if (key == "audio-param-encoding-bitrate") { int32_t audio_bitrate; if (safe_strtoi32(value.string(), &audio_bitrate)) { return setParamAudioEncodingBitRate(audio_bitrate); } } else if (key == "audio-param-time-scale") { int32_t timeScale; if (safe_strtoi32(value.string(), &timeScale)) { return setParamAudioTimeScale(timeScale); } } else if (key == "video-param-encoding-bitrate") { int32_t video_bitrate; if (safe_strtoi32(value.string(), &video_bitrate)) { return setParamVideoEncodingBitRate(video_bitrate); } } else if (key == "video-param-rotation-angle-degrees") { int32_t degrees; if (safe_strtoi32(value.string(), °rees)) { return setParamVideoRotation(degrees); } } else if (key == "video-param-i-frames-interval") { int32_t seconds; if (safe_strtoi32(value.string(), &seconds)) { return setParamVideoIFramesInterval(seconds); } } else if (key == "video-param-encoder-profile") { int32_t profile; if (safe_strtoi32(value.string(), &profile)) { return setParamVideoEncoderProfile(profile); } } else if (key == "video-param-encoder-level") { int32_t level; if (safe_strtoi32(value.string(), &level)) { return setParamVideoEncoderLevel(level); } } else if (key == "video-param-camera-id") { int32_t cameraId; if (safe_strtoi32(value.string(), &cameraId)) { return setParamVideoCameraId(cameraId); } } else if (key == "video-param-time-scale") { int32_t timeScale; if (safe_strtoi32(value.string(), &timeScale)) { return setParamVideoTimeScale(timeScale); } } else { LOGE("setParameter: failed to find key %s", key.string()); } return BAD_VALUE; }
int audio_volume_control_handler(char* cmdline, ATOP_t at_op, char* response) { ALOGD("audio cmd handler handles cmdline:%s", cmdline); int actinoID = 0; int mStreamVolumeIndex = 0; int mPhoneMode = 0; float mVoiceVolume = 0.0; bool bMusic_FM_Mute = false; char sKeyParams[64]; char *pParam = sKeyParams; String8 keyValuePairs; // five level for voice music and FM stream type int mStreamVolumeValue[5][3] = {{0,0,0},{1,1,1},{4,8,4},{5,12,12},{6,13,13}}; float mVoiceVolumeValue[5] = {0.0,0.1,0.45,0.9,1.0}; int mVoiceVolumeLevelValue[6] = {0,0,3,6,4,5}; keyValuePairs = AudioSystem::getParameters(0, String8("GetPhoneMode")); ALOGD("audio cmd handler get phone mode:%s", keyValuePairs.string()); strcpy(sKeyParams, keyValuePairs.string()); at_tok_start_flag(&pParam, '='); at_tok_nextint(&pParam, &mPhoneMode); switch(at_op){ case AT_ACTION_OP: case AT_READ_OP: case AT_TEST_OP: if (mPhoneMode==AUDIO_MODE_IN_CALL || mPhoneMode==AUDIO_MODE_IN_COMMUNICATION || Acoustic_Loopback_On){ keyValuePairs = AudioSystem::getParameters(0, String8("AT_GetVolumeMute")); ALOGD("audio cmd handler get voice mute:%s", keyValuePairs.string()); strcpy(sKeyParams, keyValuePairs.string()); pParam = sKeyParams; at_tok_start_flag(&pParam, '='); bMusic_FM_Mute = strcmp(pParam,"true")==0?true:false; if (!bMusic_FM_Mute) { AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, &mStreamVolumeIndex, AUDIO_DEVICE_OUT_EARPIECE); ALOGD("audio cmd handler get voice volume index:%d", mStreamVolumeIndex); if (mStreamVolumeIndex==1) { sprintf(response,"\r\n1\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==4) { sprintf(response,"\r\n2\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==5) { sprintf(response,"\r\n3\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==6) { sprintf(response,"\r\n4\r\n\r\nOK\r\n"); }else { sprintf(response,"\r\nNot Min/Default/Max Volume\r\n\r\nOK\r\n"); } }else { sprintf(response,"\r\n0\r\n\r\nOK\r\n"); } }else{ AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_MUSIC, &mStreamVolumeIndex, AUDIO_DEVICE_OUT_SPEAKER); if(mStreamVolumeIndex==0) { sprintf(response,"\r\n0\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==1){ sprintf(response,"\r\n1\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==8){ sprintf(response,"\r\n2\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==12){ sprintf(response,"\r\n3\r\n\r\nOK\r\n"); }else if (mStreamVolumeIndex==13){ sprintf(response,"\r\n4\r\n\r\nOK\r\n"); } else { sprintf(response,"\r\nNot Min/Default/Max Volume\r\n\r\nOK\r\n"); } } break; case AT_SET_OP: at_tok_nextint(&cmdline, &actinoID); if (actinoID<0 || actinoID>4) { sprintf(response,"\r\nVLC ERROR\r\n"); break; } if (mPhoneMode==AUDIO_MODE_IN_CALL || mPhoneMode==AUDIO_MODE_IN_COMMUNICATION || Acoustic_Loopback_On) { if (actinoID==0) { AudioSystem::setParameters(0, String8("AT_SetVolumeMute=1")); }else{ AudioSystem::setParameters(0, String8("AT_SetVolumeMute=0")); #if 0 if (Acoustic_Loopback_On) { sprintf(sKeyParams, "AT_SetACSVolume=%f", mVoiceVolumeValue[actinoID]); AudioSystem::setParameters(0, String8(sKeyParams)); } AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, mStreamVolumeValue[actinoID][0],AUDIO_DEVICE_OUT_EARPIECE); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, mStreamVolumeValue[actinoID][0],AUDIO_DEVICE_OUT_SPEAKER); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, mStreamVolumeValue[actinoID][0],AUDIO_DEVICE_OUT_WIRED_HEADSET); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_VOICE_CALL, mStreamVolumeValue[actinoID][0],AUDIO_DEVICE_OUT_WIRED_HEADPHONE); #endif } }else{ // unmute music stream, and set music volume AudioSystem::setStreamMute(AUDIO_STREAM_MUSIC, false); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_MUSIC, mStreamVolumeValue[actinoID][1],AUDIO_DEVICE_OUT_SPEAKER); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_MUSIC, mStreamVolumeValue[actinoID][1],AUDIO_DEVICE_OUT_WIRED_HEADSET); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_MUSIC, mStreamVolumeValue[actinoID][1],AUDIO_DEVICE_OUT_WIRED_HEADPHONE); //unmute FM stream, and set FM volume AudioSystem::setStreamMute(AUDIO_STREAM_FM, false); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_FM, mStreamVolumeValue[actinoID][2],AUDIO_DEVICE_OUT_SPEAKER); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_FM, mStreamVolumeValue[actinoID][2],AUDIO_DEVICE_OUT_WIRED_HEADSET); AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_FM, mStreamVolumeValue[actinoID][2],AUDIO_DEVICE_OUT_WIRED_HEADPHONE); } // Audioyusuhardware need to know the set value if (actinoID != 0) { sprintf(sKeyParams, "AT_SetACSVolume=%d", mVoiceVolumeLevelValue[actinoID]); AudioSystem::setParameters(0, String8(sKeyParams)); } sprintf(response, "\r\n[%d]VOLUME\r\n\r\nOK\r\n",actinoID); break; default: break; } return 0; }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { int c = getIntField(mHealthdConfig->batteryCurrentNowPath); char b[20]; snprintf(b, sizeof(b), " c=%d", c / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } KLOG_WARNING(LOG_TAG, "%s chg=%s%s%s\n", dmesgline, props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
// static sp<MediaExtractor> MediaExtractor::Create( const sp<DataSource> &source, const char *mime) { sp<AMessage> meta; LCHLOGD1("mime=%s, MIME=%s", mime, source->getMIMEType().string()); String8 tmp; if (mime == NULL) { float confidence; if (!source->sniff(&tmp, &confidence, &meta)) { LOGV("FAILED to autodetect media content."); return NULL; } mime = tmp.string(); LOGV("Autodetected media content as '%s' with confidence %.2f", mime, confidence); } bool isDrm = false; // DRM MIME type syntax is "drm+type+original" where // type is "es_based" or "container_based" and // original is the content's cleartext MIME type if (!strncmp(mime, "drm+", 4)) { const char *originalMime = strchr(mime+4, '+'); if (originalMime == NULL) { // second + not found return NULL; } ++originalMime; if (!strncmp(mime, "drm+es_based+", 13)) { // DRMExtractor sets container metadata kKeyIsDRM to 1 return new DRMExtractor(source, originalMime); } else if (!strncmp(mime, "drm+container_based+", 20)) { mime = originalMime; isDrm = true; } else { return NULL; } } MediaExtractor *ret = NULL; /* a@nufront begin */ /* if (source->getUri() && strlen(source->getUri()) && !isSystemMedia(source->getUri())) { using namespace FFMPEG; ret = new FFmpegExtractor(source); LOGD("zx, create FFmpegExtractor."); } else { */ /* a@nufront end */ #if !defined(USE_FFMPEG_EXTRACTOR) ZXLOGD("not use FFmpegExtractor."); #warning "not defined USE_FFMPEG_EXTRACTOR" #endif LCHLOGD1("mime=%s, file=%s", mime, source->getUri().string()); if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4) || !strcasecmp(mime, "audio/mp4")) { ret = new MPEG4Extractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) { ret = new MP3Extractor(source, meta); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB) || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) { ret = new AMRExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_FLAC)) { ret = new FLACExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) { ret = new WAVExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_OGG)) { ret = new OggExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA)) { ret = new MatroskaExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2TS)) { ret = new MPEG2TSExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WVM)) { ret = new WVMExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC_ADTS)) { ret = new AACExtractor(source); } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2PS)) { ret = new MPEG2PSExtractor(source); } #if defined(USE_FFMPEG_EXTRACTOR) #warning "defined USE_FFMPEG_EXTRACTOR" else { using namespace FFMPEG; ret = new FFmpegExtractor(source); ZXLOGD("use FFmpegExtractor."); /*a@nufront start: add open status check*/ if (((FFmpegExtractor*)ret)->IsOpenFailed()) { delete ret; ret = NULL; } /*a@nufront end*/ } #endif /* a@nufront begin */ /* else { using namespace FFMPEG; ret = new FFmpegExtractor(source); } } */ /* a@nufront end */ if (ret != NULL) { if (isDrm) { ret->setDrmFlag(true); } else { ret->setDrmFlag(false); } } return ret; }
bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) { ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.string()); String8 extension = path.getPathExtension(); extension.toLower(); return (String8(".passthru") == extension); }
/****************************************************************************** * Command * test_engineer <-h> <-shot-mode=testshot> <-shot-count=1> <-picture-size=2560x1920> <-preview-size=640x480> <-display-orientation=90> * * -h: help * -shot-count: shot count; 1 by default. * -picture-size: picture size; 2560x1920 by default. * -preview-size: preview size; 640x480 by default. * -shot-mode: shot mode; testshot by default. * For example: "normal", "hdr", "continuousshot", ...... * -display-orientation: display orientation; 90 by default. * ******************************************************************************/ bool CmdImp:: onParseCommand(Vector<String8>& rvCmd) { // (1) Set default. mShotMode = "testshot"; mShotCount = 1; mPictureSize = Size(2560, 1920); mPreviewSize = Size(640, 480); mDisplayOrientation = 90; mPictureOrientation = 0; // (2) Start to parse commands. for (size_t i = 1; i < rvCmd.size(); i++) { if ( rvCmd[i] == "-h" ) { String8 text; text += "\n"; text += "\n test_engineer <-h> <-shot-mode=testshot> <-shot-count=1> <-picture-size=2560x1920> <-preview-size=640x480> <-display-orientation=90 -jpeg-orienation=0>"; text += "\n -h: help"; text += "\n -shot-count: shot count; 1 by default."; text += "\n -picture-size: picture size; 2560x1920 by default."; text += "\n -preview-size: preview size; 640x480 by default."; text += "\n -shot-mode: shot mode; testshot by default."; text += "\n For example: normal, hdr, continuousshot, ......"; text += "\n -display-orientation: display orientation; 90 by default."; text += "\n -pic-orientation: jpeg orienation; 0 by default."; text += "\n -engineer-capture-size: preview, capture, video."; text += "\n -engineer-capture-type: pure-raw, processed-raw, jpeg-only."; text += "\n -engineer-raw-save-path: /sdcard/preview.raw, for example"; text += "\n -flicker: 50, 60."; MY_LOGD("%s", text.string()); return false; } // String8 key, val; parseOneCmdArgument(rvCmd[i], key, val); // MY_LOGD("<key/val>=<%s/%s>", key.string(), val.string()); // // if ( key == "-engineer-raw-save-path" ) { ms8RawSavePath = val; MY_LOGD("ms8RawSavePath = %s", ms8RawSavePath.string()); continue; } if ( key == "-engineer-capture-size" ) { ms8CaptureSize = val; MY_LOGD("ms8CaptureSize = %s", ms8CaptureSize.string()); continue; } if ( key == "-engineer-capture-type" ) { ms8CaptureType = val; MY_LOGD("ms8CaptureType = %s", ms8CaptureType.string()); continue; } if ( key == "-flicker" ) { ms8Flicker = val; MY_LOGD("ms8Flicker = %s", ms8Flicker.string()); continue; } if ( key == "-shot-mode" ) { mShotMode = val; // In engineer mode, use EngShot only continue; } // if ( key == "-shot-count" ) { mShotCount = ::atoi(val); continue; } // if ( key == "-picture-size" ) { ::sscanf(val.string(), "%dx%d", &mPictureSize.width, &mPictureSize.height); MY_LOGD("picture-size : %d %d", mPictureSize.width, mPictureSize.height); continue; } // if ( key == "-preview-size" ) { ::sscanf(val.string(), "%dx%d", &mPreviewSize.width, &mPreviewSize.height); MY_LOGD("preview-size : %d %d", mPreviewSize.width, mPreviewSize.height); continue; } // if ( key == "-display-orientation" ) { mDisplayOrientation = ::atoi(val); continue; } // if (key == "-pic-orientation" ) { mPictureOrientation = ::atoi(val); printf("picture orientation = %d\n", mPictureOrientation); continue; } } return true; }
void parseScanResults(String16& str, const char *reply) { unsigned int lineBeg = 0, lineEnd = 0; size_t replyLen = strlen(reply); char *pos = NULL; char ssid[BUF_SIZE] = {0}; char ssid_utf8[BUF_SIZE] = {0}; char ssid_txt[BUF_SIZE] ={0}; bool isUTF8 = false, isCh = false; char buf[BUF_SIZE] = {0}; String8 line; UConverterType conType = UCNV_UTF8; char dest[CONVERT_LINE_LEN] = {0}; UErrorCode err = U_ZERO_ERROR; UConverter* pConverter = ucnv_open(CHARSET_CN, &err); if (U_FAILURE(err)) { ALOGE("ucnv_open error"); return; } /* Parse every line of the reply to construct accessPointObjectItem list */ for (lineBeg = 0, lineEnd = 0; lineEnd <= replyLen; ++lineEnd) { if (lineEnd == replyLen || '\n' == reply[lineEnd]) { line.setTo(reply + lineBeg, lineEnd - lineBeg + 1); if (DBG) ALOGD("%s, line=%s ", __FUNCTION__, line.string()); if (strncmp(line.string(), "ssid=", 5) == 0) { sscanf(line.string() + 5, "%[^\n]", ssid); ssid_decode(buf,BUF_SIZE,ssid); isUTF8 = isUTF8String(buf,sizeof(buf)); isCh = false; for (pos = buf; '\0' != *pos; pos++) { if (0x80 == (*pos & 0x80)) { isCh = true; break; } } if (DBG) ALOGD("%s, ssid = %s, buf = %s,isUTF8= %d, isCh = %d", __FUNCTION__, ssid, buf ,isUTF8, isCh); if (!isUTF8 && isCh) { ucnv_toAlgorithmic(conType, pConverter, dest, CONVERT_LINE_LEN, buf, strlen(buf), &err); if (U_FAILURE(err)) { ALOGE("ucnv_toUChars error"); goto EXIT; } ssid_encode(ssid_txt, BUF_SIZE, dest, strlen(dest)); if (DBG) ALOGD("%s, ssid_txt = %s", __FUNCTION__,ssid_txt); str += String16("ssid="); str += String16(ssid_txt); str += String16("\n"); strncpy(ssid_utf8, dest, strlen(dest)); memset(dest, 0, CONVERT_LINE_LEN); memset(ssid_txt, 0, BUF_SIZE); } else { memset(buf, 0, BUF_SIZE); str += String16(line.string()); } } else if (strncmp(line.string(), "====", 4) == 0) { if (DBG) ALOGD("After sscanf,ssid:%s, isCh:%d", ssid, isCh); if( !isUTF8 && isCh){ if (DBG) ALOGD("add AP Object Item, ssid:%s l=%d, UTF8:%s, l=%d", ssid, strlen(ssid), ssid_utf8, strlen(ssid_utf8)); addAPObjectItem(buf, ssid_utf8); memset(buf, 0, BUF_SIZE); } } if (strncmp(line.string(), "ssid=", 5) != 0) str += String16(line.string()); lineBeg = lineEnd + 1; } } EXIT: ucnv_close(pConverter); }
static jobject android_media_MediaDrm_getKeyRequest( JNIEnv *env, jobject thiz, jbyteArray jsessionId, jbyteArray jinitData, jstring jmimeType, jint jkeyType, jobject joptParams) { sp<IDrm> drm = GetDrm(env, thiz); if (!CheckSession(env, drm, jsessionId)) { return NULL; } Vector<uint8_t> sessionId(JByteArrayToVector(env, jsessionId)); Vector<uint8_t> initData; if (jinitData != NULL) { initData = JByteArrayToVector(env, jinitData); } String8 mimeType; if (jmimeType != NULL) { mimeType = JStringToString8(env, jmimeType); } DrmPlugin::KeyType keyType; if (jkeyType == gKeyTypes.kKeyTypeStreaming) { keyType = DrmPlugin::kKeyType_Streaming; } else if (jkeyType == gKeyTypes.kKeyTypeOffline) { keyType = DrmPlugin::kKeyType_Offline; } else if (jkeyType == gKeyTypes.kKeyTypeRelease) { keyType = DrmPlugin::kKeyType_Release; } else { jniThrowException(env, "java/lang/IllegalArgumentException", "invalid keyType"); return NULL; } KeyedVector<String8, String8> optParams; if (joptParams != NULL) { optParams = HashMapToKeyedVector(env, joptParams); } Vector<uint8_t> request; String8 defaultUrl; status_t err = drm->getKeyRequest(sessionId, initData, mimeType, keyType, optParams, request, defaultUrl); if (throwExceptionAsNecessary(env, err, "Failed to get key request")) { return NULL; } // Fill out return obj jclass clazz; FIND_CLASS(clazz, "android/media/MediaDrm$KeyRequest"); jobject keyObj = NULL; if (clazz) { keyObj = env->AllocObject(clazz); jbyteArray jrequest = VectorToJByteArray(env, request); env->SetObjectField(keyObj, gFields.keyRequest.data, jrequest); jstring jdefaultUrl = env->NewStringUTF(defaultUrl.string()); env->SetObjectField(keyObj, gFields.keyRequest.defaultUrl, jdefaultUrl); } return keyObj; }
static bool throwExceptionAsNecessary( JNIEnv *env, status_t err, const char *msg = NULL) { const char *drmMessage = NULL; switch(err) { case ERROR_DRM_UNKNOWN: drmMessage = "General DRM error"; break; case ERROR_DRM_NO_LICENSE: drmMessage = "No license"; break; case ERROR_DRM_LICENSE_EXPIRED: drmMessage = "License expired"; break; case ERROR_DRM_SESSION_NOT_OPENED: drmMessage = "Session not opened"; break; case ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED: drmMessage = "Not initialized"; break; case ERROR_DRM_DECRYPT: drmMessage = "Decrypt error"; break; case ERROR_DRM_CANNOT_HANDLE: drmMessage = "Unsupported scheme or data format"; break; case ERROR_DRM_TAMPER_DETECTED: drmMessage = "Invalid state"; break; default: break; } String8 vendorMessage; if (err >= ERROR_DRM_VENDOR_MIN && err <= ERROR_DRM_VENDOR_MAX) { vendorMessage.format("DRM vendor-defined error: %d", err); drmMessage = vendorMessage.string(); } if (err == BAD_VALUE) { jniThrowException(env, "java/lang/IllegalArgumentException", msg); return true; } else if (err == ERROR_DRM_NOT_PROVISIONED) { jniThrowException(env, "android/media/NotProvisionedException", msg); return true; } else if (err == ERROR_DRM_DEVICE_REVOKED) { jniThrowException(env, "android/media/DeniedByServerException", msg); return true; } else if (err != OK) { String8 errbuf; if (drmMessage != NULL) { if (msg == NULL) { msg = drmMessage; } else { errbuf.format("%s: %s", msg, drmMessage); msg = errbuf.string(); } } ALOGE("Illegal state exception: %s", msg); jniThrowException(env, "java/lang/IllegalStateException", msg); return true; } return false; }
bool BootAnimation::movie() { ZipFileRO& zip(mZip); size_t numEntries = zip.getNumEntries(); ZipEntryRO desc = zip.findEntryByName("desc.txt"); FileMap* descMap = zip.createEntryFileMap(desc); LOGE_IF(!descMap, "descMap is null"); if (!descMap) { return false; } String8 desString((char const*)descMap->getDataPtr(), descMap->getDataLength()); char const* s = desString.string(); Animation animation; // Parse the description file for (;;) { const char* endl = strstr(s, "\n"); if (!endl) break; String8 line(s, endl - s); const char* l = line.string(); int fps, width, height, count, pause; char path[256]; if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { //LOGD("> w=%d, h=%d, fps=%d", fps, width, height); animation.width = width; animation.height = height; animation.fps = fps; } if (sscanf(l, "p %d %d %s", &count, &pause, path) == 3) { //LOGD("> count=%d, pause=%d, path=%s", count, pause, path); Animation::Part part; part.count = count; part.pause = pause; part.path = path; animation.parts.add(part); } s = ++endl; } // read all the data structures const size_t pcount = animation.parts.size(); for (size_t i=0 ; i<numEntries ; i++) { char name[256]; ZipEntryRO entry = zip.findEntryByIndex(i); if (zip.getEntryFileName(entry, name, 256) == 0) { const String8 entryName(name); const String8 path(entryName.getPathDir()); const String8 leaf(entryName.getPathLeaf()); if (leaf.size() > 0) { for (int j=0 ; j<pcount ; j++) { if (path == animation.parts[j].path) { int method; // supports only stored png files if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) { if (method == ZipFileRO::kCompressStored) { FileMap* map = zip.createEntryFileMap(entry); if (map) { Animation::Frame frame; frame.name = leaf; frame.map = map; Animation::Part& part(animation.parts.editItemAt(j)); part.frames.add(frame); } } } } } } } } // clear screen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); const int xc = (mWidth - animation.width) / 2; const int yc = ((mHeight - animation.height) / 2); nsecs_t lastFrame = systemTime(); nsecs_t frameDuration = s2ns(1) / animation.fps; Region clearReg(Rect(mWidth, mHeight)); clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height)); for (int i=0 ; i<pcount && !exitPending() ; i++) { const Animation::Part& part(animation.parts[i]); const size_t fcount = part.frames.size(); const int noTextureCache = ((animation.width * animation.height * fcount) > 48 * 1024 * 1024) ? 1 : 0; glBindTexture(GL_TEXTURE_2D, 0); for (int r=0 ; !part.count || r<part.count ; r++) { for (int j=0 ; j<fcount && !exitPending(); j++) { const Animation::Frame& frame(part.frames[j]); if (r > 0 && !noTextureCache) { glBindTexture(GL_TEXTURE_2D, frame.tid); } else { if (part.count != 1) { glGenTextures(1, &frame.tid); glBindTexture(GL_TEXTURE_2D, frame.tid); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } initTexture( frame.map->getDataPtr(), frame.map->getDataLength()); } if (!clearReg.isEmpty()) { Region::const_iterator head(clearReg.begin()); Region::const_iterator tail(clearReg.end()); glEnable(GL_SCISSOR_TEST); while (head != tail) { const Rect& r(*head++); glScissor(r.left, mHeight - r.bottom, r.width(), r.height()); glClear(GL_COLOR_BUFFER_BIT); } glDisable(GL_SCISSOR_TEST); } glDrawTexiOES(xc, yc, 0, animation.width, animation.height); eglSwapBuffers(mDisplay, mSurface); nsecs_t now = systemTime(); nsecs_t delay = frameDuration - (now - lastFrame); lastFrame = now; long wait = ns2us(frameDuration); if (wait > 0) usleep(wait); if (noTextureCache) glDeleteTextures(1, &frame.tid); } usleep(part.pause * ns2us(frameDuration)); } // free the textures for this part if (part.count != 1 && !noTextureCache) { for (int j=0 ; j<fcount ; j++) { const Animation::Frame& frame(part.frames[j]); glDeleteTextures(1, &frame.tid); } } } return false; }
MVOID MAIN_CLASS_NAME:: applyRelease(UserId_T userId) { NodeId_T const nodeId = userId; sp<IAppCallback> pAppCallback; List<MyListener> listeners; BitSet32 nodeStatusUpdated; NodeStatusUpdater updater(getFrameNo(), mLogLevel); // String8 const logTag = String8::format("frameNo:%u nodeId:%#"PRIxPTR, getFrameNo(), nodeId); MY_LOG1("%s +", logTag.string()); // { RWLock::AutoWLock _lRWLock(mRWLock); Mutex::Autolock _lMapLock(mItemMapLock); // // Update MBOOL isAnyUpdate = updater.run(nodeId, mNodeStatusMap, nodeStatusUpdated); // // Is the entire frame released? if ( isAnyUpdate && 0 == mNodeStatusMap.mInFlightNodeCount ) { nodeStatusUpdated.markBit(IPipelineFrameListener::eMSG_FRAME_RELEASED); // mTimestampFrameDone = ::elapsedRealtimeNano(); // #if 1 // mpPipelineNodeMap = 0; // mpPipelineDAG = 0; mpStreamInfoSet = 0; #endif MY_LOG1( "Done frameNo:%u @ nodeId:%#"PRIxPTR" - timestamp:%"PRIu64"=%"PRIu64"-%"PRIu64, getFrameNo(), nodeId, (mTimestampFrameDone-mTimestampFrameCreated), mTimestampFrameDone, mTimestampFrameCreated ); } // if ( ! nodeStatusUpdated.isEmpty() ) { listeners = mListeners; } // pAppCallback = mpAppCallback.promote(); } // // Release (Hal) Buffers. updater.handleResult(); // // Callback to App. if ( pAppCallback == 0 ) { MY_LOGW("Caonnot promote AppCallback for frameNo:%u, userId:%#"PRIxPTR, getFrameNo(), userId); } else { pAppCallback->updateFrame(getFrameNo(), userId); } // // Callback to listeners if needed. if ( ! nodeStatusUpdated.isEmpty() ) { NSCam::Utils::CamProfile profile(__FUNCTION__, logTag.string()); // List<MyListener>::iterator it = listeners.begin(); for (; it != listeners.end(); ++it) { sp<MyListener::IListener> p = it->mpListener.promote(); if ( p == 0 ) { continue; } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_ALL_OUT_META_BUFFERS_RELEASED) ) { MY_LOG2("%s O Meta Buffers Released", logTag.string()); p->onPipelineFrame( getFrameNo(), nodeId, IPipelineFrameListener::eMSG_ALL_OUT_META_BUFFERS_RELEASED, it->mpCookie ); } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_ALL_OUT_IMAGE_BUFFERS_RELEASED) ) { MY_LOG2("%s O Image Buffers Released", logTag.string()); p->onPipelineFrame( getFrameNo(), nodeId, IPipelineFrameListener::eMSG_ALL_OUT_IMAGE_BUFFERS_RELEASED, it->mpCookie ); } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_FRAME_RELEASED) ) { MY_LOG2("%s Frame Done", logTag.string()); p->onPipelineFrame( getFrameNo(), IPipelineFrameListener::eMSG_FRAME_RELEASED, it->mpCookie ); } } // profile.print_overtime(3, "notify listeners (nodeStatusUpdated:%#x)", nodeStatusUpdated.value); } // MY_LOG1("%s -", logTag.string()); }
void GonkBufferQueue::dumpToString(String8& result, const char* prefix, char* buffer, size_t SIZE) const { Mutex::Autolock _l(mMutex); String8 fifo; int fifoSize = 0; Fifo::const_iterator i(mQueue.begin()); while (i != mQueue.end()) { snprintf(buffer, SIZE, "%02d ", *i++); fifoSize++; fifo.append(buffer); } int maxBufferCount = getMaxBufferCountLocked(); snprintf(buffer, SIZE, "%s-BufferQueue maxBufferCount=%d, mSynchronousMode=%d, default-size=[%dx%d], " "default-format=%d, transform-hint=%02x, FIFO(%d)={%s}\n", prefix, maxBufferCount, mSynchronousMode, mDefaultWidth, mDefaultHeight, mDefaultBufferFormat, mTransformHint, fifoSize, fifo.string()); result.append(buffer); struct { const char * operator()(int state) const { switch (state) { case BufferSlot::DEQUEUED: return "DEQUEUED"; case BufferSlot::QUEUED: return "QUEUED"; case BufferSlot::FREE: return "FREE"; case BufferSlot::ACQUIRED: return "ACQUIRED"; default: return "Unknown"; } } } stateName; for (int i=0 ; i<maxBufferCount ; i++) { const BufferSlot& slot(mSlots[i]); snprintf(buffer, SIZE, "%s%s[%02d] " "state=%-8s, crop=[%d,%d,%d,%d], " "xform=0x%02x, time=%#llx, scale=%s", prefix, (slot.mBufferState == BufferSlot::ACQUIRED)?">":" ", i, stateName(slot.mBufferState), slot.mCrop.left, slot.mCrop.top, slot.mCrop.right, slot.mCrop.bottom, slot.mTransform, slot.mTimestamp, scalingModeName(slot.mScalingMode) ); result.append(buffer); const sp<GraphicBuffer>& buf(slot.mGraphicBuffer); if (buf != NULL) { snprintf(buffer, SIZE, ", %p [%4ux%4u:%4u,%3X]", buf->handle, buf->width, buf->height, buf->stride, buf->format); result.append(buffer); } result.append("\n"); } }
void AudioManager::HandleBluetoothStatusChanged(nsISupports* aSubject, const char* aTopic, const nsCString aAddress) { #ifdef MOZ_B2G_BT bool status; if (!strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED_ID)) { BluetoothHfpManagerBase* hfp = static_cast<BluetoothHfpManagerBase*>(aSubject); status = hfp->IsScoConnected(); } else { BluetoothProfileManagerBase* profile = static_cast<BluetoothProfileManagerBase*>(aSubject); status = profile->IsConnected(); } audio_policy_dev_state_t audioState = status ? AUDIO_POLICY_DEVICE_STATE_AVAILABLE : AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; if (!strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED_ID)) { if (audioState == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { String8 cmd; cmd.appendFormat("bt_samplerate=%d", kBtSampleRate); AudioSystem::setParameters(0, cmd); SetForceForUse(nsIAudioManager::USE_COMMUNICATION, nsIAudioManager::FORCE_BT_SCO); } else { int32_t force; GetForceForUse(nsIAudioManager::USE_COMMUNICATION, &force); if (force == nsIAudioManager::FORCE_BT_SCO) SetForceForUse(nsIAudioManager::USE_COMMUNICATION, nsIAudioManager::FORCE_NONE); } } else if (!strcmp(aTopic, BLUETOOTH_A2DP_STATUS_CHANGED_ID)) { if (audioState == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE && sA2dpSwitchDone) { MessageLoop::current()->PostDelayedTask( FROM_HERE, NewRunnableFunction(&ProcessDelayedA2dpRoute, audioState, aAddress), 1000); sA2dpSwitchDone = false; } else { AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, audioState, aAddress.get()); String8 cmd("bluetooth_enabled=true"); AudioSystem::setParameters(0, cmd); cmd.setTo("A2dpSuspended=false"); AudioSystem::setParameters(0, cmd); sA2dpSwitchDone = true; #if ANDROID_VERSION >= 17 if (AudioSystem::getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA) == AUDIO_POLICY_FORCE_NO_BT_A2DP) { SetForceForUse(AUDIO_POLICY_FORCE_FOR_MEDIA, AUDIO_POLICY_FORCE_NONE); } #endif } sBluetoothA2dpEnabled = audioState == AUDIO_POLICY_DEVICE_STATE_AVAILABLE; } else if (!strcmp(aTopic, BLUETOOTH_HFP_STATUS_CHANGED_ID)) { AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, audioState, aAddress.get()); AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, audioState, aAddress.get()); } #endif }
int main(int argc, char* const argv[]) { if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) { LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno)); } if (!LOG_NDEBUG) { String8 argv_String; for (int i = 0; i < argc; ++i) { argv_String.append("\""); argv_String.append(argv[i]); argv_String.append("\" "); } ALOGV("app_process main with argv: %s", argv_String.string()); } AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv)); // Process command line arguments // ignore argv[0] argc--; argv++; // Everything up to '--' or first non '-' arg goes to the vm. // // The first argument after the VM args is the "parent dir", which // is currently unused. // // After the parent dir, we expect one or more the following internal // arguments : // // --zygote : Start in zygote mode // --start-system-server : Start the system server. // --application : Start in application (stand alone, non zygote) mode. // --nice-name : The nice name for this process. // // For non zygote starts, these arguments will be followed by // the main class name. All remaining arguments are passed to // the main method of this class. // // For zygote starts, all remaining arguments are passed to the zygote. // main function. // // Note that we must copy argument string values since we will rewrite the // entire argument block when we apply the nice name to argv0. // // As an exception to the above rule, anything in "spaced commands" // goes to the vm even though it has a space in it. const char* spaced_commands[] = { "-cp", "-classpath" }; // Allow "spaced commands" to be succeeded by exactly 1 argument (regardless of -s). bool known_command = false; int i; for (i = 0; i < argc; i++) { if (known_command == true) { runtime.addOption(strdup(argv[i])); ALOGV("app_process main add known option '%s'", argv[i]); known_command = false; continue; } for (int j = 0; j < static_cast<int>(sizeof(spaced_commands) / sizeof(spaced_commands[0])); ++j) { if (strcmp(argv[i], spaced_commands[j]) == 0) { known_command = true; ALOGV("app_process main found known command '%s'", argv[i]); } } if (argv[i][0] != '-') { break; } if (argv[i][1] == '-' && argv[i][2] == 0) { ++i; // Skip --. break; } runtime.addOption(strdup(argv[i])); ALOGV("app_process main add option '%s'", argv[i]); } // Parse runtime arguments. Stop at first unrecognized option. bool zygote = false; bool startSystemServer = false; bool application = false; String8 niceName; String8 className; ++i; // Skip unused "parent dir" argument. while (i < argc) { const char* arg = argv[i++]; if (strcmp(arg, "--zygote") == 0) { zygote = true; niceName = ZYGOTE_NICE_NAME; } else if (strcmp(arg, "--start-system-server") == 0) { startSystemServer = true; } else if (strcmp(arg, "--application") == 0) { application = true; } else if (strncmp(arg, "--nice-name=", 12) == 0) { niceName.setTo(arg + 12); } else if (strncmp(arg, "--", 2) != 0) { className.setTo(arg); break; } else { --i; break; } } Vector<String8> args; if (!className.isEmpty()) { // We're not in zygote mode, the only argument we need to pass // to RuntimeInit is the application argument. // // The Remainder of args get passed to startup class main(). Make // copies of them before we overwrite them with the process name. args.add(application ? String8("application") : String8("tool")); runtime.setClassNameAndArgs(className, argc - i, argv + i); if (!LOG_NDEBUG) { String8 restOfArgs; char* const* argv_new = argv + i; int argc_new = argc - i; for (int k = 0; k < argc_new; ++k) { restOfArgs.append("\""); restOfArgs.append(argv_new[k]); restOfArgs.append("\" "); } ALOGV("Class name = %s, args = %s", className.string(), restOfArgs.string()); } } else { // We're in zygote mode. maybeCreateDalvikCache(); if (startSystemServer) { args.add(String8("start-system-server")); } char prop[PROP_VALUE_MAX]; if (property_get(ABI_LIST_PROPERTY, prop, NULL) == 0) { LOG_ALWAYS_FATAL("app_process: Unable to determine ABI list from property %s.", ABI_LIST_PROPERTY); return 11; } String8 abiFlag("--abi-list="); abiFlag.append(prop); args.add(abiFlag); // In zygote mode, pass all remaining arguments to the zygote // main() method. for (; i < argc; ++i) { args.add(String8(argv[i])); } } if (!niceName.isEmpty()) { runtime.setArgv0(niceName.string(), true /* setProcName */); } if (zygote) { runtime.start("com.android.internal.os.ZygoteInit", args, zygote); } else if (className) { runtime.start("com.android.internal.os.RuntimeInit", args, zygote); } else { fprintf(stderr, "Error: no class name or --zygote supplied.\n"); app_usage(); LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied."); } }
bool FwdLockEngine::onCanHandle(int /*uniqueId*/, const String8& path) { bool result = false; String8 extString = path.getPathExtension(); return IsFileSuffixSupported(extString); }
int main(int argc, char* const argv[]) { if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) { // Older kernels don't understand PR_SET_NO_NEW_PRIVS and return // EINVAL. Don't die on such kernels. if (errno != EINVAL) { LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno)); return 12; } } AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv)); // Process command line arguments // ignore argv[0] argc--; argv++; // Everything up to '--' or first non '-' arg goes to the vm. // // The first argument after the VM args is the "parent dir", which // is currently unused. // // After the parent dir, we expect one or more the following internal // arguments : // // --zygote : Start in zygote mode // --start-system-server : Start the system server. // --application : Start in application (stand alone, non zygote) mode. // --nice-name : The nice name for this process. // // For non zygote starts, these arguments will be followed by // the main class name. All remaining arguments are passed to // the main method of this class. // // For zygote starts, all remaining arguments are passed to the zygote. // main function. int i = runtime.addVmArguments(argc, argv); // Parse runtime arguments. Stop at first unrecognized option. bool zygote = false; bool startSystemServer = false; bool application = false; const char* niceName = NULL; String8 className; ++i; // Skip unused "parent dir" argument. while (i < argc) { const char* arg = argv[i++]; if (strcmp(arg, "--zygote") == 0) { zygote = true; niceName = ZYGOTE_NICE_NAME; } else if (strcmp(arg, "--start-system-server") == 0) { startSystemServer = true; } else if (strcmp(arg, "--application") == 0) { application = true; } else if (strncmp(arg, "--nice-name=", 12) == 0) { niceName = arg + 12; } else if (strncmp(arg, "--", 2) != 0) { className.setTo(arg); break; } else { --i; break; } } Vector<String8> args; if (!className.isEmpty()) { // We're not in zygote mode, the only argument we need to pass // to RuntimeInit is the application argument. // // The Remainder of args get passed to startup class main(). Make // copies of them before we overwrite them with the process name. args.add(application ? String8("application") : String8("tool")); runtime.setClassNameAndArgs(className, argc - i, argv + i); } else { if (startSystemServer) { args.add(String8("start-system-server")); } char prop[PROP_VALUE_MAX]; if (property_get(ABI_LIST_PROPERTY, prop, NULL) == 0) { LOG_ALWAYS_FATAL("app_process: Unable to determine ABI list from property %s.", ABI_LIST_PROPERTY); return 11; } String8 abiFlag("--abi-list="); abiFlag.append(prop); args.add(abiFlag); // In zygote mode, pass all remaining arguments to the zygote // main() method. for (; i < argc; ++i) { args.add(String8(argv[i])); } } if (niceName && *niceName) { runtime.setArgv0(niceName); set_process_name(niceName); } if (zygote) { runtime.start("com.android.internal.os.ZygoteInit", args); } else if (className) { runtime.start("com.android.internal.os.RuntimeInit", args); } else { fprintf(stderr, "Error: no class name or --zygote supplied.\n"); app_usage(); LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied."); return 10; } }
void BatteryMonitor::init(struct healthd_config *hc) { String8 path; char pval[PROPERTY_VALUE_MAX]; mHealthdConfig = hc; DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); if (dir == NULL) { KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); } else { struct dirent* entry; while ((entry = readdir(dir))) { const char* name = entry->d_name; if (!strcmp(name, ".") || !strcmp(name, "..")) continue; // Look for "type" file in each subdirectory path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: case ANDROID_POWER_SUPPLY_TYPE_USB: case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: path.clear(); path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); if (access(path.string(), R_OK) == 0) mChargerNames.add(String8(name)); break; case ANDROID_POWER_SUPPLY_TYPE_BATTERY: mBatteryDevicePresent = true; if (mHealthdConfig->batteryStatusPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryStatusPath = path; } if (mHealthdConfig->batteryHealthPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryHealthPath = path; } if (mHealthdConfig->batteryPresentPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryPresentPath = path; } if (mHealthdConfig->batteryCapacityPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryCapacityPath = path; } if (mHealthdConfig->batteryVoltagePath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/voltage_now", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) { mHealthdConfig->batteryVoltagePath = path; } else { path.clear(); path.appendFormat("%s/%s/batt_vol", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryVoltagePath = path; } } if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/current_now", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryCurrentNowPath = path; } if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/current_avg", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryCurrentAvgPath = path; } if (mHealthdConfig->batteryChargeCounterPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/charge_counter", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryChargeCounterPath = path; } if (mHealthdConfig->batteryTemperaturePath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) { mHealthdConfig->batteryTemperaturePath = path; } else { path.clear(); path.appendFormat("%s/%s/batt_temp", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryTemperaturePath = path; } } if (mHealthdConfig->batteryTechnologyPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/technology", POWER_SUPPLY_SYSFS_PATH, name); if (access(path, R_OK) == 0) mHealthdConfig->batteryTechnologyPath = path; } break; case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN: break; } } closedir(dir); } if (!mChargerNames.size()) KLOG_ERROR(LOG_TAG, "No charger supplies found\n"); if (!mBatteryDevicePresent) { KLOG_WARNING(LOG_TAG, "No battery devices found\n"); hc->periodic_chores_interval_fast = -1; hc->periodic_chores_interval_slow = -1; } else { if (mHealthdConfig->batteryStatusPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n"); if (mHealthdConfig->batteryHealthPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryHealthPath not found\n"); if (mHealthdConfig->batteryPresentPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryPresentPath not found\n"); if (mHealthdConfig->batteryCapacityPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryCapacityPath not found\n"); if (mHealthdConfig->batteryVoltagePath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryVoltagePath not found\n"); if (mHealthdConfig->batteryTemperaturePath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); if (mHealthdConfig->batteryTechnologyPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); } if (property_get("ro.boot.fake_battery", pval, NULL) > 0 && strtol(pval, NULL, 10) != 0) { mBatteryFixedCapacity = FAKE_BATTERY_CAPACITY; mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE; } }
int main(int argc, char **argv) { android::ProcessState::self()->startThreadPool(); bool audioOnly = false; bool listComponents = false; bool dumpProfiles = false; bool extractThumbnail = false; bool seekTest = false; gNumRepetitions = 1; gMaxNumFrames = 0; gReproduceBug = -1; gPreferSoftwareCodec = false; gPlaybackAudio = false; gWriteMP4 = false; sp<ALooper> looper; sp<ARTSPController> rtspController; int res; while ((res = getopt(argc, argv, "han:lm:b:ptsow:k")) >= 0) { switch (res) { case 'a': { audioOnly = true; break; } case 'l': { listComponents = true; break; } case 'm': case 'n': case 'b': { char *end; long x = strtol(optarg, &end, 10); if (*end != '\0' || end == optarg || x <= 0) { x = 1; } if (res == 'n') { gNumRepetitions = x; } else if (res == 'm') { gMaxNumFrames = x; } else { CHECK_EQ(res, 'b'); gReproduceBug = x; } break; } case 'w': { gWriteMP4 = true; gWriteMP4Filename.setTo(optarg); break; } case 'p': { dumpProfiles = true; break; } case 't': { extractThumbnail = true; break; } case 's': { gPreferSoftwareCodec = true; break; } case 'o': { gPlaybackAudio = true; break; } case 'k': { seekTest = true; break; } case '?': case 'h': default: { usage(argv[0]); exit(1); break; } } } if (gPlaybackAudio && !audioOnly) { // This doesn't make any sense if we're decoding the video track. gPlaybackAudio = false; } argc -= optind; argv += optind; if (extractThumbnail) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.player")); sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); CHECK(service.get() != NULL); sp<IMediaMetadataRetriever> retriever = service->createMetadataRetriever(getpid()); CHECK(retriever != NULL); for (int k = 0; k < argc; ++k) { const char *filename = argv[k]; CHECK_EQ(retriever->setDataSource(filename), (status_t)OK); sp<IMemory> mem = retriever->getFrameAtTime(-1, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC); if (mem != NULL) { printf("getFrameAtTime(%s) => OK\n", filename); } else { mem = retriever->extractAlbumArt(); if (mem != NULL) { printf("extractAlbumArt(%s) => OK\n", filename); } else { printf("both getFrameAtTime and extractAlbumArt " "failed on file '%s'.\n", filename); } } } return 0; } if (dumpProfiles) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.player")); sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); CHECK(service.get() != NULL); sp<IOMX> omx = service->getOMX(); CHECK(omx.get() != NULL); const char *kMimeTypes[] = { MEDIA_MIMETYPE_VIDEO_AVC, MEDIA_MIMETYPE_VIDEO_MPEG4, MEDIA_MIMETYPE_VIDEO_H263, MEDIA_MIMETYPE_AUDIO_AAC, MEDIA_MIMETYPE_AUDIO_AMR_NB, MEDIA_MIMETYPE_AUDIO_AMR_WB, MEDIA_MIMETYPE_AUDIO_MPEG }; for (size_t k = 0; k < sizeof(kMimeTypes) / sizeof(kMimeTypes[0]); ++k) { printf("type '%s':\n", kMimeTypes[k]); Vector<CodecCapabilities> results; CHECK_EQ(QueryCodecs(omx, kMimeTypes[k], true, // queryDecoders &results), (status_t)OK); for (size_t i = 0; i < results.size(); ++i) { printf(" decoder '%s' supports ", results[i].mComponentName.string()); if (results[i].mProfileLevels.size() == 0) { printf("NOTHING.\n"); continue; } for (size_t j = 0; j < results[i].mProfileLevels.size(); ++j) { const CodecProfileLevel &profileLevel = results[i].mProfileLevels[j]; printf("%s%ld/%ld", j > 0 ? ", " : "", profileLevel.mProfile, profileLevel.mLevel); } printf("\n"); } } } if (listComponents) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.player")); sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); CHECK(service.get() != NULL); sp<IOMX> omx = service->getOMX(); CHECK(omx.get() != NULL); List<IOMX::ComponentInfo> list; omx->listNodes(&list); for (List<IOMX::ComponentInfo>::iterator it = list.begin(); it != list.end(); ++it) { printf("%s\n", (*it).mName.string()); } } DataSource::RegisterDefaultSniffers(); OMXClient client; status_t err = client.connect(); for (int k = 0; k < argc; ++k) { bool syncInfoPresent = true; const char *filename = argv[k]; sp<DataSource> dataSource = DataSource::CreateFromURI(filename); if (strncasecmp(filename, "sine:", 5) && strncasecmp(filename, "rtsp://", 7) && strncasecmp(filename, "httplive://", 11) && dataSource == NULL) { fprintf(stderr, "Unable to create data source.\n"); return 1; } bool isJPEG = false; size_t len = strlen(filename); if (len >= 4 && !strcasecmp(filename + len - 4, ".jpg")) { isJPEG = true; } Vector<sp<MediaSource> > mediaSources; sp<MediaSource> mediaSource; if (isJPEG) { mediaSource = new JPEGSource(dataSource); if (gWriteMP4) { mediaSources.push(mediaSource); } } else if (!strncasecmp("sine:", filename, 5)) { char *end; long sampleRate = strtol(filename + 5, &end, 10); if (end == filename + 5) { sampleRate = 44100; } mediaSource = new SineSource(sampleRate, 1); if (gWriteMP4) { mediaSources.push(mediaSource); } } else { sp<MediaExtractor> extractor; if (!strncasecmp("rtsp://", filename, 7)) { if (looper == NULL) { looper = new ALooper; looper->start(); } rtspController = new ARTSPController(looper); status_t err = rtspController->connect(filename); if (err != OK) { fprintf(stderr, "could not connect to rtsp server.\n"); return -1; } extractor = rtspController.get(); syncInfoPresent = false; } else if (!strncasecmp("httplive://", filename, 11)) { String8 uri("http://"); uri.append(filename + 11); dataSource = new LiveSource(uri.string()); dataSource = new NuCachedSource2(dataSource); extractor = MediaExtractor::Create( dataSource, MEDIA_MIMETYPE_CONTAINER_MPEG2TS); syncInfoPresent = false; } else { extractor = MediaExtractor::Create(dataSource); if (extractor == NULL) { fprintf(stderr, "could not create extractor.\n"); return -1; } } size_t numTracks = extractor->countTracks(); if (gWriteMP4) { bool haveAudio = false; bool haveVideo = false; for (size_t i = 0; i < numTracks; ++i) { sp<MediaSource> source = extractor->getTrack(i); const char *mime; CHECK(source->getFormat()->findCString( kKeyMIMEType, &mime)); bool useTrack = false; if (!haveAudio && !strncasecmp("audio/", mime, 6)) { haveAudio = true; useTrack = true; } else if (!haveVideo && !strncasecmp("video/", mime, 6)) { haveVideo = true; useTrack = true; } if (useTrack) { mediaSources.push(source); if (haveAudio && haveVideo) { break; } } } } else { sp<MetaData> meta; size_t i; for (i = 0; i < numTracks; ++i) { meta = extractor->getTrackMetaData( i, MediaExtractor::kIncludeExtensiveMetaData); const char *mime; meta->findCString(kKeyMIMEType, &mime); if (audioOnly && !strncasecmp(mime, "audio/", 6)) { break; } if (!audioOnly && !strncasecmp(mime, "video/", 6)) { break; } meta = NULL; } if (meta == NULL) { fprintf(stderr, "No suitable %s track found. The '-a' option will " "target audio tracks only, the default is to target " "video tracks only.\n", audioOnly ? "audio" : "video"); return -1; } int64_t thumbTimeUs; if (meta->findInt64(kKeyThumbnailTime, &thumbTimeUs)) { printf("thumbnailTime: %lld us (%.2f secs)\n", thumbTimeUs, thumbTimeUs / 1E6); } mediaSource = extractor->getTrack(i); } } if (gWriteMP4) { writeSourcesToMP4(mediaSources, syncInfoPresent); } else if (seekTest) { performSeekTest(mediaSource); } else { playSource(&client, mediaSource); } if (rtspController != NULL) { rtspController->disconnect(); rtspController.clear(); sleep(3); } } client.disconnect(); return 0; }
status_t StagefrightRecorder::dump( int fd, const Vector<String16>& args) const { LOGV("dump"); const size_t SIZE = 256; char buffer[SIZE]; String8 result; if (mWriter != 0) { mWriter->dump(fd, args); } else { snprintf(buffer, SIZE, " No file writer\n"); result.append(buffer); } snprintf(buffer, SIZE, " Recorder: %p\n", this); snprintf(buffer, SIZE, " Output file (fd %d):\n", mOutputFd); result.append(buffer); snprintf(buffer, SIZE, " File format: %d\n", mOutputFormat); result.append(buffer); snprintf(buffer, SIZE, " Max file size (bytes): %lld\n", mMaxFileSizeBytes); result.append(buffer); snprintf(buffer, SIZE, " Max file duration (us): %lld\n", mMaxFileDurationUs); result.append(buffer); snprintf(buffer, SIZE, " File offset length (bits): %d\n", mUse64BitFileOffset? 64: 32); result.append(buffer); snprintf(buffer, SIZE, " Interleave duration (us): %d\n", mInterleaveDurationUs); result.append(buffer); snprintf(buffer, SIZE, " Progress notification: %lld us\n", mTrackEveryTimeDurationUs); result.append(buffer); snprintf(buffer, SIZE, " Audio\n"); result.append(buffer); snprintf(buffer, SIZE, " Source: %d\n", mAudioSource); result.append(buffer); snprintf(buffer, SIZE, " Encoder: %d\n", mAudioEncoder); result.append(buffer); snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mAudioBitRate); result.append(buffer); snprintf(buffer, SIZE, " Sampling rate (hz): %d\n", mSampleRate); result.append(buffer); snprintf(buffer, SIZE, " Number of channels: %d\n", mAudioChannels); result.append(buffer); snprintf(buffer, SIZE, " Max amplitude: %d\n", mAudioSourceNode == 0? 0: mAudioSourceNode->getMaxAmplitude()); result.append(buffer); snprintf(buffer, SIZE, " Video\n"); result.append(buffer); snprintf(buffer, SIZE, " Source: %d\n", mVideoSource); result.append(buffer); snprintf(buffer, SIZE, " Camera Id: %d\n", mCameraId); result.append(buffer); snprintf(buffer, SIZE, " Camera flags: %d\n", mFlags); result.append(buffer); snprintf(buffer, SIZE, " Encoder: %d\n", mVideoEncoder); result.append(buffer); snprintf(buffer, SIZE, " Encoder profile: %d\n", mVideoEncoderProfile); result.append(buffer); snprintf(buffer, SIZE, " Encoder level: %d\n", mVideoEncoderLevel); result.append(buffer); snprintf(buffer, SIZE, " I frames interval (s): %d\n", mIFramesIntervalSec); result.append(buffer); snprintf(buffer, SIZE, " Frame size (pixels): %dx%d\n", mVideoWidth, mVideoHeight); result.append(buffer); snprintf(buffer, SIZE, " Frame rate (fps): %d\n", mFrameRate); result.append(buffer); snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mVideoBitRate); result.append(buffer); ::write(fd, result.string(), result.size()); return OK; }
status_t NuMediaExtractor::setDataSource( const char *path, const KeyedVector<String8, String8> *headers) { Mutex::Autolock autoLock(mLock); if (mImpl != NULL) { return -EINVAL; } sp<DataSource> dataSource = DataSource::CreateFromURI(path, headers); if (dataSource == NULL) { return -ENOENT; } mIsWidevineExtractor = false; if (!strncasecmp("widevine://", path, 11)) { String8 mimeType; float confidence; sp<AMessage> dummy; bool success = SniffWVM(dataSource, &mimeType, &confidence, &dummy); if (!success || strcasecmp( mimeType.string(), MEDIA_MIMETYPE_CONTAINER_WVM)) { return ERROR_UNSUPPORTED; } sp<WVMExtractor> extractor = new WVMExtractor(dataSource); extractor->setAdaptiveStreamingMode(true); mImpl = extractor; mIsWidevineExtractor = true; } else { mImpl = MediaExtractor::Create(dataSource); } if (mImpl == NULL) { return ERROR_UNSUPPORTED; } sp<MetaData> fileMeta = mImpl->getMetaData(); const char *containerMime; if (fileMeta != NULL && fileMeta->findCString(kKeyMIMEType, &containerMime) && !strcasecmp(containerMime, "video/wvm")) { // We always want to use "cryptoPluginMode" when using the wvm // extractor. We can tell that it is this extractor by looking // at the container mime type. // The cryptoPluginMode ensures that the extractor will actually // give us data in a call to MediaSource::read(), unlike its // default mode that we use from AwesomePlayer. static_cast<WVMExtractor *>(mImpl.get())->setCryptoPluginMode(true); } else if (mImpl->getDrmFlag()) { // For all other drm content, we don't want to expose decrypted // content to Java application. mImpl.clear(); mImpl = NULL; return ERROR_UNSUPPORTED; } mDataSource = dataSource; updateDurationAndBitrate(); return OK; }
void GraphicBufferAllocator::dumpToSystemLog() { String8 s; GraphicBufferAllocator::getInstance().dump(s); LOGD("%s", s.string()); }
void *Loader::load_driver(const char* kind, egl_connection_t* cnx, uint32_t mask) { class MatchFile { public: static String8 find(const char* kind) { String8 result; String8 pattern; pattern.appendFormat("lib%s", kind); const char* const searchPaths[] = { "/vendor/lib/egl", "/system/lib/egl" }; // first, we search for the exact name of the GLES userspace // driver in both locations. // i.e.: // libGLES.so, or: // libEGL.so, libGLESv1_CM.so, libGLESv2.so for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { if (find(result, pattern, searchPaths[i], true)) { return result; } } // for compatibility with the old "egl.cfg" naming convention // we look for files that match: // libGLES_*.so, or: // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so pattern.append("_"); for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { if (find(result, pattern, searchPaths[i], false)) { return result; } } // we didn't find the driver. gah. result.clear(); return result; } private: static bool find(String8& result, const String8& pattern, const char* const search, bool exact) { // in the emulator case, we just return the hardcoded name // of the software renderer. if (checkGlesEmulationStatus() == 0) { ALOGD("Emulator without GPU support detected. " "Fallback to software renderer."); result.setTo("/system/lib/egl/libGLES_android.so"); return true; } if (exact) { String8 absolutePath; absolutePath.appendFormat("%s/%s.so", search, pattern.string()); if (!access(absolutePath.string(), R_OK)) { result = absolutePath; return true; } return false; } DIR* d = opendir(search); if (d != NULL) { struct dirent cur; struct dirent* e; while (readdir_r(d, &cur, &e) == 0 && e) { if (e->d_type == DT_DIR) { continue; } if (!strcmp(e->d_name, "libGLES_android.so")) { // always skip the software renderer continue; } if (strstr(e->d_name, pattern.string()) == e->d_name) { if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) { result.clear(); result.appendFormat("%s/%s", search, e->d_name); closedir(d); return true; } } } closedir(d); } return false; } }; String8 absolutePath = MatchFile::find(kind); if (absolutePath.isEmpty()) { // this happens often, we don't want to log an error return 0; } const char* const driver_absolute_path = absolutePath.string(); void* dso = dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL); if (dso == 0) { const char* err = dlerror(); ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown"); return 0; } ALOGD("loaded %s", driver_absolute_path); if (mask & EGL) { getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress"); ALOGE_IF(!getProcAddress, "can't find eglGetProcAddress() in %s", driver_absolute_path); egl_t* egl = &cnx->egl; __eglMustCastToProperFunctionPointerType* curr = (__eglMustCastToProperFunctionPointerType*)egl; char const * const * api = egl_names; while (*api) { char const * name = *api; __eglMustCastToProperFunctionPointerType f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); if (f == NULL) { // couldn't find the entry-point, use eglGetProcAddress() f = getProcAddress(name); if (f == NULL) { f = (__eglMustCastToProperFunctionPointerType)0; } } *curr++ = f; api++; } } if (mask & GLESv1_CM) { init_api(dso, gl_names, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl, getProcAddress); } if (mask & GLESv2) { init_api(dso, gl_names, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl, getProcAddress); } return dso; }
int main(int argc, char** argv) { const char* filename; int fd; ssize_t amt; off_t size; void* buf; zipfile_t zip; zipentry_t entry; void* cookie; void* resfile; int bufsize; int err; if (argc != 2) { return usage(); } filename = argv[1]; fd = open(filename, O_RDONLY); if (fd == -1) { fprintf(stderr, "apk: couldn't open file for read: %s\n", filename); return 1; } size = lseek(fd, 0, SEEK_END); amt = lseek(fd, 0, SEEK_SET); if (size < 0 || amt < 0) { fprintf(stderr, "apk: error determining file size: %s\n", filename); return 1; } buf = malloc(size); if (buf == NULL) { fprintf(stderr, "apk: file too big: %s\n", filename); return 1; } amt = read(fd, buf, size); if (amt != size) { fprintf(stderr, "apk: error reading file: %s\n", filename); return 1; } close(fd); zip = init_zipfile(buf, size); if (zip == NULL) { fprintf(stderr, "apk: file doesn't seem to be a zip file: %s\n", filename); return 1; } printf("files:\n"); cookie = NULL; while ((entry = iterate_zipfile(zip, &cookie))) { char* name = get_zipentry_name(entry); printf(" %s\n", name); free(name); } entry = lookup_zipentry(zip, "resources.arsc"); if (entry != NULL) { size = get_zipentry_size(entry); bufsize = size + (size / 1000) + 1; resfile = malloc(bufsize); err = decompress_zipentry(entry, resfile, bufsize); if (err != 0) { fprintf(stderr, "apk: error decompressing resources.arsc"); return 1; } ResTable res(resfile, size, resfile); res.print(); #if 0 size_t tableCount = res.getTableCount(); printf("Tables: %d\n", (int)tableCount); for (size_t tableIndex=0; tableIndex<tableCount; tableIndex++) { const ResStringPool* strings = res.getTableStringBlock(tableIndex); size_t stringCount = strings->size(); for (size_t stringIndex=0; stringIndex<stringCount; stringIndex++) { size_t len; const char16_t* ch = strings->stringAt(stringIndex, &len); String8 s(String16(ch, len)); printf(" [%3d] %s\n", (int)stringIndex, s.string()); } } size_t basePackageCount = res.getBasePackageCount(); printf("Base Packages: %d\n", (int)basePackageCount); for (size_t bpIndex=0; bpIndex<basePackageCount; bpIndex++) { const char16_t* ch = res.getBasePackageName(bpIndex); String8 s = String8(String16(ch)); printf(" [%3d] %s\n", (int)bpIndex, s.string()); } #endif } return 0; }
/* * The directory hierarchy looks like this: * "outputDir" and "assetRoot" are existing directories. * * On success, "bundle->numPackages" will be the number of Zip packages * we created. */ status_t writeAPK(Bundle* bundle, const sp<AaptAssets>& assets, const String8& outputFile) { status_t result = NO_ERROR; ZipFile* zip = NULL; int count; //bundle->setPackageCount(0); /* * Prep the Zip archive. * * If the file already exists, fail unless "update" or "force" is set. * If "update" is set, update the contents of the existing archive. * Else, if "force" is set, remove the existing archive. */ FileType fileType = getFileType(outputFile.string()); if (fileType == kFileTypeNonexistent) { // okay, create it below } else if (fileType == kFileTypeRegular) { if (bundle->getUpdate()) { // okay, open it below } else if (bundle->getForce()) { if (unlink(outputFile.string()) != 0) { fprintf(stderr, "ERROR: unable to remove '%s': %s\n", outputFile.string(), strerror(errno)); goto bail; } } else { fprintf(stderr, "ERROR: '%s' exists (use '-f' to force overwrite)\n", outputFile.string()); goto bail; } } else { fprintf(stderr, "ERROR: '%s' exists and is not a regular file\n", outputFile.string()); goto bail; } if (bundle->getVerbose()) { printf("%s '%s'\n", (fileType == kFileTypeNonexistent) ? "Creating" : "Opening", outputFile.string()); } status_t status; zip = new ZipFile; status = zip->open(outputFile.string(), ZipFile::kOpenReadWrite | ZipFile::kOpenCreate); if (status != NO_ERROR) { fprintf(stderr, "ERROR: unable to open '%s' as Zip file for writing\n", outputFile.string()); goto bail; } if (bundle->getVerbose()) { printf("Writing all files...\n"); } count = processAssets(bundle, zip, assets); if (count < 0) { fprintf(stderr, "ERROR: unable to process assets while packaging '%s'\n", outputFile.string()); result = count; goto bail; } if (bundle->getVerbose()) { printf("Generated %d file%s\n", count, (count==1) ? "" : "s"); } count = processJarFiles(bundle, zip); if (count < 0) { fprintf(stderr, "ERROR: unable to process jar files while packaging '%s'\n", outputFile.string()); result = count; goto bail; } if (bundle->getVerbose()) printf("Included %d file%s from jar/zip files.\n", count, (count==1) ? "" : "s"); result = NO_ERROR; /* * Check for cruft. We set the "marked" flag on all entries we created * or decided not to update. If the entry isn't already slated for * deletion, remove it now. */ { if (bundle->getVerbose()) printf("Checking for deleted files\n"); int i, removed = 0; for (i = 0; i < zip->getNumEntries(); i++) { ZipEntry* entry = zip->getEntryByIndex(i); if (!entry->getMarked() && entry->getDeleted()) { if (bundle->getVerbose()) { printf(" (removing crufty '%s')\n", entry->getFileName()); } zip->remove(entry); removed++; } } if (bundle->getVerbose() && removed > 0) printf("Removed %d file%s\n", removed, (removed==1) ? "" : "s"); } /* tell Zip lib to process deletions and other pending changes */ result = zip->flush(); if (result != NO_ERROR) { fprintf(stderr, "ERROR: Zip flush failed, archive may be hosed\n"); goto bail; } /* anything here? */ if (zip->getNumEntries() == 0) { if (bundle->getVerbose()) { printf("Archive is empty -- removing %s\n", outputFile.getPathLeaf().string()); } delete zip; // close the file so we can remove it in Win32 zip = NULL; if (unlink(outputFile.string()) != 0) { fprintf(stderr, "warning: could not unlink '%s'\n", outputFile.string()); } } assert(result == NO_ERROR); bail: delete zip; // must close before remove in Win32 if (result != NO_ERROR) { if (bundle->getVerbose()) { printf("Removing %s due to earlier failures\n", outputFile.string()); } if (unlink(outputFile.string()) != 0) { fprintf(stderr, "warning: could not unlink '%s'\n", outputFile.string()); } } if (result == NO_ERROR && bundle->getVerbose()) printf("Done!\n"); return result; }
String8 String8::formatV(const char* fmt, va_list args) { String8 result; result.appendFormatV(fmt, args); return result; }
static String8 find(const char* kind) { String8 result; int emulationStatus = checkGlesEmulationStatus(); switch (emulationStatus) { case 0: #if defined(__LP64__) result.setTo("/system/lib64/egl/libGLES_android.so"); #else result.setTo("/system/lib/egl/libGLES_android.so"); #endif return result; case 1: // Use host-side OpenGL through the "emulation" library #if defined(__LP64__) result.appendFormat("/system/lib64/egl/lib%s_emulation.so", kind); #else result.appendFormat("/system/lib/egl/lib%s_emulation.so", kind); #endif return result; default: // Not in emulator, or use other guest-side implementation break; } String8 pattern; pattern.appendFormat("lib%s", kind); const char* const searchPaths[] = { #if defined(__LP64__) "/vendor/lib64/egl", "/system/lib64/egl" #else "/vendor/lib/egl", "/system/lib/egl" #endif }; // first, we search for the exact name of the GLES userspace // driver in both locations. // i.e.: // libGLES.so, or: // libEGL.so, libGLESv1_CM.so, libGLESv2.so for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { if (find(result, pattern, searchPaths[i], true)) { return result; } } // for compatibility with the old "egl.cfg" naming convention // we look for files that match: // libGLES_*.so, or: // libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so pattern.append("_"); for (size_t i=0 ; i<NELEM(searchPaths) ; i++) { if (find(result, pattern, searchPaths[i], false)) { return result; } } // we didn't find the driver. gah. result.clear(); return result; }