Files
test/source/blender/imbuf/intern/IMB_anim.hh
Aras Pranckevicius b261654a93 VSE: Reduce playback stalls when new video clips start playing
When starting to play back a movie strip, there was a "oh, let's figure out if
this is a video file?" check, immediately followed by "let's initialize the
machinery to decode a video file". The first one is kinda redundant, since if
it will happen to not be a video file, the latter check will nicely fail.

Addressed that by removing (seemingly unused at all?) functionality from
`ImBufAnim`, now it is only used for video file playback. Details:

- It looks like `ImBufAnim` is only ever used to play back "video files", so
  remove all the other modes of operation from it ("image sequence").
- Which makes `ImBufAnim::curtype` be not needed, it only needs to store state
  of whether it's initialized already.
- Which means there's no need to call `imb_get_anim_type` (which does very
  costly `isffmpeg`) when starting to play ImBufAnim.
- Remove some other variables from `ImBufAnim` that were just flat out unused.

In Gold previs playback between 1:41-1:55, on Windows/Ryzen5950X:
- Slowest 3 frames went from 276, 195, 168ms -> 222, 174, 147ms (saves 20+ ms
  per frame). All of these frames are camera cuts where multiple new video
  clips start playing.
- In the whole playback, total amount of time taken by `imb_get_anim_type`:
  234ms -> zero! Since that is no longer used.
- There are still stalls when starting to play a movie clip, and that is
  actually initializing ffmpeg things. But now at least right before
  "initialize ffmpeg" there's no additional redundant work.

Pull Request: https://projects.blender.org/blender/blender/pulls/118503
2024-02-22 09:24:35 +01:00

77 lines
1.4 KiB
C++

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup imbuf
*/
#pragma once
#include <cstdint>
#include "IMB_imbuf_enums.h"
#ifdef WITH_FFMPEG
struct AVFormatContext;
struct AVCodecContext;
struct AVCodec;
struct AVFrame;
struct AVPacket;
struct SwsContext;
#endif
struct IDProperty;
struct ImBufAnimIndex;
struct ImBufAnim {
enum class State { Uninitialized, Failed, Valid };
int ib_flags;
State state;
int cur_position; /* index 0 = 1e, 1 = 2e, enz. */
int duration_in_frames;
int frs_sec;
double frs_sec_base;
double start_offset;
int x, y;
/* for number */
char filepath[1024];
int streamindex;
#ifdef WITH_FFMPEG
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
const AVCodec *pCodec;
AVFrame *pFrameRGB;
AVFrame *pFrameDeinterlaced;
SwsContext *img_convert_ctx;
int videoStream;
AVFrame *pFrame;
bool pFrame_complete;
AVFrame *pFrame_backup;
bool pFrame_backup_complete;
int64_t cur_pts;
int64_t cur_key_frame_pts;
AVPacket *cur_packet;
bool seek_before_decode;
#endif
char index_dir[768];
int proxies_tried;
int indices_tried;
ImBufAnim *proxy_anim[IMB_PROXY_MAX_SLOT];
ImBufAnimIndex *curr_idx[IMB_TC_MAX_SLOT];
char colorspace[64];
char suffix[64]; /* MAX_NAME - multiview */
IDProperty *metadata;
};