Monday, January 4, 2010

Ever had problems with Cxbx's video playback?





Okay, this is for everyone who has had problems viewing videos with Cxbx lately. I don't know how many of you are having problems with Cxbx's video playback lately, but I know I have... for a long time! Ever since I updated my video card drivers for my laptop (I have an NVIDIA GeForce 8400 GS Mobile 128MB) back in August, I noticed that Cxbx's video playback was broken. Even though my GPU supports DirectDraw's hardware accelerated overlay surfaces (or at least it claims to), it still never worked anymore! This was driving me crazy because it meant less screenshots to show you guys (it's great to have proof).

"So, what did you do to fix it?" Well, I made quite a few changes to get this working again (and a few extra changes to get it working right without problems for some games). The first thing I did was force Cxbx to update the overlay surface in software using a YUV -> RGB conversion (which Cxbx already did support). After initializing DirectDraw, Cxbx will check for hardware YUV overlay support. If it is detected, it will use the hardware mode automatically. If not, then it does the conversion in software and writes the pixels to the backbuffer. To disable it, I just commented out this in EmuD3D8.cpp: g_bSupportsYUY2 = true; While the hardware accelerated method was a good idea, it did have a few drawbacks which are just now beginning to surface. To further illustrate, I'll show the pros and cons of each:

1. Hardware YUV

Good:
- Fast
- Automatically updates itself (no need to call D3DDevice::Present)

Bad:
- Usually too fast! Can cause "robotic" audio
- Can cause crashes (Unreal Championship)
- Can't take screenshots easily

2. Software YUV

Good:
- More accurate speed wise (at least for me)
- Can take screenshots with print screen button
- More compatible

Bad:
- Can be too slow depending on your hardware
- Does not update automatically (requires hack, but easily fixed)

A good idea would be to give the user the option to use hardware or software YUV overlay updates for maximum compatibility to the user's liking.

More on the "hacks" used to get this working properly. This was really easy to do. One thing I noticed was that when trying to play videos with Dead to Rights and PacMan Worlds 2 was that before playing the video, all the parameters would be NULL. So if there's no surface passed in for the first parameter, don't update the overlay or else you'll crash and burn. The second thing is that I noticed that when I disabled the hardware overlay flag, some videos would play and others still wouldn't show up. That's because the Xbox expects each frame to show up without the need to call D3DDevice::Present. So for every time that the overlay surface is updated and Present or Swap is not called, call Present after the overlay update. And as you can see above, the results were great!

One more benefit is that since the fact that most videos play at about 30 FPS, they will generally play at that frame rate, resulting in better sounding audio (still a bit choppy sometimes, but less robotic). So there you have it. I'll see to it that there's an option to use hardware and software overlays at your discretion so you won't go through the same problems I did.

Shogun

6 comments:

  1. is awesone all this, wellis interesting allyour progress.i think that cxbx can manages more xbox videos with a feedback of dreamcast emu sources heheh, because there are somes formats similars, and special the sound, otherwise..for a reason iunderstand the famous eip errorscalled errors registers windows..hehe..blues i add some directx9 aplications on emu3d38types.h and works ..is posible make a mixed dirext8 and 9??becauseif i got that works..maybe is posible..and forthis way is more easy that cxbx have directx9 implements because directx9 uses old styles d3d8 too...greetings happy new year ...all the girls in my home love you for your progress ..
    thanks friend for work in emulation ..

    comments: friend i gotageforce 8400gs since 2006 something so..and is not so good in my case arrives with defects..and reboot my system with somes games,,i had with to quite and play the games with the graphics integrater of the motherboard..idon´tknow what hapens with nvida they are a lot of cards with damages

    ReplyDelete
  2. The videos are not a problem at all. Also, Direct3D 8 and 9 cannot be used together. I'm going to start the OpenGL port soon so no need to worry!

    I even looked at Xeon's ini like you suggested before and it did help me add new stuff. I found many missing functions that Cxbx didn't have for XDK 3911!

    I have an 8400GS in my laptop and it works fine for me. But I hope you get a better card if it's not working for you.

    ReplyDelete
  3. nice job with xeon implements..well is very sad that xeon author never gived the sources...well opengl is a world very extense you can do all that you want if you know it..there are nvidia opengl10 sdk. opengl for nvidia t2...and opengl standar libaries like glut glew..and more..but is rare because the tutorials explains how to draw someting not at how to use primitive tipes or somes d3d effects types like a format...for this reason is more hard to understan than directx...but well is awesone is you do a opengl extension..i can´t wait for to see your results when you´ll donde...and believe me i thing that will be awesones..thanks for your wish..
    i discover the problem of reboot the system when play a game..is not the watts, is not the ram ddr2 or something, is only the graphics cards that is defects faulty Nvida is making a very bad play with those things

    ReplyDelete
  4. wow wow uff blues i forgot to tell you somethinG: well like somes emus use a mode called: faked video or skip video ..blues i think that is fine if you can do this hack for cxbx ..you know all xbx video formats..but maybe somes are not encoders..for windows and the conversion and reproduccer for the codecs...ther are a case of one .sfd coneverter to mpeg or wmv video format ..well the .sfd of dreamcast games works but xbx videos can´t be encoder and only works the sound is like a simple mp3 or midi..well only in case that the video was a problem this cam be a nice solution..only you have to say skip to some .sfd video or something like that...
    i know that you say that the video is perfect but try this implement please ..hehe

    ReplyDelete
  5. OpenGL is actually easier to learn than Direct3D. It is also easier to use. GLUT will not be useful, but GLEW will. I need to take a break from Cxbx for a few days because I've worked too hard on it lately.

    Please, there is no need to worry about skipping videos. It is not a problem like it is for PCSX2. It's better to get them working than to skip them I say.

    ReplyDelete
  6. Nice work for now ;).

    ReplyDelete