コード例 #1
0
ファイル: basic.c プロジェクト: KallistiOS/KallistiOS
int main(int argc, char **argv) {
    net_ipv4_stats_t ip;
    net_udp_stats_t udp;

    /* Wait for a bit so the user can ping, etc */
    thd_sleep(10 * 1000);

    /* Print out some statistics about the connection. */
    ip = net_ipv4_get_stats();
    udp = net_udp_get_stats();

    printf("IPv4 Stats:\n"
           "Packets sent successfully:       %6d\n"
           "Packets that failed to send:     %6d\n"
           "Packets received successfully:   %6d\n"
           "Packets rejected (bad size):     %6d\n"
           "                 (bad checksum): %6d\n"
           "                 (bad protocol): %6d\n\n",
           ip.pkt_sent, ip.pkt_send_failed, ip.pkt_recv, ip.pkt_recv_bad_size,
           ip.pkt_recv_bad_chksum, ip.pkt_recv_bad_proto);

    printf("UDP Stats:\n"
           "Packets sent successfully:       %6d\n"
           "Packets that failed to send:     %6d\n"
           "Packets received successfully:   %6d\n"
           "Packets rejected (bad size):     %6d\n"
           "                 (bad checksum): %6d\n"
           "                 (no socket):    %6d\n\n",
           udp.pkt_sent, udp.pkt_send_failed, udp.pkt_recv,
           udp.pkt_recv_bad_size, udp.pkt_recv_bad_chksum,
           udp.pkt_recv_no_sock);

    return 0;
}
コード例 #2
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_EnableSettingsPage()
{
	ScreenFadeOut();
	thd_sleep(200);
	GUI_CardStackShowIndex(self.pages, 4);
	ScreenFadeIn();
}
コード例 #3
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_OnDetectPressed(GUI_Widget *widget)
{
	ScreenFadeOut();
	thd_sleep(200);
	BiosFlasher_EnableMainPage();	// Redetect bios again
	ScreenFadeIn();
}
コード例 #4
0
ファイル: opustest.c プロジェクト: KallistiOS/KallistiOS
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;

    dbgio_dev_select("fb");

    printf("Opus Decoder Library Example Program\n\n");

    opusplay_init();

    if(opusplay_play_file("/rd/test.opus", 0)) {
        printf("Cannot play /rd/test.opus!\n");
        printf("Did you remember to put an opus file in the\n"
               "romdisk before compiling?\n");
        thd_sleep(10 * 1000);

        opusplay_shutdown();
        snd_stream_shutdown();
        return 0;
    }

    printf("The Opus file should now be playing in a thread...\n\n");
    printf("Press START to exit and (Y) to restart playback.\n");

    while(1) {
        if((cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER))) {
            if((state = (cont_state_t *)maple_dev_status(cont))) {
                if(state->buttons & CONT_START)
                    break;

                if(state->buttons & CONT_Y) {
                    opusplay_stop();
                    opusplay_play_file("/rd/test.opus", 0);
                }
            }

            thd_sleep(100);
        }

    }

    printf("Cleaning up...\n");
    opusplay_stop();
    opusplay_shutdown();
    snd_stream_shutdown();
    return 0;
}
コード例 #5
0
ファイル: FAKE_mixer.c プロジェクト: arcadenea/fake_mixer
static void *snd_thread(void *data)
{

	for(;;)
	{
		MikMod_Update();
		thd_sleep(5);
	}
	
	return NULL;
}
コード例 #6
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_EnableChoseFilePage()
{
	ScreenFadeOut();
	thd_sleep(200);
	GUI_CardStackShowIndex(self.pages, 1);
	ScreenFadeIn();

	self.m_ScrollPos = 0;
	self.m_MaxScroll = BiosFlasher_GetNumFilesCurrentDir() / 10;
	GUI_PanelSetYOffset(GUI_FileManagerGetItemPanel(self.filebrowser), self.m_ScrollPos * 300);
	BiosFlasher_ActivateScrollButtons(self.m_ScrollPos, self.m_MaxScroll);
}
コード例 #7
0
ファイル: g2_ide.c プロジェクト: DC-SWAT/DreamShell
/* Initialize the device */
int ide_init() {
	int dd_off;
	
	//dbglog(DBG_INFO, "ide_init: initializing\n");

	/* Reset */
	outp(0x3f6, 0x0e);
	thd_sleep(10);
	outp(0x3f6, 0x0a);
	thd_sleep(10);

	if(wait_controller() < 0) {
		return -1;
	}
	
	outp(0x1f6,0xa0);	/* get info on first drive. 0xb0 == 2nd */
	outp(0x1f7,0xec);	/* get drive info data */
	
	if(wait_data() < 0) {
		return -1;
	}
	
	for (dd_off=0; dd_off<256; dd_off++) {
		dd[dd_off] = inpw(0x1f0);
	}

	hd_cyls = dd[1];
	hd_heads = dd[3];
	hd_sects = dd[6];

	ds_printf("DS_IDE: Detected %s, %dMB, CHS (%d/%d/%d)\n",
	get_ascii(dd, 27, 46),
	(hd_cyls * hd_heads * hd_sects * 512L) / (1024L*1024L),
	hd_cyls, hd_heads, hd_sects);

	return 0;
}
コード例 #8
0
ファイル: g2_ide.c プロジェクト: DC-SWAT/DreamShell
static int wait_data() {
	int timeout = 100;

	while (!(inp(0x1f7) & 0x08) && timeout) {
		thd_sleep(10);
		timeout--;
	}

	if (!timeout) {
		ds_printf("DS_ERROR: IDE controller timed out waiting for data.. status = %x/%x\n",
			inp(0x1f7), inp(0x1f1));
		return -1;
	}
	return 0;
}
コード例 #9
0
ファイル: conio.c プロジェクト: zig/kos-dcplaya
/* the drawing/keyboard polling thread */
static void conio_thread(void *param) {
	conio_entered = 1;
	while (!conio_exit) {
		sem_wait(ft_mutex);
		conio_input_frame();
		if (conio_ttymode == CONIO_TTY_PVR) {
#ifdef GFX
			conio_draw_frame();
#endif
		} else {
			if (conio_ttymode == CONIO_TTY_SERIAL)
				scif_flush();
			thd_sleep(1000/60);	/* Simulate frame delay */
		}
		sem_signal(ft_mutex);
	}
	conio_exit = -1;
}
コード例 #10
0
ファイル: bflash.c プロジェクト: WinCoder/DreamShell
/* Wait until the flash is ready, with timeout */
static int bflash_wait_ready(bflash_dev_t *dev, uint32 addr, int timeout) {
	int wait = 0;
	
	if (timeout < 0) {
		timeout = -timeout;
		wait = 1;
	}
	while (timeout-- && bflash_busy(addr)) {
		if (wait)
			thd_sleep(100);
		else
			thd_pass();
	}
	if (timeout <= 0) {
		ds_printf("DS_ERROR: Writing to flash timed out\n");
		return -1;
	}
	
	return 0;
}
コード例 #11
0
ファイル: spu.c プロジェクト: Corbachu/KallistiOS
void wait_start() {
    maple_device_t *cont;
    cont_state_t *state;

    while(1) {
        cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

        if(!cont) continue;

        /* Check for start on the controller */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state)
            continue;

        if(state->buttons & CONT_START) {
            printf("Pressed start\n");
            return;
        }

        thd_sleep(10);
    }
}
コード例 #12
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_EnableMainPage()
{
	
	if (GUI_CardStackGetIndex(self.pages) != 0)
	{
		ScreenFadeOut();
		thd_sleep(200);
		GUI_CardStackShowIndex(self.pages, 0);
		ScreenFadeIn();
	}

	bflash_dev_t* dev = BiosFlasher_DetectFlashChip();

	char info[64];
	sprintf(info, "Model: %s", dev->name); 
	GUI_LabelSetText(BiosFlasher_GetWidget("label_flash_name"), info);
	sprintf(info, "Size: %dKb", dev->size); 
	GUI_LabelSetText(BiosFlasher_GetWidget("label_flash_size"), info);
	sprintf(info, "Voltage: %dV", (dev->flags & F_FLASH_LOGIC_3V) ? 3 : 5); 
	GUI_LabelSetText(BiosFlasher_GetWidget("label_flash_voltage"), info);
	sprintf(info, "Access: %s", (dev->flags & F_FLASH_PROGRAM) ? "Read/Write" : "Read only"); 
	GUI_LabelSetText(BiosFlasher_GetWidget("label_flash_access"), info);
}
コード例 #13
0
ファイル: http.c プロジェクト: pcercuei/dcplaya
static int http_connect(HTTPContext *s, const char *path, const char *hoststr, int flags, int wait)
{
    int post, err, ch;
    char line[512], *q;

    hdr_clear(s);

    /* send http header */
    post = flags & O_WRONLY;

    s->len = 0;
    s->tread = 0;
    s->bpos = 0; s->bsz = 0;

    snprintf(line, sizeof(line),
             "%s %s HTTP/1.0\r\n"
             "User-Agent: %s\r\n"
             "Host: %s\r\n"
             "Accept: */*\r\n"
	     "Connection: keep-alive\r\n"
             "\r\n",
             post ? "POST" : "GET",
             path,
             //"Wget/1.9",
	     "dcplaya_net",
             hoststr);
    
    if (http_write((uint32) s, line, strlen(line)) < 0)
        return -1;

#ifdef DEBUG
    printf("http : sent header -->\n%s", line);
#endif
        
    /* init input buffer */
    s->line_count = 0;
    //s->location[0] = '\0';
    if (post) {
      //sleep(1);
      
        return 0;
    }
    
    /* wait for header */
    q = line;
    if (wait)
      thd_sleep(wait);
    for(;;) {
        ch = http_getc((uint32) s);
#ifdef DEBUG
	//printf("%c", ch);
#endif
        if (ch < 0) {
	  printf("http header truncated\n");
	  return 0;
	}
        if (ch == '\n') {
            /* process line */
            if (q > line && q[-1] == '\r')
                q--;
            *q = '\0';
#ifdef DEBUG
            printf("header='%s'\n", line);
#endif

	    if (line[0])
	      hdr_add(s, line);

            err = process_line(s, line, s->line_count);
            if (err < 0)
                return err;
            if (err == 0)
	      return 0;
	      //return s->len? 0 : -1;

            s->line_count++;
            q = line;
        } else {
            if ((q - line) < sizeof(line) - 1)
                *q++ = ch;
        }
    }
}
コード例 #14
0
ファイル: utils.c プロジェクト: WinCoder/DreamShell
void ds_sleep(int ms) {
     thd_sleep(ms);
}
コード例 #15
0
ファイル: sndmp3_mpg123.c プロジェクト: DC-SWAT/DreamShell
/* Call this function as a thread to handle playback. Playback will 
   stop and this thread will return when you call sndmp3_shutdown(). */
