Skip to content

Commit 8f37d4c

Browse files
author
sliver.chen
committed
[rga]: add rotate mode
add rotate mode for displaying image. Signed-off-by: sliver.chen <[email protected]>
1 parent 93ed55b commit 8f37d4c

File tree

7 files changed

+44
-19
lines changed

7 files changed

+44
-19
lines changed

CMakeLists.txt

100644100755
File mode changed.

README.md

100644100755
File mode changed.

main.cpp

100644100755
File mode changed.

mpp/Codec.cpp

100644100755
+19-11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ int Codec::init(const char *file_input,
8282
mDisPlay = display;
8383
srcW = src_w;
8484
srcH = src_h;
85+
dstW = src_w;
86+
dstH = src_h;
8587

8688
mFin = fopen(file_input, "rb");
8789
if (!mFin) {
@@ -126,14 +128,14 @@ int Codec::init(const char *file_input,
126128
cxx_log("failed to exec mpp_init.\n");
127129
return -7;
128130
}
129-
#if 0
131+
130132
mRGA = new RGA();
131-
ret = mRGA->init(srcW, srcH, dstW, dstH);
133+
ret = mRGA->init(srcW, srcH, srcW, srcH);
132134
if (ret < 0) {
133135
cxx_log("failed to exec mRGA->init %d.\n", ret);
134136
return -8;
135137
}
136-
#endif
138+
137139
mDev = create_sp_dev();
138140
if (!mDev) {
139141
cxx_log("failed to exec create_sp_dev.\n");
@@ -358,14 +360,20 @@ int Codec::decode_one_pkt(char *buf, int size, MppFrame *srcFrm, MppFrame *dstFr
358360
} else {
359361
cxx_log("decode_get_frame ID:%d get srcFrm %d.\n", mID, mFrmCnt++);
360362
if (mDisPlay) {
361-
drm_show_frmae(*srcFrm);
362-
if (mFout) {
363-
/*
364-
* note that write file will leads to IO block
365-
* so if you want to test frame rate,don't wirte
366-
* it.
367-
*/
368-
//dump_mpp_frame_to_file(*srcFrm, mFout);
363+
ret = mRGA->swscale(mpp_buffer_get_fd(mpp_frame_get_buffer(*srcFrm)),
364+
mpp_buffer_get_fd(mpp_frame_get_buffer(*dstFrm)));
365+
if (ret < 0) {
366+
cxx_log("failed to exec mRGA->swscale ret:%d.\n", ret);
367+
} else {
368+
drm_show_frmae(*dstFrm);
369+
if (mFout) {
370+
/*
371+
* note that write file will leads to IO block
372+
* so if you want to test frame rate,don't wirte
373+
* it.
374+
*/
375+
//dump_mpp_frame_to_file(*srcFrm, mFout);
376+
}
369377
}
370378
}
371379
}

mpp/Codec.h

100644100755
File mode changed.

rkrga/RGA.cpp

100644100755
+23-8
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ int RGA::set_dst_fmt() {
7373
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
7474
fmt.fmt.pix.width = RGA_ALIGN(mDstW, 16);
7575
fmt.fmt.pix.height = RGA_ALIGN(mDstH, 16);
76-
#ifdef USE_SDL
77-
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
78-
#else
7976
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV12;
80-
#endif
8177
fmt.fmt.pix.field = V4L2_FIELD_ANY;
8278

8379
ret = ioctl(mFd, VIDIOC_S_FMT, &fmt);
@@ -185,6 +181,20 @@ int RGA::dst_buf_map() {
185181
return 0;
186182
}
187183

184+
int RGA::set_img_rotation(unsigned degree) {
185+
struct v4l2_control ctrl = {0};
186+
int ret = 0;
187+
188+
ctrl.id = V4L2_CID_ROTATE;
189+
ctrl.value = degree;
190+
ret = ioctl(mFd, VIDIOC_S_CTRL, &ctrl);
191+
if (ret != 0) {
192+
rga_log("failed to ioctl VIDIOC_S_CTRL.\n");
193+
return -1;
194+
}
195+
return 0;
196+
}
197+
188198
int RGA::init(int srcW, int srcH, int dstW, int dstH) {
189199
int ret = 0;
190200

@@ -217,23 +227,28 @@ int RGA::init(int srcW, int srcH, int dstW, int dstH) {
217227
return -4;
218228
}
219229

230+
ret = set_img_rotation(90);
231+
if (ret < 0) {
232+
rga_log("failed to exec set_img_rotation %d.\n", ret);
233+
return -5;
234+
}
235+
220236
ret = src_buf_map();
221237
if (ret < 0) {
222238
rga_log("failed to exec src_buf_map %d.\n", ret);
223-
return -5;
239+
return -6;
224240
}
225241

226242
ret = dst_buf_map();
227243
if (ret < 0) {
228244
rga_log("failed to exec dst_buf_map %d.\n", ret);
229-
return -6;
245+
return -7;
230246
}
231247

232-
233248
ret = open_dev_strm();
234249
if (ret < 0) {
235250
rga_log("failed to exec open_dev_strm %d.\n", ret);
236-
return -7;
251+
return -8;
237252
}
238253

239254
return 0;

rkrga/RGA.h

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C" {
1111
#include <fcntl.h>
1212
#include <errno.h>
1313
#include <stdio.h>
14+
#include <stdint.h>
1415
#include <string.h>
1516
#include <sys/ioctl.h>
1617
#include <linux/videodev2.h>
@@ -31,6 +32,7 @@ class RGA {
3132
int open_dev_strm();
3233
int dst_buf_map();
3334
int src_buf_map();
35+
int set_img_rotation(unsigned degree);
3436

3537
int mFd;
3638
int mSrcW;

0 commit comments

Comments
 (0)