[FFmpeg-soc] [soc]: r5297 - in concat/libavformat: avplaylist.c avplaylist.h

gkovacs subversion at mplayerhq.hu
Wed Aug 26 09:42:59 CEST 2009


Author: gkovacs
Date: Wed Aug 26 09:42:59 2009
New Revision: 5297

Log:
added av_playlist_insert_path

Modified:
   concat/libavformat/avplaylist.c
   concat/libavformat/avplaylist.h

Modified: concat/libavformat/avplaylist.c
==============================================================================
--- concat/libavformat/avplaylist.c	Wed Aug 26 08:46:00 2009	(r5296)
+++ concat/libavformat/avplaylist.c	Wed Aug 26 09:42:59 2009	(r5297)
@@ -86,21 +86,24 @@ int av_playlist_split_encodedstring(cons
     av_free(sepidx);
 }
 
-int av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath)
+int av_playlist_insert_path(AVPlaylistContext *ctx, const char *itempath, int pos)
 {
+    int i;
     int64_t *durations_tmp;
     unsigned int *nb_streams_list_tmp;
     char **flist_tmp;
     flist_tmp = av_realloc(ctx->flist, sizeof(*(ctx->flist)) * (++ctx->pelist_size+1));
     if (!flist_tmp) {
         av_log(NULL, AV_LOG_ERROR, "av_realloc error in av_playlist_add_path\n");
-        av_free(ctx->durations);
-        ctx->durations = NULL;
+        av_free(ctx->flist);
+        ctx->flist = NULL;
         return AVERROR_NOMEM;
     } else
         ctx->flist = flist_tmp;
+    for (i = ctx->pelist_size; i > pos; --i)
+        ctx->flist[i] = ctx->flist[i - 1];
+    ctx->flist[pos] = itempath;
     ctx->flist[ctx->pelist_size] = NULL;
-    ctx->flist[ctx->pelist_size-1] = itempath;
     durations_tmp = av_realloc(ctx->durations,
                                sizeof(*(ctx->durations)) * (ctx->pelist_size+1));
     if (!durations_tmp) {
@@ -110,6 +113,9 @@ int av_playlist_add_path(AVPlaylistConte
         return AVERROR_NOMEM;
     } else
         ctx->durations = durations_tmp;
+    for (i = ctx->pelist_size; i > pos; --i)
+        ctx->durations[i] = ctx->durations[i - 1];
+    ctx->durations[pos] = 0;
     ctx->durations[ctx->pelist_size] = 0;
     nb_streams_list_tmp = av_realloc(ctx->nb_streams_list,
                                      sizeof(*(ctx->nb_streams_list)) * (ctx->pelist_size+1));
@@ -120,10 +126,18 @@ int av_playlist_add_path(AVPlaylistConte
         return AVERROR_NOMEM;
     } else
         ctx->nb_streams_list = nb_streams_list_tmp;
+    for (i = ctx->pelist_size; i > pos; --i)
+        ctx->nb_streams_list[i] = ctx->nb_streams_list[i - 1];
+    ctx->nb_streams_list[pos] = 0;
     ctx->nb_streams_list[ctx->pelist_size] = 0;
     return 0;
 }
 
+int av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath)
+{
+    return av_playlist_insert_path(ctx, itempath, ctx->pelist_size);
+}
+
 void av_playlist_relative_paths(char **flist,
                                 int len,
                                 const char *workingdir)

Modified: concat/libavformat/avplaylist.h
==============================================================================
--- concat/libavformat/avplaylist.h	Wed Aug 26 08:46:00 2009	(r5296)
+++ concat/libavformat/avplaylist.h	Wed Aug 26 09:42:59 2009	(r5297)
@@ -77,4 +77,13 @@ int av_playlist_split_encodedstring(cons
  */
 int av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath);
 
+/** @brief Creates and adds AVFormatContext for item located at specified path to a AVPlaylistContext
+ *  at specified index. Existing items will be shifted up in the list.
+ *  @param ctx Pre-allocated AVPlaylistContext to add elements to.
+ *  @param itempath Absolute path to item for which to add a playlist element.
+ *  @param pos Index which the newly inserted item will occupy.
+ *  @return Returns 0 upon success, or negative upon failure.
+ */
+int av_playlist_insert_path(AVPlaylistContext *ctx, const char *itempath, int pos);
+
 #endif /* AVFORMAT_AVPLAYLIST_H */


More information about the FFmpeg-soc mailing list