資源簡介
博文:http://blog.csdn.net/i_scream_/article/details/52787222
中的代碼。
測試平臺:ubuntu16.04 64bit + ffmpeg3 + SDL2.

代碼片段和文件信息
/*=========================================================================\
*?Copyright(C)2016?Chudai.
*
*?File?name????:?audio.c
*?Version??????:?v1.0.0
*?Author???????:?初代
*?Date?????????:?2016/10/06
*?Description??:
*?Function?list:?1.
*????????????????2.
*????????????????3.
*?History??????:
\*=========================================================================*/
/*-----------------------------------------------------------*
?*?頭文件????????????????????????????????????????????????????*
?*-----------------------------------------------------------*/
#define?__STDC_CONSTANT_MACROS??????//ffmpeg要求
#include?“player.h“
#include?“audio.h“
/*======================================================================\
*?Author?????(作者):?i.sshe
*?Date???????(日期):?2016/10/06
*?Others?????(其他):?準備audio
\*=======================================================================*/
int?prepare_audio(PlayerState?*ps)
{
ps->paudio_stream?=?ps->pformat_ctx->streams[ps->audio_stream_index];
ps->paudio_codec_ctx?=? ps->paudio_stream->codec;
ps->paudio_codec?=?avcodec_find_decoder(ps->paudio_codec_ctx->codec_id);
if?(ps->paudio_codec?==?NULL)
????{
?????????fprintf(ERR_STREAM?“Couldn‘t?find?audio?decoder!!!!!!!\n“);
?????????return?-1;
????}
//初始化AVCondecContext,以及進行一些處理工作。
avcodec_open2(ps->paudio_codec_ctx?ps->paudio_codec?NULL);
????return?0;
}
/*======================================================================\
*?Author?????(作者):?i.sshe
*?Date???????(日期):?2016/10/06
*?Others?????(其他):?播放聲音
\*=======================================================================*/
int?play_audio(PlayerState?*ps)
{
????SDL_AudioSpec??????wanted_spec;
//????SDL_AudioSpec??????spec;
????wanted_spec.freq??????=?ps->paudio_codec_ctx->sample_rate;
????wanted_spec.format????=?AUDIO_S16SYS;
????wanted_spec.channels??=?ps->paudio_codec_ctx->channels;
????wanted_spec.silence???=?0;
????wanted_spec.samples???=?1024;?????//
????wanted_spec.callback??=?audio_callback;
????wanted_spec.userdata??=?ps;?//?ps->paudio_codec_ctx;
????//打開音頻設備
????//運行callback
????if?(SDL_OpenAudio(&wanted_spec?NULL)?0)
????{
????????fprintf(ERR_STREAM?“Couldn‘t?open?audio?device\n“);
????????return?-1;
????}
????SDL_PauseAudio(0);
????return?0;
}
/*======================================================================\
*?Author?????(作者):?i.sshe
*?Date???????(日期):?2016/10/06
*?Others?????(其他):?音頻回調函數,打開設備的時候會開線程調用
\*=======================================================================*/
void?audio_callback(void?*userdata?uint8_t?*stream?int?len)
{
????PlayerState?*ps?=?(PlayerState?*)userdata;
????int? send_data_size?=?0;
????int? audio_size?=?0;
int? flag?=?0;
SDL_Event? event;
????SDL_memset(stream?0?len);
????
?????//操作
?switch(ps->player_state)
?????{
?????????case?-1:???//退出
????????? ?printf(“退出音頻線程\n“);
?????????????break;
?????????case?0:
?????????????break;
?????????case?1:????//暫停
????????? ?printf(“audio?收到暫停\n“);
?????????????break;
?????????default:
?????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????586??2016-10-09?21:45??Makefile
?????文件????????1070??2016-10-10?21:56??Readme.md
?????文件????????8432??2016-10-11?00:15??audio.c
?????文件????????4925??2016-10-10?22:19??audio.h
?????文件?????1507328??2015-02-16?13:41??naxienian.mp4
?????文件????????4516??2016-10-11?13:35??packet_queue.c
?????文件????????4475??2016-10-11?13:35??packet_queue.h
?????文件????????6471??2016-10-11?00:12??pla
?????文件????????8168??2016-10-11?00:28??pla
?????文件????????2188??2016-10-11?13:34??seek_about.c
?????文件????????2326??2016-10-11?13:34??seek_about.h
?????文件???????10324??2016-10-11?00:14??video.c
?????文件????????5525??2016-10-10?22:19??video.h
?????文件????????2627??2016-10-05?10:24??wrap_ba
?????文件????????3003??2016-10-03?15:15??wrap_ba
- 上一篇:Angular6.X 中文官方文檔
- 下一篇:仿QQ聊天軟件客戶端_服務端可架設
評論
共有 條評論