Skip to content

Commit bca0966

Browse files
committed
Split vrpn out of panda into a libp3vrpn. Split ffmpeg out of movies into libp3ffmpeg. Add registry for MovieVideo and MovieAudio. Add a libvorbisfile-based Ogg Vorbis loader. Add a native .wav loader.
1 parent 0821026 commit bca0966

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1943
-239
lines changed

panda/metalibs/panda/Sources.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#define COMPONENT_LIBS \
1212
p3recorder p3pgraph p3pgraphnodes p3pipeline \
13-
p3vrpn p3grutil p3chan p3pstatclient \
13+
p3grutil p3chan p3pstatclient \
1414
p3char p3collide p3cull p3device \
1515
p3dgraph p3display p3event p3gobj p3gsgbase \
1616
p3linmath p3mathutil p3movies p3net p3nativenet \

panda/src/configfiles/panda.prc.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
load-file-type egg pandaegg
6060

6161

62+
# These entries work very similar to load-file-type, except they are
63+
# used by the MovieVideo and MovieAudio code to determine which module
64+
# should be loaded in order to decode files of the given extension.
65+
66+
# ffmpeg is added by default because it used to be compiled in.
67+
# The * is a special catch-all extension that is consulted unless a
68+
# loader has been defined with an explicit extension.
69+
70+
load-audio-type * p3ffmpeg
71+
load-video-type * p3ffmpeg
72+
6273

6374
# The following lines define some handy object types to use within the
6475
# egg syntax. This remaps <ObjectType> { name } into whatever egg

panda/src/ffmpeg/Sources.pp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#define BUILD_DIRECTORY $[HAVE_FFMPEG]
2+
3+
#define OTHER_LIBS p3interrogatedb:c p3dconfig:c p3dtoolconfig:m \
4+
p3dtoolutil:c p3dtoolbase:c p3dtool:m p3prc:c
5+
6+
#define BUILDING_DLL BUILDING_FFMPEG
7+
8+
#define USE_PACKAGES ffmpeg
9+
10+
#begin lib_target
11+
#define TARGET p3ffmpeg
12+
13+
#define LOCAL_LIBS p3movies
14+
15+
#define COMBINED_SOURCES \
16+
$[TARGET]_composite1.cxx
17+
18+
#define SOURCES \
19+
config_ffmpeg.h \
20+
ffmpegVideo.h ffmpegVideo.I \
21+
ffmpegVideoCursor.h ffmpegVideoCursor.I \
22+
ffmpegAudio.h ffmpegAudio.I \
23+
ffmpegAudioCursor.h ffmpegAudioCursor.I \
24+
ffmpegVirtualFile.h ffmpegVirtualFile.I
25+
26+
#define INCLUDED_SOURCES \
27+
config_ffmpeg.cxx \
28+
ffmpegVideo.cxx \
29+
ffmpegVideoCursor.cxx \
30+
ffmpegAudio.cxx \
31+
ffmpegAudioCursor.cxx \
32+
ffmpegVirtualFile.cxx
33+
34+
#define INSTALL_HEADERS \
35+
config_ffmpeg.h \
36+
ffmpegVideo.h ffmpegVideo.I \
37+
ffmpegVideoCursor.h ffmpegVideoCursor.I \
38+
ffmpegAudio.h ffmpegAudio.I \
39+
ffmpegAudioCursor.h ffmpegAudioCursor.I \
40+
ffmpegVirtualFile.h ffmpegVirtualFile.I
41+
42+
#define IGATESCAN all
43+
44+
#end lib_target