static void sndmp3_thread() {
	int sj;

	stream_hnd = snd_stream_alloc(NULL, SND_STREAM_BUFFER_MAX);
	
	if(stream_hnd < 0) {
		printf("sndserver: can't alloc stream\r\n");
		return;
	}
	
	/* Main command loop */
	while(sndmp3_status != STATUS_QUIT) {
		switch(sndmp3_status) {
			case STATUS_INIT:
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_READY:
				printf("sndserver: waiting on semaphore\r\n");
				sem_wait(sndmp3_halt_sem);
				printf("sndserver: released from semaphore\r\n");
				break;
			case STATUS_STARTING:
				/* Initialize streaming driver */
				if (snd_stream_reinit(stream_hnd, mpg123_callback) < 0) {
					sndmp3_status = STATUS_READY;
				} else {
					snd_stream_start(stream_hnd, rate, channels - 1);
					sndmp3_status = STATUS_PLAYING;
				}
				break;
			case STATUS_REINIT:
				/* Re-initialize streaming driver */
				snd_stream_reinit(stream_hnd, NULL);
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_PLAYING: {
				sj = jiffies;
				if (snd_stream_poll(stream_hnd) < 0) {
					if (sndmp3_loop) {
						printf("sndserver: restarting '%s'\r\n", mp3_last_fn);
						if (libmpg123_init(mp3_last_fn) < 0) {
							sndmp3_status = STATUS_STOPPING;
							mp3_last_fn[0] = 0;
						}
					} else {
						printf("sndserver: not restarting\r\n");
						snd_stream_stop(stream_hnd);
						sndmp3_status = STATUS_READY;
						mp3_last_fn[0] = 0;
					}
					// stream_start();
				} else
					thd_sleep(50);
				break;
			}
			case STATUS_STOPPING:
				snd_stream_stop(stream_hnd);
				sndmp3_status = STATUS_READY;
				break;
		}
	}
	
	/* Done: clean up */
	libmpg123_shutdown();
	snd_stream_stop(stream_hnd);
	snd_stream_destroy(stream_hnd);

	sndmp3_status = STATUS_ZOMBIE;
}
コード例 #16
0
ファイル: sndmp3_mpglib.c プロジェクト: DC-SWAT/DreamShell
/* Call this function as a thread to handle playback. Playback will 
   stop and this thread will return when you call sndmp3_shutdown(). */
