⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ao_sdl.c

📁 DawnLightPlayer,一个新的基于ffmpeg的全功能播放器
💻 C
字号:
/********************************************** * Dawn Light Player * *   ao_sdl.c * * Created by kf701 * 13:48:35 02/29/08 CST * * $Id: ao_sdl.c 168 2008-03-21 02:50:01Z kf701 $ **********************************************/#if ENABLE_AO_SDL#include <SDL/SDL.h>#include "avcodec.h"#include "avdecode.h"#include "avformat.h"#include "avoutput.h"#include "global.h"static volatile int need_new_packet = 0;static AVSample *cur_s = NULL;static int current_sample_pos = 0, current_sample_size = 0;static int read_new_packet(void){	if ( current_sample_size == 0 ||	        (current_sample_pos && current_sample_pos == current_sample_size) )	{		if ( cur_s )		{			av_free_sample( cur_s );			av_free( cur_s );		}		need_new_packet = 1;		while ( need_new_packet )		{			usleep(20*1000);		}		current_sample_pos = 0;		current_sample_size = cur_s->size;		return current_sample_size;	}	return current_sample_size - current_sample_pos;}/* Prototype of our callback function */static void sdl_audio_callback(void *userdata, Uint8 *stream, int len){	int slen, copylen;	while ( len > 0 )	{		slen = read_new_packet();		copylen = len > slen ? slen : len;		memcpy(stream, cur_s->data + current_sample_pos, copylen);		len -= copylen;		stream += copylen;		current_sample_pos += copylen;	}}static int ao_sdl_init(void){	/* Open the audio device */	SDL_AudioSpec desired, obtained;	/* 22050Hz - FM Radio quality */	desired.freq = dlpctxp->sample_rate;	/* 16-bit signed audio */	desired.format = AUDIO_S16SYS;	/* Set channels */	if ( dlpctxp->channels > 2 )		dlpctxp->channels = 2;	desired.channels = dlpctxp->channels;	desired.silence = 0;	/* Large audio buffer reduces risk of dropouts but increases response time */	desired.samples = 1024;	/* Our callback function */	desired.callback = sdl_audio_callback;	desired.userdata = NULL;	/* Open the audio device */	if ( SDL_OpenAudio(&desired, &obtained) < 0 )	{		av_log(NULL, AV_LOG_ERROR, "Couldn't open audio: %s\n", SDL_GetError());		return -1;	}	SDL_PauseAudio(0);	return 0;}static int ao_sdl_uninit(void){	av_log(NULL, AV_LOG_INFO, "sdl audio close\n");	SDL_CloseAudio();	return 0;}static void ao_sdl_play(AVSample *s){	while ( !need_new_packet )		usleep(10*1000);	need_new_packet = 0;	cur_s = av_dup_sample(s);}static int ao_sdl_control(int cmd, void *arg){	switch (cmd)	{	case AO_PAUSE:		SDL_PauseAudio(1);		break;	case AO_RESUME:		SDL_PauseAudio(0);		break;	default:		av_log(NULL, AV_LOG_ERROR, "AO SDL not support volume control now!\n");		break;	}	return 0;}ao_t ao_sdl ={	.id = AO_ID_SDL,	.name = "sdl",	.ao_init = ao_sdl_init,	.ao_uninit = ao_sdl_uninit,	.ao_play = ao_sdl_play,	.ao_getspace = NULL,	.ao_control = ao_sdl_control,};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -