Skip to content

Commit

Permalink
mdec/movie - simple in-ram bitstream player
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Dec 31, 2020
1 parent 29eca5d commit 837c334
Show file tree
Hide file tree
Showing 10 changed files with 116,402 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ IMAGES = common \
mdec/4bit \
mdec/8bit \
mdec/frame \
mdec/movie \
mdec/step-by-step-log \
spu/memory-transfer \
spu/ram-sandbox \
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Name | Description
4bit | ♥ Decode single 8x8 block in 4bit mode (sanitized bitstream)
8bit | ♥ Decode single 8x8 block in 8bit mode (sanitized bitstream)
frame | Framework for testing MDEC decoder, default values uses DMA for all transfers, but it can be reconfigured for PIO as well (requires manual recompilation). Two executables for 15 and 24bit modes (using DMA for MDECin, MDECout and GPU)
movie | Simple MDEC in-ram bitstream player (currently 200 256x240 frames at @ 10FPS)
step-by-step-log | Manually feeds the MDEC data and monitors the MDEC status register at every step.

### SPU
Expand Down Expand Up @@ -93,7 +94,8 @@ diffvram | Diff two images and write diff png if image contents

## Examples

<img src="mdec/frame/vram-15bit.png" height="480">
<img src="mdec/movie/vram-15bit.png" height="256">
<img src="mdec/frame/vram-15bit.png" height="256">
<img src="gpu/benchmark/screenshot.png" height="480">
<img src="gpu/lines/vram.png" height="256">
<img src="gpu/transparency/vram.png" height="256">
Expand Down
7 changes: 7 additions & 0 deletions mdec/movie/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all:
@$(MAKE) --no-print-directory -f makefile.15bit clean all
@$(MAKE) --no-print-directory -f makefile.24bit clean all

clean:
@$(MAKE) --no-print-directory -f makefile.15bit clean
@$(MAKE) --no-print-directory -f makefile.24bit clean
116,293 changes: 116,293 additions & 0 deletions mdec/movie/bad_apple.h

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions mdec/movie/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <common.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <io.h>
#include <dma.hpp>
#include <mdec.h>
#include <gpu.h>

#include "bad_apple.h"

#define SCR_W 256
#define SCR_H 240

uint32_t* buffer = nullptr;
void decodeAndDisplayFrame(uint8_t* frame, size_t frameLen, uint16_t frameWidth, uint16_t frameHeight) {
const int STRIPE_WIDTH = 16;
const int STRIPE_HEIGHT = frameHeight;

#ifdef USE_24BIT
const ColorDepth depth = ColorDepth::bit_24;
const int copyWidth = STRIPE_WIDTH * 3/2;
#define BYTES_PER_PIXEL 3
#else
const ColorDepth depth = ColorDepth::bit_15;
const int copyWidth = STRIPE_WIDTH;
#define BYTES_PER_PIXEL 2
#endif

mdec_decodeDma((uint16_t*)frame, frameLen, depth, false, false);

if (buffer == nullptr) {
buffer = (uint32_t*)malloc(STRIPE_WIDTH * STRIPE_HEIGHT * BYTES_PER_PIXEL / 4 * sizeof(uint32_t));
}
for (int c = 0; c < frameWidth / STRIPE_WIDTH; c++) {
mdec_readDecodedDma(buffer, STRIPE_WIDTH * STRIPE_HEIGHT * BYTES_PER_PIXEL);
vramWriteDMA(c * copyWidth, 0, copyWidth, STRIPE_HEIGHT, (uint16_t*)buffer);
}
}

int main() {
SetVideoMode(MODE_NTSC);
initVideo(SCR_W, SCR_H);
printf("\nmdec/frame\n");
#ifdef USE_24BIT
extern DISPENV disp;
disp.isrgb24 = true;
PutDispEnv(&disp);
printf("Using framebuffer in 24bit mode\n");
#endif

clearScreen();

mdec_reset();
mdec_quantTable(quant, true);
mdec_idctTable((int16_t*)idct);
mdec_enableDma();

for (int i = 0; i<60*2; i++) {
VSync(0);
}

for (int i = 0; i<FRAME_COUNT; i++) {
frame_t frame = frames[i];
decodeAndDisplayFrame(&movieBitstream[frame.offset], frame.size, SCR_W, SCR_H);
VSync(0);
}

free(buffer);
printf("Done\n");

// Stop all pending DMA transfers
write32(DMA::CH_CONTROL_ADDR + 0x10 * (int)DMA::Channel::MDECin, 0);
write32(DMA::CH_CONTROL_ADDR + 0x10 * (int)DMA::Channel::MDECout, 0);
write32(DMA::CH_CONTROL_ADDR + 0x10 * (int)DMA::Channel::GPU, 0);
DMA::masterEnable(DMA::Channel::MDECout, false);
DMA::masterEnable(DMA::Channel::MDECin, false);
DMA::masterEnable(DMA::Channel::GPU, false);

mdec_reset();
for (;;) {
VSync(0);
}
return 0;
}
3 changes: 3 additions & 0 deletions mdec/movie/makefile.15bit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TARGET = movie-15bit.elf

include ../../common-test.mk
5 changes: 5 additions & 0 deletions mdec/movie/makefile.24bit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TARGET = movie-24bit.elf

include ../../common-test.mk

CFLAGS += -DUSE_24BIT
5 changes: 5 additions & 0 deletions mdec/movie/movieToMdec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e
export PATH=$PATH:/Users/jakub/dev/priv/mdec-tools/cmake-build-relwithdebinfo
ffmpeg -hide_banner -loglevel panic -i bad_apple.mkv -ss 2 -t 00:00:25 -vf "fps=10,scale=256:240" -pix_fmt gray %04d.png
mdec-tools -q=40 --color --movie *.png bad_apple.h
rm *.png
Binary file added mdec/movie/vram-15bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mdec/movie/vram-24bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 837c334

Please sign in to comment.