Skip to content

Commit d831be3

Browse files
committed
Hardcode everything that can be get
1 parent ebc8a52 commit d831be3

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

video_stream_mpg.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,12 @@ void VideoStreamPlaybackMPG::set_file(const String &p_file) {
6969
plm_set_video_decode_callback(mpeg, video_callback, this);
7070
plm_set_audio_decode_callback(mpeg, audio_callback, this);
7171

72-
if (plm_get_num_audio_streams(mpeg) > 0) {
73-
plm_set_audio_stream(mpeg, audio_track);
74-
channels = mpeg->audio_buffer->mode == PLM_AUDIO_MODE_MONO ? 1 : 2;
75-
mix_rate = plm_get_samplerate(mpeg);
76-
} else {
77-
plm_set_audio_enabled(mpeg, FALSE);
78-
}
79-
80-
size.x = plm_get_width(mpeg);
81-
size.y = plm_get_height(mpeg);
72+
int x = plm_get_width(mpeg);
73+
int y = plm_get_height(mpeg);
8274

83-
Ref<Image> img = Image::create_empty(size.x, size.y, false, Image::FORMAT_RGBA8);
75+
Ref<Image> img = Image::create_empty(x, y, false, Image::FORMAT_RGBA8);
8476
texture->set_image(img);
8577

86-
length = plm_get_duration(mpeg);
87-
88-
time = 0;
8978
playing = false;
9079
}
9180

@@ -105,9 +94,7 @@ void VideoStreamPlaybackMPG::clear() {
10594
}
10695

10796
void VideoStreamPlaybackMPG::play() {
108-
if (!playing) {
109-
time = 0;
110-
} else {
97+
if (playing) {
11198
stop();
11299
}
113100

@@ -121,7 +108,6 @@ void VideoStreamPlaybackMPG::stop() {
121108
set_file(file_name);
122109
}
123110
playing = false;
124-
time = 0;
125111
}
126112

127113
bool VideoStreamPlaybackMPG::is_playing() const {
@@ -137,11 +123,11 @@ bool VideoStreamPlaybackMPG::is_paused() const {
137123
}
138124

139125
double VideoStreamPlaybackMPG::get_length() const {
140-
return 0;
126+
return plm_get_duration(mpeg);
141127
}
142128

143129
double VideoStreamPlaybackMPG::get_playback_position() const {
144-
return time - plm_get_audio_lead_time(mpeg);
130+
return plm_get_time(mpeg) - plm_get_audio_lead_time(mpeg);
145131
}
146132

147133
void VideoStreamPlaybackMPG::seek(double p_time) {
@@ -160,14 +146,15 @@ void VideoStreamPlaybackMPG::update(double p_delta) {
160146
if (!playing || paused) {
161147
return;
162148
}
163-
time += p_delta;
164149

165150
plm_decode(mpeg, p_delta);
166151

167152
if (frame_pending) { // Write frame to texture
168-
frame_data.resize((size.x * size.y) << 2);
169-
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);
170-
Ref<Image> img = memnew(Image(size.x, size.y, false, Image::FORMAT_RGBA8, frame_data));
153+
int x = frame_current->width;
154+
int y = frame_current->height;
155+
frame_data.resize((x * y) << 2);
156+
yuv420_2_rgb8888(frame_data.ptrw(), frame_current->y.data, frame_current->cb.data, frame_current->cr.data, x, y, x, x >> 1, x << 2);
157+
Ref<Image> img = memnew(Image(x, y, false, Image::FORMAT_RGBA8, frame_data));
171158
texture->update(img);
172159

173160
frame_pending = false;
@@ -179,15 +166,15 @@ void VideoStreamPlaybackMPG::update(double p_delta) {
179166
}
180167

181168
int VideoStreamPlaybackMPG::get_channels() const {
182-
return channels;
169+
return mpeg->audio_buffer->mode == PLM_AUDIO_MODE_MONO ? 1 : 2;
183170
}
184171

185172
int VideoStreamPlaybackMPG::get_mix_rate() const {
186-
return mix_rate;
173+
return plm_get_samplerate(mpeg);
187174
}
188175

189176
void VideoStreamPlaybackMPG::set_audio_track(int p_track) {
190-
audio_track = p_track;
177+
plm_set_audio_stream(mpeg, p_track);
191178
}
192179

193180
VideoStreamPlaybackMPG::VideoStreamPlaybackMPG() {

video_stream_mpg.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class VideoStreamPlaybackMPG : public VideoStreamPlayback {
1919
LocalVector<uint8_t> file_data; // HACK: remove once a proper plm_buffer_t with FileAccess is done
2020
Ref<ImageTexture> texture;
2121
Vector<uint8_t> frame_data; // Image creation has a big overhead converting from LocalVector
22-
Point2i size;
2322

2423
plm_frame_t *frame_current = nullptr;
2524
bool frame_pending = false;
@@ -32,12 +31,6 @@ class VideoStreamPlaybackMPG : public VideoStreamPlayback {
3231
bool playing = false;
3332
bool paused = false;
3433

35-
double length = 0;
36-
double time = 0;
37-
int channels = 0;
38-
int mix_rate = 0;
39-
int audio_track = 0;
40-
4134
protected:
4235
void clear();
4336

@@ -77,8 +70,8 @@ class VideoStreamMPG : public VideoStream {
7770
public:
7871
Ref<VideoStreamPlayback> instantiate_playback() override {
7972
Ref<VideoStreamPlaybackMPG> pb = memnew(VideoStreamPlaybackMPG);
80-
pb->set_audio_track(audio_track);
8173
pb->set_file(file);
74+
pb->set_audio_track(audio_track);
8275
return pb;
8376
}
8477

0 commit comments

Comments
 (0)