Skip to content
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

encoder: output: Fix bug where network output was not routed through … #636

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/rpicam_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ int main(int argc, char *argv[])
VideoOptions *options = app.GetOptions();
if (options->Parse(argc, argv))
{
// Disable any codec (h.264/libav) based operations.
options->codec = "yuv420";
options->denoise = "cdn_off";
options->nopreview = true;
if (options->verbose >= 2)
Expand Down
26 changes: 11 additions & 15 deletions encoder/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "libav_encoder.hpp"
#endif

Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
bool bcm2835_encoder_available()
{
const char hw_codec[] = "/dev/video11";
struct v4l2_capability caps;
Expand All @@ -32,8 +32,15 @@ Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
close(fd);
if (!ret && !strncmp((char *)caps.card, "bcm2835-codec-encode", sizeof(caps.card)))
return new H264Encoder(options, info);
return true;
}
return false;
}

static Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
{
if (bcm2835_encoder_available())
return new H264Encoder(options, info);

#if LIBAV_PRESENT
// No hardware codec available, use x264 through libav.
Expand All @@ -45,26 +52,15 @@ Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
}

#if LIBAV_PRESENT
Encoder *libav_codec_select(VideoOptions *options, const StreamInfo &info)
static Encoder *libav_codec_select(VideoOptions *options, const StreamInfo &info)
{
if (options->libav_video_codec == "h264_v4l2m2m")
{
const char hw_codec[] = "/dev/video11";
struct v4l2_capability caps;
memset(&caps, 0, sizeof(caps));
int fd = open(hw_codec, O_RDWR, 0);
if (fd)
{
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
close(fd);
if (!ret && !strncmp((char *)caps.card, "bcm2835-codec-encode", sizeof(caps.card)))
if (bcm2835_encoder_available())
return new LibAvEncoder(options, info);
}

// No h264_v4l2m2m libav codec available, use libx264 if nothing else is provided.
options->libav_video_codec = "libx264";
}

return new LibAvEncoder(options, info);
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "net_output.hpp"
#include "output.hpp"

extern bool bcm2835_encoder_available();

Output::Output(VideoOptions const *options)
: options_(options), fp_timestamps_(nullptr), state_(WAITING_KEYFRAME), time_offset_(0), last_timestamp_(0),
buf_metadata_(std::cout.rdbuf()), of_metadata_()
Expand Down Expand Up @@ -101,7 +103,7 @@ void Output::outputBuffer(void *mem, size_t size, int64_t timestamp_us, uint32_t

Output *Output::Create(VideoOptions const *options)
{
if (options->codec == "libav")
if (options->codec == "libav" || (options->codec == "h264" && !bcm2835_encoder_available()))
return new Output(options);

if (strncmp(options->output.c_str(), "udp://", 6) == 0 || strncmp(options->output.c_str(), "tcp://", 6) == 0)
Expand Down
Loading