QCamera3Stream.cpp revision f2fc1625456303cb52ec068d25308229e4322d4c
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 =
262        reinterpret_cast<cam_stream_info_t *>(mStreamInfoBuf->getPtr(0));
263    memset(mStreamInfo, 0, sizeof(cam_stream_info_t));
264    mStreamInfo->stream_type = streamType;
265    mStreamInfo->fmt = streamFormat;
266    mStreamInfo->dim = streamDim;
267    mStreamInfo->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
268
269    mNumBufs = minNumBuffers;
270
271    rc = mCamOps->map_stream_buf(mCamHandle,
272            mChannelHandle, mHandle, CAM_MAPPING_BUF_TYPE_STREAM_INFO,
273            0, -1, mStreamInfoBuf->getFd(0), mStreamInfoBuf->getSize(0));
274    if (rc < 0) {
275        ALOGE("Failed to map stream info buffer");
276        goto err3;
277    }
278
279    // Configure the stream
280    stream_config.stream_info = mStreamInfo;
281    stream_config.mem_vtbl = mMemVtbl;
282    stream_config.padding_info = mPaddingInfo;
283    stream_config.userdata = this;
284
285    switch(streamType) {
286        case CAM_STREAM_TYPE_SNAPSHOT:
287            stream_config.stream_cb = NULL;
288            ALOGE("%s: disabling stream_cb for snapshot", __func__);
289            break;
290        default:
291            stream_config.stream_cb = dataNotifyCB;
292            break;
293    }
294
295
296    rc = mCamOps->config_stream(mCamHandle,
297            mChannelHandle, mHandle, &stream_config);
298    if (rc < 0) {
299        ALOGE("Failed to config stream, rc = %d", rc);
300        goto err4;
301    }
302
303    mDataCB = stream_cb;
304    mUserData = userdata;
305    return 0;
306
307err4:
308    mCamOps->unmap_stream_buf(mCamHandle,
309            mChannelHandle, mHandle, CAM_MAPPING_BUF_TYPE_STREAM_INFO, 0, -1);
310err3:
311    mStreamInfoBuf->deallocate();
312err2:
313    delete mStreamInfoBuf;
314    mStreamInfoBuf = NULL;
315    mStreamInfo = NULL;
316err1:
317    mCamOps->delete_stream(mCamHandle, mChannelHandle, mHandle);
318    mHandle = 0;
319    mNumBufs = 0;
320done:
321    return rc;
322}
323
324/*===========================================================================
325 * FUNCTION   : start
326 *
327 * DESCRIPTION: start stream. Will start main stream thread to handle stream
328 *              related ops.
329 *
330 * PARAMETERS : none
331 *
332 * RETURN     : int32_t type of status
333 *              NO_ERROR  -- success
334 *              none-zero failure code
335 *==========================================================================*/
336int32_t QCamera3Stream::start()
337{
338    int32_t rc = 0;
339    rc = mProcTh.launch(dataProcRoutine, this);
340    return rc;
341}
342
343/*===========================================================================
344 * FUNCTION   : stop
345 *
346 * DESCRIPTION: stop stream. Will stop main stream thread
347 *
348 * PARAMETERS : none
349 *
350 * RETURN     : int32_t type of status
351 *              NO_ERROR  -- success
352 *              none-zero failure code
353 *==========================================================================*/
354int32_t QCamera3Stream::stop()
355{
356    int32_t rc = 0;
357    rc = mProcTh.exit();
358    return rc;
359}
360
361/*===========================================================================
362 * FUNCTION   : processDataNotify
363 *
364 * DESCRIPTION: process stream data notify
365 *
366 * PARAMETERS :
367 *   @frame   : stream frame received
368 *
369 * RETURN     : int32_t type of status
370 *              NO_ERROR  -- success
371 *              none-zero failure code
372 *==========================================================================*/
373int32_t QCamera3Stream::processDataNotify(mm_camera_super_buf_t *frame)
374{
375    ALOGI("%s:\n", __func__);
376    mDataQ.enqueue((void *)frame);
377    return mProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
378}
379
380/*===========================================================================
381 * FUNCTION   : dataNotifyCB
382 *
383 * DESCRIPTION: callback for data notify. This function is registered with
384 *              mm-camera-interface to handle data notify
385 *
386 * PARAMETERS :
387 *   @recvd_frame   : stream frame received
388 *   userdata       : user data ptr
389 *
390 * RETURN     : none
391 *==========================================================================*/
392void QCamera3Stream::dataNotifyCB(mm_camera_super_buf_t *recvd_frame,
393                                 void *userdata)
394{
395    ALOGI("%s:\n", __func__);
396    QCamera3Stream* stream = (QCamera3Stream *)userdata;
397    if (stream == NULL ||
398        recvd_frame == NULL ||
399        recvd_frame->bufs[0] == NULL ||
400        recvd_frame->bufs[0]->stream_id != stream->getMyHandle()) {
401        ALOGE("%s: Not a valid stream to handle buf", __func__);
402        return;
403    }
404
405    mm_camera_super_buf_t *frame =
406        (mm_camera_super_buf_t *)malloc(sizeof(mm_camera_super_buf_t));
407    if (frame == NULL) {
408        ALOGE("%s: No mem for mm_camera_buf_def_t", __func__);
409        stream->bufDone(recvd_frame->bufs[0]->buf_idx);
410        return;
411    }
412    *frame = *recvd_frame;
413    stream->processDataNotify(frame);
414    return;
415}
416
417/*===========================================================================
418 * FUNCTION   : dataProcRoutine
419 *
420 * DESCRIPTION: function to process data in the main stream thread
421 *
422 * PARAMETERS :
423 *   @data    : user data ptr
424 *
425 * RETURN     : none
426 *==========================================================================*/
427void *QCamera3Stream::dataProcRoutine(void *data)
428{
429    int running = 1;
430    int ret;
431    QCamera3Stream *pme = (QCamera3Stream *)data;
432    QCameraCmdThread *cmdThread = &pme->mProcTh;
433
434    ALOGI("%s: E", __func__);
435    do {
436        do {
437            ret = cam_sem_wait(&cmdThread->cmd_sem);
438            if (ret != 0 && errno != EINVAL) {
439                ALOGE("%s: cam_sem_wait error (%s)",
440                      __func__, strerror(errno));
441                return NULL;
442            }
443        } while (ret != 0);
444
445        // we got notified about new cmd avail in cmd queue
446        camera_cmd_type_t cmd = cmdThread->getCmd();
447        switch (cmd) {
448        case CAMERA_CMD_TYPE_DO_NEXT_JOB:
449            {
450                ALOGD("%s: Do next job", __func__);
451                mm_camera_super_buf_t *frame =
452                    (mm_camera_super_buf_t *)pme->mDataQ.dequeue();
453                if (NULL != frame) {
454                    if (pme->mDataCB != NULL) {
455                        pme->mDataCB(frame, pme, pme->mUserData);
456                    } else {
457                        // no data cb routine, return buf here
458                        pme->bufDone(frame->bufs[0]->buf_idx);
459                        free(frame);
460                    }
461                }
462            }
463            break;
464        case CAMERA_CMD_TYPE_EXIT:
465            ALOGD("%s: Exit", __func__);
466            /* flush data buf queue */
467            pme->mDataQ.flush();
468            running = 0;
469            break;
470        default:
471            break;
472        }
473    } while (running);
474    ALOGD("%s: X", __func__);
475    return NULL;
476}
477
478/*===========================================================================
479 * FUNCTION   : bufDone
480 *
481 * DESCRIPTION: return stream buffer to kernel
482 *
483 * PARAMETERS :
484 *   @index   : index of buffer to be returned
485 *
486 * RETURN     : int32_t type of status
487 *              NO_ERROR  -- success
488 *              none-zero failure code
489 *==========================================================================*/
490int32_t QCamera3Stream::bufDone(int index)
491{
492    int32_t rc = NO_ERROR;
493
494    if (index >= mNumBufs || mBufDefs == NULL)
495        return BAD_INDEX;
496
497    rc = mCamOps->qbuf(mCamHandle, mChannelHandle, &mBufDefs[index]);
498    if (rc < 0)
499        return FAILED_TRANSACTION;
500
501    return rc;
502}
503
504/*===========================================================================
505 * FUNCTION   : getBufs
506 *
507 * DESCRIPTION: allocate stream buffers
508 *
509 * PARAMETERS :
510 *   @offset     : offset info of stream buffers
511 *   @num_bufs   : number of buffers allocated
512 *   @initial_reg_flag: flag to indicate if buffer needs to be registered
513 *                      at kernel initially
514 *   @bufs       : output of allocated buffers
515 *   @ops_tbl    : ptr to buf mapping/unmapping ops
516 *
517 * RETURN     : int32_t type of status
518 *              NO_ERROR  -- success
519 *              none-zero failure code
520 *==========================================================================*/
521int32_t QCamera3Stream::getBufs(cam_frame_len_offset_t *offset,
522                     uint8_t *num_bufs,
523                     uint8_t **initial_reg_flag,
524                     mm_camera_buf_def_t **bufs,
525                     mm_camera_map_unmap_ops_tbl_t *ops_tbl)
526{
527    int rc = NO_ERROR;
528    uint8_t *regFlags;
529
530    if (!ops_tbl) {
531        ALOGE("%s: ops_tbl is NULL", __func__);
532        return INVALID_OPERATION;
533    }
534
535    mFrameLenOffset = *offset;
536
537    mStreamBufs = mChannel->getStreamBufs(mFrameLenOffset.frame_len);
538    if (!mStreamBufs) {
539        ALOGE("%s: Failed to allocate stream buffers", __func__);
540        return NO_MEMORY;
541    }
542
543    for (int i = 0; i < mNumBufs; i++) {
544        rc = ops_tbl->map_ops(i, -1, mStreamBufs->getFd(i),
545                mStreamBufs->getSize(i), ops_tbl->userdata);
546        if (rc < 0) {
547            ALOGE("%s: map_stream_buf failed: %d", __func__, rc);
548            for (int j = 0; j < i; j++) {
549                ops_tbl->unmap_ops(j, -1, ops_tbl->userdata);
550            }
551            return INVALID_OPERATION;
552        }
553    }
554
555    //regFlags array is allocated by us, but consumed and freed by mm-camera-interface
556    regFlags = (uint8_t *)malloc(sizeof(uint8_t) * mNumBufs);
557    if (!regFlags) {
558        ALOGE("%s: Out of memory", __func__);
559        for (int i = 0; i < mNumBufs; i++) {
560            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
561        }
562        return NO_MEMORY;
563    }
564
565    mBufDefs = (mm_camera_buf_def_t *)malloc(mNumBufs * sizeof(mm_camera_buf_def_t));
566    if (mBufDefs == NULL) {
567        ALOGE("%s: getRegFlags failed %d", __func__, rc);
568        for (int i = 0; i < mNumBufs; i++) {
569            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
570        }
571        free(regFlags);
572        regFlags = NULL;
573        return INVALID_OPERATION;
574    }
575    for (int i = 0; i < mNumBufs; i++) {
576        mStreamBufs->getBufDef(mFrameLenOffset, mBufDefs[i], i);
577    }
578
579    rc = mStreamBufs->getRegFlags(regFlags);
580    if (rc < 0) {
581        ALOGE("%s: getRegFlags failed %d", __func__, rc);
582        for (int i = 0; i < mNumBufs; i++) {
583            ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
584        }
585        free(mBufDefs);
586        mBufDefs = NULL;
587        free(regFlags);
588        regFlags = NULL;
589        return INVALID_OPERATION;
590    }
591
592    *num_bufs = mNumBufs;
593    *initial_reg_flag = regFlags;
594    *bufs = mBufDefs;
595    return NO_ERROR;
596}
597
598/*===========================================================================
599 * FUNCTION   : putBufs
600 *
601 * DESCRIPTION: deallocate stream buffers
602 *
603 * PARAMETERS :
604 *   @ops_tbl    : ptr to buf mapping/unmapping ops
605 *
606 * RETURN     : int32_t type of status
607 *              NO_ERROR  -- success
608 *              none-zero failure code
609 *==========================================================================*/
610int32_t QCamera3Stream::putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl)
611{
612    int rc = NO_ERROR;
613    for (int i = 0; i < mNumBufs; i++) {
614        rc = ops_tbl->unmap_ops(i, -1, ops_tbl->userdata);
615        if (rc < 0) {
616            ALOGE("%s: map_stream_buf failed: %d", __func__, rc);
617        }
618    }
619    mBufDefs = NULL; // mBufDefs just keep a ptr to the buffer
620                     // mm-camera-interface own the buffer, so no need to free
621    memset(&mFrameLenOffset, 0, sizeof(mFrameLenOffset));
622    mChannel->putStreamBufs();
623
624    return rc;
625}
626
627/*===========================================================================
628 * FUNCTION   : invalidateBuf
629 *
630 * DESCRIPTION: invalidate a specific stream buffer
631 *
632 * PARAMETERS :
633 *   @index   : index of the buffer to invalidate
634 *
635 * RETURN     : int32_t type of status
636 *              NO_ERROR  -- success
637 *              none-zero failure code
638 *==========================================================================*/
639int32_t QCamera3Stream::invalidateBuf(int index)
640{
641    return mStreamBufs->invalidateCache(index);
642}
643
644/*===========================================================================
645 * FUNCTION   : cleanInvalidateBuf
646 *
647 * DESCRIPTION: clean and invalidate a specific stream buffer
648 *
649 * PARAMETERS :
650 *   @index   : index of the buffer to invalidate
651 *
652 * RETURN     : int32_t type of status
653 *              NO_ERROR  -- success
654 *              none-zero failure code
655 *==========================================================================*/
656int32_t QCamera3Stream::cleanInvalidateBuf(int index)
657{
658    return mStreamBufs->cleanInvalidateCache(index);
659}
660
661/*===========================================================================
662 * FUNCTION   : isTypeOf
663 *
664 * DESCRIPTION: helper function to determine if the stream is of the queried type
665 *
666 * PARAMETERS :
667 *   @type    : stream type as of queried
668 *
669 * RETURN     : true/false
670 *==========================================================================*/
671bool QCamera3Stream::isTypeOf(cam_stream_type_t type)
672{
673    if (mStreamInfo != NULL && (mStreamInfo->stream_type == type)) {
674        return true;
675    } else {
676        return false;
677    }
678}
679
680/*===========================================================================
681 * FUNCTION   : getFrameOffset
682 *
683 * DESCRIPTION: query stream buffer frame offset info
684 *
685 * PARAMETERS :
686 *   @offset  : reference to struct to store the queried frame offset info
687 *
688 * RETURN     : int32_t type of status
689 *              NO_ERROR  -- success
690 *              none-zero failure code
691 *==========================================================================*/
692int32_t QCamera3Stream::getFrameOffset(cam_frame_len_offset_t &offset)
693{
694    offset = mFrameLenOffset;
695    return 0;
696}
697
698/*===========================================================================
699 * FUNCTION   : getFrameDimension
700 *
701 * DESCRIPTION: query stream frame dimension info
702 *
703 * PARAMETERS :
704 *   @dim     : reference to struct to store the queried frame dimension
705 *
706 * RETURN     : int32_t type of status
707 *              NO_ERROR  -- success
708 *              none-zero failure code
709 *==========================================================================*/
710int32_t QCamera3Stream::getFrameDimension(cam_dimension_t &dim)
711{
712    if (mStreamInfo != NULL) {
713        dim = mStreamInfo->dim;
714        return 0;
715    }
716    return -1;
717}
718
719/*===========================================================================
720 * FUNCTION   : getFormat
721 *
722 * DESCRIPTION: query stream format
723 *
724 * PARAMETERS :
725 *   @fmt     : reference to stream format
726 *
727 * RETURN     : int32_t type of status
728 *              NO_ERROR  -- success
729 *              none-zero failure code
730 *==========================================================================*/
731int32_t QCamera3Stream::getFormat(cam_format_t &fmt)
732{
733    if (mStreamInfo != NULL) {
734        fmt = mStreamInfo->fmt;
735        return 0;
736    }
737    return -1;
738}
739
740/*===========================================================================
741 * FUNCTION   : getMyServerID
742 *
743 * DESCRIPTION: query server stream ID
744 *
745 * PARAMETERS : None
746 *
747 * RETURN     : stream ID from server
748 *==========================================================================*/
749uint32_t QCamera3Stream::getMyServerID() {
750    if (mStreamInfo != NULL) {
751        return mStreamInfo->stream_svr_id;
752    } else {
753        return 0;
754    }
755}
756
757/*===========================================================================
758 * FUNCTION   : mapBuf
759 *
760 * DESCRIPTION: map stream related buffer to backend server
761 *
762 * PARAMETERS :
763 *   @buf_type : mapping type of buffer
764 *   @buf_idx  : index of buffer
765 *   @plane_idx: plane index
766 *   @fd       : fd of the buffer
767 *   @size     : lenght of the buffer
768 *
769 * RETURN     : int32_t type of status
770 *              NO_ERROR  -- success
771 *              none-zero failure code
772 *==========================================================================*/
773int32_t QCamera3Stream::mapBuf(uint8_t buf_type,
774                              uint32_t buf_idx,
775                              int32_t plane_idx,
776                              int fd,
777                              uint32_t size)
778{
779    return mCamOps->map_stream_buf(mCamHandle, mChannelHandle,
780                                   mHandle, buf_type,
781                                   buf_idx, plane_idx,
782                                   fd, size);
783
784}
785
786/*===========================================================================
787 * FUNCTION   : unmapBuf
788 *
789 * DESCRIPTION: unmap stream related buffer to backend server
790 *
791 * PARAMETERS :
792 *   @buf_type : mapping type of buffer
793 *   @buf_idx  : index of buffer
794 *   @plane_idx: plane index
795 *
796 * RETURN     : int32_t type of status
797 *              NO_ERROR  -- success
798 *              none-zero failure code
799 *==========================================================================*/
800int32_t QCamera3Stream::unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx)
801{
802    return mCamOps->unmap_stream_buf(mCamHandle, mChannelHandle,
803                                     mHandle, buf_type,
804                                     buf_idx, plane_idx);
805
806}
807
808/*===========================================================================
809 * FUNCTION   : setParameter
810 *
811 * DESCRIPTION: set stream based parameters
812 *
813 * PARAMETERS :
814 *   @param   : ptr to parameters to be set
815 *
816 * RETURN     : int32_t type of status
817 *              NO_ERROR  -- success
818 *              none-zero failure code
819 *==========================================================================*/
820int32_t QCamera3Stream::setParameter(cam_stream_parm_buffer_t &param)
821{
822    int32_t rc = NO_ERROR;
823    mStreamInfo->parm_buf = param;
824    rc = mCamOps->set_stream_parms(mCamHandle,
825                                   mChannelHandle,
826                                   mHandle,
827                                   &mStreamInfo->parm_buf);
828    if (rc == NO_ERROR) {
829        param = mStreamInfo->parm_buf;
830    }
831    return rc;
832}
833
834}; // namespace qcamera
835