Wind Yuan | f17e93a | 2015-04-14 18:45:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * x3a_stats_pool.cpp - 3a stats pool |
| 3 | * |
| 4 | * Copyright (c) 2015 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@intel.com> |
| 19 | */ |
| 20 | |
| 21 | #include "x3a_stats_pool.h" |
| 22 | |
| 23 | namespace XCam { |
| 24 | |
| 25 | X3aStatsData::X3aStatsData (XCam3AStats *data) |
| 26 | : _data (data) |
| 27 | { |
| 28 | XCAM_ASSERT (_data); |
| 29 | } |
| 30 | |
| 31 | X3aStatsData::~X3aStatsData () |
| 32 | { |
| 33 | if (_data) |
| 34 | xcam_free (_data); |
| 35 | } |
| 36 | |
| 37 | uint8_t * |
| 38 | X3aStatsData::map () |
| 39 | { |
| 40 | return (uint8_t*)(intptr_t)(_data); |
| 41 | } |
| 42 | |
| 43 | bool |
| 44 | X3aStatsData::unmap () |
| 45 | { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | X3aStats::X3aStats (const SmartPtr<X3aStatsData> &data) |
| 50 | : BufferProxy (SmartPtr<BufferData>(data)) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | |
| 55 | XCam3AStats * |
| 56 | X3aStats::get_stats () |
| 57 | { |
| 58 | SmartPtr<BufferData> data = get_buffer_data (); |
| 59 | SmartPtr<X3aStatsData> stats = data.dynamic_cast_ptr<X3aStatsData> (); |
| 60 | |
| 61 | XCAM_FAIL_RETURN( |
| 62 | WARNING, |
| 63 | stats.ptr(), |
| 64 | NULL, |
| 65 | "X3aStats get_stats failed with NULL"); |
| 66 | return stats->get_stats (); |
| 67 | } |
| 68 | |
| 69 | X3aStatsPool::X3aStatsPool () |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | X3aStatsPool::set_stats_info (const XCam3AStatsInfo &info) |
| 75 | { |
| 76 | _stats_info = info; |
| 77 | } |
| 78 | |
| 79 | bool |
| 80 | X3aStatsPool::fixate_video_info (VideoBufferInfo &info) |
| 81 | { |
| 82 | const uint32_t grid = 16; |
| 83 | |
| 84 | _stats_info.aligned_width = (info.width + grid - 1) / grid; |
| 85 | _stats_info.aligned_height = (info.height + grid - 1) / grid; |
| 86 | |
| 87 | _stats_info.width = info.width / grid; |
| 88 | _stats_info.height = info.height / grid; |
| 89 | _stats_info.grid_pixel_size = grid; |
| 90 | _stats_info.bit_depth = 8; |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | SmartPtr<BufferData> |
| 95 | X3aStatsPool::allocate_data (const VideoBufferInfo &buffer_info) |
| 96 | { |
Wind Yuan | 2f9c6c5 | 2015-04-30 16:53:28 +0800 | [diff] [blame] | 97 | XCAM_UNUSED (buffer_info); |
| 98 | |
Wind Yuan | f17e93a | 2015-04-14 18:45:38 +0800 | [diff] [blame] | 99 | XCam3AStats *stats = NULL; |
| 100 | stats = |
| 101 | (XCam3AStats *) xcam_malloc0 ( |
| 102 | sizeof (XCam3AStats) + |
| 103 | sizeof (XCamGridStat) * _stats_info.aligned_width * _stats_info.aligned_height); |
| 104 | stats->info = _stats_info; |
| 105 | return new X3aStatsData (stats); |
| 106 | } |
| 107 | |
| 108 | SmartPtr<BufferProxy> |
| 109 | X3aStatsPool::create_buffer_from_data (SmartPtr<BufferData> &data) |
| 110 | { |
| 111 | SmartPtr<X3aStatsData> stats_data = data.dynamic_cast_ptr<X3aStatsData> (); |
| 112 | XCAM_ASSERT (stats_data.ptr ()); |
| 113 | |
| 114 | return new X3aStats (stats_data); |
| 115 | } |
| 116 | |
| 117 | }; |