static void sndmp3_thread() {
	int sj;
	
	stream_hnd = snd_stream_alloc(NULL, SND_STREAM_BUFFER_MAX);
	//assert( stream_hnd != -1 );
	
	/* Main command loop */
	while(sndmp3_status != STATUS_QUIT) {
		switch(sndmp3_status) {
			case STATUS_INIT:
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_READY:
				printf("sndserver: waiting on semaphore\r\n");
				sem_wait(sndmp3_halt_sem);
				printf("sndserver: released from semaphore\r\n");
				break;
			case STATUS_STARTING:
				/* Initialize streaming driver */
				if (snd_stream_reinit(stream_hnd, mpglib_callback) < 0) {
					sndmp3_status = STATUS_READY;
				} else {
					//snd_stream_start(stream_hnd, decinfo.samprate, decinfo.channels - 1);
					//snd_stream_start(stream_hnd, 44100, 1);
					snd_stream_start(stream_hnd, freqs[mp.fr.sampling_frequency], mp.fr.stereo);
					sndmp3_status = STATUS_PLAYING;
				}
				break;
			case STATUS_REINIT:
				/* Re-initialize streaming driver */
				snd_stream_reinit(stream_hnd, NULL);
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_PLAYING: {
				sj = jiffies;
				if (snd_stream_poll(stream_hnd) < 0) {
					if (sndmp3_loop) {
						printf("sndserver: restarting '%s'\r\n", mp3_last_fn);
						if (mpglib_init(mp3_last_fn) < 0) {
							sndmp3_status = STATUS_STOPPING;
							mp3_last_fn[0] = 0;
						}
					} else {
						printf("sndserver: not restarting\r\n");
						snd_stream_stop(stream_hnd);
						sndmp3_status = STATUS_READY;
						mp3_last_fn[0] = 0;
					}
					// stream_start();
				} else
					thd_sleep(50);
				break;
			}
			case STATUS_STOPPING:
				snd_stream_stop(stream_hnd);
				sndmp3_status = STATUS_READY;
				break;
		}
	}
	
	/* Done: clean up */
	mpglib_shutdown();
	snd_stream_stop(stream_hnd);
	snd_stream_destroy(stream_hnd);

	sndmp3_status = STATUS_ZOMBIE;
}
コード例 #17
0
ファイル: module.c プロジェクト: i-rom/DreamShell
static int rip_sec(int tn,int first,int count,int type,char *dst_file, int disc_type){

double percent,percent_last=0.0;
maple_device_t *cont;
cont_state_t *state;
file_t hnd;
int secbyte = (type == 4 ? 2048 : 2352) , i , count_old=count, bad=0, cdstat, readi;
uint8 *buffer = (uint8 *)memalign(32, SEC_BUF_SIZE * secbyte);
	
	GUI_WidgetMarkChanged(self.app->body);
//	ds_printf("Track %d		First %d	Count %d	Type %d\n",tn,first,count,type);
/*	if (secbyte == 2048) cdrom_set_sector_size (secbyte);
	else _cdrom_reinit (1);
*/
	cdrom_set_sector_size (secbyte);
	
	if ((hnd = fs_open(dst_file,O_WRONLY | O_TRUNC | O_CREAT)) == FILEHND_INVALID) {
		ds_printf("Error open file %s\n" ,dst_file); 
		cdrom_spin_down(); free(buffer); 
		return CMD_ERROR;
		}
	
	LockVideo();
	
	while(count) {
	
		int nsects = count > SEC_BUF_SIZE ? SEC_BUF_SIZE : count;
		count -= nsects;
		
		
		while((cdstat=cdrom_read_sectors(buffer, first, nsects)) != ERR_OK ) {
			if (atoi(GUI_TextEntryGetText(self.num_read)) == 0) break;
			readi++ ;
			if (readi > 5) break ;
			thd_sleep(200);
		}
			readi = 0;
		if (cdstat != ERR_OK) {
			if (!GUI_WidgetGetState(self.bad)) {
				UnlockVideo();
				GUI_ProgressBarSetPosition(self.read_error, 1.0);
				for(;;) {
					cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
					
					if(!cont) continue;
					state = (cont_state_t *)maple_dev_status(cont);
					
					if(!state) continue;
					if(state->buttons & CONT_A) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						ds_printf("DS_ERROR: Can't read sector %ld\n", first); 
						free(buffer); 
						fs_close(hnd); 
						return CMD_ERROR;
					} else if(state->buttons & CONT_B) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					} else if(state->buttons & CONT_Y) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0); 
						GUI_WidgetSetState(self.bad, 1);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					}
				}
			}
			// Ошибка, попробуем по одному
			uint8 *pbuffer = buffer;
			LockVideo();
			for(i = 0; i < nsects; i++) {
				
				while((cdstat=cdrom_read_sectors(pbuffer, first, 1)) != ERR_OK ) {
				readi++ ;
				if (readi > atoi(GUI_TextEntryGetText(self.num_read))) break ;
				if (readi == 1 || readi == 6 || readi == 11 || readi == 16 || readi == 21 || readi == 26 || readi == 31 || readi == 36 || readi == 41 || readi == 46) cdrom_reinit();
				thd_sleep(200);
				}
				readi = 0;
				
				if (cdstat != ERR_OK) {
					// Ошибка, заполним нулями и игнорируем
					UnlockVideo();
					cdrom_reinit();
					memset(pbuffer, 0, secbyte);
					bad++;
					ds_printf("DS_ERROR: Can't read sector %ld\n", first);
					LockVideo();
				}
			
				pbuffer += secbyte;
				first++;
			}
		
		} else {
			// Все ок, идем дальше
			first += nsects;
		}
	
		if(fs_write(hnd, buffer, nsects * secbyte) < 0) {
			// Ошибка записи, печально, прерываем процесс
			UnlockVideo();
			free(buffer);
			fs_close(hnd);
			return CMD_ERROR;
		}
		UnlockVideo();
		percent = 1-(float)(count) / count_old;
		if ((percent = ((int)(percent*100 + 0.5))/100.0) > percent_last) {
		percent_last = percent;
		GUI_ProgressBarSetPosition(self.pbar, percent);
		LockVideo();
		}
	}
