| 235 | } |
| 236 | |
| 237 | bool FileSourceAnnexBFile::seek(int64_t pos) |
| 238 | { |
| 239 | if (!isFileOpened) |
| 240 | return false; |
| 241 | |
| 242 | DEBUG_ANNEXBFILE("FileSourceAnnexBFile::seek to " << pos); |
| 243 | // Seek the file and update the buffer |
| 244 | srcFile.seek(pos); |
| 245 | this->fileBufferSize = srcFile.read(this->fileBuffer.data(), BUFFERSIZE); |
| 246 | if (this->fileBufferSize == 0) |
| 247 | // The file is empty of there was an error reading from the file. |
| 248 | return false; |
| 249 | this->bufferStartPosInFile = pos; |
| 250 | this->posInBuffer = 0; |
| 251 | |
| 252 | if (pos == 0) |
| 253 | this->seekToFirstNAL(); |
| 254 | else |
| 255 | { |
| 256 | // Check if we are at a start code position (001 or 0001) |
| 257 | if (this->fileBuffer.at(0) == (char)0 && this->fileBuffer.at(1) == (char)0 && this->fileBuffer.at(2) == (char)0 && this->fileBuffer.at(3) == (char)1) |
| 258 | return true; |
| 259 | if (this->fileBuffer.at(0) == (char)0 && this->fileBuffer.at(1) == (char)0 && this->fileBuffer.at(2) == (char)1) |
| 260 | return true; |
| 261 | |
| 262 | DEBUG_ANNEXBFILE("FileSourceAnnexBFile::seek could not find start code at seek position"); |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | return true; |
| 267 | } |
no test coverage detected