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