pl_mpegDC ported running but community help needed

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Twada
DC Developer
DC Developer
Posts: 45
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 20 times
Been thanked: 56 times

Re: pl_mpegDC ported running but community help needed

Post by Twada »

Ian Robinson wrote: Wed Oct 04, 2023 12:51 pm With my update before been able to watch 1 hour with no sync problems audio with the right encoding.
It is amazing!
This time, I was worried about whether the frame rate was correct because I matched it to the audio time.
I can't wait to see your update.

Your 64bitSQ seems to be faster than KOS's SQ, but how does it work?
These users thanked the author Twada for the post:
Ian Robinson
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

Twada wrote: Wed Oct 04, 2023 2:40 pm
Ian Robinson wrote: Wed Oct 04, 2023 12:51 pm With my update before been able to watch 1 hour with no sync problems audio with the right encoding.
It is amazing!
This time, I was worried about whether the frame rate was correct because I matched it to the audio time.
I can't wait to see your update.

Your 64bitSQ seems to be faster than KOS's SQ, but how does it work?
There's no need to try to wait for SQs to finish. SQs always start immediately (if the CPU can't start the SQ right away, because some kind of memory transfer is already happening, the CPU will stall until it can start the SQ). And while the SQ is happening, it's not possible to access the memory bus (if you try to, the CPU will stall until the SQ transfer completes). So there's never a point you can access RAM or an external hardware register before the SQ write completes.

No wait is lot of it.
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

I be looking at your update very soon to see if we can solve the it cant play more then 18 mins on hardware. It's playing right thru on demul dcemulator another one of those times.. after 18 mins it gets super slow for a while then freezes crashes.. Problem was time to make a change and test 18 mins of wear on the gdrom drive each time.. Prolly need to setup up my gdemu again as doing this for days and hours at time is bit much..
Twada
DC Developer
DC Developer
Posts: 45
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 20 times
Been thanked: 56 times

Re: pl_mpegDC ported running but community help needed

Post by Twada »

Ian Robinson wrote: Sat Oct 28, 2023 7:39 pm I be looking at your update very soon to see if we can solve the it cant play more then 18 mins on hardware. It's playing right thru on demul dcemulator another one of those times.. after 18 mins it gets super slow for a while then freezes crashes.. Problem was time to make a change and test 18 mins of wear on the gdrom drive each time.. Prolly need to setup up my gdemu again as doing this for days and hours at time is bit much..
I was able to play a 43 minute video with the last version, Ver0.9.
I can't be sure, but it may be a problem with the accuracy of timer_ms_gettime64().

In the first version, frame rate control was as follows.

Code: Select all

float start_time = (float)timer_ms_gettime64() / 1000.0;
float playing_time = 0.0f;
float frame_time = 1.0f / (float)plm_get_framerate(plm);
...
...
/* Decode */
playing_time = ((float)timer_ms_gettime64() / 1000.0) - start_time;
if ((frame->time - playing_time) < frame_time)
{
    frame = plm_decode_video(plm);
    if (!frame)
        break;
    decoded = 1;
}
The last version does not use timer_ms_gettime64().
I'm just comparing the decoded video and audio times. Therefore, the frame rate may not be uniform.

Code: Select all

sample = plm_decode_audio(plm);
if (sample == NULL)
{
    audio_time += audio_interval;
    break;
}
audio_time = sample->time;
...
...
audio_interval = audio_time;
...
...
/* Decode */
if ((audio_time - audio_interval) >= frame->time)
{
    frame = plm_decode_video(plm);
    if (!frame)
        break;
    decoded = 1;
}
But there's a new problem. As the loading time changes for long videos, we found that there was a difference from the audio_interval that was set at the beginning, causing audio lag.
Also, it didn't come back even after the video ended. I need to fix the termination process.
These users thanked the author Twada for the post:
Ian Robinson
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

I tested now updated playing now over 50 mins https://github.com/ianmicheal/MPEG1-Dec ... 9-19-Tashi
These users thanked the author Ian Robinson for the post:
Twada
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

watch whole movie 1 hour 30 no trouble
bandicam 2023-10-30 06-32-03-310.jpg
These users thanked the author Ian Robinson for the post:
GyroVorbis
GyroVorbis
DCEmu Banned
DCEmu Banned
Posts: 1876
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has thanked: 82 times
Been thanked: 64 times
Contact:

Re: pl_mpegDC ported running but community help needed

Post by GyroVorbis »

So what was the issue with the playback crashing or slowing down after a certain amount of time? There's definitely a race condition in the implementation of timer_ms_gettime64(), and I'm working on a PR right now to fix it... but I guess that wasn't the problem here if it's working for Ian?
These users thanked the author GyroVorbis for the post:
Ian Robinson
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

It was the timer for sure it's now stable runs and even releasing memory fine compiled into my program
https://streamable.com/ce1rhk playing on cdr built into my menu code.

