mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 08:44:19 -04:00
minor tweaks
This commit is contained in:
parent
f6a0af6f8d
commit
3a05c89924
@ -997,46 +997,12 @@ seek(int frame, bool backward) {
|
||||
PStatTimer timer(seek_pcollector);
|
||||
|
||||
if (ffmpeg_support_seek) {
|
||||
// Protect the call to av_seek_frame() in a global lock, just to be
|
||||
// paranoid.
|
||||
ReMutexHolder av_holder(_av_lock);
|
||||
|
||||
PN_int64 target_ts = (PN_int64)frame;
|
||||
if (target_ts < (PN_int64)(_initial_dts)) {
|
||||
// Attempts to seek before the first packet will fail.
|
||||
target_ts = _initial_dts;
|
||||
if (ffmpeg_global_lock) {
|
||||
ReMutexHolder av_holder(_av_lock);
|
||||
do_seek(frame, backward);
|
||||
} else {
|
||||
do_seek(frame, backward);
|
||||
}
|
||||
int flags = 0;
|
||||
if (backward) {
|
||||
flags = AVSEEK_FLAG_BACKWARD;
|
||||
}
|
||||
|
||||
if (av_seek_frame(_format_ctx, _video_index, target_ts, flags) < 0) {
|
||||
if (ffmpeg_cat.is_spam()) {
|
||||
ffmpeg_cat.spam()
|
||||
<< "Seek failure.\n";
|
||||
}
|
||||
|
||||
if (backward) {
|
||||
// Now try to seek forward.
|
||||
reset_stream();
|
||||
seek(frame, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try a binary search to get a little closer.
|
||||
if (binary_seek(_initial_dts, frame, frame, 1) < 0) {
|
||||
if (ffmpeg_cat.is_spam()) {
|
||||
ffmpeg_cat.spam()
|
||||
<< "Seek double failure.\n";
|
||||
}
|
||||
reset_stream();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fetch_packet(0);
|
||||
fetch_frame(-1);
|
||||
|
||||
} else {
|
||||
// If seeking isn't supported, close-and-reopen.
|
||||
@ -1046,6 +1012,53 @@ seek(int frame, bool backward) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FfmpegVideoCursor::do_seek
|
||||
// Access: Private
|
||||
// Description: As above, with the ffmpeg global lock held (if
|
||||
// configured on). Also only if ffmpeg-support-seek is
|
||||
// on.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FfmpegVideoCursor::
|
||||
do_seek(int frame, bool backward) {
|
||||
PN_int64 target_ts = (PN_int64)frame;
|
||||
if (target_ts < (PN_int64)(_initial_dts)) {
|
||||
// Attempts to seek before the first packet will fail.
|
||||
target_ts = _initial_dts;
|
||||
}
|
||||
int flags = 0;
|
||||
if (backward) {
|
||||
flags = AVSEEK_FLAG_BACKWARD;
|
||||
}
|
||||
|
||||
if (av_seek_frame(_format_ctx, _video_index, target_ts, flags) < 0) {
|
||||
if (ffmpeg_cat.is_spam()) {
|
||||
ffmpeg_cat.spam()
|
||||
<< "Seek failure.\n";
|
||||
}
|
||||
|
||||
if (backward) {
|
||||
// Now try to seek forward.
|
||||
reset_stream();
|
||||
seek(frame, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try a binary search to get a little closer.
|
||||
if (binary_seek(_initial_dts, frame, frame, 1) < 0) {
|
||||
if (ffmpeg_cat.is_spam()) {
|
||||
ffmpeg_cat.spam()
|
||||
<< "Seek double failure.\n";
|
||||
}
|
||||
reset_stream();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fetch_packet(0);
|
||||
fetch_frame(-1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FfmpegVideoCursor::binary_seek
|
||||
// Access: Private
|
||||
|
@ -130,6 +130,7 @@ private:
|
||||
void decode_frame(int &finished, AVPacket *packet);
|
||||
void do_decode_frame(int &finished, AVPacket *packet);
|
||||
void seek(int frame, bool backward);
|
||||
void do_seek(int frame, bool backward);
|
||||
int binary_seek(int min_frame, int max_frame, int target_frame, int num_iterations);
|
||||
void advance_to_frame(int frame);
|
||||
void reset_stream();
|
||||
|
@ -216,6 +216,11 @@ register_protocol() {
|
||||
// Here's a good place to call this global ffmpeg initialization
|
||||
// function.
|
||||
av_register_all();
|
||||
|
||||
// And this one.
|
||||
#if LIBAVFORMAT_VERSION_INT >= 0x351400
|
||||
avformat_network_init();
|
||||
#endif
|
||||
|
||||
static URLProtocol protocol;
|
||||
protocol.name = "pandavfs";
|
||||
|
Loading…
x
Reference in New Issue
Block a user