camera: Use genlock to lock/unlock buffers

Aquire a write lock on the dequeued buffer using genlock. Unlock the
locked buffer before an enqueue or a cancel operation.

This is port of commit:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=b6483d08a636a2c1f1db66bf8aba4c0e6d5a4f32
QualcommCameraHardware: Maintain lockStates for display buffers.

Maintain lock states for buffers. Unlock buffers only if they were
previously locked.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=c5e12cd8c38ee0516dff6875ec56e5bffc0d0610
Camera : Fix snapshot crash issues

Wait for snapshot thread to complete before proceeding with stop preview

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=ee78e23aa25b5d8cb3d7c99466e8b5a98e6c3167
Camera: Fix memory leak in snapshot

Since thumbnail buffers are locked in createSnapshotMemory(), no need to
do this in getBuffersAndStartpreview() again.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=6bc23a2d64a3f32f861fc4f9f440dff276eee3e4
Camera: Send Jpeg callback with correct data size

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=7cb37b8dc25851b90404cd0a99c2dd1e7d19e8bb
Camera : Fix issue in streaming textures

Set encoding pending flag to true , so that encoding starts
only when requested by upper layers.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=d802749d955a12d06b5851fcf230e35ac0cfa0a3
Camera: Remove the unused fds

1.Jpegfd was being open for all targets and closed only for 8660,
as a result a pipe creation failed after 1000 back to back snapshots
As we now use ashmem for 8660 as well, jpegfd is redundant.
So, removing the redundant parts of the code.

This is partial port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=d802749d955a12d06b5851fcf230e35ac0cfa0a3
Camera: Fix for genlock errors.

When genlock fails, the runpreviewthread function returns without
signalling the threads waiting on preview thread exit and
hence the frame thread also does not exit due to which the
camera hangs and is not able to recover. Removing the return to avoid this.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=4fc16d7ef578702aaac54cb9606297f3ba01289e
msm: native: fix memory leak during snapshot

The JPEG buffers were being allocated from the MM ION heap during
snapshot. However, the Jpeg buffer fd wasn't being closed because
of which there was a memory leak. This bug crept in because of a
recent change that removed use of PMEM for JPEG memory allocation.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=4ca6b47299da802a2975884559da4c8fed5ed76c
Do not release the jpeg buffer twice
Camera: Fix for main image corruption

Use proper luma offset while registering the snapshot buffer with
kernel. In the present code luma offset is hard coded to 0 when
registering , this holds good only when the image height is a
multiple of 16.But, for the cases where the image height is not
a multiple of 16 and for the jpeg rotation values of 90 and 180,
the luma offset is calculated differently and it becomes a non
zero value.So, use this calculated luma offset value instead
of hard coded 0 when registering the buffer.

This is port of:
https://www.codeaurora.org/cgit/quic/la/platform/hardware/qcom/camera/commit/?h=kk_2.7_rb1.21&id=4777aa1f7fccfbf70ea5a303efa14e423c9efb40
Restore mDataCallback call from receiveRawSnapshot
Enable debug print to receiveJpegPicture
Store thumbnail handle and pass to encoder