@@ -74,7 +74,7 @@ typedef struct IMFAssetLocator {
7474 */
7575typedef struct IMFAssetLocatorMap {
7676 uint8_t asset_count ;
77- IMFAssetLocator * * assets ;
77+ IMFAssetLocator * assets ;
7878} IMFAssetLocatorMap ;
7979
8080typedef struct IMFVirtualTrackResourcePlaybackCtx {
@@ -184,34 +184,36 @@ static int parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
184184 av_log (s , AV_LOG_ERROR , "Unable to parse asset map XML - missing AssetList node\n" );
185185 return AVERROR_INVALIDDATA ;
186186 }
187-
187+ asset_map -> assets = av_realloc_f (asset_map -> assets ,
188+ xmlChildElementCount (node ),
189+ sizeof (IMFAssetLocator ));
190+ if (!asset_map -> assets ) {
191+ av_log (NULL , AV_LOG_PANIC , "Cannot allocate IMF asset locators\n" );
192+ return AVERROR (ENOMEM );
193+ }
194+ asset_map -> asset_count = 0 ;
188195 node = xmlFirstElementChild (node );
189196 while (node ) {
190197 if (av_strcasecmp (node -> name , "Asset" ) != 0 )
191198 continue ;
192199
193- asset = av_malloc (sizeof (IMFAssetLocator ));
194- if (!asset )
195- return AVERROR (ENOMEM );
200+ asset = & (asset_map -> assets [asset_map -> asset_count ]);
196201
197202 if (ff_xml_read_UUID (ff_xml_get_child_element_by_name (node , "Id" ), asset -> uuid )) {
198203 av_log (s , AV_LOG_ERROR , "Could not parse UUID from asset in asset map.\n" );
199- ret = AVERROR_INVALIDDATA ;
200- goto clean_up_asset ;
204+ return AVERROR_INVALIDDATA ;
201205 }
202206
203207 av_log (s , AV_LOG_DEBUG , "Found asset id: " FF_UUID_FORMAT "\n" , UID_ARG (asset -> uuid ));
204208
205209 if (!(node = ff_xml_get_child_element_by_name (node , "ChunkList" ))) {
206210 av_log (s , AV_LOG_ERROR , "Unable to parse asset map XML - missing ChunkList node\n" );
207- ret = AVERROR_INVALIDDATA ;
208- goto clean_up_asset ;
211+ return AVERROR_INVALIDDATA ;
209212 }
210213
211214 if (!(node = ff_xml_get_child_element_by_name (node , "Chunk" ))) {
212215 av_log (s , AV_LOG_ERROR , "Unable to parse asset map XML - missing Chunk node\n" );
213- ret = AVERROR_INVALIDDATA ;
214- goto clean_up_asset ;
216+ return AVERROR_INVALIDDATA ;
215217 }
216218
217219 uri = xmlNodeGetContent (ff_xml_get_child_element_by_name (node , "Path" ));
@@ -222,28 +224,13 @@ static int parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
222224 xmlFree (uri );
223225 if (!asset -> absolute_uri ) {
224226 av_log (NULL , AV_LOG_PANIC , "Cannot allocate asset locator absolute URI\n" );
225- ret = AVERROR (ENOMEM );
226- goto clean_up_asset ;
227+ return AVERROR (ENOMEM );
227228 }
228229
229230 av_log (s , AV_LOG_DEBUG , "Found asset absolute URI: %s\n" , asset -> absolute_uri );
230231
231- node = xmlNextElementSibling (node -> parent -> parent );
232-
233- asset_map -> assets = av_realloc_f (asset_map -> assets ,
234- asset_map -> asset_count + 1 ,
235- sizeof (IMFAssetLocator ));
236- if (!asset_map -> assets ) {
237- av_log (NULL , AV_LOG_PANIC , "Cannot allocate IMF asset locators\n" );
238- ret = AVERROR (ENOMEM );
239- goto clean_up_asset ;
240- }
241- asset_map -> assets [asset_map -> asset_count ++ ] = asset ;
242- continue ;
243-
244- clean_up_asset :
245- av_freep (& asset );
246- return ret ;
232+ asset_map -> asset_count ++ ;
233+ node = xmlNextElementSibling (node );
247234 }
248235
249236 return ret ;
@@ -275,8 +262,7 @@ static void imf_asset_locator_map_free(IMFAssetLocatorMap *asset_map)
275262 return ;
276263
277264 for (int i = 0 ; i < asset_map -> asset_count ; ++ i ) {
278- av_free (asset_map -> assets [i ]-> absolute_uri );
279- av_free (asset_map -> assets [i ]);
265+ av_free (asset_map -> assets [i ].absolute_uri );
280266 }
281267
282268 av_freep (& asset_map -> assets );
@@ -360,12 +346,9 @@ static int parse_assetmap(AVFormatContext *s, const char *url, AVIOContext *in)
360346
361347static IMFAssetLocator * find_asset_map_locator (IMFAssetLocatorMap * asset_map , FFUUID uuid )
362348{
363- IMFAssetLocator * asset_locator ;
364- for (int i = 0 ; i < asset_map -> asset_count ; ++ i ) {
365- asset_locator = asset_map -> assets [i ];
366- if (memcmp (asset_map -> assets [i ]-> uuid , uuid , 16 ) == 0 )
367- return asset_locator ;
368- }
349+ for (int i = 0 ; i < asset_map -> asset_count ; ++ i )
350+ if (memcmp (asset_map -> assets [i ].uuid , uuid , 16 ) == 0 )
351+ return & (asset_map -> assets [i ]);
369352 return NULL ;
370353}
371354
0 commit comments