/* * Copyright (c) 2019 Rockchip Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "shared_item_pool.h" namespace RkCam { template SharedItemPool::SharedItemPool(const char* name, uint32_t max_count) : BufferPool() ,_name(name ? name : "default") , _max_count(max_count) { LOG1("ENTER SharedItemPool<%s>:%s", _name, __FUNCTION__); if (_max_count > 0) reserve (_max_count); LOG1("EXIT SharedItemPool<%s>:%s", _name, __FUNCTION__); } template SharedItemPool::~SharedItemPool() { LOG1("ENTER SharedItemPool<%s>:%s", _name, __FUNCTION__); LOG1("EXIT SharedItemPool<%s>:%s", _name, __FUNCTION__); } template int8_t SharedItemPool::init(uint32_t max_count) { if (_max_count > 0) return -1; if (!reserve (max_count)) return -1; _max_count = get_free_buffer_size (); return 0; } template SmartPtr> SharedItemPool::get_item() { #if 0 // dynamic_cast_ptr has performance issue SmartPtr buf = get_buffer(); SmartPtr> proxy = buf.dynamic_cast_ptr>() ; return proxy; #else // get buf directly, save one call of dynamic_cast_ptr SmartPtr> ret_buf; SmartPtr data; { SmartLock lock (_mutex); if (!_started) return NULL; } data = _buf_list.pop (); if (!data.ptr ()) { XCAM_LOG_DEBUG ("BufferPool failed to get buffer"); return NULL; } SmartPtr data_t = data.dynamic_cast_ptr(); ret_buf = new SharedItemProxy (data_t);; ret_buf->set_buf_pool (SmartPtr(this)); return ret_buf; #endif } template SmartPtr SharedItemPool::allocate_data (const VideoBufferInfo &buffer_info) { return new T(); } template SmartPtr SharedItemPool::create_buffer_from_data (SmartPtr &data) { XCAM_ASSERT (data.ptr ()); SmartPtr data_t = data.dynamic_cast_ptr(); return new SharedItemProxy (data_t); } };