xoreos  0.0.5
videoplayer.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <boost/scope_exit.hpp>
26 
27 #include "src/common/util.h"
28 #include "src/common/error.h"
29 #include "src/common/ustring.h"
30 #include "src/common/readstream.h"
31 #include "src/common/debug.h"
32 
33 #include "src/video/decoder.h"
34 #include "src/video/actimagine.h"
35 #include "src/video/bink.h"
36 #include "src/video/quicktime.h"
37 #include "src/video/xmv.h"
38 
40 
41 #include "src/events/events.h"
42 #include "src/events/requests.h"
43 
44 #include "src/aurora/resman.h"
45 
46 namespace Video {
47 
48 namespace Aurora {
49 
51  load(video);
52 }
53 
55 }
56 
58  ::Aurora::FileType type;
59 
61  video(ResMan.getResource(::Aurora::kResourceVideo, name, &type));
62  if (!video)
63  throw Common::Exception("No such video resource \"%s\"", name.c_str());
64 
65  // Loading the different video formats
66  switch (type) {
68  _video.reset(new Bink(video.release()));
69  break;
71  _video.reset(new QuickTimeDecoder(video.release()));
72  break;
74  _video.reset(new XboxMediaVideo(video.release()));
75  break;
77  _video.reset(new ActimagineDecoder(video.release()));
78  break;
79  default:
80  break;
81  }
82 
83  if (!_video)
84  throw Common::Exception("Unsupported video resource type %d", (int) type);
85 
87 }
88 
90  RequestMan.sync();
91 
92  _video->start();
93 
94  BOOST_SCOPE_EXIT( (&_video) ) {
95  _video->abort();
96  } BOOST_SCOPE_EXIT_END
97 
98  uint32 width = _video->getWidth();
99  uint32 height = _video->getHeight();
100 
101  debugC(Common::kDebugVideo, 1, "Starting video (%ux%u)", width, height);
102 
103  bool brk = false;
104 
105  Events::Event event;
106  while (!EventMan.quitRequested()) {
107 
108  while (EventMan.pollEvent(event)) {
109  if ((event.type == Events::kEventKeyDown && event.key.keysym.sym == SDLK_ESCAPE) ||
110  (event.type == Events::kEventMouseUp))
111  brk = true;
112  }
113 
114  if (brk || !_video->isPlaying())
115  break;
116 
117  EventMan.delay(10);
118  }
119 
120  if (EventMan.quitRequested() || brk)
121  debugC(Common::kDebugVideo, 1, "Aborting video");
122  else
123  debugC(Common::kDebugVideo, 1, "Ending video");
124 }
125 
126 } // End of namespace Aurora
127 
128 } // End of namespace Video
A video player.
void load(const Common::UString &name)
Definition: videoplayer.cpp:57
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Inter-thread request events.
void debugC(Common::DebugChannel channel, uint32 level, const char *s,...)
Definition: debug.cpp:34
A class holding an UTF-8 string.
Definition: ustring.h:48
Utility functions for debug output.
Decoding Actimagine videos.
VideoPlayer(const Common::UString &video)
Definition: videoplayer.cpp:50
Common::ScopedPtr< VideoDecoder > _video
Definition: videoplayer.h:49
A decoder for RAD Game Tools&#39; Bink videos.
Definition: bink.h:98
SDL_Event Event
Definition: types.h:42
A decoder for Actimagine videos.
Definition: actimagine.h:40
Keyboard key was pressed.
Definition: types.h:46
Mouse button was released.
Definition: types.h:50
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Video, Actimagine.
Definition: types.h:280
"GVideo", global, non-engine video (movies).
Definition: debugman.h:44
A decoder for Microsoft Xbox XMV videos.
Definition: xmv.h:48
Utility templates and functions.
Decoding RAD Game Tools&#39; Bink videos.
Decoding Microsoft Xbox XMV videos.
The global events manager.
StackException Exception
Definition: error.h:59
Basic reading stream interfaces.
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
Video, QuickTime/MPEG-4.
Definition: types.h:324
Unicode string handling.
Video, RAD Game Tools Bink.
Definition: types.h:129
A video resource.
Definition: types.h:409
Decoding Apple QuickTime videos.
uint32_t uint32
Definition: types.h:204
Decoder for QuickTime videos.
Definition: quicktime.h:84
FileType
Various file types used by the Aurora engine and found in archives.
Definition: types.h:56
#define RequestMan
Shortcut for accessing the request manager.
Definition: requests.h:127
Video, Xbox.
Definition: types.h:70
Scale the video up and down, if necessary.
Definition: decoder.h:61
The global resource manager for Aurora resources.
Generic video decoder interface.