Panda3D
config_ffmpeg.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file config_ffmpeg.cxx
10  * @author rdb
11  * @date 2013-08-23
12  */
13 
14 #include "config_ffmpeg.h"
15 #include "dconfig.h"
16 #include "ffmpegVideo.h"
17 #include "ffmpegVideoCursor.h"
18 #include "ffmpegAudio.h"
19 #include "ffmpegAudioCursor.h"
20 #include "movieTypeRegistry.h"
21 #include "pandaSystem.h"
22 
23 extern "C" {
24  #include <libavcodec/avcodec.h>
25  #include <libavformat/avformat.h>
26  #include <libavutil/avutil.h>
27 }
28 
29 #if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_FFMPEG)
30  #error Buildsystem error: BUILDING_FFMPEG not defined
31 #endif
32 
33 // Minimum supported versions:
34 // FFmpeg: 1.1
35 // libav: 9.20 (for Ubuntu 14.04)
36 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 35, 1)
37  #error Minimum supported version of libavcodec is 54.35.1.
38 #endif
39 
40 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54, 20, 4)
41  #error Minimum supported version of libavformat is 54.20.4.
42 #endif
43 
44 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52, 3, 0)
45  #error Minimum supported version of libavutil is 52.3.0.
46 #endif
47 
48 ConfigureDef(config_ffmpeg);
49 NotifyCategoryDef(ffmpeg, "");
50 
51 ConfigureFn(config_ffmpeg) {
53 }
54 
55 ConfigVariableInt ffmpeg_max_readahead_frames
56 ("ffmpeg-max-readahead-frames", 2,
57  PRC_DESC("The maximum number of frames ahead which an ffmpeg decoder thread "
58  "should read in advance of actual playback. Set this to 0 to "
59  "decode ffmpeg videos in the main thread."));
60 
61 ConfigVariableBool ffmpeg_show_seek_frames
62 ("ffmpeg-show-seek-frames", true,
63  PRC_DESC("Set this true to allow showing the intermediate results of seeking "
64  "through the ffmpeg stream to a target frame, or false to hold the "
65  "current frame until the target frame is achieved. This has the "
66  "biggest effect on videos that are too expensive to decode in real "
67  "time: when this is true, the video can be seen to animate at least "
68  "a little bit; when it is false, you may get long periods of one "
69  "held frame."));
70 
71 ConfigVariableBool ffmpeg_support_seek
72 ("ffmpeg-support-seek", true,
73  PRC_DESC("True to use the av_seek_frame() function to seek within ffmpeg "
74  "video files. If this is false, Panda will only seek within a "
75  "file by reading it from the beginning until the desired point, "
76  "which can be much slower. Set this false only if you suspect "
77  "a problem with av_seek_frame()."));
78 
79 ConfigVariableBool ffmpeg_global_lock
80 ("ffmpeg-global-lock", false,
81  PRC_DESC("Set this true to enable a single global mutex across *all* ffmpeg "
82  "operations. Leave this false to use the mutex only for "
83  "the ffmpeg operations that are generally known to be "
84  "not thread-safe. This will negatively affect ffmpeg performance, "
85  "especially when decoding multiple videos at once (including the "
86  "left and right channels of a stereo video). Set this true only "
87  "if you suspect a problem with ffmpeg's own thread-safe nature."));
88 
89 ConfigVariableEnum<ThreadPriority> ffmpeg_thread_priority
90 ("ffmpeg-thread-priority", TP_normal,
91  PRC_DESC("The default thread priority at which to start ffmpeg decoder "
92  "threads."));
93 
94 ConfigVariableInt ffmpeg_read_buffer_size
95 ("ffmpeg-read-buffer-size", 4096,
96  PRC_DESC("The size in bytes of the buffer used when reading input files. "
97  "This is important for performance. A typical size is that of a "
98  "cache page, e.g. 4kb."));
99 
100 ConfigVariableBool ffmpeg_prefer_libvpx
101 ("ffmpeg-prefer-libvpx", false,
102  PRC_DESC("If this is true, Panda will overrule ffmpeg's best judgment on "
103  "which decoder to use for decoding VP8 and VP9 files, and try to "
104  "choose libvpx. This is useful when you want to play WebM videos "
105  "with an alpha channel, which aren't supported by ffmpeg's own "
106  "VP8/VP9 decoders."));
107 
108 /**
109  * Initializes the library. This must be called at least once before any of
110  * the functions or classes in this library can be used. Normally it will be
111  * called by the static initializers and need not be called explicitly, but
112  * special cases exist.
113  */
114 void
116  static bool initialized = false;
117  if (initialized) {
118  return;
119  }
120  initialized = true;
121 
123 
124  FfmpegVideo::init_type();
125  FfmpegVideoCursor::init_type();
126  FfmpegAudio::init_type();
127  FfmpegAudioCursor::init_type();
128 
131 
133  ps->add_system("FFmpeg");
134 
135  // Register ffmpeg as catch-all audiovideo type.
137  reg->register_audio_type(&FfmpegAudio::make, "*");
138  reg->register_video_type(&FfmpegVideo::make, "*");
139 }
init_libffmpeg
void init_libffmpeg()
Initializes the library.
Definition: config_ffmpeg.cxx:115
ConfigVariableBool
This is a convenience class to specialize ConfigVariable as a boolean type.
Definition: configVariableBool.h:23
ffmpegAudio.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ffmpegAudioCursor.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PandaSystem::get_global_ptr
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
Definition: pandaSystem.cxx:442
ConfigVariableEnum
This class specializes ConfigVariable as an enumerated type.
Definition: configVariableEnum.h:31
PandaSystem
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:26
FfmpegVideoCursor::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type FfmpegVideo.
Definition: ffmpegVideoCursor.cxx:1191
FfmpegVirtualFile::register_protocol
static void register_protocol()
Should be called at startup to attach the appropriate hooks between Panda and FFMpeg.
Definition: ffmpegVirtualFile.cxx:185
PandaSystem::add_system
void add_system(const std::string &system)
Intended for use by each subsystem to register itself at startup.
Definition: pandaSystem.cxx:365
MovieTypeRegistry
This class records the different types of MovieAudio and MovieVideo that are available for loading.
Definition: movieTypeRegistry.h:28
pandaSystem.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FfmpegVideo::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type FfmpegVideo.
Definition: ffmpegVideo.cxx:79
movieTypeRegistry.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ffmpegVideoCursor.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
config_ffmpeg.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dconfig.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ffmpegVideo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
MovieTypeRegistry::register_video_type
void register_video_type(MakeVideoFunc func, const std::string &extensions)
Registers a MovieVideo type, so that files with any of the given extensions will be loaded as this ty...
Definition: movieTypeRegistry.cxx:213
MovieTypeRegistry::get_global_ptr
static MovieTypeRegistry * get_global_ptr()
Returns a pointer to the global MovieTypeRegistry instance.
Definition: movieTypeRegistry.I:18
MovieTypeRegistry::register_audio_type
void register_audio_type(MakeAudioFunc func, const std::string &extensions)
Registers a MovieAudio type, so that files with any of the given extensions will be loaded as this ty...
Definition: movieTypeRegistry.cxx:83
ConfigVariableInt
This is a convenience class to specialize ConfigVariable as an integer type.
Definition: configVariableInt.h:24