summaryrefslogtreecommitdiffstats
path: root/camera/inc
diff options
context:
space:
mode:
authorAndriy Chepurnyy <x0155536@ti.com>2012-08-29 14:37:46 +0300
committerDaniel Levin <dendy@ti.com>2012-11-26 20:17:15 +0200
commit45588315e9b4abc53b7fbf4f5032eed54730e40f (patch)
tree300ee55501640309acc653847e749495ae39bec4 /camera/inc
parent143c25c0f2ec3f84be5fe1c9aa85e0006a19707f (diff)
downloadhardware_ti_omap4-45588315e9b4abc53b7fbf4f5032eed54730e40f.zip
hardware_ti_omap4-45588315e9b4abc53b7fbf4f5032eed54730e40f.tar.gz
hardware_ti_omap4-45588315e9b4abc53b7fbf4f5032eed54730e40f.tar.bz2
CameraHal: Add support of HW MJPEG decoder in CameraHAL
Tis patch adds Ducati decoder support on CameraHAL level. - Added FrameDecoder - that used as base class for hw/sw decoders. - SwFrameDecoder - class that capable for sw MJPEG decoding - OmxFrameDecoder - class that capable for hardware MJPEG/H264 decoding (using Ducati decoder) - FrameDecoder is now used generic interface for decoder in V4l camera adapter - Added ability to change video stream type for V4L camera. Change-Id: Ia632cb0e202752b05a6994acc90c7f10ee851a34 Signed-off-by: Andriy Chepurnyy <x0155536@ti.com>
Diffstat (limited to 'camera/inc')
-rw-r--r--camera/inc/DecoderFactory.h35
-rw-r--r--camera/inc/FrameDecoder.h173
-rw-r--r--camera/inc/OmxFrameDecoder.h199
-rw-r--r--camera/inc/SwFrameDecoder.h47
-rwxr-xr-xcamera/inc/V4LCameraAdapter/V4LCameraAdapter.h33
5 files changed, 479 insertions, 8 deletions
diff --git a/camera/inc/DecoderFactory.h b/camera/inc/DecoderFactory.h
new file mode 100644
index 0000000..d5e566f
--- /dev/null
+++ b/camera/inc/DecoderFactory.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DECODERFACTORY_H_
+#define DECODERFACTORY_H_
+
+#include "FrameDecoder.h"
+
+namespace Ti {
+namespace Camera {
+
+class DecoderFactory {
+ DecoderFactory();
+ ~DecoderFactory();
+public:
+ static FrameDecoder* createDecoderByType(DecoderType type, bool forceSwDecoder = false);
+};
+
+} // namespace Camera
+} // namespace Ti
+
+#endif /* DECODERFACTORY_H_ */
diff --git a/camera/inc/FrameDecoder.h b/camera/inc/FrameDecoder.h
new file mode 100644
index 0000000..fab0544
--- /dev/null
+++ b/camera/inc/FrameDecoder.h
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FRAMEDECODER_H_
+#define FRAMEDECODER_H_
+
+#include <utils/Vector.h>
+#include <utils/StrongPointer.h>
+#include "CameraHal.h"
+
+
+namespace Ti {
+namespace Camera {
+
+enum DecoderType {
+ DecoderType_MJPEG,
+ DecoderType_H264
+};
+
+enum BufferStatus {
+ BufferStatus_Unknown,
+ BufferStatus_InQueued,
+ BufferStatus_InWaitForEmpty,
+ BufferStatus_InDecoded,
+ BufferStatus_OutQueued,
+ BufferStatus_OutWaitForFill,
+ BufferStatus_OutFilled
+};
+
+enum DecoderState {
+ DecoderState_Uninitialized,
+ DecoderState_Initialized,
+ DecoderState_Running,
+ DecoderState_Requested_Stop,
+ DecoderState_Stoppped
+};
+
+class MediaBuffer: public virtual android::RefBase {
+
+public:
+ MediaBuffer()
+ : bufferId(-1), buffer(0), filledLen(0), size(0),
+ mOffset(0), mTimestamp(0), mStatus(BufferStatus_Unknown) {
+ }
+
+ MediaBuffer(int id, void* buffer, size_t buffSize = 0)
+ : bufferId(id), buffer(buffer), filledLen(0), size(buffSize),
+ mOffset(0), mTimestamp(0), mStatus(BufferStatus_Unknown) {
+ }
+
+ virtual ~MediaBuffer() {
+ }
+
+ int bufferId;
+ void* buffer;
+ int filledLen;
+ size_t size;
+
+ nsecs_t getTimestamp() const {
+ return mTimestamp;
+ }
+ void setTimestamp(nsecs_t ts) {
+ mTimestamp = ts;
+ }
+
+ BufferStatus getStatus() const {
+ return mStatus;
+ }
+
+ void setStatus(BufferStatus status) {
+ mStatus = status;
+ }
+
+ android::Mutex& getLock() const {
+ return mLock;
+ }
+
+ uint32_t getOffset() const {
+ return mOffset;
+ }
+
+ void setOffset(uint32_t offset) {
+ mOffset = offset;
+ }
+
+private:
+ uint32_t mOffset;
+ nsecs_t mTimestamp;
+ BufferStatus mStatus;
+ mutable android::Mutex mLock;
+};
+
+struct DecoderParameters {
+ int width;
+ int height;
+ int inputBufferCount;
+ int outputBufferCount;
+};
+
+class FrameDecoder {
+public:
+ FrameDecoder();
+ virtual ~FrameDecoder();
+ void configure(const DecoderParameters& config);
+ status_t start();
+ void stop();
+ void release();
+ void flush();
+ status_t queueInputBuffer(int id);
+ status_t dequeueInputBuffer(int &id);
+ status_t queueOutputBuffer(int id);
+ status_t dequeueOutputBuffer(int &id);
+
+ void registerOutputBuffers(android::Vector< android::sp<MediaBuffer> > *outBuffers) {
+ android::AutoMutex lock(mLock);
+ mOutQueue.clear();
+ mOutBuffers = outBuffers;
+ }
+
+ void registerInputBuffers(android::Vector< android::sp<MediaBuffer> > *inBuffers) {
+ android::AutoMutex lock(mLock);
+ mInQueue.clear();
+ mInBuffers = inBuffers;
+ }
+
+ virtual bool getPaddedDimensions(size_t &width, size_t &height) {
+ return false;
+ }
+
+ void setHal(CameraHal* hal) {
+ mCameraHal = hal;
+ }
+
+protected:
+ virtual void doConfigure(const DecoderParameters& config) = 0;
+ virtual void doProcessInputBuffer() = 0;
+ virtual status_t doStart() = 0;
+ virtual void doStop() = 0;
+ virtual void doFlush() = 0;
+ virtual void doRelease() = 0;
+
+ DecoderParameters mParams;
+
+ android::Vector<int> mInQueue;
+ android::Vector<int> mOutQueue;
+
+ android::Vector< android::sp<MediaBuffer> >* mInBuffers;
+ android::Vector< android::sp<MediaBuffer> >* mOutBuffers;
+
+ CameraHal* mCameraHal;
+
+private:
+ DecoderState mState;
+ android::Mutex mLock;
+};
+
+} // namespace Camera
+} // namespace Ti
+
+#endif /* FRAMEDECODER_H_ */
diff --git a/camera/inc/OmxFrameDecoder.h b/camera/inc/OmxFrameDecoder.h
new file mode 100644
index 0000000..bcd9378
--- /dev/null
+++ b/camera/inc/OmxFrameDecoder.h
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OMXFRAMEDECODER_H_
+#define OMXFRAMEDECODER_H_
+
+
+#include <utils/threads.h>
+#include <utils/List.h>
+#include "FrameDecoder.h"
+#include "OMX_Types.h"
+#include "OMX_Core.h"
+#include "OMX_Component.h"
+#include "Decoder_libjpeg.h"
+
+namespace Ti {
+namespace Camera {
+
+enum OmxDecoderState {
+ OmxDecoderState_Unloaded = 0,
+ OmxDecoderState_Loaded,
+ OmxDecoderState_Idle,
+ OmxDecoderState_Executing,
+ OmxDecoderState_Error,
+ OmxDecoderState_Invalid,
+ OmxDecoderState_Reconfigure,
+ OmxDecoderState_Exit
+};
+
+enum PortType {
+ PortIndexInput = 0,
+ PortIndexOutput = 1
+};
+
+
+struct OmxMessage {
+ enum {
+ EVENT,
+ EMPTY_BUFFER_DONE,
+ FILL_BUFFER_DONE,
+ }type;
+
+ union {
+ // if type == EVENT
+ struct {
+ OMX_PTR appData;
+ OMX_EVENTTYPE event;
+ OMX_U32 data1;
+ OMX_U32 data2;
+ OMX_PTR pEventData;
+ } eventData;
+
+ // if type == (EMPTY_BUFFER_DONE || FILL_BUFFER_DONE)
+ struct {
+ OMX_PTR appData;
+ OMX_BUFFERHEADERTYPE* pBuffHead;
+ } bufferData;
+ } u;
+};
+
+class CallbackDispatcher;
+
+struct CallbackDispatcherThread : public android::Thread {
+ CallbackDispatcherThread(CallbackDispatcher *dispatcher)
+ : mDispatcher(dispatcher) {
+ }
+
+private:
+ CallbackDispatcher *mDispatcher;
+
+ bool threadLoop();
+
+ CallbackDispatcherThread(const CallbackDispatcherThread &);
+ CallbackDispatcherThread &operator=(const CallbackDispatcherThread &);
+};
+
+class CallbackDispatcher
+{
+
+public:
+ CallbackDispatcher();
+ ~CallbackDispatcher();
+
+ void post(const OmxMessage &msg);
+ bool loop();
+
+private:
+ void dispatch(const OmxMessage &msg);
+
+ CallbackDispatcher(const CallbackDispatcher &);
+ CallbackDispatcher &operator=(const CallbackDispatcher &);
+
+ android::Mutex mLock;
+ android::Condition mQueueChanged;
+ android::List<OmxMessage> mQueue;
+ android::sp<CallbackDispatcherThread> mThread;
+ bool mDone;
+};
+
+class OmxFrameDecoder : public FrameDecoder
+{
+
+public:
+ OmxFrameDecoder(DecoderType type = DecoderType_MJPEG);
+ virtual ~OmxFrameDecoder();
+
+ OMX_ERRORTYPE eventHandler(const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2,
+ const OMX_PTR pEventData);
+ OMX_ERRORTYPE fillBufferDoneHandler(OMX_BUFFERHEADERTYPE* pBuffHead);
+ OMX_ERRORTYPE emptyBufferDoneHandler(OMX_BUFFERHEADERTYPE* pBuffHead);
+
+ static OMX_ERRORTYPE eventCallback(const OMX_HANDLETYPE component,
+ const OMX_PTR appData, const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2,
+ const OMX_PTR pEventData);
+ static OMX_ERRORTYPE emptyBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR appData, OMX_BUFFERHEADERTYPE* pBuffHead);
+ static OMX_ERRORTYPE fillBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR appData, OMX_BUFFERHEADERTYPE* pBuffHead);
+
+ virtual bool getPaddedDimensions(size_t &width, size_t &height);
+
+protected:
+ virtual void doConfigure (const DecoderParameters& config);
+ virtual void doProcessInputBuffer();
+ virtual status_t doStart();
+ virtual void doStop();
+ virtual void doFlush();
+ virtual void doRelease();
+
+private:
+ status_t setComponentRole();
+ status_t enableGrallockHandles();
+ status_t allocateBuffersOutput();
+ void freeBuffersOnOutput();
+ void freeBuffersOnInput();
+ status_t doPortReconfigure();
+ void dumpPortSettings(PortType port);
+ status_t getAndConfigureDecoder();
+ status_t configureJpegPorts(int width, int height);
+ status_t switchToIdle();
+ status_t allocateBuffersInput();
+ status_t disablePortSync(int port);
+ status_t enablePortSync(int port);
+ void queueOutputBuffers();
+ status_t setVideoOutputFormat(OMX_U32 width, OMX_U32 height);
+
+
+ status_t omxInit();
+ status_t omxGetHandle(OMX_HANDLETYPE *handle, OMX_PTR pAppData, OMX_CALLBACKTYPE & callbacks);
+ OmxDecoderState getOmxState() { return mCurrentState; }
+ status_t commitState(OmxDecoderState state) { mPreviousState = mCurrentState; mCurrentState = state; return NO_ERROR; }
+ status_t setVideoPortFormatType(
+ OMX_U32 portIndex,
+ OMX_VIDEO_CODINGTYPE compressionFormat,
+ OMX_COLOR_FORMATTYPE colorFormat);
+ status_t omxGetParameter(OMX_INDEXTYPE index, OMX_PTR ptr);
+ status_t omxSetParameter(OMX_INDEXTYPE index, OMX_PTR ptr);
+ status_t omxSendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
+ status_t omxGetConfig(OMX_INDEXTYPE index, OMX_PTR ptr);
+ status_t omxSetConfig(OMX_INDEXTYPE index, OMX_PTR ptr);
+ status_t omxFillThisBuffer(OMX_BUFFERHEADERTYPE *pOutBufHdr);
+ status_t omxEmptyThisBuffer(android::sp<MediaBuffer>& inBuffer, OMX_BUFFERHEADERTYPE *pInBufHdr);
+ void omxDumpPortSettings(OMX_PARAM_PORTDEFINITIONTYPE& def);
+ void omxDumpBufferHeader (OMX_BUFFERHEADERTYPE* bh);
+ status_t omxSwitchToExecutingSync();
+
+ bool mOmxInialized;
+
+ OMX_HANDLETYPE mHandleComp;
+ OmxDecoderState mCurrentState;
+ OmxDecoderState mPreviousState;
+
+ // Condition and Mutex used during OpenMAX state transitions & command completion
+ android::Condition mStateCondition;
+ android::Mutex mHwLock;
+
+ android::Vector<OMX_BUFFERHEADERTYPE*> mOutBufferHeaders;
+ android::Vector<OMX_BUFFERHEADERTYPE*> mInBufferHeaders;
+
+ CallbackDispatcher mDispatcher;
+
+ bool mStopping;
+ DecoderType mDecoderType;
+};
+
+} //namespace Camera
+} //namespace Ti
+#endif /* OMXFRAMEDECODER_H_ */
diff --git a/camera/inc/SwFrameDecoder.h b/camera/inc/SwFrameDecoder.h
new file mode 100644
index 0000000..f123940
--- /dev/null
+++ b/camera/inc/SwFrameDecoder.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SWFRAMEDECODER_H_
+#define SWFRAMEDECODER_H_
+
+#include "FrameDecoder.h"
+#include "Decoder_libjpeg.h"
+
+namespace Ti {
+namespace Camera {
+
+class SwFrameDecoder: public FrameDecoder {
+public:
+ SwFrameDecoder();
+ virtual ~SwFrameDecoder();
+
+protected:
+ virtual void doConfigure(const DecoderParameters& config);
+ virtual void doProcessInputBuffer();
+ virtual status_t doStart() { return NO_ERROR; }
+ virtual void doStop() { }
+ virtual void doFlush() { }
+ virtual void doRelease() { }
+
+private:
+ int mjpegWithHdrSize;
+ Decoder_libjpeg mJpgdecoder;
+ unsigned char* mJpegWithHeaderBuffer;
+};
+
+} // namespace Camera
+} // namespace Ti
+#endif /* SWFRAMEDECODER_H_ */
diff --git a/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h
index d1bc015..2189727 100755
--- a/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h
+++ b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h
@@ -25,12 +25,17 @@
#include "BaseCameraAdapter.h"
#include "DebugUtils.h"
#include "Decoder_libjpeg.h"
+#include "FrameDecoder.h"
+
namespace Ti {
namespace Camera {
-//#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_YUYV
-#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_MJPEG
+#ifndef V4L2_PIX_FMT_H264
+#define V4L2_PIX_FMT_H264 0
+#endif
+
+#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_YUYV
#define DEFAULT_CAPTURE_FORMAT V4L2_PIX_FMT_YUYV
#define NB_BUFFER 10
@@ -102,7 +107,7 @@ public:
public:
- V4LCameraAdapter(size_t sensor_index);
+ V4LCameraAdapter(size_t sensor_index, CameraHal* hal);
~V4LCameraAdapter();
@@ -119,6 +124,8 @@ public:
static status_t getCaps(const int sensorId, CameraProperties::Properties* params, V4L_HANDLETYPE handle);
+ void setupWorkingMode();
+
protected:
//----------Parent class method implementation------------------------------------
@@ -160,8 +167,6 @@ private:
int previewThread();
-public:
-
private:
//capabilities data
static const CapPixelformat mPixelformats [];
@@ -198,6 +203,9 @@ private:
status_t v4lSetFormat(int, int, uint32_t);
status_t restartPreview();
status_t applyFpsValue();
+ status_t returnBufferToV4L(int id);
+ void returnOutputBuffer(int index);
+ bool isNeedToUseDecoder() const;
int mPreviewBufferCount;
int mPreviewBufferCountQueueable;
@@ -230,12 +238,21 @@ private:
int nQueued;
int nDequeued;
+ int mQueuedOutputBuffers;
+
+ FrameDecoder* mDecoder;
+ android::Vector< android::sp<MediaBuffer> > mInBuffers;
+ android::Vector< android::sp<MediaBuffer> > mOutBuffers;
- Decoder_libjpeg jpgdecoder;
- unsigned char *jpeg_with_dht_buffer[NB_BUFFER];
- unsigned int jpeg_with_dht_buffer_size;
+ android::Mutex mV4LLock;
+ int mPixelFormat;
int mFrameRate;
+
+ android::Mutex mStopLock;
+ android::Condition mStopCondition;
+
+ CameraHal* mCameraHal;
};
} // namespace Camera