CameraHal: Add support for reprocessing with buffer borders

- The header of the processed buffer should be
  set correctly in order for the camera component
  to properly match the start of the valid data.

Depends on frameworks/av change I788dd738:
http://review.omapzoom.org/#/c/29677/

Depends on hardware/libhardware change Ie37ab311:
http://review.omapzoom.org/#/c/29676/

Change-Id: I003b7cfae41ddf6bb46661e0803a4fb1b60a99e6
Signed-off-by: Emilian Peev <epeev@mm-sol.com>
Signed-off-by: Vladimir Petrov <vppetrov@mm-sol.com>
diff --git a/camera/BufferSourceAdapter.cpp b/camera/BufferSourceAdapter.cpp
index 67fb339..a595b4b 100644
--- a/camera/BufferSourceAdapter.cpp
+++ b/camera/BufferSourceAdapter.cpp
@@ -653,6 +653,10 @@
     err = extendedOps()->get_buffer_dimension(mBufferSource, &mBuffers[0].width, &mBuffers[0].height);
     err = extendedOps()->get_buffer_format(mBufferSource, &formatSource);
 
+    int t, l, r, b, w, h;
+    err = extendedOps()->get_crop(mBufferSource, &l, &t, &r, &b);
+    err = extendedOps()->get_current_size(mBufferSource, &w, &h);
+
     // lock buffer
     {
         void *y_uv[2];
@@ -666,6 +670,8 @@
     mPixelFormat = getFormatFromANW(formatSource);
 
     mBuffers[0].format = mPixelFormat;
+    mBuffers[0].actual_size = CameraHal::calculateBufferSize(mPixelFormat, w, h);
+    mBuffers[0].offset = t * w + l * CameraHal::getBPP(mPixelFormat);
     mBufferSourceDirection = BUFFER_SOURCE_TAP_IN;
 
     return mBuffers;
diff --git a/camera/CameraHal.cpp b/camera/CameraHal.cpp
index 0be515a..53f4963 100644
--- a/camera/CameraHal.cpp
+++ b/camera/CameraHal.cpp
@@ -91,6 +91,16 @@
 static int dummy_get_buffer_count(preview_stream_ops_t*, int *count) {
     return INVALID_OPERATION;
 }
+
+static int dummy_get_crop(preview_stream_ops_t*,
+                          int *, int *, int *, int *) {
+    return INVALID_OPERATION;
+}
+
+static int dummy_get_current_size(preview_stream_ops_t*,
+                                  int *, int *) {
+    return INVALID_OPERATION;
+}
 #endif
 
 #ifdef OMAP_ENHANCEMENT
@@ -102,6 +112,8 @@
     dummy_set_metadata,
     dummy_get_id,
     dummy_get_buffer_count,
+    dummy_get_crop,
+    dummy_get_current_size,
 #endif
 };
 #endif
diff --git a/camera/OMXCameraAdapter/OMXReprocess.cpp b/camera/OMXCameraAdapter/OMXReprocess.cpp
index c720c2b..9057c1c 100644
--- a/camera/OMXCameraAdapter/OMXReprocess.cpp
+++ b/camera/OMXCameraAdapter/OMXReprocess.cpp
@@ -109,8 +109,10 @@
         android::AutoMutex lock(mBurstLock);
 
         for ( int index = 0 ; index < portData->mMaxQueueable ; index++ ) {
-            CAMHAL_LOGDB("Queuing buffer on video input port - %p",
-                         portData->mBufferHeader[index]->pBuffer);
+            CAMHAL_LOGDB("Queuing buffer on video input port - %p, offset: %d, length: %d",
+                         portData->mBufferHeader[index]->pBuffer,
+                         portData->mBufferHeader[index]->nOffset,
+                         portData->mBufferHeader[index]->nFilledLen);
             portData->mStatus[index] = OMXCameraPortParameters::FILL;
             eError = OMX_EmptyThisBuffer(mCameraAdapterParameters.mHandleComp,
                     (OMX_BUFFERHEADERTYPE*)portData->mBufferHeader[index]);
@@ -323,6 +325,8 @@
         pBufferHdr->nVersion.s.nVersionMinor = 1 ;
         pBufferHdr->nVersion.s.nRevision = 0;
         pBufferHdr->nVersion.s.nStep =  0;
+        pBufferHdr->nOffset = bufArr[index].offset;
+        pBufferHdr->nFilledLen = bufArr[index].actual_size;
         portData->mBufferHeader[index] = pBufferHdr;
     }
 
diff --git a/camera/inc/CameraHal.h b/camera/inc/CameraHal.h
index 253db42..f1119fc 100644
--- a/camera/inc/CameraHal.h
+++ b/camera/inc/CameraHal.h
@@ -355,6 +355,9 @@
 
 #endif
 
+    /* These are for buffers which include borders */
+    int offset; // where valid data starts
+    int actual_size; // size of the entire buffer with borders
 } CameraBuffer;
 
 void * camera_buffer_get_omx_ptr (CameraBuffer *buffer);