1 /*
2 * soft_video_buf_allocator.cpp - soft video buffer allocator 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@intel.com>
19 */
20
21 #include "soft_video_buf_allocator.h"
22
23 namespace XCam {
24
25 class VideoMemData
26 : public BufferData
27 {
28 public:
29 explicit VideoMemData (uint32_t size);
30 virtual ~VideoMemData ();
is_valid() const31 bool is_valid () const {
32 return (_mem_ptr ? true : false);
33 }
34
35 //derive from BufferData
36 virtual uint8_t *map ();
37 virtual bool unmap ();
38
39 private:
40 uint8_t *_mem_ptr;
41 uint32_t _mem_size;
42 };
43
VideoMemData(uint32_t size)44 VideoMemData::VideoMemData (uint32_t size)
45 : _mem_ptr (NULL)
46 , _mem_size (0)
47 {
48 XCAM_ASSERT (size > 0);
49 _mem_ptr = xcam_malloc_type_array (uint8_t, size);
50 if (_mem_ptr)
51 _mem_size = size;
52 }
53
~VideoMemData()54 VideoMemData::~VideoMemData ()
55 {
56 xcam_free (_mem_ptr);
57 }
58
59 uint8_t *
map()60 VideoMemData::map ()
61 {
62 XCAM_ASSERT (_mem_ptr);
63 return _mem_ptr;
64 }
65
66 bool
unmap()67 VideoMemData::unmap ()
68 {
69 return true;
70 }
71
SoftVideoBufAllocator()72 SoftVideoBufAllocator::SoftVideoBufAllocator ()
73 {
74 }
75
SoftVideoBufAllocator(const VideoBufferInfo & info)76 SoftVideoBufAllocator::SoftVideoBufAllocator (const VideoBufferInfo &info)
77 {
78 set_video_info (info);
79 }
80
~SoftVideoBufAllocator()81 SoftVideoBufAllocator::~SoftVideoBufAllocator ()
82 {
83 }
84
85 SmartPtr<BufferData>
allocate_data(const VideoBufferInfo & buffer_info)86 SoftVideoBufAllocator::allocate_data (const VideoBufferInfo &buffer_info)
87 {
88 XCAM_FAIL_RETURN (
89 ERROR, buffer_info.size, NULL,
90 "SoftVideoBufAllocator allocate data failed. buf_size is zero");
91
92 SmartPtr<VideoMemData> data = new VideoMemData (buffer_info.size);
93 XCAM_FAIL_RETURN (
94 ERROR, data.ptr () && data->is_valid (), NULL,
95 "SoftVideoBufAllocator allocate data failed. buf_size:%d", buffer_info.size);
96
97 return data;
98 }
99
100 }
101
102