panda/src/ffmpeg/config_ffmpeg.cxx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Filename: config_ffmpeg.cxx
2+
// Created by: rdb (23Aug13)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
//
6+
// PANDA 3D SOFTWARE
7+
// Copyright (c) Carnegie Mellon University. All rights reserved.
8+
//
9+
// All use of this software is subject to the terms of the revised BSD
10+
// license. You should have received a copy of this license along
11+
// with this source code in a file named "LICENSE."
12+
//
13+
////////////////////////////////////////////////////////////////////
14+
15+
#include "config_ffmpeg.h"
16+
#include "dconfig.h"
17+
#include "ffmpegVideo.h"
18+
#include "ffmpegVideoCursor.h"
19+
#include "ffmpegAudio.h"
20+
#include "ffmpegAudioCursor.h"
21+
22+
#include "movieTypeRegistry.h"
23+
24+
extern "C" {
25+
#include "libavcodec/avcodec.h"
26+
}
27+
28+
ConfigureDef(config_ffmpeg);
29+
NotifyCategoryDef(ffmpeg, "");
30+
31+
ConfigureFn(config_ffmpeg) {
32+
init_libffmpeg();
33+
}
34+
35+
ConfigVariableInt ffmpeg_max_readahead_frames
36+
("ffmpeg-max-readahead-frames", 2,
37+
PRC_DESC("The maximum number of frames ahead which an ffmpeg decoder thread "
38+
"should read in advance of actual playback. Set this to 0 to "
39+
"decode ffmpeg videos in the main thread."));
40+
41+
ConfigVariableBool ffmpeg_show_seek_frames
42+
("ffmpeg-show-seek-frames", true,
43+
PRC_DESC("Set this true to allow showing the intermediate results of seeking "
44+
"through the ffmpeg stream to a target frame, or false to hold the "
45+
"current frame until the target frame is achieved. This has the "
46+
"biggest effect on videos that are too expensive to decode in real "
47+
"time: when this is true, the video can be seen to animate at least "
48+
"a little bit; when it is false, you may get long periods of one "
49+
"held frame."));
50+
51+
ConfigVariableBool ffmpeg_support_seek
52+
("ffmpeg-support-seek", true,
53+
PRC_DESC("True to use the av_seek_frame() function to seek within ffmpeg "
54+
"video files. If this is false, Panda will only seek within a "
55+
"file by reading it from the beginning until the desired point, "
56+
"which can be much slower. Set this false only if you suspect "
57+
"a problem with av_seek_frame()."));
58+
59+
ConfigVariableBool ffmpeg_global_lock
60+
("ffmpeg-global-lock", false,
61+
PRC_DESC("Set this true to enable a single global mutex across *all* ffmpeg "
62+
"operations. Leave this false to use the mutex only for "
63+
"the ffmpeg operations that are generally known to be "
64+
"not thread-safe. This will negatively affect ffmpeg performance, "
65+
"especially when decoding multiple videos at once (including the "
66+
"left and right channels of a stereo video). Set this true only "
67+
"if you suspect a problem with ffmpeg's own thread-safe nature."));
68+
69+
ConfigVariableEnum<ThreadPriority> ffmpeg_thread_priority
70+
("ffmpeg-thread-priority", TP_normal,
71+
PRC_DESC("The default thread priority at which to start ffmpeg decoder "
72+
"threads."));
73+
74+
ConfigVariableInt ffmpeg_read_buffer_size
75+
("ffmpeg-read-buffer-size", 4096,
76+
PRC_DESC("The size in bytes of the buffer used when reading input files. "
77+
"This is important for performance. A typical size is that of a "
78+
"cache page, e.g. 4kb."));
79+
80+
////////////////////////////////////////////////////////////////////
81+
// Function: init_libffmpeg
82+
// Description: Initializes the library. This must be called at
83+
// least once before any of the functions or classes in
84+
// this library can be used. Normally it will be
85+
// called by the static initializers and need not be
86+
// called explicitly, but special cases exist.
87+
////////////////////////////////////////////////////////////////////
88+
void
89+
init_libffmpeg() {
90+
static bool initialized = false;
91+
if (initialized) {
92+
return;
93+
}
94+
initialized = true;
95+
96+
FfmpegVirtualFile::register_protocol();
97+
98+
FfmpegVideo::init_type();
99+
FfmpegVideoCursor::init_type();
100+
FfmpegAudio::init_type();
101+
FfmpegAudioCursor::init_type();
102+
103+
FfmpegVideo::register_with_read_factory();
104+
FfmpegVideoCursor::register_with_read_factory();
105+
106+
// Register ffmpeg as catch-all audio/video type.
107+
MovieTypeRegistry *reg = MovieTypeRegistry::get_global_ptr();
108+
reg->register_audio_type(&FfmpegAudio::make, "*");
109+
reg->register_video_type(&FfmpegVideo::make, "*");
110+
}

panda/src/ffmpeg/config_ffmpeg.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Filename: config_ffmpeg.h
2+
// Created by: rdb (23Aug13)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
//
6+
// PANDA 3D SOFTWARE
7+
// Copyright (c) Carnegie Mellon University. All rights reserved.
8+
//
9+
// All use of this software is subject to the terms of the revised BSD
10+
// license. You should have received a copy of this license along
11+
// with this source code in a file named "LICENSE."
12+
//
13+
////////////////////////////////////////////////////////////////////
14+
15+
#ifndef CONFIG_FFMPEG_H
16+
#define CONFIG_FFMPEG_H
17+
18+
#include "pandabase.h"
19+
#include "notifyCategoryProxy.h"
20+
#include "configVariableEnum.h"
21+
#include "configVariableInt.h"
22+
#include "configVariableBool.h"
23+
#include "threadPriority.h"
24+
#include "dconfig.h"
25+
26+
ConfigureDecl(config_ffmpeg, EXPCL_FFMPEG, EXPTP_FFMPEG);
27+
NotifyCategoryDecl(ffmpeg, EXPCL_FFMPEG, EXPTP_FFMPEG);
28+
29+
extern EXPCL_FFMPEG void init_libffmpeg();
30+
31+
#endif /* CONFIG_FFMPEG_H */
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
////////////////////////////////////////////////////////////////////
1414

