|
FFmpeg
|
#include "libavutil/attributes.h"#include "libavutil/avassert.h"#include "libavutil/avstring.h"#include "libavutil/crc.h"#include "libavutil/error.h"#include "libavutil/hash.h"#include "libavutil/file_open.h"#include "libavutil/mem.h"#include "libavutil/opt.h"#include "libavutil/time.h"#include "url.h"#include <errno.h>#include <fcntl.h>#include <inttypes.h>#include <stdatomic.h>#include <string.h>#include <sys/file.h>#include <sys/mman.h>#include <sys/stat.h>#include <unistd.h>Go to the source code of this file.
Data Structures | |
| struct | Block |
| struct | Spacemap |
| struct | SharedContext |
Macros | |
| #define | HASH_METHOD "SHA512/256" |
| This hash should be resistant against collision attacks, so that an attacker could not generate e.g. | |
| #define | HASH_SIZE 32 |
| #define | HEADER_MAGIC MKTAG(u'\xFF', 'S', 'h', '$') |
| #define | HEADER_VERSION 3 |
| #define | MAX_CORRUPT_BLOCKS 10 |
| Hard watershed of consecutive failed blocks before we give up on the cache file altogether and assume it's entirely lost to us. | |
| #define | DEF_SET_ONCE(ctype, atype) |
| #define | OFFSET(x) |
| #define | D AV_OPT_FLAG_DECODING_PARAM |
Enumerations | |
| enum | BlockState { BLOCK_NONE = 0 , BLOCK_PENDING , BLOCK_FAILED } |
Functions | |
| static int | hash_uri (uint8_t hash[HASH_SIZE], const char *uri) |
| static uint32_t | get_block_crc (const uint8_t *block, size_t block_size) |
| static int | shared_close (URLContext *h) |
| static int | cache_map (URLContext *h, int64_t filesize) |
| static int | spacemap_init (URLContext *h, const uint8_t hash[HASH_SIZE]) |
| static int | spacemap_grow (URLContext *h, int64_t block) |
| static int64_t | get_filesize (URLContext *h) |
| static int | set_filesize (URLContext *h, int64_t new_size) |
| static int | shared_open (URLContext *h, const char *arg, int flags, AVDictionary **options) |
| static int | spacemap_remap (URLContext *h, size_t map_size) |
| static int | read_cache (SharedContext *s, uint8_t *buf, size_t size, off_t offset) |
| static int | write_cache (SharedContext *s, const uint8_t *buf, size_t size, off_t offset) |
| static size_t | clamp_size (URLContext *h, size_t size, int64_t pos) |
| static int | shared_read (URLContext *h, unsigned char *buf, int size) |
| static int64_t | shared_seek (URLContext *h, int64_t pos, int whence) |
| static int | shared_get_file_handle (URLContext *h) |
| static int | shared_get_short_seek (URLContext *h) |
Variables | |
| static const AVOption | options [] |
| static const AVClass | shared_context_class |
| const URLProtocol | ff_shared_protocol |
| #define HASH_METHOD "SHA512/256" |
This hash should be resistant against collision attacks, so that an attacker could not generate e.g.
two different URIs that map to the same cache file. This requires at least 64 bits of collision resistance in practice (i.e. 128 bits = 16 bytes of hash size). However, we can be conservative by computing e.g. a 256 bit hash and storing it inside the file header for verification.
Note that due to the way we use atomics, we should avoid zero bytes in the resulting hash; hence we tweak the input slightly to avoid this. The resulting loss in hash strength is negligible, since 32 bytes is already much more than needed.
Definition at line 60 of file shared.c.
Referenced by hash_uri().
| #define HASH_SIZE 32 |
Definition at line 61 of file shared.c.
Referenced by close_out(), hash_uri(), main(), shared_open(), and spacemap_init().
Definition at line 62 of file shared.c.
Referenced by spacemap_init().
| #define HEADER_VERSION 3 |
Definition at line 63 of file shared.c.
Referenced by hash_uri(), and spacemap_init().
| #define MAX_CORRUPT_BLOCKS 10 |
Hard watershed of consecutive failed blocks before we give up on the cache file altogether and assume it's entirely lost to us.
Definition at line 69 of file shared.c.
Referenced by shared_read().
| #define DEF_SET_ONCE | ( | ctype, | |
| atype ) |
| #define OFFSET | ( | x | ) |
| #define D AV_OPT_FLAG_DECODING_PARAM |
| enum BlockState |
|
static |
Definition at line 71 of file shared.c.
Referenced by shared_open().
|
static |
Definition at line 103 of file shared.c.
Referenced by shared_read().
|
static |
Definition at line 189 of file shared.c.
Referenced by shared_open().
|
static |
Definition at line 347 of file shared.c.
Referenced by set_filesize(), and shared_open().
|
static |
Definition at line 486 of file shared.c.
Referenced by shared_open().
|
static |
Definition at line 453 of file shared.c.
Referenced by shared_open(), and shared_read().
|
static |
Definition at line 215 of file shared.c.
Referenced by clamp_size(), shared_open(), shared_seek(), and spacemap_grow().
|
static |
Definition at line 221 of file shared.c.
Referenced by shared_open(), shared_read(), and shared_seek().
|
static |
|
static |
Definition at line 383 of file shared.c.
Referenced by spacemap_grow(), and spacemap_init().
|
static |
Definition at line 539 of file shared.c.
Referenced by shared_read().
|
static |
Definition at line 559 of file shared.c.
Referenced by shared_read().
|
static |
Definition at line 579 of file shared.c.
Referenced by shared_read().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| const URLProtocol ff_shared_protocol |