summaryrefslogtreecommitdiff
path: root/src/as-02-unwrap.cpp
diff options
context:
space:
mode:
authormilla <marc.illa@dolby.com>2021-05-26 13:31:53 +0200
committermilla <marc.illa@dolby.com>2021-06-03 13:47:34 +0200
commit7a085ad0d445ffc63ec42a2faa69a82138931575 (patch)
tree939c2235d2af55291f50c0bd0d329e5d87145ddf /src/as-02-unwrap.cpp
parentf9d7fbc33aa571c547d916b145712469efd9f4b8 (diff)
Adapt as-02-info and as-02-unwrap to iab api
Diffstat (limited to 'src/as-02-unwrap.cpp')
-rwxr-xr-xsrc/as-02-unwrap.cpp124
1 files changed, 121 insertions, 3 deletions
diff --git a/src/as-02-unwrap.cpp b/src/as-02-unwrap.cpp
index 64a399a..18429c2 100755
--- a/src/as-02-unwrap.cpp
+++ b/src/as-02-unwrap.cpp
@@ -38,12 +38,13 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <KM_fileio.h>
#include <AS_02.h>
+#include <AS_02_IAB.h>
#include "AS_02_ACES.h"
#include <WavFileWriter.h>
namespace ASDCP {
Result_t MD_to_PCM_ADesc(ASDCP::MXF::WaveAudioDescriptor* ADescObj, ASDCP::PCM::AudioDescriptor& ADesc);
-}
+} // namespace asdcp
using namespace ASDCP;
@@ -140,7 +141,7 @@ public:
bool j2c_pedantic; // passed to JP2K::SequenceParser::OpenRead
ui32_t picture_rate; // fps of picture when wrapping PCM
ui32_t fb_size; // size of picture frame buffer
- Rational edit_rate; // frame buffer size for reading clip-wrapped PCM
+ ASDCP::Rational edit_rate; // frame buffer size for reading clip-wrapped PCM
const char* file_prefix; // filename pre for files written by the extract mode
byte_t key_value[KeyLen]; // value of given encryption key (when key_flag is true)
byte_t key_id_value[UUIDlen];// value of given key ID (when key_id_flag is true)
@@ -635,7 +636,7 @@ read_PCM_file(CommandOptions& Options)
ui32_t last_frame = 0;
ASDCP::MXF::WaveAudioDescriptor *wave_descriptor = 0;
- if ( Options.edit_rate == Rational(0,0) ) // todo, make this available to the CLI
+ if ( Options.edit_rate == ASDCP::Rational(0,0) ) // todo, make this available to the CLI
{
Options.edit_rate = EditRate_24;
}
@@ -986,6 +987,119 @@ extract_generic_stream_partition_payload(const std::string& in_filename, const u
return result;
}
+Result_t read_iab_file(CommandOptions& Options)
+{
+ AESDecContext* Context = 0;
+ HMACContext* HMAC = 0;
+ AS_02::IAB::MXFReader Reader;
+ ASDCP::FrameBuffer FrameBuffer;
+
+ ui32_t last_frame = 0;
+ ASDCP::MXF::IABEssenceDescriptor *iab_descriptor = 0;
+
+ Result_t result = Reader.OpenRead(Options.input_filename);
+
+ if ( KM_SUCCESS(result) )
+ {
+ if ( Options.verbose_flag )
+ {
+ fprintf(stderr, "Frame Buffer size: %u\n", Options.fb_size);
+ }
+
+ ASDCP::MXF::InterchangeObject* tmp_obj = 0;
+
+ result = Reader.OP1aHeader().GetMDObjectByType(DefaultCompositeDict().ul(MDD_IABEssenceDescriptor), &tmp_obj);
+
+ if ( KM_SUCCESS(result) )
+ {
+ iab_descriptor = dynamic_cast<ASDCP::MXF::IABEssenceDescriptor*>(tmp_obj);
+
+ if ( iab_descriptor == 0 )
+ {
+ fprintf(stderr, "File does not contain an essence descriptor.\n");
+ return RESULT_FAIL;
+ }
+
+ if ( Options.verbose_flag )
+ {
+ iab_descriptor->Dump();
+ }
+
+ if ( iab_descriptor->ContainerDuration.get() == 0 )
+ {
+ fprintf(stderr, "ContainerDuration not set in file descriptor, attempting to use index duration.\n");
+ Reader.GetFrameCount(last_frame);
+ }
+ else
+ {
+ last_frame = (ui32_t)iab_descriptor->ContainerDuration;
+ }
+
+ if ( last_frame == 0 )
+ {
+ fprintf(stderr, "ContainerDuration not set in index, attempting to use Duration from SourceClip.\n");
+ result = Reader.OP1aHeader().GetMDObjectByType(DefaultCompositeDict().ul(MDD_SourceClip), &tmp_obj);
+ if ( KM_SUCCESS(result))
+ {
+ ASDCP::MXF::SourceClip *sourceClip = dynamic_cast<ASDCP::MXF::SourceClip*>(tmp_obj);
+ if ( ! sourceClip->Duration.empty() )
+ {
+ last_frame = (ui32_t)sourceClip->Duration;
+ }
+ }
+ }
+
+ if ( last_frame == 0 )
+ {
+ fprintf(stderr, "Unable to determine file duration.\n");
+ return RESULT_FAIL;
+ }
+
+ assert(iab_descriptor);
+ FrameBuffer.Capacity(24000); // TODO what size?
+ last_frame = (ui32_t)iab_descriptor->ContainerDuration;
+ }
+ }
+
+ if ( ASDCP_SUCCESS(result) )
+ {
+ if ( Options.duration > 0 && Options.duration < last_frame )
+ last_frame = Options.duration;
+
+ if ( Options.start_frame > 0 )
+ {
+ if ( Options.start_frame > last_frame )
+ {
+ fprintf(stderr, "Start value greater than file duration.\n");
+ return RESULT_FAIL;
+ }
+
+ last_frame = Kumu::xmin(Options.start_frame + last_frame, last_frame);
+ }
+
+ last_frame = last_frame - Options.start_frame;
+
+
+ }
+
+ for ( ui32_t i = Options.start_frame; ASDCP_SUCCESS(result) && i < last_frame; i++ )
+ {
+ result = Reader.ReadFrame(i, FrameBuffer);
+
+ if ( ASDCP_SUCCESS(result) )
+ {
+ if ( Options.verbose_flag )
+ {
+ FrameBuffer.FrameNumber(i);
+ fprintf(stdout, "Frame(%d):\n", i);
+ Kumu::hexdump(FrameBuffer.RoData(), Kumu::xmin(FrameBuffer.Size(), (ui32_t)Options.fb_dump_size), stdout);
+ }
+ }
+ }
+
+ return result;
+}
+
//
int
@@ -1032,6 +1146,10 @@ main(int argc, const char** argv)
result = read_timed_text_file(Options);
break;
+ case ESS_AS02_IAB:
+ result = read_iab_file(Options);
+ break;
+
case ESS_AS02_ISXD:
if ( Options.g_stream_sid == 0 )
{