1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

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.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9864 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
albeu 2003-04-06 18:16:11 +00:00
parent 73257ca275
commit 42ce651135
3 changed files with 24 additions and 7 deletions

View File

@ -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 @@ static int net_stream_open(client_t* cl,char* url) {
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 @@ static int net_stream_fill_buffer(client_t* cl,uint16_t max_len) {
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 @@ int handle_client(client_t* cl,mp_net_stream_packet_t* pack) {
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:

View File

@ -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,6 +66,7 @@ static mp_net_stream_packet_t* read_packet(int fd) {
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);
@ -113,6 +116,7 @@ static int write_packet(int fd, uint8_t cmd,char* data,int len) {
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 @@ static int write_packet(int fd, uint8_t cmd,char* data,int len) {
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);
}

View File

@ -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 mp_net_stream_packet_t* send_net_stream_cmd(stream_t *s,uint16_t cmd,char
}
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 fill_buffer(stream_t *s, char* buffer, int max_len){
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 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
}
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;