* @brief Returns the index of the frame that has the given timestamp * * @param timestamp Timestamp of the frame to seek to * @param rounddown If true, the seek will be to a frame that has this timestamp or a previous one */
| 70 | * @param rounddown If true, the seek will be to a frame that has this timestamp or a previous one |
| 71 | */ |
| 72 | int GetFrameIdxByTimestamp(int64_t timestamp, bool rounddown = false) const { |
| 73 | LOG_LINE << "GetFrameIdxByTimestamp: timestamp=" << timestamp << ", rounddown=" << rounddown |
| 74 | << ", index_size=" << index.size() << std::endl; |
| 75 | int frame_idx = 0; |
| 76 | for (size_t i = 0; i < index.size(); i++) { |
| 77 | if (index[i].pts == timestamp) { |
| 78 | LOG_LINE << "Exact match found at index " << i << std::endl; |
| 79 | frame_idx = i; |
| 80 | break; |
| 81 | } else if (index[i].pts > timestamp) { |
| 82 | LOG_LINE << "Frame " << i << " with pts=" << index[i].pts << " is the first frame past the timestamp" << std::endl; |
| 83 | if (rounddown && i > 0) { |
| 84 | LOG_LINE << "Round down mode: previous frame " << i - 1 << " with pts=" << index[i - 1].pts << " is the last frame before the timestamp" << std::endl; |
| 85 | frame_idx = i - 1; |
| 86 | } else { |
| 87 | LOG_LINE << "Round up mode: frame " << i << " with pts=" << index[i].pts << " is the first frame past the timestamp" << std::endl; |
| 88 | frame_idx = i; |
| 89 | } |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | assert(frame_idx >= 0 && frame_idx < static_cast<int>(index.size())); |
| 94 | LOG_LINE << "Returning frame_idx=" << frame_idx << std::endl; |
| 95 | return frame_idx; |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | /** |
no test coverage detected