Exemplo n.º 1
0
PSW systeme(PSW m) {
    if(lastInputTime + 3 < time(NULL)){
        system_io_fake_input();
        DEBUG_PUTS(DEBUG_T_SYSTEM, "FAKE INPUT");
        lastInputTime = time(NULL);
    }
    
    if (m.IN == 0)
        return m;

    DEBUG_PRINTF(DEBUG_T_SHOW_INT, "INTERUPT: %s\n", system_int2str(m.IN));

    switch (m.IN) {
        case INT_INIT:
            return (systeme_init());
        case INT_SEGV:
            system_int_fatal(m.IN);
            break;
        case INT_TRACE:
            system_int_trace(&m);
            break;
        case INT_INST:
            system_int_fatal(m.IN);
            break;
        case INT_SYSC:
            system_int_sysc(&m);
            break;
        case INT_CLOCK:
            system_clock(&m);
            break;
    }
    return m;
}
Exemplo n.º 2
0
static void system_sysc_sleep(PSW* m) {
    DEBUG_PRINTF(DEBUG_T_SYSC, "SYSCALL SLEEP(%d)\n", m->DR[m->RI.i]);
    
    process_current()->state = PROC_STATE_SLEEP;
    process_current()->waketime = time(NULL) + m->DR[m->RI.i];
    ++m->PC;

    system_clock(m); //Change de processus
}
Exemplo n.º 3
0
static int dash_live_worker(const char* file, dash_playlist_t* dash)
{
    int r, type;
    int avcrecord = 0;
    int aacconfig = 0;
    uint32_t timestamp;
    uint32_t s_timestamp = 0;
    uint32_t diff = 0;
    uint64_t clock;

    flv_parser_t* parser = flv_parser_create(dash_live_onflv, dash);

    while (1)
    {
        void* f = flv_reader_create(file);

        clock = system_clock(); // timestamp start from 0
        while ((r = flv_reader_read(f, &type, &timestamp, dash->packet, sizeof(dash->packet))) > 0)
        {
			uint64_t t = system_clock();
			if (clock + timestamp > t && clock + timestamp < t + 3 * 1000)
				system_sleep(clock + timestamp - t);
			else if (clock + timestamp > t + 3 * 1000)
				clock = t - timestamp;

            timestamp += diff;
            s_timestamp = timestamp > s_timestamp ? timestamp : s_timestamp;
            r = flv_parser_input(parser, type, dash->packet, r, timestamp);
            if (0 != r)
            {
                assert(0);
                break; // TODO: handle send failed
            }
        }

        flv_reader_destroy(f);

        diff = s_timestamp + 30;
    }

    flv_parser_destroy(parser);
}
Exemplo n.º 4
0
static void system_sysc_getchar(PSW* m){
    DEBUG_PUTS(DEBUG_T_SYSC, "SYSCALL GETCHAR()");
    
    Process* proc = process_current();
    char c = system_io_getchar(proc);
    
    //Change de processus (en attente de caractère)
    if(proc->state == PROC_STATE_GETCHAR){
        system_clock(m);
        return;
    }
    
    m->DR[m->RI.i] = c;
    ++m->PC;
}
Exemplo n.º 5
0
static void system_sysc_exit(PSW* m) {
    DEBUG_PRINTF(DEBUG_T_SYSC, "SYSCALL EXIT()\n");
    
    Process* process = process_current();
    
    if(process == NULL){
        DEBUG_PUTS(DEBUG_T_SYSTEM, "Pas de processus courant");
        return;
    }
    
    DEBUG_PRINTF(DEBUG_T_SYSTEM, "Suppr. proc %d\n", (int)process->number);
    
    process_kill(process);
    system_clock(m);
}
Exemplo n.º 6
0
int MP4FileSource::Play()
{
	bool sendframe = false;
	if (3 == m_status)
		return 0;

SEND_PACKET:
	if (0 == m_frame.bytes)
	{
		int r = mov_reader_read(m_reader, m_frame.buffer, sizeof(m_frame.buffer), MP4OnRead, &m_frame);
		if (r == 0)
		{
			// 0-EOF
			m_status = 3;
			SendBye();
			return r;
		}
		else if (r < 0)
		{
			// error
			return r;
		}
	}

	m_status = 1;
	uint64_t clock = system_clock();
	for (int i = 0; i < m_count; i++)
	{
		struct media_t* m = &m_media[i];
		if (m->track != m_frame.track)
			continue;

		if (0 == m_clock || m_clock > clock)
			m_clock = clock;
		if (-1 == m_dts)
			m_dts = m_frame.dts;

		if (int64_t(clock - m_clock) + m_dts >= m_frame.dts)
		{
			if (0 == strcmp("H264", m->name))
			{
				// MPEG4 -> H.264 byte stream
				uint8_t* p = m_frame.buffer;
				size_t bytes = m_frame.bytes;
				while (bytes > 0)
				{
					// nalu size -> start code
					assert(bytes > 4);
					uint32_t n = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
					p[0] = 0;
					p[1] = 0;
					p[2] = 0;
					p[3] = 1;
					bytes -= n + 4;
					p += n + 4;
				}

				//printf("[V] pts: %lld, dts: %lld, clock: %llu\n", m_frame.pts, m_frame.dts, clock);
			}
			else if (0 == strcmp("MP4A-LATM", m->name) || 0 == strcmp("MPEG4-GENERIC", m->name))
			{
				// add ADTS header
				//printf("[A] pts: %lld, dts: %lld, clock: %llu\n", m_frame.pts, m_frame.dts, clock);
			}
			else
			{
				assert(0);
			}

			if (-1 == m->dts_first)
				m->dts_first = m_frame.pts;
			m->dts_last = m_frame.pts;
			uint32_t timestamp = m->timestamp + m->dts_last - m->dts_first;
/*
			if (-1 == m->dts)
				m->dts = m_frame.dts;
			m->timestamp += m_frame.dts - m->dts;
			m->dts = m_frame.dts;
*/
			rtp_payload_encode_input(m->packer, m_frame.buffer, m_frame.bytes, (uint32_t)(timestamp * (m->frequency / 1000) /*kHz*/));
			SendRTCP(m, clock);

			m_frame.bytes = 0; // send flag
			sendframe = 1;
			goto SEND_PACKET;
		}

		break;
	}

	return sendframe ? 1 : 0;
}