1 /* 2 * image_handler.cpp - image handler implementation 3 * 4 * Copyright (c) 2017 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan (at) intel.com> 19 */ 20 21 #include "image_handler.h" 22 23 namespace XCam { 24 25 ImageHandler::ImageHandler (const char* name) 26 : _name (NULL) 27 { 28 if (name) 29 _name = strndup (name, XCAM_MAX_STR_SIZE); 30 } 31 32 ImageHandler::~ImageHandler() 33 { 34 xcam_mem_clear (_name); 35 } 36 37 bool 38 ImageHandler::set_allocator (const SmartPtr<BufferPool> &allocator) 39 { 40 XCAM_FAIL_RETURN ( 41 ERROR, allocator.ptr (), false, 42 "softhandler(%s) set allocator(is NULL)", XCAM_STR(get_name ())); 43 _allocator = allocator; 44 return true; 45 } 46 47 XCamReturn 48 ImageHandler::finish () 49 { 50 return XCAM_RETURN_NO_ERROR; 51 } 52 53 54 XCamReturn 55 ImageHandler::terminate () 56 { 57 if (_allocator.ptr ()) 58 _allocator->stop (); 59 60 return XCAM_RETURN_NO_ERROR; 61 } 62 63 void 64 ImageHandler::execute_status_check (const SmartPtr<ImageHandler::Parameters> ¶ms, const XCamReturn error) 65 { 66 if (_callback.ptr ()) 67 _callback->execute_status (this, params, error); 68 } 69 70 XCamReturn 71 ImageHandler::reserve_buffers (const VideoBufferInfo &info, uint32_t count) 72 { 73 XCAM_FAIL_RETURN ( 74 ERROR, _allocator.ptr (), XCAM_RETURN_ERROR_PARAM, 75 "softhandler(%s) reserve buffers failed, alloctor was not set", XCAM_STR(get_name ())); 76 77 _allocator->set_video_info (info); 78 79 XCAM_FAIL_RETURN ( 80 ERROR, _allocator->reserve (count), XCAM_RETURN_ERROR_MEM, 81 "softhandler(%s) reserve buffers(%d) failed", XCAM_STR(get_name ()), count); 82 83 return XCAM_RETURN_NO_ERROR; 84 } 85 86 SmartPtr<VideoBuffer> 87 ImageHandler::get_free_buf () 88 { 89 XCAM_FAIL_RETURN ( 90 ERROR, _allocator.ptr (), NULL, 91 "softhandler(%s) get free buffer failed since allocator was not initilized", XCAM_STR(get_name ())); 92 93 return _allocator->get_buffer (_allocator); 94 } 95 96 } 97