From 4b46719bfb7ef7bfad4f3b2ffd2cef8ae6e1128a Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Tue, 7 Mar 2017 04:26:54 +0900 Subject: [PATCH] list: Decide the entry eliminator of list at its initialization. --- codecs/a52.c | 2 +- codecs/alac.c | 2 +- codecs/description.c | 28 ++++---- codecs/dts.c | 2 +- codecs/h264.c | 78 ++++++++++++--------- codecs/hevc.c | 127 ++++++++++++++++++++--------------- codecs/mp4a.c | 2 +- codecs/mp4sys.c | 25 +++---- codecs/mp4v.c | 2 +- codecs/nalu.c | 6 +- codecs/qt_wfex.c | 2 +- common/list.c | 117 +++++++++++++++++++++++--------- common/list.h | 186 ++++++++++++++++++++++++++++++++------------------- core/box.c | 181 +++++++++++++++++++++++++------------------------ core/box.h | 4 +- core/box_default.c | 14 +++- core/box_default.h | 1 + core/chapter.c | 4 +- core/file.c | 6 +- core/fragment.c | 18 ++--- core/isom.c | 72 ++++++++++---------- core/meta.c | 2 +- core/print.c | 11 ++- core/print.h | 3 +- core/read.c | 125 +++++++++++++++++----------------- core/summary.c | 39 ++++++----- core/timeline.c | 92 ++++++++++++------------- importer/a52_imp.c | 12 ++-- importer/adts_imp.c | 6 +- importer/als_imp.c | 6 +- importer/amr_imp.c | 4 +- importer/dts_imp.c | 8 +-- importer/importer.c | 8 +-- importer/isobm_imp.c | 8 +-- importer/mp3_imp.c | 6 +- importer/nalu_imp.c | 48 ++++++------- importer/vc1_imp.c | 6 +- importer/wave_imp.c | 17 ++--- 38 files changed, 729 insertions(+), 551 deletions(-) rewrite common/list.h (60%) diff --git a/codecs/a52.c b/codecs/a52.c index 7dcc425..3a03f58 100644 --- a/codecs/a52.c +++ b/codecs/a52.c @@ -740,7 +740,7 @@ int eac3_print_codec_specific( FILE *fp, lsmash_file_t *file, isom_box_t *box, i int eac3_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_audio_entry_t *eac3 = (isom_audio_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_audio_entry_t *eac3 = (isom_audio_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( eac3 ) ) return LSMASH_ERR_INVALID_DATA; isom_box_t *ext = isom_get_extension_box( &eac3->extensions, ISOM_BOX_TYPE_DEC3 ); diff --git a/codecs/alac.c b/codecs/alac.c index ba86601..7aa95c8 100644 --- a/codecs/alac.c +++ b/codecs/alac.c @@ -109,7 +109,7 @@ int alac_print_codec_specific( FILE *fp, lsmash_file_t *file, isom_box_t *box, i int alac_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_audio_entry_t *alac = (isom_audio_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_audio_entry_t *alac = (isom_audio_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( alac ) ) return LSMASH_ERR_INVALID_DATA; uint8_t *exdata = NULL; diff --git a/codecs/description.c b/codecs/description.c index 750c979..94ed75d 100644 --- a/codecs/description.c +++ b/codecs/description.c @@ -577,7 +577,7 @@ static int codec_construct_qt_audio_decompression_info( lsmash_codec_specific_t isom_remove_box_by_itself( box ); return LSMASH_ERR_MEMORY_ALLOC; } - if( lsmash_add_entry( &wave->extensions, box ) < 0 ) + if( lsmash_list_add_entry( &wave->extensions, box ) < 0 ) { isom_remove_unknown_box( box ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1304,7 +1304,7 @@ static int isom_set_qtff_mp4a_description( isom_audio_entry_t *audio, lsmash_aud || (mp4a = isom_add_mp4a( wave ), LSMASH_IS_NON_EXISTING_BOX( mp4a )) || (terminator = isom_add_terminator( wave ), LSMASH_IS_NON_EXISTING_BOX( terminator )) ) { - lsmash_remove_entry_tail( &audio->extensions, wave->destruct ); + lsmash_list_remove_entry_tail( &audio->extensions ); return LSMASH_ERR_NAMELESS; } frma->data_format = audio->type.fourcc; @@ -1489,7 +1489,7 @@ static int isom_set_qtff_lpcm_description( isom_audio_entry_t *audio, lsmash_aud || (enda = isom_add_enda( wave ), LSMASH_IS_NON_EXISTING_BOX( enda )) || (terminator = isom_add_terminator( wave ), LSMASH_IS_NON_EXISTING_BOX( terminator )) ) { - lsmash_remove_entry_tail( &audio->extensions, wave->destruct ); + lsmash_list_remove_entry_tail( &audio->extensions ); return LSMASH_ERR_NAMELESS; } frma->data_format = sample_type.fourcc; @@ -1740,7 +1740,7 @@ static int isom_set_qtff_sound_decompression_parameters if( LSMASH_IS_BOX_ADDITION_FAILURE( isom_add_frma ( wave ) ) || LSMASH_IS_BOX_ADDITION_FAILURE( isom_add_terminator( wave ) ) ) { - lsmash_remove_entry_tail( &audio->extensions, wave->destruct ); + lsmash_list_remove_entry_tail( &audio->extensions ); return LSMASH_ERR_NAMELESS; } wave->frma->data_format = audio->type.fourcc; @@ -2208,7 +2208,7 @@ static int isom_setup_tx3g_description( isom_stsd_t *stsd, lsmash_summary_t *sum isom_font_record_t *font = lsmash_malloc( sizeof(isom_font_record_t) ); if( !font ) goto fail; - if( lsmash_add_entry( ftab->list, font ) < 0 ) + if( lsmash_list_add_entry( ftab->list, font ) < 0 ) { lsmash_free( font ); goto fail; @@ -2352,7 +2352,7 @@ lsmash_summary_t *isom_create_video_summary_from_description( isom_sample_entry_ dst_ct->array[i].b = src_ct->array[i].b; } } - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2470,7 +2470,7 @@ lsmash_summary_t *isom_create_video_summary_from_description( isom_sample_entry_ } else continue; - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2489,7 +2489,7 @@ lsmash_summary_t *isom_create_video_summary_from_description( isom_sample_entry_ specific->size = box->size; specific->data.unstructured = lsmash_memdup( box->binary, box->size ); if( !specific->data.unstructured - || lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2536,7 +2536,7 @@ static int isom_append_structured_mp4sys_decoder_config( lsmash_codec_specific_l lsmash_destroy_codec_specific_data( specific ); if( !conv ) return LSMASH_ERR_NAMELESS; - if( lsmash_add_entry( &opaque->list, conv ) < 0 ) + if( lsmash_list_add_entry( &opaque->list, conv ) < 0 ) { lsmash_destroy_codec_specific_data( conv ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2587,7 +2587,7 @@ lsmash_summary_t *isom_create_audio_summary_from_description( isom_sample_entry_ common->revision_level = audio->revision_level; common->vendor = audio->vendor; common->compression_ID = audio->compression_ID; - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2635,7 +2635,7 @@ lsmash_summary_t *isom_create_audio_summary_from_description( isom_sample_entry_ else data->format_flags |= QT_LPCM_FORMAT_FLAG_BIG_ENDIAN; } - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2690,7 +2690,7 @@ lsmash_summary_t *isom_create_audio_summary_from_description( isom_sample_entry_ lsmash_qt_audio_channel_layout_t *data = (lsmash_qt_audio_channel_layout_t *)specific->data.structured; data->channelLayoutTag = chan->channelLayoutTag; data->channelBitmap = chan->channelBitmap; - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -2809,7 +2809,7 @@ lsmash_summary_t *isom_create_audio_summary_from_description( isom_sample_entry_ } specific->data.unstructured = box_data; specific->size = box_size; - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); lsmash_bs_cleanup( bs ); @@ -2832,7 +2832,7 @@ lsmash_summary_t *isom_create_audio_summary_from_description( isom_sample_entry_ specific->size = box->size; specific->data.unstructured = lsmash_memdup( box->binary, box->size ); if( !specific->data.unstructured - || lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; diff --git a/codecs/dts.c b/codecs/dts.c index 45f11ad..f0f8e02 100644 --- a/codecs/dts.c +++ b/codecs/dts.c @@ -1813,7 +1813,7 @@ int dts_print_codec_specific( FILE *fp, lsmash_file_t *file, isom_box_t *box, in int dts_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_audio_entry_t *dts_audio = (isom_audio_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_audio_entry_t *dts_audio = (isom_audio_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( dts_audio ) ) return LSMASH_ERR_INVALID_DATA; isom_box_t *ext = isom_get_extension_box( &dts_audio->extensions, ISOM_BOX_TYPE_DDTS ); diff --git a/codecs/h264.c b/codecs/h264.c index 6bae08e..183313a 100644 --- a/codecs/h264.c +++ b/codecs/h264.c @@ -48,18 +48,36 @@ typedef enum H264_SLICE_TYPE_SI = 4 } h264_slice_type; -void lsmash_destroy_h264_parameter_sets +static lsmash_h264_parameter_sets_t *h264_allocate_parameter_sets( void ) +{ + lsmash_h264_parameter_sets_t *parameter_sets = lsmash_malloc_zero( sizeof(lsmash_h264_parameter_sets_t) ); + if( !parameter_sets ) + return NULL; + lsmash_list_init( parameter_sets->sps_list, isom_remove_dcr_ps ); + lsmash_list_init( parameter_sets->pps_list, isom_remove_dcr_ps ); + lsmash_list_init( parameter_sets->spsext_list, isom_remove_dcr_ps ); + return parameter_sets; +} + +static void h264_deallocate_parameter_sets ( lsmash_h264_specific_parameters_t *param ) { if( !param || !param->parameter_sets ) return; - lsmash_remove_entries( param->parameter_sets->sps_list, isom_remove_dcr_ps ); - lsmash_remove_entries( param->parameter_sets->pps_list, isom_remove_dcr_ps ); - lsmash_remove_entries( param->parameter_sets->spsext_list, isom_remove_dcr_ps ); - lsmash_free( param->parameter_sets ); - param->parameter_sets = NULL; + lsmash_list_remove_entries( param->parameter_sets->sps_list ); + lsmash_list_remove_entries( param->parameter_sets->pps_list ); + lsmash_list_remove_entries( param->parameter_sets->spsext_list ); + lsmash_freep( ¶m->parameter_sets ); +} + +void lsmash_destroy_h264_parameter_sets +( + lsmash_h264_specific_parameters_t *param +) +{ + h264_deallocate_parameter_sets( param ); } void h264_destruct_specific_data @@ -69,7 +87,7 @@ void h264_destruct_specific_data { if( !data ) return; - lsmash_destroy_h264_parameter_sets( data ); + h264_deallocate_parameter_sets( data ); lsmash_free( data ); } @@ -80,11 +98,11 @@ void h264_cleanup_parser { if( !info ) return; - lsmash_remove_entries( info->sps_list, NULL ); - lsmash_remove_entries( info->pps_list, NULL ); - lsmash_remove_entries( info->slice_list, NULL ); - lsmash_destroy_h264_parameter_sets( &info->avcC_param ); - lsmash_destroy_h264_parameter_sets( &info->avcC_param_next ); + lsmash_list_remove_entries( info->sps_list ); + lsmash_list_remove_entries( info->pps_list ); + lsmash_list_remove_entries( info->slice_list ); + h264_deallocate_parameter_sets( &info->avcC_param ); + h264_deallocate_parameter_sets( &info->avcC_param_next ); lsmash_destroy_multiple_buffers( info->buffer.bank ); lsmash_bits_adhoc_cleanup( info->bits ); info->bits = NULL; @@ -116,9 +134,9 @@ int h264_setup_parser lsmash_destroy_multiple_buffers( sb->bank ); return LSMASH_ERR_MEMORY_ALLOC; } - lsmash_init_entry_list( info->sps_list ); - lsmash_init_entry_list( info->pps_list ); - lsmash_init_entry_list( info->slice_list ); + lsmash_list_init_simple( info->sps_list ); + lsmash_list_init_simple( info->pps_list ); + lsmash_list_init_simple( info->slice_list ); return 0; } @@ -252,7 +270,7 @@ static h264_sps_t *h264_get_sps if( !sps ) return NULL; sps->seq_parameter_set_id = sps_id; - if( lsmash_add_entry( sps_list, sps ) < 0 ) + if( lsmash_list_add_entry( sps_list, sps ) < 0 ) { lsmash_free( sps ); return NULL; @@ -280,7 +298,7 @@ static h264_pps_t *h264_get_pps if( !pps ) return NULL; pps->pic_parameter_set_id = pps_id; - if( lsmash_add_entry( pps_list, pps ) < 0 ) + if( lsmash_list_add_entry( pps_list, pps ) < 0 ) { lsmash_free( pps ); return NULL; @@ -308,7 +326,7 @@ static h264_slice_info_t *h264_get_slice_info if( !slice ) return NULL; slice->slice_id = slice_id; - if( lsmash_add_entry( slice_list, slice ) < 0 ) + if( lsmash_list_add_entry( slice_list, slice ) < 0 ) { lsmash_free( slice ); return NULL; @@ -1987,7 +2005,7 @@ int lsmash_append_h264_parameter_set return LSMASH_ERR_FUNCTION_PARAM; if( !param->parameter_sets ) { - param->parameter_sets = lsmash_malloc_zero( sizeof(lsmash_h264_parameter_sets_t) ); + param->parameter_sets = h264_allocate_parameter_sets(); if( !param->parameter_sets ) return LSMASH_ERR_MEMORY_ALLOC; } @@ -2001,7 +2019,7 @@ int lsmash_append_h264_parameter_set isom_dcr_ps_entry_t *ps = isom_create_ps_entry( ps_data, ps_length ); if( !ps ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ps_list, ps ) < 0 ) + if( lsmash_list_add_entry( ps_list, ps ) < 0 ) { isom_remove_dcr_ps( ps ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2038,7 +2056,7 @@ int lsmash_append_h264_parameter_set ps = isom_create_ps_entry( ps_data, ps_length ); if( !ps ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ps_list, ps ) < 0 ) + if( lsmash_list_add_entry( ps_list, ps ) < 0 ) { isom_remove_dcr_ps( ps ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2063,7 +2081,7 @@ int lsmash_append_h264_parameter_set lsmash_free( rbsp_buffer ); if( err < 0 ) { - lsmash_remove_entry_tail( ps_list, isom_remove_dcr_ps ); + lsmash_list_remove_entry_tail( ps_list ); return err; } if( ps_list->entry_count == 1 ) @@ -2165,7 +2183,7 @@ static inline int h264_move_dcr_nalu_entry if( !dst_entry ) { /* Move the parameter set. */ - if( lsmash_add_entry( dst_ps_list, src_ps ) < 0 ) + if( lsmash_list_add_entry( dst_ps_list, src_ps ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; src_entry->data = NULL; } @@ -2204,7 +2222,7 @@ int h264_move_pending_avcC_param info->avcC_param = info->avcC_param_next; info->avcC_param.parameter_sets = parameter_sets; /* No pending avcC. */ - lsmash_destroy_h264_parameter_sets( &info->avcC_param_next ); + h264_deallocate_parameter_sets( &info->avcC_param_next ); uint8_t lengthSizeMinusOne = info->avcC_param_next.lengthSizeMinusOne; memset( &info->avcC_param_next, 0, sizeof(lsmash_h264_specific_parameters_t) ); info->avcC_param_next.lengthSizeMinusOne = lengthSizeMinusOne; @@ -2372,7 +2390,7 @@ int h264_construct_specific_parameters return LSMASH_ERR_INVALID_DATA; if( !param->parameter_sets ) { - param->parameter_sets = lsmash_malloc_zero( sizeof(lsmash_h264_parameter_sets_t) ); + param->parameter_sets = h264_allocate_parameter_sets(); if( !param->parameter_sets ) return LSMASH_ERR_MEMORY_ALLOC; } @@ -2494,11 +2512,11 @@ int h264_copy_codec_specific assert( dst && dst->format == LSMASH_CODEC_SPECIFIC_FORMAT_STRUCTURED && dst->data.structured ); lsmash_h264_specific_parameters_t *src_data = (lsmash_h264_specific_parameters_t *)src->data.structured; lsmash_h264_specific_parameters_t *dst_data = (lsmash_h264_specific_parameters_t *)dst->data.structured; - lsmash_destroy_h264_parameter_sets( dst_data ); + h264_deallocate_parameter_sets( dst_data ); *dst_data = *src_data; if( !src_data->parameter_sets ) return 0; - dst_data->parameter_sets = lsmash_malloc_zero( sizeof(lsmash_h264_parameter_sets_t) ); + dst_data->parameter_sets = h264_allocate_parameter_sets(); if( !dst_data->parameter_sets ) return LSMASH_ERR_MEMORY_ALLOC; for( int i = 0; i < 3; i++ ) @@ -2514,12 +2532,12 @@ int h264_copy_codec_specific isom_dcr_ps_entry_t *dst_ps = isom_create_ps_entry( src_ps->nalUnit, src_ps->nalUnitLength ); if( !dst_ps ) { - lsmash_destroy_h264_parameter_sets( dst_data ); + h264_deallocate_parameter_sets( dst_data ); return LSMASH_ERR_MEMORY_ALLOC; } - if( lsmash_add_entry( dst_ps_list, dst_ps ) < 0 ) + if( lsmash_list_add_entry( dst_ps_list, dst_ps ) < 0 ) { - lsmash_destroy_h264_parameter_sets( dst_data ); + h264_deallocate_parameter_sets( dst_data ); isom_remove_dcr_ps( dst_ps ); return LSMASH_ERR_MEMORY_ALLOC; } diff --git a/codecs/hevc.c b/codecs/hevc.c index 251b193..78b48a9 100644 --- a/codecs/hevc.c +++ b/codecs/hevc.c @@ -52,7 +52,42 @@ typedef enum HEVC_SLICE_TYPE_I = 2, } hevc_slice_type; -void lsmash_destroy_hevc_parameter_arrays +static lsmash_hevc_parameter_arrays_t *hevc_alloc_parameter_arrays( void ) +{ + lsmash_hevc_parameter_arrays_t *parameter_arrays = lsmash_malloc_zero( sizeof(lsmash_hevc_parameter_arrays_t) ); + if( !parameter_arrays ) + return NULL; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_VPS ].array_completeness = 1; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_VPS ].NAL_unit_type = HEVC_NALU_TYPE_VPS; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SPS ].array_completeness = 1; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SPS ].NAL_unit_type = HEVC_NALU_TYPE_SPS; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PPS ].array_completeness = 1; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PPS ].NAL_unit_type = HEVC_NALU_TYPE_PPS; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PREFIX_SEI].array_completeness = 0; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PREFIX_SEI].NAL_unit_type = HEVC_NALU_TYPE_PREFIX_SEI; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SUFFIX_SEI].array_completeness = 0; + parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SUFFIX_SEI].NAL_unit_type = HEVC_NALU_TYPE_SUFFIX_SEI; + for( int i = 0; i < HEVC_DCR_NALU_TYPE_NUM; i++ ) + lsmash_list_init( parameter_arrays->ps_array[i].list, isom_remove_dcr_ps ); + return parameter_arrays; +} + +static int hevc_alloc_parameter_arrays_if_needed +( + lsmash_hevc_specific_parameters_t *param +) +{ + assert( param ); + if( param->parameter_arrays ) + return 0; + lsmash_hevc_parameter_arrays_t *parameter_arrays = hevc_alloc_parameter_arrays(); + if( !parameter_arrays ) + return LSMASH_ERR_MEMORY_ALLOC; + param->parameter_arrays = parameter_arrays; + return 0; +} + +static void hevc_deallocate_parameter_arrays ( lsmash_hevc_specific_parameters_t *param ) @@ -60,9 +95,16 @@ void lsmash_destroy_hevc_parameter_arrays if( !param || !param->parameter_arrays ) return; for( int i = 0; i < HEVC_DCR_NALU_TYPE_NUM; i++ ) - lsmash_remove_entries( param->parameter_arrays->ps_array[i].list, isom_remove_dcr_ps ); - lsmash_free( param->parameter_arrays ); - param->parameter_arrays = NULL; + lsmash_list_remove_entries( param->parameter_arrays->ps_array[i].list ); + lsmash_freep( ¶m->parameter_arrays ); +} + +void lsmash_destroy_hevc_parameter_arrays +( + lsmash_hevc_specific_parameters_t *param +) +{ + hevc_deallocate_parameter_arrays( param ); } void hevc_destruct_specific_data @@ -72,7 +114,7 @@ void hevc_destruct_specific_data { if( !data ) return; - lsmash_destroy_hevc_parameter_arrays( data ); + hevc_deallocate_parameter_arrays( data ); lsmash_free( data ); } @@ -95,11 +137,11 @@ void hevc_cleanup_parser { if( !info ) return; - lsmash_remove_entries( info->vps_list, NULL ); - lsmash_remove_entries( info->sps_list, NULL ); - lsmash_remove_entries( info->pps_list, hevc_remove_pps ); - lsmash_destroy_hevc_parameter_arrays( &info->hvcC_param ); - lsmash_destroy_hevc_parameter_arrays( &info->hvcC_param_next ); + lsmash_list_remove_entries( info->vps_list ); + lsmash_list_remove_entries( info->sps_list ); + lsmash_list_remove_entries( info->pps_list ); + hevc_deallocate_parameter_arrays( &info->hvcC_param ); + hevc_deallocate_parameter_arrays( &info->hvcC_param_next ); lsmash_destroy_multiple_buffers( info->buffer.bank ); lsmash_bits_adhoc_cleanup( info->bits ); info->bits = NULL; @@ -131,9 +173,9 @@ int hevc_setup_parser lsmash_destroy_multiple_buffers( sb->bank ); return LSMASH_ERR_MEMORY_ALLOC; } - lsmash_init_entry_list( info->vps_list ); - lsmash_init_entry_list( info->sps_list ); - lsmash_init_entry_list( info->pps_list ); + lsmash_list_init_simple( info->vps_list ); + lsmash_list_init_simple( info->sps_list ); + lsmash_list_init( info->pps_list, hevc_remove_pps ); info->prev_nalu_type = HEVC_NALU_TYPE_UNKNOWN; return 0; } @@ -276,7 +318,7 @@ static hevc_vps_t *hevc_get_vps if( !vps ) return NULL; vps->video_parameter_set_id = vps_id; - if( lsmash_add_entry( vps_list, vps ) < 0 ) + if( lsmash_list_add_entry( vps_list, vps ) < 0 ) { lsmash_free( vps ); return NULL; @@ -304,7 +346,7 @@ static hevc_sps_t *hevc_get_sps if( !sps ) return NULL; sps->seq_parameter_set_id = sps_id; - if( lsmash_add_entry( sps_list, sps ) < 0 ) + if( lsmash_list_add_entry( sps_list, sps ) < 0 ) { lsmash_free( sps ); return NULL; @@ -332,7 +374,7 @@ static hevc_pps_t *hevc_get_pps if( !pps ) return NULL; pps->pic_parameter_set_id = pps_id; - if( lsmash_add_entry( pps_list, pps ) < 0 ) + if( lsmash_list_add_entry( pps_list, pps ) < 0 ) { lsmash_free( pps ); return NULL; @@ -2255,31 +2297,6 @@ static inline void hevc_reorder_parameter_set_ascending_id entry->next = new_entry; } -static inline int hevc_alloc_parameter_arrays -( - lsmash_hevc_specific_parameters_t *param -) -{ - assert( param ); - if( param->parameter_arrays ) - return 0; - lsmash_hevc_parameter_arrays_t *parameter_arrays = lsmash_malloc_zero( sizeof(lsmash_hevc_parameter_arrays_t) ); - if( !parameter_arrays ) - return LSMASH_ERR_MEMORY_ALLOC; - param->parameter_arrays = parameter_arrays; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_VPS ].array_completeness = 1; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_VPS ].NAL_unit_type = HEVC_NALU_TYPE_VPS; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SPS ].array_completeness = 1; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SPS ].NAL_unit_type = HEVC_NALU_TYPE_SPS; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PPS ].array_completeness = 1; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PPS ].NAL_unit_type = HEVC_NALU_TYPE_PPS; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PREFIX_SEI].array_completeness = 0; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_PREFIX_SEI].NAL_unit_type = HEVC_NALU_TYPE_PREFIX_SEI; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SUFFIX_SEI].array_completeness = 0; - parameter_arrays->ps_array[HEVC_DCR_NALU_TYPE_SUFFIX_SEI].NAL_unit_type = HEVC_NALU_TYPE_SUFFIX_SEI; - return 0; -} - int lsmash_append_hevc_dcr_nalu ( lsmash_hevc_specific_parameters_t *param, @@ -2291,7 +2308,7 @@ int lsmash_append_hevc_dcr_nalu uint8_t *ps_data = _ps_data; if( !param || !ps_data || ps_length < 2 ) return LSMASH_ERR_FUNCTION_PARAM; - int err = hevc_alloc_parameter_arrays( param ); + int err = hevc_alloc_parameter_arrays_if_needed( param ); if( err < 0 ) return err; hevc_parameter_array_t *ps_array = hevc_get_parameter_set_array( param, ps_type ); @@ -2305,7 +2322,7 @@ int lsmash_append_hevc_dcr_nalu isom_dcr_ps_entry_t *ps = isom_create_ps_entry( ps_data, ps_length ); if( !ps ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ps_list, ps ) < 0 ) + if( lsmash_list_add_entry( ps_list, ps ) < 0 ) { isom_remove_dcr_ps( ps ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2346,7 +2363,7 @@ int lsmash_append_hevc_dcr_nalu ps = isom_create_ps_entry( ps_data, ps_length ); if( !ps ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ps_list, ps ) < 0 ) + if( lsmash_list_add_entry( ps_list, ps ) < 0 ) { isom_remove_dcr_ps( ps ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2521,7 +2538,7 @@ int lsmash_append_hevc_dcr_nalu err = 0; goto clean; fail: - ps = (isom_dcr_ps_entry_t *)lsmash_get_entry_data( ps_list, ps_list->entry_count ); + ps = (isom_dcr_ps_entry_t *)lsmash_list_get_entry_data( ps_list, ps_list->entry_count ); if( ps ) ps->unused = 1; clean: @@ -2628,7 +2645,7 @@ static int hevc_move_dcr_nalu_entry if( !dst_entry ) { /* Move the parameter set. */ - if( lsmash_add_entry( dst_ps_list, src_ps ) < 0 ) + if( lsmash_list_add_entry( dst_ps_list, src_ps ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; src_entry->data = NULL; } @@ -2670,7 +2687,7 @@ int hevc_move_pending_hvcC_param info->hvcC_param = info->hvcC_param_next; info->hvcC_param.parameter_arrays = parameter_arrays; /* No pending hvcC. */ - lsmash_destroy_hevc_parameter_arrays( &info->hvcC_param_next ); + hevc_deallocate_parameter_arrays( &info->hvcC_param_next ); uint8_t lengthSizeMinusOne = info->hvcC_param_next.lengthSizeMinusOne; memset( &info->hvcC_param_next, 0, sizeof(lsmash_hevc_specific_parameters_t) ); info->hvcC_param_next.lengthSizeMinusOne = lengthSizeMinusOne; @@ -2685,7 +2702,7 @@ int lsmash_set_hevc_array_completeness int array_completeness ) { - if( hevc_alloc_parameter_arrays( param ) < 0 ) + if( hevc_alloc_parameter_arrays_if_needed( param ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; hevc_parameter_array_t *ps_array = hevc_get_parameter_set_array( param, ps_type ); if( !ps_array ) @@ -2701,7 +2718,7 @@ int lsmash_get_hevc_array_completeness int *array_completeness ) { - if( hevc_alloc_parameter_arrays( param ) < 0 ) + if( hevc_alloc_parameter_arrays_if_needed( param ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; hevc_parameter_array_t *ps_array = hevc_get_parameter_set_array( param, ps_type ); if( !ps_array ) @@ -2868,7 +2885,7 @@ int hevc_construct_specific_parameters } if( size != src->size ) return LSMASH_ERR_INVALID_DATA; - if( hevc_alloc_parameter_arrays( param ) < 0 ) + if( hevc_alloc_parameter_arrays_if_needed( param ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = lsmash_bs_create(); if( !bs ) @@ -3071,12 +3088,12 @@ static inline int hevc_copy_dcr_nalu_array isom_dcr_ps_entry_t *dst_ps = isom_create_ps_entry( src_ps->nalUnit, src_ps->nalUnitLength ); if( !dst_ps ) { - lsmash_destroy_hevc_parameter_arrays( dst_data ); + hevc_deallocate_parameter_arrays( dst_data ); return LSMASH_ERR_MEMORY_ALLOC; } - if( lsmash_add_entry( dst_ps_list, dst_ps ) < 0 ) + if( lsmash_list_add_entry( dst_ps_list, dst_ps ) < 0 ) { - lsmash_destroy_hevc_parameter_arrays( dst_data ); + hevc_deallocate_parameter_arrays( dst_data ); isom_remove_dcr_ps( dst_ps ); return LSMASH_ERR_MEMORY_ALLOC; } @@ -3094,11 +3111,11 @@ int hevc_copy_codec_specific assert( dst && dst->format == LSMASH_CODEC_SPECIFIC_FORMAT_STRUCTURED && dst->data.structured ); lsmash_hevc_specific_parameters_t *src_data = (lsmash_hevc_specific_parameters_t *)src->data.structured; lsmash_hevc_specific_parameters_t *dst_data = (lsmash_hevc_specific_parameters_t *)dst->data.structured; - lsmash_destroy_hevc_parameter_arrays( dst_data ); + hevc_deallocate_parameter_arrays( dst_data ); *dst_data = *src_data; if( !src_data->parameter_arrays ) return 0; - dst_data->parameter_arrays = lsmash_malloc_zero( sizeof(lsmash_hevc_parameter_arrays_t) ); + dst_data->parameter_arrays = hevc_alloc_parameter_arrays(); if( !dst_data->parameter_arrays ) return LSMASH_ERR_MEMORY_ALLOC; for( int i = 0; i < HEVC_DCR_NALU_TYPE_NUM; i++ ) diff --git a/codecs/mp4a.c b/codecs/mp4a.c index 427d9c4..cb6c1d8 100644 --- a/codecs/mp4a.c +++ b/codecs/mp4a.c @@ -941,7 +941,7 @@ void mp4a_print_AudioSpecificConfig( FILE *fp, uint8_t *dsi_payload, uint32_t ds int mp4a_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_audio_entry_t *mp4a = (isom_audio_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_audio_entry_t *mp4a = (isom_audio_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( mp4a ) ) return LSMASH_ERR_INVALID_DATA; isom_esds_t *esds; diff --git a/codecs/mp4sys.c b/codecs/mp4sys.c index 4ff3464..487960d 100644 --- a/codecs/mp4sys.c +++ b/codecs/mp4sys.c @@ -265,7 +265,7 @@ static void mp4sys_remove_descriptor_in_predefined_list( void *opaque_descriptor * Because of freeing an entry of the list here, don't pass the list to free this descriptor. * Or double free. */ entry->data = NULL; - lsmash_remove_entry_direct( list, entry, NULL ); + lsmash_list_remove_entry_direct( list, entry ); break; } } @@ -286,7 +286,7 @@ static void mp4sys_destruct_descriptor( mp4sys_descriptor_t *descriptor ) static void mp4sys_remove_all_child_descriptors( lsmash_entry_list_t *children ) { - lsmash_remove_entries( children, mp4sys_destruct_descriptor ); + lsmash_list_remove_entries( children ); } /* Remove a descriptor by the pointer containing its address. @@ -306,7 +306,7 @@ void mp4sys_remove_descriptor( void *opaque_descriptor ) { /* Free the corresponding entry here, therefore don't call this function as a callback function * if a function frees the same entry later and calls this function. */ - lsmash_remove_entry_direct( &parent->children, entry, mp4sys_destruct_descriptor ); + lsmash_list_remove_entry_direct( &parent->children, entry ); return; } } @@ -592,6 +592,7 @@ static inline void *mp4sys_construct_descriptor_orig descriptor->parent = parent; descriptor->destruct = destructor; descriptor->write = writer; + lsmash_list_init( &descriptor->children, mp4sys_destruct_descriptor ); return descriptor; } @@ -622,7 +623,7 @@ static mp4sys_DecoderSpecificInfo_t *mp4sys_add_DecoderSpecificInfo( mp4sys_Deco return NULL; MP4SYS_CONSTRUCT_DESCRIPTOR( dsi, DecoderSpecificInfo, dcd, NULL ); dsi->header.tag = MP4SYS_DESCRIPTOR_TAG_DecSpecificInfoTag; - if( lsmash_add_entry( &dcd->children, dsi ) < 0 ) + if( lsmash_list_add_entry( &dcd->children, dsi ) < 0 ) { mp4sys_remove_descriptor( dsi ); return NULL; @@ -644,7 +645,7 @@ static mp4sys_DecoderConfigDescriptor_t *mp4sys_add_DecoderConfigDescriptor return NULL; MP4SYS_CONSTRUCT_DESCRIPTOR( dcd, DecoderConfigDescriptor, esd, NULL ); dcd->header.tag = MP4SYS_DESCRIPTOR_TAG_DecoderConfigDescrTag; - if( lsmash_add_entry( &esd->children, dcd ) < 0 ) + if( lsmash_list_add_entry( &esd->children, dcd ) < 0 ) { mp4sys_remove_descriptor( dcd ); return NULL; @@ -659,7 +660,7 @@ static mp4sys_SLConfigDescriptor_t *mp4sys_add_SLConfigDescriptor( mp4sys_ES_Des return NULL; MP4SYS_CONSTRUCT_DESCRIPTOR( slcd, SLConfigDescriptor, esd, NULL ); slcd->header.tag = MP4SYS_DESCRIPTOR_TAG_SLConfigDescrTag; - if( lsmash_add_entry( &esd->children, slcd ) < 0 ) + if( lsmash_list_add_entry( &esd->children, slcd ) < 0 ) { mp4sys_remove_descriptor( slcd ); return NULL; @@ -677,14 +678,14 @@ static mp4sys_ES_ID_Inc_t *mp4sys_add_ES_ID_Inc( mp4sys_ObjectDescriptor_t *od ) return NULL; MP4SYS_CONSTRUCT_DESCRIPTOR( es_id_inc, ES_ID_Inc, od, NULL ); es_id_inc->header.tag = MP4SYS_DESCRIPTOR_TAG_ES_ID_IncTag; - if( lsmash_add_entry( &od->children, es_id_inc ) < 0 ) + if( lsmash_list_add_entry( &od->children, es_id_inc ) < 0 ) { mp4sys_remove_descriptor( es_id_inc ); return NULL; } - if( lsmash_add_entry( &od->esDescr, es_id_inc ) < 0 ) + if( lsmash_list_add_entry( &od->esDescr, es_id_inc ) < 0 ) { - lsmash_remove_entry_tail( &od->children, mp4sys_remove_ES_ID_Inc ); + lsmash_list_remove_entry_tail( &od->children ); return NULL; } return es_id_inc; @@ -1156,7 +1157,7 @@ static mp4sys_SLConfigDescriptor_t *mp4sys_get_SLConfigDescriptor( lsmash_bs_t * static mp4sys_ES_Descriptor_t *mp4sys_get_ES_Descriptor( lsmash_bs_t *bs, mp4sys_descriptor_head_t *header, void *parent ) { MP4SYS_CONSTRUCT_DESCRIPTOR( esd, ES_Descriptor, parent, NULL ); - if( parent && lsmash_add_entry( &((mp4sys_descriptor_t *)parent)->children, esd ) < 0 ) + if( parent && lsmash_list_add_entry( &((mp4sys_descriptor_t *)parent)->children, esd ) < 0 ) { mp4sys_remove_descriptor( esd ); return NULL; @@ -1216,7 +1217,7 @@ static mp4sys_ES_ID_Inc_t *mp4sys_get_ES_ID_Inc( lsmash_bs_t *bs, mp4sys_descrip static mp4sys_ObjectDescriptor_t *mp4sys_get_ObjectDescriptor( lsmash_bs_t *bs, mp4sys_descriptor_head_t *header, void *parent ) { MP4SYS_CONSTRUCT_DESCRIPTOR( od, ObjectDescriptor, parent, NULL ); - if( parent && lsmash_add_entry( &((mp4sys_descriptor_t *)parent)->children, od ) < 0 ) + if( parent && lsmash_list_add_entry( &((mp4sys_descriptor_t *)parent)->children, od ) < 0 ) { mp4sys_remove_descriptor( od ); return NULL; @@ -1368,7 +1369,7 @@ int mp4sys_setup_summary_from_DecoderSpecificInfo( lsmash_audio_summary_t *summa params->avgBitrate = dcd->avgBitrate; if( (err = mp4a_setup_summary_from_AudioSpecificConfig( summary, dsi_payload, dsi_payload_length )) < 0 || (err = lsmash_set_mp4sys_decoder_specific_info( params, dsi_payload, dsi_payload_length )) < 0 - || (err = lsmash_add_entry( &summary->opaque->list, cs )) < 0 ) + || (err = lsmash_list_add_entry( &summary->opaque->list, cs )) < 0 ) { lsmash_destroy_codec_specific_data( cs ); goto fail; diff --git a/codecs/mp4v.c b/codecs/mp4v.c index ceaa263..907d12e 100644 --- a/codecs/mp4v.c +++ b/codecs/mp4v.c @@ -29,7 +29,7 @@ int mp4v_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_visual_entry_t *mp4v = (isom_visual_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_visual_entry_t *mp4v = (isom_visual_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( mp4v ) ) return LSMASH_ERR_INVALID_DATA; isom_esds_t *esds = (isom_esds_t *)isom_get_extension_box_format( &mp4v->extensions, ISOM_BOX_TYPE_ESDS ); diff --git a/codecs/nalu.c b/codecs/nalu.c index 66d80f4..0f2480b 100644 --- a/codecs/nalu.c +++ b/codecs/nalu.c @@ -189,7 +189,7 @@ int nalu_get_dcr_ps isom_dcr_ps_entry_t *data = lsmash_malloc( sizeof(isom_dcr_ps_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( list, data ) < 0 ) + if( lsmash_list_add_entry( list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -198,7 +198,7 @@ int nalu_get_dcr_ps data->nalUnit = lsmash_bs_get_bytes( bs, data->nalUnitLength ); if( !data->nalUnit ) { - lsmash_remove_entries( list, isom_remove_dcr_ps ); + lsmash_list_remove_entries( list ); return LSMASH_ERR_NAMELESS; } } @@ -244,7 +244,7 @@ uint64_t nalu_get_codeNum int nalu_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_visual_entry_t *sample_entry = (isom_visual_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_visual_entry_t *sample_entry = (isom_visual_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( sample_entry ) ) return LSMASH_ERR_INVALID_DATA; isom_btrt_t *btrt = (isom_btrt_t *)isom_get_extension_box_format( &sample_entry->extensions, ISOM_BOX_TYPE_BTRT ); diff --git a/codecs/qt_wfex.c b/codecs/qt_wfex.c index c41ca07..1a1fe7d 100644 --- a/codecs/qt_wfex.c +++ b/codecs/qt_wfex.c @@ -30,7 +30,7 @@ int waveform_audio_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index ) { - isom_sample_entry_t *sample_entry = (isom_sample_entry_t *)lsmash_get_entry_data( &stbl->stsd->list, sample_description_index ); + isom_sample_entry_t *sample_entry = (isom_sample_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( sample_entry ) ) return LSMASH_ERR_INVALID_DATA; isom_box_t *ext = isom_get_extension_box( &sample_entry->extensions, QT_BOX_TYPE_WAVE ); diff --git a/common/list.c b/common/list.c index 927d133..10f6799 100644 --- a/common/list.c +++ b/common/list.c @@ -24,25 +24,60 @@ #include -void lsmash_init_entry_list( lsmash_entry_list_t *list ) +static void lsmash_list_clear +( + lsmash_entry_list_t *list +) { list->head = NULL; list->tail = NULL; list->last_accessed_entry = NULL; list->last_accessed_number = 0; list->entry_count = 0; + list->eliminator = NULL; } -lsmash_entry_list_t *lsmash_create_entry_list( void ) +void lsmash_list_init_orig +( + lsmash_entry_list_t *list, + lsmash_entry_data_eliminator eliminator +) +{ + assert( eliminator != NULL ); + list->head = NULL; + list->tail = NULL; + list->last_accessed_entry = NULL; + list->last_accessed_number = 0; + list->entry_count = 0; + list->eliminator = eliminator; +} + +lsmash_entry_list_t *lsmash_list_create_orig +( + lsmash_entry_data_eliminator eliminator +) { lsmash_entry_list_t *list = lsmash_malloc( sizeof(lsmash_entry_list_t) ); if( !list ) return NULL; - lsmash_init_entry_list( list ); + lsmash_list_init( list, eliminator ); return list; } -int lsmash_add_entry( lsmash_entry_list_t *list, void *data ) +void lsmash_list_destroy +( + lsmash_entry_list_t *list +) +{ + lsmash_list_remove_entries( list ); + lsmash_free( list ); +} + +int lsmash_list_add_entry +( + lsmash_entry_list_t *list, + void *data +) { if( !list ) return LSMASH_ERR_FUNCTION_PARAM; @@ -61,12 +96,15 @@ int lsmash_add_entry( lsmash_entry_list_t *list, void *data ) return 0; } -int lsmash_remove_entry_direct_orig( lsmash_entry_list_t *list, lsmash_entry_t *entry, lsmash_entry_data_eliminator eliminator ) +int lsmash_list_remove_entry_direct +( + lsmash_entry_list_t *list, + lsmash_entry_t *entry +) { if( !list || !entry ) return LSMASH_ERR_FUNCTION_PARAM; - if( !eliminator ) - eliminator = lsmash_free; + assert( !entry->data || list->eliminator ); lsmash_entry_t *next = entry->next; lsmash_entry_t *prev = entry->prev; if( entry == list->head ) @@ -78,7 +116,7 @@ int lsmash_remove_entry_direct_orig( lsmash_entry_list_t *list, lsmash_entry_t * else next->prev = prev; if( entry->data ) - eliminator( entry->data ); + list->eliminator( entry->data ); if( entry == list->last_accessed_entry ) { if( next ) @@ -106,49 +144,62 @@ int lsmash_remove_entry_direct_orig( lsmash_entry_list_t *list, lsmash_entry_t * return 0; } -int lsmash_remove_entry_orig( lsmash_entry_list_t *list, uint32_t entry_number, lsmash_entry_data_eliminator eliminator ) +int lsmash_list_remove_entry +( + lsmash_entry_list_t *list, + uint32_t entry_number +) { - lsmash_entry_t *entry = lsmash_get_entry( list, entry_number ); - return lsmash_remove_entry_direct( list, entry, eliminator ); + lsmash_entry_t *entry = lsmash_list_get_entry( list, entry_number ); + return lsmash_list_remove_entry_direct( list, entry ); } -int lsmash_remove_entry_tail_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ) +int lsmash_list_remove_entry_tail +( + lsmash_entry_list_t *list +) { - return lsmash_remove_entry_direct( list, list->tail, eliminator ); + return lsmash_list_remove_entry_direct( list, list->tail ); } -void lsmash_remove_entries_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ) +void lsmash_list_remove_entries +( + lsmash_entry_list_t *list +) { if( !list ) return; - if( !eliminator ) - eliminator = lsmash_free; + /* Note that it's valid that list contain no entries or no data to be eliminated. */ for( lsmash_entry_t *entry = list->head; entry; ) { lsmash_entry_t *next = entry->next; if( entry->data ) - eliminator( entry->data ); + list->eliminator( entry->data ); lsmash_free( entry ); entry = next; } - lsmash_init_entry_list( list ); -} - -void lsmash_remove_list_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ) -{ - if( !list ) - return; - lsmash_remove_entries( list, eliminator ); - lsmash_free( list ); + lsmash_entry_data_eliminator eliminator = list->eliminator; + lsmash_list_clear( list ); + list->eliminator = eliminator; } -void lsmash_move_entries( lsmash_entry_list_t *dst, lsmash_entry_list_t *src ) +void lsmash_list_move_entries +( + lsmash_entry_list_t *dst, + lsmash_entry_list_t *src +) { *dst = *src; - lsmash_init_entry_list( src ); + lsmash_entry_data_eliminator eliminator = src->eliminator; + lsmash_list_clear( src ); + src->eliminator = eliminator; } -lsmash_entry_t *lsmash_get_entry( lsmash_entry_list_t *list, uint32_t entry_number ) +lsmash_entry_t *lsmash_list_get_entry +( + lsmash_entry_list_t *list, + uint32_t entry_number +) { if( !list || !entry_number || entry_number > list->entry_count ) return NULL; @@ -190,8 +241,12 @@ lsmash_entry_t *lsmash_get_entry( lsmash_entry_list_t *list, uint32_t entry_numb return entry; } -void *lsmash_get_entry_data( lsmash_entry_list_t *list, uint32_t entry_number ) +void *lsmash_list_get_entry_data +( + lsmash_entry_list_t *list, + uint32_t entry_number +) { - lsmash_entry_t *entry = lsmash_get_entry( list, entry_number ); + lsmash_entry_t *entry = lsmash_list_get_entry( list, entry_number ); return entry ? entry->data : NULL; } diff --git a/common/list.h b/common/list.h dissimilarity index 60% index 6924382..ab489c1 100644 --- a/common/list.h +++ b/common/list.h @@ -1,69 +1,117 @@ -/***************************************************************************** - * list.h - ***************************************************************************** - * Copyright (C) 2010-2017 L-SMASH project - * - * Authors: Yusuke Nakamura - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *****************************************************************************/ - -/* This file is available under an ISC license. */ - -typedef struct lsmash_entry_tag lsmash_entry_t; - -struct lsmash_entry_tag -{ - lsmash_entry_t *next; - lsmash_entry_t *prev; - void *data; -}; - -typedef struct -{ - lsmash_entry_t *head; - lsmash_entry_t *tail; - lsmash_entry_t *last_accessed_entry; - uint32_t last_accessed_number; - uint32_t entry_count; -} lsmash_entry_list_t; - -typedef void (*lsmash_entry_data_eliminator)(void *data); /* very same as free() of standard c lib; void free(void *); */ - -#define lsmash_remove_entry_direct( list, entry, eliminator ) \ - lsmash_remove_entry_direct_orig( list, entry, (lsmash_entry_data_eliminator)(eliminator) ) - -#define lsmash_remove_entry( list, entry_number, eliminator ) \ - lsmash_remove_entry_orig( list, entry_number, (lsmash_entry_data_eliminator)(eliminator) ) - -#define lsmash_remove_entry_tail( list, eliminator ) \ - lsmash_remove_entry_tail_orig( list, (lsmash_entry_data_eliminator)(eliminator) ) - -#define lsmash_remove_entries( list, eliminator ) \ - lsmash_remove_entries_orig( list, (lsmash_entry_data_eliminator)(eliminator) ) - -#define lsmash_remove_list( list, eliminator ) \ - lsmash_remove_list_orig( list, (lsmash_entry_data_eliminator)(eliminator) ) - -void lsmash_init_entry_list( lsmash_entry_list_t *list ); -lsmash_entry_list_t *lsmash_create_entry_list( void ); -int lsmash_add_entry( lsmash_entry_list_t *list, void *data ); -int lsmash_remove_entry_direct_orig( lsmash_entry_list_t *list, lsmash_entry_t *entry, lsmash_entry_data_eliminator eliminator ); -int lsmash_remove_entry_orig( lsmash_entry_list_t *list, uint32_t entry_number, lsmash_entry_data_eliminator eliminator ); -int lsmash_remove_entry_tail_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ); -void lsmash_remove_entries_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ); -void lsmash_remove_list_orig( lsmash_entry_list_t *list, lsmash_entry_data_eliminator eliminator ); -void lsmash_move_entries( lsmash_entry_list_t *dst, lsmash_entry_list_t *src ); - -lsmash_entry_t *lsmash_get_entry( lsmash_entry_list_t *list, uint32_t entry_number ); -void *lsmash_get_entry_data( lsmash_entry_list_t *list, uint32_t entry_number ); +/***************************************************************************** + * list.h + ***************************************************************************** + * Copyright (C) 2010-2017 L-SMASH project + * + * Authors: Yusuke Nakamura + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + *****************************************************************************/ + +/* This file is available under an ISC license. */ + +typedef void (*lsmash_entry_data_eliminator)( void *data ); /* very same as free() of standard C lib; void free( void * ); + * If 'data' is equal to NULL, the eliminator must do nothing. */ + +typedef struct lsmash_entry_tag lsmash_entry_t; + +struct lsmash_entry_tag +{ + lsmash_entry_t *next; + lsmash_entry_t *prev; + void *data; +}; + +typedef struct +{ + lsmash_entry_t *head; + lsmash_entry_t *tail; + lsmash_entry_t *last_accessed_entry; + uint32_t last_accessed_number; + uint32_t entry_count; + lsmash_entry_data_eliminator eliminator; +} lsmash_entry_list_t; + +/* Utility macros to avoid 'lsmash_entry_data_eliminator' casts to the 'eliminator' argument */ +#define lsmash_list_init( list, eliminator ) \ + lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)(eliminator) ) +#define lsmash_list_init_simple( list ) \ + lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)lsmash_free ) + +#define lsmash_list_create( eliminator ) \ + lsmash_list_create_orig( (lsmash_entry_data_eliminator)(eliminator) ) +#define lsmash_list_create_simple() \ + lsmash_list_create_orig( (lsmash_entry_data_eliminator)lsmash_free ) + +/* functions for internal usage */ +void lsmash_list_init_orig +( + lsmash_entry_list_t *list, + lsmash_entry_data_eliminator eliminator +); + +lsmash_entry_list_t *lsmash_list_create_orig +( + lsmash_entry_data_eliminator eliminator +); + +void lsmash_list_destroy +( + lsmash_entry_list_t *list +); + +int lsmash_list_add_entry +( + lsmash_entry_list_t *list, + void *data +); + +int lsmash_list_remove_entry_direct +( + lsmash_entry_list_t *list, + lsmash_entry_t *entry +); + +int lsmash_list_remove_entry +( + lsmash_entry_list_t *list, + uint32_t entry_number +); + +int lsmash_list_remove_entry_tail +( + lsmash_entry_list_t *list +); + +void lsmash_list_remove_entries +( + lsmash_entry_list_t *list +); + +void lsmash_list_move_entries +( + lsmash_entry_list_t *dst, + lsmash_entry_list_t *src +); + +lsmash_entry_t *lsmash_list_get_entry +( + lsmash_entry_list_t *list, + uint32_t entry_number +); + +void *lsmash_list_get_entry_data +( + lsmash_entry_list_t *list, + uint32_t entry_number +); diff --git a/core/box.c b/core/box.c index 785e75e..18b6955 100644 --- a/core/box.c +++ b/core/box.c @@ -99,7 +99,7 @@ int isom_add_box_to_extension_list( void *parent_box, void *child_box ) isom_box_t *child = (isom_box_t *)child_box; assert( LSMASH_IS_EXISTING_BOX( parent ) && LSMASH_IS_EXISTING_BOX( child ) ); /* Append at the end of the list. */ - if( lsmash_add_entry( &parent->extensions, child ) < 0 ) + if( lsmash_list_add_entry( &parent->extensions, child ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; /* Don't reorder the appended box when the file is opened for reading. */ if( LSMASH_IS_NON_EXISTING_BOX( parent->file ) @@ -409,7 +409,7 @@ int isom_add_extension_binary return 0; } -static void isom_remove_extension_box( isom_box_t *ext ) +void isom_remove_extension_box( isom_box_t *ext ) { if( LSMASH_IS_NON_EXISTING_BOX( ext ) ) return; @@ -421,7 +421,7 @@ static void isom_remove_extension_box( isom_box_t *ext ) void isom_remove_all_extension_boxes( lsmash_entry_list_t *extensions ) { - lsmash_remove_entries( extensions, isom_remove_extension_box ); + lsmash_list_remove_entries( extensions ); } isom_box_t *isom_get_extension_box( lsmash_entry_list_t *extensions, lsmash_box_type_t box_type ) @@ -500,21 +500,18 @@ lsmash_entry_t *isom_get_entry_of_box #define REMOVE_BOX_IN_LIST( box_name ) \ isom_remove_box_in_predefined_list( box_name ) -#define REMOVE_LIST_BOX_TEMPLATE( REMOVER, box_name, eliminator ) \ - do \ - { \ - lsmash_remove_list( box_name->list, eliminator ); \ - REMOVER( box_name ); \ +#define REMOVE_LIST_BOX_TEMPLATE( REMOVER, box_name ) \ + do \ + { \ + lsmash_list_destroy( box_name->list ); \ + REMOVER( box_name ); \ } while( 0 ) -#define REMOVE_LIST_BOX( ... ) CALL_FUNC_DEFAULT_ARGS( REMOVE_LIST_BOX, __VA_ARGS__ ) -#define REMOVE_LIST_BOX_2( box_name, eliminator ) \ - REMOVE_LIST_BOX_TEMPLATE( REMOVE_BOX, box_name, eliminator ) -#define REMOVE_LIST_BOX_1( box_name ) \ - REMOVE_LIST_BOX_2( box_name, NULL ) +#define REMOVE_LIST_BOX( box_name ) \ + REMOVE_LIST_BOX_TEMPLATE( REMOVE_BOX, box_name ) #define REMOVE_LIST_BOX_IN_LIST( box_name ) \ - REMOVE_LIST_BOX_TEMPLATE( REMOVE_BOX_IN_LIST, box_name, NULL ) + REMOVE_LIST_BOX_TEMPLATE( REMOVE_BOX_IN_LIST, box_name ) #define DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE( ... ) \ CALL_FUNC_DEFAULT_ARGS( DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE, __VA_ARGS__ ) @@ -535,12 +532,8 @@ lsmash_entry_t *isom_get_entry_of_box #define DEFINE_SIMPLE_BOX_IN_LIST_REMOVER( func_name, box_name ) \ DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE( REMOVE_BOX_IN_LIST, box_name ) -#define DEFINE_SIMPLE_LIST_BOX_REMOVER( ... ) \ - CALL_FUNC_DEFAULT_ARGS( DEFINE_SIMPLE_LIST_BOX_REMOVER, __VA_ARGS__ ) -#define DEFINE_SIMPLE_LIST_BOX_REMOVER_3( func_name, box_name, ... ) \ - DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE_3( REMOVE_LIST_BOX_2, box_name, __VA_ARGS__ ) -#define DEFINE_SIMPLE_LIST_BOX_REMOVER_2( func_name, box_name ) \ - DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE_2( REMOVE_LIST_BOX_1, box_name ) +#define DEFINE_SIMPLE_LIST_BOX_REMOVER( func_name, box_name ) \ + DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE( REMOVE_LIST_BOX, box_name ) #define DEFINE_SIMPLE_LIST_BOX_IN_LIST_REMOVER( func_name, box_name ) \ DEFINE_SIMPLE_BOX_REMOVER_TEMPLATE( REMOVE_LIST_BOX_IN_LIST, box_name ) @@ -574,7 +567,7 @@ static void isom_remove_box_in_predefined_list( void *opaque_box ) * Because of freeing an entry of the list here, don't pass the list to free this box. * Or double free. */ entry->data = NULL; - lsmash_remove_entry_direct( list, entry, NULL ); + lsmash_list_remove_entry_direct( list, entry ); break; } } @@ -597,7 +590,7 @@ void isom_remove_box_by_itself( void *opaque_box ) { /* Free the corresponding entry here, therefore don't call this function as a callback function * if a function frees the same entry later and calls this function. */ - lsmash_remove_entry_direct( &parent->extensions, entry, isom_remove_extension_box ); + lsmash_list_remove_entry_direct( &parent->extensions, entry ); return; } } @@ -613,14 +606,14 @@ static void isom_remove_file_abstract( isom_file_abstract_t *file_abstract ) { if( LSMASH_IS_NON_EXISTING_BOX( file_abstract ) ) return; - isom_remove_print_funcs( file_abstract ); + isom_printer_destory_list( file_abstract ); isom_remove_timelines( file_abstract ); lsmash_free( file_abstract->compatible_brands ); lsmash_bs_cleanup( file_abstract->bs ); lsmash_importer_destroy( file_abstract->importer ); if( file_abstract->fragment ) { - lsmash_remove_list( file_abstract->fragment->pool, isom_remove_sample_pool ); + lsmash_list_destroy( file_abstract->fragment->pool ); lsmash_free( file_abstract->fragment ); } REMOVE_BOX_IN_LIST( file_abstract ); @@ -645,7 +638,7 @@ static void isom_remove_trak( isom_trak_t *trak ) if( trak->cache ) { isom_remove_sample_pool( trak->cache->chunk.pool ); - lsmash_remove_list( trak->cache->roll.pool, NULL ); + lsmash_list_destroy( trak->cache->roll.pool ); lsmash_free( trak->cache->rap ); lsmash_free( trak->cache->fragment ); lsmash_free( trak->cache ); @@ -679,8 +672,6 @@ DEFINE_SIMPLE_BOX_REMOVER( isom_remove_text, text ) static void isom_remove_hdlr( isom_hdlr_t *hdlr ) { - if( LSMASH_IS_NON_EXISTING_BOX( hdlr ) ) - return; lsmash_free( hdlr->componentName ); REMOVE_BOX( hdlr ); } @@ -697,14 +688,7 @@ static void isom_remove_esds( isom_esds_t *esds ) mp4sys_remove_descriptor( esds->ES ); } -static void isom_remove_font_record( isom_font_record_t *font_record ) -{ - if( !font_record ) - return; - lsmash_free( font_record->font_name ); - lsmash_free( font_record ); -} -DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_ftab, ftab, isom_remove_font_record ) +DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_ftab, ftab ) DEFINE_SIMPLE_BOX_REMOVER( isom_remove_frma, frma ) DEFINE_SIMPLE_BOX_REMOVER( isom_remove_enda, enda ) @@ -947,7 +931,7 @@ static void isom_remove_sdtp( isom_sdtp_t *sdtp ) { if( LSMASH_IS_NON_EXISTING_BOX( sdtp ) ) return; - lsmash_remove_list( sdtp->list, NULL ); + lsmash_list_destroy( sdtp->list ); REMOVE_BOX( sdtp ); } @@ -955,7 +939,7 @@ static void isom_remove_sgpd( isom_sgpd_t *sgpd ) { if( LSMASH_IS_NON_EXISTING_BOX( sgpd ) ) return; - lsmash_remove_list( sgpd->list, NULL ); + lsmash_list_destroy( sgpd->list ); REMOVE_BOX_IN_LIST( sgpd ); } @@ -963,7 +947,7 @@ static void isom_remove_sbgp( isom_sbgp_t *sbgp ) { if( LSMASH_IS_NON_EXISTING_BOX( sbgp ) ) return; - lsmash_remove_list( sbgp->list, NULL ); + lsmash_list_destroy( sbgp->list ); REMOVE_BOX_IN_LIST( sbgp ); } @@ -980,24 +964,8 @@ DEFINE_SIMPLE_BOX_REMOVER( isom_remove_dref, dref ) DEFINE_SIMPLE_BOX_REMOVER( isom_remove_dinf, dinf ) DEFINE_SIMPLE_BOX_REMOVER( isom_remove_minf, minf ) DEFINE_SIMPLE_BOX_REMOVER( isom_remove_mdia, mdia ) - -static void isom_remove_chpl_entry( isom_chpl_entry_t *data ) -{ - if( !data ) - return; - lsmash_free( data->chapter_name ); - lsmash_free( data ); -} -DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_chpl, chpl, isom_remove_chpl_entry ) - -static void isom_remove_keys_entry( isom_keys_entry_t *data ) -{ - if( !data ) - return; - lsmash_free( data->key_value ); - lsmash_free( data ); -} -DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_keys, keys, isom_remove_keys_entry ) +DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_chpl, chpl ) +DEFINE_SIMPLE_LIST_BOX_REMOVER( isom_remove_keys, keys ) static void isom_remove_mean( isom_mean_t *mean ) { @@ -1051,7 +1019,7 @@ DEFINE_SIMPLE_BOX_REMOVER( isom_remove_tfdt, tfdt ) static void isom_remove_trun( isom_trun_t *trun ) { - lsmash_remove_list( trun->optional, NULL ); + lsmash_list_destroy( trun->optional ); REMOVE_BOX_IN_LIST( trun ); } @@ -1075,6 +1043,47 @@ static void isom_remove_styp( isom_styp_t *styp ) REMOVE_BOX_IN_LIST( styp ); } +#define isom_remove_elst_entry lsmash_free +#define isom_remove_stts_entry lsmash_free +#define isom_remove_ctts_entry lsmash_free +#define isom_remove_stsz_entry lsmash_free +#define isom_remove_stz2_entry lsmash_free +#define isom_remove_stss_entry lsmash_free +#define isom_remove_stps_entry lsmash_free +#define isom_remove_sdtp_entry lsmash_free +#define isom_remove_stsc_entry lsmash_free +#define isom_remove_stco_entry lsmash_free +#define isom_remove_co64_entry lsmash_free +#define isom_remove_sgpd_entry lsmash_free +#define isom_remove_sbgp_entry lsmash_free +#define isom_remove_trun_entry lsmash_free +#define isom_remove_tfra_entry lsmash_free +#define isom_remove_sidx_entry lsmash_free + +static void isom_remove_ftab_entry( isom_font_record_t *font_record ) +{ + if( !font_record ) + return; + lsmash_free( font_record->font_name ); + lsmash_free( font_record ); +} + +static void isom_remove_chpl_entry( isom_chpl_entry_t *data ) +{ + if( !data ) + return; + lsmash_free( data->chapter_name ); + lsmash_free( data ); +} + +static void isom_remove_keys_entry( isom_keys_entry_t *data ) +{ + if( !data ) + return; + lsmash_free( data->key_value ); + lsmash_free( data ); +} + /* box size updater */ uint64_t isom_update_box_size( void *opaque_box ) { @@ -1125,12 +1134,12 @@ uint64_t isom_update_box_size( void *opaque_box ) } \ } while( 0 ) -#define ADD_BOX_TO_PREDEFINED_LIST( box_name, parent_name ) \ - if( lsmash_add_entry( &parent_name->box_name##_list, box_name ) < 0 ) \ - { \ - lsmash_remove_entry_tail( &parent_name->extensions, isom_remove_##box_name ); \ - return isom_non_existing_##box_name(); \ - } \ +#define ADD_BOX_TO_PREDEFINED_LIST( box_name, parent_name ) \ + if( lsmash_list_add_entry( &parent_name->box_name##_list, box_name ) < 0 ) \ + { \ + lsmash_list_remove_entry_tail( &parent_name->extensions ); \ + return isom_non_existing_##box_name(); \ + } \ box_name->offset_in_parent = offsetof( isom_##parent_name##_t, box_name##_list ) #define INIT_BOX_COMMON0( box_name, parent_name, box_type, precedence ) \ @@ -1153,10 +1162,10 @@ uint64_t isom_update_box_size( void *opaque_box ) } #define CREATE_LIST_BOX( box_name, parent_name, box_type, precedence, has_destructor ) \ CREATE_BOX( box_name, parent_name, box_type, precedence, has_destructor ); \ - box_name->list = lsmash_create_entry_list(); \ + box_name->list = lsmash_list_create( isom_remove_##box_name##_entry ); \ if( !box_name->list ) \ { \ - lsmash_remove_entry_tail( &parent_name->extensions, isom_remove_##box_name ); \ + lsmash_list_remove_entry_tail( &parent_name->extensions ); \ return isom_non_existing_##box_name(); \ } @@ -1210,7 +1219,7 @@ DEFINE_SIMPLE_BOX_IN_LIST_ADDER( isom_add_file_abstract, file_abstract, root_abs isom_tref_type_t *isom_add_track_reference_type( isom_tref_t *tref, isom_track_reference_type type ) { - if( !tref ) + if( LSMASH_IS_NON_EXISTING_BOX( tref ) ) return isom_non_existing_tref_type(); isom_tref_type_t *tref_type = ALLOCATE_BOX( tref_type ); if( LSMASH_IS_NON_EXISTING_BOX( tref_type ) ) @@ -1230,9 +1239,9 @@ isom_tref_type_t *isom_add_track_reference_type( isom_tref_t *tref, isom_track_r lsmash_free( tref_type ); return isom_non_existing_tref_type(); } - if( lsmash_add_entry( &tref->ref_list, tref_type ) < 0 ) + if( lsmash_list_add_entry( &tref->ref_list, tref_type ) < 0 ) { - lsmash_remove_entry_tail( &tref->extensions, isom_remove_track_reference_type ); + lsmash_list_remove_entry_tail( &tref->extensions ); return isom_non_existing_tref_type(); } tref_type->offset_in_parent = offsetof( isom_tref_t, ref_list ); @@ -1285,7 +1294,7 @@ isom_trak_t *isom_add_trak( isom_moov_t *moov ) fragment->subsegment.first_ed_cts = LSMASH_TIMESTAMP_UNDEFINED; fragment->subsegment.first_rp_cts = LSMASH_TIMESTAMP_UNDEFINED; } - if( lsmash_add_entry( &moov->trak_list, trak ) < 0 ) + if( lsmash_list_add_entry( &moov->trak_list, trak ) < 0 ) goto fail; trak->offset_in_parent = offsetof( isom_moov_t, trak_list ); trak->cache = cache; @@ -1293,7 +1302,7 @@ isom_trak_t *isom_add_trak( isom_moov_t *moov ) fail: lsmash_free( fragment ); lsmash_free( cache ); - lsmash_remove_entry_tail( &moov->extensions, isom_remove_trak ); + lsmash_list_remove_entry_tail( &moov->extensions ); return isom_non_existing_trak(); } @@ -1364,9 +1373,9 @@ isom_dref_entry_t *isom_add_dref_entry( isom_dref_t *dref, lsmash_box_type_t typ lsmash_free( dref_entry ); return isom_non_existing_dref_entry(); } - if( lsmash_add_entry( &dref->list, dref_entry ) < 0 ) + if( lsmash_list_add_entry( &dref->list, dref_entry ) < 0 ) { - lsmash_remove_entry_tail( &dref->extensions, isom_remove_dref_entry ); + lsmash_list_remove_entry_tail( &dref->extensions ); return isom_non_existing_dref_entry(); } dref_entry->offset_in_parent = offsetof( isom_dref_t, list ); @@ -1377,25 +1386,25 @@ DEFINE_SIMPLE_BOX_ADDER( isom_add_dref, dref, dinf, ISOM_BOX_TYPE_DREF, LSMASH_B DEFINE_SIMPLE_BOX_ADDER( isom_add_stbl, stbl, minf, ISOM_BOX_TYPE_STBL, LSMASH_BOX_PRECEDENCE_ISOM_STBL ) DEFINE_SIMPLE_BOX_ADDER( isom_add_stsd, stsd, stbl, ISOM_BOX_TYPE_STSD, LSMASH_BOX_PRECEDENCE_ISOM_STSD ) -static int isom_add_sample_description_entry +static void *isom_add_sample_description_entry ( isom_stsd_t *stsd, - void *description, - void (*destructor)( isom_sample_entry_t * ) + void *description ) { + assert( description ); if( isom_add_box_to_extension_list( stsd, description ) < 0 ) { - lsmash_free( description ); - return LSMASH_ERR_MEMORY_ALLOC; + isom_remove_box_by_itself( description ); + return description; } - if( lsmash_add_entry( &stsd->list, description ) < 0 ) + if( lsmash_list_add_entry( &stsd->list, description ) < 0 ) { - lsmash_remove_entry_tail( &stsd->extensions, destructor ); - return LSMASH_ERR_MEMORY_ALLOC; + lsmash_list_remove_entry_tail( &stsd->extensions ); + return description; } ((isom_box_t *)description)->offset_in_parent = offsetof( isom_stsd_t, list ); - return 0; + return description; } isom_visual_entry_t *isom_add_visual_description( isom_stsd_t *stsd, lsmash_codec_type_t sample_type ) @@ -1406,7 +1415,7 @@ isom_visual_entry_t *isom_add_visual_description( isom_stsd_t *stsd, lsmash_code return visual; isom_init_box_common( visual, stsd, sample_type, LSMASH_BOX_PRECEDENCE_HM, isom_remove_visual_description ); visual->manager |= LSMASH_VIDEO_DESCRIPTION; - return isom_add_sample_description_entry( stsd, visual, isom_remove_visual_description ) ? NULL : visual; + return isom_add_sample_description_entry( stsd, visual ); } isom_audio_entry_t *isom_add_audio_description( isom_stsd_t *stsd, lsmash_codec_type_t sample_type ) @@ -1417,7 +1426,7 @@ isom_audio_entry_t *isom_add_audio_description( isom_stsd_t *stsd, lsmash_codec_ return audio; isom_init_box_common( audio, stsd, sample_type, LSMASH_BOX_PRECEDENCE_HM, isom_remove_audio_description ); audio->manager |= LSMASH_AUDIO_DESCRIPTION; - return isom_add_sample_description_entry( stsd, audio, isom_remove_audio_description ) ? NULL : audio; + return isom_add_sample_description_entry( stsd, audio ); } isom_qt_text_entry_t *isom_add_qt_text_description( isom_stsd_t *stsd ) @@ -1427,7 +1436,7 @@ isom_qt_text_entry_t *isom_add_qt_text_description( isom_stsd_t *stsd ) if( LSMASH_IS_NON_EXISTING_BOX( text ) ) return text; isom_init_box_common( text, stsd, QT_CODEC_TYPE_TEXT_TEXT, LSMASH_BOX_PRECEDENCE_HM, isom_remove_qt_text_description ); - return isom_add_sample_description_entry( stsd, text, isom_remove_qt_text_description ) ? NULL : text; + return isom_add_sample_description_entry( stsd, text ); } isom_tx3g_entry_t *isom_add_tx3g_description( isom_stsd_t *stsd ) @@ -1437,7 +1446,7 @@ isom_tx3g_entry_t *isom_add_tx3g_description( isom_stsd_t *stsd ) if( LSMASH_IS_NON_EXISTING_BOX( tx3g ) ) return tx3g; isom_init_box_common( tx3g, stsd, ISOM_CODEC_TYPE_TX3G_TEXT, LSMASH_BOX_PRECEDENCE_HM, isom_remove_tx3g_description ); - return isom_add_sample_description_entry( stsd, tx3g, isom_remove_tx3g_description ) ? NULL : tx3g; + return isom_add_sample_description_entry( stsd, tx3g ); } isom_esds_t *isom_add_esds( void *parent_box ) @@ -1931,7 +1940,7 @@ int lsmash_add_box_ex isom_reorder_tail_box( parent ); /* Do also its children by the same way. */ lsmash_entry_list_t extensions = box->extensions; - lsmash_init_entry_list( &box->extensions ); /* to avoid freeing the children */ + lsmash_list_init_simple( &box->extensions ); /* to avoid freeing the children */ isom_remove_box_by_itself( box ); for( lsmash_entry_t *entry = extensions.head; entry; entry = entry->next ) { diff --git a/core/box.h b/core/box.h index 0495707..3f49a21 100644 --- a/core/box.h +++ b/core/box.h @@ -35,6 +35,7 @@ typedef struct lsmash_file_tag isom_file_abstract_t; typedef struct lsmash_root_tag isom_root_abstract_t; typedef struct isom_unknown_box_tag isom_unknown_t; +typedef struct lsmash_box_tag isom_dummy_t; /* for dummy usage */ typedef struct lsmash_box_tag isom_box_t; typedef struct isom_unknown_box_tag isom_unknown_box_t; @@ -851,7 +852,7 @@ typedef struct uint16_t font_ID; /* Pascal string */ uint8_t font_name_length; - char *font_name; + char *font_name; } isom_font_record_t; /* Font Table Box */ @@ -2550,6 +2551,7 @@ isom_free_t *isom_add_free( void *parent_box ); isom_styp_t *isom_add_styp( lsmash_file_t *file ); isom_sidx_t *isom_add_sidx( lsmash_file_t *file ); +void isom_remove_extension_box( isom_box_t *ext ); void isom_remove_sample_description( isom_sample_entry_t *sample ); void isom_remove_unknown_box( isom_unknown_box_t *unknown_box ); void isom_remove_sample_pool( isom_sample_pool_t *pool ); diff --git a/core/box_default.c b/core/box_default.c index fdd06d9..bcf1335 100644 --- a/core/box_default.c +++ b/core/box_default.c @@ -37,7 +37,7 @@ .manager = LSMASH_NON_EXISTING_BOX, \ .precedence = 0, \ .pos = 0, \ - .extensions = { NULL }, \ + .extensions = { .head = NULL }, \ .size = 0, \ .type = LSMASH_BOX_TYPE_INITIALIZER @@ -58,6 +58,7 @@ static const isom_box_t isom_opaque_box_default = INITIALIZE_BASEBOX_COMMON( opaque ) }; +DEFINE_SIMPLE_BOX_DEFAULT_CONSTANT( dummy ); DEFINE_SIMPLE_BOX_DEFAULT_CONSTANT( unknown ); DEFINE_SIMPLE_BOX_DEFAULT_CONSTANT( ftyp ); DEFINE_SIMPLE_BOX_DEFAULT_CONSTANT( ctab ); @@ -241,6 +242,16 @@ DEFINE_SIMPLE_CONTAINER_BOX_DEFAULT_CONSTANT( trak, tkhd, tapt, edts, tref, mdia DEFINE_SIMPLE_CONTAINER_BOX_DEFAULT_CONSTANT( moov, mvhd, iods, udta, ctab, meta, mvex ); DEFINE_SIMPLE_CONTAINER_BOX_DEFAULT_CONSTANT( file_abstract, ftyp, moov, mdat, meta, mfra ); +/* Box-lists predefined in the parent box definitions are initialized by 0s, thus the entry eliminator + * of each list also be set to NULL (0). This must not be an issue since all box are deallocated through + * the 'extensions' list of the parent box. Only 'entry' which holds the actual box data is deallocated + * when the box is deallocated by the isom_remove_box_in_predefined_list() function. Because of that, + * here, there are no explicit default constant definitions of indivisual predefined box-lists. */ + + +/* Allocate box by default settings. + * + * Use this function to allocate boxes as much as possible, it covers forgetful settings. */ void *allocate_box_by_default ( const void *nonexist_ptr, @@ -252,5 +263,6 @@ void *allocate_box_by_default if( !box ) return (void *)nonexist_ptr; box->manager &= ~LSMASH_NON_EXISTING_BOX; + lsmash_list_init( &box->extensions, isom_remove_extension_box ); return (void *)box; } diff --git a/core/box_default.h b/core/box_default.h index 5539157..f383798 100644 --- a/core/box_default.h +++ b/core/box_default.h @@ -31,6 +31,7 @@ return (isom_##box_name##_t *)&isom_##box_name##_box_default; \ } +DEFINE_BOX_DEFAULT_CONSTANT( dummy ) DEFINE_BOX_DEFAULT_CONSTANT( unknown ) DEFINE_BOX_DEFAULT_CONSTANT( ftyp ) DEFINE_BOX_DEFAULT_CONSTANT( ctab ) diff --git a/core/chapter.c b/core/chapter.c index fdc9d76..a9dde8d 100644 --- a/core/chapter.c +++ b/core/chapter.c @@ -156,7 +156,7 @@ static int isom_add_chpl_entry( isom_chpl_t *chpl, isom_chapter_entry_t *chap_da } memcpy( data->chapter_name, chap_data->chapter_name, data->chapter_name_length ); data->chapter_name[ data->chapter_name_length ] = '\0'; - if( lsmash_add_entry( chpl->list, data ) < 0 ) + if( lsmash_list_add_entry( chpl->list, data ) < 0 ) { lsmash_free( data->chapter_name ); lsmash_free( data ); @@ -384,7 +384,7 @@ char *lsmash_get_tyrant_chapter( lsmash_root_t *root, uint32_t index, double *ti || LSMASH_IS_NON_EXISTING_BOX( file->moov->udta->chpl ) ) return NULL; isom_chpl_t *chpl = file->moov->udta->chpl; - isom_chpl_entry_t *data = (isom_chpl_entry_t *)lsmash_get_entry_data( chpl->list, index ); + isom_chpl_entry_t *data = (isom_chpl_entry_t *)lsmash_list_get_entry_data( chpl->list, index ); if( !data ) return NULL; double timescale = chpl->version ? 10000000.0 : file->moov->mvhd->timescale; diff --git a/core/file.c b/core/file.c index 7c6136d..1353455 100644 --- a/core/file.c +++ b/core/file.c @@ -57,7 +57,7 @@ int isom_check_compatibility /* Get the brand container. */ isom_ftyp_t *ftyp = LSMASH_IS_EXISTING_BOX( file->ftyp ) ? file->ftyp - : (isom_ftyp_t *)lsmash_get_entry_data( &file->styp_list, 1 ); + : (isom_ftyp_t *)lsmash_list_get_entry_data( &file->styp_list, 1 ); /* Check brand to decide mandatory boxes. */ if( LSMASH_IS_NON_EXISTING_BOX( ftyp ) ) { @@ -583,7 +583,7 @@ lsmash_file_t *lsmash_set_file if( !file->fragment ) goto fail; file->fragment->first_moof_pos = FIRST_MOOF_POS_UNDETERMINED; - file->fragment->pool = lsmash_create_entry_list(); + file->fragment->pool = lsmash_list_create( isom_remove_sample_pool ); if( !file->fragment->pool ) goto fail; } @@ -705,7 +705,7 @@ int lsmash_switch_media_segment } else successor->initializer = predecessor->initializer; - isom_styp_t *styp = (isom_styp_t *)lsmash_get_entry_data( &successor->styp_list, 1 ); + isom_styp_t *styp = (isom_styp_t *)lsmash_list_get_entry_data( &successor->styp_list, 1 ); if( LSMASH_IS_NON_EXISTING_BOX( styp ) ) { ret = isom_set_brands( successor, 0, 0, NULL, 0 ); diff --git a/core/fragment.c b/core/fragment.c index 14528f4..9bdf31e 100644 --- a/core/fragment.c +++ b/core/fragment.c @@ -184,7 +184,7 @@ static int isom_write_fragment_random_access_info( lsmash_file_t *file ) { /* Irregular case. Drop this entry. */ lsmash_entry_t *next = rap_entry->next; - lsmash_remove_entry_direct( tfra->list, rap_entry, NULL ); + lsmash_list_remove_entry_direct( tfra->list, rap_entry ); rap_entry = next; continue; } @@ -222,7 +222,7 @@ static int isom_write_fragment_random_access_info( lsmash_file_t *file ) while( rap_entry ) { lsmash_entry_t *next = rap_entry->next; - lsmash_remove_entry_direct( tfra->list, rap_entry, NULL ); + lsmash_list_remove_entry_direct( tfra->list, rap_entry ); rap_entry = next; } break; @@ -499,7 +499,7 @@ static int isom_output_fragment_media_data( lsmash_file_t *file ) file->mdat->size = 0; file->mdat->media_size = 0; } - lsmash_remove_entries( frag_manager->pool, isom_remove_sample_pool ); + lsmash_list_remove_entries( frag_manager->pool ); frag_manager->pool_size = 0; frag_manager->sample_count = 0; return 0; @@ -657,7 +657,7 @@ static int isom_make_segment_index_entry isom_sidx_referenced_item_t *data = lsmash_malloc( sizeof(isom_sidx_referenced_item_t) ); if( !data ) return LSMASH_ERR_NAMELESS; - if( lsmash_add_entry( sidx->list, data ) < 0 ) + if( lsmash_list_add_entry( sidx->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1112,7 +1112,7 @@ static isom_trun_optional_row_t *isom_request_trun_optional_row( isom_trun_t *tr isom_trun_optional_row_t *row = NULL; if( !trun->optional ) { - trun->optional = lsmash_create_entry_list(); + trun->optional = lsmash_list_create_simple(); if( !trun->optional ) return NULL; } @@ -1128,7 +1128,7 @@ static isom_trun_optional_row_t *isom_request_trun_optional_row( isom_trun_t *tr row->sample_size = tfhd->default_sample_size; row->sample_flags = tfhd->default_sample_flags; row->sample_composition_time_offset = 0; - if( lsmash_add_entry( trun->optional, row ) < 0 ) + if( lsmash_list_add_entry( trun->optional, row ) < 0 ) { lsmash_free( row ); return NULL; @@ -1244,7 +1244,7 @@ int isom_append_fragment_track_run isom_fragment_manager_t *frag_manager = file->fragment; /* Move data in the pool of the current track fragment to the pool of the current movie fragment. * Empty the pool of current track. We don't delete data of samples here. */ - if( lsmash_add_entry( frag_manager->pool, chunk->pool ) < 0 ) + if( lsmash_list_add_entry( frag_manager->pool, chunk->pool ) < 0 ) return LSMASH_ERR_MEMORY_ALLOC; frag_manager->sample_count += chunk->pool->sample_count; frag_manager->pool_size += chunk->pool->size; @@ -1573,7 +1573,7 @@ static int isom_fragment_update_sample_tables( isom_traf_t *traf, lsmash_sample_ } if( !tfra->list ) { - tfra->list = lsmash_create_entry_list(); + tfra->list = lsmash_list_create_simple(); if( !tfra->list ) return LSMASH_ERR_MEMORY_ALLOC; } @@ -1586,7 +1586,7 @@ static int isom_fragment_update_sample_tables( isom_traf_t *traf, lsmash_sample_ rap->traf_number = cache->fragment->traf_number; rap->trun_number = traf->trun_list.entry_count; rap->sample_number = trun->sample_count; - if( lsmash_add_entry( tfra->list, rap ) < 0 ) + if( lsmash_list_add_entry( tfra->list, rap ) < 0 ) { lsmash_free( rap ); return LSMASH_ERR_MEMORY_ALLOC; diff --git a/core/isom.c b/core/isom.c index 9009e1e..fd7a4fe 100644 --- a/core/isom.c +++ b/core/isom.c @@ -122,7 +122,7 @@ static int isom_add_elst_entry( isom_elst_t *elst, uint64_t segment_duration, in data->segment_duration = segment_duration; data->media_time = media_time; data->media_rate = media_rate; - if( lsmash_add_entry( elst->list, data ) < 0 ) + if( lsmash_list_add_entry( elst->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -166,7 +166,7 @@ static int isom_add_stts_entry( isom_stbl_t *stbl, uint32_t sample_delta ) return LSMASH_ERR_MEMORY_ALLOC; data->sample_count = 1; data->sample_delta = sample_delta; - if( lsmash_add_entry( stbl->stts->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stts->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -184,7 +184,7 @@ static int isom_add_ctts_entry( isom_stbl_t *stbl, uint32_t sample_count, uint32 return LSMASH_ERR_MEMORY_ALLOC; data->sample_count = sample_count; data->sample_offset = sample_offset; - if( lsmash_add_entry( stbl->ctts->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->ctts->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -203,7 +203,7 @@ static int isom_add_stsc_entry( isom_stbl_t *stbl, uint32_t first_chunk, uint32_ data->first_chunk = first_chunk; data->samples_per_chunk = samples_per_chunk; data->sample_description_index = sample_description_index; - if( lsmash_add_entry( stbl->stsc->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stsc->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -229,7 +229,7 @@ static int isom_add_stsz_entry( isom_stbl_t *stbl, uint32_t entry_size ) /* found sample_size varies, create sample_size list */ if( !stsz->list ) { - stsz->list = lsmash_create_entry_list(); + stsz->list = lsmash_list_create_simple(); if( !stsz->list ) return LSMASH_ERR_MEMORY_ALLOC; for( uint32_t i = 0; i < stsz->sample_count; i++ ) @@ -238,7 +238,7 @@ static int isom_add_stsz_entry( isom_stbl_t *stbl, uint32_t entry_size ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->entry_size = stsz->sample_size; - if( lsmash_add_entry( stsz->list, data ) < 0 ) + if( lsmash_list_add_entry( stsz->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -250,7 +250,7 @@ static int isom_add_stsz_entry( isom_stbl_t *stbl, uint32_t entry_size ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->entry_size = entry_size; - if( lsmash_add_entry( stsz->list, data ) < 0 ) + if( lsmash_list_add_entry( stsz->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -268,7 +268,7 @@ static int isom_add_stss_entry( isom_stbl_t *stbl, uint32_t sample_number ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->sample_number = sample_number; - if( lsmash_add_entry( stbl->stss->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stss->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -285,7 +285,7 @@ static int isom_add_stps_entry( isom_stbl_t *stbl, uint32_t sample_number ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->sample_number = sample_number; - if( lsmash_add_entry( stbl->stps->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stps->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -329,7 +329,7 @@ static int isom_add_sdtp_entry( isom_box_t *parent, lsmash_sample_property_t *pr data->sample_depends_on = prop->independent & 0x03; data->sample_is_depended_on = prop->disposable & 0x03; data->sample_has_redundancy = prop->redundant & 0x03; - if( lsmash_add_entry( sdtp->list, data ) < 0 ) + if( lsmash_list_add_entry( sdtp->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -346,7 +346,7 @@ static int isom_add_co64_entry( isom_stbl_t *stbl, uint64_t chunk_offset ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->chunk_offset = chunk_offset; - if( lsmash_add_entry( stbl->stco->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stco->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -395,7 +395,7 @@ static int isom_add_stco_entry( isom_stbl_t *stbl, uint64_t chunk_offset ) if( !data ) return LSMASH_ERR_MEMORY_ALLOC; data->chunk_offset = (uint32_t)chunk_offset; - if( lsmash_add_entry( stbl->stco->list, data ) < 0 ) + if( lsmash_list_add_entry( stbl->stco->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -479,7 +479,7 @@ static isom_rap_entry_t *isom_add_rap_group_entry( isom_sgpd_t *sgpd ) data->description_length = 0; data->num_leading_samples_known = 0; data->num_leading_samples = 0; - if( lsmash_add_entry( sgpd->list, data ) < 0 ) + if( lsmash_list_add_entry( sgpd->list, data ) < 0 ) { lsmash_free( data ); return NULL; @@ -496,7 +496,7 @@ static isom_roll_entry_t *isom_add_roll_group_entry( isom_sgpd_t *sgpd, int16_t return NULL; data->description_length = 0; data->roll_distance = roll_distance; - if( lsmash_add_entry( sgpd->list, data ) < 0 ) + if( lsmash_list_add_entry( sgpd->list, data ) < 0 ) { lsmash_free( data ); return NULL; @@ -513,7 +513,7 @@ static isom_group_assignment_entry_t *isom_add_group_assignment_entry( isom_sbgp return NULL; data->sample_count = sample_count; data->group_description_index = group_description_index; - if( lsmash_add_entry( sbgp->list, data ) < 0 ) + if( lsmash_list_add_entry( sbgp->list, data ) < 0 ) { lsmash_free( data ); return NULL; @@ -656,7 +656,7 @@ static int isom_update_mdhd_duration( isom_trak_t *trak, uint32_t last_sample_de else { /* Remove the last entry. */ - if( (err = lsmash_remove_entry_tail( stts->list, NULL )) < 0 ) + if( (err = lsmash_list_remove_entry_tail( stts->list )) < 0 ) return err; /* copy the previous sample_delta. */ ++ ((isom_stts_entry_t *)stts->list->tail->data)->sample_count; @@ -1373,7 +1373,7 @@ uint32_t lsmash_get_track_ID( lsmash_root_t *root, uint32_t track_number ) if( isom_check_initializer_present( root ) < 0 || LSMASH_IS_NON_EXISTING_BOX( root->file->initializer->moov ) ) return 0; - isom_trak_t *trak = (isom_trak_t *)lsmash_get_entry_data( &root->file->initializer->moov->trak_list, track_number ); + isom_trak_t *trak = (isom_trak_t *)lsmash_list_get_entry_data( &root->file->initializer->moov->trak_list, track_number ); if( LSMASH_IS_NON_EXISTING_BOX( trak ) || LSMASH_IS_NON_EXISTING_BOX( trak->tkhd ) ) return 0; @@ -1526,7 +1526,7 @@ int lsmash_get_data_reference isom_trak_t *trak = isom_get_trak( root->file->initializer, track_ID ); if( check_dref_presence( trak ) < 0 ) return LSMASH_ERR_NAMELESS; - isom_dref_entry_t *url = lsmash_get_entry_data( &trak->mdia->minf->dinf->dref->list, data_ref->index ); + isom_dref_entry_t *url = lsmash_list_get_entry_data( &trak->mdia->minf->dinf->dref->list, data_ref->index ); if( LSMASH_IS_NON_EXISTING_BOX( url ) ) return LSMASH_ERR_NAMELESS; if( !(url->flags & 0x000001) && url->location ) @@ -1623,7 +1623,7 @@ int lsmash_assign_data_reference isom_trak_t *trak = isom_get_trak( root->file->initializer, track_ID ); if( check_dref_presence( trak ) < 0 ) return LSMASH_ERR_NAMELESS; - isom_dref_entry_t *url = (isom_dref_entry_t *)lsmash_get_entry_data( &trak->mdia->minf->dinf->dref->list, data_ref_index ); + isom_dref_entry_t *url = (isom_dref_entry_t *)lsmash_list_get_entry_data( &trak->mdia->minf->dinf->dref->list, data_ref_index ); if( LSMASH_IS_NON_EXISTING_BOX( url ) ) return LSMASH_ERR_NAMELESS; if( !(url->flags & 0x000001) ) @@ -1976,7 +1976,7 @@ static int isom_compress_sample_size_table( isom_stbl_t *stbl ) stz2->field_size = 8; else stz2->field_size = 16; - lsmash_move_entries( stz2->list, stsz->list ); + lsmash_list_move_entries( stz2->list, stsz->list ); isom_remove_box_by_itself( stsz ); } } @@ -2370,8 +2370,8 @@ static lsmash_file_t *isom_get_written_media_file ) { isom_minf_t *minf = trak->mdia->minf; - isom_sample_entry_t *description = (isom_sample_entry_t *)lsmash_get_entry_data( &minf->stbl->stsd->list, sample_description_index ); - isom_dref_entry_t *dref_entry = (isom_dref_entry_t *)lsmash_get_entry_data( &minf->dinf->dref->list, description ? description->data_reference_index : 1 ); + isom_sample_entry_t *description = (isom_sample_entry_t *)lsmash_list_get_entry_data( &minf->stbl->stsd->list, sample_description_index ); + isom_dref_entry_t *dref_entry = (isom_dref_entry_t *)lsmash_list_get_entry_data( &minf->dinf->dref->list, description ? description->data_reference_index : 1 ); lsmash_file_t *file = (!dref_entry || LSMASH_IS_NON_EXISTING_BOX( dref_entry->ref_file )) ? trak->file : dref_entry->ref_file; if( !(file->flags & LSMASH_FILE_MODE_MEDIA) || !(file->flags & LSMASH_FILE_MODE_WRITE) ) @@ -2637,8 +2637,8 @@ int lsmash_set_last_sample_delta( lsmash_root_t *root, uint32_t track_ID, uint32 if( !last_stts_data ) return LSMASH_ERR_INVALID_DATA; /* Consider QuikcTime fixed compression audio. */ - isom_audio_entry_t *audio = (isom_audio_entry_t *)lsmash_get_entry_data( &trak->mdia->minf->stbl->stsd->list, - trak->cache->chunk.sample_description_index ); + isom_audio_entry_t *audio = (isom_audio_entry_t *)lsmash_list_get_entry_data( &trak->mdia->minf->stbl->stsd->list, + trak->cache->chunk.sample_description_index ); if( LSMASH_IS_NON_EXISTING_BOX( audio ) ) return LSMASH_ERR_INVALID_DATA; if( (audio->manager & LSMASH_AUDIO_DESCRIPTION) @@ -2693,7 +2693,7 @@ int lsmash_modify_explicit_timeline_map( lsmash_root_t *root, uint32_t track_ID, if( !trak->edts->elst->list ) return LSMASH_ERR_NAMELESS; isom_elst_t *elst = trak->edts->elst; - isom_elst_entry_t *data = (isom_elst_entry_t *)lsmash_get_entry_data( elst->list, edit_number ); + isom_elst_entry_t *data = (isom_elst_entry_t *)lsmash_list_get_entry_data( elst->list, edit_number ); if( !data ) return LSMASH_ERR_NAMELESS; data->segment_duration = edit.duration; @@ -2761,7 +2761,7 @@ int lsmash_get_explicit_timeline_map( lsmash_root_t *root, uint32_t track_ID, ui edit->rate = 0; return 0; } - data = (isom_elst_entry_t *)lsmash_get_entry_data( trak->edts->elst->list, edit_number ); + data = (isom_elst_entry_t *)lsmash_list_get_entry_data( trak->edts->elst->list, edit_number ); } if( !data ) return LSMASH_ERR_NAMELESS; @@ -3108,7 +3108,7 @@ int isom_rap_grouping_established( isom_rap_group_t *group, int num_leading_samp { /* The same description already exists. * Remove the latest random access entry. */ - lsmash_remove_entry_tail( sgpd->list, NULL ); + lsmash_list_remove_entry_tail( sgpd->list ); /* Replace assigned group_description_index with the one corresponding the same description. */ if( group->assignment->group_description_index == 0 ) { @@ -3304,7 +3304,7 @@ static int isom_deduplicate_roll_group( isom_sbgp_t *sbgp, lsmash_entry_list_t * { /* Deduplication */ uint32_t current_group_number = sbgp->list->entry_count - pool->entry_count + 1; - isom_group_assignment_entry_t *prev_assignment = (isom_group_assignment_entry_t *)lsmash_get_entry_data( sbgp->list, current_group_number - 1 ); + isom_group_assignment_entry_t *prev_assignment = (isom_group_assignment_entry_t *)lsmash_list_get_entry_data( sbgp->list, current_group_number - 1 ); for( lsmash_entry_t *entry = pool->head; entry; ) { isom_roll_group_t *group = (isom_roll_group_t *)entry->data; @@ -3319,8 +3319,8 @@ static int isom_deduplicate_roll_group( isom_sbgp_t *sbgp, lsmash_entry_list_t * lsmash_entry_t *next_entry = entry->next; prev_assignment->sample_count += group->assignment->sample_count; int err; - if( (err = lsmash_remove_entry( sbgp->list, current_group_number, NULL )) < 0 - || (err = lsmash_remove_entry_direct( pool, entry, NULL )) < 0 ) + if( (err = lsmash_list_remove_entry( sbgp->list, current_group_number )) < 0 + || (err = lsmash_list_remove_entry_direct( pool, entry )) < 0 ) return err; entry = next_entry; } @@ -3344,7 +3344,7 @@ static int isom_clean_roll_pool( lsmash_entry_list_t *pool ) return LSMASH_ERR_INVALID_DATA; if( !group->delimited || group->described != ROLL_DISTANCE_DETERMINED ) return 0; - int err = lsmash_remove_entry_direct( pool, entry, NULL ); + int err = lsmash_list_remove_entry_direct( pool, entry ); if( err < 0 ) return err; } @@ -3406,7 +3406,7 @@ static isom_roll_entry_t *isom_get_roll_description assert( group_description_index > 0x10000 ); group_description_index -= 0x10000; } - return (isom_roll_entry_t *)lsmash_get_entry_data( group->sgpd->list, group_description_index ); + return (isom_roll_entry_t *)lsmash_list_get_entry_data( group->sgpd->list, group_description_index ); } int isom_group_roll_recovery( isom_box_t *parent, isom_cache_t *cache, lsmash_sample_t *sample ) @@ -3459,13 +3459,13 @@ int isom_group_roll_recovery( isom_box_t *parent, isom_cache_t *cache, lsmash_sa lsmash_entry_list_t *pool = cache->roll.pool; if( !pool ) { - pool = lsmash_create_entry_list(); + pool = lsmash_list_create_simple(); if( !pool ) return LSMASH_ERR_MEMORY_ALLOC; cache->roll.pool = pool; } lsmash_sample_property_t *prop = &sample->prop; - isom_roll_group_t *group = (isom_roll_group_t *)lsmash_get_entry_data( pool, pool->entry_count ); + isom_roll_group_t *group = (isom_roll_group_t *)lsmash_list_get_entry_data( pool, pool->entry_count ); int is_recovery_start = LSMASH_IS_POST_ROLL_START( prop->ra_flags ); int valid_pre_roll = !is_recovery_start && (prop->ra_flags != ISOM_SAMPLE_RANDOM_ACCESS_FLAG_NONE) @@ -3497,7 +3497,7 @@ int isom_group_roll_recovery( isom_box_t *parent, isom_cache_t *cache, lsmash_sa group->prev_is_recovery_start = is_recovery_start; group->is_fragment = is_fragment; group->assignment = isom_add_group_assignment_entry( sbgp, 1, 0 ); - if( !group->assignment || lsmash_add_entry( pool, group ) < 0 ) + if( !group->assignment || lsmash_list_add_entry( pool, group ) < 0 ) { lsmash_free( group ); return LSMASH_ERR_MEMORY_ALLOC; @@ -4056,7 +4056,7 @@ int lsmash_append_sample( lsmash_root_t *root, uint32_t track_ID, lsmash_sample_ || !trak->cache || !trak->mdia->minf->stbl->stsc->list ) return LSMASH_ERR_NAMELESS; - isom_sample_entry_t *sample_entry = (isom_sample_entry_t *)lsmash_get_entry_data( &trak->mdia->minf->stbl->stsd->list, sample->index ); + isom_sample_entry_t *sample_entry = (isom_sample_entry_t *)lsmash_list_get_entry_data( &trak->mdia->minf->stbl->stsd->list, sample->index ); if( LSMASH_IS_NON_EXISTING_BOX( sample_entry ) ) return LSMASH_ERR_NAMELESS; /* Append a sample. */ diff --git a/core/meta.c b/core/meta.c index 8bb350e..a0d55dc 100644 --- a/core/meta.c +++ b/core/meta.c @@ -397,7 +397,7 @@ int lsmash_get_itunes_metadata( lsmash_root_t *root, uint32_t metadata_number, l if( !file->moov->udta->meta->ilst ) return LSMASH_ERR_NAMELESS; isom_ilst_t *ilst = file->moov->udta->meta->ilst; - isom_metaitem_t *metaitem = (isom_metaitem_t *)lsmash_get_entry_data( &ilst->metaitem_list, metadata_number ); + isom_metaitem_t *metaitem = (isom_metaitem_t *)lsmash_list_get_entry_data( &ilst->metaitem_list, metadata_number ); if( LSMASH_IS_NON_EXISTING_BOX( metaitem ) || LSMASH_IS_NON_EXISTING_BOX( metaitem->data ) || metaitem->data->value == NULL diff --git a/core/print.c b/core/print.c index f1f99c3..1ef5478 100644 --- a/core/print.c +++ b/core/print.c @@ -2564,7 +2564,7 @@ int isom_add_print_func( lsmash_file_t *file, void *box, int level ) data->box = (isom_box_t *)box; data->func = isom_select_print_func( (isom_box_t *)box ); assert( data->func ); - if( lsmash_add_entry( file->print, data ) < 0 ) + if( lsmash_list_add_entry( file->print, data ) < 0 ) { isom_print_remove_plastic_box( data->box ); lsmash_free( data ); @@ -2581,8 +2581,13 @@ static void isom_remove_print_func( isom_print_entry_t *data ) lsmash_free( data ); } -void isom_remove_print_funcs( lsmash_file_t *file ) +void isom_printer_destory_list( lsmash_file_t *file ) { - lsmash_remove_list( file->print, isom_remove_print_func ); + lsmash_list_destroy( file->print ); file->print = NULL; } + +lsmash_entry_list_t *isom_printer_create_list( void ) +{ + return lsmash_list_create( isom_remove_print_func ); +} diff --git a/core/print.h b/core/print.h index ef443ee..d8e5fc3 100644 --- a/core/print.h +++ b/core/print.h @@ -24,6 +24,7 @@ #define LSMASH_PRINT_H int isom_add_print_func( lsmash_file_t *file, void *box, int level ); -void isom_remove_print_funcs( lsmash_file_t *file ); +void isom_printer_destory_list( lsmash_file_t *file ); +lsmash_entry_list_t *isom_printer_create_list( void ); #endif /* LSMASH_PRINT_H */ diff --git a/core/read.c b/core/read.c index b3f9c03..fdbbf9f 100644 --- a/core/read.c +++ b/core/read.c @@ -27,6 +27,7 @@ #include #include "box.h" +#include "box_default.h" #include "file.h" #include "print.h" #include "read.h" @@ -225,12 +226,12 @@ static int isom_read_unknown_box( lsmash_file_t *file, isom_box_t *box, isom_box uint64_t read_size = box->size - lsmash_bs_count( bs ); if( box->manager & LSMASH_INCOMPLETE_BOX ) return LSMASH_ERR_INVALID_DATA; - isom_unknown_box_t *unknown = lsmash_malloc_zero( sizeof(isom_unknown_box_t) ); - if( !unknown ) + isom_unknown_box_t *unknown = ALLOCATE_BOX( unknown ); + if( LSMASH_IS_NON_EXISTING_BOX( unknown ) ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( &parent->extensions, unknown ) < 0 ) + if( lsmash_list_add_entry( &parent->extensions, unknown ) < 0 ) { - lsmash_free( unknown ); + isom_remove_box_by_itself( unknown ); return LSMASH_ERR_MEMORY_ALLOC; } isom_box_common_copy( unknown, box ); @@ -248,15 +249,15 @@ static int isom_read_unknown_box( lsmash_file_t *file, isom_box_t *box, isom_box if( !(file->flags & LSMASH_FILE_MODE_DUMP) ) return 0; /* Create a dummy for dump. */ - isom_box_t *dummy = lsmash_malloc_zero( sizeof(isom_box_t) ); - if( !dummy ) + isom_dummy_t *dummy = ALLOCATE_BOX( dummy ); + if( LSMASH_IS_NON_EXISTING_BOX( dummy ) ) return LSMASH_ERR_MEMORY_ALLOC; box->manager |= LSMASH_ABSENT_IN_FILE | LSMASH_UNKNOWN_BOX; isom_box_common_copy( dummy, box ); int ret = isom_add_print_func( file, dummy, level ); if( ret < 0 ) { - lsmash_free( dummy ); + isom_remove_box_by_itself( dummy ); return ret; } return 0; @@ -264,7 +265,7 @@ static int isom_read_unknown_box( lsmash_file_t *file, isom_box_t *box, isom_box #define ADD_BOX( box_name, parent_type ) \ isom_##box_name##_t *box_name = isom_add_##box_name( (parent_type *)parent ); \ - if( !box_name ) \ + if( LSMASH_IS_NON_EXISTING_BOX( box_name ) ) \ return LSMASH_ERR_NAMELESS static int isom_read_ftyp( lsmash_file_t *file, isom_box_t *box, isom_box_t *parent, int level ) @@ -348,7 +349,7 @@ static int isom_read_sidx( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_sidx_referenced_item_t *data = lsmash_malloc( sizeof(isom_sidx_referenced_item_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( sidx->list, data ) < 0 ) + if( lsmash_list_add_entry( sidx->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -589,7 +590,7 @@ static int isom_read_elst( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_elst_entry_t *data = lsmash_malloc( sizeof(isom_elst_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( elst->list, data ) < 0 ) + if( lsmash_list_add_entry( elst->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -971,46 +972,44 @@ fail: static void *isom_sample_description_alloc( lsmash_codec_type_t sample_type, isom_stsd_t *stsd ) { assert( isom_check_media_hdlr_from_stsd( stsd ) ); - /* Determine suitable allocation size. */ - size_t alloc_size = 0; + void *sample_desc = NULL; lsmash_media_type media_type = ((isom_mdia_t *)stsd->parent->parent->parent)->hdlr->componentSubtype; if( media_type == ISOM_MEDIA_HANDLER_TYPE_VIDEO_TRACK ) - alloc_size = sizeof(isom_visual_entry_t); + sample_desc = ALLOCATE_BOX( visual_entry ); else if( media_type == ISOM_MEDIA_HANDLER_TYPE_AUDIO_TRACK ) - alloc_size = sizeof(isom_audio_entry_t); + sample_desc = ALLOCATE_BOX( audio_entry ); else if( media_type == ISOM_MEDIA_HANDLER_TYPE_TEXT_TRACK ) { if( lsmash_check_codec_type_identical( sample_type, ISOM_CODEC_TYPE_TX3G_TEXT ) ) - alloc_size = sizeof(isom_tx3g_entry_t); + sample_desc = ALLOCATE_BOX( tx3g_entry ); else if( lsmash_check_codec_type_identical( sample_type, QT_CODEC_TYPE_TEXT_TEXT ) ) - alloc_size = sizeof(isom_qt_text_entry_t); + sample_desc = ALLOCATE_BOX( qt_text_entry ); } else if( lsmash_check_codec_type_identical( sample_type, ISOM_CODEC_TYPE_MP4S_SYSTEM ) ) - alloc_size = sizeof(isom_mp4s_entry_t); - /* Return allocated memory block if the allocation size is non-zero. */ - if( alloc_size == 0 ) + sample_desc = ALLOCATE_BOX( mp4s_entry ); + if( !sample_desc ) return NULL; - return lsmash_malloc_zero( alloc_size ); + ((isom_box_t *)sample_desc)->offset_in_parent = offsetof( isom_stsd_t, list ); + ((isom_box_t *)sample_desc)->destruct = (isom_extension_destructor_t)isom_remove_sample_description; + return sample_desc; } static void *isom_add_description( lsmash_codec_type_t sample_type, isom_stsd_t *stsd ) { - void *sample = isom_sample_description_alloc( sample_type, stsd ); - if( !sample ) + void *sample_desc = isom_sample_description_alloc( sample_type, stsd ); + if( !sample_desc ) return NULL; - if( lsmash_add_entry( &stsd->list, sample ) < 0 ) + if( lsmash_list_add_entry( &stsd->list, sample_desc ) < 0 ) { - lsmash_free( sample ); + lsmash_free( sample_desc ); return NULL; } - if( lsmash_add_entry( &stsd->extensions, sample ) < 0 ) + if( lsmash_list_add_entry( &stsd->extensions, sample_desc ) < 0 ) { - lsmash_remove_entry_tail( &stsd->list, lsmash_free ); + lsmash_list_remove_entry_tail( &stsd->list ); return NULL; } - ((isom_box_t *)sample)->offset_in_parent = offsetof( isom_stsd_t, list ); - ((isom_box_t *)sample)->destruct = (isom_extension_destructor_t)isom_remove_sample_description; - return sample; + return sample_desc; } static int isom_read_visual_description( lsmash_file_t *file, isom_box_t *box, isom_box_t *parent, int level ) @@ -1018,7 +1017,7 @@ static int isom_read_visual_description( lsmash_file_t *file, isom_box_t *box, i if( !lsmash_check_box_type_identical( parent->type, ISOM_BOX_TYPE_STSD ) ) return isom_read_unknown_box( file, box, parent, level ); isom_visual_entry_t *visual = (isom_visual_entry_t *)isom_add_description( box->type, (isom_stsd_t *)parent ); - if( !visual ) + if( LSMASH_IS_NON_EXISTING_BOX( visual ) ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = file->bs; for( int i = 0; i < 6; i++ ) @@ -1212,7 +1211,7 @@ static int isom_read_audio_description( lsmash_file_t *file, isom_box_t *box, is if( !lsmash_check_box_type_identical( parent->type, ISOM_BOX_TYPE_STSD ) ) return isom_read_unknown_box( file, box, parent, level ); isom_audio_entry_t *audio = (isom_audio_entry_t *)isom_add_description( box->type, (isom_stsd_t *)parent ); - if( !audio ) + if( LSMASH_IS_NON_EXISTING_BOX( audio ) ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = file->bs; for( int i = 0; i < 6; i++ ) @@ -1352,7 +1351,7 @@ static int isom_read_qt_text_description( lsmash_file_t *file, isom_box_t *box, if( !lsmash_check_box_type_identical( parent->type, ISOM_BOX_TYPE_STSD ) ) return isom_read_unknown_box( file, box, parent, level ); isom_qt_text_entry_t *text = (isom_qt_text_entry_t *)isom_add_description( box->type, (isom_stsd_t *)parent ); - if( !text ) + if( LSMASH_IS_NON_EXISTING_BOX( text ) ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = file->bs; for( int i = 0; i < 6; i++ ) @@ -1397,7 +1396,7 @@ static int isom_read_tx3g_description( lsmash_file_t *file, isom_box_t *box, iso if( !lsmash_check_box_type_identical( parent->type, ISOM_BOX_TYPE_STSD ) ) return isom_read_unknown_box( file, box, parent, level ); isom_tx3g_entry_t *tx3g = (isom_tx3g_entry_t *)isom_add_description( box->type, (isom_stsd_t *)parent ); - if( !tx3g ) + if( LSMASH_IS_NON_EXISTING_BOX( tx3g ) ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = file->bs; for( int i = 0; i < 6; i++ ) @@ -1450,7 +1449,7 @@ static int isom_read_ftab( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_font_record_t *data = lsmash_malloc_zero( sizeof(isom_font_record_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ftab->list, data ) < 0 ) + if( lsmash_list_add_entry( ftab->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1475,7 +1474,7 @@ static int isom_read_mp4s_description( lsmash_file_t *file, isom_box_t *box, iso if( !lsmash_check_box_type_identical( parent->type, ISOM_BOX_TYPE_STSD ) ) return isom_read_unknown_box( file, box, parent, level ); isom_mp4s_entry_t *mp4s = (isom_mp4s_entry_t *)isom_add_description( box->type, (isom_stsd_t *)parent ); - if( !mp4s ) + if( LSMASH_IS_NON_EXISTING_BOX( mp4s ) ) return LSMASH_ERR_MEMORY_ALLOC; lsmash_bs_t *bs = file->bs; for( int i = 0; i < 6; i++ ) @@ -1509,7 +1508,7 @@ static int isom_read_stts( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stts_entry_t *data = lsmash_malloc( sizeof(isom_stts_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stts->list, data ) < 0 ) + if( lsmash_list_add_entry( stts->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1533,7 +1532,7 @@ static int isom_read_ctts( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_ctts_entry_t *data = lsmash_malloc( sizeof(isom_ctts_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( ctts->list, data ) < 0 ) + if( lsmash_list_add_entry( ctts->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1572,7 +1571,7 @@ static int isom_read_stss( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stss_entry_t *data = lsmash_malloc( sizeof(isom_stss_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stss->list, data ) < 0 ) + if( lsmash_list_add_entry( stss->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1595,7 +1594,7 @@ static int isom_read_stps( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stps_entry_t *data = lsmash_malloc( sizeof(isom_stps_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stps->list, data ) < 0 ) + if( lsmash_list_add_entry( stps->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1619,7 +1618,7 @@ static int isom_read_sdtp( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_sdtp_entry_t *data = lsmash_malloc( sizeof(isom_sdtp_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( sdtp->list, data ) < 0 ) + if( lsmash_list_add_entry( sdtp->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1646,7 +1645,7 @@ static int isom_read_stsc( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stsc_entry_t *data = lsmash_malloc( sizeof(isom_stsc_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stsc->list, data ) < 0 ) + if( lsmash_list_add_entry( stsc->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1670,7 +1669,7 @@ static int isom_read_stsz( lsmash_file_t *file, isom_box_t *box, isom_box_t *par uint64_t pos = lsmash_bs_count( bs ); if( pos < box->size ) { - stsz->list = lsmash_create_entry_list(); + stsz->list = lsmash_list_create_simple(); if( !stsz->list ) return LSMASH_ERR_MEMORY_ALLOC; for( ; pos < box->size && stsz->list->entry_count < stsz->sample_count; pos = lsmash_bs_count( bs ) ) @@ -1678,7 +1677,7 @@ static int isom_read_stsz( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stsz_entry_t *data = lsmash_malloc( sizeof(isom_stsz_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stsz->list, data ) < 0 ) + if( lsmash_list_add_entry( stsz->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1716,7 +1715,7 @@ static int isom_read_stz2( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stsz_entry_t *data = lsmash_malloc( sizeof(isom_stsz_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stz2->list, data ) < 0 ) + if( lsmash_list_add_entry( stz2->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1733,7 +1732,7 @@ static int isom_read_stz2( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stsz_entry_t *data = lsmash_malloc( sizeof(isom_stsz_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stz2->list, data ) < 0 ) + if( lsmash_list_add_entry( stz2->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1778,7 +1777,7 @@ static int isom_read_stco( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_stco_entry_t *data = lsmash_malloc( sizeof(isom_stco_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stco->list, data ) < 0 ) + if( lsmash_list_add_entry( stco->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1792,7 +1791,7 @@ static int isom_read_stco( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_co64_entry_t *data = lsmash_malloc( sizeof(isom_co64_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( stco->list, data ) < 0 ) + if( lsmash_list_add_entry( stco->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1823,7 +1822,7 @@ static int isom_read_sgpd( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_rap_entry_t *data = lsmash_malloc( sizeof(isom_rap_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( sgpd->list, data ) < 0 ) + if( lsmash_list_add_entry( sgpd->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1849,7 +1848,7 @@ static int isom_read_sgpd( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_roll_entry_t *data = lsmash_malloc( sizeof(isom_roll_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( sgpd->list, data ) < 0 ) + if( lsmash_list_add_entry( sgpd->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1885,7 +1884,7 @@ static int isom_read_sbgp( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_group_assignment_entry_t *data = lsmash_malloc( sizeof(isom_group_assignment_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( sbgp->list, data ) < 0 ) + if( lsmash_list_add_entry( sbgp->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1931,7 +1930,7 @@ static int isom_read_chpl( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_chpl_entry_t *data = lsmash_malloc( sizeof(isom_chpl_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( chpl->list, data ) < 0 ) + if( lsmash_list_add_entry( chpl->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2093,7 +2092,7 @@ static int isom_read_trun( lsmash_file_t *file, isom_box_t *box, isom_box_t *par if( box->flags & ISOM_TR_FLAGS_FIRST_SAMPLE_FLAGS_PRESENT ) trun->first_sample_flags = isom_bs_get_sample_flags( bs ); if( trun->sample_count && has_optional_rows ) { - trun->optional = lsmash_create_entry_list(); + trun->optional = lsmash_list_create_simple(); if( !trun->optional ) return LSMASH_ERR_MEMORY_ALLOC; for( uint32_t i = 0; i < trun->sample_count; i++ ) @@ -2101,7 +2100,7 @@ static int isom_read_trun( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_trun_optional_row_t *data = lsmash_malloc( sizeof(isom_trun_optional_row_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( trun->optional, data ) < 0 ) + if( lsmash_list_add_entry( trun->optional, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2119,8 +2118,8 @@ static int isom_read_free( lsmash_file_t *file, isom_box_t *box, isom_box_t *par { if( file->fake_file_mode ) return isom_read_unknown_box( file, box, parent, level ); - isom_box_t *skip = lsmash_malloc_zero( sizeof(isom_box_t) ); - if( !skip ) + isom_skip_t *skip = ALLOCATE_BOX( skip ); + if( LSMASH_IS_NON_EXISTING_BOX( skip ) ) return LSMASH_ERR_MEMORY_ALLOC; isom_skip_box_rest( file->bs, box ); box->manager |= LSMASH_ABSENT_IN_FILE; @@ -2128,7 +2127,7 @@ static int isom_read_free( lsmash_file_t *file, isom_box_t *box, isom_box_t *par int ret = isom_add_print_func( file, skip, level ); if( ret < 0 ) { - lsmash_free( skip ); + isom_remove_box_by_itself( skip ); return ret; } return 0; @@ -2138,8 +2137,8 @@ static int isom_read_mdat( lsmash_file_t *file, isom_box_t *box, isom_box_t *par { if( file->fake_file_mode || !lsmash_check_box_type_identical( parent->type, LSMASH_BOX_TYPE_UNSPECIFIED ) ) return isom_read_unknown_box( file, box, parent, level ); - isom_box_t *mdat = lsmash_malloc_zero( sizeof(isom_box_t) ); - if( !mdat ) + isom_mdat_t *mdat = ALLOCATE_BOX( mdat ); + if( LSMASH_IS_NON_EXISTING_BOX( mdat ) ) return LSMASH_ERR_MEMORY_ALLOC; isom_skip_box_rest( file->bs, box ); box->manager |= LSMASH_ABSENT_IN_FILE; @@ -2148,7 +2147,7 @@ static int isom_read_mdat( lsmash_file_t *file, isom_box_t *box, isom_box_t *par int ret = isom_add_print_func( file, mdat, level ); if( ret < 0 ) { - lsmash_free( mdat ); + isom_remove_box_by_itself( mdat ); return ret; } return 0; @@ -2192,7 +2191,7 @@ static int isom_read_keys( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_keys_entry_t *data = lsmash_malloc( sizeof(isom_keys_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( keys->list, data ) < 0 ) + if( lsmash_list_add_entry( keys->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2384,7 +2383,7 @@ static int isom_read_tfra( lsmash_file_t *file, isom_box_t *box, isom_box_t *par tfra->length_size_of_sample_num = temp & 0x3; if( tfra->number_of_entry ) { - tfra->list = lsmash_create_entry_list(); + tfra->list = lsmash_list_create_simple(); if( !tfra->list ) return LSMASH_ERR_MEMORY_ALLOC; uint64_t (*bs_get_funcs[5])( lsmash_bs_t * ) = @@ -2405,7 +2404,7 @@ static int isom_read_tfra( lsmash_file_t *file, isom_box_t *box, isom_box_t *par isom_tfra_location_time_entry_t *data = lsmash_malloc( sizeof(isom_tfra_location_time_entry_t) ); if( !data ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( tfra->list, data ) < 0 ) + if( lsmash_list_add_entry( tfra->list, data ) < 0 ) { lsmash_free( data ); return LSMASH_ERR_MEMORY_ALLOC; @@ -2951,7 +2950,7 @@ int isom_read_file( lsmash_file_t *file ) lsmash_bs_reset_counter( bs ); if( file->flags & LSMASH_FILE_MODE_DUMP ) { - file->print = lsmash_create_entry_list(); + file->print = isom_printer_create_list(); if( !file->print ) return LSMASH_ERR_MEMORY_ALLOC; } diff --git a/core/summary.c b/core/summary.c index 7ef5a68..fb1770a 100644 --- a/core/summary.c +++ b/core/summary.c @@ -46,7 +46,7 @@ int lsmash_setup_AudioSpecificConfig( lsmash_audio_summary_t *summary ) lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)entry->data; if( !cs || cs->type != LSMASH_CODEC_SPECIFIC_DATA_TYPE_MP4SYS_DECODER_CONFIG ) continue; - lsmash_remove_entry_direct( &summary->opaque->list, entry, lsmash_destroy_codec_specific_data ); + lsmash_list_remove_entry_direct( &summary->opaque->list, entry ); } /* Create and add a new one. */ uint32_t data_length; @@ -71,7 +71,7 @@ int lsmash_setup_AudioSpecificConfig( lsmash_audio_summary_t *summary ) param->streamType = MP4SYS_STREAM_TYPE_AudioStream; int err = lsmash_set_mp4sys_decoder_specific_info( param, data, data_length ); lsmash_free( data ); - if( err < 0 || (err = lsmash_add_entry( &summary->opaque->list, cs )) < 0 ) + if( err < 0 || (err = lsmash_list_add_entry( &summary->opaque->list, cs )) < 0 ) { lsmash_destroy_codec_specific_data( cs ); return err; @@ -79,6 +79,25 @@ int lsmash_setup_AudioSpecificConfig( lsmash_audio_summary_t *summary ) return 0; } +static lsmash_codec_specific_list_t *summary_allocate_opaque( void ) +{ + lsmash_codec_specific_list_t *opaque = (lsmash_codec_specific_list_t *)lsmash_malloc_zero( sizeof(lsmash_codec_specific_list_t) ); + if( opaque ) + lsmash_list_init( &opaque->list, lsmash_destroy_codec_specific_data ); + return opaque; +} + +static void summary_deallocate_opaque +( + lsmash_codec_specific_list_t *opaque +) +{ + if( !opaque ) + return; + lsmash_list_remove_entries( &opaque->list ); + lsmash_free( opaque ); +} + lsmash_summary_t *lsmash_create_summary( lsmash_summary_type summary_type ) { size_t summary_size; @@ -97,7 +116,7 @@ lsmash_summary_t *lsmash_create_summary( lsmash_summary_type summary_type ) lsmash_summary_t *summary = (lsmash_summary_t *)lsmash_malloc_zero( summary_size ); if( !summary ) return NULL; - summary->opaque = (lsmash_codec_specific_list_t *)lsmash_malloc_zero( sizeof(lsmash_codec_specific_list_t) ); + summary->opaque = summary_allocate_opaque(); if( !summary->opaque ) { lsmash_free( summary ); @@ -112,17 +131,7 @@ void lsmash_cleanup_summary( lsmash_summary_t *summary ) { if( !summary ) return; - if( summary->opaque ) - { - for( lsmash_entry_t *entry = summary->opaque->list.head; entry; ) - { - lsmash_entry_t *next = entry->next; - lsmash_destroy_codec_specific_data( (lsmash_codec_specific_t *)entry->data ); - lsmash_free( entry ); - entry = next; - } - lsmash_free( summary->opaque ); - } + summary_deallocate_opaque( summary->opaque ); lsmash_free( summary ); } @@ -133,7 +142,7 @@ int lsmash_add_codec_specific_data( lsmash_summary_t *summary, lsmash_codec_spec lsmash_codec_specific_t *dup = isom_duplicate_codec_specific_data( specific ); if( !dup ) return LSMASH_ERR_NAMELESS; - if( lsmash_add_entry( &summary->opaque->list, dup ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, dup ) < 0 ) { lsmash_destroy_codec_specific_data( dup ); return LSMASH_ERR_MEMORY_ALLOC; diff --git a/core/timeline.c b/core/timeline.c index 15806d9..b64b755 100644 --- a/core/timeline.c +++ b/core/timeline.c @@ -107,10 +107,10 @@ isom_timeline_t *isom_timeline_create( void ) if( !timeline ) return NULL; timeline->class = &lsmash_timeline_class; - lsmash_init_entry_list( timeline->edit_list ); - lsmash_init_entry_list( timeline->chunk_list ); - lsmash_init_entry_list( timeline->info_list ); - lsmash_init_entry_list( timeline->bunch_list ); + lsmash_list_init_simple( timeline->edit_list ); + lsmash_list_init_simple( timeline->chunk_list ); + lsmash_list_init_simple( timeline->info_list ); + lsmash_list_init_simple( timeline->bunch_list ); return timeline; } @@ -118,10 +118,10 @@ void isom_timeline_destroy( isom_timeline_t *timeline ) { if( !timeline ) return; - lsmash_remove_entries( timeline->edit_list, NULL ); - lsmash_remove_entries( timeline->chunk_list, NULL ); /* chunk data must be already freed. */ - lsmash_remove_entries( timeline->info_list, NULL ); - lsmash_remove_entries( timeline->bunch_list, NULL ); + lsmash_list_remove_entries( timeline->edit_list ); + lsmash_list_remove_entries( timeline->chunk_list ); /* chunk data must be already freed. */ + lsmash_list_remove_entries( timeline->info_list ); + lsmash_list_remove_entries( timeline->bunch_list ); lsmash_free( timeline ); } @@ -129,7 +129,7 @@ void isom_remove_timelines( lsmash_file_t *file ) { if( LSMASH_IS_NON_EXISTING_BOX( file ) || !file->timeline ) return; - lsmash_remove_list( file->timeline, isom_timeline_destroy ); + lsmash_list_destroy( file->timeline ); } void lsmash_destruct_timeline( lsmash_root_t *root, uint32_t track_ID ) @@ -145,7 +145,7 @@ void lsmash_destruct_timeline( lsmash_root_t *root, uint32_t track_ID ) continue; if( timeline->track_ID == track_ID ) { - lsmash_remove_entry_direct( root->file->timeline, entry, isom_timeline_destroy ); + lsmash_list_remove_entry_direct( root->file->timeline, entry ); break; } } @@ -284,7 +284,7 @@ static int isom_add_sample_info_entry( isom_timeline_t *timeline, isom_sample_in isom_sample_info_t *dst_info = lsmash_malloc( sizeof(isom_sample_info_t) ); if( !dst_info ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( timeline->info_list, dst_info ) < 0 ) + if( lsmash_list_add_entry( timeline->info_list, dst_info ) < 0 ) { lsmash_free( dst_info ); return LSMASH_ERR_MEMORY_ALLOC; @@ -298,7 +298,7 @@ int isom_add_lpcm_bunch_entry( isom_timeline_t *timeline, isom_lpcm_bunch_t *src isom_lpcm_bunch_t *dst_bunch = lsmash_malloc( sizeof(isom_lpcm_bunch_t) ); if( !dst_bunch ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( timeline->bunch_list, dst_bunch ) < 0 ) + if( lsmash_list_add_entry( timeline->bunch_list, dst_bunch ) < 0 ) { lsmash_free( dst_bunch ); return LSMASH_ERR_MEMORY_ALLOC; @@ -312,7 +312,7 @@ static int isom_add_portable_chunk_entry( isom_timeline_t *timeline, isom_portab isom_portable_chunk_t *dst_chunk = lsmash_malloc( sizeof(isom_portable_chunk_t) ); if( !dst_chunk ) return LSMASH_ERR_MEMORY_ALLOC; - if( lsmash_add_entry( timeline->chunk_list, dst_chunk ) < 0 ) + if( lsmash_list_add_entry( timeline->chunk_list, dst_chunk ) < 0 ) { lsmash_free( dst_chunk ); return LSMASH_ERR_MEMORY_ALLOC; @@ -347,7 +347,7 @@ static isom_lpcm_bunch_t *isom_get_bunch( isom_timeline_t *timeline, uint32_t sa if( sample_number >= timeline->last_accessed_lpcm_bunch_first_sample_number && sample_number < timeline->last_accessed_lpcm_bunch_first_sample_number + timeline->last_accessed_lpcm_bunch_sample_count ) /* Get from the last accessed LPCM bunch. */ - return (isom_lpcm_bunch_t *)lsmash_get_entry_data( timeline->bunch_list, timeline->last_accessed_lpcm_bunch_number ); + return (isom_lpcm_bunch_t *)lsmash_list_get_entry_data( timeline->bunch_list, timeline->last_accessed_lpcm_bunch_number ); uint32_t first_sample_number_in_next_bunch; uint32_t bunch_number = 1; uint64_t bunch_dts; @@ -365,14 +365,14 @@ static isom_lpcm_bunch_t *isom_get_bunch( isom_timeline_t *timeline, uint32_t sa first_sample_number_in_next_bunch = 1; bunch_dts = 0; } - isom_lpcm_bunch_t *bunch = (isom_lpcm_bunch_t *)lsmash_get_entry_data( timeline->bunch_list, bunch_number++ ); + isom_lpcm_bunch_t *bunch = (isom_lpcm_bunch_t *)lsmash_list_get_entry_data( timeline->bunch_list, bunch_number++ ); if( !bunch ) return NULL; first_sample_number_in_next_bunch += bunch->sample_count; while( sample_number >= first_sample_number_in_next_bunch ) { bunch_dts += bunch->duration * bunch->sample_count; - bunch = (isom_lpcm_bunch_t *)lsmash_get_entry_data( timeline->bunch_list, bunch_number++ ); + bunch = (isom_lpcm_bunch_t *)lsmash_list_get_entry_data( timeline->bunch_list, bunch_number++ ); if( !bunch ) return NULL; first_sample_number_in_next_bunch += bunch->sample_count; @@ -393,14 +393,14 @@ static int isom_get_dts_from_info_list( isom_timeline_t *timeline, uint32_t samp *dts = 0; else if( sample_number == timeline->last_accessed_sample_number + 1 ) { - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, timeline->last_accessed_sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, timeline->last_accessed_sample_number ); if( !info ) return LSMASH_ERR_NAMELESS; *dts = timeline->last_accessed_sample_dts + info->duration; } else if( sample_number == timeline->last_accessed_sample_number - 1 ) { - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, timeline->last_accessed_sample_number - 1 ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, timeline->last_accessed_sample_number - 1 ); if( !info ) return LSMASH_ERR_NAMELESS; *dts = timeline->last_accessed_sample_dts - info->duration; @@ -433,7 +433,7 @@ static int isom_get_cts_from_info_list( isom_timeline_t *timeline, uint32_t samp int ret = isom_get_dts_from_info_list( timeline, sample_number, cts ); if( ret < 0 ) return ret; - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info ) return LSMASH_ERR_NAMELESS; *cts = isom_make_cts( *cts, info->offset, timeline->ctd_shift ); @@ -460,7 +460,7 @@ static int isom_get_cts_from_bunch_list( isom_timeline_t *timeline, uint32_t sam static int isom_get_sample_duration_from_info_list( isom_timeline_t *timeline, uint32_t sample_number, uint32_t *sample_duration ) { - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info ) return LSMASH_ERR_NAMELESS; *sample_duration = info->duration; @@ -478,7 +478,7 @@ static int isom_get_sample_duration_from_bunch_list( isom_timeline_t *timeline, static int isom_check_sample_existence_in_info_list( isom_timeline_t *timeline, uint32_t sample_number ) { - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info || !info->chunk ) return 0; return !!info->chunk->file; @@ -543,7 +543,7 @@ static lsmash_sample_t *isom_get_sample_from_media_timeline( isom_timeline_t *ti uint64_t dts; if( isom_get_dts_from_info_list( timeline, sample_number, &dts ) < 0 ) return NULL; - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info || !info->chunk ) return NULL; @@ -582,7 +582,7 @@ static int isom_get_sample_info_from_media_timeline( isom_timeline_t *timeline, int ret = isom_get_dts_from_info_list( timeline, sample_number, &dts ); if( ret < 0 ) return ret; - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info ) return LSMASH_ERR_NAMELESS; sample->dts = dts; @@ -603,7 +603,7 @@ static int isom_get_lpcm_sample_property_from_media_timeline( isom_timeline_t *t static int isom_get_sample_property_from_media_timeline( isom_timeline_t *timeline, uint32_t sample_number, lsmash_sample_property_t *prop ) { - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, sample_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number ); if( !info ) return LSMASH_ERR_NAMELESS; *prop = info->prop; @@ -691,7 +691,7 @@ static int isom_get_roll_recovery_grouping_info { uint32_t group_description_index = assignment->group_description_index; isom_sgpd_t *sgpd = isom_select_appropriate_sgpd( sgpd_roll, sgpd_frag_roll, &group_description_index ); - isom_roll_entry_t *roll_data = (isom_roll_entry_t *)lsmash_get_entry_data( sgpd->list, group_description_index ); + isom_roll_entry_t *roll_data = (isom_roll_entry_t *)lsmash_list_get_entry_data( sgpd->list, group_description_index ); if( roll_data ) { if( roll_data->roll_distance > 0 ) @@ -734,7 +734,7 @@ static int isom_get_random_access_point_grouping_info { uint32_t group_description_index = assignment->group_description_index; isom_sgpd_t *sgpd = isom_select_appropriate_sgpd( sgpd_rap, sgpd_frag_rap, &group_description_index ); - isom_rap_entry_t *rap_data = (isom_rap_entry_t *)lsmash_get_entry_data( sgpd->list, group_description_index ); + isom_rap_entry_t *rap_data = (isom_rap_entry_t *)lsmash_list_get_entry_data( sgpd->list, group_description_index ); if( rap_data ) { /* If this is not an open RAP, we treat it as an unknown RAP since non-IDR sample could make a closed GOP. */ @@ -770,7 +770,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) /* Create a timeline list if it doesn't exist. */ if( !file->timeline ) { - file->timeline = lsmash_create_entry_list(); + file->timeline = lsmash_list_create( isom_timeline_destroy ); if( !file->timeline ) return LSMASH_ERR_MEMORY_ALLOC; } @@ -819,11 +819,11 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) int movie_fragments_present = (LSMASH_IS_EXISTING_BOX( file->moov->mvex ) && file->moof_list.head); if( !movie_fragments_present && (!stts_entry || !stsc_entry || !stco_entry || !stco_entry->data || (next_stsc_entry && !next_stsc_entry->data)) ) goto fail; - isom_sample_entry_t *description = (isom_sample_entry_t *)lsmash_get_entry_data( &stsd->list, stsc_data ? stsc_data->sample_description_index : 1 ); + isom_sample_entry_t *description = (isom_sample_entry_t *)lsmash_list_get_entry_data( &stsd->list, stsc_data ? stsc_data->sample_description_index : 1 ); if( LSMASH_IS_NON_EXISTING_BOX( description ) ) goto fail; lsmash_entry_list_t *dref_list = LSMASH_IS_EXISTING_BOX( dref ) ? &dref->list : NULL; - isom_dref_entry_t *dref_entry = (isom_dref_entry_t *)lsmash_get_entry_data( dref_list, description->data_reference_index ); + isom_dref_entry_t *dref_entry = (isom_dref_entry_t *)lsmash_list_get_entry_data( dref_list, description->data_reference_index ); int all_sync = LSMASH_IS_NON_EXISTING_BOX( stss ); int large_presentation = stco->large_presentation || lsmash_check_box_type_identical( stco->type, ISOM_BOX_TYPE_CO64 ); int is_lpcm_audio = isom_is_lpcm_audio( description ); @@ -859,7 +859,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) { isom_elst_entry_t *edit = (isom_elst_entry_t *)lsmash_memdup( elst_entry->data, sizeof(isom_elst_entry_t) ); if( !edit - || lsmash_add_entry( timeline->edit_list, edit ) < 0 ) + || lsmash_list_add_entry( timeline->edit_list, edit ) < 0 ) { err = LSMASH_ERR_MEMORY_ALLOC; goto fail; @@ -1065,7 +1065,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) goto fail; stsc_data = (isom_stsc_entry_t *)stsc_entry->data; /* Update sample description. */ - description = (isom_sample_entry_t *)lsmash_get_entry_data( &stsd->list, stsc_data->sample_description_index ); + description = (isom_sample_entry_t *)lsmash_list_get_entry_data( &stsd->list, stsc_data->sample_description_index ); is_lpcm_audio = LSMASH_IS_EXISTING_BOX( description ) ? isom_is_lpcm_audio( description ) : 0; is_qt_fixed_comp_audio = LSMASH_IS_EXISTING_BOX( description ) ? isom_is_qt_fixed_compressed_audio( description ) : 0; if( is_qt_fixed_comp_audio ) @@ -1076,7 +1076,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) constant_sample_size = stsz ? stsz->sample_size : 0; } /* Reference media data. */ - dref_entry = (isom_dref_entry_t *)lsmash_get_entry_data( dref_list, LSMASH_IS_EXISTING_BOX( description ) ? description->data_reference_index : 0 ); + dref_entry = (isom_dref_entry_t *)lsmash_list_get_entry_data( dref_list, LSMASH_IS_EXISTING_BOX( description ) ? description->data_reference_index : 0 ); chunk.file = (!dref_entry || LSMASH_IS_NON_EXISTING_BOX( dref_entry->ref_file )) ? NULL : dref_entry->ref_file; } sample_number_in_chunk = samples_per_packet; @@ -1113,7 +1113,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) sample_number += samples_per_packet; packet_number += 1; } - isom_portable_chunk_t *last_chunk = lsmash_get_entry_data( timeline->chunk_list, timeline->chunk_list->entry_count ); + isom_portable_chunk_t *last_chunk = lsmash_list_get_entry_data( timeline->chunk_list, timeline->chunk_list->entry_count ); if( last_chunk ) { if( offset_from_chunk ) @@ -1121,7 +1121,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) else { /* Remove the last invalid chunk. */ - lsmash_remove_entry( timeline->chunk_list, timeline->chunk_list->entry_count, NULL ); + lsmash_list_remove_entry( timeline->chunk_list, timeline->chunk_list->entry_count ); --chunk_number; } } @@ -1202,10 +1202,10 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) sample_description_index = tfhd->sample_description_index; else sample_description_index = trex->default_sample_description_index; - description = (isom_sample_entry_t *)lsmash_get_entry_data( &stsd->list, sample_description_index ); + description = (isom_sample_entry_t *)lsmash_list_get_entry_data( &stsd->list, sample_description_index ); is_lpcm_audio = LSMASH_IS_EXISTING_BOX( description ) ? isom_is_lpcm_audio( description ) : 0; /* Reference media data. */ - dref_entry = (isom_dref_entry_t *)lsmash_get_entry_data( dref_list, LSMASH_IS_EXISTING_BOX( description ) ? description->data_reference_index : 0 ); + dref_entry = (isom_dref_entry_t *)lsmash_list_get_entry_data( dref_list, LSMASH_IS_EXISTING_BOX( description ) ? description->data_reference_index : 0 ); lsmash_file_t *ref_file = (!dref_entry || LSMASH_IS_NON_EXISTING_BOX( dref_entry->ref_file )) ? NULL : dref_entry->ref_file; /* Each track run can be considered as a chunk. * Here, we consider physically consecutive track runs as one chunk. */ @@ -1397,7 +1397,7 @@ int isom_timeline_construct( lsmash_root_t *root, uint32_t track_ID ) goto fail; /* No samples in this track. */ if( bunch.sample_count && (err = isom_add_lpcm_bunch_entry( timeline, &bunch )) < 0 ) goto fail; - if( (err = lsmash_add_entry( file->timeline, timeline )) < 0 ) + if( (err = lsmash_list_add_entry( file->timeline, timeline )) < 0 ) goto fail; /* Finish timeline construction. */ timeline->sample_count = sample_count; @@ -1500,7 +1500,7 @@ int lsmash_get_composition_to_decode_shift_from_media_timeline( lsmash_root_t *r static int isom_get_closest_past_random_accessible_point_from_media_timeline( isom_timeline_t *timeline, uint32_t sample_number, uint32_t *rap_number ) { - lsmash_entry_t *entry = lsmash_get_entry( timeline->info_list, sample_number-- ); + lsmash_entry_t *entry = lsmash_list_get_entry( timeline->info_list, sample_number-- ); if( !entry || !entry->data ) return LSMASH_ERR_NAMELESS; @@ -1520,7 +1520,7 @@ static int isom_get_closest_past_random_accessible_point_from_media_timeline( is static inline int isom_get_closest_future_random_accessible_point_from_media_timeline( isom_timeline_t *timeline, uint32_t sample_number, uint32_t *rap_number ) { - lsmash_entry_t *entry = lsmash_get_entry( timeline->info_list, sample_number++ ); + lsmash_entry_t *entry = lsmash_list_get_entry( timeline->info_list, sample_number++ ); if( !entry || !entry->data ) return LSMASH_ERR_NAMELESS; @@ -1587,7 +1587,7 @@ int lsmash_get_closest_random_accessible_point_detail_from_media_timeline( lsmas int ret = isom_get_closest_random_accessible_point_from_media_timeline_internal( timeline, sample_number, rap_number ); if( ret < 0 ) return ret; - isom_sample_info_t *info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, *rap_number ); + isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, *rap_number ); if( !info ) return LSMASH_ERR_NAMELESS; if( ra_flags ) @@ -1614,7 +1614,7 @@ int lsmash_get_closest_random_accessible_point_detail_from_media_timeline( lsmas dts += info->duration; if( rap_cts <= dts ) break; /* leading samples of this random accessible point must not be present more. */ - info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, current_sample_number++ ); + info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, current_sample_number++ ); if( !info ) break; uint64_t cts = isom_make_cts_adjust( dts, info->offset, timeline->ctd_shift ); @@ -1631,7 +1631,7 @@ int lsmash_get_closest_random_accessible_point_detail_from_media_timeline( lsmas if( isom_get_closest_past_random_accessible_point_from_media_timeline( timeline, prev_rap_number - 1, &prev_rap_number ) < 0 ) /* The previous random accessible point is not present. */ return 0; - info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, prev_rap_number ); + info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, prev_rap_number ); if( !info ) return LSMASH_ERR_NAMELESS; if( !(info->prop.ra_flags & ISOM_SAMPLE_RANDOM_ACCESS_FLAG_GDR) ) @@ -1704,7 +1704,7 @@ int lsmash_get_closest_random_accessible_point_detail_from_media_timeline( lsmas if( isom_get_closest_past_random_accessible_point_from_media_timeline( timeline, prev_rap_number - 1, &prev_rap_number ) < 0 ) /* The previous random accessible point is not present. */ return 0; - info = (isom_sample_info_t *)lsmash_get_entry_data( timeline->info_list, prev_rap_number ); + info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, prev_rap_number ); if( !info ) return LSMASH_ERR_NAMELESS; if( !(info->prop.ra_flags & ISOM_SAMPLE_RANDOM_ACCESS_FLAG_GDR) || sample_number >= info->prop.post_roll.complete ) @@ -1771,7 +1771,7 @@ isom_elst_entry_t *isom_timelime_get_explicit_timeline_map isom_timeline_t *timeline = isom_get_timeline( root, track_ID ); if( !timeline ) return NULL; - return lsmash_get_entry_data( timeline->edit_list, edit_number ); + return lsmash_list_get_entry_data( timeline->edit_list, edit_number ); } uint32_t isom_timelime_count_explicit_timeline_map @@ -1800,7 +1800,7 @@ int lsmash_copy_timeline_map( lsmash_root_t *dst, uint32_t dst_track_ID, lsmash_ || dst_trak->mdia->mdhd->timescale == 0 ) return LSMASH_ERR_NAMELESS; if( LSMASH_IS_EXISTING_BOX( dst_trak->edts->elst ) ) - lsmash_remove_entries( dst_trak->edts->elst->list, NULL ); + lsmash_list_remove_entries( dst_trak->edts->elst->list ); uint32_t src_movie_timescale; uint32_t src_media_timescale; uint64_t src_track_duration; @@ -1883,7 +1883,7 @@ int lsmash_copy_timeline_map( lsmash_root_t *dst, uint32_t dst_track_ID, lsmash_ dst_data->media_time = (src_data->media_time + media_time_shift) * ((double)dst_media_timescale / src_media_timescale) + 0.5; else dst_data->media_time = ISOM_EDIT_MODE_EMPTY; - if( lsmash_add_entry( dst_list, dst_data ) < 0 ) + if( lsmash_list_add_entry( dst_list, dst_data ) < 0 ) { lsmash_free( dst_data ); return LSMASH_ERR_MEMORY_ALLOC; diff --git a/importer/a52_imp.c b/importer/a52_imp.c index dbc7d3c..c403251 100644 --- a/importer/a52_imp.c +++ b/importer/a52_imp.c @@ -111,7 +111,7 @@ static lsmash_audio_summary_t *ac3_create_summary( ac3_info_t *info ) } cs->data.unstructured = lsmash_create_ac3_specific_info( &info->dac3_param, &cs->size ); if( !cs->data.unstructured - || lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( cs ); @@ -159,7 +159,7 @@ static int ac3_importer_get_accessunit( importer_t *importer, uint32_t track_num return LSMASH_ERR_NAMELESS; if( track_number != 1 ) return LSMASH_ERR_FUNCTION_PARAM; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; ac3_importer_t *ac3_imp = (ac3_importer_t *)importer->info; @@ -260,7 +260,7 @@ static int ac3_importer_probe( importer_t *importer ) err = LSMASH_ERR_NAMELESS; goto fail; } - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; @@ -492,7 +492,7 @@ static int eac3_importer_get_accessunit( importer_t *importer, uint32_t track_nu return LSMASH_ERR_NAMELESS; if( track_number != 1 ) return LSMASH_ERR_FUNCTION_PARAM; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; eac3_importer_t *eac3_imp = (eac3_importer_t *)importer->info; @@ -579,7 +579,7 @@ static lsmash_audio_summary_t *eac3_create_summary( eac3_importer_t *eac3_imp ) } cs->data.unstructured = lsmash_create_eac3_specific_info( &info->dec3_param, &cs->size ); if( !cs->data.unstructured - || lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( cs ); @@ -617,7 +617,7 @@ static int eac3_importer_probe( importer_t *importer ) if( importer->status != IMPORTER_EOF ) importer->status = IMPORTER_OK; eac3_imp->au_number = 0; - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; diff --git a/importer/adts_imp.c b/importer/adts_imp.c index 2fd270a..699d35c 100644 --- a/importer/adts_imp.c +++ b/importer/adts_imp.c @@ -291,7 +291,7 @@ static lsmash_audio_summary_t *mp4sys_adts_create_summary return NULL; } lsmash_free( data ); - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( specific ); @@ -320,7 +320,7 @@ static int mp4sys_adts_get_accessunit return IMPORTER_EOF; if( current_status == IMPORTER_CHANGE ) { - lsmash_entry_t *entry = lsmash_get_entry( importer->summaries, track_number ); + lsmash_entry_t *entry = lsmash_list_get_entry( importer->summaries, track_number ); if( !entry || !entry->data ) return LSMASH_ERR_NAMELESS; lsmash_audio_summary_t *summary = mp4sys_adts_create_summary( &adts_imp->header ); @@ -481,7 +481,7 @@ static int mp4sys_adts_probe goto fail; } /* importer status */ - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; diff --git a/importer/als_imp.c b/importer/als_imp.c index 3fbca06..f2705c2 100644 --- a/importer/als_imp.c +++ b/importer/als_imp.c @@ -215,7 +215,7 @@ static int mp4a_als_importer_get_accessunit( importer_t *importer, uint32_t trac return LSMASH_ERR_NAMELESS; if( track_number != 1 ) return LSMASH_ERR_FUNCTION_PARAM; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; mp4a_als_importer_t *als_imp = (mp4a_als_importer_t *)importer->info; @@ -317,7 +317,7 @@ static lsmash_audio_summary_t *als_create_summary( lsmash_bs_t *bs, als_specific goto fail; } lsmash_free( data ); - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_destroy_codec_specific_data( specific ); goto fail; @@ -345,7 +345,7 @@ static int mp4a_als_importer_probe( importer_t *importer ) } /* importer status */ als_imp->samples_in_frame = summary->samples_in_frame; - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; diff --git a/importer/amr_imp.c b/importer/amr_imp.c index fd910df..7a1dca1 100644 --- a/importer/amr_imp.c +++ b/importer/amr_imp.c @@ -194,7 +194,7 @@ static int amr_create_damr cs->size = AMR_DAMR_LENGTH; lsmash_bs_cleanup( bs ); if( !cs->data.unstructured - || lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_destroy_codec_specific_data( cs ); return LSMASH_ERR_MEMORY_ALLOC; @@ -222,7 +222,7 @@ static lsmash_audio_summary_t *amr_create_summary summary->samples_in_frame = (160 << wb); summary->sbr_mode = MP4A_AAC_SBR_NOT_SPECIFIED; /* no effect */ if( amr_create_damr( summary, wb ) < 0 - || lsmash_add_entry( importer->summaries, summary ) < 0 ) + || lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); return NULL; diff --git a/importer/dts_imp.c b/importer/dts_imp.c index 088ec61..cba43d4 100644 --- a/importer/dts_imp.c +++ b/importer/dts_imp.c @@ -207,7 +207,7 @@ static int dts_importer_get_accessunit( importer_t *importer, uint32_t track_num return LSMASH_ERR_NAMELESS; if( track_number != 1 ) return LSMASH_ERR_FUNCTION_PARAM; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; dts_importer_t *dts_imp = (dts_importer_t *)importer->info; @@ -254,7 +254,7 @@ static lsmash_audio_summary_t *dts_create_summary( dts_info_t *info ) } specific->data.unstructured = lsmash_create_dts_specific_info( param, &specific->size ); if( !specific->data.unstructured - || lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( specific ); @@ -327,7 +327,7 @@ static int dts_importer_probe( importer_t *importer ) if( importer->status != IMPORTER_EOF ) importer->status = IMPORTER_OK; dts_imp->au_number = 0; - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; @@ -347,7 +347,7 @@ static uint32_t dts_importer_get_last_delta( importer_t* importer, uint32_t trac dts_importer_t *dts_imp = (dts_importer_t *)importer->info; if( !dts_imp || track_number != 1 || importer->status != IMPORTER_EOF || dts_imp->au_length ) return 0; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return 0; return (summary->frequency * dts_imp->info.frame_duration) / dts_imp->info.ddts_param.DTSSamplingFrequency; diff --git a/importer/importer.c b/importer/importer.c index 902390b..78f4f2d 100644 --- a/importer/importer.c +++ b/importer/importer.c @@ -81,7 +81,7 @@ importer_t *lsmash_importer_alloc( lsmash_root_t *root ) if( !importer ) return NULL; importer->root = root; - importer->summaries = lsmash_create_entry_list(); + importer->summaries = lsmash_list_create( lsmash_cleanup_summary ); if( !importer->summaries ) { lsmash_destroy_root( importer->root ); @@ -98,7 +98,7 @@ void lsmash_importer_destroy( importer_t *importer ) lsmash_file_t *file = importer->file; if( importer->funcs.cleanup ) importer->funcs.cleanup( importer ); - lsmash_remove_list( importer->summaries, lsmash_cleanup_summary ); + lsmash_list_destroy( importer->summaries ); lsmash_free( importer ); /* Prevent freeing this already freed importer in file's destructor again. */ if( file && file->importer ) @@ -245,7 +245,7 @@ lsmash_summary_t *lsmash_duplicate_summary( importer_t *importer, uint32_t track { if( !importer ) return NULL; - lsmash_summary_t *src_summary = lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_summary_t *src_summary = lsmash_list_get_entry_data( importer->summaries, track_number ); if( !src_summary ) return NULL; lsmash_summary_t *summary = lsmash_create_summary( src_summary->summary_type ); @@ -271,7 +271,7 @@ lsmash_summary_t *lsmash_duplicate_summary( importer_t *importer, uint32_t track if( !src_specific ) continue; lsmash_codec_specific_t *dup = isom_duplicate_codec_specific_data( src_specific ); - if( lsmash_add_entry( &summary->opaque->list, dup ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, dup ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( dup ); diff --git a/importer/isobm_imp.c b/importer/isobm_imp.c index fb930b9..7e856bc 100644 --- a/importer/isobm_imp.c +++ b/importer/isobm_imp.c @@ -107,8 +107,8 @@ static int isobm_importer_get_accessunit( importer_t *importer, uint32_t track_n lsmash_delete_sample( sample ); return LSMASH_ERR_NAMELESS; } - lsmash_remove_entry( importer->summaries, track_number, lsmash_cleanup_summary ); - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + lsmash_list_remove_entry( importer->summaries, track_number ); + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_delete_sample( sample ); lsmash_cleanup_summary( (lsmash_summary_t *)summary ); @@ -164,7 +164,7 @@ static int isobm_importer_probe( importer_t *importer ) goto fail; } lsmash_summary_t *summary = lsmash_get_summary( root, isobm_imp->track_ID, 1 ); - if( (err = lsmash_add_entry( importer->summaries, summary )) < 0 ) + if( (err = lsmash_list_add_entry( importer->summaries, summary )) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); goto fail; @@ -201,7 +201,7 @@ static int isobm_importer_construct_timeline( importer_t *importer, uint32_t tra return err; if( importer->is_adhoc_open ) { - lsmash_summary_t *summary = lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_summary_t *summary = lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; summary->max_au_length = lsmash_get_max_sample_size_in_media_timeline( root, track_ID ); diff --git a/importer/mp3_imp.c b/importer/mp3_imp.c index 0da8742..5b75212 100644 --- a/importer/mp3_imp.c +++ b/importer/mp3_imp.c @@ -192,7 +192,7 @@ static lsmash_audio_summary_t *mp4sys_mp3_create_summary( mp4sys_mp3_header_t *h } lsmash_free( data ); #endif - if( lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( specific ); @@ -296,7 +296,7 @@ static int mp4sys_mp3_get_accessunit( importer_t *importer, uint32_t track_numbe return IMPORTER_EOF; if( current_status == IMPORTER_CHANGE ) { - lsmash_entry_t *entry = lsmash_get_entry( importer->summaries, track_number ); + lsmash_entry_t *entry = lsmash_list_get_entry( importer->summaries, track_number ); if( !entry || !entry->data ) return LSMASH_ERR_NAMELESS; lsmash_audio_summary_t *summary = mp4sys_mp3_create_summary( header, 1 ); /* FIXME: use legacy mode. */ @@ -475,7 +475,7 @@ static int mp4sys_mp3_probe( importer_t *importer ) goto fail; } /* importer status */ - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; diff --git a/importer/nalu_imp.c b/importer/nalu_imp.c index 495442e..64378d8 100644 --- a/importer/nalu_imp.c +++ b/importer/nalu_imp.c @@ -64,7 +64,7 @@ static void remove_h264_importer( h264_importer_t *h264_imp ) { if( !h264_imp ) return; - lsmash_remove_entries( h264_imp->avcC_list, lsmash_destroy_codec_specific_data ); + lsmash_list_remove_entries( h264_imp->avcC_list ); h264_cleanup_parser( &h264_imp->info ); lsmash_free( h264_imp->ts_list.timestamp ); lsmash_free( h264_imp ); @@ -86,7 +86,7 @@ static h264_importer_t *create_h264_importer( importer_t *importer ) remove_h264_importer( h264_imp ); return NULL; } - lsmash_init_entry_list( h264_imp->avcC_list ); + lsmash_list_init( h264_imp->avcC_list, lsmash_destroy_codec_specific_data ); return h264_imp; } @@ -151,7 +151,7 @@ static lsmash_video_summary_t *h264_create_summary } cs->data.unstructured = lsmash_create_h264_specific_info( param, &cs->size ); if( !cs->data.unstructured - || lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( cs ); @@ -194,7 +194,7 @@ static int h264_store_codec_specific lsmash_destroy_codec_specific_data( dst_cs ); return LSMASH_ERR_NAMELESS; } - if( lsmash_add_entry( h264_imp->avcC_list, dst_cs ) < 0 ) + if( lsmash_list_add_entry( h264_imp->avcC_list, dst_cs ) < 0 ) { lsmash_destroy_codec_specific_data( dst_cs ); return LSMASH_ERR_MEMORY_ALLOC; @@ -421,15 +421,15 @@ static int h264_importer_get_accessunit if( current_status == IMPORTER_CHANGE ) { /* Update the active summary. */ - lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_get_entry_data( h264_imp->avcC_list, ++ h264_imp->avcC_number ); + lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_list_get_entry_data( h264_imp->avcC_list, ++ h264_imp->avcC_number ); if( !cs ) return LSMASH_ERR_NAMELESS; lsmash_h264_specific_parameters_t *avcC_param = (lsmash_h264_specific_parameters_t *)cs->data.structured; lsmash_video_summary_t *summary = h264_create_summary( avcC_param, &info->sps, h264_imp->max_au_length ); if( !summary ) return LSMASH_ERR_NAMELESS; - lsmash_remove_entry( importer->summaries, track_number, lsmash_cleanup_summary ); - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + lsmash_list_remove_entry( importer->summaries, track_number ); + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); return LSMASH_ERR_MEMORY_ALLOC; @@ -700,7 +700,7 @@ static lsmash_video_summary_t *h264_setup_first_summary ) { h264_importer_t *h264_imp = (h264_importer_t *)importer->info; - lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_get_entry_data( h264_imp->avcC_list, ++ h264_imp->avcC_number ); + lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_list_get_entry_data( h264_imp->avcC_list, ++ h264_imp->avcC_number ); if( !cs || !cs->data.structured ) { lsmash_destroy_codec_specific_data( cs ); @@ -713,7 +713,7 @@ static lsmash_video_summary_t *h264_setup_first_summary lsmash_destroy_codec_specific_data( cs ); return NULL; } - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); return NULL; @@ -867,15 +867,15 @@ static int h264_importer_probe( importer_t *importer ) memset( &info->slice, 0, sizeof(h264_slice_info_t) ); memset( &info->sps, 0, sizeof(h264_sps_t) ); memset( &info->pps, 0, sizeof(h264_pps_t) ); - lsmash_remove_entries( info->avcC_param.parameter_sets->sps_list, isom_remove_dcr_ps ); - lsmash_remove_entries( info->avcC_param.parameter_sets->pps_list, isom_remove_dcr_ps ); - lsmash_remove_entries( info->avcC_param.parameter_sets->spsext_list, isom_remove_dcr_ps ); + lsmash_list_remove_entries( info->avcC_param.parameter_sets->sps_list ); + lsmash_list_remove_entries( info->avcC_param.parameter_sets->pps_list ); + lsmash_list_remove_entries( info->avcC_param.parameter_sets->spsext_list ); lsmash_destroy_h264_parameter_sets( &info->avcC_param_next ); return 0; fail: remove_h264_importer( h264_imp ); importer->info = NULL; - lsmash_remove_entries( importer->summaries, lsmash_cleanup_summary ); + lsmash_list_remove_entries( importer->summaries ); return err; } @@ -928,7 +928,7 @@ static void remove_hevc_importer( hevc_importer_t *hevc_imp ) { if( !hevc_imp ) return; - lsmash_remove_entries( hevc_imp->hvcC_list, lsmash_destroy_codec_specific_data ); + lsmash_list_remove_entries( hevc_imp->hvcC_list ); hevc_cleanup_parser( &hevc_imp->info ); lsmash_free( hevc_imp->ts_list.timestamp ); lsmash_free( hevc_imp ); @@ -950,7 +950,7 @@ static hevc_importer_t *create_hevc_importer( importer_t *importer ) remove_hevc_importer( hevc_imp ); return NULL; } - lsmash_init_entry_list( hevc_imp->hvcC_list ); + lsmash_list_init( hevc_imp->hvcC_list, lsmash_destroy_codec_specific_data ); hevc_imp->info.eos = 1; return hevc_imp; } @@ -1017,7 +1017,7 @@ static lsmash_video_summary_t *hevc_create_summary } specific->data.unstructured = lsmash_create_hevc_specific_info( param, &specific->size ); if( !specific->data.unstructured - || lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( specific ); @@ -1061,7 +1061,7 @@ static int hevc_store_codec_specific lsmash_destroy_codec_specific_data( dst_cs ); return LSMASH_ERR_NAMELESS; } - if( lsmash_add_entry( hevc_imp->hvcC_list, dst_cs ) < 0 ) + if( lsmash_list_add_entry( hevc_imp->hvcC_list, dst_cs ) < 0 ) { lsmash_destroy_codec_specific_data( dst_cs ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1279,15 +1279,15 @@ static int hevc_importer_get_accessunit( importer_t *importer, uint32_t track_nu if( current_status == IMPORTER_CHANGE ) { /* Update the active summary. */ - lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_get_entry_data( hevc_imp->hvcC_list, ++ hevc_imp->hvcC_number ); + lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_list_get_entry_data( hevc_imp->hvcC_list, ++ hevc_imp->hvcC_number ); if( !cs ) return LSMASH_ERR_NAMELESS; lsmash_hevc_specific_parameters_t *hvcC_param = (lsmash_hevc_specific_parameters_t *)cs->data.structured; lsmash_video_summary_t *summary = hevc_create_summary( hvcC_param, &info->sps, hevc_imp->max_au_length ); if( !summary ) return LSMASH_ERR_NAMELESS; - lsmash_remove_entry( importer->summaries, track_number, lsmash_cleanup_summary ); - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + lsmash_list_remove_entry( importer->summaries, track_number ); + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); return LSMASH_ERR_MEMORY_ALLOC; @@ -1359,7 +1359,7 @@ static lsmash_video_summary_t *hevc_setup_first_summary ) { hevc_importer_t *hevc_imp = (hevc_importer_t *)importer->info; - lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_get_entry_data( hevc_imp->hvcC_list, ++ hevc_imp->hvcC_number ); + lsmash_codec_specific_t *cs = (lsmash_codec_specific_t *)lsmash_list_get_entry_data( hevc_imp->hvcC_list, ++ hevc_imp->hvcC_number ); if( !cs || !cs->data.structured ) { lsmash_destroy_codec_specific_data( cs ); @@ -1372,7 +1372,7 @@ static lsmash_video_summary_t *hevc_setup_first_summary lsmash_destroy_codec_specific_data( cs ); return NULL; } - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); return NULL; @@ -1527,13 +1527,13 @@ static int hevc_importer_probe( importer_t *importer ) memset( &info->sps, 0, sizeof(hevc_sps_t) ); memset( &info->pps, 0, SIZEOF_PPS_EXCLUDING_HEAP ); for( int i = 0; i < HEVC_DCR_NALU_TYPE_NUM; i++ ) - lsmash_remove_entries( info->hvcC_param.parameter_arrays->ps_array[i].list, isom_remove_dcr_ps ); + lsmash_list_remove_entries( info->hvcC_param.parameter_arrays->ps_array[i].list ); lsmash_destroy_hevc_parameter_arrays( &info->hvcC_param_next ); return 0; fail: remove_hevc_importer( hevc_imp ); importer->info = NULL; - lsmash_remove_entries( importer->summaries, lsmash_cleanup_summary ); + lsmash_list_remove_entries( importer->summaries ); return err; } diff --git a/importer/vc1_imp.c b/importer/vc1_imp.c index ff7995e..aad8c16 100644 --- a/importer/vc1_imp.c +++ b/importer/vc1_imp.c @@ -328,7 +328,7 @@ static lsmash_video_summary_t *vc1_create_summary( vc1_info_t *info, vc1_sequenc } specific->data.unstructured = lsmash_create_vc1_specific_info( &info->dvc1_param, &specific->size ); if( !specific->data.unstructured - || lsmash_add_entry( &summary->opaque->list, specific ) < 0 ) + || lsmash_list_add_entry( &summary->opaque->list, specific ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); lsmash_destroy_codec_specific_data( specific ); @@ -499,7 +499,7 @@ static int vc1_importer_probe( importer_t *importer ) err = LSMASH_ERR_NAMELESS; goto fail; } - if( lsmash_add_entry( importer->summaries, summary ) < 0 ) + if( lsmash_list_add_entry( importer->summaries, summary ) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); err = LSMASH_ERR_MEMORY_ALLOC; @@ -520,7 +520,7 @@ static int vc1_importer_probe( importer_t *importer ) fail: remove_vc1_importer( vc1_imp ); importer->info = NULL; - lsmash_remove_entries( importer->summaries, lsmash_cleanup_summary ); + lsmash_list_remove_entries( importer->summaries ); return err; } diff --git a/importer/wave_imp.c b/importer/wave_imp.c index a5bad0b..2c00570 100644 --- a/importer/wave_imp.c +++ b/importer/wave_imp.c @@ -113,7 +113,7 @@ static int wave_importer_get_accessunit( importer_t *importer, uint32_t track_nu return LSMASH_ERR_NAMELESS; if( track_number != 1 ) return LSMASH_ERR_FUNCTION_PARAM; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; wave_importer_t *wave_imp = (wave_importer_t *)importer->info; @@ -211,7 +211,7 @@ static lsmash_audio_summary_t *wave_create_summary( waveformat_extensible_t *fmt lpcm->format_flags |= QT_AUDIO_FORMAT_FLAG_ALIGNED_HIGH; if( summary->sample_size > 8 ) lpcm->format_flags |= QT_AUDIO_FORMAT_FLAG_SIGNED_INTEGER; - if( lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_destroy_codec_specific_data( cs ); goto fail; @@ -233,7 +233,7 @@ static lsmash_audio_summary_t *wave_create_summary( waveformat_extensible_t *fmt layout->channelLayoutTag = QT_CHANNEL_LAYOUT_UNKNOWN | wfx->nChannels; layout->channelBitmap = 0; } - if( lsmash_add_entry( &summary->opaque->list, cs ) < 0 ) + if( lsmash_list_add_entry( &summary->opaque->list, cs ) < 0 ) { lsmash_destroy_codec_specific_data( cs ); goto fail; @@ -341,7 +341,7 @@ static int wave_importer_probe( importer_t *importer ) err = LSMASH_ERR_NAMELESS; goto fail; } - if( (err = lsmash_add_entry( importer->summaries, summary )) < 0 ) + if( (err = lsmash_list_add_entry( importer->summaries, summary )) < 0 ) { lsmash_cleanup_summary( (lsmash_summary_t *)summary ); goto fail; @@ -364,7 +364,7 @@ static uint32_t wave_importer_get_last_delta( importer_t *importer, uint32_t tra wave_importer_t *wave_imp = (wave_importer_t *)importer->info; if( !wave_imp || track_number != 1 || importer->status != IMPORTER_EOF ) return 0; - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return 0; return wave_imp->number_of_samples / summary->samples_in_frame >= wave_imp->au_number @@ -374,7 +374,7 @@ static uint32_t wave_importer_get_last_delta( importer_t *importer, uint32_t tra static int wave_importer_construct_timeline( importer_t *importer, uint32_t track_number ) { - lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_get_entry_data( importer->summaries, track_number ); + lsmash_audio_summary_t *summary = (lsmash_audio_summary_t *)lsmash_list_get_entry_data( importer->summaries, track_number ); if( !summary ) return LSMASH_ERR_NAMELESS; isom_timeline_t *timeline = isom_timeline_create(); @@ -384,7 +384,8 @@ static int wave_importer_construct_timeline( importer_t *importer, uint32_t trac lsmash_file_t *file = importer->file; if( !file->timeline ) { - file->timeline = lsmash_create_entry_list(); + /* TODO: this is not a proper place. It should be enclosed in isom_timeline_create(). */ + file->timeline = lsmash_list_create( isom_timeline_destroy ); if( !file->timeline ) { err = LSMASH_ERR_MEMORY_ALLOC; @@ -424,7 +425,7 @@ static int wave_importer_construct_timeline( importer_t *importer, uint32_t trac if( (err = isom_add_lpcm_bunch_entry( timeline, &bunch )) < 0 ) goto fail; } - if( (err = lsmash_add_entry( file->timeline, timeline )) < 0 ) + if( (err = lsmash_list_add_entry( file->timeline, timeline )) < 0 ) goto fail; return 0; fail: -- 2.11.4.GIT