Even started recreating old fmv games with out a problem.
These users thanked the author Ian Robinson for the post:
GyroVorbis
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

GyroVorbis
DCEmu Banned
DCEmu Banned
Posts: 1876
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has thanked: 82 times
Been thanked: 64 times
Contact:

Re: pl_mpegDC ported running but community help needed

Post by GyroVorbis »

Guys, I just wanted to post publicly, for those of you not following along with the KOS and kos-ports master branch that pl_mpegDC has officially been approved and added as a kos-pot as libmpeg!

https://github.com/KallistiOS/kos-ports ... er/libmpeg

Thank you to Twada, Ian, BBHoodsta, and everyone who made this possible! Hopefully we will eventually be adding a good example to the KOS repo which shows how to use it. I definitely think everyone who wants to add cutscenes to their game is going to want to include this in their games!
These users thanked the author GyroVorbis for the post (total 2):
Ian RobinsonTwada
Moi
QuakeDev Respected
QuakeDev Respected
Posts: 592
Joined: Thu Mar 14, 2002 1:15 am
Has thanked: 0
Been thanked: 6 times

Re: pl_mpegDC ported running but community help needed

Post by Moi »

Great stuff! Any chance for a VCD player being made out of that library?
These users thanked the author Moi for the post (total 2):
|darc|GyroVorbis
Create your own Dreamcast games using the Quake-Engine:
http://quakedev.dcemulation.org/develop/getstarted.htm
|darc|
DCEmu Webmaster
DCEmu Webmaster
Posts: 16389
Joined: Wed Mar 14, 2001 6:00 pm
Location: New Orleans, LA
Has thanked: 120 times
Been thanked: 92 times
Contact:

Re: pl_mpegDC ported running but community help needed

Post by |darc| »

Moi wrote: Fri Jan 19, 2024 5:43 am Great stuff! Any chance for a VCD player being made out of that library?
I'd wondered the same thing; Ian says he's not interested in making a VCD Player, but it should be a great starting point for anyone who's interested in that
These users thanked the author |darc| for the post (total 2):
GyroVorbisIan Robinson
It's thinking...
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

Update converted to DR render state much faster
https://github.com/ianmicheal/MPEG1-Dec ... peg1.c#L22
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

Latest

More optimized
mpeg1.c
(16.49 KiB) Downloaded 42 times
:)
These users thanked the author Ian Robinson for the post (total 2):
|darc|Twada
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

Update up port to new kos and gcc13 640x480
https://streamable.com/ij2wgz

Update src soon :)
These users thanked the author Ian Robinson for the post:
|darc|
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

PL_MPEG640x480
Optimized middleware for KallistiOS for intro logos you can auto load your main program The recommended resolutions are: 640x480 up to 800kb/sec 112kb/sec audio This is not for movies but for logos and branding for indie games. Thanks to ross for helping me with the math to get 640x480 to work!
WARNING not for long videos for short logo's company names at HQ
loading from /rd/ is fast and smooth loading from /cd/ is very slow might be fine for GDEMU

example HQ branding short videos https://streamable.com/kd9hcd

reading from a romdisk /rd/
https://github.com/ianmicheal/PL_MPEG640x480

Reading from a cdr /cd/
https://streamable.com/3fb3y9

Ok for movies this is not the version i was asked for HQ version that could show company logo or intros that's what this version is for only..
New kos and gcc13 up port..
These users thanked the author Ian Robinson for the post:
|darc|
Twada
DC Developer
DC Developer
Posts: 45
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 20 times
Been thanked: 56 times

Re: pl_mpegDC ported running but community help needed

Post by Twada »

Ian Robinson wrote: Thu Sep 19, 2024 6:06 pm PL_MPEG640x480
Optimized middleware for KallistiOS for intro logos you can auto load your main program The recommended resolutions are: 640x480 up to 800kb/sec 112kb/sec audio This is not for movies but for logos and branding for indie games. Thanks to ross for helping me with the math to get 640x480 to work!
WARNING not for long videos for short logo's company names at HQ
loading from /rd/ is fast and smooth loading from /cd/ is very slow might be fine for GDEMU

example HQ branding short videos https://streamable.com/kd9hcd

reading from a romdisk /rd/
https://github.com/ianmicheal/PL_MPEG640x480

Reading from a cdr /cd/
https://streamable.com/3fb3y9

Ok for movies this is not the version i was asked for HQ version that could show company logo or intros that's what this version is for only..
New kos and gcc13 up port..
The 640x480 video is beautiful!

The sound was set to mono due to processing speed, but if we could play videos at a high resolution like 640x480, we might be able to implement stereo sound.

The recent updates to KOS have been remarkable!
These users thanked the author Twada for the post:
Ian Robinson
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

