Skip to content

Commit 9ae39f8

Browse files
committed
encoder: output: Fix bug where network output was not routed through libav on Pi 5
If the --codec libav option is not set, and a network stream output is specified, the NetOutput class will be initialised together with libav and fail to work on a Pi 5. Fix this by ensuring if we are going to use libav, do not initialise the NetOutput class, and allow libav to handle the network output. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 0bcbaaf commit 9ae39f8

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

apps/rpicam_raw.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ int main(int argc, char *argv[])
7979
VideoOptions *options = app.GetOptions();
8080
if (options->Parse(argc, argv))
8181
{
82+
// Disable any codec (h.264/libav) based operations.
83+
options->codec = "yuv420";
8284
options->denoise = "cdn_off";
8385
options->nopreview = true;
8486
if (options->verbose >= 2)

encoder/encoder.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "libav_encoder.hpp"
2222
#endif
2323

24-
Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
24+
bool bcm2835_encoder_available()
2525
{
2626
const char hw_codec[] = "/dev/video11";
2727
struct v4l2_capability caps;
@@ -32,8 +32,15 @@ Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
3232
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
3333
close(fd);
3434
if (!ret && !strncmp((char *)caps.card, "bcm2835-codec-encode", sizeof(caps.card)))
35-
return new H264Encoder(options, info);
35+
return true;
3636
}
37+
return false;
38+
}
39+
40+
static Encoder *h264_codec_select(VideoOptions *options, const StreamInfo &info)
41+
{
42+
if (bcm2835_encoder_available())
43+
return new H264Encoder(options, info);
3744

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

4754
#if LIBAV_PRESENT
48-
Encoder *libav_codec_select(VideoOptions *options, const StreamInfo &info)
55+
static Encoder *libav_codec_select(VideoOptions *options, const StreamInfo &info)
4956
{
5057
if (options->libav_video_codec == "h264_v4l2m2m")
5158
{
52-
const char hw_codec[] = "/dev/video11";
53-
struct v4l2_capability caps;
54-
memset(&caps, 0, sizeof(caps));
55-
int fd = open(hw_codec, O_RDWR, 0);
56-
if (fd)
57-
{
58-
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
59-
close(fd);
60-
if (!ret && !strncmp((char *)caps.card, "bcm2835-codec-encode", sizeof(caps.card)))
59+
if (bcm2835_encoder_available())
6160
return new LibAvEncoder(options, info);
62-
}
63-
6461
// No h264_v4l2m2m libav codec available, use libx264 if nothing else is provided.
6562
options->libav_video_codec = "libx264";
6663
}
67-
6864
return new LibAvEncoder(options, info);
6965
}
7066
#endif

output/output.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "net_output.hpp"
1414
#include "output.hpp"
1515

16+
extern bool bcm2835_encoder_available();
17+
1618
Output::Output(VideoOptions const *options)
1719
: options_(options), fp_timestamps_(nullptr), state_(WAITING_KEYFRAME), time_offset_(0), last_timestamp_(0),
1820
buf_metadata_(std::cout.rdbuf()), of_metadata_()
@@ -101,7 +103,7 @@ void Output::outputBuffer(void *mem, size_t size, int64_t timestamp_us, uint32_t
101103

102104
Output *Output::Create(VideoOptions const *options)
103105
{
104-
if (options->codec == "libav")
106+
if (options->codec == "libav" || (options->codec == "h264" && !bcm2835_encoder_available()))
105107
return new Output(options);
106108

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

0 commit comments

Comments
 (0)