예제 #1
0
void intf_sys_t::handleMessages()
{
    unsigned i_received = 0;
    uint8_t p_packet[PACKET_MAX_LEN];
    bool b_pingTimeout = false;

    int i_waitdelay = PING_WAIT_TIME;
    int i_retries = PING_WAIT_RETRIES;

    bool b_msgReceived = false;
    uint32_t i_payloadSize = 0;
    int i_ret = recvPacket(p_stream, b_msgReceived, i_payloadSize, i_sock_fd,
                           p_tls, &i_received, p_packet, &b_pingTimeout,
                           &i_waitdelay, &i_retries);

    int canc = vlc_savecancel();
    // Not cancellation-safe part.

#if defined(_WIN32)
    if ((i_ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_ret == 0))
#else
    if ((i_ret < 0 && errno != EAGAIN) || i_ret == 0)
#endif
    {
        msg_Err(p_stream, "The connection to the Chromecast died (receiving).");
        vlc_mutex_locker locker(&lock);
        setConnectionStatus(CHROMECAST_CONNECTION_DEAD);
        vlc_restorecancel(canc);
        return;
    }

    if (b_pingTimeout)
    {
        msgPing();
        msgReceiverGetStatus();
    }

    if (b_msgReceived)
    {
        castchannel::CastMessage msg;
        msg.ParseFromArray(p_packet + PACKET_HEADER_LEN, i_payloadSize);
        processMessage(msg);
    }

    // Send the answer messages if there is any.
    if (!messagesToSend.empty())
    {
        i_ret = sendMessages();
#if defined(_WIN32)
        if ((i_ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_ret == 0))
#else
        if ((i_ret < 0 && errno != EAGAIN) || i_ret == 0)
#endif
        {
            msg_Err(p_stream, "The connection to the Chromecast died (sending).");
            vlc_mutex_locker locker(&lock);
            setConnectionStatus(CHROMECAST_CONNECTION_DEAD);
        }
    }

    vlc_restorecancel(canc);
}
예제 #2
0
void MessageHandler::dispatch(Connection *cCon, Message *msg) {
	switch (msg->messageType()) {
		case Message::Speex:
			msgSpeex(cCon, static_cast<MessageSpeex *>(msg));
			break;
		case Message::ServerAuthenticate:
			msgServerAuthenticate(cCon, static_cast<MessageServerAuthenticate *>(msg));
			break;
		case Message::ServerReject:
			msgServerReject(cCon, static_cast<MessageServerReject *>(msg));
			break;
		case Message::ServerSync:
			msgServerSync(cCon, static_cast<MessageServerSync *>(msg));
			break;
		case Message::ServerJoin:
			msgServerJoin(cCon, static_cast<MessageServerJoin *>(msg));
			break;
		case Message::ServerLeave:
			msgServerLeave(cCon, static_cast<MessageServerLeave *>(msg));
			break;
		case Message::ServerBanList:
			msgServerBanList(cCon, static_cast<MessageServerBanList *>(msg));
			break;
		case Message::PlayerMute:
			msgPlayerMute(cCon, static_cast<MessagePlayerMute *>(msg));
			break;
		case Message::PlayerDeaf:
			msgPlayerDeaf(cCon, static_cast<MessagePlayerDeaf *>(msg));
			break;
		case Message::PlayerSelfMuteDeaf:
			msgPlayerSelfMuteDeaf(cCon, static_cast<MessagePlayerSelfMuteDeaf *>(msg));
			break;
		case Message::PlayerKick:
			msgPlayerKick(cCon, static_cast<MessagePlayerKick *>(msg));
			break;
		case Message::PlayerBan:
			msgPlayerBan(cCon, static_cast<MessagePlayerBan *>(msg));
			break;
		case Message::PlayerMove:
			msgPlayerMove(cCon, static_cast<MessagePlayerMove *>(msg));
			break;
		case Message::PlayerRename:
			msgPlayerRename(cCon, static_cast<MessagePlayerRename *>(msg));
			break;
		case Message::ChannelAdd:
			msgChannelAdd(cCon, static_cast<MessageChannelAdd *>(msg));
			break;
		case Message::ChannelRemove:
			msgChannelRemove(cCon, static_cast<MessageChannelRemove *>(msg));
			break;
		case Message::ChannelMove:
			msgChannelMove(cCon, static_cast<MessageChannelMove *>(msg));
			break;
		case Message::ChannelLink:
			msgChannelLink(cCon, static_cast<MessageChannelLink *>(msg));
			break;
		case Message::ChannelRename:
			msgChannelRename(cCon, static_cast<MessageChannelRename *>(msg));
			break;
		case Message::ChannelDescUpdate:
			msgChannelDescUpdate(cCon, static_cast<MessageChannelDescUpdate *>(msg));
			break;
		case Message::TextMessage:
			msgTextMessage(cCon, static_cast<MessageTextMessage *>(msg));
			break;
		case Message::PermissionDenied:
			msgPermissionDenied(cCon, static_cast<MessagePermissionDenied *>(msg));
			break;
		case Message::EditACL:
			msgEditACL(cCon, static_cast<MessageEditACL *>(msg));
			break;
		case Message::QueryUsers:
			msgQueryUsers(cCon, static_cast<MessageQueryUsers *>(msg));
			break;
		case Message::Ping:
			msgPing(cCon, static_cast<MessagePing *>(msg));
			break;
		case Message::PingStats:
			msgPingStats(cCon, static_cast<MessagePingStats *>(msg));
			break;
		case Message::PlayerTexture:
			msgTexture(cCon, static_cast<MessageTexture *>(msg));
			break;
		case Message::CryptSetup:
			msgCryptSetup(cCon, static_cast<MessageCryptSetup *>(msg));
			break;
		case Message::CryptSync:
			msgCryptSync(cCon, static_cast<MessageCryptSync *>(msg));
			break;
		case Message::ContextAction:
			msgContextAction(cCon, static_cast<MessageContextAction *>(msg));
			break;
		case Message::ContextAddAction:
			msgContextAddAction(cCon, static_cast<MessageContextAddAction *>(msg));
			break;
		default:
			qFatal("MessageHandler called with unknown message type %d", msg->messageType());
	}
}
예제 #3
0
파일: cast.cpp 프로젝트: Adatan/vlc
/*****************************************************************************
 * Chromecast thread
 *****************************************************************************/
