les虫播放pcm时出现意外声音

时间:2019-05-15 03:34:31

标签: android opensl

我使用ffmpeg解码mp4并获取AVFrame。然后我根据pt将AVFrame发送到OpenSLES线程。但是播放一些视频时出现了一些意外的声音。我的代码如下。谢谢!

enter image description here

void _playCallback(SLAndroidSimpleBufferQueueItf bq, void *context) {
    auto player = (opensles_player *) context;
    auto swrContext = ((opensles_player *) context)->swrContext;
    auto queue = player->audioQueue;
    auto frame = queue->pull();
    if (frame != nullptr && swrContext != nullptr) {
        int size = av_samples_get_buffer_size(nullptr, 
        av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO),
                                          frame->nb_samples,
                                          AV_SAMPLE_FMT_S16, 1);
        if (size > 0) {
            uint8_t *out_buffer = (uint8_t *) av_malloc(44100 * 2);
            swr_convert(swrContext, &out_buffer, 44100, (const uint8_t 
            **) frame->data,
                    frame->nb_samples);
            (*bq)->Enqueue(bq, out_buffer, size);
        }
    }
    av_frame_free(&frame);
}

0 个答案:

没有答案