mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-04 14:08:37 +00:00
cellRec: fix width of encoder frames
Turns out the pitch was accidentally used as width, leading to an out of bounds read/write. I kept the pitch in the struct for completeness' sake. It may be needed later, if only for error checks.
This commit is contained in:
parent
f40a6d496a
commit
39bbf17caf
12 changed files with 24 additions and 22 deletions
|
|
@ -15,7 +15,7 @@ namespace utils
|
|||
image_sink() = default;
|
||||
|
||||
virtual void stop(bool flush = true) = 0;
|
||||
virtual void add_frame(std::vector<u8>& frame, const u32 width, const u32 height, s32 pixel_format, usz timestamp_ms) = 0;
|
||||
virtual void add_frame(std::vector<u8>& frame, u32 pitch, u32 width, u32 height, s32 pixel_format, usz timestamp_ms) = 0;
|
||||
|
||||
s64 get_pts(usz timestamp_ms) const
|
||||
{
|
||||
|
|
@ -32,12 +32,13 @@ namespace utils
|
|||
struct encoder_frame
|
||||
{
|
||||
encoder_frame() = default;
|
||||
encoder_frame(usz timestamp_ms, u32 width, u32 height, s32 av_pixel_format, std::vector<u8>&& data)
|
||||
: timestamp_ms(timestamp_ms), width(width), height(height), av_pixel_format(av_pixel_format), data(std::move(data))
|
||||
encoder_frame(usz timestamp_ms, u32 pitch, u32 width, u32 height, s32 av_pixel_format, std::vector<u8>&& data)
|
||||
: timestamp_ms(timestamp_ms), pitch(pitch), width(width), height(height), av_pixel_format(av_pixel_format), data(std::move(data))
|
||||
{}
|
||||
|
||||
s64 pts = -1; // Optional
|
||||
usz timestamp_ms = 0;
|
||||
u32 pitch = 0;
|
||||
u32 width = 0;
|
||||
u32 height = 0;
|
||||
s32 av_pixel_format = 0; // NOTE: Make sure this is a valid AVPixelFormat
|
||||
|
|
|
|||
|
|
@ -604,14 +604,14 @@ namespace utils
|
|||
m_audio_codec_id = codec_id;
|
||||
}
|
||||
|
||||
void video_encoder::add_frame(std::vector<u8>& frame, const u32 width, const u32 height, s32 pixel_format, usz timestamp_ms)
|
||||
void video_encoder::add_frame(std::vector<u8>& frame, u32 pitch, u32 width, u32 height, s32 pixel_format, usz timestamp_ms)
|
||||
{
|
||||
// Do not allow new frames while flushing
|
||||
if (m_flush)
|
||||
return;
|
||||
|
||||
std::lock_guard lock(m_mtx);
|
||||
m_frames_to_encode.emplace_back(timestamp_ms, width, height, pixel_format, std::move(frame));
|
||||
m_frames_to_encode.emplace_back(timestamp_ms, pitch, width, height, pixel_format, std::move(frame));
|
||||
}
|
||||
|
||||
void video_encoder::pause(bool flush)
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace utils
|
|||
void set_sample_rate(u32 sample_rate);
|
||||
void set_audio_bitrate(u32 bitrate);
|
||||
void set_audio_codec(s32 codec_id);
|
||||
void add_frame(std::vector<u8>& frame, const u32 width, const u32 height, s32 pixel_format, usz timestamp_ms) override;
|
||||
void add_frame(std::vector<u8>& frame, u32 pitch, u32 width, u32 height, s32 pixel_format, usz timestamp_ms) override;
|
||||
void pause(bool flush = true);
|
||||
void stop(bool flush = true) override;
|
||||
void encode();
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace utils
|
|||
return pts > m_last_pts_incoming;
|
||||
}
|
||||
|
||||
void video_provider::present_frame(std::vector<u8>& data, const u32 width, const u32 height, bool is_bgra)
|
||||
void video_provider::present_frame(std::vector<u8>& data, u32 pitch, u32 width, u32 height, bool is_bgra)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
|
|
@ -132,6 +132,6 @@ namespace utils
|
|||
m_last_pts_incoming = pts;
|
||||
|
||||
m_current_encoder_frame++;
|
||||
m_image_sink->add_frame(data, width, height, is_bgra ? AVPixelFormat::AV_PIX_FMT_BGRA : AVPixelFormat::AV_PIX_FMT_RGBA, timestamp_ms);
|
||||
m_image_sink->add_frame(data, pitch, width, height, is_bgra ? AVPixelFormat::AV_PIX_FMT_BGRA : AVPixelFormat::AV_PIX_FMT_RGBA, timestamp_ms);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace utils
|
|||
bool set_image_sink(std::shared_ptr<image_sink> sink, recording_mode type);
|
||||
void set_pause_time(usz pause_time_ms);
|
||||
bool can_consume_frame();
|
||||
void present_frame(std::vector<u8>& data, const u32 width, const u32 height, bool is_bgra);
|
||||
void present_frame(std::vector<u8>& data, u32 pitch, u32 width, u32 height, bool is_bgra);
|
||||
|
||||
private:
|
||||
recording_mode m_type = recording_mode::stopped;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue