/* this will be used to handle Drag&Drop files */ void mplDandDHandler(int num,char** files) { struct stat buf; int f = 0; char* subtitles = NULL; char* filename = NULL; if (num <= 0) return; /* now fill it with new items */ for(f=0; f < num; f++){ char* str = strdup( files[f] ); plItem* item; url_unescape_string(str, files[f]); if(stat(str,&buf) == 0 && S_ISDIR(buf.st_mode) == 0) { /* this is not a directory so try to play it */ mp_msg( MSGT_GPLAYER,MSGL_V,"Received D&D %s\n",str ); /* check if it is a subtitle file */ { char* ext = strrchr(str,'.'); if (ext) { static char supported[] = "utf/sub/srt/smi/rt//txt/ssa/aqt/"; char* type; int len; if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\ (type-supported)%4 == 0 && *(type+len) == '/'){ /* handle subtitle file */ gfree((void**)&subtitles); subtitles = str; continue; } } } /* clear playlist */ if (filename == NULL) { filename = files[f]; gtkSet(gtkDelPl,0,NULL); } item = calloc(1,sizeof(plItem)); /* FIXME: decompose file name ? */ /* yes -- Pontscho */ if ( strrchr( str,'/' ) ) { char * s = strrchr( str,'/' ); *s=0; s++; item->name = gstrdup( s ); item->path = gstrdup( str ); } else { item->name = strdup(str); item->path = strdup(""); } gtkSet(gtkAddPlItem,0,(void*)item); } else { mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str ); } free( str ); } if (filename) { mplSetFileName( NULL,filename,STREAMTYPE_FILE ); if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evStop,0 ); mplEventHandling( evPlay,0 ); } if (subtitles) { gfree((void**)&guiIntfStruct.Subtitlename); guiIntfStruct.Subtitlename = subtitles; guiLoadSubtitle(guiIntfStruct.Subtitlename); } }
static pascal OSErr AppleEventHandlerProc(const AppleEvent *theAppleEvent, AppleEvent* reply, SInt32 handlerRefcon) { OSErr err=errAEEventNotHandled, res=noErr; AEDescList docList; long itemsInList; AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, NULL, FALSE); if((res=AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))==noErr) { if((res=AECountItems(&docList, &itemsInList))==noErr) { Size currentSize=0; int valid=0,i; char *parm=NULL; play_tree_t *last_entry=NULL; files=play_tree_new(); for(i=1;i<=itemsInList;++i) { for(;;) { OSErr e; Size actualSize=0; AEKeyword keywd; DescType returnedType; if((e=AEGetNthPtr(&docList, i, typeFileURL, &keywd, &returnedType, (Ptr)parm, currentSize, &actualSize))==noErr) { if(actualSize>=currentSize) { currentSize=actualSize+1; parm=realloc(parm, currentSize); } else { parm[actualSize]=0; valid=1; break; } } else { valid=0; break; } } if(valid) { URL_t *url=url_new(parm); if(url && !strcmp(url->protocol,"file") && !strcmp(url->hostname,"localhost")) { play_tree_t *entry=play_tree_new(); url_unescape_string(url->file, url->file); play_tree_add_file(entry, url->file); add_entry(&files, &last_entry, entry); } url_free(url); } } if(parm) free(parm); err=noErr; } else mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AECountItems() error %d\n", res); AEDisposeDesc(&docList); } else mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AEGetParamDesc() error %d\n", res); QuitApplicationEventLoop(); return err; }
int asf_mmst_streaming_start(stream_t *stream) { char str[1024]; char data[BUF_SIZE]; uint8_t asf_header[HDR_BUF_SIZE]; int asf_header_len; int i, packet_length; char *path, *unescpath; URL_t *url1 = stream->streaming_ctrl->url; int s = stream->fd; if( s>0 ) { closesocket( stream->fd ); stream->fd = -1; } /* parse url */ path = strchr(url1->file,'/') + 1; /* 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) { mp_tmsg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed.\n"); return -1; } url_unescape_string(unescpath,path); path=unescpath; if( url1->port==0 ) { url1->port=1755; } s = connect2Server( url1->hostname, url1->port, 1); if( s<0 ) { free(path); return s; } mp_tmsg(MSGT_NETWORK,MSGL_INFO,"Connected\n"); seq_num=0; /* * 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 * */ /* prepare for the url encoding conversion */ #ifdef CONFIG_ICONV url_conv = iconv_open("UTF-16LE", "UTF-8"); #endif snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); string_utf16 (data, str, strlen(str)); // send_command(s, commandno ....) send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data); recv (s, data, BUF_SIZE, 0) ; /*This sends details of the local machine IP address to a Funnel system at the server. * Also, the TCP or UDP transport selection is sent. * * here 192.168.0.1 is local ip address TCP/UDP states the tronsport we r using * and 1037 is the local TCP or UDP socket number * cmd 2 0x02 * */ string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); memset (data, 0, 8); send_command (s, 2, 0, 0, 24*2+10, data); recv (s, data, BUF_SIZE, 0) ; /* 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); send_command (s, 5, 0, 0, strlen(path)*2+10, data); free(path); get_answer (s); /* The ASF header chunk request. Includes ?session' variable for pre header value. * After this command is sent, * 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); // mp_msg(MSGT_NETWORK,MSGL_INFO,"---------------------------------- asf_header %d\n",asf_header); if (asf_header_len==0) { //error reading header closesocket(s); return -1; } packet_length = interp_header (asf_header, asf_header_len); /* * 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. * * 0x33 */ memset (data, 0, 40); int audio_id = stream->opts->audio_id; 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 { 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); } get_answer (s); /* 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. * 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); stream->fd = s; stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read; stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek; stream->streaming_ctrl->status = streaming_playing_e; stream->streaming = true; packet_length1 = packet_length; mp_msg(MSGT_NETWORK,MSGL_INFO,"mmst packet_length = %d\n", packet_length); #ifdef CONFIG_ICONV if (url_conv != (iconv_t)(-1)) iconv_close(url_conv); #endif return 0; }
/* this will be used to handle drag & drop files */ static void uiMainDND(int num,char** files) { struct stat buf; int f = 0; char* subtitles = NULL; char* file = NULL; char* s; if (num <= 0) return; /* now fill it with new items */ for(f=0; f < num; f++){ char* str = strdup( files[f] ); plItem* item; url_unescape_string(str, files[f]); if(stat(str,&buf) == 0 && S_ISDIR(buf.st_mode) == 0) { /* this is not a directory so try to play it */ mp_msg( MSGT_GPLAYER,MSGL_V,"Received D&D %s\n",str ); /* check if it is a subtitle file */ { char* ext = strrchr(str,'.'); if (ext) { static char supported[] = "utf/sub/srt/smi/rt//txt/ssa/aqt/"; char* type; int len; if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\ (type-supported)%4 == 0 && *(type+len) == '/'){ /* handle subtitle file */ nfree(subtitles); subtitles = str; continue; } } } /* clear playlist */ if (file == NULL) { file = files[f]; listMgr(PLAYLIST_DELETE,0); } item = calloc(1,sizeof(plItem)); s = strrchr( str,'/' ); /* FIXME: decompose file name ? */ /* yes -- Pontscho */ if ( s ) { *s=0; s++; item->name = gstrdup( s ); item->path = gstrdup( str ); } else { // NOTE TO MYSELF: this shouldn't happen, make sure we have a full path item->name = strdup(str); item->path = strdup("."); } listMgr(PLAYLIST_ITEM_APPEND,item); } else { mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str ); } free( str ); } if (file) { uiSetFile( NULL,file,STREAMTYPE_FILE ); if ( guiInfo.Playing == GUI_PLAY ) uiEvent( evStop,0 ); uiEvent( evPlay,0 ); } if (subtitles) { nfree(guiInfo.SubtitleFilename); guiInfo.SubtitleFilename = subtitles; mplayerLoadSubtitle(guiInfo.SubtitleFilename); } }