Пример #1
0
void inputloop(void *arg) {
	sleep(1);
	static struct termios oldt, newt;
	tcgetattr( STDIN_FILENO, &oldt);
	newt = oldt;
	newt.c_lflag &= ~(ICANON);
	tcsetattr( STDIN_FILENO, TCSANOW, &newt);
	int last_playlist = -1;
	struct tunerstate tunerstate;
	while(1) {
		tuner_getstate( g_tuner, &tunerstate );
		if (tunerstate.music_playlist_index != last_playlist) {
			if (last_playlist != -1) {
				track_ended(0);
			}
			last_playlist = tunerstate.music_playlist_index;
			if (last_playlist != -1) {
				start_playlist (tunerstate.music_playlist_uri);
			}
		}
		peek_input();
		usleep(100000);
	}
	return NULL;
}
Пример #2
0
void _hardware_event(int event) {
	switch(event) {
		case HE_FREQ_UP: tuner_tune_by(g_tuner, 10); tuner_debug(); break;
		case HE_FREQ_DOWN: tuner_tune_by(g_tuner, -10); tuner_debug(); break;
		case HE_CHANNEL1: tuner_goto(g_tuner, 0); tuner_debug(); break;
		case HE_CHANNEL2: tuner_goto(g_tuner, 1); tuner_debug(); break;
		case HE_CHANNEL3: tuner_goto(g_tuner, 2); tuner_debug(); break;
		case HE_CHANNEL4: tuner_goto(g_tuner, 3); tuner_debug(); break;
		case HE_CHANNEL5: tuner_goto(g_tuner, 4); tuner_debug(); break;
		case HE_PLAY_PAUSE:
			if (g_is_playing) {
				printf("Pause playback\n");
				sp_session_player_play(g_sess, 0);
				g_is_playing = 0;
			} else {
				printf("Resume playback\n");
				sp_session_player_play(g_sess, 1);
				g_is_playing = 1;
			}
			notify_main_thread(g_sess);
			break;
		case HE_SKIP_NEXT:
			hardware_banner("Skip", 100);
			track_ended(1);
			notify_main_thread(g_sess);
			break;
	}
}
Пример #3
0
int main(int argc, char **argv)
{
	sp_session *sp;
	sp_error err;
	int next_timeout = 0;
	const char *username = NULL;
	const char *password = NULL;
	int opt;

	while ((opt = getopt(argc, argv, "u:p:l:d")) != EOF) {
		switch (opt) {
		case 'u':
			username = optarg;
			break;

		case 'p':
			password = optarg;
			break;

		case 'l':
			g_listname = optarg;
			break;

		case 'd':
			g_remove_tracks = 1;
			break;

		default:
			exit(1);
		}
	}

	if (!username || !password || !g_listname) {
		usage(basename(argv[0]));
		exit(1);
	}

	audio_init(&g_audiofifo);

	/* Create session */
	spconfig.application_key_size = g_appkey_size;

	err = sp_session_create(&spconfig, &sp);

	if (SP_ERROR_OK != err) {
		fprintf(stderr, "Unable to create session: %s\n",
			sp_error_message(err));
		exit(1);
	}

	g_sess = sp;

	pthread_mutex_init(&g_notify_mutex, NULL);
	pthread_cond_init(&g_notify_cond, NULL);

	sp_session_login(sp, username, password, 0, NULL);
	pthread_mutex_lock(&g_notify_mutex);

	for (;;) {
		if (next_timeout == 0) {
			while(!g_notify_do)
				pthread_cond_wait(&g_notify_cond, &g_notify_mutex);
		} else {
			struct timespec ts;

#if _POSIX_TIMERS > 0
			clock_gettime(CLOCK_REALTIME, &ts);
#else
			struct timeval tv;
			gettimeofday(&tv, NULL);
			TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif
			ts.tv_sec += next_timeout / 1000;
			ts.tv_nsec += (next_timeout % 1000) * 1000000;

			pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		}

		g_notify_do = 0;
		pthread_mutex_unlock(&g_notify_mutex);

		if (g_playback_done) {
			track_ended();
			g_playback_done = 0;
		}

		do {
			sp_session_process_events(sp, &next_timeout);
		} while (next_timeout == 0);

		pthread_mutex_lock(&g_notify_mutex);
	}

	return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
	sp_session *sp;
	sp_error err;
	int next_timeout = 0;
	const char *username = NULL;
	const char *password = NULL;
	const char *serialdevice = NULL;
	int opt;

	mtrace();

	while ((opt = getopt(argc, argv, "u:p:s:")) != EOF) {
		switch (opt) {
		case 'u':
			username = optarg;
			break;

		case 'p':
			password = optarg;
			break;

		case 's':
			serialdevice = optarg;
			break;

		default:
			exit(1);
		}
	}

	if (!username || !password) {
		usage(basename(argv[0]));
		exit(1);
	}

	srand(time(NULL));

	audio_fifo_reset(&g_musicfifo);
	audio_fifo_reset(&g_gaplessfifo);
	audio_fifo_reset(&g_staticfifo1);
	audio_fifo_reset(&g_staticfifo2);
	audio_fifo_reset(&g_audiofifo);
	
	printf("music fifo: %X\n", &g_musicfifo);
	printf("gapless fifo: %X\n", &g_gaplessfifo);
	printf("static1 fifo: %X\n", &g_staticfifo1);
	printf("static2 fifo: %X\n", &g_staticfifo2);
	printf("audio fifo: %X\n", &g_audiofifo);

	hardware_start(serialdevice);

	hardware_banner("welcome.", 200);
	hardware_set_callback(_hardware_event);

	g_static1 = static_init(BROWN_NOISE, "static1.raw");
	g_static2 = static_init(PINK_NOISE, "static2.raw");
	g_static3 = static_init(WHITE_NOISE, "static3.raw");

	g_tuner = tuner_init();
	tuner_addchannel(g_tuner, 130 + rand()%100, "Channel 1", "spotify:user:possan:playlist:4g17smZvFZqg4dN74XMBYH");
	tuner_addchannel(g_tuner, 410 + rand()%100, "Channel 2", "spotify:user:possan:playlist:2BBVnBjG4Cynww1mnjfV0v");
	tuner_addchannel(g_tuner, 700 + rand()%100, "Channel 3", "spotify:user:possan:playlist:72weZVptgKfYFyzafxBdO5");
	tuner_goto(g_tuner, rand() % tuner_numchannels(g_tuner));
	tuner_tune_by(g_tuner, -70 + rand()%150);

	printf("Start loop...\n");

	spconfig.application_key_size = g_appkey_size;

	audio_init(&g_audiofifo);
	// audio_init(&g_gaplessfifo);

	err = sp_session_create(&spconfig, &sp);

	if (SP_ERROR_OK != err) {
		fprintf(stderr, "Unable to create session: %s\n", sp_error_message(err));
		exit(1);
	}

	g_sess = sp;

	pthread_mutex_init(&g_notify_mutex, NULL);
	pthread_cond_init(&g_notify_cond, NULL);

	sp_session_login(sp, username, password, 0, NULL);
	pthread_mutex_lock(&g_notify_mutex);

	static pthread_t id;
	pthread_create(&id, NULL, inputloop, NULL);

	static pthread_t id2;
	pthread_create(&id2, NULL, gaplessloop, NULL);

	static pthread_t id3;
	pthread_create(&id3, NULL, static1loop, NULL);

	static pthread_t id4;
	pthread_create(&id4, NULL, static2loop, NULL);

	static pthread_t id5;
	pthread_create(&id5, NULL, static3loop, NULL);

	for (;;) {
		// printf("In loop\n");
		if (next_timeout == 0) {
			while(!g_notify_do) {
				pthread_cond_wait(&g_notify_cond, &g_notify_mutex);
			}
		} else {
			struct timespec ts;

#if _POSIX_TIMERS > 0
			clock_gettime(CLOCK_REALTIME, &ts);
#else
			struct timeval tv;
			gettimeofday(&tv, NULL);
			TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif
			ts.tv_sec += next_timeout / 1000;
			ts.tv_nsec += (next_timeout % 1000) * 1000000;
			pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		}

		g_notify_do = 0;
		pthread_mutex_unlock(&g_notify_mutex);

		if (g_playback_done) {
			track_ended(1);
			g_playback_done = 0;
		}

		do {
			sp_session_process_events(sp, &next_timeout);
		} while (next_timeout == 0);

		pthread_mutex_lock(&g_notify_mutex);
	}

	return 0;
}
Пример #5
0
int main(int argc, char **argv)
{
    init_session_config();
    init_session_callbacks();
    init_playlist_callbacks();
    init_playlist_container_callbacks();

    sp_session *sp;
    sp_error err;
    int next_timeout = 0;
    const char *username = NULL;
    const char *password = NULL;
    int opt;

    while ((opt = getopt(argc, argv, "u:p:l:d")) != EOF) {
        switch (opt) {
        case 'u':
            username = optarg;
            break;

        case 'p':
            password = optarg;
            break;

        case 'l':
            g_listname = optarg;
            break;

        case 'd':
            g_remove_tracks = 1;
            break;

        default:
            exit(1);
        }
    }

    if (!username || !password || !g_listname) {
        usage(argv[0]);
        exit(1);
    }

    audio_open();

    err = sp_session_create(&spconfig, &sp);

    if (SP_ERROR_OK != err) {
        fprintf(stderr, "Unable to create session: %s\n",
            sp_error_message(err));
        exit(1);
    }

    g_sess = sp;

    g_notify_mutex = SDL_CreateMutex();
    g_notify_cond = SDL_CreateCond();


    sp_playlistcontainer_add_callbacks(
        sp_session_playlistcontainer(g_sess),
        &pc_callbacks,
        NULL);

    sp_session_login(sp, username, password);
    SDL_mutexP(g_notify_mutex);

    for (;;) {
        if (next_timeout == 0) {
            while(!g_notify_do && !g_playback_done)
                SDL_CondWait(g_notify_cond, g_notify_mutex);
        } else {
            SDL_CondWaitTimeout(g_notify_cond, g_notify_mutex, next_timeout);
        }

        g_notify_do = 0;
        SDL_mutexV(g_notify_mutex);

        if (g_playback_done) {
            track_ended();
            g_playback_done = 0;
        }

        do {
            sp_session_process_events(sp, &next_timeout);
        } while (next_timeout == 0);

        SDL_mutexP(g_notify_mutex);
    }

    return 0;
}
Пример #6
0
JNIEXPORT int JNICALL Java_jahspotify_impl_JahSpotifyImpl_initialize ( JNIEnv *env, jobject obj, jstring username, jstring password )
{
    sp_session *sp;
    sp_error err;
    uint8_t *nativePassword = NULL;
    uint8_t *nativeUsername = NULL;
    int next_timeout = 0;

    if ( !username || !password )
    {
        fprintf ( stderr, "Username or password not specified\n" );
        return 1;
    }

    /* Create session */
    spconfig.application_key_size = g_appkey_size;
    err = sp_session_create ( &spconfig, &sp );

    if ( SP_ERROR_OK != err )
    {
        fprintf ( stderr, "Unable to create session: %s\n",sp_error_message ( err ) );
        return 1;
    }

    fprintf ( stderr, "Session created %x\n",(int)sp);

    nativeUsername = ( uint8_t * ) ( *env )->GetStringUTFChars ( env, username, NULL );
    nativePassword = ( uint8_t * ) ( *env )->GetStringUTFChars ( env, password, NULL );

    g_sess = sp;

    pthread_mutex_init ( &g_notify_mutex, NULL );
    pthread_cond_init ( &g_notify_cond, NULL );

    sp_playlistcontainer_add_callbacks ( sp_session_playlistcontainer ( g_sess ),&pc_callbacks,NULL );

    fprintf ( stderr, "Initiating login: %s\n",nativeUsername );

    sp_session_login ( sp, nativeUsername, nativePassword );
    pthread_mutex_lock ( &g_notify_mutex );


    for ( ;; )
    {
        if ( next_timeout == 0 )
        {
            while ( !g_notify_do && !g_playback_done )
                pthread_cond_wait ( &g_notify_cond, &g_notify_mutex );
        }
        else
        {
            struct timespec ts;

#if _POSIX_TIMERS > 0
            clock_gettime ( CLOCK_REALTIME, &ts );
#else
            struct timeval tv;
            gettimeofday ( &tv, NULL );
            TIMEVAL_TO_TIMESPEC ( &tv, &ts );
#endif
            ts.tv_sec += next_timeout / 1000;
            ts.tv_nsec += ( next_timeout % 1000 ) * 1000000;

            pthread_cond_timedwait ( &g_notify_cond, &g_notify_mutex, &ts );
        }

        g_notify_do = 0;
        pthread_mutex_unlock ( &g_notify_mutex );

        if ( g_playback_done )
        {
            track_ended();
            g_playback_done = 0;
        }

        sp_connectionstate conn_state = sp_session_connectionstate(sp);
        switch (conn_state)
        {
        case SP_CONNECTION_STATE_UNDEFINED:
        case SP_CONNECTION_STATE_LOGGED_OUT:
        case SP_CONNECTION_STATE_LOGGED_IN:
            break;
        case SP_CONNECTION_STATE_DISCONNECTED:
            fprintf ( stderr, "Disconnected!\n");
            break;
        }


        do
        {
            sp_session_process_events ( sp, &next_timeout );
        }
        while ( next_timeout == 0 );

        pthread_mutex_lock ( &g_notify_mutex );
    }

    // FIXME: Release the username/password allocated?

    return 0;

}
Пример #7
0
	int main(int argc, char **argv)
	{
		//extern const char g_appkey[];
		extern const uint8_t g_appkey[];
		extern const size_t g_appkey_size;
		sp_session_config spconfig;

		memset(&spconfig, 0, sizeof(spconfig));
		spconfig.api_version = SPOTIFY_API_VERSION;

		spconfig.cache_location = "tmp";
		spconfig.settings_location = "tmp";

		spconfig.application_key = g_appkey;
		spconfig.application_key_size = g_appkey_size;

		spconfig.user_agent = "jukebewkx";

		//spconfig.callbacks = 0;
		spconfig.callbacks = &session_callbacks;

		spconfig.compress_playlists = 0;

		sp_session *sp;
		sp_error err;
		int next_timeout = 0;
		const char *username = NULL;
		const char *password = NULL;
		int opt;

		while ((opt = getopt(argc, argv, "u:p:l:d")) != EOF) {
			switch (opt) {
			case 'u':
				username = optarg;
				break;

			case 'p':
				password = optarg;
				break;

			case 'l':
				g_listname = optarg;
				break;

			case 'd':
				g_remove_tracks = 1;
				break;

			default:
				exit(1);
			}
		}

		if (!username || !password || !g_listname) {
			usage(argv[0]);
			exit(1);
		}

		//audio_init(&g_audiofifo);

		/* Create session */
		spconfig.application_key_size = g_appkey_size;

		pthread_mutex_init(&g_notify_mutex, NULL);
		pthread_cond_init(&g_notify_cond, NULL);

		for (int i = 0; i < 322; i++)
		{
			char penis = g_appkey[i];
		}

		err = sp_session_create(&spconfig, &sp);

		if (SP_ERROR_OK != err) {
			fprintf(stderr, "Unable to create session: %s\n",
				sp_error_message(err));
			exit(1);
		}

		g_sess = sp;


		sp_session_login(sp, username, password, 0, NULL);
		pthread_mutex_lock(&g_notify_mutex);

		for (;;) {
			if (next_timeout == 0) {
				while(!g_notify_do)
					pthread_cond_wait(&g_notify_cond, &g_notify_mutex);
			} else {
				struct timespec ts;

	#if _POSIX_TIMERS > 0
				clock_gettime(CLOCK_REALTIME, &ts);
	#else
				struct timeval tv;
				gettimeofday(&tv, NULL);
				TIMEVAL_TO_TIMESPEC(&tv, &ts);
	#endif
				ts.tv_sec += next_timeout / 1000;
				ts.tv_nsec += (next_timeout % 1000) * 1000000;

				pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
			}

			g_notify_do = 0;
			pthread_mutex_unlock(&g_notify_mutex);

			if (g_playback_done) {
				track_ended();
				g_playback_done = 0;
			}

			do {
				sp_session_process_events(sp, &next_timeout);
			} while (next_timeout == 0);

			pthread_mutex_lock(&g_notify_mutex);
		}

		return 0;
	}