static OsNetworkHandle* OsNetworkHandle_Create() { LOGFUNC(); OsNetworkHandle* handle = (OsNetworkHandle*) malloc(sizeof(OsNetworkHandle)); if ( handle == NULL ) return NULL; THandle mtx = OsMutexCreate(""); if ( mtx == kHandleNull ) { free(handle); return NULL; } handle->iMutex = mtx; handle->iSocket = -1; handle->iIntSocket = -1; handle->iFlagInterrupted = 0; LOG("Allocted OsNetworkHandle %08x\n", handle); return handle; }
void CaptureThread::run() { LOGFUNC("CaptureThread::run"); while(1) { //////////////////////////////// // Stop thread if doStop=TRUE // //////////////////////////////// doStopMutex.lock(); if(doStop) { doStop=false; doStopMutex.unlock(); break; } doStopMutex.unlock(); ////////////////////////////////////// // Stop capturing if doPause = TRUE // ////////////////////////////////////// doPauseMutex.lock(); if(doPause){ pauseCondition.wait(&doPauseMutex); } doPauseMutex.unlock(); // Save capture time captureTime=t.elapsed(); // Start timer (used to calculate capture rate) t.start(); // Synchronize with other streams (if enabled for this stream) sharedImageBuffer->sync(CameraDevice->deviceNumber); mCaptureFrameMutex.lock(); // Capture fraCameraDeviceme (if available) if(!CameraDevice->grabFrame(&mGrabbedFrame))continue; if(imageNeeded){ if(imageToCapture!=NULL) *imageToCapture = mGrabbedFrame.copy(); imageNeeded = false; } // Add frame to buffer if(mGrabbedFrame.width()!=0 && mGrabbedFrame.height()!=0){ sharedImageBuffer->getByDeviceNumber(CameraDevice->deviceNumber)->add(mGrabbedFrame, dropFrameIfBufferFull); } else{ LOG_D("Invalid frame"); } mCaptureFrameMutex.unlock(); // Update statistics updateFPS(captureTime); statsData.nFramesProcessed++; // Inform GUI of updated statistics emit updateStatisticsInGUI(statsData); } }
uint32_t InStream::get_channels() const { LOGFUNC("%s(%p)", __func__, this); if (mConfig.channels == 1) { return AUDIO_CHANNEL_IN_MONO; } else { return AUDIO_CHANNEL_IN_STEREO; } }
int InStream::startInputStream() { LOGFUNC("%s(%p)", __func__, this); mUcm.activateEntry(mEntry, this); int card = mUcm.getCaptureCard(mEntry); int port = mUcm.getCapturePort(mEntry); ALOGE("setting capture card=%d port=%d", card, port); mPcm = pcm_open(card, port, PCM_IN, &mConfig); if (!pcm_is_ready(mPcm)) { ALOGE("cannot open pcm_in driver: %s", pcm_get_error(mPcm)); pcm_close(mPcm); mPcm = NULL; mUcm.deactivateEntry(mEntry); return -ENOMEM; } mStandby = false; return 0; }
int ucmhal_adev_open(const hw_module_t* module, const char* name, hw_device_t** device) { LOGFUNC("%s(%p, %s, %p)", __func__, module, name, device); if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; UcmHal::Dev *dev = new UcmHal::Dev(module); if (!dev) return -ENOMEM; int ret = dev->init_check(); if (ret) delete dev; else *device = &dev->audio_hw_device()->common; return ret; }
static void OsNetworkHandle_Destroy(OsNetworkHandle* aHandle) { LOGFUNC(); #if INT_ENABLED if ( aHandle->iIntSocket >= 0 ) { lwip_close(aHandle->iIntSocket); } #endif OsMutexDestroy(aHandle->iMutex); aHandle->iSocket = -1; aHandle->iIntSocket = -1; aHandle->iFlagInterrupted = 1; free(aHandle); LOG("Destroyd OsNetworkHandle %08x\n", aHandle); }
static int OsNetworkHandle_Initialise(OsNetworkHandle* aHandle, int aSocket) { LOGFUNC(); aHandle->iSocket = aSocket; #if INT_ENABLED int ih = lwip_socket(AF_INET, SOCK_DGRAM, 0); if ( ih < 0 ) { LOG("%s failed with %d\n", __FUNCTION__, errno); return -1; } struct sockaddr_in s; s.sin_family = AF_INET; s.sin_port = htons( 10000 + (short) aSocket ); // relate port to fd s.sin_addr.s_addr = IPADDR_LOOPBACK; // localhost int err = lwip_bind ( ih, (struct sockaddr*) &s, sizeof(s) ); if ( err < 0 ) { lwip_close(ih); return -1; } aHandle->iIntSocket = ih; #endif LOG("Created OsNetworkHandle %d:%d\n", aHandle->iSocket, aHandle->iIntSocket); return 0; }
ssize_t InStream::read(void* buffer, size_t bytes) { int ret = 0; LOGFUNC("%s(%p, %p, %d)", __func__, this, buffer, bytes); AutoMutex lock(mLock); if (mStandby) { if (startInputStream()) return -EBUSY; } ret = pcm_read(mPcm, buffer, bytes); ALOGV("pcm_read(%p, %p, %d) returned %d", mPcm, buffer, bytes, ret); if (ret >= 0 && mDev.mMicMute) memset(buffer, 0, bytes); if (ret < 0) { ALOGE("pcm_read(%p, %p, %d) returned %d", mPcm, buffer, bytes, ret); usleep(bytes * 1000000 / audio_stream_frame_size(&audio_stream_in()->common) / mConfig.rate); } return bytes; }
size_t InStream::get_buffer_size() const { LOGFUNC("%s(%p)", __func__, this); return mConfig.period_size; }
int main(int argc, char *argv[]) { int opt; char *parameters = "m:l:t:i:"; LOG_MODULE module; LOG_LEVEL severity; int times; int interval; unsigned long id = 1;//default va_list ap; char text[LOGGER_TEXT_SIZE]; char *p_text = NULL; while((opt = getopt(argc, argv, parameters)) != -1) { switch(opt) { case 'm': if(*optarg == '-') { print_help(); return -1; } module = atoi(optarg); printf("module: %d\n", module); break; case 'l': if(*optarg == '-') { print_help(); return -1; } severity = atoi(optarg); printf("severity: %d\n", severity); break; case 't': if(*optarg == '-') { print_help(); return -1; } times = atoi(optarg); printf("times: %d\n", times); break; case 'i': if(*optarg == '-') { print_help(); return -1; } interval = atoi(optarg); printf("interval: %d\n", interval); break; default: printf("default\n"); print_help(); return -1; break; } } printf("argc: %d, optind: %d\n", argc, optind); #if 1 if((argc - optind) != 1) { printf("Incorrect inputed arguments\n"); print_help(); return -1; } #endif p_text = argv[optind]; memcpy(text, p_text, sizeof(text)); printf("text: %s\n", text); LOGFUNC(module, severity, id, text); //LOGFUNC(L_CLI, L_DEBUGGING, 1, "This is debug message, pleas ignore it\n"); return 0; }
int InStream::set_gain(float gain) { LOGFUNC("%s(%p)", __func__, this); //TODO return 0; }
int Dev::get_mic_mute(bool *state) const { LOGFUNC("%s(%p, %d)", __func__, this, mMicMute); *state = mMicMute; return 0; }
int Dev::set_mic_mute(bool state) { LOGFUNC("%s(%p, %d)", __func__, this, state); mMicMute = state; // TODO Should set input stream volumes to zero? return 0; }
int Dev::set_master_volume(float volume) { LOGFUNC("%s(%p, %f)", __func__, this, volume); return -ENOSYS; }
char * Dev::get_parameters(const char *keys) const { LOGFUNC("%s(%p, %s)", __func__, this, keys); // TODO this is broken return mParameters.toStr(); }
int Dev::set_parameters(const char *kvpairs) { LOGFUNC("%s(%p, %s)", __func__, this, kvpairs); mParameters.updateTrigger(kvpairs); return 0; }
uint32_t InStream::get_input_frames_lost() { LOGFUNC("%s(%p)", __func__, this); //TODO return 0; }