多線程視頻播放可以采用生產(chǎn)者模式來設(shè)計
一共三個線程,一個隊列
- 數(shù)據(jù)讀取線程(生產(chǎn)者)
- 音頻播放線程(消費者)
- 視頻播放線程(消費者)
//生產(chǎn)者線程
pthread_create(&(player->thread_read_from_stream),NULL,player_read_from_stream,(void*)player);
//消費者線程
DecoderData data1 = {player,video_stream_index}, *decoder_data1 = &data1;
pthread_create(&(player->decode_threads[video_stream_index]),NULL,decode_data,(void*)decoder_data1);
DecoderData data2 = {player,audio_stream_index}, *decoder_data2 = &data2;
pthread_create(&(player->decode_threads[audio_stream_index]),NULL,decode_data,(void*)decoder_data2);```