1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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 this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ags/engine/ac/game_setup.h"
24 #include "ags/engine/ac/game_state.h"
25 #include "ags/engine/ac/global_audio.h"
26 #include "ags/engine/ac/global_display.h"
27 #include "ags/engine/ac/global_game.h"
28 #include "ags/engine/ac/global_video.h"
29 #include "ags/engine/ac/path_helper.h"
30 #include "ags/shared/core/asset_manager.h"
31 #include "ags/engine/debugging/debugger.h"
32 #include "ags/engine/debugging/debug_log.h"
33 #include "ags/engine/media/video/video.h"
34 #include "ags/engine/media/audio/audio_system.h"
35 #include "ags/engine/platform/base/ags_platform_driver.h"
36 #include "ags/shared/util/string_compat.h"
37 #include "ags/ags.h"
38 #include "ags/globals.h"
39 
40 namespace AGS3 {
41 
42 using namespace AGS::Shared;
43 
scrPlayVideo(const char * name,int skip,int flags)44 void scrPlayVideo(const char *name, int skip, int flags) {
45 	EndSkippingUntilCharStops();
46 
47 	if (_GP(play).fast_forward)
48 		return;
49 	if (_G(debug_flags) & DBG_NOVIDEO)
50 		return;
51 
52 	if ((flags < 10) && (_GP(usetup).audio_backend == 0)) {
53 		// if game audio is disabled in Setup, then don't
54 		// play any sound on the video either
55 		flags += 10;
56 	}
57 
58 	pause_sound_if_necessary_and_play_video(name, skip, flags);
59 }
60 
61 
62 #ifndef AGS_NO_VIDEO_PLAYER
63 
pause_sound_if_necessary_and_play_video(const char * name,int skip,int flags)64 void pause_sound_if_necessary_and_play_video(const char *name, int skip, int flags) {
65 	int musplaying = _GP(play).cur_music_number, i;
66 	int ambientWas[MAX_SOUND_CHANNELS];
67 	for (i = 1; i < MAX_SOUND_CHANNELS; i++)
68 		ambientWas[i] = _GP(ambient)[i].channel;
69 
70 	if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "ogv") == 0)) {
71 		play_theora_video(name, skip, flags, true);
72 	} else if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "mpg") == 0)) {
73 		play_mpeg_video(name, skip, flags, true);
74 	} else if ((strlen(name) > 3) && (ags_stricmp(&name[strlen(name) - 3], "avi") == 0)) {
75 		play_avi_video(name, skip, flags, true);
76 	} else {
77 		// Unsure what the video type is, so try each in turn
78 		if (!play_avi_video(name, skip, flags, false) &&
79 		        !play_mpeg_video(name, skip, flags, false) &&
80 		        !play_theora_video(name, skip, flags, false))
81 			Display("Unsupported video '%s'", name);
82 	}
83 
84 	if (flags < 10) {
85 		update_music_volume();
86 		// restart the music
87 		if (musplaying >= 0)
88 			newmusic(musplaying);
89 		for (i = 1; i < MAX_SOUND_CHANNELS; i++) {
90 			if (ambientWas[i] > 0)
91 				PlayAmbientSound(ambientWas[i], _GP(ambient)[i].num, _GP(ambient)[i].vol, _GP(ambient)[i].x, _GP(ambient)[i].y);
92 		}
93 	}
94 }
95 
96 #else
97 
pause_sound_if_necessary_and_play_video(const char * name,int skip,int flags)98 void pause_sound_if_necessary_and_play_video(const char *name, int skip, int flags) {
99 }
100 
101 #endif
102 
103 } // namespace AGS3
104