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

📄 avin_ha1.c

📁 DawnLightPlayer,一个新的基于ffmpeg的全功能播放器
💻 C
字号:
/********************************************** * Dawn Light Player * *   avin_udp.c * * Created by kf701.ye at gmail.com * 17:48:08 02/26/08 CST * * $Id: avin_ha1.c 168 2008-03-21 02:50:01Z kf701 $ **********************************************/#if ENABLE_AVIN_HA1#if !defined(__MINGW32__)#include <netdb.h>#endif#include "avdecode.h"#include "avformat.h"#include "avinput.h"#include "global.h"static void avctx_init_aac(AVCodecContext *avctxp){	avctxp->skip_bottom = 0;	strcpy(avctxp->codec_name, "libfaad");	avctxp->codec_type = CODEC_TYPE_AUDIO;	avctxp->codec_id = CODEC_ID_AAC;	avctxp->bit_rate = 39*1024;	avctxp->sample_fmt = 1;	avctxp->sample_rate = 48000;	avctxp->channels = 2;	/* set dlpctx */	dlpctxp->bit_rate = avctxp->bit_rate;	dlpctxp->sample_fmt = avctxp->sample_fmt;	dlpctxp->sample_rate = avctxp->sample_rate;	dlpctxp->channels = avctxp->channels;}static void avctx_init_h264(AVCodecContext *avctxp){	avctxp->skip_bottom = 0;	strcpy(avctxp->codec_name, "h264");	avctxp->codec_type = CODEC_TYPE_VIDEO;	avctxp->codec_id = CODEC_ID_H264;	avctxp->bits_per_sample = 32;	avctxp->width = 320;	avctxp->height = 240;	/* set dlpctx */	dlpctxp->width = avctxp->width;	dlpctxp->height = avctxp->height;	dlpctxp->fps = 25;}int avin_ha1_init(void){	dlp_vctxp = &dlp_vctx;	dlp_actxp = &dlp_actx;	avctx_init_h264(dlp_vctxp);	avctx_init_aac(dlp_actxp);#if defined(__MINGW32__)	{		WSADATA wsaData;		WSAStartup(MAKEWORD(1,1), &wsaData);	}#endif	av_log(NULL, AV_LOG_INFO, "INIT input from net UDP\n");	return 0;}int avin_ha1_uninit(void){#if defined(__MINGW32__)	WSACleanup();#endif	av_log(NULL, AV_LOG_INFO, "UNINIT input from net UDP\n");	return 0;}static int open_udp( uint16_t port){	int fd;	struct sockaddr_in addr;	fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);	if ( fd == -1 )	{		av_log(NULL, AV_LOG_ERROR,"%s,%d:socket error\n",__func__,__LINE__);		return -1;	}	memset((char*) &(addr),0, sizeof((addr)));	addr.sin_family = AF_INET;	addr.sin_addr.s_addr = htonl(INADDR_ANY);	addr.sin_port = htons(port);	if ( bind( fd,(struct sockaddr*)&addr, sizeof(addr)) != 0 )	{		av_log(NULL,AV_LOG_ERROR,"%s,%d:bind error\n",__func__,__LINE__);		return -1;	}	return fd;}typedef void(*udp_data_func)(uint8_t*, int);#define VIDEO_UDP_PORT  5555#define AUDIO_UDP_PORT  5556#define AVIN_MAX_PKT_SIZE 32*1024void avin_ha1_main(void){	int asockfd, vsockfd;	fd_set readset;	int max_fd, select_ret, nread, vqlen, aqlen;	uint8_t *buf;	AVPacket *pkt;	vsockfd = open_udp( VIDEO_UDP_PORT );	if ( -1 == vsockfd )	{		av_log(NULL, AV_LOG_ERROR, "%s,%d: open sock err,%m\n", __FILE__, __LINE__);		return ;	}	asockfd = open_udp( AUDIO_UDP_PORT );	if ( -1 == asockfd )	{		av_log(NULL, AV_LOG_ERROR, "%s,%d: open sock err,%m\n", __FILE__, __LINE__);		return ;	}	buf = malloc(AVIN_MAX_PKT_SIZE);	while ( 1 )	{		vqlen = dlp_queue_length(video_packet_queue);		aqlen = dlp_queue_length(audio_packet_queue);		if ( aqlen > MAX_VIDEO_PACKET_QUEUE_LEN ||		        vqlen > MAX_AUDIO_PACKET_QUEUE_LEN )		{			av_log(NULL, AV_LOG_DEBUG, "video packet queue len: %d\n", vqlen);			av_log(NULL, AV_LOG_DEBUG, "audio packet queue len: %d\n", aqlen);			usleep(50*1000);			continue;		}		FD_ZERO(&readset);		FD_SET( asockfd , &readset );		FD_SET( vsockfd , &readset );		max_fd = MAX(asockfd, vsockfd) + 1;		select_ret = select(max_fd+1, &readset, NULL, NULL, NULL);		if ( select_ret < 0 )		{			av_log(NULL, AV_LOG_ERROR, "%s,%d: select err,%m\n", __FILE__, __LINE__);			continue;		}		if ( FD_ISSET (asockfd, &readset) )		{			nread = recvfrom(asockfd, (void*)buf, AVIN_MAX_PKT_SIZE, 0, NULL, NULL);			if ( nread <= 0 )			{				av_log(NULL, AV_LOG_ERROR, "%s: recvfrom err\n", __func__);				continue;			}			pkt = av_mallocz(sizeof(AVPacket));			av_new_packet(pkt, nread);			memcpy(pkt->data, buf, nread);			dlp_queue_push_tail(audio_packet_queue, pkt);		}		if ( FD_ISSET (vsockfd, &readset) )		{			nread = recvfrom(vsockfd, (void*)buf, AVIN_MAX_PKT_SIZE, 0, NULL, NULL);			if ( nread <= 0 )			{				av_log(NULL, AV_LOG_ERROR, "%s: recvfrom err\n", __func__);				continue;			}			pkt = av_mallocz( sizeof(AVPacket) );			av_new_packet( pkt, nread);			memcpy( pkt->data, buf, nread );			dlp_queue_push_tail( video_packet_queue, pkt );		}	} /* end while */}int avin_ha1_control(int cmd, void *arg){	av_log(NULL, AV_LOG_ERROR, "not support now for avin udp\n");	return -1;}avin_t avin_ha1 ={	AVIN_ID_HA1,	"ha1", /* h264 and aac */	avin_ha1_init,	avin_ha1_uninit,	avin_ha1_main,	avin_ha1_control,};#endif

⌨️ 快捷键说明

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