ANativeWindowDisplayAdapter::~ANativeWindowDisplayAdapter() { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; ///The ANativeWindow object will get destroyed here destroy(); ///If Display thread exists if (mDisplayThread.get()) { ///Kill the display thread sem.Create(); msg.command = DisplayThread::DISPLAY_EXIT; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Exit and cleanup the thread mDisplayThread->requestExitAndWait(); // Delete the display thread mDisplayThread.clear(); } LOG_FUNCTION_NAME_EXIT; }
int main() { cout << "Simple Serialization Illustration."<<endl; sem.Create(0); std::thread t1 (function1); std::thread t2 (function2); t1.join(); t2.join(); sem.Destroy(); cout << "Thank you executing my implementaion © to ashish modi. "<<endl; }
ANativeWindowDisplayAdapter::~ANativeWindowDisplayAdapter() { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; ///If Frame provider exists if (mFrameProvider) { // Unregister with the frame provider mFrameProvider->disableFrameNotification(CameraFrame::ALL_FRAMES); delete mFrameProvider; mFrameProvider = NULL; } ///The ANativeWindow object will get destroyed here destroy(); ///If Display thread exists if(mDisplayThread.get()) { ///Kill the display thread sem.Create(); msg.command = DisplayThread::DISPLAY_EXIT; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Exit and cleanup the thread mDisplayThread->requestExitAndWait(); // Delete the display thread mDisplayThread.clear(); } LOG_FUNCTION_NAME_EXIT; }
int ANativeWindowDisplayAdapter::enableDisplay(int width, int height, struct timeval *refTime, S3DParameters *s3dParams) { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; if ( mDisplayEnabled ) { LOGINFO("Display is already enabled"); LOG_FUNCTION_NAME_EXIT; return NO_ERROR; } //Send START_DISPLAY COMMAND to display thread. Display thread will start and then wait for a message sem.Create(); msg.command = DisplayThread::DISPLAY_START; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Register with the frame provider for frames mFrameProvider->enableFrameNotification(CameraFrame::PREVIEW_FRAME_SYNC); mDisplayEnabled = true; mPreviewWidth = width; mPreviewHeight = height; LOGINFO("mPreviewWidth = %d mPreviewHeight = %d", mPreviewWidth, mPreviewHeight); LOG_FUNCTION_NAME_EXIT; return NO_ERROR; }
int ANativeWindowDisplayAdapter::disableDisplay(bool cancel_buffer) { status_t ret = NO_ERROR; GraphicBufferMapper &mapper = GraphicBufferMapper::get(); LOG_FUNCTION_NAME; if (!mDisplayEnabled) { LOGE("Display is already disabled"); LOG_FUNCTION_NAME_EXIT; return ALREADY_EXISTS; } // Unregister with the frame provider here if (NULL != mDisplayThread.get()) { //Send STOP_DISPLAY COMMAND to display thread. Display thread will stop and dequeue all messages // and then wait for message Semaphore sem; sem.Create(); TIUTILS::Message msg; msg.command = DisplayThread::DISPLAY_STOP; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK for display to be disabled sem.Wait(); } Mutex::Autolock lock(mLock); { ///Reset the display enabled flag mDisplayEnabled = false; ///Reset the offset values mXOff = 0; mYOff = 0; ///Reset the frame width and height values mFrameWidth = 0; mFrameHeight = 0; mPreviewWidth = 0; mPreviewHeight = 0; if (cancel_buffer) { // Return the buffers to ANativeWindow here, the mFramesWithCameraAdapterMap is also cleared inside returnBuffersToWindow(); } else { mANativeWindow = NULL; // Clear the frames with camera adapter map mFramesWithCameraAdapterMap.clear(); } } LOG_FUNCTION_NAME_EXIT; return NO_ERROR; }