29 #define PL_MPEG_IMPLEMENTATION
30 #include <ext/pl_mpeg/pl_mpeg.h>
45 using std::make_unique;
48 using std::unique_ptr;
55 void MPEG1Decoder::openFile(
const string& pathName,
const string& fileName) {
60 plm = plm_create_with_filename((pathName +
"/" + fileName).c_str());
62 Console::println(
"MPEG1Decoder::openFile(): Failed to open: " + pathName +
"/" + fileName);
77 audioBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(32768));
80 plm_set_loop(
plm, TRUE);
81 plm_set_audio_enabled(
plm, TRUE);
82 plm_set_audio_stream(
plm, 0);
85 if (plm_get_num_audio_streams(
plm) > 0) {
86 auto samplesPerBuffer = 4096;
92 if (
plm ==
nullptr)
return;
93 plm_seek(
plm, 0.0f, FALSE);
97 if (
plm ==
nullptr)
return;
98 plm_decode(
plm, deltaTime);
102 if (
plm ==
nullptr)
return;
103 plm_seek(
plm, time, FALSE);
107 if (
plm ==
nullptr)
return 0LL;
115 if (
plm ==
nullptr)
return 0LL;
122 if (
plm ==
nullptr)
return;
131 auto frameBuffer = mpeg1Decoder->
videoBuffer->getBuffer();
132 plm_frame_to_rgba(frame, frameBuffer, frame->width * 4);
133 for (
auto y = 0; y < mpeg1Decoder->videoHeight; y++) {
134 for (
auto x = 0; x < mpeg1Decoder->videoWidth; x++) {
135 frameBuffer[y * mpeg1Decoder->videoWidth * 4 + x * 4 + 3] = 0xff;
142 int samplesToProcess = samples->count * 2;
143 for (
auto i = 0LL; i < samplesToProcess; i++) {
144 auto sample =
static_cast<int16_t
>(samples->interleaved[i] * 32767);
145 mpeg1Decoder->
audioBuffer->put((uint8_t*)&sample,
sizeof(int16_t));
Buffer * put(uint8_t value)
Put value into buffer.
virtual int64_t getCapacity() const
virtual int64_t getPosition() const
PL_MPEG/MPEG1 video decoder.
int64_t readVideoFromStream(ByteBuffer *data) override
Read raw RGB video data from stream.
void close() override
Closes the audio file.
int64_t readAudioFromStream(ByteBuffer *data) override
Read raw PCM data from stream.
unique_ptr< ByteBuffer > audioBuffer
void update(float deltaTime) override
Update.
unique_ptr< ByteBuffer > videoBuffer
void seek(float time) override
Update.
static void plmOnVideo(plm_t *plm, plm_frame_t *frame, void *user)
PLM on video.
void reset() override
Resets this video decoder, if a stream was open it will be rewinded.
static void plmOnAudio(plm_t *plm, plm_samples_t *samples, void *user)
PLM on audio.