UnlockVideo();
free(buffer);
fs_close(hnd);
ds_printf("%d Bad sectors on track\n", bad);
return CMD_OK;
}
コード例 #18
0
ファイル: player.c プロジェクト: DC-SWAT/DreamShell
int ffplay(const char *filename, const char *force_format) {

	char errbuf[256];
	int r = 0;
	
	int frameFinished;
	AVPacket packet;
	int audio_buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
	int16_t *audio_buf = (int16_t *) malloc((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2);
	
	if(!audio_buf) {
		ds_printf("DS_ERROR: No free memory\n");
		return -1;
	}
	
	memset(audio_buf, 0, (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2);
	
	AVFormatContext *pFormatCtx = NULL;
	AVFrame *pFrame = NULL;
	AVCodecContext *pVideoCodecCtx = NULL, *pAudioCodecCtx = NULL;
	AVInputFormat *file_iformat = NULL;
	
	video_txr_t movie_txr;
	int videoStream = -1, audioStream = -1;
	
	maple_device_t *cont = NULL;
	cont_state_t *state = NULL;
	int pause = 0, done = 0;
	
	char fn[MAX_FN_LEN];
	sprintf(fn, "ds:%s", filename);

	memset(&movie_txr, 0, sizeof(movie_txr));
	
	if(!codecs_inited) {
		avcodec_register_all();
		avcodec_register(&mp1_decoder);
		avcodec_register(&mp2_decoder);
		avcodec_register(&mp3_decoder);
		avcodec_register(&vorbis_decoder);
		//avcodec_register(&mpeg4_decoder);
		codecs_inited = 1;
	}
	
	if(force_format)
      file_iformat = av_find_input_format(force_format);
    else
      file_iformat = NULL;


	// Open video file
	ds_printf("DS_PROCESS_FFMPEG: Opening file: %s\n", filename);
	if((r = av_open_input_file((AVFormatContext**)(&pFormatCtx), fn, file_iformat, /*FFM_PACKET_SIZE*/0, NULL)) != 0) {
		av_strerror(r, errbuf, 256);
		ds_printf("DS_ERROR_FFMPEG: %s\n", errbuf);
		free(audio_buf);
		return -1; // Couldn't open file
	}
	
	// Retrieve stream information
	ds_printf("DS_PROCESS_FFMPEG: Retrieve stream information...\n");
	if((r = av_find_stream_info(pFormatCtx)) < 0) {
		av_strerror(r, errbuf, 256);
		ds_printf("DS_ERROR_FFMPEG: %s\n", errbuf);
		av_close_input_file(pFormatCtx);
		free(audio_buf);
		return -1; // Couldn't find stream information
	}

	// Dump information about file onto standard error
	dump_format(pFormatCtx, 0, filename, 0);
	//thd_sleep(5000);
	
	pVideoCodecCtx = findDecoder(pFormatCtx, AVMEDIA_TYPE_VIDEO, &videoStream);
	pAudioCodecCtx = findDecoder(pFormatCtx, AVMEDIA_TYPE_AUDIO, &audioStream);
	
	//LockInput();
	
	if(pVideoCodecCtx) {
		
		//LockVideo();
		ShutdownVideoThread();
		SDL_DS_FreeScreenTexture(0);
		int format = 0;
		
		switch(pVideoCodecCtx->pix_fmt) {
			case PIX_FMT_YUV420P:
			case PIX_FMT_YUVJ420P:
			
				format = PVR_TXRFMT_YUV422;
#ifdef USE_HW_YUV				
				yuv_conv_init();
#endif
				break;
				
			case PIX_FMT_UYVY422:
			case PIX_FMT_YUVJ422P:
			
				format = PVR_TXRFMT_YUV422;
				break;
				
			default:
				format = PVR_TXRFMT_RGB565;
				break;
		}
		
		MakeVideoTexture(&movie_txr, pVideoCodecCtx->width, pVideoCodecCtx->height, format | PVR_TXRFMT_NONTWIDDLED, PVR_FILTER_BILINEAR);
		
#ifdef USE_HW_YUV				
		yuv_conv_setup(movie_txr.addr, PVR_YUV_MODE_MULTI, PVR_YUV_FORMAT_YUV420, movie_txr.width, movie_txr.height);
		pvr_dma_init();
#endif

	} else {
		ds_printf("DS_ERROR: Didn't find a video stream.\n");
	}
	
	
	if(pAudioCodecCtx) {
		
#ifdef USE_DIRECT_AUDIO
		audioinit(pAudioCodecCtx);
#else

		sprintf(fn, "%s/firmware/aica/ds_stream.drv", getenv("PATH"));
		
		if(snd_init_fw(fn) < 0) {
			goto exit_free;
		}
	
		if(aica_audio_open(pAudioCodecCtx->sample_rate, pAudioCodecCtx->channels, 8192) < 0) {
			goto exit_free;
		}
		//snd_cpu_clock(0x19);
		//snd_init_decoder(8192);
#endif
		
	} else {
		ds_printf("DS_ERROR: Didn't find a audio stream.\n");
	}
	
	//ds_printf("FORMAT: %d\n", pVideoCodecCtx->pix_fmt);

	// Allocate video frame
	pFrame = avcodec_alloc_frame();

	if(pFrame == NULL) {
		ds_printf("DS_ERROR: Can't alloc memory\n");
		goto exit_free;
	}
	
	int pressed = 0, framecnt = 0;
	uint32 fa = 0;
	
	fa = GET_EXPORT_ADDR("ffplay_format_handler");
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			void (*ff_format_func)(AVFormatContext *, AVCodecContext *, AVCodecContext *) = 
				(void (*)(AVFormatContext *, AVCodecContext *, AVCodecContext *))fa;
			ff_format_func(pFormatCtx, pVideoCodecCtx, pAudioCodecCtx);
		EXPT_GUARD_CATCH;
		EXPT_GUARD_END;
	}
	
	fa = GET_EXPORT_ADDR("ffplay_frame_handler");
	void (*ff_frame_func)(AVFrame *) = NULL;
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			ff_frame_func = (void (*)(AVFrame *))fa;
			// Test call
			ff_frame_func(NULL);
		EXPT_GUARD_CATCH;
			ff_frame_func = NULL;
		EXPT_GUARD_END;
	}
	
	fa = GET_EXPORT_ADDR("ffplay_render_handler");
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			movie_txr.render_cb = (void (*)(void *))fa;
			// Test call
			movie_txr.render_cb(NULL);
		EXPT_GUARD_CATCH;
			movie_txr.render_cb = NULL;
		EXPT_GUARD_END;
	}
	
	while(av_read_frame(pFormatCtx, &packet) >= 0 && !done) {
		
		do {
			if(ff_frame_func) 
				ff_frame_func(pFrame);
					
			cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
			framecnt++;

			if(cont) {
				state = (cont_state_t *)maple_dev_status(cont);
				
				if (!state) {
					break;
				}
				if (state->buttons & CONT_START || state->buttons & CONT_B) {
					av_free_packet(&packet);
					done = 1;
				}
				if (state->buttons & CONT_A) {
					if((framecnt - pressed) > 10) {
						pause = pause ? 0 : 1;
						if(pause) {
#ifdef USE_DIRECT_AUDIO
							audio_end();
#else
							stop_audio();
#endif
						} else {
#ifndef USE_DIRECT_AUDIO
							start_audio();
#endif
						}
					}
					pressed = framecnt;
				}
				
				if(state->buttons & CONT_DPAD_LEFT) {
					//av_seek_frame(pFormatCtx, -1, timestamp * ( AV_TIME_BASE / 1000 ), AVSEEK_FLAG_BACKWARD);
				}
				
				if(state->buttons & CONT_DPAD_RIGHT) {
					//av_seek_frame(pFormatCtx, -1, timestamp * ( AV_TIME_BASE / 1000 ), AVSEEK_FLAG_BACKWARD);
				}
			}
			
			if(pause) thd_sleep(100);
			
		} while(pause);
		
		//printf("Packet: size: %d data: %02x%02x%02x pst: %d\n", packet.size, packet.data[0], packet.data[1], packet.data[2], pFrame->pts);
		
		// Is this a packet from the video stream?
		if(packet.stream_index == videoStream) {
			//printf("video\n");
			// Decode video frame
			if((r = avcodec_decode_video2(pVideoCodecCtx, pFrame, &frameFinished, &packet)) < 0) {
				//av_strerror(r, errbuf, 256);
				//printf("DS_ERROR_FFMPEG: %s\n", errbuf);
			} else {
				
				// Did we get a video frame?
				if(frameFinished && !pVideoCodecCtx->hurry_up) {
					RenderVideo(&movie_txr, pFrame, pVideoCodecCtx);
				}
			}

		} else if(packet.stream_index == audioStream) {
			//printf("audio\n");
			//snd_decode((uint8*)audio_buf, audio_buf_size, AICA_CODEC_MP3);
			
			audio_buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
			if((r = avcodec_decode_audio3(pAudioCodecCtx, audio_buf, &audio_buf_size, &packet)) < 0) {
				//av_strerror(r, errbuf, 256);
				//printf("DS_ERROR_FFMPEG: %s\n", errbuf);
				//continue;
			} else {
				
				if(audio_buf_size > 0 && !pAudioCodecCtx->hurry_up) {

#ifdef USE_DIRECT_AUDIO
					audio_write(pAudioCodecCtx, audio_buf, audio_buf_size);
#else
					aica_audio_write((char*)audio_buf, audio_buf_size);
#endif
				}
			}
		}

		// Free the packet that was allocated by av_read_frame
		av_free_packet(&packet);
	}
	
	goto exit_free;
	
