Skip to content

Commit

Permalink
Fix theora playback on certian videos.
Browse files Browse the repository at this point in the history
This fixes a bug that would cause Y2R to render certian videos incorrectly.
  • Loading branch information
oreo639 committed Nov 20, 2020
1 parent f91f843 commit 02824e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ libsbuild
tmplibs
build
out
debug.txt
*.3dsx
*.cia
*.smdh
Expand Down
21 changes: 10 additions & 11 deletions source/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "frame.h"

Y2RU_ConversionParams convSettings;

static inline u32 Pow2(u32 x)
{
if (x <= 2)
Expand Down Expand Up @@ -102,10 +100,10 @@ void frameWrite(C2D_Image* frame, THEORA_videoinfo* info, th_ycbcr_buffer ybr) {
return;

bool is_busy = true;
while (is_busy) {
Y2RU_StopConversion();

Y2RU_IsBusyConversion(&is_busy);
Y2RU_StopConversion();
while (is_busy) {
Y2RU_IsBusyConversion(&is_busy);
}

switch(info->fmt)
Expand All @@ -128,12 +126,13 @@ void frameWrite(C2D_Image* frame, THEORA_videoinfo* info, th_ycbcr_buffer ybr) {
Y2RU_SetStandardCoefficient(COEFFICIENT_ITU_R_BT_601_SCALING);
Y2RU_SetAlpha(0xFF);

//svcWaitSynchronization(y2rEvent, 1000 * 1000);
{
Y2RU_SetSendingY(ybr[0].data, ybr[0].stride * ybr[0].height, ybr[0].width, ybr[0].stride - ybr[0].width);
Y2RU_SetSendingU(ybr[1].data, ybr[1].stride * ybr[1].height, ybr[1].width, ybr[1].stride - ybr[1].width);
Y2RU_SetSendingV(ybr[2].data, ybr[2].stride * ybr[2].height, ybr[2].width, ybr[2].stride - ybr[2].width);
}
//Y2RU_SetSendingY(ybr[0].data, ybr[0].stride * ybr[0].height, ybr[0].width, ybr[0].stride - ybr[0].width);
//Y2RU_SetSendingU(ybr[1].data, ybr[1].stride * ybr[1].height, ybr[1].width, ybr[1].stride - ybr[1].width);
//Y2RU_SetSendingV(ybr[2].data, ybr[2].stride * ybr[2].height, ybr[2].width, ybr[2].stride - ybr[2].width);

Y2RU_SetSendingY(ybr[0].data, info->width * info->height, info->width, ybr[0].stride - info->width);
Y2RU_SetSendingU(ybr[1].data, (info->width/2) * (info->height/2), info->width/2, ybr[1].stride - (info->width >> 1));
Y2RU_SetSendingV(ybr[2].data, (info->width/2) * (info->height/2), info->width/2, ybr[2].stride - (info->width >> 1));

Y2RU_SetReceiving(frame->tex->data, info->width * info->height * fmtGetBPP(frame->tex->fmt), info->width * 8 * fmtGetBPP(frame->tex->fmt), (Pow2(info->width) - info->width) * 8 * fmtGetBPP(frame->tex->fmt));
Y2RU_StartConversion();
Expand Down
6 changes: 4 additions & 2 deletions source/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@ int THEORA_CallbackCreate(THEORA_Context* ctx, void* datasource, THEORA_callback
if (ctx->tinfo.fps_denominator)
fps = ((double) ctx->tinfo.fps_numerator) / ((double) ctx->tinfo.fps_denominator);

ctx->videoinfo.width = ctx->tinfo.pic_width;
ctx->videoinfo.height = ctx->tinfo.pic_height;
ctx->videoinfo.width = ((ctx->tinfo.pic_x + ctx->tinfo.frame_width + 1) & ~1) - (ctx->tinfo.pic_x & ~1); // ctx->tinfo.pic_width;
ctx->videoinfo.height = ((ctx->tinfo.pic_y + ctx->tinfo.frame_height + 1) & ~1) - (ctx->tinfo.pic_y & ~1); // ctx->tinfo.pic_height;
ctx->videoinfo.x_offs = ctx->tinfo.pic_x;
ctx->videoinfo.y_offs = ctx->tinfo.pic_y;
ctx->videoinfo.fps = fps;
ctx->videoinfo.fmt = ctx->tinfo.pixel_fmt;
ctx->videoinfo.colorspace = ctx->tinfo.colorspace;
Expand Down
2 changes: 2 additions & 0 deletions source/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct tf_callbacks {
typedef struct {
int width;
int height;
int x_offs;
int y_offs;
double fps;
th_pixel_fmt fmt;
th_colorspace colorspace;
Expand Down

0 comments on commit 02824e4

Please sign in to comment.