static void* chromecastThread(void* p_data)
{
    int canc = vlc_savecancel();
    // Not cancellation-safe part.
    sout_stream_t* p_stream = (sout_stream_t*)p_data;
    sout_stream_sys_t* p_sys = p_stream->p_sys;

    unsigned i_received = 0;
    char p_packet[PACKET_MAX_LEN];
    bool b_pingTimeout = false;

    int i_waitdelay = PING_WAIT_TIME;
    int i_retries = PING_WAIT_RETRIES;

    msgAuth(p_stream);
    sendMessages(p_stream);
    vlc_restorecancel(canc);

    while (1)
    {
        bool b_msgReceived = false;
        uint32_t i_payloadSize = 0;
        int i_ret = recvPacket(p_stream, b_msgReceived, i_payloadSize, p_sys->i_sock_fd,
                               p_sys->p_tls, &i_received, p_packet, &b_pingTimeout,
                               &i_waitdelay, &i_retries);

        canc = vlc_savecancel();
        // Not cancellation-safe part.

#if defined(_WIN32)
        if ((i_ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_ret == 0))
#else
        if ((i_ret < 0 && errno != EAGAIN) || i_ret == 0)
#endif
        {
            msg_Err(p_stream, "The connection to the Chromecast died.");
            vlc_mutex_locker locker(&p_sys->lock);
            p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
            atomic_store(&p_sys->ab_error, true);
            break;
        }

        if (b_pingTimeout)
        {
            msgPing(p_stream);
            msgStatus(p_stream);
        }

        if (b_msgReceived)
        {
            castchannel::CastMessage msg;
            msg.ParseFromArray(p_packet + PACKET_HEADER_LEN, i_payloadSize);
            processMessage(p_stream, msg);
        }

        // Send the answer messages if there is any.
        if (!p_sys->messagesToSend.empty())
        {
            i_ret = sendMessages(p_stream);
#if defined(_WIN32)
            if ((i_ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_ret == 0))
#else
            if ((i_ret < 0 && errno != EAGAIN) || i_ret == 0)
#endif
            {
                msg_Err(p_stream, "The connection to the Chromecast died.");
                vlc_mutex_locker locker(&p_sys->lock);
                p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
            }
        }

        vlc_mutex_lock(&p_sys->lock);
        if ( p_sys->i_status == CHROMECAST_CONNECTION_DEAD )
        {
            atomic_store(&p_sys->ab_error, true);
            vlc_mutex_unlock(&p_sys->lock);
            break;
        }
        vlc_mutex_unlock(&p_sys->lock);

        vlc_restorecancel(canc);
    }

    return NULL;
}