Esempio n. 1
0
void *pulse_play(PacketList *list)
{
	while(list->num_packets < 50)
		fprintf(stderr,"In loop.\r");
	
	do
	{	
		PacketNode *node=PacketQueueGet(list);
		if((pa_simple_write(handle,node->packet,node->packet_size,&error)) < 0)
			break;
		
		fprintf(stderr,"%03d Packets in queue.\r",list->num_packets);
		if(node==NULL)
			break;
		
		//Clean up packets after playing
		free(node->packet);
		node->packet=NULL;
		free(node);
		node=NULL;
		if(list->num_packets==0)
			break;
	}
	while(1);
	
	fprintf(stderr,"Total %d packets played.\n",list->total_packets_count);
	return NULL;
}
Esempio n. 2
0
void *AviWriteThread(void *arg)
{
	SWAviWrite *paviwrite = (SWAviWrite *)arg;
	
	if (!paviwrite)
	{
		return false;
	}
	
	quit = false;
	running = true;
	SWPacket *packet = NULL;
	AVPacket pkt;
	uint8_t *buffer;
	int ret;

	while(!quit)
	{
		packet = (SWPacket *)PacketQueueGet(pWPacketQueue);
		
		if (!packet)
		{
			usleep(50);
	
			continue;
		}
		if (packet->stream_index == -1)
		{
			break;
		}
		//写入文件
		av_init_packet(&pkt);
		pkt.data = NULL;
		pkt.size = 0;
		buffer = (uint8_t *)packet->data;
		if (buffer)
		{	
			pkt.data = buffer;
			pkt.size = packet->size;
			if (packet->key)
			{	
				pkt.flags |= AV_PKT_FLAG_KEY;
			}
			pkt.stream_index = packet->stream_index;
			pkt.pts = packet->pts;
			pkt.dts = packet->dts;
			fflush(stdout);
			ret = av_interleaved_write_frame(paviwrite->pFormatCtx, &pkt);
			if (ret != 0) 
			{
				fprintf(stderr, "Error while writing audio frame: %s\n",
								av_err2str(ret));
				exit(1);
			}
			
		 }
		 //av_free_packet(&pkt);
		 free(packet);
		 packet = NULL;		
		
	}	
	running = false;
	ReleaseAviWrite(paviwrite);
	printf("write end\n");
}