static int64_t mmsh_read_seek(URLContext *h, int stream_index, int64_t timestamp, int flags) { MMSHContext *mmsh_old = h->priv_data; MMSHContext *mmsh = av_mallocz(sizeof(*mmsh)); int ret; if (!mmsh) return AVERROR(ENOMEM); h->priv_data = mmsh; ret= mmsh_open_internal(h, mmsh_old->location, 0, FFMAX(timestamp, 0), 0); if(ret>=0){ h->priv_data = mmsh_old; mmsh_close(h); h->priv_data = mmsh; av_free(mmsh_old); mmsh->mms.asf_header_read_size = mmsh->mms.asf_header_size; }else { h->priv_data = mmsh_old; av_free(mmsh); } return ret; }
static int mmsh_open(URLContext *h, const char *uri, int flags) { int ret = mmsh_open_internal(h, uri, flags, 0, 0); if (ret < 0) mmsh_close(h); return ret; }
void mmsx_close (mmsx_t *mmsx) { if(mmsx->connection) mms_close(mmsx->connection); else mmsh_close(mmsx->connection_h); free(mmsx); }
void mmsx_close(mmsx_t *mmsx) { if (mmsx->connection) { mms_close(mmsx->connection); } else { mmsh_close(mmsx->connection_h); } free(mmsx); }
static int mms_vfs_fclose_impl (VFSFile * file) { MMSHandle * h = (MMSHandle *) vfs_get_handle (file); if (h->mms) mms_close (h->mms); else mmsh_close (h->mmsh); g_free (h); return 0; }
static gboolean gst_mms_stop (GstBaseSrc * bsrc) { GstMMS *mms; mms = GST_MMS (bsrc); if (mms->connection != NULL) { mms_close (mms->connection); mms->connection = NULL; } if (mms->connection_h != NULL) { mmsh_close (mms->connection_h); mms->connection_h = NULL; } return TRUE; }
static void mms_plugin_dispose (input_plugin_t *this_gen) { mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen; if (this->mms) mms_close (this->mms); if (this->mmsh) mmsh_close (this->mmsh); this->mms = NULL; this->mmsh = NULL; if (this->nbc) { nbc_close (this->nbc); this->nbc = NULL; } free(this->mrl); free (this); }
static int mmsh_open(URLContext *h, const char *uri, int flags) { int i, port, err; char httpname[256], path[256], host[128], location[1024]; char *stream_selection = NULL; char headers[1024]; MMSHContext *mmsh; MMSContext *mms; mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext)); if (!h->priv_data) return AVERROR(ENOMEM); mmsh->request_seq = h->is_streamed = 1; mms = &mmsh->mms; av_strlcpy(location, uri, sizeof(location)); av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, path, sizeof(path), location); if (port<0) port = 80; // default mmsh protocol port ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path); if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { return AVERROR(EIO); } snprintf(headers, sizeof(headers), "Accept: */*\r\n" USERAGENT "Host: %s:%d\r\n" "Pragma: no-cache,rate=1.000000,stream-time=0," "stream-offset=0:0,request-context=%u,max-duration=0\r\n" CLIENTGUID "Connection: Close\r\n\r\n", host, port, mmsh->request_seq++); ff_http_set_headers(mms->mms_hd, headers); err = url_connect(mms->mms_hd); if (err) { goto fail; } err = get_http_header_data(mmsh); if (err) { av_log(NULL, AV_LOG_ERROR, "Get http header data failed!\n"); goto fail; } // close the socket and then reopen it for sending the second play request. url_close(mms->mms_hd); memset(headers, 0, sizeof(headers)); if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { return AVERROR(EIO); } stream_selection = av_mallocz(mms->stream_num * 19 + 1); if (!stream_selection) return AVERROR(ENOMEM); for (i = 0; i < mms->stream_num; i++) { char tmp[20]; err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id); if (err < 0) goto fail; av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1); } // send play request err = snprintf(headers, sizeof(headers), "Accept: */*\r\n" USERAGENT "Host: %s:%d\r\n" "Pragma: no-cache,rate=1.000000,request-context=%u\r\n" "Pragma: xPlayStrm=1\r\n" CLIENTGUID "Pragma: stream-switch-count=%d\r\n" "Pragma: stream-switch-entry=%s\r\n" "Connection: Close\r\n\r\n", host, port, mmsh->request_seq++, mms->stream_num, stream_selection); av_freep(&stream_selection); if (err < 0) { av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n"); goto fail; } av_dlog(NULL, "out_buffer is %s", headers); ff_http_set_headers(mms->mms_hd, headers); err = url_connect(mms->mms_hd); if (err) { goto fail; } err = get_http_header_data(mmsh); if (err) { av_log(NULL, AV_LOG_ERROR, "Get http header data failed!\n"); goto fail; } av_dlog(NULL, "Connection successfully open\n"); return 0; fail: av_freep(&stream_selection); mmsh_close(h); av_dlog(NULL, "Connection failed with error %d\n", err); return err; }
//--------------------------------------------------------------------------- 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; }