Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: override timed text duration #120

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/AS_DCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ namespace ASDCP {

// Opens an XML file for reading, parses data to provide a complete
// set of stream metadata for the MXFWriter below.
Result_t OpenRead(const std::string& filename) const;
Result_t OpenRead(const std::string& filename, ui32_t d=0) const;

// Parses an XML document to provide a complete set of stream metadata
// for the MXFWriter below. The optional filename argument is used to
Expand Down
31 changes: 21 additions & 10 deletions src/TimedText_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser
{
XMLElement m_Root;
ResourceTypeMap_t m_ResourceTypes;
Result_t OpenRead();
Result_t OpenRead(ui32_t d=0);

ASDCP_NO_COPY_CONSTRUCT(h__SubtitleParser);

Expand Down Expand Up @@ -140,8 +140,8 @@ class ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser
return m_DefaultResolver;
}

Result_t OpenRead(const std::string& filename);
Result_t OpenRead(const std::string& xml_doc, const std::string& filename);
Result_t OpenRead(const std::string& filename, ui32_t duration_override=0);
Result_t OpenRead(const std::string& xml_doc, const std::string& filename, ui32_t duration_override=0);
Result_t ReadAncillaryResource(const byte_t* uuid, FrameBuffer& FrameBuf, const IResourceResolver& Resolver) const;
};
namespace {
Expand Down Expand Up @@ -179,20 +179,20 @@ namespace {

//
Result_t
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const std::string& filename)
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const std::string& filename, ui32_t duration_override)
{
Result_t result = ReadFileIntoString(filename, m_XMLDoc);

if ( KM_SUCCESS(result) )
result = OpenRead();
result = OpenRead(duration_override);

m_Filename = filename;
return result;
}

//
Result_t
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const std::string& xml_doc, const std::string& filename)
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const std::string& xml_doc, const std::string& filename, ui32_t duration_override)
{
m_XMLDoc = xml_doc;

Expand All @@ -205,12 +205,12 @@ ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(const std::strin
m_Filename = filename;
}

return OpenRead();
return OpenRead(duration_override);
}

//
Result_t
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead()
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead(ui32_t duration_override)
{
if ( ! m_Root.ParseString(m_XMLDoc) )
return RESULT_FORMAT;
Expand Down Expand Up @@ -370,6 +370,17 @@ ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead()

m_TDesc.ContainerDuration = end_count - beginTC.GetFrames();

if (duration_override)
{
if (duration_override < m_TDesc.ContainerDuration)
{
DefaultLogSink(). Error("Override Duration (%d) may not be less than the actual intrinsic duration (%d).\n",
duration_override, m_TDesc.ContainerDuration);
return RESULT_FORMAT;
}
m_TDesc.ContainerDuration = duration_override;
}

return RESULT_OK;
}

Expand Down Expand Up @@ -426,11 +437,11 @@ ASDCP::TimedText::DCSubtitleParser::~DCSubtitleParser()
// Opens the stream for reading, parses enough data to provide a complete
// set of stream metadata for the MXFWriter below.
ASDCP::Result_t
ASDCP::TimedText::DCSubtitleParser::OpenRead(const std::string& filename) const
ASDCP::TimedText::DCSubtitleParser::OpenRead(const std::string& filename, ui32_t d) const
{
const_cast<ASDCP::TimedText::DCSubtitleParser*>(this)->m_Parser = new h__SubtitleParser;

Result_t result = m_Parser->OpenRead(filename);
Result_t result = m_Parser->OpenRead(filename, d);

if ( ASDCP_FAILURE(result) )
const_cast<ASDCP::TimedText::DCSubtitleParser*>(this)->m_Parser = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/asdcp-wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Options:\n\
Defaults to 4,194,304 (4MB)\n\
-C <UL> - Set ChannelAssignment UL value in a PCM file\n\
-d <duration> - Number of frames to process, default all\n\
Note: For timed-text MXFs, this option forces the\n\
value for the Asset's intrinsic duration.\n\
-e - Encrypt MPEG or JP2K headers (default)\n\
-E - Do not encrypt MPEG or JP2K headers\n\
-f <start-frame> - Starting frame number, default 0\n\
Expand Down Expand Up @@ -1368,7 +1370,8 @@ write_timed_text_file(CommandOptions& Options)
byte_t IV_buf[CBC_BLOCK_SIZE];

// set up essence parser
Result_t result = Parser.OpenRead(Options.filenames.front());
Result_t result = Parser.OpenRead(Options.filenames.front(),
(Options.duration == 0xffffffff ? 0 : Options.duration));

// set up MXF writer
if ( ASDCP_SUCCESS(result) )
Expand Down
Loading