exit_free:

	if(pFrame)
		av_free(pFrame);
	
	if(pFormatCtx)
		av_close_input_file(pFormatCtx);
	
	if(audioStream > -1) {
		if(pAudioCodecCtx)
			avcodec_close(pAudioCodecCtx);
#ifdef USE_DIRECT_AUDIO
		audio_end();
#else
		aica_audio_close();
		sprintf(fn, "%s/firmware/aica/kos_stream.drv", getenv("PATH"));
		snd_init_fw(fn);
#endif
	}
	
	if(audio_buf) {
		free(audio_buf);
	}
	
	if(videoStream > -1) {
		if(pVideoCodecCtx)
			avcodec_close(pVideoCodecCtx);
		FreeVideoTexture(&movie_txr);
		SDL_DS_AllocScreenTexture(GetScreen());
		InitVideoThread();
		//UnlockVideo();
	}
	
	//UnlockInput();
	ProcessVideoEventsUpdate(NULL);
	return 0;
}
コード例 #19
0
void SDL_Delay(Uint32 ms)
{
	thd_sleep(ms);
}
コード例 #20
0
ファイル: sndoggvorbis.c プロジェクト: KallistiOS/kos-ports
/* sndoggvorbis_thread()
 *
 * this function is called by sndoggvorbis_mainloop and handles all the threads
 * status handling and playing functionality.
 */
void sndoggvorbis_thread()
{
	int stat;

	stream_hnd = snd_stream_alloc(NULL, SND_STREAM_BUFFER_MAX);
	assert( stream_hnd != SND_STREAM_INVALID );

	while(sndoggvorbis_status != STATUS_QUIT)
	{
		switch(sndoggvorbis_status)
		{
			case STATUS_INIT:
				sndoggvorbis_status= STATUS_READY;
				break;

			case STATUS_READY:
				printf("oggthread: waiting on semaphore\n");
				sem_wait(sndoggvorbis_halt_sem);
				printf("oggthread: released from semaphore (status=%d)\n", sndoggvorbis_status);
				break;

			case STATUS_QUEUEING: {
				vorbis_info * vi = ov_info(&vf, -1);

				snd_stream_reinit(stream_hnd, callback);
				snd_stream_queue_enable(stream_hnd);
				printf("oggthread: stream_init called\n");
				snd_stream_start(stream_hnd, vi->rate, vi->channels - 1);
				snd_stream_volume(stream_hnd, sndoggvorbis_vol);
				printf("oggthread: stream_start called\n");
				if (sndoggvorbis_status != STATUS_STOPPING)
					sndoggvorbis_status = STATUS_QUEUED;
				break;
			}

			case STATUS_QUEUED:
				printf("oggthread: queue waiting on semaphore\n");
				sem_wait(sndoggvorbis_halt_sem);
				printf("oggthread: queue released from semaphore\n");
				break;

			case STATUS_STARTING: {
				vorbis_info * vi = ov_info(&vf, -1);

				if (sndoggvorbis_queue_enabled) {
					snd_stream_queue_go(stream_hnd);
				} else {
					snd_stream_reinit(stream_hnd, callback);
					printf("oggthread: stream_init called\n");
					snd_stream_start(stream_hnd, vi->rate, vi->channels - 1);
					printf("oggthread: stream_start called\n");
				}
				snd_stream_volume(stream_hnd, sndoggvorbis_vol);
				sndoggvorbis_status=STATUS_PLAYING;
				break;
			}

			case STATUS_PLAYING:
				/* Preliminary Bitrate Code
				 * For our tests the bitrate is being set in the struct once in a
				 * while so that the user can just read out this value from the struct
				 * and use it for whatever purpose
				 */
				/* if (tempcounter==sndoggvorbis_bitrateint)
				{
					long test;
					if((test=VorbisFile_getBitrateInstant()) != -1)
					{
						sndoggvorbis_info.actualbitrate=test;
					}
					tempcounter = 0;
				}
				tempcounter++; */

				/* Stream Polling and end-of-stream detection */
				if ( (stat = snd_stream_poll(stream_hnd)) < 0)
				{
					printf("oggthread: stream ended (status %d)\n", stat);
					printf("oggthread: not restarting\n");
					snd_stream_stop(stream_hnd);

					/* Reset our PCM buffer */
					pcm_count = 0;
					last_read = 0;
					pcm_ptr = pcm_buffer;

					/* This can also happen sometimes when you stop the stream
					   manually, so we'll call this here to make sure */
					ov_clear(&vf);
					sndoggvorbis_lastfilename[0] = 0;
					sndoggvorbis_status = STATUS_READY;
					sndoggvorbis_clear_comments();
				} else {
					/* Sleep some until the next buffer is needed */
					thd_sleep(50);
				}
				break;

			case STATUS_STOPPING:
				snd_stream_stop(stream_hnd);
				ov_clear(&vf);
				/* Reset our PCM buffer */
				pcm_count = 0;
				last_read = 0;
				pcm_ptr = pcm_buffer;

				sndoggvorbis_lastfilename[0] = 0;
				sndoggvorbis_status = STATUS_READY;
				sndoggvorbis_clear_comments();
				break;
		}
	}

	snd_stream_stop(stream_hnd);
	snd_stream_destroy(stream_hnd);
	sndoggvorbis_status=STATUS_ZOMBIE;

	printf("oggthread: thread released\n");
}
コード例 #21
0
ファイル: module.c プロジェクト: i-rom/DreamShell
void gd_ripper_StartRip() {
	file_t fd;
	CDROM_TOC toc ;
	int status, disc_type ,cdcr ,start ,s_end ,nsec ,type ,tn ,session,terr=0;
	char dst_folder[MAX_FN_LEN];
	char dst_file[MAX_FN_LEN];
	char riplabel[64];
	char text[MAX_FN_LEN];
	uint64 stoptimer , starttimer , riptime;
	
	starttimer = timer_ms_gettime64 (); // timer
	cdrom_reinit();
	snprintf(text ,MAX_FN_LEN,"%s", GUI_TextEntryGetText(self.gname));
	if(GUI_WidgetGetState(self.sd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/sd/%s", text);
	}else if(GUI_WidgetGetState(self.hdd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/ide/%s", text);
	}else if(GUI_WidgetGetState(self.net_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/net/%s", text);
	}
//ds_printf("Dst file1 %s\n" ,dst_folder);	
getstatus:	
	if((cdcr = cdrom_get_status(&status, &disc_type)) != ERR_OK) {
		switch (cdcr){
			case ERR_NO_DISC :
				ds_printf("DS_ERROR: Disk not inserted\n");
				return;
			case ERR_DISC_CHG :
				cdrom_reinit();
				goto getstatus;
			case CD_STATUS_BUSY :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SEEKING :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SCANNING :
				thd_sleep(200);
				goto getstatus;
			default:
				ds_printf("DS_ERROR: GD-rom error\n");
				return;
		}
	}
	if (disc_type == CD_CDROM_XA){
	rname:
			snprintf(dst_file,MAX_FN_LEN, "%s.iso", dst_folder);
			if ((fd=fs_open(dst_file , O_RDONLY)) != FILEHND_INVALID) {
				fs_close(fd); strcpy(dst_file,"\0"); 
				strcat(dst_folder , "0"); 
				goto rname ;
			} else disc_type = 1;
	} else if (disc_type == CD_GDROM){
	rname1:
			if ((fd=fs_open (dst_folder , O_DIR)) != FILEHND_INVALID) {
				fs_close(fd); 
				strcat(dst_folder , "0"); 
				goto rname1 ;
			} else {strcpy(dst_file,"\0");
			snprintf(dst_file,MAX_FN_LEN,"%s", dst_folder); 
			disc_type = 2; 
			fs_mkdir(dst_file);
			}
			
			while(cdrom_read_toc(&toc, 1) != CMD_OK) { 
				terr++;
				cdrom_reinit();
				if (terr > 100){
				ds_printf("DS_ERROR: Toc read error for gdlast\n");
				fs_rmdir(dst_folder); 
				return; 
				}
			}
			terr=0;
			self.lastgdtrack = TOC_TRACK(toc.last);
	} else {
			ds_printf("DS_ERROR: This is not game disk\nInserted %d disk\n",disc_type);
			return;
	}
//ds_printf("Dst file %s\n" ,dst_file);
	
	for (session=0; session < disc_type; session++) {
		cdrom_set_sector_size(2048);
		while(cdrom_read_toc(&toc, session) != CMD_OK) {
			terr++; 
			if(terr==5) cdrom_reinit(); 
			thd_sleep(500); 
			if (terr > 10) { 
				ds_printf("DS_ERROR: Toc read error\n");
			if (disc_type == 1) {
				if(fs_unlink(dst_file) != 0) 
				ds_printf("Error delete file: %s\n" ,dst_file);
			}else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				} 
				return; 
			}
		}
		terr = 0;
		int first = TOC_TRACK(toc.first);
		int last = TOC_TRACK(toc.last);
		for (tn=first; tn <= last; tn++ ) {
			if (disc_type == 1) tn = last;
			type = TOC_CTRL(toc.entry[tn-1]);
			if (disc_type == 2) {
				strcpy(dst_file,"\0"); 
				snprintf(dst_file,MAX_FN_LEN,"%s/track%02d.%s", dst_folder, tn, (type == 4 ? "iso" : "raw"));
			}
			
			start = TOC_LBA(toc.entry[tn-1]);
			s_end = TOC_LBA((tn == last ? toc.leadout_sector : toc.entry[tn]));
			nsec = s_end - start;
			
			if (disc_type == 1 && type == 4) nsec -= 2 ;
			else if (session==1 && tn != last && type != TOC_CTRL(toc.entry[tn])) nsec -= 150;
			else if (session==0 && type == 4) nsec -= 150;
			
			if (disc_type == 2 && session == 0) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else if (disc_type == 2 && session == 1 && tn != self.lastgdtrack) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Last track\n");
			}
			
			GUI_LabelSetText(self.track_label, riplabel);
			
			if (rip_sec(tn, start, nsec, type, dst_file, disc_type) != CMD_OK) {
				GUI_LabelSetText(self.track_label, " ");
				stoptimer = timer_ms_gettime64 (); // timer
				GUI_ProgressBarSetPosition(self.pbar, 0.0);
				cdrom_spin_down();
				if (disc_type == 1) {
					if(fs_unlink(dst_file) != 0) ds_printf("Error delete file: %s\n" ,dst_file);
				} else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				}
				return ;
			}
			GUI_LabelSetText(self.track_label, " ");
			GUI_ProgressBarSetPosition(self.pbar, 0.0);
		}
	}
	GUI_LabelSetText(self.track_label, " ");
	GUI_WidgetMarkChanged(self.app->body);
	if (disc_type == 2){
		if (gdfiles(dst_folder, dst_file, text) != CMD_OK){
			cdrom_spin_down();
			if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
				ds_printf("Error folder '%s' not found\n" ,dst_folder); 
				return;
			}
			
			dirent_t *dir;
			
			while ((dir = fs_readdir(fd))){
				if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
				strcpy(dst_file,"\0");
				snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
				fs_unlink(dst_file);
			}
			fs_close(fd);
			fs_rmdir(dst_folder);
			return;	
		}
		
		
	}
	GUI_ProgressBarSetPosition(self.pbar, 0.0);
	cdrom_spin_down();
	stoptimer = timer_ms_gettime64 (); // timer
	riptime = stoptimer - starttimer;
	int ripmin = riptime / 60000 ;
	int ripsec = riptime % 60 ;
	ds_printf("DS_OK: End ripping. Save at %d:%d\n",ripmin,ripsec);
}
コード例 #22
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_EnableResultPage(int result, const char* fileName)
{
	ScreenFadeOut();
	thd_sleep(200);
	GUI_CardStackShowIndex(self.pages, 3);
	ScreenFadeIn();
	
	char title[32];
	char msg[64];	// TODO: Check overflow
	memset(title, 0, sizeof(title));
	memset(msg, 0, sizeof(msg));
	switch(self.m_CurrentOperation)
	{
		case eWriting:
			if (result == eSuccess)
			{
				sprintf(title, "Done");
				sprintf(msg, "Writing successful");
			}
			else
			{
				sprintf(title, "Error");
				sprintf(msg, "Writing fail. Status code: %d", result);
			}
		break;

		case eReading:
			if (result == eSuccess)
			{
				sprintf(title, "Done");
				sprintf(msg, "Reading successful. File stored at file %s", fileName);
			}
			else
			{
				sprintf(title, "Error");
				sprintf(msg, "Reading fail. Status code: %d", result);
			}
		break;

		case eCompare:
			if (result == eSuccess)
			{
				sprintf(title, "Done");
				sprintf(msg, "Comare successful. Flash data match");
			}
			else if (result == eDataMissmatch)
			{
				sprintf(title, "Done");
				sprintf(msg, "Comare successful. Flash data missmatch");
			}
			else
			{
				sprintf(title, "Error");
				sprintf(msg, "Comaring fail. Status code: %d", result);
			}
		break;

		case eNone:
		case eErasing:
		break;
	};

	GUI_LabelSetText(BiosFlasher_GetWidget("result_title_text"), title);
	GUI_LabelSetText(BiosFlasher_GetWidget("result_desc_text"), msg);
}