[Android] [PATCH 4/4] android: add native AudioTrack aout module
Rafaël Carré
funman at videolan.org
Fri Mar 9 04:53:00 CET 2012
Le 2012-03-08 22:27, 某因幡 a écrit :
> Inline.
>
> 2012/3/8 Jean-Baptiste Kempf <jb at videolan.org>:
>>> +static AudioSystem_getOutputFrameCount as_getOutputFrameCount = NULL;
>>> +static AudioSystem_getOutputLatency as_getOutputLatency = NULL;
>>> +static AudioSystem_getOutputSamplingRate as_getOutputSamplingRate = NULL;
>>> +static AudioTrack_getMinFrameCount at_getMinFrameCount = NULL;
>>> +static AudioTrack_ctor at_ctor = NULL;
>>> +static AudioTrack_ctor_legacy at_ctor_legacy = NULL;
>>> +static AudioTrack_dtor at_dtor = NULL;
>>> +static AudioTrack_initCheck at_initCheck = NULL;
>>> +static AudioTrack_start at_start = NULL;
>>> +static AudioTrack_stop at_stop = NULL;
>>> +static AudioTrack_write at_write = NULL;
>>> +static AudioTrack_flush at_flush = NULL;
>>
>> Why static ?
>>
>
> What's wrong?
It's always weird to see process-wide variables when VLC is heavily
multi-threaded, though I don't know if there can be several audio output
objects in one process.
androidsurface video output stores function pointers in the context for
example.
>>> + audio_output_t *p_aout = (audio_output_t*)(p_this);
>>> + int status;
>>> + int afSampleRate, afFrameCount, afLatency, minBufCount, minFrameCount;
>>> + int type, channel, rate, format, size;
>>> +
>>
>>> + // AudioSystem::MUSIC = 3
>>> + type = 3;
>>
>> Please use a define for that.
>>
>>> + // 4000 <= frequency <= 48000
>>> + if (p_aout->format.i_rate < 4000)
>>> + p_aout->format.i_rate = 4000;
>>> + if (p_aout->format.i_rate > 48000)
>>> + p_aout->format.i_rate = 48000;
>>> + rate = p_aout->format.i_rate;
>>> + p_sys->rate = rate;
>>
>> It cannot go above 48000?
>>
>
> I should have seen such lines in Android source tree and did some test
> about a year ago...
> Now I see it seems to depends on hardware.
>
>>> + // AudioSystem::PCM_16_BIT = 1
>>> + // AudioSystem::PCM_8_BIT = 2
>>> + format = (p_aout->format.i_format == VLC_CODEC_S16L) ? 1 : 2;
>>
>> As above.
>>
>>> + p_sys->size = p_aout->format.i_bytes_per_frame;
>>> + // sizeof(AudioTrack) == 0x58 (not sure) on 2.2.1, this should be enough
>>> + p_sys->AudioTrack = malloc(256);
>>
>> What does the sourcecode of Cyanogen say?
>>
>
> Not sure, but actually it works. I had a X10i with firmware Android
> 1.6/2.1/2.3, unofficial 2.2 and CM 7.2. :p
Yeah it will probably work for a long time if not forever.
To be extra sure we could allocate a bit more and poison the last area
with e.g. 0x42424242 and regularly check if this memory changed.
Or require the C++ definition of this class and check for its size (not
sure if it is doable at build time).
More information about the Android
mailing list