From 1d63bb7c5ba9935f9260c03799e5095255b9b1eb Mon Sep 17 00:00:00 2001 From: HARUYAMA Seigo Date: Tue, 12 Jan 2021 14:04:05 +0900 Subject: [PATCH 1/4] =?UTF-8?q?std=20=E5=90=8D=E5=89=8D=E7=A9=BA=E9=96=93?= =?UTF-8?q?=E3=81=AE=E4=BB=98=E4=B8=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/writer/faststart_writer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/writer/faststart_writer.cpp b/src/writer/faststart_writer.cpp index a11a29e..2753cc5 100644 --- a/src/writer/faststart_writer.cpp +++ b/src/writer/faststart_writer.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -141,13 +143,13 @@ std::uint64_t FaststartWriter::getMdatHeaderSize() const { } void FaststartWriter::copyMdatData() { - if (auto ret = ::fseek(m_mdat_fd, 0, SEEK_SET); ret == -1) { + if (auto ret = std::fseek(m_mdat_fd, 0, SEEK_SET); ret == -1) { throw std::runtime_error("fseek failed"); } char buffer[COPY_MDAT_DATA_BUFFER_SIZE]; - while (!::feof(m_mdat_fd)) { - std::size_t size = ::fread(buffer, 1, COPY_MDAT_DATA_BUFFER_SIZE, m_mdat_fd); + while (!std::feof(m_mdat_fd)) { + std::size_t size = std::fread(buffer, 1, COPY_MDAT_DATA_BUFFER_SIZE, m_mdat_fd); std::copy_n(buffer, size, std::ostreambuf_iterator(m_os)); if (!m_os.good()) { throw std::runtime_error( @@ -155,7 +157,7 @@ void FaststartWriter::copyMdatData() { } } - if (auto ret = ::fclose(m_mdat_fd); ret == EOF) { + if (auto ret = std::fclose(m_mdat_fd); ret == EOF) { throw std::runtime_error( fmt::format("FaststartWriter::copyMdatData(): cannot close the intermediate file: {}", m_mdat_path.string())); } From 6dfdf74f9f3bdda304929ae46590dabb3aefd738 Mon Sep 17 00:00:00 2001 From: HARUYAMA Seigo Date: Tue, 12 Jan 2021 14:09:12 +0900 Subject: [PATCH 2/4] =?UTF-8?q?FaststartWriter::deleteIntermediateFile()?= =?UTF-8?q?=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/shiguredo/mp4/writer/faststart_writer.hpp | 1 + src/writer/faststart_writer.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/shiguredo/mp4/writer/faststart_writer.hpp b/include/shiguredo/mp4/writer/faststart_writer.hpp index 6af89e0..2c2d93c 100644 --- a/include/shiguredo/mp4/writer/faststart_writer.hpp +++ b/include/shiguredo/mp4/writer/faststart_writer.hpp @@ -42,6 +42,7 @@ class FaststartWriter : public Writer { void appendTrakAndUdtaBoxInfo(const std::vector&) override; void writeMdatHeader(); void copyMdatData(); + void deleteIntermediateFile(); private: std::ostream& m_os; diff --git a/src/writer/faststart_writer.cpp b/src/writer/faststart_writer.cpp index 2753cc5..4406d7d 100644 --- a/src/writer/faststart_writer.cpp +++ b/src/writer/faststart_writer.cpp @@ -162,10 +162,7 @@ void FaststartWriter::copyMdatData() { fmt::format("FaststartWriter::copyMdatData(): cannot close the intermediate file: {}", m_mdat_path.string())); } - if (bool result = std::filesystem::remove(m_mdat_path); !result) { - throw std::runtime_error( - fmt::format("FaststartWriter::copyMdatData(): cannot remove the intermediate file: {}", m_mdat_path.string())); - } + deleteIntermediateFile(); } void FaststartWriter::appendTrakAndUdtaBoxInfo(const std::vector& tracks) { @@ -195,4 +192,11 @@ void FaststartWriter::appendTrakAndUdtaBoxInfo(const std::vector Date: Tue, 12 Jan 2021 14:09:25 +0900 Subject: [PATCH 3/4] =?UTF-8?q?dump=5Ftest=20target=20=E3=82=92=20get=5Fin?= =?UTF-8?q?put=5Ffiles=20=E3=81=AB=E4=BE=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/integration/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/Makefile b/test/integration/Makefile index b785ed6..197d3e7 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -7,7 +7,7 @@ get_input_files: [ -f input/sample-5s.mp4 ] || curl -o input/sample-5s.mp4 https://samplelib.com/lib/download/mp4/sample-5s.mp4 # "Below are sample videos available for download with no license restrictions." -- https://samplelib.com/sample-mp4.html sha224sum -c input/check -test: get_input_files mux_test dump_test +test: mux_test dump_test sha224sum -c output/check mux_test: @@ -18,7 +18,7 @@ mux_test: faketime -f '2020-12-01 00:00:00' ../../release/mp4-muxer aacvp9 -f output/aacvp9_test.mp4 --aac resources/aac.csv --vp9 resources/vp9.csv faketime -f '2020-12-01 00:00:00' ../../release/mp4-muxer aacvp9_faststart -f output/aacvp9_faststart_test.mp4 --aac resources/aac.csv --vp9 resources/vp9.csv -dump_test: +dump_test: get_input_files for f in input/*.mp4; do \ base=$$(basename $${f}); \ ../../release/mp4-tool dump -f $${f} > output/$${base}.dump; \ From a4b6d5e499d11d671f9fbaf946502293882a609a Mon Sep 17 00:00:00 2001 From: HARUYAMA Seigo Date: Tue, 12 Jan 2021 14:23:36 +0900 Subject: [PATCH 4/4] =?UTF-8?q?FaststartWriter::getIntermediateFilePath()?= =?UTF-8?q?=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/shiguredo/mp4/writer/faststart_writer.hpp | 1 + src/writer/faststart_writer.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/shiguredo/mp4/writer/faststart_writer.hpp b/include/shiguredo/mp4/writer/faststart_writer.hpp index 2c2d93c..4d53a08 100644 --- a/include/shiguredo/mp4/writer/faststart_writer.hpp +++ b/include/shiguredo/mp4/writer/faststart_writer.hpp @@ -43,6 +43,7 @@ class FaststartWriter : public Writer { void writeMdatHeader(); void copyMdatData(); void deleteIntermediateFile(); + std::filesystem::path getIntermediateFilePath(); private: std::ostream& m_os; diff --git a/src/writer/faststart_writer.cpp b/src/writer/faststart_writer.cpp index 4406d7d..e8807a9 100644 --- a/src/writer/faststart_writer.cpp +++ b/src/writer/faststart_writer.cpp @@ -199,4 +199,9 @@ void FaststartWriter::deleteIntermediateFile() { } } +std::filesystem::path FaststartWriter::getIntermediateFilePath() { + return m_mdat_path; +} + } // namespace shiguredo::mp4::writer +