Read the stream until we find the requested Frame
| 1262 | |
| 1263 | // Read the stream until we find the requested Frame |
| 1264 | std::shared_ptr<Frame> FFmpegReader::ReadStream(int64_t requested_frame) { |
| 1265 | // Allocate video frame |
| 1266 | bool check_seek = false; |
| 1267 | int packet_error = -1; |
| 1268 | int64_t no_progress_count = 0; |
| 1269 | int64_t prev_packets_read = packet_status.packets_read(); |
| 1270 | int64_t prev_packets_decoded = packet_status.packets_decoded(); |
| 1271 | int64_t prev_video_decoded = packet_status.video_decoded; |
| 1272 | double prev_video_pts_seconds = video_pts_seconds; |
| 1273 | |
| 1274 | // Debug output |
| 1275 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream", "requested_frame", requested_frame); |
| 1276 | |
| 1277 | // Loop through the stream until the correct frame is found |
| 1278 | while (true) { |
| 1279 | // Check if working frames are 'finished' |
| 1280 | if (!is_seeking) { |
| 1281 | // Check for final frames |
| 1282 | CheckWorkingFrames(requested_frame); |
| 1283 | } |
| 1284 | |
| 1285 | // Check if requested 'final' frame is available (and break out of loop if found) |
| 1286 | bool is_cache_found = (final_cache.GetFrame(requested_frame) != NULL); |
| 1287 | if (is_cache_found) { |
| 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | if (!hold_packet || !packet) { |
| 1292 | // Get the next packet |
| 1293 | packet_error = GetNextPacket(); |
| 1294 | if (packet_error < 0 && !packet) { |
| 1295 | // No more packets to be found |
| 1296 | packet_status.packets_eof = true; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | // Debug output |
| 1301 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream (GetNextPacket)", "requested_frame", requested_frame,"packets_read", packet_status.packets_read(), "packets_decoded", packet_status.packets_decoded(), "is_seeking", is_seeking); |
| 1302 | |
| 1303 | // Check the status of a seek (if any) |
| 1304 | if (is_seeking) { |
| 1305 | check_seek = CheckSeek(); |
| 1306 | } else { |
| 1307 | check_seek = false; |
| 1308 | } |
| 1309 | |
| 1310 | if (check_seek) { |
| 1311 | // Packet may become NULL on Close inside Seek if CheckSeek returns false |
| 1312 | // Jump to the next iteration of this loop |
| 1313 | continue; |
| 1314 | } |
| 1315 | |
| 1316 | // Video packet |
| 1317 | if ((info.has_video && packet && packet->stream_index == videoStream) || |
| 1318 | (info.has_video && packet_status.video_decoded < packet_status.video_read) || |
| 1319 | (info.has_video && !packet && !packet_status.video_eof)) { |
| 1320 | // Process Video Packet |
| 1321 | ProcessVideoPacket(requested_frame); |
nothing calls this directly
no test coverage detected