From 63a7bbb5f232e087c24d0a9cbf0f4fefe542af2d Mon Sep 17 00:00:00 2001 From: hap Date: Fri, 19 Jun 2020 11:54:21 +0200 Subject: recording: fix frame sync regression (nw) --- src/emu/machine.cpp | 2 +- src/emu/recording.cpp | 23 ++++++++++++++++------- src/emu/recording.h | 3 ++- src/lib/util/png.cpp | 6 +++--- src/lib/util/png.h | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 4e471a75007..ac9f324a626 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -276,7 +276,7 @@ void running_machine::start() m_video->begin_recording(filename, movie_recording::format::MNG); filename = options().avi_write(); - if (filename[0] != 0) + if (filename[0] != 0 && !m_video->is_recording()) m_video->begin_recording(filename, movie_recording::format::AVI); // if we're coming in with a savegame request, process it now diff --git a/src/emu/recording.cpp b/src/emu/recording.cpp index e7cf3d88678..e4f1861fa9e 100644 --- a/src/emu/recording.cpp +++ b/src/emu/recording.cpp @@ -31,7 +31,7 @@ namespace virtual bool append_single_video_frame(bitmap_rgb32 &bitmap, const rgb_t *palette, int palette_entries) override; private: - avi_file::ptr m_avi_file; // handle to the open movie file + avi_file::ptr m_avi_file; // handle to the open movie file }; @@ -48,8 +48,8 @@ namespace virtual bool append_single_video_frame(bitmap_rgb32 &bitmap, const rgb_t *palette, int palette_entries) override; private: - std::unique_ptr m_mng_file; // handle to the open movie file - std::map m_info_fields; + std::unique_ptr m_mng_file; // handle to the open movie file + std::map m_info_fields; }; }; @@ -64,9 +64,10 @@ namespace movie_recording::movie_recording(screen_device *screen) : m_screen(screen) + , m_frame_period(attotime::zero) + , m_next_frame_time(attotime::zero) , m_frame(0) { - m_frame_period = m_screen ? m_screen->frame_period() : attotime::from_hz(screen_device::DEFAULT_FRAME_RATE); } @@ -174,7 +175,7 @@ bool avi_movie_recording::initialize(running_machine &machine, std::unique_ptrframe_period().as_hz() : screen_device::DEFAULT_FRAME_RATE); info.video_sampletime = 1000; info.video_numsamples = 0; info.video_width = width; @@ -189,6 +190,9 @@ bool avi_movie_recording::initialize(running_machine &machine, std::unique_ptr &&file, bitmap_t &snap_bitmap) { + // compute the frame time (MNG rate is an unsigned integer) + attotime period = screen() ? screen()->frame_period() : attotime::from_hz(screen_device::DEFAULT_FRAME_RATE); + u32 rate = u32(period.as_hz()); + set_frame_period(attotime::from_hz(rate)); + m_mng_file = std::move(file); - png_error pngerr = mng_capture_start(*m_mng_file, snap_bitmap, frame_period().as_hz()); + png_error pngerr = mng_capture_start(*m_mng_file, snap_bitmap, rate); if (pngerr != PNGERR_NONE) osd_printf_error("Error capturing MNG, png_error=%d\n", pngerr); return pngerr == PNGERR_NONE; diff --git a/src/emu/recording.h b/src/emu/recording.h index b805db27757..0a26c5c7db8 100644 --- a/src/emu/recording.h +++ b/src/emu/recording.h @@ -73,10 +73,11 @@ protected: // accessors int current_frame() const { return m_frame; } + void set_frame_period(attotime time) { m_frame_period = time; } private: screen_device * m_screen; // screen associated with this movie (can be nullptr) - attotime m_frame_period; // time of frame period + attotime m_frame_period; // duration of movie frame attotime m_next_frame_time; // time of next frame int m_frame; // current movie frame number }; diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp index 6eb5293da53..6b59436750c 100644 --- a/src/lib/util/png.cpp +++ b/src/lib/util/png.cpp @@ -1246,18 +1246,18 @@ png_error png_write_bitmap(util::core_file &fp, png_info *info, bitmap_t const & ********************************************************************************/ /** - * @fn png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate) + * @fn png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, unsigned rate) * * @brief Mng capture start. * * @param [in,out] fp If non-null, the fp. * @param [in,out] bitmap The bitmap. - * @param rate The rate. + * @param rate The framerate. * * @return A png_error. */ -png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate) +png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, unsigned rate) { uint8_t mhdr[28]; diff --git a/src/lib/util/png.h b/src/lib/util/png.h index ff14ff5f674..5f852fd8c16 100644 --- a/src/lib/util/png.h +++ b/src/lib/util/png.h @@ -103,7 +103,7 @@ png_error png_read_bitmap(util::core_file &fp, bitmap_argb32 &bitmap); png_error png_write_bitmap(util::core_file &fp, png_info *info, bitmap_t const &bitmap, int palette_length, const rgb_t *palette); -png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, double rate); +png_error mng_capture_start(util::core_file &fp, bitmap_t &bitmap, unsigned rate); png_error mng_capture_frame(util::core_file &fp, png_info &info, bitmap_t const &bitmap, int palette_length, const rgb_t *palette); png_error mng_capture_stop(util::core_file &fp); -- cgit v1.2.3