2006-09-18 13:00:51 +00:00
|
|
|
/*
|
|
|
|
* MMST implementation taken from the xine-mms plugin made by
|
|
|
|
* Major MMS (http://geocities.com/majormms/).
|
|
|
|
* Ported to MPlayer by Abhijeet Phatak <abhijeetphatak@yahoo.com>.
|
|
|
|
*
|
|
|
|
* Information about the MMS protocol can be found at http://get.to/sdp
|
|
|
|
*
|
|
|
|
* copyright (C) 2002 Abhijeet Phatak <abhijeetphatak@yahoo.com>
|
|
|
|
* copyright (C) 2002 the xine project
|
|
|
|
* copyright (C) 2000-2001 major mms
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-09-18 13:00:51 +00:00
|
|
|
*/
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2002-10-23 20:39:49 +00:00
|
|
|
#include <inttypes.h>
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2005-10-31 23:37:41 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
2009-02-01 13:42:27 +00:00
|
|
|
#if HAVE_WINSOCK2_H
|
2008-08-31 13:59:54 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifndef CONFIG_SETLOCALE
|
2008-08-07 10:36:07 +00:00
|
|
|
#undef CONFIG_ICONV
|
2004-06-26 09:55:17 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2003-11-01 14:43:28 +00:00
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
#include "url.h"
|
2006-08-04 17:01:29 +00:00
|
|
|
#include "libmpdemux/asf.h"
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
#include "network.h"
|
2006-08-05 10:30:06 +00:00
|
|
|
#include "tcp.h"
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2007-02-08 17:03:24 +00:00
|
|
|
extern int audio_id;
|
|
|
|
extern int video_id;
|
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
#define BUF_SIZE 102400
|
2004-12-15 19:12:46 +00:00
|
|
|
#define HDR_BUF_SIZE 8192
|
2005-04-16 13:42:50 +00:00
|
|
|
#define MAX_STREAMS 20
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
typedef struct
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
uint8_t buf[BUF_SIZE];
|
|
|
|
int num_bytes;
|
|
|
|
|
|
|
|
} command_t;
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
static int seq_num;
|
|
|
|
static int num_stream_ids;
|
2005-04-16 13:42:50 +00:00
|
|
|
static int stream_ids[MAX_STREAMS];
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
static int get_data (int s, char *buf, size_t count);
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static void put_32 (command_t *cmd, uint32_t value)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
cmd->buf[cmd->num_bytes ] = value % 256;
|
|
|
|
value = value >> 8;
|
|
|
|
cmd->buf[cmd->num_bytes+1] = value % 256 ;
|
|
|
|
value = value >> 8;
|
|
|
|
cmd->buf[cmd->num_bytes+2] = value % 256 ;
|
|
|
|
value = value >> 8;
|
|
|
|
cmd->buf[cmd->num_bytes+3] = value % 256 ;
|
|
|
|
|
|
|
|
cmd->num_bytes += 4;
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static uint32_t get_32 (unsigned char *cmd, int offset)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
ret = cmd[offset] ;
|
|
|
|
ret |= cmd[offset+1]<<8 ;
|
|
|
|
ret |= cmd[offset+2]<<16 ;
|
|
|
|
ret |= cmd[offset+3]<<24 ;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static void send_command (int s, int command, uint32_t switches,
|
2002-05-14 22:31:21 +00:00
|
|
|
uint32_t extra, int length,
|
2009-05-13 02:58:57 +00:00
|
|
|
char *data)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
command_t cmd;
|
|
|
|
int len8;
|
|
|
|
|
2003-10-22 17:26:15 +00:00
|
|
|
len8 = (length + 7) / 8;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
cmd.num_bytes = 0;
|
|
|
|
|
|
|
|
put_32 (&cmd, 0x00000001); /* start sequence */
|
|
|
|
put_32 (&cmd, 0xB00BFACE); /* #-)) */
|
2003-10-22 17:26:15 +00:00
|
|
|
put_32 (&cmd, len8*8 + 32);
|
2002-05-14 22:31:21 +00:00
|
|
|
put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */
|
|
|
|
put_32 (&cmd, len8 + 4);
|
|
|
|
put_32 (&cmd, seq_num);
|
|
|
|
seq_num++;
|
|
|
|
put_32 (&cmd, 0x0); /* unknown */
|
|
|
|
put_32 (&cmd, 0x0);
|
|
|
|
put_32 (&cmd, len8+2);
|
|
|
|
put_32 (&cmd, 0x00030000 | command); /* dir | command */
|
|
|
|
put_32 (&cmd, switches);
|
|
|
|
put_32 (&cmd, extra);
|
|
|
|
|
|
|
|
memcpy (&cmd.buf[48], data, length);
|
2003-10-22 17:26:15 +00:00
|
|
|
if (length & 7)
|
|
|
|
memset(&cmd.buf[48 + length], 0, 8 - (length & 7));
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2003-10-22 17:26:15 +00:00
|
|
|
if (send (s, cmd.buf, len8*8+48, 0) != (len8*8+48)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_WriteError);
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2003-11-01 14:43:28 +00:00
|
|
|
static iconv_t url_conv;
|
2003-11-06 22:34:20 +00:00
|
|
|
#endif
|
2003-11-01 14:43:28 +00:00
|
|
|
|
|
|
|
static void string_utf16(char *dest, char *src, int len) {
|
2003-11-06 22:34:20 +00:00
|
|
|
int i;
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2003-11-01 14:43:28 +00:00
|
|
|
size_t len1, len2;
|
|
|
|
char *ip, *op;
|
|
|
|
|
2003-11-08 00:26:51 +00:00
|
|
|
if (url_conv != (iconv_t)(-1))
|
2003-11-06 22:34:20 +00:00
|
|
|
{
|
2003-11-01 14:43:28 +00:00
|
|
|
memset(dest, 0, 1000);
|
|
|
|
len1 = len; len2 = 1000;
|
|
|
|
ip = src; op = dest;
|
|
|
|
|
|
|
|
iconv(url_conv, &ip, &len1, &op, &len2);
|
2003-11-06 22:34:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#endif
|
2005-04-13 19:21:05 +00:00
|
|
|
if (len > 499) len = 499;
|
2003-11-06 22:34:20 +00:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
dest[i*2] = src[i];
|
|
|
|
dest[i*2+1] = 0;
|
|
|
|
}
|
|
|
|
/* trailing zeroes */
|
|
|
|
dest[i*2] = 0;
|
|
|
|
dest[i*2+1] = 0;
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2003-11-06 22:34:20 +00:00
|
|
|
}
|
2003-11-01 14:43:28 +00:00
|
|
|
#endif
|
2003-11-06 22:34:20 +00:00
|
|
|
}
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static void get_answer (int s)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
char data[BUF_SIZE];
|
|
|
|
int command = 0x1b;
|
|
|
|
|
|
|
|
while (command == 0x1b) {
|
|
|
|
int len;
|
|
|
|
|
2003-05-29 19:36:58 +00:00
|
|
|
len = recv (s, data, BUF_SIZE, 0) ;
|
2002-05-14 22:31:21 +00:00
|
|
|
if (!len) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_EOFAlert);
|
2002-05-14 22:31:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = get_32 (data, 36) & 0xFFFF;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
if (command == 0x1b)
|
2002-05-14 22:31:21 +00:00
|
|
|
send_command (s, 0x1b, 0, 0, 0, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static int get_data (int s, char *buf, size_t count)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
2002-10-29 09:18:53 +00:00
|
|
|
ssize_t len;
|
|
|
|
size_t total = 0;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
while (total < count) {
|
|
|
|
|
2003-05-29 19:36:58 +00:00
|
|
|
len = recv (s, &buf[total], count-total, 0);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2004-06-07 19:23:04 +00:00
|
|
|
if (len<=0) {
|
2002-05-14 22:31:21 +00:00
|
|
|
perror ("read error:");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
total += len;
|
|
|
|
|
|
|
|
if (len != 0) {
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"[%d/%d]", total, count);
|
2002-05-14 22:31:21 +00:00
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static int get_header (int s, uint8_t *header, streaming_ctrl_t *streaming_ctrl)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
unsigned char pre_header[8];
|
2002-10-29 09:18:53 +00:00
|
|
|
int header_len;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
header_len = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (!get_data (s, pre_header, 8)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_PreHeaderReadFailed);
|
2002-05-14 22:31:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (pre_header[4] == 0x02) {
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
int packet_len;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
packet_len = (pre_header[7] << 8 | pre_header[6]) - 8;
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"asf header packet detected, len=%d\n", packet_len);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2004-12-15 19:12:46 +00:00
|
|
|
if (packet_len < 0 || packet_len > HDR_BUF_SIZE - header_len) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_MMST_InvalidHeaderSize);
|
2004-12-15 19:12:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
if (!get_data (s, &header[header_len], packet_len)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_HeaderDataReadFailed);
|
2002-05-14 22:31:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
header_len += packet_len;
|
|
|
|
|
|
|
|
if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) {
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
if( streaming_bufferize( streaming_ctrl, header, header_len )<0 ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"get header packet finished\n");
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2008-05-16 08:43:15 +00:00
|
|
|
return header_len;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
int32_t packet_len;
|
2002-05-14 22:31:21 +00:00
|
|
|
int command;
|
|
|
|
char data[BUF_SIZE];
|
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
if (!get_data (s, (char*)&packet_len, 4)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_packet_lenReadFailed);
|
2002-05-14 22:31:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"command packet detected, len=%d\n", packet_len);
|
2004-12-15 19:12:46 +00:00
|
|
|
|
|
|
|
if (packet_len < 0 || packet_len > BUF_SIZE) {
|
|
|
|
mp_msg(MSGT_NETWORK, MSGL_FATAL,
|
2005-10-31 23:37:41 +00:00
|
|
|
MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize);
|
2004-12-15 19:12:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
if (!get_data (s, data, packet_len)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_CmdDataReadFailed);
|
2002-05-14 22:31:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
command = get_32 (data, 24) & 0xFFFF;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"command: %02x\n", command);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
|
|
|
if (command == 0x1b)
|
2002-05-14 22:31:21 +00:00
|
|
|
send_command (s, 0x1b, 0, 0, 0, data);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"get header packet succ\n");
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static int interp_header (uint8_t *header, int header_len)
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
int i;
|
2002-09-22 02:33:28 +00:00
|
|
|
int packet_length=-1;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* parse header
|
|
|
|
*/
|
|
|
|
|
|
|
|
i = 30;
|
|
|
|
while (i<header_len) {
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
uint64_t guid_1, guid_2, length;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
|
2002-05-14 22:31:21 +00:00
|
|
|
| ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
|
|
|
|
| ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
|
|
|
|
| ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
|
|
|
|
i += 8;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
|
2002-05-14 22:31:21 +00:00
|
|
|
| ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
|
|
|
|
| ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
|
|
|
|
| ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
|
|
|
|
i += 8;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"guid found: %016llx%016llx\n", guid_1, guid_2);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8)
|
2002-05-14 22:31:21 +00:00
|
|
|
| ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24)
|
|
|
|
| ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40)
|
|
|
|
| ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56);
|
|
|
|
|
|
|
|
i += 8;
|
|
|
|
|
2004-04-05 21:31:27 +00:00
|
|
|
if ( (guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22630ULL) ) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_HeaderObject);
|
2004-04-05 21:31:27 +00:00
|
|
|
} else if ((guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22636ULL)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_DataObject);
|
2004-04-05 21:31:27 +00:00
|
|
|
} else if ((guid_1 == 0x6553200cc000e48eULL) && (guid_2 == 0x11cfa9478cabdca1ULL)) {
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
packet_length = get_32(header, i+92-24);
|
|
|
|
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_FileObjectPacketLen,
|
2002-05-14 22:31:21 +00:00
|
|
|
packet_length, get_32(header, i+96-24));
|
|
|
|
|
|
|
|
|
2004-04-05 21:31:27 +00:00
|
|
|
} else if ((guid_1 == 0x6553200cc000e68eULL) && (guid_2 == 0x11cfa9b7b7dc0791ULL)) {
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
int stream_id = header[i+48] | header[i+49] << 8;
|
|
|
|
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_StreamObjectStreamID, stream_id);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2005-04-16 13:42:50 +00:00
|
|
|
if (num_stream_ids < MAX_STREAMS) {
|
2002-05-14 22:31:21 +00:00
|
|
|
stream_ids[num_stream_ids] = stream_id;
|
|
|
|
num_stream_ids++;
|
2005-04-15 23:31:57 +00:00
|
|
|
} else {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_2ManyStreamID);
|
2005-04-15 23:31:57 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
} else {
|
2005-06-03 15:59:24 +00:00
|
|
|
#if 0
|
|
|
|
int b = i;
|
|
|
|
printf ("unknown object (guid: %016llx, %016llx, len: %lld)\n", guid_1, guid_2, length);
|
|
|
|
for (; b < length; b++)
|
|
|
|
{
|
|
|
|
if (isascii(header[b]) || isalpha(header[b]))
|
|
|
|
printf("%c ", header[b]);
|
|
|
|
else
|
|
|
|
printf("%x ", header[b]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#else
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_WARN,MSGTR_MPDEMUX_MMST_UnknownObject);
|
2005-06-03 15:59:24 +00:00
|
|
|
#endif
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"length : %lld\n", length);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
i += length-24;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet_length;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) {
|
2002-05-14 22:31:21 +00:00
|
|
|
unsigned char pre_header[8];
|
|
|
|
char data[BUF_SIZE];
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
if (!get_data (s, pre_header, 8)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_PreHeaderReadFailed);
|
2002-10-23 20:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
// for (i=0; i<8; i++)
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"pre_header[%d] = %02x (%d)\n",
|
2002-10-23 20:39:49 +00:00
|
|
|
// i, pre_header[i], pre_header[i]);
|
|
|
|
|
|
|
|
if (pre_header[4] == 0x04) {
|
|
|
|
|
|
|
|
int packet_len;
|
|
|
|
|
|
|
|
packet_len = (pre_header[7] << 8 | pre_header[6]) - 8;
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"asf media packet detected, len=%d\n", packet_len);
|
2002-10-23 20:39:49 +00:00
|
|
|
|
2004-12-15 19:12:46 +00:00
|
|
|
if (packet_len < 0 || packet_len > BUF_SIZE) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize);
|
2004-12-15 19:12:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
if (!get_data (s, data, packet_len)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_MediaDataReadFailed);
|
2002-10-23 20:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
streaming_bufferize(stream_ctrl, data, padding);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
int32_t packet_len;
|
|
|
|
int command;
|
2002-10-23 20:39:49 +00:00
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
if (!get_data (s, (char*)&packet_len, 4)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_packet_lenReadFailed);
|
2002-10-23 20:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-29 09:18:53 +00:00
|
|
|
packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4;
|
2002-10-23 20:39:49 +00:00
|
|
|
|
2004-12-15 19:12:46 +00:00
|
|
|
if (packet_len < 0 || packet_len > BUF_SIZE) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize);
|
2004-12-15 19:12:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
if (!get_data (s, data, packet_len)) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_CmdDataReadFailed);
|
2002-10-23 20:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b)
|
|
|
|
|| (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) {
|
|
|
|
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_MissingSignature);
|
2002-10-23 20:39:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = get_32 (data, 24) & 0xFFFF;
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command);
|
2002-10-23 20:39:49 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
if (command == 0x1b)
|
2002-10-23 20:39:49 +00:00
|
|
|
send_command (s, 0x1b, 0, 0, 0, data);
|
|
|
|
else if (command == 0x1e) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_PatentedTechnologyJoke);
|
2002-10-23 20:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (command == 0x21 ) {
|
|
|
|
// Looks like it's new in WMS9
|
|
|
|
// Unknown command, but ignoring it seems to work.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (command != 0x05) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_UnknownCmd,command);
|
2002-10-23 20:39:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"get media packet succ\n");
|
2002-10-23 20:39:49 +00:00
|
|
|
|
|
|
|
return 1;
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
|
|
|
|
static int packet_length1;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static int asf_mmst_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl )
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
2002-10-23 20:39:49 +00:00
|
|
|
int len;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
while( stream_ctrl->buffer_size==0 ) {
|
|
|
|
// buffer is empty - fill it!
|
|
|
|
int ret = get_media_packet( fd, packet_length1, stream_ctrl);
|
|
|
|
if( ret<0 ) {
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_GetMediaPacketErr,strerror(errno));
|
2002-10-23 20:39:49 +00:00
|
|
|
return -1;
|
2004-03-28 14:44:49 +00:00
|
|
|
} else if (ret==0) //EOF?
|
|
|
|
return ret;
|
2002-10-23 20:39:49 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos;
|
|
|
|
if(len>size) len=size;
|
2002-05-14 22:31:21 +00:00
|
|
|
memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len );
|
|
|
|
stream_ctrl->buffer_pos += len;
|
|
|
|
if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) {
|
|
|
|
free( stream_ctrl->buffer );
|
|
|
|
stream_ctrl->buffer = NULL;
|
|
|
|
stream_ctrl->buffer_size = 0;
|
|
|
|
stream_ctrl->buffer_pos = 0;
|
|
|
|
}
|
2002-10-23 20:39:49 +00:00
|
|
|
return len;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static int asf_mmst_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl )
|
2002-05-14 22:31:21 +00:00
|
|
|
{
|
|
|
|
return -1;
|
2002-10-29 09:18:53 +00:00
|
|
|
// Shut up gcc warning
|
|
|
|
fd++;
|
|
|
|
pos++;
|
|
|
|
streaming_ctrl=NULL;
|
2002-05-14 22:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int asf_mmst_streaming_start(stream_t *stream)
|
|
|
|
{
|
|
|
|
char str[1024];
|
2003-05-25 18:28:26 +00:00
|
|
|
char data[BUF_SIZE];
|
2004-12-15 19:12:46 +00:00
|
|
|
uint8_t asf_header[HDR_BUF_SIZE];
|
2002-05-14 22:31:21 +00:00
|
|
|
int asf_header_len;
|
|
|
|
int len, i, packet_length;
|
2004-07-02 20:36:50 +00:00
|
|
|
char *path, *unescpath;
|
2002-05-14 22:31:21 +00:00
|
|
|
URL_t *url1 = stream->streaming_ctrl->url;
|
2002-10-29 09:18:53 +00:00
|
|
|
int s = stream->fd;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2002-09-03 01:25:31 +00:00
|
|
|
if( s>0 ) {
|
2003-06-11 16:48:09 +00:00
|
|
|
closesocket( stream->fd );
|
2002-09-03 01:25:31 +00:00
|
|
|
stream->fd = -1;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
/* parse url */
|
|
|
|
path = strchr(url1->file,'/') + 1;
|
|
|
|
|
2004-07-02 20:36:50 +00:00
|
|
|
/* mmst filename are not url_escaped by MS MediaPlayer and are expected as
|
|
|
|
* "plain text" by the server, so need to decode it here
|
|
|
|
*/
|
|
|
|
unescpath=malloc(strlen(path)+1);
|
|
|
|
if (!unescpath) {
|
2005-11-05 00:51:36 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
|
2009-05-13 02:58:57 +00:00
|
|
|
return -1;
|
2004-07-02 20:36:50 +00:00
|
|
|
}
|
|
|
|
url_unescape_string(unescpath,path);
|
|
|
|
path=unescpath;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-07-02 20:36:50 +00:00
|
|
|
|
2004-08-07 23:48:35 +00:00
|
|
|
if( url1->port==0 ) {
|
|
|
|
url1->port=1755;
|
|
|
|
}
|
2003-08-15 19:13:23 +00:00
|
|
|
s = connect2Server( url1->hostname, url1->port, 1);
|
2002-09-03 01:25:31 +00:00
|
|
|
if( s<0 ) {
|
2004-07-02 20:36:50 +00:00
|
|
|
free(path);
|
2002-09-03 01:25:31 +00:00
|
|
|
return s;
|
|
|
|
}
|
2005-10-31 23:37:41 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_Connected);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
seq_num=0;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
/*
|
2009-05-13 02:58:57 +00:00
|
|
|
* Send the initial connect info including player version no. Client GUID (random) and the host address being connected to.
|
|
|
|
* This command is sent at the very start of protocol initiation. It sends local information to the serve
|
|
|
|
* cmd 1 0x01
|
2002-05-14 22:31:21 +00:00
|
|
|
* */
|
|
|
|
|
2003-11-01 14:43:28 +00:00
|
|
|
/* prepare for the url encoding conversion */
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2009-05-31 13:09:48 +00:00
|
|
|
url_conv = iconv_open("UTF-16LE", "UTF-8");
|
2003-11-06 22:34:20 +00:00
|
|
|
#endif
|
2003-11-01 14:43:28 +00:00
|
|
|
|
2003-05-25 18:28:26 +00:00
|
|
|
snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname);
|
2003-10-22 17:26:15 +00:00
|
|
|
string_utf16 (data, str, strlen(str));
|
2002-05-14 22:31:21 +00:00
|
|
|
// send_command(s, commandno ....)
|
2003-10-22 17:26:15 +00:00
|
|
|
send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2003-05-29 19:36:58 +00:00
|
|
|
len = recv (s, data, BUF_SIZE, 0) ;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
/*This sends details of the local machine IP address to a Funnel system at the server.
|
2002-05-14 22:31:21 +00:00
|
|
|
* Also, the TCP or UDP transport selection is sent.
|
|
|
|
*
|
2003-10-22 17:26:15 +00:00
|
|
|
* here 192.168.0.1 is local ip address TCP/UDP states the tronsport we r using
|
2002-05-14 22:31:21 +00:00
|
|
|
* and 1037 is the local TCP or UDP socket number
|
|
|
|
* cmd 2 0x02
|
|
|
|
* */
|
|
|
|
|
2003-10-22 17:26:15 +00:00
|
|
|
string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24);
|
2002-05-14 22:31:21 +00:00
|
|
|
memset (data, 0, 8);
|
2003-10-22 17:26:15 +00:00
|
|
|
send_command (s, 2, 0, 0, 24*2+10, data);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2003-05-29 19:36:58 +00:00
|
|
|
len = recv (s, data, BUF_SIZE, 0) ;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
/* This command sends file path (at server) and file name request to the server.
|
|
|
|
* 0x5 */
|
|
|
|
|
|
|
|
string_utf16 (&data[8], path, strlen(path));
|
|
|
|
memset (data, 0, 8);
|
2003-10-22 17:26:15 +00:00
|
|
|
send_command (s, 5, 0, 0, strlen(path)*2+10, data);
|
2004-07-02 20:36:50 +00:00
|
|
|
free(path);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
get_answer (s);
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
/* The ASF header chunk request. Includes ?session' variable for pre header value.
|
|
|
|
* After this command is sent,
|
2002-05-14 22:31:21 +00:00
|
|
|
* the server replies with 0x11 command and then the header chunk with header data follows.
|
|
|
|
* 0x15 */
|
|
|
|
|
|
|
|
memset (data, 0, 40);
|
|
|
|
data[32] = 2;
|
|
|
|
|
|
|
|
send_command (s, 0x15, 1, 0, 40, data);
|
|
|
|
|
|
|
|
num_stream_ids = 0;
|
|
|
|
/* get_headers(s, asf_header); */
|
|
|
|
|
|
|
|
asf_header_len = get_header (s, asf_header, stream->streaming_ctrl);
|
2005-06-03 15:33:26 +00:00
|
|
|
// mp_msg(MSGT_NETWORK,MSGL_INFO,"---------------------------------- asf_header %d\n",asf_header);
|
2006-12-09 18:57:48 +00:00
|
|
|
if (asf_header_len==0) { //error reading header
|
|
|
|
closesocket(s);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-05-14 22:31:21 +00:00
|
|
|
packet_length = interp_header (asf_header, asf_header_len);
|
|
|
|
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
/*
|
|
|
|
* This command is the media stream MBR selector. Switches are always 6 bytes in length.
|
|
|
|
* After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02].
|
|
|
|
* Where:
|
|
|
|
* [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files.
|
|
|
|
* It is not yet understood what all this means.
|
|
|
|
* And the last [02] byte is probably the header ?session' value.
|
|
|
|
*
|
2002-05-14 22:31:21 +00:00
|
|
|
* 0x33 */
|
|
|
|
|
|
|
|
memset (data, 0, 40);
|
|
|
|
|
2007-02-08 17:03:24 +00:00
|
|
|
if (audio_id > 0) {
|
|
|
|
data[2] = 0xFF;
|
|
|
|
data[3] = 0xFF;
|
|
|
|
data[4] = audio_id;
|
|
|
|
send_command(s, 0x33, num_stream_ids, 0xFFFF | audio_id << 16, 8, data);
|
|
|
|
} else {
|
2002-05-14 22:31:21 +00:00
|
|
|
for (i=1; i<num_stream_ids; i++) {
|
|
|
|
data [ (i-1) * 6 + 2 ] = 0xFF;
|
|
|
|
data [ (i-1) * 6 + 3 ] = 0xFF;
|
|
|
|
data [ (i-1) * 6 + 4 ] = stream_ids[i];
|
|
|
|
data [ (i-1) * 6 + 5 ] = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data);
|
2007-02-08 17:03:24 +00:00
|
|
|
}
|
2002-05-14 22:31:21 +00:00
|
|
|
|
|
|
|
get_answer (s);
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
/* Start sending file from packet xx.
|
|
|
|
* This command is also used for resume downloads or requesting a lost packet.
|
|
|
|
* Also used for seeking by sending a play point value which seeks to the media time point.
|
|
|
|
* Includes ?session' value in pre header and the maximum media stream time.
|
2002-05-14 22:31:21 +00:00
|
|
|
* 0x07 */
|
|
|
|
|
|
|
|
memset (data, 0, 40);
|
|
|
|
|
|
|
|
for (i=8; i<16; i++)
|
|
|
|
data[i] = 0xFF;
|
|
|
|
|
|
|
|
data[20] = 0x04;
|
|
|
|
|
|
|
|
send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data);
|
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
stream->fd = s;
|
|
|
|
stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read;
|
|
|
|
stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek;
|
|
|
|
stream->streaming_ctrl->buffering = 1;
|
|
|
|
stream->streaming_ctrl->status = streaming_playing_e;
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2002-10-23 20:39:49 +00:00
|
|
|
packet_length1 = packet_length;
|
2005-11-06 15:25:08 +00:00
|
|
|
mp_msg(MSGT_NETWORK,MSGL_INFO,"mmst packet_length = %d\n", packet_length);
|
2002-05-14 22:31:21 +00:00
|
|
|
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2003-11-08 00:26:51 +00:00
|
|
|
if (url_conv != (iconv_t)(-1))
|
2003-11-06 22:34:20 +00:00
|
|
|
iconv_close(url_conv);
|
|
|
|
#endif
|
2003-11-01 14:43:28 +00:00
|
|
|
|
2002-05-14 22:31:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|