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

📄 mp4_play.c.svn-base

📁 psp播放器PPA源码,在MSYS/CYGWIN环境下编译(GNU-C)
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
#include "mp4_play.h"void mp4_play_safe_constructor(struct mp4_play_struct *p) {	p->audio_reserved = -1;	p->semaphore_can_get_video   = -1;	p->semaphore_can_put_video   = -1;	p->semaphore_can_get_audio   = -1;	p->semaphore_can_put_audio   = -1;	p->output_thread = -1;	p->show_thread   = -1;			mp4_decode_safe_constructor(&p->decoder);}void mp4_play_close(struct mp4_play_struct *p, int usePos, int pspType) {		if (!(p->audio_reserved < 0)) {		while(sceAudioGetChannelRestLen(0) > 0 );		sceAudioChRelease(0);	}	cooleyesAudioSetFrequency(sceKernelDevkitVersion(), 44100);	if (!(p->semaphore_can_get_video   < 0)) sceKernelDeleteSema(p->semaphore_can_get_video);	if (!(p->semaphore_can_put_video   < 0)) sceKernelDeleteSema(p->semaphore_can_put_video);	if (!(p->semaphore_can_get_audio   < 0)) sceKernelDeleteSema(p->semaphore_can_get_audio);	if (!(p->semaphore_can_put_audio   < 0)) sceKernelDeleteSema(p->semaphore_can_put_audio);		if (!(p->output_thread < 0)) sceKernelDeleteThread(p->output_thread);	if (!(p->show_thread   < 0)) sceKernelDeleteThread(p->show_thread);	mp4_decode_close(&p->decoder, pspType);	int i = 0;	for (i=0; i<p->subtitle_count; i++)		subtitle_parse_close( &subtitle_parser[i] );		//if (usePos) mp4_stat_save( p );	mp4_stat_save( p );		mp4_play_safe_constructor(p);}	static int mp4_wait(volatile struct mp4_play_struct *p, SceUID s, char *e) {	SceUInt t = 1;		int result = sceKernelWaitSema(s, 1, &t);	if (result == SCE_KERNEL_ERROR_OK) {		return(1);	}	else if (result == SCE_KERNEL_ERROR_WAIT_TIMEOUT) {		return(0);	}	else {		p->return_result  = e;		p->return_request = 1;		return(-1);	}	}static int mp4_avsync_status(int audio_timestamp, int video_timestamp, int video_frame_duration) {	// if video ahead of audio, do nothing	if(video_timestamp - audio_timestamp > 2 * video_frame_duration)		return 0;	// if audio ahead of video, skip frame	if(audio_timestamp - video_timestamp > 2 * video_frame_duration)		return 2;	return 1;}static int mp4_show_thread(SceSize input_length, void *input) {	volatile struct mp4_play_struct *p = *((void **) input);	p->current_video_buffer_number = 0;	int wait;	int avsync_status = 1;	int first = 1;		while (p->return_request == 0) {				wait = mp4_wait(p, p->semaphore_can_get_video, "mp4_show_thread: sceKernelWaitSema failed on semaphore_can_get_video");		if ( wait == -1) {			break;		}		else if ( wait == 1 ) {						avsync_status = mp4_avsync_status( p->decoder.output_audio_frame_buffers[p->current_audio_buffer_number].timestamp,				p->decoder.output_video_frame_buffers[p->current_video_buffer_number].timestamp,				p->decoder.video_frame_duration);			if(avsync_status > 0) {				if(avsync_status == 1) {					sceDisplayWaitVblankStart();					sceDisplaySetFrameBuf(p->decoder.output_video_frame_buffers[p->current_video_buffer_number].data, p->decoder.output_texture_width, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE);				}				p->current_video_buffer_number = (p->current_video_buffer_number + 1) % p->decoder.number_of_frame_buffers;				if ( first == 1 ) {					first = 0;				}				else {					if (sceKernelSignalSema(p->semaphore_can_put_video, 1) < 0) {						p->return_result  = "mp4_show_thread: sceKernelSignalSema failed on semaphore_can_put_video";						p->return_request = 1;						break;					}						}					}			else {				if (sceKernelSignalSema(p->semaphore_can_get_video, 1) < 0) {					p->return_result  = "mp4_show_thread: sceKernelSignalSema failed on semaphore_can_get_video1";					p->return_request = 1;					break;				}			}		}		else {			sceKernelDelayThread(1);		}			while (p->return_request == 0 && p->paused == 1) {			sceKernelDelayThread(100000);		}			}	return(0);}static unsigned int FONTCOLORS[] = { 	0xffffff,	0xff0000,	0x00ff00,	0x0000ff,	0xffff00,	0x00ffff};static unsigned int BORDERCOLORS[] = {		0x000000,	0x7f0000,	0x007f00,	0x00007f,	0x7f7f00,	0x007f7f};static void mp4_input(volatile struct mp4_play_struct *p, SceCtrlData *previous_controller) {	scePowerTick(0);	SceCtrlData controller;	sceCtrlReadBufferPositive(&controller, 1);	if(1)	{		if (((controller.Buttons & PSP_CTRL_TRIANGLE) == 0) && (previous_controller->Buttons & PSP_CTRL_TRIANGLE)) {			p->return_request = 1;			p->return_result = "exit: manual";		}		else {			if (p->paused == 1) {				p->seek = 0;				if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0)) {					p->paused = 0;				}				else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0)) {					make_screenshot();				}			}			else {				if (controller.Buttons & PSP_CTRL_CROSS) {					if (controller.Buttons & PSP_CTRL_RIGHT) {						p->seek = 2;					}					else if (controller.Buttons & PSP_CTRL_LEFT) {						p->seek = -2;					}					else {						p->seek = 0;						if ((controller.Buttons & PSP_CTRL_UP) && ((previous_controller->Buttons & PSP_CTRL_UP) == 0)) {							if (p->zoom != 200) {								p->zoom += 5;							}						}						else if ((controller.Buttons & PSP_CTRL_DOWN) && ((previous_controller->Buttons & PSP_CTRL_DOWN) == 0)) {							if (p->zoom != 100) {								p->zoom -= 5;							}						}						else if ((controller.Buttons & PSP_CTRL_RTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_RTRIGGER) == 0)) {							if (p->loop == 0) {								p->loop = 1;							}							else {								p->loop = 0;							}						}						else if ((controller.Buttons & PSP_CTRL_LTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_LTRIGGER) == 0)) {							if (p->subtitle_count) {								p->subtitle = (p->subtitle + 1)%(p->subtitle_count+1);								if (p->subtitle)									snprintf(info_string,512,"[i]%s[/i]", subtitle_parser[p->subtitle-1].filename);								else									snprintf(info_string,512,"[i]no subtitle[/i]");								info_count = 60;							}						}						else if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0)) {							p->subtitle_fontcolor = (p->subtitle_fontcolor+1)%NUMBER_OF_FONTCOLORS;							gu_font_color_set( FONTCOLORS[p->subtitle_fontcolor] );						}						else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0)) {							p->subtitle_bordercolor = (p->subtitle_bordercolor+1)%NUMBER_OF_BORDERCOLORS;							gu_font_border_color_set( BORDERCOLORS[p->subtitle_bordercolor] );						}						else if ((controller.Buttons & PSP_CTRL_SELECT) && ((previous_controller->Buttons & PSP_CTRL_SELECT) == 0)) {							if(p->audio_channel > -1) {								p->audio_channel--;							}							else {								p->audio_channel = 1;							}						}						else if ((controller.Buttons & PSP_CTRL_START) && ((previous_controller->Buttons & PSP_CTRL_START) == 0)) {							gu_lcd_output_inversion_set();						}					}				}				else if ((controller.Buttons & PSP_CTRL_SQUARE) && ((previous_controller->Buttons & PSP_CTRL_SQUARE) == 0)) {					p->paused = 1;					p->seek   = 0;				}				else if (controller.Buttons & PSP_CTRL_RIGHT) {					p->seek = 1;				}				else if (controller.Buttons & PSP_CTRL_LEFT) {					p->seek = -1;				}				else if ((controller.Buttons & PSP_CTRL_SELECT) && ((previous_controller->Buttons & PSP_CTRL_SELECT) == 0)) {					if (p->audio_stream + 1 == p->decoder.reader.file.audio_tracks) {						p->audio_stream = 0;					}					else {						p->audio_stream ++;					}				}				else if ((controller.Buttons & PSP_CTRL_UP) && ((previous_controller->Buttons & PSP_CTRL_UP) == 0)) {					if (p->volume_boost != 6) {						p->volume_boost ++;					}					pcm_set_normalize_ratio(p->volume_boost);				}				else if ((controller.Buttons & PSP_CTRL_DOWN) && ((previous_controller->Buttons & PSP_CTRL_DOWN) == 0)) {					if (p->volume_boost != 0) {						p->volume_boost --;					}					pcm_set_normalize_ratio(p->volume_boost);				}				else if ((controller.Buttons & PSP_CTRL_RTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_RTRIGGER) == 0)) {					if (p->luminosity_boost != (number_of_luminosity_boosts - 1)) {						p->luminosity_boost ++;					}				}				else if ((controller.Buttons & PSP_CTRL_LTRIGGER) && ((previous_controller->Buttons & PSP_CTRL_LTRIGGER) == 0)) {					if (p->luminosity_boost != 0) {						p->luminosity_boost --;					}				}				else if ((controller.Buttons & PSP_CTRL_START) && ((previous_controller->Buttons & PSP_CTRL_START) == 0)) {					if (p->aspect_ratio != (number_of_aspect_ratios - 1)) {						p->aspect_ratio ++;					}					else {						p->aspect_ratio = 0;					}				}				else if ((controller.Buttons & PSP_CTRL_CIRCLE) && ((previous_controller->Buttons & PSP_CTRL_CIRCLE) == 0)) {					if (p->show_interface == 0) {						p->show_interface = 1;					}					else {						p->show_interface = 0;					}				}				else {					p->seek = 0;				}			}		}	}	*previous_controller = controller;}static int mp4_output_thread(SceSize input_length, void *input) {	volatile struct mp4_play_struct *p = *((void **) input);	p->current_audio_buffer_number = 0;	int wait;	int first = 1;	SceInt32 volume = 0;		while (p->return_request == 0) {		volatile struct mp4_decode_buffer_struct *current_buffer = &p->decoder.output_audio_frame_buffers[p->current_audio_buffer_number];				wait = mp4_wait(p, p->semaphore_can_get_audio, "mp4_output_thread: sceKernelWaitSema failed on semaphore_can_get_audio");		if ( wait == -1) {			break;		}		else if ( wait == 1 ) {			if ( volume < PSP_AUDIO_VOLUME_MAX ) {				volume += PSP_AUDIO_VOLUME_MAX/5;				if ( volume >= PSP_AUDIO_VOLUME_MAX ) 					volume = PSP_AUDIO_VOLUME_MAX;			}			sceAudioOutputBlocking(0, volume, current_buffer->data);			p->current_audio_buffer_number = (p->current_audio_buffer_number + 1) % p->decoder.number_of_frame_buffers;			if (first == 1) {				first = 0;			}			else {					if (sceKernelSignalSema(p->semaphore_can_put_audio, 1) < 0) {					p->return_result  = "mp4_output_thread: sceKernelSignalSema failed on semaphore_can_put_audio";					p->return_request = 1;					break;				}			}					}		else {			sceKernelDelayThread(1);		}		while (p->return_request == 0 && p->paused == 1) {			sceKernelDelayThread(100000);		}	}	return(0);

⌨️ 快捷键说明

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