Skip to content

Commit

Permalink
breaking: add Track::addData()
Browse files Browse the repository at this point in the history
  • Loading branch information
haruyama committed Apr 30, 2023
1 parent 15639d8 commit b65e106
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 15 deletions.
26 changes: 13 additions & 13 deletions example/mp4-muxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions include/shiguredo/mp4/track/aac.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <vector>

#include "shiguredo/mp4/track/soun.hpp"

Expand Down Expand Up @@ -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<std::uint8_t>&, 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;
Expand Down
3 changes: 3 additions & 0 deletions include/shiguredo/mp4/track/av1.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <vector>

#include "shiguredo/mp4/track/vide.hpp"

Expand Down Expand Up @@ -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<std::uint8_t>&, bool) override;
void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override;

private:
void makeStsdBoxInfo(BoxInfo*);
Expand Down
3 changes: 3 additions & 0 deletions include/shiguredo/mp4/track/mp3.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <vector>

#include "shiguredo/mp4/track/soun.hpp"

Expand Down Expand Up @@ -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<std::uint8_t>&, 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;
Expand Down
3 changes: 3 additions & 0 deletions include/shiguredo/mp4/track/opus.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <vector>

#include "shiguredo/mp4/track/soun.hpp"

Expand Down Expand Up @@ -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<std::uint8_t>&, 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;
Expand Down
6 changes: 4 additions & 2 deletions include/shiguredo/mp4/track/track.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ enum HandlerType {
class Track {
public:
virtual ~Track() = default;
void addMdatData(const std::uint64_t timestamp, const std::vector<std::uint8_t>&, 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<std::uint8_t>&, 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<std::uint8_t>&, 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;
Expand Down
3 changes: 3 additions & 0 deletions include/shiguredo/mp4/track/vpx.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <vector>

#include "shiguredo/mp4/track/vide.hpp"

Expand Down Expand Up @@ -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<std::uint8_t>&, bool) override;
void addData(const std::uint64_t, const std::uint8_t*, const std::size_t, bool) override;

private:
const VPXCodec m_codec;
Expand Down
11 changes: 11 additions & 0 deletions src/track/aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ void AACTrack::makeSbgpBoxInfo(BoxInfo* stbl) {
.group_description_index = 1})}})});
}

void AACTrack::addData(const std::uint64_t timestamp, const std::vector<std::uint8_t>& 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
11 changes: 11 additions & 0 deletions src/track/av1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ void AV1Track::appendTrakBoxInfo(BoxInfo* moov) {
makeOffsetBoxInfo(stbl);
}

void AV1Track::addData(const std::uint64_t timestamp, const std::vector<std::uint8_t>& 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
11 changes: 11 additions & 0 deletions src/track/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ void MP3Track::appendTrakBoxInfo(BoxInfo* moov) {
makeOffsetBoxInfo(stbl);
}

void MP3Track::addData(const std::uint64_t timestamp, const std::vector<std::uint8_t>& 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
11 changes: 11 additions & 0 deletions src/track/opus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,15 @@ void OpusTrack::makeSbgpBoxInfo(BoxInfo* stbl) {
.group_description_index = 1})}})});
}

void OpusTrack::addData(const std::uint64_t timestamp, const std::vector<std::uint8_t>& 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
11 changes: 11 additions & 0 deletions src/track/vpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ void VPXTrack::appendTrakBoxInfo(BoxInfo* moov) {
makeOffsetBoxInfo(stbl);
}

void VPXTrack::addData(const std::uint64_t timestamp, const std::vector<std::uint8_t>& 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

0 comments on commit b65e106

Please sign in to comment.