{"id":20,"date":"2015-03-29T14:27:14","date_gmt":"2015-03-29T14:27:14","guid":{"rendered":"https:\/\/boochlin.com\/?p=20"},"modified":"2015-03-31T10:12:25","modified_gmt":"2015-03-31T10:12:25","slug":"android-camera-analyze-%e4%b8%80-camera-1","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=20","title":{"rendered":"Android Camera analyze (\u4e00) &#8211; Camera 1 Architecture"},"content":{"rendered":"<p><iframe style=\"border: 1px solid #CCC; border-width: 1px; margin-bottom: 5px; max-width: 100%;\" src=\"\/\/www.slideshare.net\/slideshow\/embed_code\/46414495\" width=\"600\" height=\"500\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/p>\n<div style=\"margin-bottom: 5px;\"><strong> <a title=\"Introduction of Android Camera1\" href=\"\/\/www.slideshare.net\/boochlin\/camera1-46414495\" target=\"_blank\">Introduction of Android Camera1<\/a><\/strong><\/div>\n<p>\u9019\u7bc7\u7b97\u662f\u6bd4\u8f03\u4e45\u7684\u8cc7\u6599<br \/>\n\u4e3b\u8981\u662f\u5728\u8ac7andorid 4.4\u4e4b\u524d\u7684Camera\u67b6\u69cb<br \/>\n\u57285.0\u4e4b\u524d\u90fd\u662f\u4ee5 camera 1 \u7684api\u70ba\u4e3b<\/p>\n<p>\u5728\u7814\u7a76camera\u67b6\u69cb\u6642\uff0c\u8981\u7279\u5225\u6ce8\u610f\u4e0d\u5c11\u90fd\u8981\u8ddf\u5e95\u5c64\u6e9d\u901a\uff0c\uff08\u4e0d\u904e\u672c\u7bc7\u4e5f\u6c92\u8ac7\u5230kernel\u90a3\u4e00\u7aef\uff09<br \/>\n\u60f3\u7576\u7136\u5fc5\u9808\u8981\u770bc code\uff0c\u9019\u9ede\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u6642\u9593<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<h4>page 4 :<\/h4>\n<p style=\"padding-left: 30px;\">1.Camera framework to native code \u653e\u5728xxx<br \/>\n\u6703build\u6210xxxxxxxx.so<br \/>\n2.Camera \u662f\u8d70 servce client\u7684\u65b9\u5f0f\u5728\u904b\u4f5c\uff0c\u6240\u4ee5\u6709\u9019\u4e9b\u5be6\u4f5c\u7684class<br \/>\nBefore 4.2<br \/>\n<span style=\"color: #ff0000;\">frameworks\\base\\include\\camera<\/span><br \/>\n<span style=\"color: #ff0000;\"> frameworks\\base\\libs\\camera<\/span><br \/>\n<span style=\"color: #ff0000;\"> frameworks\\base\\services\\camera\\libcameraservice\\<\/span><\/p>\n<h4>page 5 :<\/h4>\n<p style=\"padding-left: 30px;\">\u4e09\u500bso\u4e4b\u9593\u7684\u95dc\u4fc2<br \/>\nCamera java call to native by jni \u85c9\u7531libandroid_runtime.so<br \/>\n\u8abf\u7528libcamera_client\u53bb\u5c0dlibcameraservice.os\u5c0dhard ware \u64cd\u4f5c<\/p>\n<h4>page 6 :<\/h4>\n<p style=\"padding-left: 30px;\">\u6574\u7406\u8d77\u4f86\u5c31\u662f\u9019\u6a23<br \/>\n1. Java framewrok \u547c\u53eb<br \/>\n2. \u900f\u904ejni\u53bbcall native \u7684 framewrk<br \/>\n3. \u5229\u7528ipc\u7684\u65b9\u5f0f\u53bb\u8ddfcamera service \u6e9d\u901a<br \/>\n4. Camera \u5247\u662f\u547c\u53eb hal interface \u53bb\u64cd\u4f5charadware<br \/>\n5. \u800chal \u7684\u5be6\u4f5c\u5247\u662f\u7531\u5404\u500bvendor\u53bb\u5b8c\u6210<\/p>\n<h4>page 7 :<\/h4>\n<p style=\"padding-left: 30px;\"><strong>\u7531java jni\u53bb\u547c\u53ebcamera\u7684\u5be6\u9ad4<\/strong><br \/>\n<strong> Camera \u4e3b\u8981\u6709\u5169\u5927\u529f\u80fd:<\/strong><\/p>\n<p style=\"padding-left: 30px;\">1. \u63a5\u6536\u4f86\u81easervice \u7684callback \u6240\u4ee5\u4ed6\u7e7c\u627fcmera client \u4e26\u5be6\u4f5c ex:jpeg call back<\/p>\n<p style=\"padding-left: 30px;\">2. \u5c0dcamera service \u76f4\u63a5\u64cd\u4f5c(\u50cf\u662f start previcew \u6240\u4ee5\u540c\u6642\u4e5f\u6709\u500b camera:service:client\u7684\u6210\u54e1\uff0c\u5be6\u4f5c\u65bcicamera<br \/>\n\u7531\u65bc\u90fd\u662f\u63a1\u7528ipc \u7684\u67b6\u69cb\uff0c\u6240\u4ee5\u6703\u6709bp,bn\u7684class<br \/>\nBp\u5c31\u662f\u4ee3\u7406\u4eba\u7a97\u53e3\uff0cbn\u5c31\u662f\u672c\u4eba<br \/>\nIcameraservice\u5247\u662f\u63d0\u4f9binitialize open\u6642\u6703\u4f7f\u7528\u5230\u7684<\/p>\n<h4>page 8 \u5230 18:<\/h4>\n<p style=\"padding-left: 30px;\">\u9019\u88e1\u975e\u5e38\u5efa\u8b70\u53c3\u8003<\/p>\n<p style=\"padding-left: 30px;\"><a title=\"reference\" href=\"http:\/\/blog.chinaunix.net\/uid-28416178-id-3446034.html\" target=\"_blank\">http:\/\/blog.chinaunix.net\/uid-28416178-id-3446034.html<\/a><\/p>\n<p style=\"padding-left: 30px;\">\u8001\u5be6\u8aaa\u61c9\u8a72\u5beb\u7684\u6bd4\u6211\u597d \uff0c\u4e0d\u904e\u53ef\u4ee5\u53c3\u7167\u6295\u5f71\u7247\u4e0a\u7684code\u7247\u6bb5\uff0c\u6709\u66f4\u65b0\u6210\u5f8c\u671f\u7684code\u3002<\/p>\n<p>&nbsp;<\/p>\n<h4>page 19:<\/h4>\n<p style=\"padding-left: 30px;\">\u5982\u679c\u6709\u8a8d\u771f\u770b\u5b8c\u524d\u5e7e\u9801\uff0c\u61c9\u8a72\u5f88\u597d\u7406\u89e3<\/p>\n<p style=\"padding-left: 30px;\">\u9019\u662f\u4e00\u4efd\u5f9e\u4e0a\u5230\u4e0b\u7684\u4e32\u9023\u904e\u7a0b\uff0c\u4ee5startPreview()\u7684\u904e\u7a0b\u70ba\u4f8b<\/p>\n<p style=\"padding-left: 30px;\">1. \u900f\u904ebnCameraClient \u547c\u53eb Icamera<br \/>\n2. Icamera \u5229\u7528 ipc \u7684\u6a5f\u5236\u8207BnCamera\u6e9d\u901a<br \/>\n3. Hal\u5c64\u5b8c\u6210\u4e4b\u5f8c\u4e00\u6a23\u900f\u904eipc\u56de\u61c9\u7d66Icamera \u767c\u9001\u5b8c\u6210\u8cc7\u6599<br \/>\n4. \u540c\u6642notifyCallback\u7d66 IcameraClient \u7d66\u4e0a\u5c64\u901a\u77e5\u5b8c\u6210<br \/>\n\u8981\u6ce8\u610f\u7684\u662f \u767c\u9001\u5b8c\u6210\u8cc7\u6599\u8ddfnotifycallback \u662f\u8d70\u4e0d\u540c\u7684ipc\u904e\u7a0b<\/p>\n<h4>page 20:<\/h4>\n<p style=\"padding-left: 30px;\">Callback\u7684\u904e\u7a0b\u4ecb\u7d39<br \/>\n<strong>1. CameraService:call back from hardward , flow start from camera client ex:jpeg call back.<\/strong><br \/>\n<span style=\"color: #ff0000;\">Code:<\/span><\/p>\n<pre>client-&gt;handleCompressedPicture(dataPtr);\r\n<\/pre>\n<p style=\"padding-left: 30px;\">\u5f9e\u4e0a\u9762\u53d6\u5f97\u7684client \u7aef \u547c\u53ebhandleCompressedPicture\uff0c\u5b8c\u6210\u7684\u8cc7\u6599\u5247\u662f dataPtr<\/p>\n<p style=\"padding-left: 30px;\"><strong>2. ClientCamera:use: ipc binder \u201cbpcameraclient , bncameraclient in IcameraClient\u00a0<\/strong><strong>to send data , and implement in Camera.cpp.<\/strong><br \/>\n<span style=\"color: #ff0000;\">\u00a0Code:<\/span><\/p>\n<pre>sp c = mRemoteCallback;\r\nc-&gt;dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem, NULL);\r\n<\/pre>\n<p>\u9084\u662f\u8981\u5148\u53d6\u5f97 IcameraClient \u7136\u5f8c\u767c\u51fa dataCallback<br \/>\n\u6bd4\u8f03\u7279\u5225\u7684\u662f\u9019\u88e1\u8981\u958b\u59cb\u5e36\u5165 \u6307\u4ee4(CAMERA_MSG_COMPRESSED_IMAGE)+data(mem)<\/p>\n<h4>page 21:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>3. JNI : use ipc binder \u201cbpcameraclient , bncameraclient in IcameraClient to send data\u00a0<\/strong><strong>, and implement in Camera.cpp.<\/strong><br \/>\n<span style=\"color: #ff0000;\"> Code: <\/span><\/p>\n<pre>listener-&gt;postData(msgType, dataPtr, metadata);\r\n\u7d42\u65bc\u63a5\u5230\u4e86jni\u5c64\uff0c\u9019\u88e1listener\u662f\u4e0a\u9762\u6240\u8a2d\u5b9a\u7684\u63a5\u53d7\u8005\r\n<\/pre>\n<h4>page 22:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>\u627f\u7e8c\u4e0a\u9801 CameraListener \u7684\u8a2d\u8a08\uff0c\u9019\u88e1\u7684\u5beb\u6cd5\u662f\u70ba\u4e86\u548c JNIEnv \u505a\u929c\u63a5.<\/strong><br \/>\n<strong> Note:<\/strong><br \/>\nmsgType enum values and data structures, ex: \u201ccamera_frame_metadata_t\u201d<br \/>\nare defined in \u201csystem\\core\\include\\system\\camera.h.<\/p>\n<pre>class CameraListener: virtual public RefBase\r\n{\r\npublic:\r\nvirtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;\r\nvirtual void postData(int32_t msgType, const sp&amp; dataPtr,\r\ncamera_frame_metadata_t *metadata) = 0;\r\nvirtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType,\r\nconst sp&amp; dataPtr) = 0;\r\n};\r\n\r\n<\/pre>\n<h4>page 23:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>4. Implement cameraListener post data in android_haradware_camera.cpp.<\/strong><br \/>\n<span style=\"color: #ff0000;\">Code: <\/span><\/p>\n<pre>copyAndPost(env, dataPtr, dataMsgType);\r\n<\/pre>\n<p style=\"padding-left: 30px;\"><strong>5.post image data to Java by JNI.<\/strong><br \/>\n<span style=\"color: #ff0000;\">Code:<\/span><\/p>\n<pre>env-&gt;CallStaticVoidMethod(mCameraJClass, fields.post_event,\r\nmCameraJObjectWeak, msgType, 0, 0, obj);\r\n<\/pre>\n<p>\u500b\u4eba\u8a8d\u70ba\u9019\u88e1\u53ef\u4ee5\u8a73\u7d30\u53bb\u7814\u7a76jni\u7684\u6a5f\u5236\uff0c\u9019\u88e1\u4e0d\u591a\u8ac7\uff0c\u5f88\u9177\u7684\u624b\u6cd5<\/p>\n<h4>page 24:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>6. Call back to ap level :Framework\/base\/core\/java\/android\/hardware\/camera.java.<\/strong><br \/>\n<span style=\"color: #ff0000;\">Code: <\/span><\/p>\n<pre>public void handleMessage(Message msg) {\r\nswitch(msg.what) {\r\ncase CAMERA_MSG_COMPRESSED_IMAGE:\r\nmJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);\r\n<\/pre>\n<p>\u7d42\u65bc\u63a5\u5230java\u5c64\u5566\uff0c\u770bc code\u771f\u7684\u6709\u9ede\u7d2f\uff0c\u5f9eap\u5c64\u8a3b\u518a\u7684callback\u767c\u9001\u56de\u53bb<\/p>\n<p style=\"padding-left: 30px;\">\u4ee5\u4e0a\u5b8c\u6210\uff0c\u4e0b\u4e00\u56de\u5247\u662f\u65b0\u7684api \u904b\u7528 \u00a0&#8220;camera2&#8221;<\/p>\n<p>ref:<br \/>\nhttp:\/\/blog.chinaunix.net\/uid-28416178-id-3446034.html<br \/>\nhttp:\/\/blog.csdn.net\/llping2011\/article\/details\/9372799<br \/>\nhttp:\/\/blog.163.com\/shawpin@126\/blog\/static\/116663752201092394147937\/<br \/>\nhttp:\/\/www.eoeandroid.com\/blog-10407-5106.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction of Android Camera1 \u9019\u7bc7\u7b97\u662f\u6bd4\u8f03\u4e45\u7684\u8cc7\u6599 \u4e3b\u8981\u662f\u5728\u8ac7andorid 4.4\u4e4b\u524d\u7684Camera\u67b6\u69cb \u57285.0\u4e4b\u524d\u90fd\u662f\u4ee5 camera 1 \u7684api\u70ba\u4e3b \u5728\u7814\u7a76&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[47],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":1,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":28,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/28"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}