FastLED 3.9.15
Loading...
Searching...
No Matches

◆ plm_demux_get_duration()

double fl::third_party::plm_demux_get_duration ( plm_demux_t * self,
int type )

Definition at line 1329 of file pl_mpeg.hpp.

1329 {
1330 size_t file_size = plm_buffer_get_size(self->buffer);
1331
1332 if (
1334 self->last_file_size == file_size
1335 ) {
1336 return self->duration;
1337 }
1338
1339 size_t previous_pos = plm_buffer_tell(self->buffer);
1340 int previous_start_code = self->start_code;
1341
1342 // Find last video PTS. Start searching 64kb from the end and go further
1343 // back if needed.
1344 long start_range = 64L * 1024L;
1345 long max_range = 4096L * 1024L;
1346 for (long range = start_range; range <= max_range; range *= 2) {
1347 long seek_pos = file_size - range;
1348 if (seek_pos < 0) {
1349 seek_pos = 0;
1350 range = max_range; // Make sure to bail after this round
1351 }
1352 plm_demux_buffer_seek(self, seek_pos);
1353 self->current_packet.length = 0;
1354
1355 double last_pts = PLM_PACKET_INVALID_TS;
1356 plm_packet_t *packet = NULL;
1357 while ((packet = plm_demux_decode(self))) {
1358 if (packet->pts != PLM_PACKET_INVALID_TS && packet->type == type) {
1359 last_pts = packet->pts;
1360 }
1361 }
1362 if (last_pts != PLM_PACKET_INVALID_TS) {
1363 self->duration = last_pts - plm_demux_get_start_time(self, type);
1364 break;
1365 }
1366 }
1367
1368 plm_demux_buffer_seek(self, previous_pos);
1369 self->start_code = previous_start_code;
1370 self->last_file_size = file_size;
1371 return self->duration;
1372}
#define NULL
void plm_demux_buffer_seek(plm_demux_t *self, size_t pos) FL_NOEXCEPT
Definition pl_mpeg.hpp:1297
plm_packet_t * plm_demux_decode(plm_demux_t *self) FL_NOEXCEPT
Definition pl_mpeg.hpp:1517
size_t plm_buffer_get_size(plm_buffer_t *self) FL_NOEXCEPT
Definition pl_mpeg.hpp:867
double plm_demux_get_start_time(plm_demux_t *self, int type) FL_NOEXCEPT
Definition pl_mpeg.hpp:1304
size_t plm_buffer_tell(plm_buffer_t *self) FL_NOEXCEPT
Definition pl_mpeg.hpp:945
#define PLM_PACKET_INVALID_TS
Definition pl_mpeg.h:171

References FL_NOEXCEPT, NULL, plm_buffer_get_size(), plm_buffer_tell(), plm_demux_buffer_seek(), plm_demux_decode(), plm_demux_get_start_time(), PLM_PACKET_INVALID_TS, fl::third_party::plm_packet_t::pts, and fl::third_party::plm_packet_t::type.

Referenced by plm_demux_seek(), plm_get_duration(), and plm_seek_frame().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: