Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ target_link_libraries(create_sadm_from_scratch PRIVATE adm)

add_executable(parse_sadm_xml parse_sadm_xml.cpp)
target_link_libraries(parse_sadm_xml PRIVATE adm)

add_executable(adm_segmenter adm_segmenter.cpp)
target_link_libraries(adm_segmenter PRIVATE adm)
86 changes: 86 additions & 0 deletions examples/adm_segmenter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include "adm/common_definitions.hpp"
#include "adm/parse.hpp"
#include "adm/write.hpp"
#include "adm/segmenter.hpp"
#include "adm/utilities/id_assignment.hpp"
#include "adm/utilities/object_creation.hpp"

using namespace adm;

std::string genSadmFilename(std::string pref, uint32_t ind);
TrackUidList buildTrackList(std::shared_ptr<Document> document);

int main(int argc, char const *argv[]) {
std::string fout_pre = "/tmp/segmenter_output";
int size = 1000;
int max_fr = 10;

auto document = parseXml("../tests/test_data/segmenter_input.xml");

// Get file length
std::chrono::nanoseconds filelength((uint64_t)(max_fr * size) * 1000000L);
for (auto programme : document->getElements<AudioProgramme>()) {
if (programme->has<Start>() && programme->has<End>()) {
filelength = programme->get<End>().get().asNanoseconds() - programme->get<Start>().get().asNanoseconds();
break;
} else if (programme->has<End>()) {
filelength = programme->get<End>().get().asNanoseconds();
break;
}
}

auto trackUidList = buildTrackList(document);

Segmenter segmenter(document, Time(filelength));
SegmentStart segment_start(std::chrono::milliseconds(0));
SegmentDuration segment_size(std::chrono::milliseconds{size});
int fr = 0;
while (segment_start < filelength && fr < max_fr) {
segmenter.buildFrame(segment_start, segment_size, fr);
auto transportTrackFormat = segmenter.generateTransportTrackFormat(trackUidList,
segment_start, segment_size);
auto frame = segmenter.getFrame();
auto frameHeader = segmenter.getFrameHeader();

std::stringstream xmlStream;
writeXml(xmlStream, frame, *frameHeader);

std::string fname = genSadmFilename(fout_pre, fr);
std::ofstream sfile(fname);

sfile << xmlStream.str();

// Get ready for next frame
xmlStream.str("");
segment_start = SegmentStart(segment_start.get() + segment_size.get());
fr++;
}

return 0;
}


std::string genSadmFilename(std::string pref, uint32_t ind) {
char c[256];
sprintf(c, "%s_%04d.xml", pref.c_str(), ind);
std::string s(c);
return s;
}

