-
Notifications
You must be signed in to change notification settings - Fork 10.1k
replay: C3/C3X hardware decoder #35821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
61cae04
to
24f0095
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Did a quick pass and left some comments to start.
Do we really need the rotator? Decoder won't output NV12?
(To clarify, I'd like to merge the rotator support anyway. It's nice to have support for all the HW blocks in openpilot anyway.)
tools/replay/qcom/decoder.h
Outdated
(V4L2_CID_MPEG_MSM_VIDC_BASE + 22) | ||
|
||
|
||
enum v4l2_mpeg_vidc_video_decoder_multi_stream { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is copy/pasted from some kernel header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and a bunch of other stuff in this file
msgq_repo
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
tools/replay/qcom/sde_rotator.h
Outdated
@@ -0,0 +1,37 @@ | |||
#pragma once | |||
|
|||
#include <fcntl.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this file really use all these includes? I imagine half are unused
tools/replay/qcom/sde_rotator.cc
Outdated
#define V4L2_PIX_FMT_NV12_UBWC v4l2_fourcc('Q', '1', '2', '8') | ||
#endif | ||
|
||
static void checked_ioctl(int fd, unsigned long request, void *argp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put this in common/ instead of copy/pasting everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better yet make check
an argument to util::safe_ioctl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if safe_ioctl accepts a message and an error callback? It is used in spi.cc so it would be like this:
auto fail = [serial, this] {cleanup(); throw std::runtime_error("Error connecting to panda with serial: " + serial);};
// SPI settings
util::safe_ioctl(spi_fd, SPI_IOC_WR_MODE, &spi_mode, "failed setting SPI mode", fail);
util::safe_ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed, "failed setting SPI speed", fail);
util::safe_ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word, "failed setting SPI bits per word", fail);
template<typename ErrorCallback>
int safe_ioctl(int fd, unsigned long request, void *argp, const char* error_msg, ErrorCallback error_callback) {
int ret;
do {
ret = ioctl(fd, request, argp);
} while ((ret == -1) && (errno == EINTR));
if (ret == -1 && error_msg) {
LOGE("ioctl failed: %s", error_msg);
error_callback();
}
return ret;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tools/replay/qcom/sde_rotator.cc
Outdated
if (!queued) // nothing in flight | ||
return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use braces even for one liners
tools/replay/qcom/sde_rotator.cc
Outdated
return &cap_buf; | ||
} | ||
|
||
void SdeRotator::convertStride(VisionBuf *rotated_buf, VisionBuf *user_buf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rotate can't handle this?
I am basing this off a working example code https://github.com/jakethesnake420/v4l2-decode. With that said, I don't have a complete understanding of why certain things are done the way they are.
The venus driver throws an error when trying to set the capture buffer type to NV12.
Which tells me that the decoded picture buffer needs to be UBWC. The DPB format seems to get overridden when I set the capture plane format. I have tried a few things to get it working but the only way I could see is to use the rotator. The stuff in decoder.h is copied from kernel headers to work around build issues. I think this can be cleaned up I just have not spent the time yet to solve the issue. The change to msgq_repo is to add a modified version of the VisionBuf::allocate that maps the memory differently. new function allocate_no_cache:
versus original allocate:
Another pain point. I couldn't get the driver to accept a custom fmt_cap.fmt.pix.bytesperline as its calculated by the driver and its based on the resolution and alignment. I tried to format the output to a size that the driver would accept and then scale it up/down but I faced additional issues. I am not an expert on troubleshooting v4l2 or video formats so its difficult for me to tell what is wrong when an image is deformed a certain way. |
06bd2ec
to
66121d1
Compare
@jakethesnake420 can you rebase after the ioctl improvements and do a bit of cleanup? then I can see if I see can simplify this a bit before merging |
trigger-jenkins |
7aad2e2
to
561efd8
Compare
561efd8
to
0d6aa7a
Compare
Rebased, cleaned and further simplified. |
The last major thing to simplify is the visionbuf stuff. Maybe allocate() can be refactored slightly to work instead of adding the new allocate_no_cache function. I originally did it this way to match the example from samsung with little understanding. |
This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity. |
I started working on simplifying this but there's too many things that are a mess:
I can understand if one or two of these are left, but this feels like a PR that just started working. |
Ok I will take another swing at these issues. |
21ddb9d
to
276bc77
Compare
I was able to find solutions.
|
tools/replay/qcom/decoder.cc
Outdated
@@ -259,7 +262,7 @@ bool MsmVidc::setDBP() { | |||
struct v4l2_ext_control control[2] = {0}; | |||
struct v4l2_ext_controls controls = {0}; | |||
control[0].id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE; | |||
control[0].value = 0; // V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_PRIMARY | |||
control[0].value = 1; // V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the key difference to get the decoder to decode directly to linear NV12 (non-UBWC)
Nice, this is a lot simpler but now I'm getting this immediately when running
|
Unfortunately I can't reproduce this. There will likely be information in dmesg. You can change the driver debug verbosity I just did a clean install as a test and it works for me. |
It should be possible to use the ion buffers created by vipc, eliminating the copy buffer and buffer creation code. But it may not be simple. |
Thanks for the PR! |
This reverts commit 1f1efec.
This reverts commit 1f1efec.
Your welcome! |
On the comma device, kill openpilot managed procs in tmux with ctrl+c, then start the ui again with
./selfdrive/ui/ui
.then run:
COMMA_CACHE=/data/cache ./tools/replay/replay --demo --ecam --dcam