1 /*
2 * scaler_service.cpp
3 *
4 * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
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: Cody Xie <cody.xie@rock-chips.com>
19 */
20 #include "scaler_service.h"
21
22 #include "image_processor.h"
23 #include "dma_video_buffer.h"
24
25 using namespace XCam;
26
27 namespace RkCam {
28
29 template <typename To, typename From>
30 To convert(From&);
31
32 template <>
convert(std::shared_ptr<DmaVideoBuffer> & dma)33 img_buffer_t convert(std::shared_ptr<DmaVideoBuffer>& dma) {
34 auto info = dma->get_video_info();
35 img_buffer_t buf = {
36 .vir_addr = nullptr,
37 .phy_addr = nullptr,
38 .fd = -1,
39 .width = (int)info.width,
40 .height = (int)info.height,
41 .wstride = (int)info.aligned_width,
42 .hstride = (int)info.aligned_height,
43 .format = RK_PIX_FMT_NV12,
44 };
45
46 buf.fd = dma->get_fd();
47 buf.format = static_cast<rk_aiq_format_t>(info.format);
48
49 return buf;
50 }
51
ScalerTask(std::unique_ptr<ImageProcessor> proc)52 ScalerTask::ScalerTask(std::unique_ptr<ImageProcessor> proc) : proc_(std::move(proc)) {}
53
operator ()(ServiceParam<scaler_param> & p)54 TaskResult ScalerTask::operator()(ServiceParam<scaler_param>& p) {
55 auto full = p.payload->input_image;
56 auto scales = p.payload->scaled_images;
57 auto last = full;
58 for (auto it = scales.begin(); it != scales.end(); it++) {
59 img_buffer_t src = convert<img_buffer_t>(last);
60 img_buffer_t dst = convert<img_buffer_t>(*it);
61 proc_->resize(src, dst, 0, 0);
62 last = *it;
63 }
64
65 return TaskResult::kSuccess;
66 }
67
68 } // namespace RkCam
69