Skip to content

Commit

Permalink
Fix MPEG playback on Sokol render paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jan 21, 2025
1 parent b9e9b5e commit d74868b
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions source_files/edge/i_movie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ static float ty2 = 1.0f;
static double last_time = 0;
static ma_pcm_rb movie_ring_buffer;
static ma_sound movie_sound_buffer;
static bool canvas_can_update;

// Disabled until Dasho can figure out why the frame size changes between creating the texture and updating it
// Which is probably also an issue under GL1
#ifndef EDGE_SOKOL
static bool MovieSetupAudioStream(int rate)
{
if (ma_pcm_rb_init(ma_format_f32, 2, PLM_AUDIO_SAMPLES_PER_FRAME * 4, NULL, NULL, &movie_ring_buffer) != MA_SUCCESS)
Expand All @@ -87,7 +85,6 @@ static bool MovieSetupAudioStream(int rate)
ma_engine_set_volume(&music_engine, music_volume.f_);
return true;
}
#endif

void MovieAudioCallback(plm_t *mpeg, plm_samples_t *samples, void *user)
{
Expand Down Expand Up @@ -137,23 +134,20 @@ void MovieVideoCallback(plm_t *mpeg, plm_frame_t *frame, void *user)
EPI_UNUSED(mpeg);
EPI_UNUSED(user);

plm_frame_to_rgba(frame, rgb_data, frame->width * 4);
if (canvas_can_update)
{
plm_frame_to_rgba(frame, rgb_data, frame->width * 4);

render_state->BindTexture(canvas);
render_state->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frame->width, frame->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
rgb_data);
render_state->BindTexture(canvas);
render_state->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frame->width, frame->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
rgb_data);

canvas_can_update = false;
}
}

void PlayMovie(const std::string &name)
{
#ifdef EDGE_SOKOL
// Disabled until Dasho can figure out why the frame size changes between creating the texture and updating it
// Which is probably also an issue under GL1
EPI_UNUSED(name);
playing_movie = false;
skip_bar_active = false;
return;
#else
MovieDefinition *movie = moviedefs.Lookup(name.c_str());

if (!movie)
Expand Down Expand Up @@ -274,7 +268,7 @@ void PlayMovie(const std::string &name)

#ifdef EDGE_SOKOL
// On sokol, this sets up the texture dimenions, for dynamic texture
render_state->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frame_width, frame_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
render_state->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, movie_width, movie_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr, kRenderUsageDynamic);
render_state->FinishTextures(1, &canvas);
#endif
Expand Down Expand Up @@ -302,7 +296,7 @@ void PlayMovie(const std::string &name)
fadeout = 0;

playing_movie = true;
#endif
canvas_can_update = true;
}

static void EndMovie()
Expand Down Expand Up @@ -434,6 +428,8 @@ void MovieDrawer()

FinishUnitBatch();
}

canvas_can_update = true;
}

bool MovieResponder(InputEvent *ev)
Expand Down

0 comments on commit d74868b

Please sign in to comment.