TrackUidList buildTrackList(std::shared_ptr<Document> document) {
TrackUidList trackUidList;

auto atus = document->getElements<AudioTrackUid>();
uint16_t track_idx = 1;
for (auto atu : atus) {
TrackUid track_uid;
track_uid.uid = formatId(atu->get<AudioTrackUidId>());
track_uid.trackIndex = track_idx;
trackUidList.trackUid.push_back(track_uid);
track_idx++;
}
return trackUidList;
}
36 changes: 36 additions & 0 deletions include/adm/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ namespace adm {
ADM_EXPORT bool add(std::shared_ptr<AudioTrackFormat> trackFormat);
/// @brief Add an AudioTrackUid
ADM_EXPORT bool add(std::shared_ptr<AudioTrackUid> trackUid);
/// @brief Add a profileList
ADM_EXPORT bool add(std::shared_ptr<ProfileList> profileList);
/// @brief Add a tagList
ADM_EXPORT bool add(std::shared_ptr<TagList> tagList);
Comment on lines +84 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be set()? (you can't have >1 profileList or tagList in a document)

///@}

/** @name Remove ADM elements
Expand All @@ -104,6 +108,10 @@ namespace adm {
ADM_EXPORT bool remove(std::shared_ptr<AudioTrackFormat> trackFormat);
/// @brief Remove an AudioTrackUid
ADM_EXPORT bool remove(std::shared_ptr<AudioTrackUid> trackUid);
/// @brief Remove a profileList
ADM_EXPORT bool remove(std::shared_ptr<ProfileList> profileList);
/// @brief Remove a tagList
ADM_EXPORT bool remove(std::shared_ptr<TagList> tagList);
///@}

/**
Expand All @@ -126,6 +134,12 @@ namespace adm {
template <typename Element>
ElementRange<Element> getElements();

template <typename Element>
std::shared_ptr<const Element> getElement() const;

template <typename Element>
std::shared_ptr<Element> getElement();

Comment on lines +137 to +142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something specific about TagList and ProfileList, I'd be a bit inclined to remove getElement(), and instead add TagList and ProfileList to DocumentBase as OptionalElements - Partly for consistency with the rest of the API when retreiving individual sub elements (everywhere else uses get<T>()), partly so you get the usual has/get/set/isDefault behaviour for free. I think if we kept things as-it, a 2076-2 or below document would just return nullptr, which I don't think we do anywhere else to indicate an absence?

/** @name Lookup ADM elements by its Id
*
* Lookup the first ADM element with the given Id.
Expand Down Expand Up @@ -257,6 +271,10 @@ namespace adm {
detail::ParameterTraits<AudioTrackFormat>::tag) const;
ADM_EXPORT ElementRange<const AudioTrackUid> getElements(
detail::ParameterTraits<AudioTrackUid>::tag) const;
ADM_EXPORT std::shared_ptr<const ProfileList> getElement(
detail::ParameterTraits<ProfileList>::tag) const;
ADM_EXPORT std::shared_ptr<const TagList> getElement(
detail::ParameterTraits<TagList>::tag) const;
ADM_EXPORT ElementRange<AudioProgramme> getElements(
detail::ParameterTraits<AudioProgramme>::tag);
ADM_EXPORT ElementRange<AudioContent> getElements(
Expand All @@ -273,6 +291,10 @@ namespace adm {
detail::ParameterTraits<AudioTrackFormat>::tag);
ADM_EXPORT ElementRange<AudioTrackUid> getElements(
detail::ParameterTraits<AudioTrackUid>::tag);
ADM_EXPORT std::shared_ptr<ProfileList> getElement(
detail::ParameterTraits<ProfileList>::tag);
ADM_EXPORT std::shared_ptr<TagList> getElement(
detail::ParameterTraits<TagList>::tag);

/// check the parent of an element
///
Expand Down Expand Up @@ -300,6 +322,8 @@ namespace adm {
std::vector<std::shared_ptr<AudioStreamFormat>> audioStreamFormats_;
std::vector<std::shared_ptr<AudioTrackFormat>> audioTrackFormats_;
std::vector<std::shared_ptr<AudioTrackUid>> audioTrackUids_;
std::shared_ptr<ProfileList> profileList_;
std::shared_ptr<TagList> tagList_;
Comment on lines +325 to +326
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably want to be boost::optional<> rather than std::shared_ptr<> as we don't need reference semantics I don't think, just the ability for the elements to not be present?

detail::IdAssigner idAssigner_;
};

Expand All @@ -317,4 +341,16 @@ namespace adm {
return getElements(Tag());
}

template <typename Element>
std::shared_ptr<const Element> Document::getElement() const {
typedef typename detail::ParameterTraits<Element>::tag Tag;
return getElement(Tag());
}

template <typename Element>
std::shared_ptr<Element> Document::getElement() {
typedef typename detail::ParameterTraits<Element>::tag Tag;
return getElement(Tag());
}

} // namespace adm
1 change: 1 addition & 0 deletions include/adm/elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "adm/elements/audio_stream_format.hpp"
#include "adm/elements/audio_track_uid.hpp"
#include "adm/elements/profile_list.hpp"
#include "adm/elements/tag_list.hpp"

#include "adm/elements/audio_block_format_direct_speakers.hpp"
#include "adm/elements/audio_block_format_matrix.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/adm/elements/audio_channel_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ namespace adm {
return previous == 0u || current == previous.get() + 1u;
}
}

template <typename BlockFormat>
void AudioChannelFormat::assignId(BlockFormat &blockFormat,
BlockFormat *previousBlock) {
Expand Down
4 changes: 2 additions & 2 deletions include/adm/elements/profile_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ namespace adm {
using ProfileListBase = HasParameters<VectorParameter<Profiles>>;
} // namespace detail

struct ProfileceListTag {};
struct ProfileListTag {};

class ProfileList : private detail::ProfileListBase,
private detail::AddWrapperMethods<ProfileList> {
public:
using tag = ProfileceListTag;
using tag = ProfileListTag;

template <typename... Parameters>
explicit ProfileList(Parameters... namedArgs) {
Expand Down
Loading
Loading