Skip to content

Commit 7557307

Browse files
committed
Refactor
1 parent 734538a commit 7557307

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

video_stream_mpg.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
#include "thirdparty/misc/yuv2rgb.h"
1313

14-
void VideoStreamPlaybackMPG::buffer_data(plm_buffer_t *buf, void *user) { // TODO: fix this and use custom buffer
15-
PLM_UNUSED(user);
14+
void VideoStreamPlaybackMPG::dummy_yuv2rgb() {
15+
// MPEG-1 only supports 4:2:0, these are here to prevent werror from yelling
16+
yuv444_2_rgb8888(nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0);
17+
yuv422_2_rgb8888(nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0);
18+
}
19+
20+
void VideoStreamPlaybackMPG::load_callback(plm_buffer_t *buf, void *user) { // TODO: fix this and use custom buffer
1621
Ref<FileAccess> fa = *(Ref<FileAccess> *)buf->load_callback_user_data;
1722

1823
if (buf->discard_read_bytes) {
@@ -28,17 +33,14 @@ void VideoStreamPlaybackMPG::buffer_data(plm_buffer_t *buf, void *user) { // TOD
2833
}
2934
}
3035

31-
void VideoStreamPlaybackMPG::video_write(plm_t *self, plm_frame_t *frame, void *user) {
32-
PLM_UNUSED(user);
33-
VideoStreamPlaybackMPG *ps = (VideoStreamPlaybackMPG *)self->video_decode_callback_user_data;
36+
void VideoStreamPlaybackMPG::video_callback(plm_t *self, plm_frame_t *frame, void *user) {
37+
VideoStreamPlaybackMPG *ps = (VideoStreamPlaybackMPG *)user;
3438
ps->frame_current = frame;
3539
ps->frame_pending = true;
3640
}
3741

38-
void VideoStreamPlaybackMPG::audio_write(plm_t *self, plm_samples_t *samples, void *user) {
39-
PLM_UNUSED(user);
40-
VideoStreamPlaybackMPG *ps = (VideoStreamPlaybackMPG *)self->audio_decode_callback_user_data;
41-
42+
void VideoStreamPlaybackMPG::audio_callback(plm_t *self, plm_samples_t *samples, void *user) {
43+
VideoStreamPlaybackMPG *ps = (VideoStreamPlaybackMPG *)user;
4244
if (ps->mix_callback) {
4345
ps->mix_callback(ps->mix_udata, samples->interleaved, samples->count);
4446
}
@@ -64,8 +66,8 @@ void VideoStreamPlaybackMPG::set_file(const String &p_file) {
6466
file->close();
6567
mpeg = plm_create_with_memory(file_data.ptr(), file_data.size(), FALSE);
6668

67-
plm_set_video_decode_callback(mpeg, video_write, this);
68-
plm_set_audio_decode_callback(mpeg, audio_write, this);
69+
plm_set_video_decode_callback(mpeg, video_callback, this);
70+
plm_set_audio_decode_callback(mpeg, audio_callback, this);
6971

7072
if (plm_get_num_audio_streams(mpeg) > 0) {
7173
plm_set_audio_stream(mpeg, audio_track);
@@ -163,15 +165,9 @@ void VideoStreamPlaybackMPG::update(double p_delta) {
163165

164166
plm_decode(mpeg, p_delta);
165167

166-
if (frame_pending) {
168+
if (frame_pending) { // Write frame to texture
167169
frame_data.resize((size.x * size.y) << 2);
168170
yuv420_2_rgb8888(frame_data.ptrw(), frame_current->y.data, frame_current->cb.data, frame_current->cr.data, size.x, size.y, size.x, size.x >> 1, size.x << 2);
169-
170-
if (false) { // MPEG-1 only supports 4:2:0, these are here to prevent werror from yelling
171-
yuv444_2_rgb8888(nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0);
172-
yuv422_2_rgb8888(nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0);
173-
}
174-
175171
Ref<Image> img = memnew(Image(size.x, size.y, false, Image::FORMAT_RGBA8, frame_data));
176172
texture->update(img);
177173

video_stream_mpg.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ class VideoStreamPlaybackMPG : public VideoStreamPlayback {
1313
GDCLASS(VideoStreamPlaybackMPG, VideoStreamPlayback);
1414

1515
plm_t *mpeg = nullptr;
16-
plm_frame_t *frame_current = nullptr;
1716

1817
Ref<FileAccess> file;
1918
String file_name;
20-
LocalVector<uint8_t> file_data; // HACK: remove once a proper plm_buffer_t with FileAccess is done
19+
LocalVector<uint8_t> file_data; // HACK: remove once a proper plm_buffer_t with FileAccess is done
2120
Ref<ImageTexture> texture;
2221
Vector<uint8_t> frame_data; // Image creation has a big overhead converting from LocalVector
2322
Point2i size;
2423

24+
plm_frame_t *frame_current = nullptr;
2525
bool frame_pending = false;
2626

27-
static void buffer_data(plm_buffer_t *buf, void *user);
28-
static void video_write(plm_t *self, plm_frame_t *frame, void *user);
29-
static void audio_write(plm_t *self, plm_samples_t *samples, void *user);
27+
static void dummy_yuv2rgb();
28+
static void load_callback(plm_buffer_t *buf, void *user);
29+
static void video_callback(plm_t *self, plm_frame_t *frame, void *user);
30+
static void audio_callback(plm_t *self, plm_samples_t *samples, void *user);
3031

3132
int delay_compensation = 0;
3233

3334
bool playing = false;
3435
bool paused = false;
35-
36+
3637
double length = 0;
3738
double time = 0;
3839
int channels = 0;

0 commit comments

Comments
 (0)