Skip to content

Commit 8a5a545

Browse files
Cleanup hw_frame and fix case when packet is re-used and hence out_frame is populated.
1 parent 703c70f commit 8a5a545

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/zm_videostore.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,6 @@ int VideoStore::writePacket(const std::shared_ptr<ZMPacket> zm_pkt) {
11071107

11081108
int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> zm_packet) {
11091109
av_packet_guard pkt_guard;
1110-
#if HAVE_LIBAVUTIL_HWCONTEXT_H
1111-
av_frame_ptr hw_frame;
1112-
#endif
11131110

11141111
frame_count += 1;
11151112

@@ -1119,7 +1116,9 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> zm_packet)
11191116

11201117
av_frame_ptr frame(av_frame_alloc());
11211118

1122-
if (!zm_packet->out_frame) {
1119+
if (zm_packet->out_frame) {
1120+
av_frame_ref(frame.get(), zm_packet->out_frame.get());
1121+
} else {
11231122
Debug(3, "Have no out frame. codec is %s sw_pf %d %s hw_pf %d %s %dx%d",
11241123
chosen_codec_data->codec_name,
11251124
chosen_codec_data->sw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->sw_pix_fmt),
@@ -1179,7 +1178,7 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> zm_packet)
11791178
#if HAVE_LIBAVUTIL_HWCONTEXT_H
11801179
if (video_out_ctx->hw_frames_ctx) {
11811180
int ret;
1182-
hw_frame = av_frame_ptr{av_frame_alloc()};
1181+
av_frame_ptr hw_frame = av_frame_ptr{av_frame_alloc()};
11831182
if (!hw_frame) {
11841183
return AVERROR(ENOMEM);
11851184
}
@@ -1267,11 +1266,14 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> zm_packet)
12671266
// Some hwaccel codecs may get full if we only receive one pkt for one frame
12681267

12691268
do {
1269+
zm_dump_frame(frame.get(), "sending frame");
12701270
int ret = avcodec_send_frame(video_out_ctx, frame.get());
12711271
if (ret < 0) {
12721272
if (AVERROR(EAGAIN) != ret) {
12731273
Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str());
12741274
return ret;
1275+
} else {
1276+
Debug(3, "Got EAGAIN");
12751277
}
12761278
} else {
12771279
break;

0 commit comments

Comments
 (0)