[FFmpeg-devel] [RFC] Browser remote content API

wm4 nfxjfg at googlemail.com
Sun Feb 16 15:10:18 CET 2014


On Sun, 16 Feb 2014 00:51:42 +0100
Lukasz Marek <lukasz.m.luki at gmail.com> wrote:


> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index 4f4ac3c..ff8ec22 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -53,6 +53,32 @@ typedef struct AVIOInterruptCB {
>      void *opaque;
>  } AVIOInterruptCB;
>  
> +enum AVIODirEntryType {
> +    AVIO_ENTRY_UNKNOWN,
> +    AVIO_ENTRY_DIR,
> +    AVIO_ENTRY_FILE
> +};

From the UNIX point of view, there are many more entry types, and from
the other point of view (accessing arbitrary content), it gets even
worse, because entries could for example be links pointing elsewhere.

> +/**
> + * Describes single entry of the directory.
> + */
> +typedef struct AVIODirEntry {
> +    char *name;                      /**< filename */
> +    enum AVIODirEntryType type;      /**< one of AVIO_ENTRY_* value */
> +    int64_t size;                    /**< file size */
> +    int64_t creation_timestamp;      /**< creation timestamp */
> +    int64_t modification_timestamp;  /**< modification timestamp */
> +} AVIODirEntry;
> +
> +/**
> + * List of directory entries.
> + * @see avio_list_dir()
> + */
> +typedef struct AVIODirEntryList {
> +    AVIODirEntry **enties;
> +    int nb_entries;
> +} AVIODirEntryList;
> +
>  /**
>   * Bytestream IO Context.
>   * New fields can be added to the end with minor version bumps.
> @@ -164,6 +190,29 @@ typedef struct AVIOContext {
>   */
>  int avio_check(const char *url, int flags);
>  
> +#define AVIO_SORT_DESCENDING           0x001 /**< use descending mode instead of ascending */
> +#define AVIO_SORT_DIRS_FIRST           0x002 /**< move all dir names (sorted) in front of the list */
> +#define AVIO_SORT_BY_SIZE              0x004 /**< sort by size before sorting by name */
> +#define AVIO_SORT_BY_CREATION_DATE     0x008 /**< sort by creation date before sorting by name */
> +#define AVIO_SORT_BY_MODIFICATION_DATE 0x010 /**< sort by modification date before sorting by name */

Why would the API sort for you? You could add a separate sort API
function, but I think the user can just sort on his own. Even if you
include this, how do you change after which criteria it sorts first?

> +/**
> + * Allow to read content of the directory.
> + *
> + * @param url          directory to be listed.
> + * @param[out] entries sorted directory entries.
> + * @param sort_flags   combination of AVIO_SORT_* flags.
> + * @param options      protocol options.
> + * @return 0 on success or <0 on error.
> + */
> +int avio_list_dir(const char *url, AVIODirEntryList **entries, int sort_flags,
> +                  AVDictionary **options);
> +
> +/**
> + * Free directory entries list.
> + */
> +void avio_free_dir_list(AVIODirEntryList **entries);

I think an opendir()/readdir() style API would be better. You're not
forced to allocate a huge list of entries (and reallocate it several
times as you append to it), and you wouldn't need to allocate memory
for each entry.

Details could be queried by a separate stat()-style function. The
function could take the opendir() handle as parameter, so that in case
of remote protocols the entry could be retrieved from a cache. It also
could help keeping down the load, as it's the user's decision whether
to call the underlying stat() implementation.

>  /**
>   * Allocate and initialize an AVIOContext for buffered I/O. It must be later
>   * freed with av_free().
> diff --git a/libavformat/url.h b/libavformat/url.h
> index 712ea0f..f64f34d 100644
> --- a/libavformat/url.h
> +++ b/libavformat/url.h
> @@ -89,6 +89,7 @@ typedef struct URLProtocol {
>      const AVClass *priv_data_class;
>      int flags;
>      int (*url_check)(URLContext *h, int mask);
> +    int (*url_list_dir)(URLContext *h, const char *dir, AVIODirEntryList *entries);
>  } URLProtocol;
>  
>  /**



More information about the ffmpeg-devel mailing list