|
楼主 |
发表于 2011-3-2 10:16:48
|
显示全部楼层
本帖最后由 neillyang 于 2011-3-2 10:23 编辑
回复 2# array
osg::ImageStream::AudioStreams& audioStreams = videostream->getAudioStreams();
if (!audioStreams.empty() && (audioStream == 0))
{
audioStream = audioStreams[0].get();
audioStream->setAudioSink(new SDLAudioSink(audioStream));
}
问题就在这块,注释掉这块就没问题,但是也没声音了不是
上述相关联的部分如下:
//SDLAudioSink
static void soundReadCallback(void * user_data, uint8_t * data, int datalen)
{
SDLAudioSink * sink = reinterpret_cast<SDLAudioSink*>(user_data);
osg::ref_ptr<osg::AudioStream> as = sink->_audioStream.get();
if (as.valid())
as->consumeAudioBuffer(data, datalen);
}
SDLAudioSink::~SDLAudioSink()
{
stop();
}
void SDLAudioSink::play()
{
if (_started)
{
if (_paused)
{
SDL_PauseAudio(0);
_paused = false;
}
return;
}
_started = true;
_paused = false;
SDL_AudioSpec specs = { 0 };
SDL_AudioSpec wanted_specs = { 0 };
wanted_specs.freq = _audioStream->audioFrequency();
wanted_specs.format = AUDIO_S16SYS;
wanted_specs.channels = _audioStream->audioNbChannels();
wanted_specs.silence = 0;
wanted_specs.samples = 1024;
wanted_specs.callback = soundReadCallback;
wanted_specs.userdata = this;
if (SDL_OpenAudio(&wanted_specs, &specs) < 0)
return;
SDL_PauseAudio(0);
}
void SDLAudioSink::pause()
{
if (_started)
{
SDL_PauseAudio(1);
_paused = true;
}
}
void SDLAudioSink::stop()
{
if (_started)
{
if (!_paused) SDL_PauseAudio(1);
SDL_CloseAudio();
}
} |
|