This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 6ca9e60b0093c256bda33c178da4988961e77c41
Author:     Niklas Haas <[email protected]>
AuthorDate: Fri Aug 14 17:09:17 2026 +0200
Commit:     Niklas Haas <[email protected]>
CommitDate: Tue Sep 15 10:04:36 2026 +0000

    avformat/shared: add spacemap metadata for the number of cached blocks
    
    This can only ever be a lower bound in theory, because a process could crash
    exactly in between committing the cached block and updating the count, 
though
    that edge case is incredibly rare.
    
    This is a backwards-compatible addition so it doesn't require a cache 
version
    update. New clients will simply see a gross underestimate of the number of
    cached blocks, which means the upcoming option does not work retroactively,
    but I consider that a better trade-off than invalidating all existing cache
    objects for no reason.
    
    Sponsored-by: nxtedition AB
    Signed-off-by: Niklas Haas <[email protected]>
---
 libavformat/shared.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/shared.c b/libavformat/shared.c
index 23e435e571..cd545d54ba 100644
--- a/libavformat/shared.c
+++ b/libavformat/shared.c
@@ -125,7 +125,8 @@ typedef struct Spacemap {
     atomic_ushort block_shift;
     atomic_ullong filesize; /* byte offset of true EOF, or 0 if unknown */
     atomic_uchar hash[HASH_SIZE]; /* hash of resource URI / filename */
-    char reserved[80];
+    atomic_ullong blocks_cached; /* (lower bound on) the number of blocks 
cached */
+    char reserved[72];
 
     Block blocks[];
 } Spacemap;
@@ -653,7 +654,7 @@ static int shared_read(URLContext *h, unsigned char *buf, 
int size)
     Block *const block = &s->spacemap->blocks[block_id];
     unsigned state = atomic_load_explicit(&block->state, memory_order_acquire);
     int64_t pending_since = 0;
-    int verify_read = 0, acquired = 0;
+    int verify_read = 0, acquired = 0, allocated = 0;
 
 retry:
     switch (state) {
@@ -737,6 +738,7 @@ read_block:
         {
             /* Acquired pending state, proceed to fetch the block */
             acquired = 1;
+            allocated = (state == BLOCK_NONE || state == BLOCK_FAILED);
             state = BLOCK_PENDING;
             break;
         }
@@ -892,6 +894,8 @@ read_block:
                    "offset 0x%"PRIx64", CRC 0x%08X\n", bytes_read, block_id,
                    block_pos, crc);
             atomic_store_explicit(&block->state, crc, memory_order_release);
+            if (allocated)
+                atomic_fetch_add_explicit(&s->spacemap->blocks_cached, 1, 
memory_order_release);
         }
     } else {
         RELEASE_PENDING(block, state);

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to