refactor: VideoReader and videoin post-audio review cleanup

VideoReader:
- Remove unused #include <iostream>
- Remove dead AudioInfo::samples and ::channel_stride fields
- Rename have_video → has_video (consistent with has_audio)
- Rename get_next_frame → read_next (returns audio too, not just frames)
- Fix outdated comment on read_next
- Remove trailing blank line in allocate_audio_conversion_buffers

videoin:
- Remove redundant FFmpeg includes (VideoReader.hpp provides them)
- Fix bug: mxlFlowWriterGetMaxWriteLengthSamples called with invalid
  audio_writer when mxlCreateFlowWriter fails — moved inside else branch
- Rename call site: get_next_frame → read_next
- Rename have_video → has_video at call sites
- Use = nullptr for audio_writer (consistent with video_writer)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
JohannesItten
2026-07-05 12:44:35 +03:00
parent 166efc3c59
commit 0298cf9b48
2 changed files with 18 additions and 33 deletions
+11 -17
View File
@@ -16,8 +16,6 @@ extern "C" {
#include "Signal.hpp"
#include "V210.hpp"
#include <iostream>
namespace dmf {
class VideoReader {
@@ -31,10 +29,8 @@ public:
};
struct AudioInfo {
int sample_rate = 0;
int channels = 0;
int samples = 0;
int channel_stride = 0; // floats between channel planes (NDI planar layout)
int sample_rate = 0;
int channels = 0;
};
enum class FrameKind { None, Video, Audio };
@@ -42,14 +38,14 @@ public:
VideoInfo video_info{};
AudioInfo audio_info{};
bool has_audio = false;
bool have_video = false;
bool has_video = false;
explicit VideoReader(const std::string& filename) {
if (!open_file(filename))
return;
if (!have_video && !has_audio) return;
if (!has_video && !has_audio) return;
get_source_info();
if (have_video) allocate_video_conversion_buffers();
if (has_video) allocate_video_conversion_buffers();
if (has_audio) allocate_audio_conversion_buffers();
}
@@ -65,12 +61,11 @@ public:
av_packet_free(&packet);
}
// Returns true when a frame was decoded and written into video_buf.
// Returns false when g_running goes false.
FrameKind get_next_frame(uint8_t* video_buf, uint32_t mxl_stride, uint8_t* audio_buf, int max_audio_samples, int& out_samples_written) {
// Returns Video or Audio when a frame/packet was decoded, None when g_running goes false.
FrameKind read_next(uint8_t* video_buf, uint32_t mxl_stride, uint8_t* audio_buf, int max_audio_samples, int& out_samples_written) {
while (dmf::g_running.load(std::memory_order_relaxed)) {
// Drain any frames buffered in the decoder first
if (have_video && avcodec_receive_frame(video_codec_context, video_frame) == 0) {
if (has_video && avcodec_receive_frame(video_codec_context, video_frame) == 0) {
if (!video_buf) {
av_frame_unref(video_frame);
continue; // nowhere to write — discard frame
@@ -138,7 +133,7 @@ public:
if (av_read_frame(format_context, packet) < 0) {
// EOF — loop back to start
avformat_seek_file(format_context, -1, 0, 0, 0, AVSEEK_FLAG_BACKWARD);
if (have_video) avcodec_flush_buffers(video_codec_context);
if (has_video) avcodec_flush_buffers(video_codec_context);
if (has_audio) avcodec_flush_buffers(audio_codec_context);
swr_close(swr_audio_ctx);
swr_init(swr_audio_ctx);
@@ -184,7 +179,7 @@ private:
const AVMediaType type = format_context->streams[i]->codecpar->codec_type;
if (type == AVMEDIA_TYPE_VIDEO && video_stream_index == -1) {
video_stream_index = static_cast<int>(i);
have_video = true;
has_video = true;
} else if (type == AVMEDIA_TYPE_AUDIO && audio_stream_index == -1) {
audio_stream_index = static_cast<int>(i);
has_audio = true;
@@ -225,7 +220,7 @@ private:
video_info.fps_den = fps.den;
video_info.pix_fmt = video_codec_context->pix_fmt;
} else {
have_video = false;
has_video = false;
}
// audio part
@@ -279,7 +274,6 @@ private:
if (swr_init(swr_audio_ctx) < 0) {
throw std::runtime_error("Failed to create SwrContext");
}
}
};