Twada wrote: Sat Sep 21, 2024 8:32 am
Ian Robinson wrote: Thu Sep 19, 2024 6:06 pm PL_MPEG640x480
Optimized middleware for KallistiOS for intro logos you can auto load your main program The recommended resolutions are: 640x480 up to 800kb/sec 112kb/sec audio This is not for movies but for logos and branding for indie games. Thanks to ross for helping me with the math to get 640x480 to work!
WARNING not for long videos for short logo's company names at HQ
loading from /rd/ is fast and smooth loading from /cd/ is very slow might be fine for GDEMU

example HQ branding short videos https://streamable.com/kd9hcd

reading from a romdisk /rd/
https://github.com/ianmicheal/PL_MPEG640x480

Reading from a cdr /cd/
https://streamable.com/3fb3y9

Ok for movies this is not the version i was asked for HQ version that could show company logo or intros that's what this version is for only..
New kos and gcc13 up port..
The 640x480 video is beautiful!

The sound was set to mono due to processing speed, but if we could play videos at a high resolution like 640x480, we might be able to implement stereo sound.

The recent updates to KOS have been remarkable!
I have found out that DMA transfer lets it run fullspeed all the time but there is a problem on hardware doing this but not on dc emulators
Here is it running with DMA transfer on flycast https://streamable.com/wu0c4z Total constant 29fps

Now on hardware it is also 29fps but with this glitch it's not all the time.
bandicam 2024-09-22 07-12-48-234.jpg
i wrote a debug function to check yuv conversion when it does this
it flips to YUV Averages: Y=80.01, U=80.58, V=49.81 that's the glitch

Hardware glitch https://streamable.com/u8g3up see the glitch here
bandicam 2024-09-22 07-12-46-106.jpg
And when it plays normal the SQ YUV YUV Averages: Y=45.88, U=45.86, V=45.87 ..

I'm on gcc13 and new kos now.. On the repo i have https://github.com/ianmicheal/MPEG1-Dec ... perimental where you can view all the versions..

Also have this version with updates not using DMA transfer
Key Features:

2MB streaming buffer for smooth playback
YUV422 texture format for video rendering
Audio streaming support
FPS counting and display
Buffer management with refill tracking


Main Functions:
a. initialize_stream_buffer(): Sets up the 2MB buffer for streaming
b. cleanup_stream_buffer(): Frees allocated buffer memory
c. display_draw(): Renders the video frame using PVR
d. app_on_video(): Processes each video frame
e. sound_callback(): Handles audio streaming
f. Mpeg1Play(): Main playback function
Key Optimizations:

Direct rendering for improved performance
Minimum buffer fill level before playback starts
Optimized buffer refill process
YUV data verification for debugging

Debug Information:

FPS counter
Buffer refill count
Remaining buffer size
YUV data averages (commented out)

Implemented DEBUG_PRINT macro for correct file and line number formatting
Modified format specifiers in Mpeg1Play for uint32_t variables
https://github.com/ianmicheal/MPEG1-Dec ... al/mpeg1.c
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 126
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 224 times
Been thanked: 45 times

Re: pl_mpegDC ported running but community help needed

Post by Ian Robinson »

new faster DR rendering almost fast forward 55fps constant now to write av sync using the nano sec timer get this to be good little player hehe https://streamable.com/cdgxqo feel the need for speed OUTPUT:> DEBUG [mpeg1.c:353]: FPS: 55, Buffer refills: 0, Buffer remaining: 233449, Video time: 72.86
OUTPUT:> KallistiOS v2.1.0
OUTPUT:> Git revision: v2.0.0-1542-gcd4e5db0
OUTPUT:> Sun Sep 22 17:04:02 EDT 2024
OUTPUT:> dreamcast@DESKTOP-BH47JSG.:/opt/toolchains/dc/kos
OUTPUT:> sh-elf-gcc (GCC) 13.2.0
:)
Twada
DC Developer
DC Developer
Posts: 45
Joined: Wed Jan 20, 2016 4:55 am
Has thanked: 20 times
Been thanked: 56 times

Re: pl_mpegDC ported running but community help needed

Post by Twada »

Ian Robinson wrote: Sun Sep 22, 2024 11:56 am I have found out that DMA transfer lets it run fullspeed all the time but there is a problem on hardware doing this but not on dc emulators
Here is it running with DMA transfer on flycast https://streamable.com/wu0c4z Total constant 29fps

Hardware glitch https://streamable.com/u8g3up see the glitch here
Great improvement! I just now learned how to use plm_buffer_write(). :grin:

The glitch when using DMA is very similar to the glitch I had when I commented out pvr_wait_ready().
It's probably caused by sending data to the YUV converter in the middle of rendering, or rendering while the YUV converter is converting a frame.
If your DMA is running asynchronously, that might be the cause.

1. Synchronize with pvr_wait_ready();
2. Send one frame's worth of data to the YUV converter using SQ or DMA.
3. Render. If the data is not complete at this time, the glitch occurs.
These users thanked the author Twada for the post:
Ian Robinson
Post Reply