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