Re: Really messy audio/video-problem
From: Paul G. Tobey [eMVP] (ptobey_no_spam_at_instrument_no_spam.com)
Date: 04/16/04
- Next message: Paul G. Tobey [eMVP]: "Re: Target Platform problem"
- Previous message: PeterH: "Target Platform problem"
- In reply to: Daniel: "Really messy audio/video-problem"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 16 Apr 2004 08:39:58 -0700
Sounds like the processor or maybe the audio hardware is being slowed down
to save power. You might check the power settings and see if turning off a
few things helps.
Paul T.
"Daniel" <shiningstars99@nospam.yahoo.com> wrote in message
news:84F559F3-0246-4802-AD72-5F82075614AE@microsoft.com...
> I'm writing an app for Smartphone 2003 (using eVC 4) that views a music
video by displaying each frame using bitblt. A strange behaviour occurs.
>
> It works fine for a while when I've pressed play and then, it goes down to
a third of the normal speed. When this happen, if I touch a key (the menuba,
or any button at all) - then it flows again for a while, goes down in speed
etc.
>
> I should mention that I've created a new thread as a sort of a player
engine for both the sound and the video - this to make the sound flow
smoothly and to be able to synch the video and sound (based on how the media
files I use are encoded). It's a while-loop that keeps sending data to the
sound-device (and to bitblt) as long as the user haven't pressed stop or
pause. It looks like this:
>
> /////////////////////////////////////
>
> DWORD WINAPI CWaveEngine::ThreadLoop(LPVOID param) {
> CWaveEngine *parent = (CWaveEngine *)param;
> while(parent->m_audioState != StateStopped) {
> if (parent->m_audioState == StatePaused) {
> parent->PlaySilence(); }
> else {
> parent->BufferWritten();
> }
> }
> ExitThread(0);
> return 0;
> }
>
> /////////////////////////////////////
>
> The working bee, BufferWritten, looks approx. like this:
>
> BufferWritten()
>
> //Audio
> GetAudioFrame(audioBuffer);
> PlayWave(audioBuffer)
>
> //Video
> if (contenttype == VIDEO) {
> GetVideoFrame(videoBuffer);
> SetBackgroundImage(videoBuffer); (bitblts into a memory DC)
> }
>
> UpdateGraphichs(); (bitblts the memdc into the DC)
> }
>
> /////////////////////////////////////
>
> If I just play soundfiles, everything's work nice. This made me think that
the bitblt was too slow, so I tried using GAPI (and this help library:
http://www.smartphonedn.com/articles/gapibuffer.html), but that did no
difference at all!
>
> Then I started to clock parts of the code and something that's strange is
that when the video is dragging - suddenly, the time for audioplaying
(sending to waveoutwrite) rises from about 1 or 2% of total time to 70%!
I've also isolated the dragging to waveoutwrite which starts to take awfully
lot of time.
>
> Now, I don't know if it's the audioplaying that _causes_ the video to drag
or if it's the video drag that causes the audio to take up 70% of the time.
>
> This is how I play the sound (I use a CALLBACK_EVENT and pcmout contains
audio chunks, so that I can call wavoutwrite a couple of times before I
unprepare the first header):
>
> /////////////////////////////////////////
> void CPlayEngine::PlayWave(int bytesDecoded) {
>
> if (m_prepared[m_bufCount] == true) { //If m_prepared, then
> while (!(m_whdr[m_bufCount].dwFlags & WHDR_DONE)) { //wait for device
> WaitForSingleObject(m_hDoneEvent, INFINITE);
> }
> waveOutUnprepareHeader(m_hwo, &m_whdr[m_bufCount], sizeof(WAVEHDR)); //and
unprepare.
> m_prepared[m_bufCount] = false;
> }
>
> memcpy(m_whdr[m_bufCount].lpData,(char *)pcmOut[m_bufCount],bytesDecoded);
//Declare the waveheader
> m_whdr[m_bufCount].dwBufferLength = bytesDecoded;
> m_prepared[m_bufCount] = true;
> waveOutPrepareHeader(m_hwo, &m_whdr[m_bufCount], sizeof(WAVEHDR));
//Prepare the header
>
> ResetEvent(m_hDoneEvent);
>
> waveOutWrite(m_hwo, &m_whdr[m_bufCount], sizeof(WAVEHDR));
>
> m_bufCount++;
> if (m_bufCount==MAXBUF)
> m_bufCount=0;
> }
> //////////////////////////////////////////////
>
> The fact that a key event (or any event thas gets the phone to wake up)
gets the video to play at normal speed, makes one think that some kind of a
message queue or a buffer or anything are full at gets cleared when the
event come. Also, the interval for how long the video plays before going
down in speed isn't constant - so I guess it's not anything with the system
not being idle. I've tried calling SystemIdleReset repeatedly and even
posting a key event with PostMessage - this made it better for a while
actually, until I pressed a key and then the same phenomenon showed up
again - and when the program was restarted everything was in the same messy
state again.
>
> I should add that everything works fine on the emulator - and the problem
only occurs on device (which is a Qtek 8080).
>
> As you understand, this is getting really frustrating, so any help at all
is really appreciated!
>
> Thanks in advance,
> Daniel
- Next message: Paul G. Tobey [eMVP]: "Re: Target Platform problem"
- Previous message: PeterH: "Target Platform problem"
- In reply to: Daniel: "Really messy audio/video-problem"
- Messages sorted by: [ date ] [ thread ]