History

avformat/matroskaenc: Simplify writing Void elements

Reserving space in Matroska works by writing a Void element. And until now this worked as follows: The current position was recorded and the EBML ID as well as the length field written; then the new position was recorded to know how much more to write. Afterwards the actual writing has been performed via ffio_fill(). But it is unnecessary to explicitly use the positions (obtained via avio_tell()) to find out how much still needs to be written, because the length of the ID and the length field are known. So rewrite the function to no longer use them. Also, given that ffio_fill() uses an int parameter and given that no current caller (and no sane future caller) will want to reserve several GB of space, make the size parameter of put_ebml_void() itself an int.

Andreas Rheinhardt committed 6 years ago

Commit 98a6c6e1 parent 8e4c8711 file · +9 −8Browse files

Unified · Split

libavformat/matroskaenc.c+9−8
@@ -288,21 +288,22 @@ static void put_ebml_string(AVIOContext *pb, uint32_t elementid, · 287 unmodified lines
288 *288 *
289 * @param size The number of bytes to reserve, which must be at least 2.289 * @param size The number of bytes to reserve, which must be at least 2.
290 */290 */
291static void put_ebml_void(AVIOContext *pb, uint64_t size)291static void put_ebml_void(AVIOContext *pb, int size)
292{292{
293 int64_t currentpos = avio_tell(pb);
294
295 av_assert0(size >= 2);293 av_assert0(size >= 2);
296 294
297 put_ebml_id(pb, EBML_ID_VOID);295 put_ebml_id(pb, EBML_ID_VOID);
298 // we need to subtract the length needed to store the size from the296 // we need to subtract the length needed to store the size from the
299 // size we need to reserve so 2 cases, we use 8 bytes to store the297 // size we need to reserve so 2 cases, we use 8 bytes to store the
300 // size if possible, 1 byte otherwise298 // size if possible, 1 byte otherwise
301 if (size < 10)299 if (size < 10) {
302 put_ebml_num(pb, size - 2, 0);300 size -= 2;
303 else301 put_ebml_num(pb, size, 0);
304 put_ebml_num(pb, size - 9, 8);302 } else {
305 ffio_fill(pb, 0, currentpos + size - avio_tell(pb));303 size -= 9;
304 put_ebml_num(pb, size, 8);
305 }
306 ffio_fill(pb, 0, size);
306}307}
307 308
308static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,309static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t