void mmsdown(const char *url,const char *filename,double sumtime) { mmsx_t* mmsx; mms_io_t *io = NULL; void *data; FILE *file; int length=1024; int bandwidth=1000; int stop=0; double time; file=fopen(filename,"wb+"); data=file; mmsx=mmsx_connect (io, data, url,bandwidth);//请求文件头,开始接受asf数据 while(!stop && mmsx != NULL) { time=mmsx_read (io, mmsx, file, length);//下载流媒体包,长度为length,返回音频时间 if(sumtime > 0 && time>=sumtime) stop=1; //{ // int iresult; // struct _stat buf; // iresult = _stat(filename, &buf); // printf("%f\n", (double)buf.st_size / 1024 / 1024); //} } if(mmsx) mmsx_close (mmsx); if(file) fclose(file); }
//--------------------------------------------------------------------------- size_t Reader_libmms::Format_Test(MediaInfo_Internal* MI, const String &File_Name) { //Opening the file mmsx_t* Handle=mmsx_connect(0, 0, Ztring(File_Name).To_Local().c_str(), (int)-1); if (Handle==NULL) return 0; mms_off_t Offset=mmsx_seek(0, Handle, 0, SEEK_SET); uint32_t Length=mmsx_get_length(Handle); //Buffer size_t Buffer_Size_Max=Buffer_NormalSize; int8u* Buffer=new int8u[Buffer_Size_Max]; //Parser MI->Open_Buffer_Init(Length, File_Name); //Test the format with buffer bool StopAfterFilled=MI->Config.File_StopAfterFilled_Get(); std::bitset<32> Status; do { //Seek (if needed) if (MI->Open_Buffer_Continue_GoTo_Get()!=(int64u)-1) { if (MI->Open_Buffer_Continue_GoTo_Get()>=Length) break; //Seek requested, but on a file bigger in theory than what is in the real file, we can't do this if (mmsx_seek(0, Handle, mms_off_t(MI->Open_Buffer_Continue_GoTo_Get()), SEEK_SET)!=MI->Open_Buffer_Continue_GoTo_Get()) break; //File is not seekable MI->Open_Buffer_Init((int64u)-1, MI->Open_Buffer_Continue_GoTo_Get()); } //Buffering size_t Buffer_Size=mmsx_read(0, Handle, (char*)Buffer, (int)Buffer_Size_Max); if (Buffer_Size==0) break; //Problem while reading //Parser Status=MI->Open_Buffer_Continue(Buffer, Buffer_Size); } while (!(Status[File__Analyze::IsFinished] || (StopAfterFilled && Status[File__Analyze::IsFilled]))); if (Length==0) //If Size==0, Status is never updated Status=MI->Open_Buffer_Continue(NULL, 0); //File mmsx_close(Handle); //Buffer delete[] Buffer; //Buffer=NULL; //Is this file detected? if (!Status[File__Analyze::IsAccepted]) return 0; MI->Open_Buffer_Finalize(); return 1; }
void MMSStreamReader::run() { int to_read = 1024; char prebuf[to_read]; m_handle = mmsx_connect (0, 0, m_url.toLocal8Bit().constData(), 128 * 1024); if(!m_handle) { qWarning("MMSStreamReader: connection failed"); setErrorString("connection failed"); emit error(); QIODevice::close(); return; } m_mutex.lock(); if(m_aborted) { m_mutex.unlock(); qDebug("MMSStreamReader: aborted"); return; } m_mutex.unlock(); qint64 len = 0; forever { m_mutex.lock(); if(m_buffer_at + to_read > m_buffer_size) { m_buffer_size = m_buffer_at + to_read; m_buffer = (char *)realloc(m_buffer, m_buffer_size); } m_mutex.unlock(); len = mmsx_read (0, m_handle, prebuf, to_read); m_mutex.lock(); if(len < 0) { m_mutex.unlock(); qWarning("MMSStreamReader: mms thread funished with code %lld (%s)", len, strerror(len)); if(!m_aborted && !m_ready) { setErrorString(strerror(len)); emit error(); } break; } memcpy(m_buffer + m_buffer_at, prebuf, len); m_buffer_at += len; if(!m_ready) checkBuffer(); m_mutex.unlock(); if(m_aborted) break; DownloadThread::usleep(5000); } QIODevice::close(); }
static int mms_ensure_connected (MMS_FILE *fp) { if (!fp->stream) { fp->stream = mmsx_connect ((mms_io_t *)fp->io, fp, fp->fname, 1544000, &fp->need_abort); if (!fp->stream) { return -1; } } return 0; }
static gboolean gst_mms_start (GstBaseSrc * bsrc) { GstMMS *mms; guint bandwidth_avail; mms = GST_MMS (bsrc); if (!mms->uri_name || *mms->uri_name == '\0') goto no_uri; if (mms->connection_speed) bandwidth_avail = mms->connection_speed; else bandwidth_avail = G_MAXINT; /* If we already have a connection, and the uri isn't changed, reuse it, as connecting is expensive. */ if (mms->connection) { if (!strcmp (mms->uri_name, mms->current_connection_uri_name)) { GST_DEBUG_OBJECT (mms, "Reusing existing connection for %s", mms->uri_name); return TRUE; } else { mmsx_close (mms->connection); g_free (mms->current_connection_uri_name); mms->current_connection_uri_name = NULL; } } /* FIXME: pass some sane arguments here */ GST_DEBUG_OBJECT (mms, "Trying mms_connect (%s) with bandwidth constraint of %d bps", mms->uri_name, bandwidth_avail); mms->connection = mmsx_connect (NULL, NULL, mms->uri_name, bandwidth_avail); if (mms->connection) { /* Save the uri name so that it can be checked for connection reusing, see above. */ mms->current_connection_uri_name = g_strdup (mms->uri_name); GST_DEBUG_OBJECT (mms, "Connect successful"); return TRUE; } else { gchar *url, *location; GST_ERROR_OBJECT (mms, "Could not connect to this stream, redirecting to rtsp"); location = gst_uri_get_location (mms->uri_name); url = g_strdup_printf ("rtsp://%s", location); g_free (location); gst_element_post_message (GST_ELEMENT_CAST (mms), gst_message_new_element (GST_OBJECT_CAST (mms), gst_structure_new ("redirect", "new-location", G_TYPE_STRING, url, NULL))); return FALSE; } no_uri: { GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ, ("No URI to open specified"), (NULL)); return FALSE; } }
//--------------------------------------------------------------------------- size_t Reader_libmms::Format_Test(MediaInfo_Internal* MI, const String &File_Name) { mmsx_t* Handle; //Opening the file #if MEDIAINFO_LIBMMS_DESCRIBE_SUPPORT if (MI->Config.File_Mmsh_Describe_Only_Get()) { // Use MMSH & Send a DESCRIBE request mmsh_t* MmshHandle; MmshHandle=mmsh_describe_request(0, 0, Ztring(File_Name).To_Local().c_str()); if (MmshHandle==NULL) return 0; Handle=mmsx_set_mmsh_handle(MmshHandle); if (Handle==NULL) { mmsh_close(MmshHandle); return 0; } } else #endif //MEDIAINFO_LIBMMS_DESCRIBE_SUPPORT { // Use MMS or MMSH (Send a DESCRIBE & PLAY request) Handle=mmsx_connect(0, 0, Ztring(File_Name).To_Local().c_str(), (int)-1); if (Handle==NULL) return 0; } //Init size_t Buffer_Size_Max; uint32_t Length; if (!MI->Config.File_Mmsh_Describe_Only_Get()) { //Buffer Buffer_Size_Max=Buffer_NormalSize; //MediaInfo init mms_off_t Offset=mmsx_seek(0, Handle, 0, SEEK_SET); uint32_t Length=mmsx_get_length(Handle); MI->Open_Buffer_Init(Length, File_Name); } else { //Buffer Buffer_Size_Max=mmsx_get_asf_header_len(Handle); //MediaInfo init Length=(uint32_t)-1; MI->Open_Buffer_Init((int64u)-1, File_Name); } int8u* Buffer=new int8u[Buffer_Size_Max]; //Test the format with buffer bool StopAfterFilled=MI->Config.File_StopAfterFilled_Get(); std::bitset<32> Status; do { //Seek (if needed) if (MI->Open_Buffer_Continue_GoTo_Get()!=(int64u)-1) { if (MI->Open_Buffer_Continue_GoTo_Get()>=Length) break; //Seek requested, but on a file bigger in theory than what is in the real file, we can't do this if (mmsx_seek(0, Handle, mms_off_t(MI->Open_Buffer_Continue_GoTo_Get()), SEEK_SET)!=MI->Open_Buffer_Continue_GoTo_Get()) break; //File is not seekable MI->Open_Buffer_Init((int64u)-1, MI->Open_Buffer_Continue_GoTo_Get()); } //Buffering size_t Buffer_Size; if (!MI->Config.File_Mmsh_Describe_Only_Get()) Buffer_Size=mmsx_read(0, Handle, (char*)Buffer, (int)Buffer_Size_Max); else Buffer_Size=mmsx_peek_header(Handle, (char*)Buffer, (int)Buffer_Size_Max); //Parser Status=MI->Open_Buffer_Continue(Buffer, Buffer_Size); if (Buffer_Size==0 || MI->Config.File_Mmsh_Describe_Only_Get()) break; } while (!(Status[File__Analyze::IsFinished] || (StopAfterFilled && Status[File__Analyze::IsFilled]))); //File mmsx_close(Handle); //Buffer delete[] Buffer; //Buffer=NULL; //Is this file detected? if (!Status[File__Analyze::IsAccepted]) return 0; MI->Open_Buffer_Finalize(); return 1; }