Esempio n. 1
0
static int Playlist(vlc_object_t *obj, char const *cmd,
                    vlc_value_t oldval, vlc_value_t newval, void *p_data)
{
  intf_thread_t *intf = (intf_thread_t*)obj;
  intf_sys_t *sys = intf->p_sys;

  playlist_t *playlist = sys->playlist;
  input_thread_t * input = playlist_CurrentInput(playlist);
  int state;

  if(input) {
    state = var_GetInteger(input, "state");
    vlc_object_release(input);
  } else {
    return VLC_EGENERIC;
  }

  if(strcmp(cmd, "pause") == 0) {
    msg_Info(intf, "Pause");    
    if(state == PLAYING_S)
      playlist_Pause(sys->playlist);
  } else if(strcmp(cmd, "play") == 0) {
    msg_Info(intf, "Play");
    if(state != PLAYING_S)
      playlist_Play(sys->playlist);
  }
}
Esempio n. 2
0
/**
 * When there are one or more pending corks, playback should be paused.
 * This is used for audio policy.
 * \warning Always add and remove a cork with var_IncInteger() and var_DecInteger().
 * var_Get() and var_Set() are prone to race conditions.
 */
static int CorksCallback( vlc_object_t *obj, char const *var,
                          vlc_value_t old, vlc_value_t cur, void *dummy )
{
    playlist_t *pl = (playlist_t *)obj;

    msg_Dbg( obj, "corks count: %"PRId64" -> %"PRId64, old.i_int, cur.i_int );
    if( !old.i_int == !cur.i_int )
        return VLC_SUCCESS; /* nothing to do */

    if( cur.i_int )
    {
        if( var_InheritBool( obj, "playlist-cork" ) )
        {
            msg_Dbg( obj, "corked" );
            playlist_Pause( pl );
        }
        else
            msg_Dbg( obj, "not corked" );
    }
    else
        msg_Dbg( obj, "uncorked" );

    (void) var; (void) dummy;
    return VLC_SUCCESS;
}
Esempio n. 3
0
void CmdPause::execute()
{
    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
    if( pPlaylist == NULL )
    {
        return;
    }

    playlist_Pause( pPlaylist );
}
Esempio n. 4
0
static void Run(intf_thread_t *intf)
{
  intf_sys_t *sys = intf->p_sys;
  int fd;

  int canc = vlc_savecancel();

  RegisterCallbacks(intf);

  while(1) {
    msg_Info(intf, "Creating IRC connection...");

    fd = net_ConnectTCP(VLC_OBJECT(intf), sys->server, 6667);

    if(fd == -1) {
      msg_Err(intf, "Error connecting to server");
      return;
    }

    msg_Info(intf, "Connected to server");

    /* initialize context */
    sys->fd = fd;
    sys->line_loc = 0;

    SendBufferInit(intf);

    SendBufferAppend(intf, "NICK ");
    SendBufferAppend(intf, sys->nick);
    SendBufferAppend(intf, "\r\n");

    SendBufferAppend(intf, "USER ");
    SendBufferAppend(intf, sys->nick);
    SendBufferAppend(intf, " 8 * vlc\r\n");

    sys->playlist = pl_Get(intf);

    #ifdef STOP_HACK
    playlist_Pause(sys->playlist);
    input_thread_t * input = playlist_CurrentInput(sys->playlist);
    var_SetFloat(input, "position", 0.0);
    #endif

    EventLoop(fd, intf);

    free(sys->send_buffer->buffer);

    sleep(30);
  }

  free(sys);

  vlc_restorecancel(canc);
}
Esempio n. 5
0
static void ProcessCommand(intf_thread_t *p_intf, const char *p_string) {
    intf_sys_t *p_sys = p_intf->p_sys;
    playlist_t *p_playlist = p_sys->p_playlist;
    char *p_line = strdup(p_string);
    int i_argc;
    char** p_argv = NULL;

    i_argc = ParseLineCommand(p_line, &p_argv);
    if (i_argc == 0 || !p_argv)
        goto msg;
    if (i_argc == 1) {
        if (!strcmp(p_argv[0], "help")) {
            Notify(p_intf, "woshenmedoubuzhidao\n");
        }
        else if (!strcmp(p_argv[0], "play")) {
            playlist_Play(p_playlist);
        }
        else if (!strcmp(p_argv[0], "pause")) {
            playlist_Pause(p_playlist);
        }
        else if (!strcmp(p_argv[0], "stop")) {
            playlist_Stop(p_playlist);
        }
        else if (!strcmp(p_argv[0], "close")) {
            playlist_Clear(p_playlist, pl_Unlocked);
        }
        else if (!strcmp(p_argv[0], "ff")) {
        }
        else if (!strcmp(p_argv[0], "fb")) {
        }
        else if (!strcmp(p_argv[0], "quit")) {
            net_Close(p_sys->i_socket);
            p_sys->i_socket = -1;
        }
        else if (!strcmp(p_argv[0], "shutdown")) {

        }
        else
            goto msg;
    }
    else if (i_argc == 2) {
        if (!strcmp(p_argv[0], "open")) {
            char *path = p_argv[1];
            int len = strlen(path);
            char *uri = malloc(len * 3 + 1);
            if (!uri) {
                Notify(p_intf, "oops\n");
                goto out;
            }
            int i, j;
            for (i = 0, j = 0; i < len; i++) {
                uint8_t ch = path[i];

                if (ch < 32 || ch > 127) {
                    uri[j] = '%';
                    uri[j + 1] = ch >> 4;
                    uri[j + 1] += (uri[j + 1] > 9 ? 0x37 : 0x30);
                    uri[j + 2] = ch & 15;
                    uri[j + 2] += (uri[j + 2] > 9 ? 0x37 : 0x30);
                    j += 3;
                }
                else {
                    uri[j] = path[i];
                    j++;
                }
            }
Esempio n. 6
0
static int vlclua_playlist_pause( lua_State * L )
{
    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
    playlist_Pause( p_playlist );
    return 0;
}
Esempio n. 7
0
static LRESULT HandleCadMessage(intf_thread_t* p_intf, HWND hwnd, WPARAM wParam, LPARAM lParam)
{
	intf_sys_t* const p_sys = p_intf->p_sys;

	switch (lParam)
	{
	case IPC_PLAY:
		{
			playlist_Play(pl_Get(p_intf->p_libvlc));
			return 1;
		}

	case IPC_PLAYPAUSE:
		{
			playlist_t* p_playlist = pl_Get(p_intf->p_libvlc);
			const bool playing = playlist_Status(p_playlist) == PLAYLIST_RUNNING;
			playlist_Control(p_playlist, playing ? PLAYLIST_PAUSE : PLAYLIST_PLAY, pl_Unlocked);
			return 1;
		}

	case IPC_PAUSE:
		{
			playlist_Pause(pl_Get(p_intf->p_libvlc));
			return 1;
		}

	case IPC_STOP:
		{
			playlist_Stop(pl_Get(p_intf->p_libvlc));
			return 1;
		}
			
	case IPC_NEXT:
		{
			playlist_Next(pl_Get(p_intf->p_libvlc));
			return 1;
		}

	case IPC_PREVIOUS:
		{
			playlist_Prev(pl_Get(p_intf->p_libvlc));
			return 1;
		}

	case IPC_SET_VOLUME:
		{
			playlist_VolumeSet(pl_Get(p_intf->p_libvlc), (int)wParam / 100.0f);
			return 1;
		}

	case IPC_GET_VOLUME:
		{
			// VLC can return a volume larger than 100% so we need to cap it to 100 here.
			const float volume = playlist_VolumeGet(pl_Get(p_intf->p_libvlc)) * 100.0f;
			return (LRESULT)min(volume, 100.0f);
		}

	case IPC_GET_DURATION:
		{
			unsigned int duration = 0;
			if (p_sys->p_input)
			{
				input_item_t* const p_item = input_GetItem(p_sys->p_input);
				duration = (unsigned int)(input_item_GetDuration(p_item) / 1000000);
			}
			return duration;
		}

	case IPC_GET_POSITION:
		{
			int pos = 0;
			if (p_sys->p_input)
			{
				pos = (int)(var_GetTime(p_sys->p_input, "time") / CLOCK_FREQ);
			}
			return pos;
		}

	case IPC_SET_POSITION:
		{
			if (p_sys->p_input)
			{
				var_SetTime(p_sys->p_input, "time", (int64_t)wParam * CLOCK_FREQ);
			}
			return 0;
		}

	case IPC_GET_SHUFFLE:
		{
			return (int)var_GetBool(pl_Get(p_intf->p_libvlc), "random");
		}

	case IPC_SET_SHUFFLE:
		{
			return (int)var_SetBool(pl_Get(p_intf->p_libvlc), "random", (bool)wParam);
		}

	case IPC_GET_REPEAT:
		{
			return (int)var_GetBool(pl_Get(p_intf->p_libvlc), "repeat");
		}

	case IPC_SET_REPEAT:
		{
			return (int)var_SetBool(pl_Get(p_intf->p_libvlc), "repeat", (bool)wParam);
		}

	case IPC_SET_RATING:
		{
			// VLC does not support ratings so send back 0.
			PostMessage(p_sys->cad_window, WM_USER, 0, IPC_RATING_CHANGED_NOTIFICATION);
			return 0;
		}

	case IPC_SET_CALLBACK_HWND:
		{
			p_sys->cad_window = (HWND)wParam;
			return 1;
		}

	case IPC_SHOW_WINDOW:
		{
			// TODO.
			return 0;
		}

	case IPC_GET_STATE:
		{
			const int status = playlist_Status(pl_Get(p_intf->p_libvlc));
			return
				status == PLAYLIST_RUNNING ? 1 :
				status == PLAYLIST_PAUSED ? 2 :
				0;
		}

	case IPC_SHUTDOWN_NOTIFICATION:
		{
			p_sys->cad_window = NULL;
			return 1;
		}

	case IPC_CLOSE:
		{
			libvlc_Quit(p_intf->p_libvlc);
			return 1;
		}

	case IPC_GET_CURRENT_TRACK:
		{
			if (!p_sys->p_input) return 0;
			input_item_t* p_item = input_GetItem(p_sys->p_input);

			char buffer[DATA_MAX_LENGTH];
			int buffer_len = 0;

			// If the i sstarts with file://, we assume that it is a local file and detailed
			// metadata is available. Otherwise, we assume it to be a network stream (i.e. radio)
			// with limited info (only a title).
			char* const file = decode_URI(input_item_GetURI(p_item));
			if (strncmp(file, "file://", 7) == 0)
			{
				char* const title = input_item_GetTitleFbName(p_item);
				char* const artist = input_item_GetArtist(p_item);
				char* const album = input_item_GetAlbum(p_item);
				char* const cover = decode_URI(input_item_GetArtworkURL(p_item));
				const unsigned int duration = input_item_GetDuration(p_item) / 1000000U;

				buffer_len = _snprintf(
					buffer, ARRAYSIZE(buffer), "%s\t%s\t%s\t\t\t\t\t%u\t%s\t\t%s\t\t\t\t\t\t\t",
					title ? title : "",
					artist ? artist : "",
					album ? album : "",
					duration,
					file ? &file[8] : "",
					cover ? &cover[8] : "");  // Skip the "file://" part.

				free(title);
				free(artist);
				free(album);
				free(cover);
			}
			else if (char* now_playing = input_item_GetNowPlaying(p_item))
			{
				char* artist = NULL;
				char* title = now_playing;
				char* pos = strstr(now_playing, " - ");
				if (pos)
				{
					pos[0] = '\0';
					artist = title;
					title = pos + 3;	// Skip the " - "
				}

				buffer_len = _snprintf(
					buffer, ARRAYSIZE(buffer), "%s\t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t",
					title ? title : "",
					artist ? artist : "");

				free(now_playing);
			}

			free(file);

			if (buffer_len)
			{
				wchar_t buffer_w[DATA_MAX_LENGTH];
				const int buffer_w_len = MultiByteToWideChar(
					CP_UTF8, 0, buffer, buffer_len + 1, buffer_w, ARRAYSIZE(buffer_w));

				COPYDATASTRUCT cds;
				cds.dwData = IPC_CURRENT_TRACK_NOTIFICATION;
				cds.lpData = &buffer_w;
				cds.cbData = buffer_w_len * sizeof(buffer_w[0]);
				SendMessage(
					p_sys->cad_window, WM_COPYDATA, IPC_CURRENT_TRACK_NOTIFICATION, (LPARAM)&cds);
			}

			return 1;
		}
	}

	return 0;
}