static void gst_mms_finalize (GObject * gobject) { GstMMS *mmssrc = GST_MMS (gobject); /* We may still have a connection open, as we preserve unused / pristine open connections in stop to reuse them in start. */ if (mmssrc->connection) { mmsx_close (mmssrc->connection); mmssrc->connection = NULL; } if (mmssrc->current_connection_uri_name) { g_free (mmssrc->current_connection_uri_name); mmssrc->current_connection_uri_name = NULL; } if (mmssrc->uri_name) { g_free (mmssrc->uri_name); mmssrc->uri_name = NULL; } if (G_OBJECT_CLASS (parent_class)->finalize) G_OBJECT_CLASS (parent_class)->finalize (gobject); }
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; }
static void mms_close (DB_FILE *stream) { //fprintf (stderr, "\033[0;32mmms_close was called\033[37;0m\n"); assert (stream); MMS_FILE *fp = (MMS_FILE *)stream; if (fp->stream) { mmsx_close (fp->stream); } if (fp->fname) { free (fp->fname); } free (stream); }
void MMSStreamReader::abort() { m_mutex.lock(); if (m_aborted) { m_mutex.unlock(); return; } m_aborted = true; m_mutex.unlock(); if(m_thread->isRunning()) m_thread->wait(); m_ready = false; if (m_handle) mmsx_close(m_handle); m_handle = 0; }
static gboolean gst_mms_stop (GstBaseSrc * bsrc) { GstMMS *mms = GST_MMS (bsrc); if (mms->connection != NULL) { /* Check if the connection is still pristine, that is if no more then just the mmslib cached asf header has been read. If it is still pristine preserve it as we often are re-started with the same URL and connecting is expensive */ if (mmsx_get_current_pos (mms->connection) > mmsx_get_asf_header_len (mms->connection)) { mmsx_close (mms->connection); mms->connection = NULL; g_free (mms->current_connection_uri_name); mms->current_connection_uri_name = NULL; } } return TRUE; }
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; }