From 290c74beffab6e025e205c9601b63693f4f18724 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 20 Nov 2014 05:22:07 +0900 Subject: [PATCH] importer: Add fake movie maker. --- core/box.h | 3 ++ core/file.c | 17 ++-------- core/isom.c | 92 ++++++++++++++++++++++++++++++++++------------------- importer/importer.c | 40 +++++++++++++++++++++++ importer/importer.h | 17 ++++++++++ 5 files changed, 122 insertions(+), 47 deletions(-) diff --git a/core/box.h b/core/box.h index 0a25ae4..499ce8a 100644 --- a/core/box.h +++ b/core/box.h @@ -2494,6 +2494,9 @@ isom_sbgp_t *isom_get_roll_recovery_sample_to_group( lsmash_entry_list_t *list ) isom_sgpd_t *isom_get_fragment_sample_group_description( isom_traf_t *traf, uint32_t grouping_type ); isom_sbgp_t *isom_get_fragment_sample_to_group( isom_traf_t *traf, uint32_t grouping_type ); +isom_trak_t *isom_track_create( lsmash_file_t *file, lsmash_media_type media_type ); +isom_moov_t *isom_movie_create( lsmash_file_t *file ); + isom_dcr_ps_entry_t *isom_create_ps_entry( uint8_t *ps, uint32_t ps_size ); void isom_remove_dcr_ps( isom_dcr_ps_entry_t *ps ); diff --git a/core/file.c b/core/file.c index 80568cd..219d6fe 100644 --- a/core/file.c +++ b/core/file.c @@ -547,21 +547,8 @@ lsmash_file_t *lsmash_set_file param->brands, param->brand_count ) < 0 ) goto fail; /* Create the movie header if the initialization of the streams is required. */ - if( file->flags & LSMASH_FILE_MODE_INITIALIZATION ) - { - if( !isom_add_moov( file ) - || !isom_add_mvhd( file->moov ) ) - goto fail; - /* Default Movie Header Box. */ - isom_mvhd_t *mvhd = file->moov->mvhd; - mvhd->rate = 0x00010000; - mvhd->volume = 0x0100; - mvhd->matrix[0] = 0x00010000; - mvhd->matrix[4] = 0x00010000; - mvhd->matrix[8] = 0x40000000; - mvhd->next_track_ID = 1; - file->initializer = file; - } + if( (file->flags & LSMASH_FILE_MODE_INITIALIZATION) && !isom_movie_create( file ) ) + goto fail; } if( !root->file ) root->file = file; diff --git a/core/isom.c b/core/isom.c index 1945692..8574603 100644 --- a/core/isom.c +++ b/core/isom.c @@ -1528,40 +1528,12 @@ int isom_setup_handler_reference( isom_hdlr_t *hdlr, uint32_t media_type ) return 0; } -/******************************* - public interfaces -*******************************/ - -/*---- track manipulators ----*/ - -void lsmash_delete_track( lsmash_root_t *root, uint32_t track_ID ) -{ - if( isom_check_initializer_present( root ) < 0 - || !root->file->initializer->moov ) - return; - for( lsmash_entry_t *entry = root->file->initializer->moov->trak_list.head; entry; entry = entry->next ) - { - isom_trak_t *trak = (isom_trak_t *)entry->data; - if( !trak - || !trak->tkhd ) - return; - if( trak->tkhd->track_ID == track_ID ) - { - isom_remove_box_by_itself( trak ); - return; - } - } -} - -uint32_t lsmash_create_track( lsmash_root_t *root, lsmash_media_type media_type ) +isom_trak_t *isom_track_create( lsmash_file_t *file, lsmash_media_type media_type ) { - if( isom_check_initializer_present( root ) < 0 ) - return 0; - lsmash_file_t *file = root->file; /* Don't allow to create a new track if the initial movie is already written. */ if( (file->fragment && file->fragment->movie) || (file->moov && (file->moov->manager & LSMASH_WRITTEN_BOX)) ) - return 0; + return NULL; isom_trak_t *trak = isom_add_trak( file->moov ); if( !trak || !trak->file @@ -1641,10 +1613,66 @@ uint32_t lsmash_create_track( lsmash_root_t *root, lsmash_media_type media_type tkhd->track_ID = trak->file->moov->mvhd->next_track_ID ++; } trak->mdia->mdhd->language = file->qt_compatible ? 0 : ISOM_LANGUAGE_CODE_UNDEFINED; - return trak->tkhd->track_ID; + return trak; fail: isom_remove_box_by_itself( trak ); - return 0; + return NULL; +} + +isom_moov_t *isom_movie_create( lsmash_file_t *file ) +{ + isom_moov_t *moov = isom_add_moov( file ); + isom_mvhd_t *mvhd = isom_add_mvhd( moov ); + if( !mvhd ) + { + isom_remove_box_by_itself( moov ); + return NULL; + } + /* Default Movie Header Box. */ + mvhd->rate = 0x00010000; + mvhd->volume = 0x0100; + mvhd->matrix[0] = 0x00010000; + mvhd->matrix[4] = 0x00010000; + mvhd->matrix[8] = 0x40000000; + mvhd->next_track_ID = 1; + file->initializer = file; + return moov; +} + +/******************************* + public interfaces +*******************************/ + +/*---- track manipulators ----*/ + +void lsmash_delete_track( lsmash_root_t *root, uint32_t track_ID ) +{ + if( isom_check_initializer_present( root ) < 0 + || !root->file->initializer->moov ) + return; + for( lsmash_entry_t *entry = root->file->initializer->moov->trak_list.head; entry; entry = entry->next ) + { + isom_trak_t *trak = (isom_trak_t *)entry->data; + if( !trak + || !trak->tkhd ) + return; + if( trak->tkhd->track_ID == track_ID ) + { + isom_remove_box_by_itself( trak ); + return; + } + } +} + +uint32_t lsmash_create_track( lsmash_root_t *root, lsmash_media_type media_type ) +{ + if( isom_check_initializer_present( root ) < 0 ) + return 0; + isom_trak_t *trak = isom_track_create( root->file, media_type ); + if( !trak + || !trak->tkhd ) + return 0; + return trak->tkhd->track_ID; } uint32_t lsmash_get_track_ID( lsmash_root_t *root, uint32_t track_number ) diff --git a/importer/importer.c b/importer/importer.c index 3999dbb..8f2fac8 100644 --- a/importer/importer.c +++ b/importer/importer.c @@ -286,3 +286,43 @@ lsmash_summary_t *lsmash_duplicate_summary( importer_t *importer, uint32_t track } return summary; } + +int lsmash_importer_make_fake_movie( importer_t *importer ) +{ + if( !importer || !importer->file || (importer->file->flags & LSMASH_FILE_MODE_BOX) ) + return LSMASH_ERR_FUNCTION_PARAM; + if( !isom_movie_create( importer->file ) ) + return LSMASH_ERR_NAMELESS; + return 0; +} + +int lsmash_importer_make_fake_track( importer_t *importer, lsmash_media_type media_type, uint32_t *track_ID ) +{ + if( !importer || !importer->file || (importer->file->flags & LSMASH_FILE_MODE_BOX) || !track_ID ) + return LSMASH_ERR_FUNCTION_PARAM; + isom_trak_t *trak = isom_track_create( importer->file, media_type ); + int err; + if( !trak + || !trak->tkhd + || trak->tkhd->track_ID == 0 + || !trak->mdia + || !trak->mdia->minf ) + { + err = LSMASH_ERR_NAMELESS; + goto fail; + } + if( (err = isom_complement_data_reference( trak->mdia->minf )) < 0 ) + goto fail; + *track_ID = trak->tkhd->track_ID; + return 0; +fail: + isom_remove_box_by_itself( trak ); + return err; +} + +void lsmash_importer_break_fake_movie( importer_t *importer ) +{ + if( !importer || !importer->file ) + return; + isom_remove_box_by_itself( importer->file->moov ); +} diff --git a/importer/importer.h b/importer/importer.h index f5461bd..0a02c87 100644 --- a/importer/importer.h +++ b/importer/importer.h @@ -74,6 +74,23 @@ struct importer_tag lsmash_entry_list_t *summaries; }; +int lsmash_importer_make_fake_movie +( + importer_t *importer +); + +int lsmash_importer_make_fake_track +( + importer_t *importer, + lsmash_media_type media_type, + uint32_t *track_ID +); + +void lsmash_importer_break_fake_movie +( + importer_t *importer +); + #else int lsmash_importer_set_file -- 2.11.4.GIT