MCPcopy Create free account
hub / github.com/FFMS/ffms2 / CacheBeginning

Method CacheBeginning

src/core/audiosource.cpp:164–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164void FFMS_AudioSource::CacheBeginning() {
165 // Nothing to do if the cache is already populated
166 if (!Cache.empty()) return;
167
168 // The first packet after a seek is often decoded incorrectly, which
169 // makes it impossible to ever correctly seek back to the beginning, so
170 // store the first block now
171
172 // In addition, anything with the same PTS as the first packet can't be
173 // distinguished from the first packet and so can't be seeked to, so
174 // store those as well
175
176 // Some of LAVF's splitters don't like to seek to the beginning of the
177 // file (ts and?), so cache a few blocks even if PTSes are unique
178 // Packet 7 is the last packet I've had be unseekable to, so cache up to
179 // 10 for a bit of an extra buffer
180 auto end = Cache.end();
181 while (PacketNumber < Frames.size() &&
182 ((Frames[0].PTS != AV_NOPTS_VALUE && Frames[PacketNumber].PTS == Frames[0].PTS) ||
183 Cache.size() < 10)) {
184
185 // Vorbis in particular seems to like having 60+ packets at the start
186 // of the file with a PTS of 0, so we might need to expand the search
187 // range to account for that.
188 // Expanding slightly before it's strictly needed to ensure there's a
189 // bit of space for an actual cache
190 if (Cache.size() >= MaxCacheBlocks - 5) {
191 if (MaxCacheBlocks >= EXCESSIVE_CACHE_SIZE)
192 throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_ALLOCATION_FAILED,
193 "Exceeded the search range for an initial valid audio PTS");
194 MaxCacheBlocks *= 2;
195 }
196
197 DecodeNextBlock(&end);
198 }
199 // Store the iterator to the last element of the cache which is used for
200 // correctness rather than speed, so that when looking for one to delete
201 // we know how much to skip
202 CacheNoDelete = Cache.end();
203 --CacheNoDelete;
204}
205
206static int PopCount(int64_t v) {
207 int c = 0;

Callers

nothing calls this directly

Calls 4

FFMS_ExceptionClass · 0.85
emptyMethod · 0.80
endMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected