Friday, June 29, 2007

Au - rendering (cscope with helix code)

- start from the decoding function (PCM_CONVERTER_ULaw2Linear)
use cscope, I can find who call it, or it call whom.
Here I focus on the first part, who call it?

- it was CPCMAudioFormat::DecodeAudioData
go to definition

- CPCMAudioFormat is derected by CAudioFormat
so what is CAudioFormat?

- CAudioFormat is a fileformat reader, there is no "I" class related to it.
now go back to find who use CPCMAudioFormat? C-F5

- it was in datatype/wav/renderer/pcm/pcmrend.cpp
class CPCMAudioRenderer, function CreateFormatObject.
so take me to CPCMAudioRenderer(C-F7)

- datatype/wav/renderer/pcm/pub/pcmrend.h
take a close look on CPCMAudioRender
1 is it a plugin? Sure it is, GetPluginInfo will return the plugin information.

- take a look on IHXPlugin, it has two functions, GetPlugInfo, and InitPlugIn
so where is InitPlugin for CPCMAudioRender?

- IT is strange it does not have InitPlugin. !!!
Now take a look on IHXRenderer.

- Actually I take a look of CAudioRenderer, it is public directed from IHXPlugin and IHXRenderer
- it has a InitPlugin, that's why CPCMAudioRenderer does not contained it.

- It is easy to use definition of CAudioRenderer to find the implementation of InitPlugin.
Now goback to CAudioRenderer, to find what kind of function should be defined as a renderer.

- hxrendr.h GetRendererInfo, StartStream,EndStream OnHeader, OnPacket OnTimeSync etc.
so goto CPCMAudioRenderer or CAudioRenderer to find each implentation

- It is good CAudioRenderer contains a bunch of implementation such as
StartStream, EndStream etc.
So for PCM renderer, what should be implemented?

- As i read in CPCMAudioRenderer, GetRendererInfo it contains "const string" for the class.(information). CreateFormatObject to create CPCMAudioFormat
HXCreetaeInstance to create its self, and CanUpload2 (I think this one is not important)
so the main thing is what I read before "CreateFormatObject"!

- Read "SDK::coding a rendering plugin for audio", it is a little different
a. StartStream, get interface of AudioPlayer.
YES CAudioRenderer::StartStream contains it.
b. Create an AudioStream object, is it not in StartStream?
Let me find CreateAudioStream, it is in CAudioRenderer::InitAudioStream
c. InitAudioStream was call in CAudioRenderer::OnHeader, OnHeader first create format object, then create audio stream object.
d. As I read the SDK, OnHeader required channels, bits per sampel, samples per sec etc, where is it in the code?
Hey, That's HXAudioFormat, how it is set?
e. m_pAudioFormat (in CAudioRenderer) is created by CreateFormatObject, I
seems wandering here :-) Just take anothe close look on CreateFormatObject.
f. So I goback to CAudioFormat::GetAudioForamt, the convertion of
Here is the result:

HX_RESULT CAudioFormat::GetAudioFormat(HXAudioFormat& audioFmt)
audioFmt.uChannels = m_pAudioFmt->uChannels;
audioFmt.uBitsPerSample = m_pAudioFmt->uBitsPerSample;
audioFmt.ulSamplesPerSec = m_pAudioFmt->ulSamplesPerSec;
audioFmt.uMaxBlockSize = m_pAudioFmt->uMaxBlockSize;

return HXR_OK;

the up questions are figured out.

g. (the 4th on page 175) m_pAudioStream::Init with pHeader at audrend.cpp.
What is pHeader.

- Now let's go back, another question who call DecodeAudioData in
CPCMAudioFormat? (Before this question, I have digged about the creation

a It is at CAudioFormat::CreateAudioFrame, so who call this function?

b The answer is CAudioRenderer::DoAudio, up??

c Now it is here: CAudioRenderer::OnPacket

d Now I found I am digging about the 5th on page 175

- Now is the write PCM audio data, (the 6th on page 175)
a. the write was called in CAudioRenderer::WriteToAudioServices
b. CAudioRenderer::DoAudio first CreateAudioFrame, then WriteToAudioServices.
(Note here there could be multiple audio stream)

== postmortem

1. with SDK's guideline, I can use cscope to find how it was implemented in
helix source code. so cscope is a very power tool!

2. use cscope on this things: (function example)
- where is the definition of the function (here)
- who call this function (up)
- In this function, it call what functions (below)
In C++, it is a little different, usually I check the definition of the
class, it will display member functions in this class, so I can locate the
function definition

%%% csope %%%
Finding functions calling: WriteToAudioServices

Database directory: /home/build/src/cscope_d/
*** /home/build/src/helix/datatype/common/audrend/audrend.cpp:
DoAudio[1401] retVal = WriteToAudioServices(&audioData);

*** /home/build/src/helix/datatype/rm/audio/renderer/rarender.cpp:
DoAudio[1688] pnr = WriteToAudioServices(uLowest, &audioData, ulActualTimestamp);


move curser to DoAudio, type 'c', it will find functions that call DoAudio.

- right now, the problem is how to go back to WriteToAudioServerices, I need
to buffer list, or go back to class, then locate the source code to find
it, it is seems no covenient.

3. main issue: use gdb how to debug it? (the renderering plugin)