Revision f0e9f442

View differences:

libavformat/matroskaenc.c
106 106
    return bytes;
107 107
}
108 108

  
109
// XXX: test this thoroughly and get rid of minbytes hack (currently needed to
110
// use up all of the space reserved in start_ebml_master)
111
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
109
/**
110
 * Write a size in EBML variable length format.
111
 *
112
 * @param bytes The number of bytes that need to be used to write the size.
113
 *              If zero, any number of bytes can be used.
114
 */
115
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int bytes)
112 116
{
113
    int i, bytes = FFMAX(minbytes, ebml_size_bytes(size));
117
    int i, needed_bytes = ebml_size_bytes(size);
114 118

  
115 119
    // sizes larger than this are currently undefined in EBML
116 120
    // so write "unknown" size
......
119 123
        return;
120 124
    }
121 125

  
126
    if (bytes == 0)
127
        // don't care how many bytes are used, so use the min
128
        bytes = needed_bytes;
129
    else if (needed_bytes > bytes) {
130
        // the bytes needed to write the given size would exceed the bytes
131
        // that we need to use, so write unknown size. This shouldn't happen.
132
        av_log(NULL, AV_LOG_WARNING, "Size of %llu needs %d bytes but only %d bytes reserved\n",
133
               size, needed_bytes, bytes);
134
        put_ebml_size_unknown(pb, bytes);
135
        return;
136
    }
137

  
122 138
    size |= 1ULL << bytes*7;
123 139
    for (i = bytes - 1; i >= 0; i--)
124 140
        put_byte(pb, size >> i*8);

Also available in: Unified diff