37
37
extern int sound_device_frequency;
38
38
39
39
bool playing_movie = false ;
40
- static bool need_canvas_update = false ;
41
40
static bool skip_bar_active;
42
41
static GLuint canvas = 0 ;
43
42
static uint8_t *rgb_data = nullptr ;
@@ -57,15 +56,42 @@ static float tx2 = 1.0f;
57
56
static float ty1 = 0 .0f ;
58
57
static float ty2 = 1 .0f ;
59
58
static double last_time = 0 ;
60
- static plm_frame_t *movie_frame = nullptr ;
61
- static plm_samples_t *movie_samples = nullptr ;
62
59
63
60
static bool MovieSetupAudioStream (int rate)
64
61
{
65
62
plm_set_audio_lead_time (decoder, (double )1024 / (double )rate);
63
+ PauseMusic ();
64
+ SoundQueueStop ();
65
+ SoundQueueInitialize ();
66
66
return true ;
67
67
}
68
68
69
+ void MovieAudioCallback (plm_t *mpeg, plm_samples_t *samples, void *user)
70
+ {
71
+ (void )mpeg;
72
+ (void )user;
73
+ if (samples)
74
+ {
75
+ SoundData *movie_buf = SoundQueueGetFreeBuffer (PLM_AUDIO_SAMPLES_PER_FRAME);
76
+ if (movie_buf)
77
+ {
78
+ movie_buf->length_ = PLM_AUDIO_SAMPLES_PER_FRAME;
79
+ memcpy (movie_buf->data_ , samples->interleaved , PLM_AUDIO_SAMPLES_PER_FRAME * 2 * sizeof (int16_t ));
80
+ SoundQueueAddBuffer (movie_buf, movie_sample_rate);
81
+ }
82
+ }
83
+ }
84
+
85
+ void MovieVideoCallback (plm_t *mpeg, plm_frame_t *frame, void *user)
86
+ {
87
+ (void )mpeg;
88
+ (void )user;
89
+
90
+ plm_frame_to_rgb (frame, rgb_data, frame->width * 3 );
91
+ glBindTexture (GL_TEXTURE_2D, canvas);
92
+ glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB, frame->width , frame->height , 0 , GL_RGB, GL_UNSIGNED_BYTE, rgb_data);
93
+ }
94
+
69
95
void PlayMovie (const std::string &name)
70
96
{
71
97
MovieDefinition *movie = moviedefs.Lookup (name.c_str ());
@@ -191,6 +217,8 @@ void PlayMovie(const std::string &name)
191
217
int num_pixels = movie_width * movie_height * 3 ;
192
218
rgb_data = new uint8_t [num_pixels];
193
219
memset (rgb_data, 0 , num_pixels);
220
+ plm_set_video_decode_callback (decoder, MovieVideoCallback, nullptr );
221
+ plm_set_audio_decode_callback (decoder, MovieAudioCallback, nullptr );
194
222
if (!no_sound)
195
223
{
196
224
plm_set_audio_enabled (decoder, 1 );
@@ -209,8 +237,6 @@ void PlayMovie(const std::string &name)
209
237
static void EndMovie ()
210
238
{
211
239
plm_destroy (decoder);
212
- movie_frame = nullptr ;
213
- movie_samples = nullptr ;
214
240
decoder = nullptr ;
215
241
delete[] movie_bytes;
216
242
movie_bytes = nullptr ;
@@ -224,23 +250,15 @@ static void EndMovie()
224
250
glDeleteTextures (1 , &canvas);
225
251
canvas = 0 ;
226
252
}
253
+ ResumeMusic ();
227
254
}
228
255
229
256
void MovieDrawer ()
230
257
{
231
258
if (!playing_movie)
232
259
return ;
233
- if (!plm_has_ended (decoder) && movie_frame )
260
+ if (!plm_has_ended (decoder))
234
261
{
235
- if (need_canvas_update)
236
- {
237
- plm_frame_to_rgb (movie_frame, rgb_data, movie_frame->width * 3 );
238
- glBindTexture (GL_TEXTURE_2D, canvas);
239
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB, movie_frame->width , movie_frame->height , 0 , GL_RGB, GL_UNSIGNED_BYTE,
240
- rgb_data);
241
- need_canvas_update = false ;
242
- }
243
-
244
262
SetupMatrices2D ();
245
263
246
264
glEnable (GL_TEXTURE_2D);
@@ -397,22 +415,7 @@ void MovieTicker()
397
415
elapsed_time = 1.0 / 30.0 ;
398
416
last_time = current_time;
399
417
400
- movie_frame = plm_decode_video (decoder);
401
- if (movie_frame)
402
- need_canvas_update = true ;
403
- movie_samples = plm_decode_audio (decoder);
404
- SoundData *movie_buf = SoundQueueGetFreeBuffer (PLM_AUDIO_SAMPLES_PER_FRAME);
405
- if (movie_buf)
406
- {
407
- movie_buf->length_ = PLM_AUDIO_SAMPLES_PER_FRAME;
408
- if (movie_samples)
409
- {
410
- memcpy (movie_buf->data_ , movie_samples->interleaved , PLM_AUDIO_SAMPLES_PER_FRAME * 2 * sizeof (int16_t ));
411
- SoundQueueAddBuffer (movie_buf, movie_sample_rate);
412
- }
413
- else
414
- SoundQueueReturnBuffer (movie_buf);
415
- }
418
+ plm_decode (decoder, elapsed_time);
416
419
417
420
if (skip_bar_active)
418
421
{
0 commit comments