1515
#include "ffmpegAudio.h"
16-
17-
#ifdef HAVE_FFMPEG
18-
1916
#include "ffmpegAudioCursor.h"
17+
#include "dcast.h"
2018

2119
TypeHandle FfmpegAudio::_type_handle;
2220

@@ -50,13 +48,19 @@ PT(MovieAudioCursor) FfmpegAudio::
5048
open() {
5149
PT(FfmpegAudioCursor) result = new FfmpegAudioCursor(this);
5250
if (result->_format_ctx == 0) {
53-
movies_cat.error() << "Could not open " << _filename << "\n";
51+
ffmpeg_cat.error() << "Could not open " << _filename << "\n";
5452
return NULL;
5553
} else {
5654
return (MovieAudioCursor*)(FfmpegAudioCursor*)result;
5755
}
5856
}
5957

6058
////////////////////////////////////////////////////////////////////
61-
62-
#endif // HAVE_FFMPEG
59+
// Function: FfmpegAudio::make
60+
// Access: Published, Static
61+
// Description: Obtains a MovieAudio that references a file.
62+
////////////////////////////////////////////////////////////////////
63+
PT(MovieAudio) FfmpegAudio::
64+
make(const Filename &name) {
65+
return DCAST(MovieAudio, new FfmpegAudio(name));
66+
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#define FFMPEGAUDIO_H
1717

1818
#include "pandabase.h"
19-
20-
#ifdef HAVE_FFMPEG
21-
2219
#include "movieAudio.h"
2320

2421
class FfmpegAudioCursor;
@@ -27,13 +24,14 @@ class FfmpegAudioCursor;
2724
// Class : FfmpegAudio
2825
// Description : A stream that generates a sequence of audio samples.
2926
////////////////////////////////////////////////////////////////////
30-
class EXPCL_PANDA_MOVIES FfmpegAudio : public MovieAudio {
31-
27+
class EXPCL_FFMPEG FfmpegAudio : public MovieAudio {
3228
PUBLISHED:
3329
FfmpegAudio(const Filename &name);
3430
virtual ~FfmpegAudio();
3531
virtual PT(MovieAudioCursor) open();
3632

33+
static PT(MovieAudio) make(const Filename &name);
34+
3735
private:
3836
friend class FfmpegAudioCursor;
3937

@@ -57,5 +55,4 @@ class EXPCL_PANDA_MOVIES FfmpegAudio : public MovieAudio {
5755

5856
#include "ffmpegAudio.I"
5957

60-
#endif // HAVE_FFMPEG
61-
#endif // FFMPEG_AUDIO.H
58+
#endif // FFMPEGAUDIO_H
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "ffmpegAudioCursor.h"
1616

17-
#ifdef HAVE_FFMPEG
18-
1917
#include "ffmpegAudio.h"
2018
extern "C" {
2119
#include "libavutil/dict.h"
@@ -116,10 +114,10 @@ FfmpegAudioCursor(FfmpegAudio *src) :
116114
if (_audio_ctx->sample_fmt != AV_SAMPLE_FMT_S16) {
117115
#ifdef HAVE_SWRESAMPLE
118116
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 25, 0)
119-
movies_cat.error()
117+
ffmpeg_cat.error()
120118
<< "Codec does not use signed 16-bit sample format. Upgrade libavcodec to 53.25.0 or higher.\n";
121119
#else
122-
movies_cat.debug()
120+
ffmpeg_cat.debug()
123121
<< "Codec does not use signed 16-bit sample format. Setting up swresample context.\n";
124122
#endif
125123

@@ -132,12 +130,12 @@ FfmpegAudioCursor(FfmpegAudio *src) :
132130
av_opt_set_sample_fmt(_resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
133131

134132
if (swr_init(_resample_ctx) != 0) {
135-
movies_cat.error()
133+
ffmpeg_cat.error()
136134
<< "Failed to set up resample context.\n";
137135
_resample_ctx = NULL;
138136
}
139137
#else
140-
movies_cat.error()
138+
ffmpeg_cat.error()
141139
<< "Codec does not use signed 16-bit sample format, but support for libswresample has not been enabled.\n";
142140
#endif
143141
}
@@ -354,7 +352,7 @@ seek(double t) {
354352
target_ts = _initial_dts;
355353
}
356354
if (av_seek_frame(_format_ctx, _audio_index, target_ts, AVSEEK_FLAG_BACKWARD) < 0) {
357-
movies_cat.error() << "Seek failure. Shutting down movie.\n";
355+
ffmpeg_cat.error() << "Seek failure. Shutting down movie.\n";
358356
cleanup();
359357
return;
360358
}
@@ -417,7 +415,3 @@ read_samples(int n, PN_int16 *data) {
417415
}
418416
_samples_read += n;
419417
}
420-
421-
////////////////////////////////////////////////////////////////////
422-
423-
#endif // HAVE_FFMPEG

0 commit comments

Comments
 (0)