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