QCamera3Stream.cpp revision 33cb7276f6c4d2eda72253d11cd9242e1f82bf7d
1/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved.
2*
3* Redistribution and use in source and binary forms, with or without
4* modification, are permitted provided that the following conditions are
5* met:
6*     * Redistributions of source code must retain the above copyright
7*       notice, this list of conditions and the following disclaimer.
8*     * Redistributions in binary form must reproduce the above
9*       copyright notice, this list of conditions and the following
10*       disclaimer in the documentation and/or other materials provided
11*       with the distribution.
12*     * Neither the name of The Linux Foundation nor the names of its
13*       contributors may be used to endorse or promote products derived
14*       from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29
30#define LOG_TAG "QCamera3Stream"
31
32#include <utils/Log.h>
33#include <utils/Errors.h>
34#include "QCamera3HWI.h"
35#include "QCamera3Stream.h"
36#include "QCamera3Channel.h"
37
38using namespace android;
39
40namespace qcamera {
41
42/*===========================================================================
43 * FUNCTION   : get_bufs
44 *
45 * DESCRIPTION: static function entry to allocate stream buffers
46 *
47 * PARAMETERS :
48 *   @offset     : offset info of stream buffers
49 *   @num_bufs   : number of buffers allocated
50 *   @initial_reg_flag: flag to indicate if buffer needs to be registered
51 *                      at kernel initially
52 *   @bufs       : output of allocated buffers
53 *   @ops_tbl    : ptr to buf mapping/unmapping ops
54 *   @user_data  : user data ptr of ops_tbl
55 *
56 * RETURN     : int32_t type of status
57 *              NO_ERROR  -- success
58 *              none-zero failure code
59 *==========================================================================*/
60int32_t QCamera3Stream::get_bufs(
61                     cam_frame_len_offset_t *offset,
62                     uint8_t *num_bufs,
63                     uint8_t **initial_reg_flag,
64                     mm_camera_buf_def_t **bufs,
65                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
66                     void *user_data)
67{
68    QCamera3Stream *stream = reinterpret_cast<QCamera3Stream *>(user_data);
69    if (!stream) {
70        ALOGE("getBufs invalid stream pointer");
71        return NO_MEMORY;
72    }
73    return stream->getBufs(offset, num_bufs, initial_reg_flag, bufs, ops_tbl);
74}
75
76/*===========================================================================
77 * FUNCTION   : put_bufs
78 *
79 * DESCRIPTION: static function entry to deallocate stream buffers
80 *
81 * PARAMETERS :
82 *   @ops_tbl    : ptr to buf mapping/unmapping ops
83 *   @user_data  : user data ptr of ops_tbl
84 *
85 * RETURN     : int32_t type of status
86 *              NO_ERROR  -- success
87 *              none-zero failure code
88 *==========================================================================*/
89int32_t QCamera3Stream::put_bufs(
90                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
91                     void *user_data)
92{
93    QCamera3Stream *stream = reinterpret_cast<QCamera3Stream *>(user_data);
94    if (!stream) {
95        ALOGE("putBufs invalid stream pointer");
96        return NO_MEMORY;
97    }
98    return stream->putBufs(ops_tbl);
99}
100
101/*===========================================================================
102 * FUNCTION   : invalidate_buf
103 *
104 * DESCRIPTION: static function entry to invalidate a specific stream buffer
105 *
106 * PARAMETERS :
107 *   @index      : index of the stream buffer to invalidate
108 *   @user_data  : user data ptr of ops_tbl
109 *
110 * RETURN     : int32_t type of status
111 *              NO_ERROR  -- success
112 *              none-zero failure code
113 *==========================================================================*/
114int32_t QCamera3Stream::invalidate_buf(int index, void *user_data)
115{
116    QCamera3Stream *stream = reinterpret_cast<QCamera3Stream *>(user_data);
117    if (!stream) {
118        ALOGE("invalid stream pointer");
119        return NO_MEMORY;
120    }
121    return stream->invalidateBuf(index);
122}
123
124/*===========================================================================
125 * FUNCTION   : clean_invalidate_buf
126 *
127 * DESCRIPTION: static function entry to clean and invalidate a specific stream buffer
128 *
129 * PARAMETERS :
130 *   @index      : index of the stream buffer to invalidate
131 *   @user_data  : user data ptr of ops_tbl
132 *
133 * RETURN     : int32_t type of status
134 *              NO_ERROR  -- success
135 *              none-zero failure code
136 *==========================================================================*/
137int32_t QCamera3Stream::clean_invalidate_buf(int index, void *user_data)
138{
139    QCamera3Stream *stream = reinterpret_cast<QCamera3Stream *>(user_data);
140    if (!stream) {
141        ALOGE("invalid stream pointer");
142        return NO_MEMORY;
143    }
144    return stream->cleanInvalidateBuf(index);
145}
146
147/*===========================================================================
148 * FUNCTION   : QCamera3Stream
149 *
150 * DESCRIPTION: constructor of QCamera3Stream
151 *
152 * PARAMETERS :
153 *   @allocator  : memory allocator obj
154 *   @camHandle  : camera handle
155 *   @chId       : channel handle
156 *   @camOps     : ptr to camera ops table
157 *   @paddingInfo: ptr to padding info
158 *
159 * RETURN     : None
160 *==========================================================================*/
161QCamera3Stream::QCamera3Stream(uint32_t camHandle,
162                             uint32_t chId,
163                             mm_camera_ops_t *camOps,
164                             cam_padding_info_t *paddingInfo,
165                             QCamera3Channel *channel) :
166        mCamHandle(camHandle),
167        mChannelHandle(chId),
168        mHandle(0),
169        mCamOps(camOps),
170        mStreamInfo(NULL),
171        mNumBufs(0),
172        mDataCB(NULL),
173        mStreamInfoBuf(NULL),
174        mStreamBufs(NULL),
175        mBufDefs(NULL),
176        mChannel(channel)
177{
178    mMemVtbl.user_data = this;
179    mMemVtbl.get_bufs = get_bufs;
180    mMemVtbl.put_bufs = put_bufs;
181    mMemVtbl.invalidate_buf = invalidate_buf;
182    mMemVtbl.clean_invalidate_buf = clean_invalidate_buf;
183    memset(&mFrameLenOffset, 0, sizeof(mFrameLenOffset));
184    memcpy(&mPaddingInfo, paddingInfo, sizeof(cam_padding_info_t));
185}
186
187/*===========================================================================
188 * FUNCTION   : ~QCamera3Stream
189 *
190 * DESCRIPTION: deconstructor of QCamera3Stream
191 *
192 * PARAMETERS : None
193 *
194 * RETURN     : None
195 *==========================================================================*/
196QCamera3Stream::~QCamera3Stream()
197{
198    if (mStreamInfoBuf != NULL) {
199        int rc = mCamOps->unmap_stream_buf(mCamHandle,
200                    mChannelHandle, mHandle, CAM_MAPPING_BUF_TYPE_STREAM_INFO, 0, -1);
201        if (rc < 0) {
202            ALOGE("Failed to map stream info buffer");
203        }
204        mStreamInfoBuf->deallocate();
205        delete mStreamInfoBuf;
206        mStreamInfoBuf = NULL;
207    }
208
209    // delete stream
210    if (mHandle > 0) {
211        mCamOps->delete_stream(mCamHandle, mChannelHandle, mHandle);
212        mHandle = 0;
213    }
214}
215
216/*===========================================================================
217 * FUNCTION   : init
218 *
219 * DESCRIPTION: initialize stream obj
220 *
221 * PARAMETERS :
222 *   @streamInfoBuf: ptr to buf that contains stream info
223 *   @stream_cb    : stream data notify callback. Can be NULL if not needed
224 *   @userdata     : user data ptr
225 *
226 * RETURN     : int32_t type of status
227 *              NO_ERROR  -- success
228 *              none-zero failure code
229 *==========================================================================*/
230int32_t QCamera3Stream::init(cam_stream_type_t streamType,
231                            cam_format_t streamFormat,
232                            cam_dimension_t streamDim,
233                            uint8_t minNumBuffers,
234                            stream_cb_routine stream_cb,
235                            void *userdata)
236{
237    int32_t rc = OK;
238    mm_camera_stream_config_t stream_config;
239
240    mHandle = mCamOps->add_stream(mCamHandle, mChannelHandle);
241    if (!mHandle) {
242        ALOGE("add_stream failed");
243        rc = UNKNOWN_ERROR;
244        goto done;
245    }
246
247    // allocate and map stream info memory
248    mStreamInfoBuf = new QCamera3HeapMemory();
249    if (mStreamInfoBuf == NULL) {
250        ALOGE("%s: no memory for stream info buf obj", __func__);
251        rc = -ENOMEM;
252        goto err1;
253    }
254    rc = mStreamInfoBuf->allocate(1, sizeof(cam_stream_info_t), false);
255    if (rc < 0) {
256        ALOGE("%s: no memory for stream info", __func__);
257        rc = -ENOMEM;
258        goto err2;
259    }
260
261    mStreamInfo = reinterpret_cast<cam_stream_info_t *>(mStreamInfoBuf->getPtr(0));
262    memset(mStreamInfo, 0, sizeof(cam_stream_info_t));
263    mStreamInfo->stream_type = streamType;
264    mStreamInfo->fmt = streamFormat;
265    mStreamInfo->dim = streamDim;
266    mStreamInfo->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
267
268    mNumBufs = minNumBuffers;
269
270    rc = mCamOps->map_stream_buf(mCamHandle,
271                mChannelHandle, mHandle, CAM_MAPPING_BUF_TYPE_STREAM_INFO,
272                0, -1, mStreamInfoBuf->getFd(0), mStreamInfoBuf->getSize(0));
273    if (rc < 0) {
274        ALOGE("Failed to map stream info buffer");
275        goto err3;
276    }
277
278    // Configure the stream
279    stream_config.stream_info = mStreamInfo;
280    stream_config.mem_vtbl = mMemVtbl;
281    stream_config.stream_cb = dataNotifyCB;
282    stream_config.padding_info = mPaddingInfo;
283    stream_config.userdata = this;
284    rc = mCamOps->config_stream(mCamHandle,
285                mChannelHandle, mHandle, &stream_config);
286    if (rc < 0) {
287        ALOGE("Failed to config stream, rc = %d", rc);
288        goto err4;
289    }
290
291    mDataCB = stream_cb;
292    mUserData = userdata;
293    return 0;
294
295err4:
296    mCamOps->unmap_stream_buf(mCamHandle,
297                mChannelHandle, mHandle, CAM_MAPPING_BUF_TYPE_STREAM_INFO, 0, -1);
298err3:
299    mStreamInfoBuf->deallocate();
300err2:
301    delete mStreamInfoBuf;
302    mStreamInfoBuf = NULL;
303    mStreamInfo = NULL;
304err1:
305    mCamOps->delete_stream(mCamHandle, mChannelHandle, mHandle);
306    mHandle = 0;
307    mNumBufs = 0;
308done:
309    return rc;
310}
311
312/*===========================================================================
313 * FUNCTION   : start
314 *
315 * DESCRIPTION: start stream. Will start main stream thread to handle stream
316 *              related ops.
317 *
318 * PARAMETERS : none
319 *
320 * RETURN     : int32_t type of status
321 *              NO_ERROR  -- success
322 *              none-zero failure code
323 *==========================================================================*/
324int32_t QCamera3Stream::start()
325{
326    int32_t rc = 0;
327    rc = mProcTh.launch(dataProcRoutine, this);
328    return rc;
329}
330
331/*===========================================================================
332 * FUNCTION   : stop
333 *
334 * DESCRIPTION: stop stream. Will stop main stream thread
335 *
336 * PARAMETERS : none
337 *
338 * RETURN     : int32_t type of status
339 *              NO_ERROR  -- success
340 *              none-zero failure code
341 *==========================================================================*/
342int32_t QCamera3Stream::stop()
343{
344    int32_t rc = 0;
345    rc = mProcTh.exit();
346    return rc;
347}
348
349/*===========================================================================
350 * FUNCTION   : processDataNotify
351 *
352 * DESCRIPTION: process stream data notify
353 *
354 * PARAMETERS :
355 *   @frame   : stream frame received
356 *
357 * RETURN     : int32_t type of status
358 *              NO_ERROR  -- success
359 *              none-zero failure code
360 *==========================================================================*/
361int32_t QCamera3Stream::processDataNotify(mm_camera_super_buf_t *frame)
362{
363    ALOGI("%s:\n", __func__);
364    mDataQ.enqueue((void *)frame);
365    return mProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
366}
367
368/*===========================================================================
369 * FUNCTION   : dataNotifyCB
370 *
371 * DESCRIPTION: callback for data notify. This function is registered with
372 *              mm-camera-interface to handle data notify
373 *
374 * PARAMETERS :
375 *   @recvd_frame   : stream frame received
376 *   userdata       : user data ptr
377 *
378 * RETURN     : none
379 *==========================================================================*/
380void QCamera3Stream::dataNotifyCB(mm_camera_super_buf_t *recvd_frame,
381                                 void *userdata)
382{
383    ALOGI("%s:\n", __func__);
384    QCamera3Stream* stream = (QCamera3Stream *)userdata;
385    if (stream == NULL ||
386        recvd_frame == NULL ||
387        recvd_frame->bufs[0] == NULL ||
388        recvd_frame->bufs[0]->stream_id != stream->getMyHandle()) {
389        ALOGE("%s: Not a valid stream to handle buf", __func__);
390        return;
391    }
392
393    mm_camera_super_buf_t *frame =
394        (mm_camera_super_buf_t *)malloc(sizeof(mm_camera_super_buf_t));
395    if (frame == NULL) {
396        ALOGE("%s: No mem for mm_camera_buf_def_t", __func__);
397        stream->bufDone(recvd_frame->bufs[0]->buf_idx);
398        return;
399    }
400    *frame = *recvd_frame;
401    stream->processDataNotify(frame);
402    return;
403}
404
405/*===========================================================================
406 * FUNCTION   : dataProcRoutine
407 *
408 * DESCRIPTION: function to process data in the main stream thread
409 *
410 * PARAMETERS :
411 *   @data    : user data ptr
412 *
413 * RETURN     : none
414 *==========================================================================*/
415void *QCamera3Stream::dataProcRoutine(void *data)
416{
417    int running = 1;
418    int ret;
419    QCamera3Stream *pme = (QCamera3Stream *)data;
420    QCameraCmdThread *cmdThread = &pme->mProcTh;
421
422    ALOGI("%s: E", __func__);
423    do {
424        do {
425            ret = cam_sem_wait(&cmdThread->cmd_sem);
426            if (ret != 0 && errno != EINVAL) {
427                ALOGE("%s: cam_sem_wait error (%s)",
428                      __func__, strerror(errno));
429                return NULL;
430            }
431        } while (ret != 0);
432
433        // we got notified about new cmd avail in cmd queue
434        camera_cmd_type_t cmd = cmdThread->getCmd();
435        switch (cmd) {
436        case CAMERA_CMD_TYPE_DO_NEXT_JOB:
437            {
438                ALOGD("%s: Do next job", __func__);
439                mm_camera_super_buf_t *frame =
440                    (mm_camera_super_buf_t *)pme->mDataQ.dequeue();
441                if (NULL != frame) {
442                    if (pme->mDataCB != NULL) {
443                        pme->mDataCB(frame, pme, pme->mUserData);
444                    } else {
445                        // no data cb routine, return buf here
446                        pme->bufDone(frame->bufs[0]->buf_idx);
447                        free(frame);
448                    }
449                }
450            }
451            break;
452        case CAMERA_CMD_TYPE_EXIT:
453            ALOGD("%s: Exit", __func__);
454            /* flush data buf queue */
455            pme->mDataQ.flush();
456            running = 0;
457            break;
458        default:
459            break;
460        }
461    } while (running);
462    ALOGD("%s: X", __func__);
463    return NULL;
464}
465
466/*===========================================================================
467 * FUNCTION   : bufDone
468 *
469 * DESCRIPTION: return stream buffer to kernel
470 *
471 * PARAMETERS :
472 *   @index   : index of buffer to be returned
473 *
474 * RETURN     : int32_t type of status
475 *              NO_ERROR  -- success
476 *              none-zero failure code
477 *==========================================================================*/
478int32_t QCamera3Stream::bufDone(int index)
479{
480    int32_t rc = NO_ERROR;
481
482    if (index >= mNumBufs || mBufDefs == NULL)
483        return BAD_INDEX;
484
485    rc = mCamOps->qbuf(mCamHandle, mChannelHandle, &mBufDefs[index]);
486    if (rc < 0)
487        return FAILED_TRANSACTION;
488
489    return rc;
490}
491
492/*===========================================================================
493 * FUNCTION   : getBufs
494 *
495 * DESCRIPTION: allocate stream buffers
496 *
497 * PARAMETERS :
498 *   @offset     : offset info of stream buffers
499 *   @num_bufs   : number of buffers allocated
500 *   @initial_reg_flag: flag to indicate if buffer needs to be registered
501 *                      at kernel initially
502 *   @bufs       : output of allocated buffers
503 *   @ops_tbl    : ptr to buf mapping/unmapping ops
504 *
505 * RETURN     : int32_t type of status
506 *              NO_ERROR  -- success
507 *              none-zero failure code
508 *==========================================================================*/
509int32_t QCamera3Stream::getBufs(cam_frame_len_offset_t *offset,
510                     uint8_t *num_bufs,
511                     uint8_t **initial_reg_flag,
512                     mm_camera_buf_def_t **bufs,
513                     mm_camera_map_unmap_ops_tbl_t *ops_tbl)
514{
515    int rc = NO_ERROR;
516    uint8_t *regFlags;
517
518    if (!ops_tbl) {
519        ALOGE("%s: ops_tbl is NULL", __func__);
520        return INVALID_OPERATION;
521    }
522
523    mFrameLenOffset = *offset;
524
525    mStreamBufs = mChannel->getStreamBufs(mFrameLenOffset.frame_len);
526    if (!mStreamBufs) {
527        ALOGE("%s: Failed to allocate stream buffers", __func__);
528        return NO_MEMORY;
529    }
530
531    for (int i = 0; i < mNumBufs; i++) {
532        rc = ops_tbl->map_ops(i, -1, mStreamBufs->getFd(i),
533                mStreamBufs->getSize(i), ops_tbl->userdata);
534        if (rc < 0) {
535            ALOGE("%s: map_stream_buf failed: %d", __func__, rc);
536            for (int j = 0; j < i; j++) {
537                ops_tbl->unmap_ops(j, -1, ops_tbl->userdata);
538            }
539            return INVALID_OPERATION;
540        }
541    }
542
543    //regFlags array is allocated by us, but consumed and freed by mm-camera-interface
544    regFlags = (uint8_t *)malloc(sizeof(uint8_t) * mNumBufs);
545    if (!regFlags) {
546        ALOGE("%s: Out of memory", __func__);
547        for (int i = 0; i < mNumBufs; i++) {
548            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
549        }
550        return NO_MEMORY;
551    }
552
553    mBufDefs = (mm_camera_buf_def_t *)malloc(mNumBufs * sizeof(mm_camera_buf_def_t));
554    if (mBufDefs == NULL) {
555        ALOGE("%s: getRegFlags failed %d", __func__, rc);
556        for (int i = 0; i < mNumBufs; i++) {
557            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
558        }
559        free(regFlags);
560        regFlags = NULL;
561        return INVALID_OPERATION;
562    }
563    for (int i = 0; i < mNumBufs; i++) {
564        mStreamBufs->getBufDef(mFrameLenOffset, mBufDefs[i], i);
565    }
566
567    rc = mStreamBufs->getRegFlags(regFlags);
568    if (rc < 0) {
569        ALOGE("%s: getRegFlags failed %d", __func__, rc);
570        for (int i = 0; i < mNumBufs; i++) {
571            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
572        }
573        free(mBufDefs);
574        mBufDefs = NULL;
575        free(regFlags);
576        regFlags = NULL;
577        return INVALID_OPERATION;
578    }
579
580    *num_bufs = mNumBufs;
581    *initial_reg_flag = regFlags;
582    *bufs = mBufDefs;
583    return NO_ERROR;
584}
585
586/*===========================================================================
587 * FUNCTION   : putBufs
588 *
589 * DESCRIPTION: deallocate stream buffers
590 *
591 * PARAMETERS :
592 *   @ops_tbl    : ptr to buf mapping/unmapping ops
593 *
594 * RETURN     : int32_t type of status
595 *              NO_ERROR  -- success
596 *              none-zero failure code
597 *==========================================================================*/
598int32_t QCamera3Stream::putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl)
599{
600    int rc = NO_ERROR;
601    for (int i = 0; i < mNumBufs; i++) {
602        rc = ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
603        if (rc < 0) {
604            ALOGE("%s: map_stream_buf failed: %d", __func__, rc);
605        }
606    }
607    mBufDefs = NULL; // mBufDefs just keep a ptr to the buffer
608                     // mm-camera-interface own the buffer, so no need to free
609    memset(&mFrameLenOffset, 0, sizeof(mFrameLenOffset));
610    mChannel->putStreamBufs();
611
612    return rc;
613}
614
615/*===========================================================================
616 * FUNCTION   : invalidateBuf
617 *
618 * DESCRIPTION: invalidate a specific stream buffer
619 *
620 * PARAMETERS :
621 *   @index   : index of the buffer to invalidate
622 *
623 * RETURN     : int32_t type of status
624 *              NO_ERROR  -- success
625 *              none-zero failure code
626 *==========================================================================*/
627int32_t QCamera3Stream::invalidateBuf(int index)
628{
629    return mStreamBufs->invalidateCache(index);
630}
631
632/*===========================================================================
633 * FUNCTION   : cleanInvalidateBuf
634 *
635 * DESCRIPTION: clean and invalidate a specific stream buffer
636 *
637 * PARAMETERS :
638 *   @index   : index of the buffer to invalidate
639 *
640 * RETURN     : int32_t type of status
641 *              NO_ERROR  -- success
642 *              none-zero failure code
643 *==========================================================================*/
644int32_t QCamera3Stream::cleanInvalidateBuf(int index)
645{
646    return mStreamBufs->cleanInvalidateCache(index);
647}
648
649/*===========================================================================
650 * FUNCTION   : isTypeOf
651 *
652 * DESCRIPTION: helper function to determine if the stream is of the queried type
653 *
654 * PARAMETERS :
655 *   @type    : stream type as of queried
656 *
657 * RETURN     : true/false
658 *==========================================================================*/
659bool QCamera3Stream::isTypeOf(cam_stream_type_t type)
660{
661    if (mStreamInfo != NULL && (mStreamInfo->stream_type == type)) {
662        return true;
663    } else {
664        return false;
665    }
666}
667
668/*===========================================================================
669 * FUNCTION   : getFrameOffset
670 *
671 * DESCRIPTION: query stream buffer frame offset info
672 *
673 * PARAMETERS :
674 *   @offset  : reference to struct to store the queried frame offset info
675 *
676 * RETURN     : int32_t type of status
677 *              NO_ERROR  -- success
678 *              none-zero failure code
679 *==========================================================================*/
680int32_t QCamera3Stream::getFrameOffset(cam_frame_len_offset_t &offset)
681{
682    offset = mFrameLenOffset;
683    return 0;
684}
685
686/*===========================================================================
687 * FUNCTION   : getFrameDimension
688 *
689 * DESCRIPTION: query stream frame dimension info
690 *
691 * PARAMETERS :
692 *   @dim     : reference to struct to store the queried frame dimension
693 *
694 * RETURN     : int32_t type of status
695 *              NO_ERROR  -- success
696 *              none-zero failure code
697 *==========================================================================*/
698int32_t QCamera3Stream::getFrameDimension(cam_dimension_t &dim)
699{
700    if (mStreamInfo != NULL) {
701        dim = mStreamInfo->dim;
702        return 0;
703    }
704    return -1;
705}
706
707/*===========================================================================
708 * FUNCTION   : getFormat
709 *
710 * DESCRIPTION: query stream format
711 *
712 * PARAMETERS :
713 *   @fmt     : reference to stream format
714 *
715 * RETURN     : int32_t type of status
716 *              NO_ERROR  -- success
717 *              none-zero failure code
718 *==========================================================================*/
719int32_t QCamera3Stream::getFormat(cam_format_t &fmt)
720{
721    if (mStreamInfo != NULL) {
722        fmt = mStreamInfo->fmt;
723        return 0;
724    }
725    return -1;
726}
727
728/*===========================================================================
729 * FUNCTION   : getMyServerID
730 *
731 * DESCRIPTION: query server stream ID
732 *
733 * PARAMETERS : None
734 *
735 * RETURN     : stream ID from server
736 *==========================================================================*/
737uint32_t QCamera3Stream::getMyServerID() {
738    if (mStreamInfo != NULL) {
739        return mStreamInfo->stream_svr_id;
740    } else {
741        return 0;
742    }
743}
744
745/*===========================================================================
746 * FUNCTION   : mapBuf
747 *
748 * DESCRIPTION: map stream related buffer to backend server
749 *
750 * PARAMETERS :
751 *   @buf_type : mapping type of buffer
752 *   @buf_idx  : index of buffer
753 *   @plane_idx: plane index
754 *   @fd       : fd of the buffer
755 *   @size     : lenght of the buffer
756 *
757 * RETURN     : int32_t type of status
758 *              NO_ERROR  -- success
759 *              none-zero failure code
760 *==========================================================================*/
761int32_t QCamera3Stream::mapBuf(uint8_t buf_type,
762                              uint32_t buf_idx,
763                              int32_t plane_idx,
764                              int fd,
765                              uint32_t size)
766{
767    return mCamOps->map_stream_buf(mCamHandle, mChannelHandle,
768                                   mHandle, buf_type,
769                                   buf_idx, plane_idx,
770                                   fd, size);
771
772}
773
774/*===========================================================================
775 * FUNCTION   : unmapBuf
776 *
777 * DESCRIPTION: unmap stream related buffer to backend server
778 *
779 * PARAMETERS :
780 *   @buf_type : mapping type of buffer
781 *   @buf_idx  : index of buffer
782 *   @plane_idx: plane index
783 *
784 * RETURN     : int32_t type of status
785 *              NO_ERROR  -- success
786 *              none-zero failure code
787 *==========================================================================*/
788int32_t QCamera3Stream::unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx)
789{
790    return mCamOps->unmap_stream_buf(mCamHandle, mChannelHandle,
791                                     mHandle, buf_type,
792                                     buf_idx, plane_idx);
793
794}
795
796/*===========================================================================
797 * FUNCTION   : setParameter
798 *
799 * DESCRIPTION: set stream based parameters
800 *
801 * PARAMETERS :
802 *   @param   : ptr to parameters to be set
803 *
804 * RETURN     : int32_t type of status
805 *              NO_ERROR  -- success
806 *              none-zero failure code
807 *==========================================================================*/
808int32_t QCamera3Stream::setParameter(cam_stream_parm_buffer_t &param)
809{
810    int32_t rc = NO_ERROR;
811    mStreamInfo->parm_buf = param;
812    rc = mCamOps->set_stream_parms(mCamHandle,
813                                   mChannelHandle,
814                                   mHandle,
815                                   &mStreamInfo->parm_buf);
816    if (rc == NO_ERROR) {
817        param = mStreamInfo->parm_buf;
818    }
819    return rc;
820}
821
822}; // namespace qcamera
823