| 162 | } |
| 163 | |
| 164 | void 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 | |
| 206 | static int PopCount(int64_t v) { |
| 207 | int c = 0; |
nothing calls this directly
no test coverage detected