Panda3D
 All Classes Functions Variables Enumerations
ffmpegVideo.cxx
1 // Filename: ffmpegVideo.cxx
2 // Created by: jyelon (01Aug2007)
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 "ffmpegVideo.h"
16 #include "ffmpegVideoCursor.h"
17 #include "config_ffmpeg.h"
18 #include "bamReader.h"
19 #include "dcast.h"
20 
21 TypeHandle FfmpegVideo::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: FfmpegVideo::Constructor
25 // Access: Public
26 // Description: Constructs an ffmpeg video that reads its contents
27 // from the indicate filename, which may be a file in
28 // the VFS.
29 ////////////////////////////////////////////////////////////////////
31 FfmpegVideo(const Filename &name) :
32  MovieVideo(name)
33 {
34  _filename = name;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: FfmpegVideo::Constructor
39 // Access: Public
40 // Description: Constructs an ffmpeg video that reads its contents
41 // from the indicated subfile information. This is
42 // normally used for low-level purposes only; you would
43 // normally use the constructor that takes a filename.
44 ////////////////////////////////////////////////////////////////////
46 FfmpegVideo(const SubfileInfo &info) :
47  MovieVideo(info.get_filename())
48 {
49  _filename = info.get_filename();
50  _subfile_info = info;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: FfmpegVideo::Destructor
55 // Access: Public
56 // Description: xxx
57 ////////////////////////////////////////////////////////////////////
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: FfmpegVideo::open
64 // Access: Published, Virtual
65 // Description: Open this video, returning a MovieVideoCursor.
66 ////////////////////////////////////////////////////////////////////
68 open() {
69  PT(FfmpegVideoCursor) result = new FfmpegVideoCursor(this);
70  if (result->_format_ctx == 0) {
71  ffmpeg_cat.error() << "Could not open " << _filename << "\n";
72  return NULL;
73  } else {
74  return result.p();
75  }
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: FfmpegVideo::make
80 // Access: Published, Static
81 // Description: Obtains a MovieVideo that references a file.
82 ////////////////////////////////////////////////////////////////////
84 make(const Filename &name) {
85  return DCAST(MovieVideo, new FfmpegVideo(name));
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: FfmpegVideo::register_with_read_factory
90 // Access: Public, Static
91 // Description: Tells the BamReader how to create objects of type
92 // FfmpegVideo.
93 ////////////////////////////////////////////////////////////////////
94 void FfmpegVideo::
96  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: FfmpegVideo::write_datagram
101 // Access: Public, Virtual
102 // Description: Writes the contents of this object to the datagram
103 // for shipping out to a Bam file.
104 ////////////////////////////////////////////////////////////////////
105 void FfmpegVideo::
107  MovieVideo::write_datagram(manager, dg);
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: FfmpegVideo::make_from_bam
112 // Access: Protected, Static
113 // Description: This function is called by the BamReader's factory
114 // when a new object of type FfmpegVideo is encountered
115 // in the Bam file. It should create the FfmpegVideo
116 // and extract its information from the file.
117 ////////////////////////////////////////////////////////////////////
118 TypedWritable *FfmpegVideo::
119 make_from_bam(const FactoryParams &params) {
120  FfmpegVideo *video = new FfmpegVideo("");
121  DatagramIterator scan;
122  BamReader *manager;
123 
124  parse_params(params, scan, manager);
125  video->fillin(scan, manager);
126 
127  return video;
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: FfmpegVideo::fillin
132 // Access: Protected
133 // Description: This internal function is called by make_from_bam to
134 // read in all of the relevant data from the BamFile for
135 // the new FfmpegVideo.
136 ////////////////////////////////////////////////////////////////////
137 void FfmpegVideo::
138 fillin(DatagramIterator &scan, BamReader *manager) {
139  MovieVideo::fillin(scan, manager);
140 }
const Filename & get_filename() const
Returns the movie&#39;s filename.
Definition: movieAudio.I:23
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static void register_with_read_factory()
Tells the BamReader how to create objects of type FfmpegVideo.
Definition: ffmpegVideo.cxx:95
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A MovieVideo is actually any source that provides a sequence of video frames.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: movieVideo.cxx:77
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
FfmpegVideo(const Filename &name)
Constructs an ffmpeg video that reads its contents from the indicate filename, which may be a file in...
Definition: ffmpegVideo.cxx:31
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
const Filename & get_filename() const
A shortcut to the filename.
Definition: subfileInfo.I:106
A MovieVideo is actually any source that provides a sequence of video frames.
Definition: movieVideo.h:42
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:29
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual ~FfmpegVideo()
xxx
Definition: ffmpegVideo.cxx:59