Mercurial > mplayer.hg
changeset 9863:4c6c6c361f24
It should now be endian aware. Untested as i only have le box :(
Would be cool if someone with a be,le network could test.
author | albeu |
---|---|
date | Sun, 06 Apr 2003 18:16:11 +0000 |
parents | d172681d07eb |
children | b65bcfaedbe5 |
files | TOOLS/netstream/netstream.c libmpdemux/netstream.h libmpdemux/stream_netstream.c |
diffstat | 3 files changed, 24 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/TOOLS/netstream/netstream.c Sun Apr 06 17:18:26 2003 +0000 +++ b/TOOLS/netstream/netstream.c Sun Apr 06 18:16:11 2003 +0000 @@ -36,6 +36,7 @@ #include <libmpdemux/stream.h> #include <mp_msg.h> +#include <bswap.h> /// Netstream packets def and some helpers #include <libmpdemux/netstream.h> @@ -79,6 +80,7 @@ ret.sector_size = cl->stream->sector_size; ret.start_pos = cl->stream->start_pos; ret.end_pos = cl->stream->end_pos; + net_stream_opened_2_me(&ret); if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t))) return 0; @@ -102,8 +104,8 @@ pack = malloc(max_len + sizeof(mp_net_stream_packet_t)); pack->cmd = NET_STREAM_OK; r = stream_read(cl->stream,pack->data,max_len); - pack->len = r + sizeof(mp_net_stream_packet_t); - if(!net_write(cl->fd,(char*)pack,pack->len)) { + pack->len = le2me_16(r + sizeof(mp_net_stream_packet_t)); + if(!net_write(cl->fd,(char*)pack,le2me_16(pack->len))) { free(pack); return 0; } @@ -173,13 +175,13 @@ mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n"); return 0; } - return net_stream_fill_buffer(cl,*((uint16_t*)pack->data)); + return net_stream_fill_buffer(cl,le2me_16(*((uint16_t*)pack->data))); case NET_STREAM_SEEK: if(pack->len != sizeof(mp_net_stream_packet_t) + 8) { mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n"); return 0; } - return net_stream_seek(cl,*((uint64_t*)pack->data)); + return net_stream_seek(cl,le2me_64(*((uint64_t*)pack->data))); case NET_STREAM_RESET: return net_stream_reset(cl); case NET_STREAM_CLOSE:
--- a/libmpdemux/netstream.h Sun Apr 06 17:18:26 2003 +0000 +++ b/libmpdemux/netstream.h Sun Apr 06 18:16:11 2003 +0000 @@ -3,6 +3,8 @@ * Common stuff for netstream * Packets and so on are defined here along with a few helpers * wich are used by both the client and the server + * + * Data is always low endian */ typedef struct mp_net_stream_packet_st { @@ -64,7 +66,8 @@ free(pack); return NULL; } - + pack->len = le2me_16(pack->len); + if(pack->len < sizeof(mp_net_stream_packet_t)) { mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid packet (too small: %d)\n",pack->len); free(pack); @@ -113,6 +116,7 @@ pack->cmd = cmd; // printf("Write packet %d %d (%p) %d\n",fd,cmd,data,len); + pack->len = le2me_16(pack->len); if(net_write(fd,(char*)pack,pack->len)) { free(pack); return 1; @@ -120,3 +124,11 @@ free(pack); return 0; } + +static void net_stream_opened_2_me(mp_net_stream_opened_t* o) { + o->file_format = le2me_32(o->file_format); + o->flags = le2me_32(o->flags); + o->sector_size = le2me_32(o->sector_size); + o->start_pos = le2me_64(o->start_pos); + o->end_pos = le2me_64(o->end_pos); +}
--- a/libmpdemux/stream_netstream.c Sun Apr 06 17:18:26 2003 +0000 +++ b/libmpdemux/stream_netstream.c Sun Apr 06 18:16:11 2003 +0000 @@ -57,6 +57,7 @@ #include "help_mp.h" #include "../m_option.h" #include "../m_struct.h" +#include "../bswap.h" #include "netstream.h" @@ -158,7 +159,7 @@ } static int fill_buffer(stream_t *s, char* buffer, int max_len){ - uint16_t len = max_len; + uint16_t len = le2me_16(max_len); mp_net_stream_packet_t* pack; pack = send_net_stream_cmd(s,NET_STREAM_FILL_BUFFER,(char*)&len,2); @@ -179,7 +180,7 @@ static int seek(stream_t *s,off_t newpos) { - uint64_t pos = (uint64_t)newpos; + uint64_t pos = le2me_64((uint64_t)newpos); mp_net_stream_packet_t* pack; pack = send_net_stream_cmd(s,NET_STREAM_SEEK,(char*)&pos,8); @@ -259,6 +260,8 @@ } opened = (mp_net_stream_opened_t*)pack->data; + net_stream_opened_2_me(opened); + *file_format = opened->file_format; stream->flags = opened->flags; stream->sector_size = opened->sector_size;