SlideShare uma empresa Scribd logo
1 de 27
Android Camera  Architecture Author: Picker
Architecture
 
Architecture Path of the Source Code  frameworks/base/core/java/android/hardware/ frameworks/base/core/jni/ frameworks/base/libs/camera/ frameworks/base/services/camera/libcameraservice/ vendor/nvidia/tegra/hal/libnvomxcamera/
Proxy Pattern
Reference to:  Design Patterns  by Gamma, Helm, Johnson, Vlissides
A Possible Object Diagram of Proxy Structure at Run-Time Proxy Structure Reference to:  Design Patterns  by Gamma, Helm, Johnson, Vlissides
Implementation - Design a Abstract Class for Proxy and Server to Extend it. - Give an RealObject Instance for Proxy. Execute these Methods by Proxy.  - The Client just Need to Face the Proxy.
Singleton Pattern
Reference to:  Design Patterns  by Gamma, Helm, Johnson, Vlissides Singleton Structure
Reference to:  Design Patterns  by Gamma, Helm, Johnson, Vlissides Singleton* Singleton::_instance = 0; Singleton* Singleton::Instance () { if (_instance == 0) { _instance = new Singleton; } return _instance; } Implementation
Architecture Diagram
Proxy Pattern Singleton Pattern
33 // client singleton for camera service binder interface 34 Mutex Camera::mLock; 35  sp<ICameraService> Camera::mCameraService; 36 sp<Camera::DeathNotifier> Camera::mDeathNotifier; Singleton Pattern Camera.cpp frameworks/base/libs/camera/
38 // establish binder interface to camera service 39 const sp<ICameraService>& Camera::getCameraService() 40 {  41  Mutex::Autolock _l(mLock); 42  if (mCameraService.get() == 0) { 43  sp<IServiceManager> sm = defaultServiceManager(); 44  sp<IBinder> binder; 45  do { 46  binder = sm->getService(String16(&quot;media.camera&quot;)); 47  if (binder != 0) 48  break; 49  LOGW(&quot;CameraService not published, waiting...&quot;); 50  usleep(500000); // 0.5 s  51  } while(true); 52  if (mDeathNotifier == NULL) {  53  mDeathNotifier = new DeathNotifier(); 54  } 55  binder->linkToDeath(mDeathNotifier); 56  mCameraService = interface_cast<ICameraService>(binder); 57  } 58  LOGE_IF(mCameraService==0, &quot;no CameraService!?&quot;); 59  return mCameraService; 60 }  Camera.cpp frameworks/base/libs/camera/
53  class BpCamera: public BpInterface<ICamera> 54 { 55 public: 56  BpCamera(const sp<IBinder>& impl) 57  : BpInterface<ICamera>(impl) 58  { 59  } 60  61  // disconnect from camera service 62  void disconnect() 63  { 64  LOGV(&quot;disconnect&quot;); 65  Parcel data, reply; 66  data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); 67  remote()->transact(DISCONNECT, data, &reply); 68  } ICamera.cpp frameworks/base/libs/camera/ Proxy Pattern - Sender
34 class CameraService : 35  public BinderService<CameraService>, 36  public BnCameraService 37 { 38  class Client; 39  friend class BinderService<CameraService>; 82  class Client : public BnCamera 83  { 84  public: 85  // ICamera interface (see ICamera for details) 86  virtual void  disconnect(); 87  virtual status_t  connect(const sp<ICameraClient>& client); 88  virtual status_t  lock(); 89  virtual status_t  unlock(); … … … 206 } Proxy Pattern - Receiver CameraService.h frameworks/base/services/camera/libcameraservice/
A Simple Workflow of  Starting the Camera Preview
 
An Example: Set the Preview Display
349  public final void  setPreviewDisplay (SurfaceHolder holder) throws IOException { 350  if (holder != null) { 351  setPreviewDisplay (holder.getSurface()); 352  } else { 353  setPreviewDisplay ((Surface)null); 354  } 355  } Camera.java frameworks/base/core/java/android/hardware/
android_hardware_Camera.cpp 381 static void  android_hardware_Camera_setPreviewDisplay ( JNIEnv *env, jobject thiz, jobject jSurface) 382 { 383  LOGV(&quot;setPreviewDisplay&quot;); 384  sp<Camera> camera = get_native_camera(env, thiz, NULL); 385  if (camera == 0) return; 386  387  sp<Surface> surface = NULL;  388  if (jSurface != NULL) { 389  surface = reinterpret_cast<Surface*>( env->GetIntField(jSurface, fields.surface)); 390  } 391  if ( camera->setPreviewDisplay (surface) != NO_ERROR) { 392  jniThrowException(env, &quot;java/io/IOException&quot;, &quot;setPreviewDisplay failed&quot;); 393  } 394 }  frameworks/base/core/jni/
Camera.cpp frameworks/base/libs/camera/ 171 // pass the buffered ISurface to the camera service 172 status_t  Camera::setPreviewDisplay (const sp<Surface>& surface) 173 {  174  LOGV(&quot;setPreviewDisplay&quot;); 175  sp <ICamera> c = mCamera; 176  if (c == 0) return NO_INIT;  177  if (surface != 0) { 178  return  c->setPreviewDisplay (surface->getISurface()); 179  } else { 180  LOGD(&quot;app passed NULL surface&quot;); 181  return  c->setPreviewDisplay (0); 182  } 183 }
ICamera.cpp 70  // pass the buffered ISurface to the camera service 71  status_t  setPreviewDisplay (const sp<ISurface>& surface) 72  { 73  LOGV(&quot;setPreviewDisplay&quot;);  74  Parcel data, reply; 75  data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); 76  data.writeStrongBinder(surface->asBinder()); 77  remote()->transact (SET_PREVIEW_DISPLAY, data, &reply); 78  return reply.readInt32();  79  } frameworks/base/libs/camera/
CameraService.cpp frameworks/base/libs/camera/ 485 status_t  CameraService::Client::setPreviewDisplay (const sp<ISurface>& surface) { 486  LOG1(&quot;setPreviewDisplay(%p) (pid %d)&quot;, surface.get(), getCallingPid());  … … … 510  mSurface = surface; 511  mOverlayRef = 0; 512  // If preview has been already started, set overlay or register preview 513  // buffers now. 514  if ( mHardware->previewEnabled() ) {  515  if (mUseOverlay) { 516  result = setOverlay();  517  } else if (mSurface != 0) {  518  result = registerPreviewBuffers(); 519  } 520  }
frameworks/base/libs/camera/ CameraService.cpp 525 status_t  CameraService::Client::registerPreviewBuffers () { 526  int w, h; 527  CameraParameters params(mHardware->getParameters()); 528  params.getPreviewSize(&w, &h); 529  530  // FIXME: don't use a hardcoded format here. 531  ISurface::BufferHeap buffers(w, h, w, h, 532  HAL_PIXEL_FORMAT_YCrCb_420_SP, 533  mOrientation, 534  0, 535  mHardware->getPreviewHeap ()); 536  537  status_t result = mSurface->registerBuffers(buffers); 538  if (result != NO_ERROR) { 539  LOGE(&quot;registerBuffers failed with status %d&quot;, result); 540  } 541  return result; 542 }
frameworks/base/libs/camera/ CameraHardwareStub.cpp 104 sp<IMemoryHeap>  CameraHardwareStub::getPreviewHeap()  const 105 {  106  return mPreviewHeap; 107 }

Mais conteúdo relacionado

Mais procurados

Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
Binderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroidBinderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroid
l_b__
 
Android audio system(오디오 플링거 서비스 초기화)
Android audio system(오디오 플링거 서비스 초기화)Android audio system(오디오 플링거 서비스 초기화)
Android audio system(오디오 플링거 서비스 초기화)
fefe7270
 

Mais procurados (20)

Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2 Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2
 
Binderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroidBinderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroid
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Android audio system(오디오 플링거 서비스 초기화)
Android audio system(오디오 플링거 서비스 초기화)Android audio system(오디오 플링거 서비스 초기화)
Android audio system(오디오 플링거 서비스 초기화)
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted Firmware
 
ExoPlayer for Application developers
ExoPlayer for Application developersExoPlayer for Application developers
ExoPlayer for Application developers
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 

Semelhante a Android Camera Architecture

Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
bhochhi
 

Semelhante a Android Camera Architecture (20)

Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
FLAR Workflow
FLAR WorkflowFLAR Workflow
FLAR Workflow
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Android camera2
Android camera2Android camera2
Android camera2
 
my accadanic project ppt
my accadanic project pptmy accadanic project ppt
my accadanic project ppt
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
 
Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
 

Mais de Picker Weng

Vim+cscope+ctags+taglist
Vim+cscope+ctags+taglistVim+cscope+ctags+taglist
Vim+cscope+ctags+taglist
Picker Weng
 

Mais de Picker Weng (10)

Introduction to Agile & Scrum
Introduction to Agile & ScrumIntroduction to Agile & Scrum
Introduction to Agile & Scrum
 
The Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on LinuxThe Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on Linux
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Tutorial for Installing eclox
Tutorial for Installing ecloxTutorial for Installing eclox
Tutorial for Installing eclox
 
Chromium OS - User Accounts and Management
Chromium OS - User Accounts and ManagementChromium OS - User Accounts and Management
Chromium OS - User Accounts and Management
 
[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8
 
[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6
 
OpenCV 2.2.0 for Android
OpenCV 2.2.0 for AndroidOpenCV 2.2.0 for Android
OpenCV 2.2.0 for Android
 
Uml
UmlUml
Uml
 
Vim+cscope+ctags+taglist
Vim+cscope+ctags+taglistVim+cscope+ctags+taglist
Vim+cscope+ctags+taglist
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Android Camera Architecture

  • 1. Android Camera Architecture Author: Picker
  • 3.  
  • 4. Architecture Path of the Source Code frameworks/base/core/java/android/hardware/ frameworks/base/core/jni/ frameworks/base/libs/camera/ frameworks/base/services/camera/libcameraservice/ vendor/nvidia/tegra/hal/libnvomxcamera/
  • 6. Reference to: Design Patterns by Gamma, Helm, Johnson, Vlissides
  • 7. A Possible Object Diagram of Proxy Structure at Run-Time Proxy Structure Reference to: Design Patterns by Gamma, Helm, Johnson, Vlissides
  • 8. Implementation - Design a Abstract Class for Proxy and Server to Extend it. - Give an RealObject Instance for Proxy. Execute these Methods by Proxy. - The Client just Need to Face the Proxy.
  • 10. Reference to: Design Patterns by Gamma, Helm, Johnson, Vlissides Singleton Structure
  • 11. Reference to: Design Patterns by Gamma, Helm, Johnson, Vlissides Singleton* Singleton::_instance = 0; Singleton* Singleton::Instance () { if (_instance == 0) { _instance = new Singleton; } return _instance; } Implementation
  • 14. 33 // client singleton for camera service binder interface 34 Mutex Camera::mLock; 35 sp<ICameraService> Camera::mCameraService; 36 sp<Camera::DeathNotifier> Camera::mDeathNotifier; Singleton Pattern Camera.cpp frameworks/base/libs/camera/
  • 15. 38 // establish binder interface to camera service 39 const sp<ICameraService>& Camera::getCameraService() 40 { 41 Mutex::Autolock _l(mLock); 42 if (mCameraService.get() == 0) { 43 sp<IServiceManager> sm = defaultServiceManager(); 44 sp<IBinder> binder; 45 do { 46 binder = sm->getService(String16(&quot;media.camera&quot;)); 47 if (binder != 0) 48 break; 49 LOGW(&quot;CameraService not published, waiting...&quot;); 50 usleep(500000); // 0.5 s 51 } while(true); 52 if (mDeathNotifier == NULL) { 53 mDeathNotifier = new DeathNotifier(); 54 } 55 binder->linkToDeath(mDeathNotifier); 56 mCameraService = interface_cast<ICameraService>(binder); 57 } 58 LOGE_IF(mCameraService==0, &quot;no CameraService!?&quot;); 59 return mCameraService; 60 } Camera.cpp frameworks/base/libs/camera/
  • 16. 53 class BpCamera: public BpInterface<ICamera> 54 { 55 public: 56 BpCamera(const sp<IBinder>& impl) 57 : BpInterface<ICamera>(impl) 58 { 59 } 60 61 // disconnect from camera service 62 void disconnect() 63 { 64 LOGV(&quot;disconnect&quot;); 65 Parcel data, reply; 66 data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); 67 remote()->transact(DISCONNECT, data, &reply); 68 } ICamera.cpp frameworks/base/libs/camera/ Proxy Pattern - Sender
  • 17. 34 class CameraService : 35 public BinderService<CameraService>, 36 public BnCameraService 37 { 38 class Client; 39 friend class BinderService<CameraService>; 82 class Client : public BnCamera 83 { 84 public: 85 // ICamera interface (see ICamera for details) 86 virtual void disconnect(); 87 virtual status_t connect(const sp<ICameraClient>& client); 88 virtual status_t lock(); 89 virtual status_t unlock(); … … … 206 } Proxy Pattern - Receiver CameraService.h frameworks/base/services/camera/libcameraservice/
  • 18. A Simple Workflow of Starting the Camera Preview
  • 19.  
  • 20. An Example: Set the Preview Display
  • 21. 349 public final void setPreviewDisplay (SurfaceHolder holder) throws IOException { 350 if (holder != null) { 351 setPreviewDisplay (holder.getSurface()); 352 } else { 353 setPreviewDisplay ((Surface)null); 354 } 355 } Camera.java frameworks/base/core/java/android/hardware/
  • 22. android_hardware_Camera.cpp 381 static void android_hardware_Camera_setPreviewDisplay ( JNIEnv *env, jobject thiz, jobject jSurface) 382 { 383 LOGV(&quot;setPreviewDisplay&quot;); 384 sp<Camera> camera = get_native_camera(env, thiz, NULL); 385 if (camera == 0) return; 386 387 sp<Surface> surface = NULL; 388 if (jSurface != NULL) { 389 surface = reinterpret_cast<Surface*>( env->GetIntField(jSurface, fields.surface)); 390 } 391 if ( camera->setPreviewDisplay (surface) != NO_ERROR) { 392 jniThrowException(env, &quot;java/io/IOException&quot;, &quot;setPreviewDisplay failed&quot;); 393 } 394 } frameworks/base/core/jni/
  • 23. Camera.cpp frameworks/base/libs/camera/ 171 // pass the buffered ISurface to the camera service 172 status_t Camera::setPreviewDisplay (const sp<Surface>& surface) 173 { 174 LOGV(&quot;setPreviewDisplay&quot;); 175 sp <ICamera> c = mCamera; 176 if (c == 0) return NO_INIT; 177 if (surface != 0) { 178 return c->setPreviewDisplay (surface->getISurface()); 179 } else { 180 LOGD(&quot;app passed NULL surface&quot;); 181 return c->setPreviewDisplay (0); 182 } 183 }
  • 24. ICamera.cpp 70 // pass the buffered ISurface to the camera service 71 status_t setPreviewDisplay (const sp<ISurface>& surface) 72 { 73 LOGV(&quot;setPreviewDisplay&quot;); 74 Parcel data, reply; 75 data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); 76 data.writeStrongBinder(surface->asBinder()); 77 remote()->transact (SET_PREVIEW_DISPLAY, data, &reply); 78 return reply.readInt32(); 79 } frameworks/base/libs/camera/
  • 25. CameraService.cpp frameworks/base/libs/camera/ 485 status_t CameraService::Client::setPreviewDisplay (const sp<ISurface>& surface) { 486 LOG1(&quot;setPreviewDisplay(%p) (pid %d)&quot;, surface.get(), getCallingPid()); … … … 510 mSurface = surface; 511 mOverlayRef = 0; 512 // If preview has been already started, set overlay or register preview 513 // buffers now. 514 if ( mHardware->previewEnabled() ) { 515 if (mUseOverlay) { 516 result = setOverlay(); 517 } else if (mSurface != 0) { 518 result = registerPreviewBuffers(); 519 } 520 }
  • 26. frameworks/base/libs/camera/ CameraService.cpp 525 status_t CameraService::Client::registerPreviewBuffers () { 526 int w, h; 527 CameraParameters params(mHardware->getParameters()); 528 params.getPreviewSize(&w, &h); 529 530 // FIXME: don't use a hardcoded format here. 531 ISurface::BufferHeap buffers(w, h, w, h, 532 HAL_PIXEL_FORMAT_YCrCb_420_SP, 533 mOrientation, 534 0, 535 mHardware->getPreviewHeap ()); 536 537 status_t result = mSurface->registerBuffers(buffers); 538 if (result != NO_ERROR) { 539 LOGE(&quot;registerBuffers failed with status %d&quot;, result); 540 } 541 return result; 542 }
  • 27. frameworks/base/libs/camera/ CameraHardwareStub.cpp 104 sp<IMemoryHeap> CameraHardwareStub::getPreviewHeap() const 105 { 106 return mPreviewHeap; 107 }