vlc_linux/vlc-3.0.16/modules/stream_out/chromecast/chromecast_communication.cpp
/**
 * @brief Send a message to the Chromecast
 * @param msg the CastMessage to send
 * @return vlc error code
 */
@brief Send a message to the Chromecast
@param msg the CastMessage to send
@return vlc error code
@brief Send a message to the Chromecast @param msg the CastMessage to send @return vlc error code
int ChromecastCommunication::sendMessage( const castchannel::CastMessage &msg )
{
    int i_size = msg.ByteSize();
    uint8_t *p_data = new(std::nothrow) uint8_t[PACKET_HEADER_LEN + i_size];
    if (p_data == NULL)
        return VLC_ENOMEM;
#ifndef NDEBUG
    msg_Dbg( m_module, "sendMessage: %s->%s %s", msg.namespace_().c_str(), msg.destination_id().c_str(), msg.payload_utf8().c_str());
#endif
    SetDWBE(p_data, i_size);
    msg.SerializeWithCachedSizesToArray(p_data + PACKET_HEADER_LEN);
    int i_ret = vlc_tls_Write(m_tls, p_data, PACKET_HEADER_LEN + i_size);
    delete[] p_data;
    if (i_ret == PACKET_HEADER_LEN + i_size)
        return VLC_SUCCESS;
    msg_Warn( m_module, "failed to send message %s (%s)", msg.payload_utf8().c_str(), strerror( errno ) );
    return VLC_EGENERIC;
}
int ChromecastCommunication :: sendMessage ( const castchannel :: CastMessage & msg ) { int i_size = msg . ByteSize ( ) ; uint8_t * p_data = new ( std :: nothrow ) uint8_t [ PACKET_HEADER_LEN + i_size ] ; if ( p_data == NULL ) return VLC_ENOMEM ; #ifndef NDEBUG msg_Dbg ( m_module , " " , msg . namespace_ ( ) . c_str ( ) , msg . destination_id ( ) . c_str ( ) , msg . payload_utf8 ( ) . c_str ( ) ) ; #endif SetDWBE ( p_data , i_size ) ; msg . SerializeWithCachedSizesToArray ( p_data + PACKET_HEADER_LEN ) ; int i_ret = vlc_tls_Write ( m_tls , p_data , PACKET_HEADER_LEN + i_size ) ; delete [ ] p_data ; if ( i_ret == PACKET_HEADER_LEN + i_size ) return VLC_SUCCESS ; msg_Warn ( m_module , " " , msg . payload_utf8 ( ) . c_str ( ) , strerror ( errno ) ) ; return VLC_EGENERIC ; }
@brief Send a message to the Chromecast
 @param msg the CastMessage to send
 @return vlc error code
@brief Send a message to the Chromecast @param msg the CastMessage to send @return vlc error code