From 4f568f97cf1765d95d5ea350933f621ff5ef8c0c Mon Sep 17 00:00:00 2001 From: Robert Kausch Date: Sat, 19 Mar 2022 22:25:25 +0100 Subject: [PATCH] Update old test programs and utils. --- test/OLD/c_api.c | 62 ---------- test/OLD/mp4clip.cpp | 243 --------------------------------------- test/OLD/nullcreate.cpp | 120 ------------------- test/OLD/nullvplayer.cpp | 114 ------------------ test/OLD/urltrack.cpp | 91 --------------- test/c_api.c | 59 ++++++++++ test/mp4clip.cpp | 235 +++++++++++++++++++++++++++++++++++++ test/nullcreate.cpp | 185 +++++++++++++++++++++++++++++ test/nullvplayer.cpp | 116 +++++++++++++++++++ test/urltrack.cpp | 90 +++++++++++++++ 10 files changed, 685 insertions(+), 630 deletions(-) delete mode 100644 test/OLD/c_api.c delete mode 100644 test/OLD/mp4clip.cpp delete mode 100644 test/OLD/nullcreate.cpp delete mode 100644 test/OLD/nullvplayer.cpp delete mode 100644 test/OLD/urltrack.cpp create mode 100644 test/c_api.c create mode 100644 test/mp4clip.cpp create mode 100644 test/nullcreate.cpp create mode 100644 test/nullvplayer.cpp create mode 100644 test/urltrack.cpp diff --git a/test/OLD/c_api.c b/test/OLD/c_api.c deleted file mode 100644 index 0b417ce..0000000 --- a/test/OLD/c_api.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is MPEG4IP. - * - * The Initial Developer of the Original Code is Cisco Systems Inc. - * Portions created by Cisco Systems Inc. are - * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. - * - * Contributor(s): - * Dave Mackie dmackie@cisco.com - */ - -#include "mp4.h" - -main(int argc, char** argv) -{ -#if 0 - MP4FileHandle mp4File = MP4Read(argv[1], MP4_DETAILS_ERROR); - - if (!mp4File) { - exit(1); - } - - MP4Dump(mp4File, stdout, 0); - - MP4Close(mp4File); - - exit(0); -#else - MP4FileHandle mp4File; - - mp4File = MP4Read(argv[1], MP4_DETAILS_ERROR); - MP4SetVerbosity(mp4File, MP4_DETAILS_ALL); - if (MP4HaveAtom(mp4File, "moov.mbhd")) { - printf("found moov.mvhd\n"); - } - if (MP4HaveTrackAtom(mp4File, 1, argv[2])) { - printf("found %s\n", argv[2]); - } else { - printf("didn't find it\n"); - } - -#if 0 - u_int8_t* data=(u_int8_t*)"this is my tag data"; - u_int32_t len=strlen((char*)data); - MP4SetMetadataFreeForm(mp4File, "mytag1",data,len); - MP4SetMetadataFreeForm(mp4File, "my_tag2",data,len); -#endif - MP4Close(mp4File); - exit(0); -#endif -} - diff --git a/test/OLD/mp4clip.cpp b/test/OLD/mp4clip.cpp deleted file mode 100644 index 28a9b1a..0000000 --- a/test/OLD/mp4clip.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is MPEG4IP. - * - * The Initial Developer of the Original Code is Cisco Systems Inc. - * Portions created by Cisco Systems Inc. are - * Copyright (C) Cisco Systems Inc. 2001-2002. All Rights Reserved. - * - * Contributor(s): - * Dave Mackie dmackie@cisco.com - */ - -// N.B. mp4clips clips tracks in an mp4 file -// without regard to sync samples aka "key frames" -// as a testing app the burden is on the user to choose -// an appropriate clip start time - -#include "mp4.h" -#include "mpeg4ip_getopt.h" - -char* ProgName; - -// forward declaration -void ClipTrack( - MP4FileHandle srcFile, - MP4TrackId trackId, - MP4FileHandle dstFile, - float startTime, - float duration); - - -int main(int argc, char** argv) -{ - char* usageString = - "usage: %s [-t ] [-v []] [-s ] -l \n"; - char* srcFileName = NULL; - char* dstFileName = NULL; - MP4TrackId trackId = MP4_INVALID_TRACK_ID; - u_int32_t verbosity = MP4_DETAILS_ERROR; - float startTime = 0.0; - float duration = 0.0; - - /* begin processing command line */ - ProgName = argv[0]; - while (true) { - int c = -1; - int option_index = 0; - static struct option long_options[] = { - { "length", 1, 0, 'l' }, - { "start", 1, 0, 's' }, - { "track", 1, 0, 't' }, - { "verbose", 2, 0, 'v' }, - { "version", 0, 0, 'V' }, - { NULL, 0, 0, 0 } - }; - - c = getopt_long_only(argc, argv, "l:s:t:v::V", - long_options, &option_index); - - if (c == -1) - break; - - switch (c) { - case 'l': - if (sscanf(optarg, "%f", &duration) != 1) { - fprintf(stderr, - "%s: bad length specified: %s\n", - ProgName, optarg); - } - break; - case 's': - if (sscanf(optarg, "%f", &startTime) != 1) { - fprintf(stderr, - "%s: bad start time specified: %s\n", - ProgName, optarg); - } - break; - case 't': - if (sscanf(optarg, "%u", &trackId) != 1) { - fprintf(stderr, - "%s: bad track-id specified: %s\n", - ProgName, optarg); - exit(1); - } - break; - case 'v': - verbosity |= MP4_DETAILS_READ; - if (optarg) { - u_int32_t level; - if (sscanf(optarg, "%u", &level) == 1) { - if (level >= 2) { - verbosity |= MP4_DETAILS_TABLE; - } - if (level >= 3) { - verbosity |= MP4_DETAILS_SAMPLE; - } - if (level >= 4) { - verbosity = MP4_DETAILS_ALL; - } - } - } - break; - case '?': - fprintf(stderr, usageString, ProgName); - exit(0); - case 'V': - fprintf(stderr, "%s - %s version %s\n", - ProgName, MPEG4IP_PACKAGE, MPEG4IP_VERSION); - exit(0); - default: - fprintf(stderr, "%s: unknown option specified, ignoring: %c\n", - ProgName, c); - } - } - - /* check that we have at least one non-option argument */ - if ((argc - optind) < 1) { - fprintf(stderr, usageString, ProgName); - exit(1); - } - - if (verbosity) { - fprintf(stderr, "%s version %s\n", ProgName, MPEG4IP_VERSION); - } - - /* point to the specified file name */ - srcFileName = argv[optind++]; - - /* get dest file name */ - if ((argc - optind) > 0) { - dstFileName = argv[optind++]; - } - - /* warn about extraneous non-option arguments */ - if (optind < argc) { - fprintf(stderr, "%s: unknown options specified, ignoring: ", ProgName); - while (optind < argc) { - fprintf(stderr, "%s ", argv[optind++]); - } - fprintf(stderr, "\n"); - } - - if (duration == 0.0) { - fprintf(stderr, - "%s: please specify clip length with -l option\n", - ProgName); - } - - /* end processing of command line */ - - - MP4FileHandle srcFile = - MP4Modify(srcFileName, verbosity); - - if (!srcFile) { - exit(1); - } - - MP4FileHandle dstFile = - MP4_INVALID_FILE_HANDLE; - - if (dstFileName) { - dstFile = MP4Create(dstFileName, verbosity); - } - - if (trackId == MP4_INVALID_TRACK_ID) { - u_int32_t numTracks = MP4GetNumberOfTracks(srcFile); - - for (u_int32_t i = 0; i < numTracks; i++) { - trackId = MP4FindTrackId(srcFile, i); - ClipTrack(srcFile, trackId, dstFile, startTime, duration); - } - } else { - ClipTrack(srcFile, trackId, dstFile, startTime, duration); - } - - MP4Close(srcFile); - if (dstFile != MP4_INVALID_FILE_HANDLE) { - MP4Close(dstFile); - } - - return(0); -} - -void ClipTrack( - MP4FileHandle srcFile, - MP4TrackId trackId, - MP4FileHandle dstFile, - float startTime, - float duration) -{ - MP4Timestamp trackStartTime = - MP4ConvertToTrackTimestamp( - srcFile, - trackId, - (u_int64_t)(startTime * 1000), - MP4_MSECS_TIME_SCALE); - - MP4Duration trackDuration = - MP4ConvertToTrackDuration( - srcFile, - trackId, - (u_int64_t)(duration * 1000), - MP4_MSECS_TIME_SCALE); - - MP4EditId editId = - MP4AddTrackEdit( - srcFile, - trackId, - 1, - trackStartTime, - trackDuration); - - if (editId == MP4_INVALID_EDIT_ID) { - fprintf(stderr, - "%s: can't create track edit\n", - ProgName); - return; - } - - if (dstFile) { - MP4CopyTrack( - srcFile, - trackId, - dstFile, - true); - - MP4DeleteTrackEdit( - srcFile, - trackId, - editId); - } -} - diff --git a/test/OLD/nullcreate.cpp b/test/OLD/nullcreate.cpp deleted file mode 100644 index 1460651..0000000 --- a/test/OLD/nullcreate.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is MPEG4IP. - * - * The Initial Developer of the Original Code is Cisco Systems Inc. - * Portions created by Cisco Systems Inc. are - * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. - * - * Contributor(s): - * Dave Mackie dmackie@cisco.com - */ - -#include "mp4.h" -#if 0 -#include "mp4util.h" -#endif - -main(int argc, char** argv) -{ -#if 1 - if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - - u_int32_t verbosity = MP4_DETAILS_ALL; - - MP4FileHandle mp4File = MP4Create(argv[1], verbosity); - - if (!mp4File) { - exit(1); - } - - printf("Created skeleton\n"); - MP4Dump(mp4File); - - MP4SetODProfileLevel(mp4File, 1); - MP4SetSceneProfileLevel(mp4File, 1); - MP4SetVideoProfileLevel(mp4File, 1); - MP4SetAudioProfileLevel(mp4File, 1); - MP4SetGraphicsProfileLevel(mp4File, 1); - - MP4TrackId odTrackId = - MP4AddODTrack(mp4File); - - MP4TrackId bifsTrackId = - MP4AddSceneTrack(mp4File); - - MP4TrackId videoTrackId = -#if 0 - MP4AddVideoTrack(mp4File, 90000, 3000, 320, 240); -#else - MP4AddH264VideoTrack(mp4File, 90000, 3000, 320, 240, - 1, 2, 3, 1); - static uint8_t pseq[] = { 0, 1, 2, 3, 4, 5, 6,7, 8, 9 }; - - MP4AddH264SequenceParameterSet(mp4File, videoTrackId, pseq, 10); - MP4AddH264SequenceParameterSet(mp4File, videoTrackId, pseq, 6); - MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 7); - MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 8); - MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 7); - -#endif - - MP4TrackId videoHintTrackId = - MP4AddHintTrack(mp4File, videoTrackId); - - MP4TrackId audioTrackId = - MP4AddAudioTrack(mp4File, 44100, 1152); - - MP4TrackId audioHintTrackId = - MP4AddHintTrack(mp4File, audioTrackId); - - printf("Added tracks\n"); - MP4Dump(mp4File); - - MP4Close(mp4File); - - // MP4MakeIsmaCompliant(argv[1], verbosity); - - exit(0); -#else - uint8_t *bin = NULL; - - for (uint32_t ix = 4; ix < 1024; ix++) { - printf("pass %d\n", ix); - bin = (uint8_t *)malloc(ix); - for (uint32_t jx = 0; jx < ix; jx++) { - bin[jx] = ((uint32_t)random()) >> 24; - } - char *test; - test = MP4ToBase64(bin, ix); - uint8_t *ret; - uint32_t retsize; - ret = Base64ToBinary(test, strlen(test), &retsize); - if (retsize != ix) { - printf("return size not same %d %d\n", ix, retsize); - exit(0); - } - if (memcmp(ret, bin, ix) != 0) { - printf("memory not same\n"); - exit(0); - } - free(test); - free(ret); - free(bin); - } - return 0; -#endif -} - diff --git a/test/OLD/nullvplayer.cpp b/test/OLD/nullvplayer.cpp deleted file mode 100644 index c80cb63..0000000 --- a/test/OLD/nullvplayer.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is MPEG4IP. - * - * The Initial Developer of the Original Code is Cisco Systems Inc. - * Portions created by Cisco Systems Inc. are - * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. - * - * Contributor(s): - * Dave Mackie dmackie@cisco.com - */ - -#include "mp4.h" - -main(int argc, char** argv) -{ - if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - - u_int32_t verbosity = MP4_DETAILS_ALL; - char* fileName = argv[1]; - - // open the mp4 file, and read meta-info - MP4FileHandle mp4File = MP4Read(fileName, verbosity); - - u_int8_t profileLevel = MP4GetVideoProfileLevel(mp4File); - - // get a handle on the first video track - MP4TrackId trackId = MP4FindTrackId(mp4File, 0, "video"); - - // gather the crucial track information - - u_int32_t timeScale = MP4GetTrackTimeScale(mp4File, trackId); - - // note all times and durations - // are in units of the track time scale - - MP4Duration trackDuration = MP4GetTrackDuration(mp4File, trackId); - - MP4SampleId numSamples = MP4GetTrackNumberOfSamples(mp4File, trackId); - - u_int32_t maxSampleSize = MP4GetTrackMaxSampleSize(mp4File, trackId); - - u_int8_t* pConfig; - u_int32_t configSize = 0; - - MP4GetTrackESConfiguration(mp4File, trackId, &pConfig, &configSize); - - // initialize decoder with Elementary Stream (ES) configuration - - // done with our copy of ES configuration - free(pConfig); - - - // now consecutively read and display the track samples - - u_int8_t* pSample = (u_int8_t*)malloc(maxSampleSize); - u_int32_t sampleSize; - MP4Timestamp sampleTime; - MP4Duration sampleDuration; - MP4Duration sampleRenderingOffset; - bool isSyncSample; - - for (MP4SampleId sampleId = 1; sampleId <= numSamples; sampleId++) { - - // give ReadSample our own buffer, and let it know how big it is - sampleSize = maxSampleSize; - - // read next sample from video track - MP4ReadSample(mp4File, trackId, sampleId, - &pSample, &sampleSize, - &sampleTime, &sampleDuration, &sampleRenderingOffset, - &isSyncSample); - - // convert timestamp and duration from track time to milliseconds - u_int64_t myTime = MP4ConvertFromTrackTimestamp(mp4File, trackId, - sampleTime, MP4_MSECS_TIME_SCALE); - - u_int64_t myDuration = MP4ConvertFromTrackDuration(mp4File, trackId, - sampleDuration, MP4_MSECS_TIME_SCALE); - - // decode frame and display it - } - - // close mp4 file - MP4Close(mp4File); - - - // Note to seek to time 'when' in the track - // use MP4GetSampleIdFromTime(MP4FileHandle hFile, - // MP4Timestamp when, bool wantSyncSample) - // 'wantSyncSample' determines if a sync sample is desired or not - // e.g. - // MP4Timestamp when = - // MP4ConvertToTrackTimestamp(mp4File, trackId, 30, MP4_SECS_TIME_SCALE); - // MP4SampleId newSampleId = MP4GetSampleIdFromTime(mp4File, when, true); - // MP4ReadSample(mp4File, trackId, newSampleId, ...); - // - // Note that start time for sample may be later than 'when' - - exit(0); -} - diff --git a/test/OLD/urltrack.cpp b/test/OLD/urltrack.cpp deleted file mode 100644 index a61c480..0000000 --- a/test/OLD/urltrack.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is MPEG4IP. - * - * The Initial Developer of the Original Code is Cisco Systems Inc. - * Portions created by Cisco Systems Inc. are - * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. - * - * Contributor(s): - * Dave Mackie dmackie@cisco.com - */ - -#include "mp4.h" - -main(int argc, char** argv) -{ - if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - - u_int32_t verbosity = 0 /* MP4_DETAILS_ALL */; - - MP4FileHandle mp4File = MP4Create(argv[1], verbosity); - - if (!mp4File) { - exit(1); - } - - MP4TrackId urlTrackId = -#if 0 - MP4AddTrack(mp4File, "URLF"); -#else - MP4AddHrefTrack(mp4File, 90000, MP4_INVALID_DURATION); -#endif - printf("urlTrackId %d\n", urlTrackId); - - u_int8_t i; - char url[128]; - - for (i = 1; i <= 5; i++) { - sprintf(url, "http://server.com/foo/bar%u.html", i); - - MP4WriteSample(mp4File, urlTrackId, - (u_int8_t*)url, strlen(url) + 1, (MP4Duration)i); - } - - MP4Close(mp4File); - - mp4File = MP4Read(argv[1], verbosity); - - // check that we can find the track again -#if 0 - urlTrackId = MP4FindTrackId(mp4File, 0, "URLF"); -#else - urlTrackId = MP4FindTrackId(mp4File, 0, MP4_CNTL_TRACK_TYPE); -#endif - printf("urlTrackId %d\n", urlTrackId); - - for (i = 1; i <= 5; i++) { - u_int8_t* pSample = NULL; - u_int32_t sampleSize = 0; - MP4Duration duration; - bool rc; - - rc = MP4ReadSample(mp4File, urlTrackId, i, - &pSample, &sampleSize, NULL, &duration); - - if (rc) { - printf("Sample %i duration "D64": %s\n", - i, duration, pSample); - free(pSample); - } else { - printf("Couldn't read sample %i\n", i); - } - } - - MP4Close(mp4File); - - exit(0); -} - diff --git a/test/c_api.c b/test/c_api.c new file mode 100644 index 0000000..93eae8a --- /dev/null +++ b/test/c_api.c @@ -0,0 +1,59 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. + * + * Contributor(s): + * Dave Mackie dmackie@cisco.com + */ + +#include +#include +#include + +int main(int argc, char** argv) +{ +#if 0 + MP4FileHandle mp4File = MP4Read(argv[1]); + if (!mp4File) + return 1; + + MP4Dump(mp4File, 0); + MP4Close(mp4File, 0); + + return 0; +#else + MP4FileHandle mp4File = MP4Read(argv[1]); + MP4LogSetLevel(MP4_LOG_VERBOSE4); + if (MP4HaveAtom(mp4File, "moov.mvhd")) { + printf("found moov.mvhd\n"); + } + if (MP4HaveTrackAtom(mp4File, 1, argv[2])) { + printf("found %s\n", argv[2]); + } else { + printf("didn't find it\n"); + } + +#if 0 + uint8_t* data = (uint8_t*)"this is my tag data"; + uint32_t len = strlen((char*)data); + MP4SetMetadataFreeForm(mp4File, "mytag1", data, len); + MP4SetMetadataFreeForm(mp4File, "my_tag2", data, len); +#endif + MP4Close(mp4File, 0); + return 0; +#endif +} + diff --git a/test/mp4clip.cpp b/test/mp4clip.cpp new file mode 100644 index 0000000..fc7ba93 --- /dev/null +++ b/test/mp4clip.cpp @@ -0,0 +1,235 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001-2002. All Rights Reserved. + * + * Contributor(s): + * Dave Mackie dmackie@cisco.com + */ + +// N.B. mp4clips clips tracks in an mp4 file +// without regard to sync samples aka "key frames" +// as a testing app the burden is on the user to choose +// an appropriate clip start time + +#include "util/impl.h" + +using namespace mp4v2::util; + +char* ProgName; + +// forward declaration +void ClipTrack( + MP4FileHandle srcFile, + MP4TrackId trackId, + MP4FileHandle dstFile, + float startTime, + float duration); + + +int main(int argc, char** argv) +{ + const char* usageString = "usage: %s [-t ] [-v []] [-s ] -l \n"; + char* srcFileName = NULL; + char* dstFileName = NULL; + MP4TrackId trackId = MP4_INVALID_TRACK_ID; + MP4LogLevel verbosity = MP4_LOG_ERROR; + float startTime = 0.0; + float duration = 0.0; + + /* begin processing command line */ + ProgName = argv[0]; + while (true) { + int c = -1; + int option_index = 0; + static const prog::Option long_options[] = { + { "length", prog::Option::REQUIRED_ARG, 0, 'l' }, + { "start", prog::Option::REQUIRED_ARG, 0, 's' }, + { "track", prog::Option::REQUIRED_ARG, 0, 't' }, + { "verbose", prog::Option::OPTIONAL_ARG, 0, 'v' }, + { "version", prog::Option::NO_ARG, 0, 'V' }, + { NULL, prog::Option::NO_ARG, 0, 0 } + }; + + c = prog::getOptionSingle( argc, argv, "l:s:t:v::V", long_options, &option_index ); + + if (c == -1) + break; + + switch (c) { + case 'l': + if (sscanf(prog::optarg, "%f", &duration) != 1) { + fprintf(stderr, + "%s: bad length specified: %s\n", + ProgName, optarg); + } + break; + case 's': + if (sscanf(prog::optarg, "%f", &startTime) != 1) { + fprintf(stderr, + "%s: bad start time specified: %s\n", + ProgName, optarg); + } + break; + case 't': + if (sscanf(prog::optarg, "%u", &trackId) != 1) { + fprintf(stderr, + "%s: bad track-id specified: %s\n", + ProgName, optarg); + return 1; + } + break; + case 'v': + verbosity = MP4_LOG_VERBOSE1; + if (prog::optarg) { + uint32_t level; + if (sscanf(prog::optarg, "%u", &level) == 1) { + if (level >= 2) { + verbosity = MP4_LOG_VERBOSE2; + } + if (level >= 3) { + verbosity = MP4_LOG_VERBOSE3; + } + if (level >= 4) { + verbosity = MP4_LOG_VERBOSE4; + } + } + } + break; + case '?': + fprintf(stderr, usageString, ProgName); + return 0; + case 'V': + fprintf(stderr, "%s - %s version %s\n", + ProgName, MP4V2_PROJECT_name, MP4V2_PROJECT_version); + return 0; + default: + fprintf(stderr, "%s: unknown option specified, ignoring: %c\n", + ProgName, c); + } + } + + /* check that we have at least one non-option argument */ + if ((argc - prog::optind) < 1) { + fprintf(stderr, usageString, ProgName); + return 1; + } + + MP4LogSetLevel(verbosity); + if (verbosity > MP4_LOG_INFO) { + fprintf(stderr, "%s version %s\n", ProgName, MP4V2_PROJECT_version); + } + + /* point to the specified file name */ + srcFileName = argv[prog::optind++]; + + /* get dest file name */ + if ((argc - optind) > 0) { + dstFileName = argv[prog::optind++]; + } + + /* warn about extraneous non-option arguments */ + if (optind < argc) { + fprintf(stderr, "%s: unknown options specified, ignoring: ", ProgName); + while (prog::optind < argc) { + fprintf(stderr, "%s ", argv[prog::optind++]); + } + fprintf(stderr, "\n"); + } + + if (duration == 0.0) { + fprintf(stderr, + "%s: please specify clip length with -l option\n", + ProgName); + } + + /* end processing of command line */ + + MP4FileHandle srcFile = MP4Modify(srcFileName); + if (!srcFile) + return 1; + + MP4FileHandle dstFile = MP4_INVALID_FILE_HANDLE; + if (dstFileName) + dstFile = MP4Create(dstFileName); + + if (trackId == MP4_INVALID_TRACK_ID) { + uint32_t numTracks = MP4GetNumberOfTracks(srcFile); + + for (uint32_t i = 0; i < numTracks; i++) { + trackId = MP4FindTrackId(srcFile, i); + ClipTrack(srcFile, trackId, dstFile, startTime, duration); + } + } else { + ClipTrack(srcFile, trackId, dstFile, startTime, duration); + } + + MP4Close(srcFile); + if (dstFile != MP4_INVALID_FILE_HANDLE) + MP4Close(dstFile); + + return(0); +} + +void ClipTrack( + MP4FileHandle srcFile, + MP4TrackId trackId, + MP4FileHandle dstFile, + float startTime, + float duration) +{ + MP4Timestamp trackStartTime = + MP4ConvertToTrackTimestamp( + srcFile, + trackId, + (uint64_t)(startTime * 1000), + MP4_MSECS_TIME_SCALE); + + MP4Duration trackDuration = + MP4ConvertToTrackDuration( + srcFile, + trackId, + (uint64_t)(duration * 1000), + MP4_MSECS_TIME_SCALE); + + MP4EditId editId = + MP4AddTrackEdit( + srcFile, + trackId, + 1, + trackStartTime, + trackDuration); + + if (editId == MP4_INVALID_EDIT_ID) { + fprintf(stderr, + "%s: can't create track edit\n", + ProgName); + return; + } + + if (dstFile) { + MP4CopyTrack( + srcFile, + trackId, + dstFile, + true); + + MP4DeleteTrackEdit( + srcFile, + trackId, + editId); + } +} + diff --git a/test/nullcreate.cpp b/test/nullcreate.cpp new file mode 100644 index 0000000..ce3afd9 --- /dev/null +++ b/test/nullcreate.cpp @@ -0,0 +1,185 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. + * + * Contributor(s): + * Dave Mackie dmackie@cisco.com + */ + +#include +#include +#include +#include +#include + +static bool convertBase64 (const char data, uint8_t *value) +{ + static const uint8_t decodingarr64[128] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, + }; + uint8_t index = (uint8_t)data; + if ((index & 0x80) != 0) return false; + + if (decodingarr64[index] == 0xff) return false; + *value = decodingarr64[index]; + return true; +} + +uint8_t *Base64ToBinary (const char *pData, uint32_t decodeSize, uint32_t *pDataSize) +{ + uint8_t *ret; + uint32_t size, ix, groups; + if (pData == NULL || decodeSize == 0 || pDataSize == NULL) + return NULL; + + if ((decodeSize % 4) != 0) { + // must be multiples of 4 characters + return NULL; + } + size = (decodeSize * 3) / 4; + groups = decodeSize / 4; + ret = (uint8_t *)calloc(1, size); + if (ret == NULL) return NULL; + for (ix = 0; ix < groups; ix++) { + uint8_t value[4]; + for (uint8_t jx = 0; jx < 4; jx++) { + if (pData[jx] == '=') { + if (ix != (groups - 1)) { + free(ret); + return NULL; + } + size--; + value[jx] = 0; + } else if (convertBase64(pData[jx], &value[jx]) == false) { + free(ret); + return NULL; + } + } + ret[(ix * 3)] = value[0] << 2 | ((value[1] >> 4) & 0x3); + ret[(ix * 3) + 1] = (value[1] << 4) | (value[2] >> 2 & 0xf); + ret[(ix * 3) + 2] = ((value[2] & 0x3) << 6) | value[3]; + pData += 4; + } + *pDataSize = size; + return ret; +} + +main(int argc, char** argv) +{ +#if 1 + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + MP4LogSetLevel(MP4_LOG_VERBOSE4); + MP4FileHandle mp4File = MP4Create(argv[1]); + if (!mp4File) + return 1; + + printf("Created skeleton\n"); + MP4Dump(mp4File); + + MP4SetODProfileLevel(mp4File, 1); + MP4SetSceneProfileLevel(mp4File, 1); + MP4SetVideoProfileLevel(mp4File, 1); + MP4SetAudioProfileLevel(mp4File, 1); + MP4SetGraphicsProfileLevel(mp4File, 1); + + MP4TrackId odTrackId = + MP4AddODTrack(mp4File); + + MP4TrackId bifsTrackId = + MP4AddSceneTrack(mp4File); + + MP4TrackId videoTrackId = +#if 0 + MP4AddVideoTrack(mp4File, 90000, 3000, 320, 240); +#else + MP4AddH264VideoTrack(mp4File, 90000, 3000, 320, 240, + 1, 2, 3, 1); + static uint8_t pseq[] = { 0, 1, 2, 3, 4, 5, 6,7, 8, 9 }; + + MP4AddH264SequenceParameterSet(mp4File, videoTrackId, pseq, 10); + MP4AddH264SequenceParameterSet(mp4File, videoTrackId, pseq, 6); + MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 7); + MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 8); + MP4AddH264PictureParameterSet(mp4File, videoTrackId, pseq, 7); + +#endif + + MP4TrackId videoHintTrackId = + MP4AddHintTrack(mp4File, videoTrackId); + + MP4TrackId audioTrackId = + MP4AddAudioTrack(mp4File, 44100, 1152); + + MP4TrackId audioHintTrackId = + MP4AddHintTrack(mp4File, audioTrackId); + + printf("Added tracks\n"); + MP4Dump(mp4File); + + MP4Close(mp4File); + + // MP4MakeIsmaCompliant(argv[1], verbosity); + + return 0; +#else + uint8_t *bin = NULL; + + for (uint32_t ix = 4; ix < 1024; ix++) { + printf("pass %d\n", ix); + bin = (uint8_t *)malloc(ix); + for (uint32_t jx = 0; jx < ix; jx++) { + bin[jx] = ((uint32_t)rand()) & 0xFF; + } + char *test; + test = MP4BinaryToBase64(bin, ix); + uint8_t *ret; + uint32_t retsize; + ret = Base64ToBinary(test, strlen(test), &retsize); + if (retsize != ix) { + printf("return size not same %d %d\n", ix, retsize); + return 0; + } + if (memcmp(ret, bin, ix) != 0) { + printf("memory not same\n"); + return 0; + } + free(test); + free(ret); + free(bin); + } + return 0; +#endif +} + diff --git a/test/nullvplayer.cpp b/test/nullvplayer.cpp new file mode 100644 index 0000000..1ba5d99 --- /dev/null +++ b/test/nullvplayer.cpp @@ -0,0 +1,116 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. + * + * Contributor(s): + * Dave Mackie dmackie@cisco.com + */ + +#include +#include + +main(int argc, char** argv) +{ + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + MP4LogSetLevel(MP4_LOG_VERBOSE4); + + char* fileName = argv[1]; + + // open the mp4 file, and read meta-info + MP4FileHandle mp4File = MP4Read(fileName); + + uint8_t profileLevel = MP4GetVideoProfileLevel(mp4File); + + // get a handle on the first video track + MP4TrackId trackId = MP4FindTrackId(mp4File, 0, "video"); + + // gather the crucial track information + + uint32_t timeScale = MP4GetTrackTimeScale(mp4File, trackId); + + // note all times and durations + // are in units of the track time scale + + MP4Duration trackDuration = MP4GetTrackDuration(mp4File, trackId); + + MP4SampleId numSamples = MP4GetTrackNumberOfSamples(mp4File, trackId); + + uint32_t maxSampleSize = MP4GetTrackMaxSampleSize(mp4File, trackId); + + uint8_t* pConfig; + uint32_t configSize = 0; + + MP4GetTrackESConfiguration(mp4File, trackId, &pConfig, &configSize); + + // initialize decoder with Elementary Stream (ES) configuration + + // done with our copy of ES configuration + MP4Free(pConfig); + + // now consecutively read and display the track samples + + uint8_t* pSample = (uint8_t*)malloc(maxSampleSize); + uint32_t sampleSize; + MP4Timestamp sampleTime; + MP4Duration sampleDuration; + MP4Duration sampleRenderingOffset; + bool isSyncSample; + + for (MP4SampleId sampleId = 1; sampleId <= numSamples; sampleId++) { + + // give ReadSample our own buffer, and let it know how big it is + sampleSize = maxSampleSize; + + // read next sample from video track + MP4ReadSample(mp4File, trackId, sampleId, + &pSample, &sampleSize, + &sampleTime, &sampleDuration, &sampleRenderingOffset, + &isSyncSample); + + // convert timestamp and duration from track time to milliseconds + uint64_t myTime = MP4ConvertFromTrackTimestamp(mp4File, trackId, + sampleTime, MP4_MSECS_TIME_SCALE); + + uint64_t myDuration = MP4ConvertFromTrackDuration(mp4File, trackId, + sampleDuration, MP4_MSECS_TIME_SCALE); + + // decode frame and display it + } + + MP4Free(pSample); + + // close mp4 file + MP4Close(mp4File); + + // Note to seek to time 'when' in the track + // use MP4GetSampleIdFromTime(MP4FileHandle hFile, + // MP4Timestamp when, bool wantSyncSample) + // 'wantSyncSample' determines if a sync sample is desired or not + // e.g. + // MP4Timestamp when = + // MP4ConvertToTrackTimestamp(mp4File, trackId, 30, MP4_SECS_TIME_SCALE); + // MP4SampleId newSampleId = MP4GetSampleIdFromTime(mp4File, when, true); + // MP4ReadSample(mp4File, trackId, newSampleId, ...); + // + // Note that start time for sample may be later than 'when' + + return 0; +} + diff --git a/test/urltrack.cpp b/test/urltrack.cpp new file mode 100644 index 0000000..129fcd3 --- /dev/null +++ b/test/urltrack.cpp @@ -0,0 +1,90 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is MPEG4IP. + * + * The Initial Developer of the Original Code is Cisco Systems Inc. + * Portions created by Cisco Systems Inc. are + * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved. + * + * Contributor(s): + * Dave Mackie dmackie@cisco.com + */ + +#include +#include +#include + +main(int argc, char** argv) +{ + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + MP4LogSetLevel(MP4_LOG_VERBOSE4); + MP4FileHandle mp4File = MP4Create(argv[1]); + if (!mp4File) + return 1; + + MP4TrackId urlTrackId = +#if 0 + MP4AddTrack(mp4File, "URLF"); +#else + MP4AddHrefTrack(mp4File, 90000, MP4_INVALID_DURATION); +#endif + printf("urlTrackId %d\n", urlTrackId); + + uint8_t i; + char url[128]; + + for (i = 1; i <= 5; i++) { + sprintf(url, "http://server.com/foo/bar%u.html", i); + + MP4WriteSample(mp4File, urlTrackId, + (uint8_t*)url, strlen(url) + 1, (MP4Duration)i); + } + + MP4Close(mp4File); + + mp4File = MP4Read(argv[1]); + + // check that we can find the track again +#if 0 + urlTrackId = MP4FindTrackId(mp4File, 0, "URLF"); +#else + urlTrackId = MP4FindTrackId(mp4File, 0, MP4_CNTL_TRACK_TYPE); +#endif + printf("urlTrackId %d\n", urlTrackId); + + for (i = 1; i <= 5; i++) { + uint8_t* pSample = NULL; + uint32_t sampleSize = 0; + MP4Duration duration; + bool rc; + + rc = MP4ReadSample(mp4File, urlTrackId, i, + &pSample, &sampleSize, NULL, &duration); + + if (rc) { + printf("Sample %i duration %llu: %s\n", + i, duration, pSample); + MP4Free(pSample); + } else { + printf("Couldn't read sample %i\n", i); + } + } + + MP4Close(mp4File); + + return 0; +} +