From b65e106e4a29937107d2651abd7a2083aff47a21 Mon Sep 17 00:00:00 2001 From: HARUYAMA Seigo Date: Sun, 30 Apr 2023 14:51:28 +0900 Subject: [PATCH] breaking: add Track::addData() --- example/mp4-muxer.cpp | 26 +++++++++++++------------- include/shiguredo/mp4/track/aac.hpp | 3 +++ include/shiguredo/mp4/track/av1.hpp | 3 +++ include/shiguredo/mp4/track/mp3.hpp | 3 +++ include/shiguredo/mp4/track/opus.hpp | 3 +++ include/shiguredo/mp4/track/track.hpp | 6 ++++-- include/shiguredo/mp4/track/vpx.hpp | 3 +++ src/track/aac.cpp | 11 +++++++++++ src/track/av1.cpp | 11 +++++++++++ src/track/mp3.cpp | 11 +++++++++++ src/track/opus.cpp | 11 +++++++++++ src/track/vpx.cpp | 11 +++++++++++ 12 files changed, 87 insertions(+), 15 deletions(-) diff --git a/example/mp4-muxer.cpp b/example/mp4-muxer.cpp index 9a96f89..1f50d4d 100644 --- a/example/mp4-muxer.cpp +++ b/example/mp4-muxer.cpp @@ -115,7 +115,7 @@ int main(int argc, char** argv) { shiguredo::mp4::track::OpusTrack opus_trak( {.pre_skip = 312, .duration = duration, .track_id = writer.getAndUpdateNextTrackID(), .writer = &writer}); for (std::size_t i = 0; i < 800; ++i) { - opus_trak.addMdatData(resources[i].timestamp, resources[i].data, resources[i].is_key); + opus_trak.addData(resources[i].timestamp, resources[i].data, resources[i].is_key); } writer.appendTrakAndUdtaBoxInfo({&opus_trak}); writer.writeFreeBoxAndMdatHeader(); @@ -143,12 +143,12 @@ int main(int argc, char** argv) { // chunk length: 1000ms for (std::size_t j = 0; j < 50; ++j) { const auto i = s * 50 + j; - opus_trak.addMdatData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); + opus_trak.addData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); } opus_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 25; ++j) { const auto i = s * 25 + j; - vpx_trak.addMdatData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); + vpx_trak.addData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); } vpx_trak.terminateCurrentChunk(); } @@ -176,12 +176,12 @@ int main(int argc, char** argv) { // chunk length: 1000ms for (std::size_t j = 0; j < 50; ++j) { const auto i = s * 50 + j; - opus_trak.addMdatData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); + opus_trak.addData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); } opus_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 25; ++j) { const auto i = s * 25 + j; - av1_trak.addMdatData(av1_resources[i].timestamp, av1_resources[i].data, av1_resources[i].is_key); + av1_trak.addData(av1_resources[i].timestamp, av1_resources[i].data, av1_resources[i].is_key); } av1_trak.terminateCurrentChunk(); } @@ -217,12 +217,12 @@ int main(int argc, char** argv) { // chunk length: 960ms for (std::size_t j = 0; j < 40; ++j) { const auto i = s * 40 + j; - mp3_trak.addMdatData(mp3_resources[i].timestamp, mp3_resources[i].data, mp3_resources[i].is_key); + mp3_trak.addData(mp3_resources[i].timestamp, mp3_resources[i].data, mp3_resources[i].is_key); } mp3_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 24; ++j) { const auto i = s * 24 + j; - vpx_trak.addMdatData(vp8_resources[i].timestamp, vp8_resources[i].data, vp8_resources[i].is_key); + vpx_trak.addData(vp8_resources[i].timestamp, vp8_resources[i].data, vp8_resources[i].is_key); } vpx_trak.terminateCurrentChunk(); } @@ -257,12 +257,12 @@ int main(int argc, char** argv) { // chunk length: 960ms for (std::size_t j = 0; j < 45; ++j) { const auto i = s * 45 + j; - aac_trak.addMdatData(aac_resources[i].timestamp, aac_resources[i].data, aac_resources[i].is_key); + aac_trak.addData(aac_resources[i].timestamp, aac_resources[i].data, aac_resources[i].is_key); } aac_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 24; ++j) { const auto i = s * 24 + j; - vpx_trak.addMdatData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); + vpx_trak.addData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); } vpx_trak.terminateCurrentChunk(); } @@ -292,12 +292,12 @@ int main(int argc, char** argv) { // chunk length: 1000ms for (std::size_t j = 0; j < 50; ++j) { const auto i = s * 50 + j; - opus_trak.addMdatData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); + opus_trak.addData(opus_resources[i].timestamp, opus_resources[i].data, opus_resources[i].is_key); } opus_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 25; ++j) { const auto i = s * 25 + j; - vpx_trak.addMdatData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); + vpx_trak.addData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); } vpx_trak.terminateCurrentChunk(); } @@ -334,12 +334,12 @@ int main(int argc, char** argv) { // chunk length: 960 ms for (std::size_t j = 0; j < 45; ++j) { const auto i = s * 45 + j; - aac_trak.addMdatData(aac_resources[i].timestamp, aac_resources[i].data, aac_resources[i].is_key); + aac_trak.addData(aac_resources[i].timestamp, aac_resources[i].data, aac_resources[i].is_key); } aac_trak.terminateCurrentChunk(); for (std::size_t j = 0; j < 24; ++j) { const auto i = s * 24 + j; - vpx_trak.addMdatData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); + vpx_trak.addData(vp9_resources[i].timestamp, vp9_resources[i].data, vp9_resources[i].is_key); } vpx_trak.terminateCurrentChunk(); } diff --git a/include/shiguredo/mp4/track/aac.hpp b/include/shiguredo/mp4/track/aac.hpp index 3edfd92..f670ca0 100644 --- a/include/shiguredo/mp4/track/aac.hpp +++ b/include/shiguredo/mp4/track/aac.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "shiguredo/mp4/track/soun.hpp" @@ -33,6 +34,8 @@ class AACTrack : public SounTrack { public: explicit AACTrack(const AACTrackParameters&); void appendTrakBoxInfo(BoxInfo*) override; + void addData(const std::uint64_t, const std::vector&, bool) override; + void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override; private: const std::uint32_t m_buffer_size_db; diff --git a/include/shiguredo/mp4/track/av1.hpp b/include/shiguredo/mp4/track/av1.hpp index 914006a..f671c52 100644 --- a/include/shiguredo/mp4/track/av1.hpp +++ b/include/shiguredo/mp4/track/av1.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "shiguredo/mp4/track/vide.hpp" @@ -32,6 +33,8 @@ class AV1Track : public VideTrack { public: explicit AV1Track(const AV1TrackParameters&); void appendTrakBoxInfo(BoxInfo*) override; + void addData(const std::uint64_t, const std::vector&, bool) override; + void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override; private: void makeStsdBoxInfo(BoxInfo*); diff --git a/include/shiguredo/mp4/track/mp3.hpp b/include/shiguredo/mp4/track/mp3.hpp index f1cece1..16c581e 100644 --- a/include/shiguredo/mp4/track/mp3.hpp +++ b/include/shiguredo/mp4/track/mp3.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "shiguredo/mp4/track/soun.hpp" @@ -33,6 +34,8 @@ class MP3Track : public SounTrack { public: explicit MP3Track(const MP3TrackParameters&); void appendTrakBoxInfo(BoxInfo*) override; + void addData(const std::uint64_t, const std::vector&, bool) override; + void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override; private: const std::uint32_t m_buffer_size_db; diff --git a/include/shiguredo/mp4/track/opus.hpp b/include/shiguredo/mp4/track/opus.hpp index 7aec81d..222276d 100644 --- a/include/shiguredo/mp4/track/opus.hpp +++ b/include/shiguredo/mp4/track/opus.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "shiguredo/mp4/track/soun.hpp" @@ -30,6 +31,8 @@ class OpusTrack : public SounTrack { public: explicit OpusTrack(const OpusTrackParameters&); void appendTrakBoxInfo(BoxInfo*) override; + void addData(const std::uint64_t, const std::vector&, bool) override; + void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override; private: const std::uint64_t m_pre_skip; diff --git a/include/shiguredo/mp4/track/track.hpp b/include/shiguredo/mp4/track/track.hpp index cb741d7..3540456 100644 --- a/include/shiguredo/mp4/track/track.hpp +++ b/include/shiguredo/mp4/track/track.hpp @@ -42,15 +42,17 @@ enum HandlerType { class Track { public: virtual ~Track() = default; - void addMdatData(const std::uint64_t timestamp, const std::vector&, bool is_key); - void addMdatData(const std::uint64_t timestamp, const std::uint8_t*, const std::size_t, bool is_key); virtual void appendTrakBoxInfo(BoxInfo*) = 0; + virtual void addData(const std::uint64_t, const std::vector&, bool) = 0; + virtual void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) = 0; void setMediaTime(const std::int64_t); std::uint64_t getTimescale() const; void resetChunkOffsets(std::uint64_t); void terminateCurrentChunk(); protected: + void addMdatData(const std::uint64_t, const std::vector&, bool); + void addMdatData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool); std::uint32_t m_timescale; float m_duration; std::uint32_t m_mvhd_timescale; diff --git a/include/shiguredo/mp4/track/vpx.hpp b/include/shiguredo/mp4/track/vpx.hpp index d59f142..7aef722 100644 --- a/include/shiguredo/mp4/track/vpx.hpp +++ b/include/shiguredo/mp4/track/vpx.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "shiguredo/mp4/track/vide.hpp" @@ -40,6 +41,8 @@ class VPXTrack : public VideTrack { public: explicit VPXTrack(const VPXTrackParameters&); void appendTrakBoxInfo(BoxInfo*) override; + void addData(const std::uint64_t, const std::vector&, bool) override; + void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override; private: const VPXCodec m_codec; diff --git a/src/track/aac.cpp b/src/track/aac.cpp index b6fa111..e85f5f7 100644 --- a/src/track/aac.cpp +++ b/src/track/aac.cpp @@ -100,4 +100,15 @@ void AACTrack::makeSbgpBoxInfo(BoxInfo* stbl) { .group_description_index = 1})}})}); } +void AACTrack::addData(const std::uint64_t timestamp, const std::vector& data, bool is_key) { + addMdatData(timestamp, data, is_key); +} + +void AACTrack::addData(const std::uint64_t timestamp, + const std::uint8_t* data, + const std::size_t data_size, + bool is_key) { + addMdatData(timestamp, data, data_size, is_key); +} + } // namespace shiguredo::mp4::track diff --git a/src/track/av1.cpp b/src/track/av1.cpp index 0e35528..063adac 100644 --- a/src/track/av1.cpp +++ b/src/track/av1.cpp @@ -71,4 +71,15 @@ void AV1Track::appendTrakBoxInfo(BoxInfo* moov) { makeOffsetBoxInfo(stbl); } +void AV1Track::addData(const std::uint64_t timestamp, const std::vector& data, bool is_key) { + addMdatData(timestamp, data, is_key); +} + +void AV1Track::addData(const std::uint64_t timestamp, + const std::uint8_t* data, + const std::size_t data_size, + bool is_key) { + addMdatData(timestamp, data, data_size, is_key); +} + } // namespace shiguredo::mp4::track diff --git a/src/track/mp3.cpp b/src/track/mp3.cpp index 7f8ee63..aab4bc1 100644 --- a/src/track/mp3.cpp +++ b/src/track/mp3.cpp @@ -73,4 +73,15 @@ void MP3Track::appendTrakBoxInfo(BoxInfo* moov) { makeOffsetBoxInfo(stbl); } +void MP3Track::addData(const std::uint64_t timestamp, const std::vector& data, bool is_key) { + addMdatData(timestamp, data, is_key); +} + +void MP3Track::addData(const std::uint64_t timestamp, + const std::uint8_t* data, + const std::size_t data_size, + bool is_key) { + addMdatData(timestamp, data, data_size, is_key); +} + } // namespace shiguredo::mp4::track diff --git a/src/track/opus.cpp b/src/track/opus.cpp index 669291b..2220df0 100644 --- a/src/track/opus.cpp +++ b/src/track/opus.cpp @@ -85,4 +85,15 @@ void OpusTrack::makeSbgpBoxInfo(BoxInfo* stbl) { .group_description_index = 1})}})}); } +void OpusTrack::addData(const std::uint64_t timestamp, const std::vector& data, bool is_key) { + addMdatData(timestamp, data, is_key); +} + +void OpusTrack::addData(const std::uint64_t timestamp, + const std::uint8_t* data, + const std::size_t data_size, + bool is_key) { + addMdatData(timestamp, data, data_size, is_key); +} + } // namespace shiguredo::mp4::track diff --git a/src/track/vpx.cpp b/src/track/vpx.cpp index d554957..ff1dd16 100644 --- a/src/track/vpx.cpp +++ b/src/track/vpx.cpp @@ -70,4 +70,15 @@ void VPXTrack::appendTrakBoxInfo(BoxInfo* moov) { makeOffsetBoxInfo(stbl); } +void VPXTrack::addData(const std::uint64_t timestamp, const std::vector& data, bool is_key) { + addMdatData(timestamp, data, is_key); +} + +void VPXTrack::addData(const std::uint64_t timestamp, + const std::uint8_t* data, + const std::size_t data_size, + bool is_key) { + addMdatData(timestamp, data, data_size, is_key); +} + } // namespace shiguredo::mp4::track