static void destroy_rtspgetsessions(STREAM_RTSP_SESSIONS_T *pRtsp) { unsigned int idx; if(pRtsp->pRtspGetSessionsBuf) { for(idx = 0; idx < pRtsp->numRtspGetSessions; idx++) { if(pRtsp->pRtspGetSessionsBuf[idx].pRequestBufWr) { pRtsp->pRtspGetSessionsBuf[idx].pRequestBufRd[0] = '\0'; vsxlib_cond_broadcast(&pRtsp->pRtspGetSessionsBuf[idx].cond.cond, &pRtsp->pRtspGetSessionsBuf[idx].cond.mtx); pthread_cond_destroy(&pRtsp->pRtspGetSessionsBuf[idx].cond.cond); pthread_mutex_destroy(&pRtsp->pRtspGetSessionsBuf[idx].cond.mtx); pthread_mutex_destroy(&pRtsp->pRtspGetSessionsBuf[idx].mtx); avc_free((void *) &pRtsp->pRtspGetSessionsBuf[idx].pRequestBufWr); } pRtsp->pRtspGetSessionsBuf[idx].pRequestBufRd = NULL; } avc_free((void *) &pRtsp->pRtspGetSessionsBuf); } pRtsp->pRtspGetSessionsHead = pRtsp->pRtspGetSessionsTail = NULL; pRtsp->numRtspGetSessions = 0; }
int rtmp_auth_cache_close(RTMP_AUTH_PERSIST_STORAGE_T *pcachedAuth) { RTMP_AUTH_PERSIST_NODE_T *p, *ptmp; if(!pcachedAuth) { return -1; } pthread_mutex_lock(&pcachedAuth->mtx); p = pcachedAuth->phead; while(p) { ptmp = p; p = p->pnext; avc_free((void *) ptmp); } pcachedAuth->phead = NULL; pthread_mutex_unlock(&pcachedAuth->mtx); pcachedAuth->max = 0; pthread_mutex_destroy(&pcachedAuth->mtx); return 0; }
void flvsrv_close(FLVSRV_CTXT_T *pFlv) { if(pFlv) { codecfmt_close(&pFlv->av); if(pFlv->out.bs.buf) { avc_free((void *) &pFlv->out.bs.buf); } pFlv->out.bs.sz = 0; //if(pFlv->av.vid.tmpFrame.buf) { // avc_free((void *) &pFlv->av.vid.tmpFrame.buf); //} //pFlv->av.vid.tmpFrame.sz = 0; //if(pFlv->av.vid.codecType == XC_CODEC_TYPE_H264) { // avcc_freeCfg(&pFlv->av.vid.codecCtxt.h264.avcc); //} outfmt_freequeuedframes(&pFlv->queuedFrames); } }
void codecfmt_close(CODEC_AV_CTXT_T *pAv) { if(pAv->vid.tmpFrame.buf) { avc_free((void *) &pAv->vid.tmpFrame.buf); } pAv->vid.tmpFrame.sz = 0; if(pAv->aud.tmpFrame.buf) { avc_free((void *) &pAv->aud.tmpFrame.buf); } pAv->aud.tmpFrame.sz = 0; if(pAv->vid.codecType == XC_CODEC_TYPE_H264) { avcc_freeCfg(&pAv->vid.codecCtxt.h264.avcc); } pAv->vid.sentSeqHdr = 0; pAv->vid.haveSeqHdr = 0; pAv->aud.haveSeqHdr = 0; }
void rtspsrv_close(STREAM_RTSP_SESSIONS_T *pRtsp) { unsigned int idx; if(!pRtsp) { return; } if(pRtsp->sockStaticLocalPort != INVALID_SOCKET) { net_closesocket(&pRtsp->sockStaticLocalPort); } if(pRtsp->runMonitor > 0) { pRtsp->runMonitor = -2; while(pRtsp->runMonitor != -1) { usleep(5000); } } pthread_mutex_destroy(&pRtsp->mtx); if(pRtsp->psessions) { avc_free((void *) &pRtsp->psessions); } for(idx = 0; idx < RTSP_FORCE_TCP_UA_LIST_MAX; idx++) { if(pRtsp->rtspForceTcpUAList.arr[idx]) { avc_free((void *) &pRtsp->rtspForceTcpUAList.arr[idx]); } } pRtsp->rtspForceTcpUAList.count = 0; destroy_rtspgetsessions(pRtsp); *((unsigned int *) &pRtsp->max) = 0; }
int stream_stats_destroy(STREAM_STATS_T **ppStats, pthread_mutex_t *pmtx) { unsigned int idx; unsigned int throughputIdx; if(pmtx) { pthread_mutex_lock(pmtx); } if(!ppStats || !(*ppStats)) { if(pmtx) { pthread_mutex_unlock(pmtx); } return -1; } pthread_mutex_lock(&(*ppStats)->mtx); (*ppStats)->active = 0; // // Automatically detach from monitor linked list // if((*ppStats)->pMonitor) { stream_monitor_detach( (*ppStats)->pMonitor, *ppStats); } for(idx = 0; idx < THROUGHPUT_STATS_BURSTRATES_MAX; idx++) { for(throughputIdx = 0; throughputIdx < 2; throughputIdx++) { burstmeter_close(&(*ppStats)->throughput_rt[throughputIdx].bitratesWr[idx]); burstmeter_close(&(*ppStats)->throughput_rt[throughputIdx].bitratesRd[idx]); } } pthread_mutex_unlock(&(*ppStats)->mtx); pthread_mutex_destroy(&(*ppStats)->mtx); avc_free((void **) ppStats); if(pmtx) { pthread_mutex_unlock(pmtx); } return 0; }
int mpd_close(MPD_CREATE_CTXT_T *pCtxt, int deleteFiles, int dealloc) { int rc = 0; unsigned int idx; char mpdpath[VSX_MAX_PATH_LEN]; int outidx; struct stat st; if(!pCtxt) { return -1; } if(deleteFiles) { // // Remove playlist .mpd files // for(idx = 0; idx < sizeof(pCtxt->mpdOutputTypes) / sizeof(pCtxt->mpdOutputTypes[0]); idx++) { for(outidx = -1; outidx < IXCODE_VIDEO_OUT_MAX; outidx++) { write_mpd_path(pCtxt, outidx, pCtxt->mpdOutputTypes[idx].type, mpdpath, sizeof(mpdpath)); if(fileops_stat(mpdpath, &st) == 0 && (rc = fileops_DeleteFile(mpdpath)) != 0) { LOG(X_ERROR("Failed to delete '%s'"), mpdpath); } } } } if(dealloc) { for(idx = 0; idx < DASH_MPD_MAX_ADAPTATIONS; idx++) { if(pCtxt->segs[idx].pSegments) { avc_free((void **) &pCtxt->segs[idx].pSegments); } } } return rc; }
int stream_monitor_stop(STREAM_STATS_MONITOR_T *pMonitor) { int rc = 0; if(!pMonitor) { return -1; } pMonitor->active = 0; if(pMonitor->runMonitor > 0) { pMonitor->runMonitor = -2; while(pMonitor->runMonitor != -1) { usleep(5000); } } if(pMonitor->pAbr) { stream_abr_close(pMonitor->pAbr); avc_free((void **) &pMonitor->pAbr); } return rc; }
int rtspsrv_init(STREAM_RTSP_SESSIONS_T *pRtsp) { pthread_t ptdMonitor; struct sockaddr_storage sa; pthread_attr_t attrMonitor; RTSP_MONITOR_CTXT_T startCtxt; const char *s; if(!pRtsp || pRtsp->max <= 0) { return -1; } if(pRtsp->psessions) { avc_free((void *) &pRtsp->psessions); } destroy_rtspgetsessions(pRtsp); if(!(pRtsp->psessions = (RTSP_SESSION_T *) avc_calloc(pRtsp->max, sizeof(RTSP_SESSION_T)))) { return -1; } pRtsp->numRtspGetSessions = pRtsp->max * 2; if(!(pRtsp->pRtspGetSessionsBuf = (RTSP_HTTP_SESSION_T *) avc_calloc(pRtsp->numRtspGetSessions, sizeof(RTSP_HTTP_SESSION_T)))) { avc_free((void *) &pRtsp->psessions); pRtsp->numRtspGetSessions = 0; return -1; } pthread_mutex_init(&pRtsp->mtx, NULL); // // If all UDP / RTP sockets are bound to the same port then establish // the listener of this port prior to any RTSP interaction because some app // gateways may send some UDP polling data to the base port - and returning // an ICMP port unreachable would prevent such app gateways from allocating // UDP proxy ports // pRtsp->sockStaticLocalPort = INVALID_SOCKET; if(pRtsp->staticLocalPort > 0) { memset(&sa, 0, sizeof(sa)); sa.ss_family = AF_INET; ((struct sockaddr_in *) &sa)->sin_addr.s_addr = INADDR_ANY; INET_PORT(sa) = htons(pRtsp->staticLocalPort); if((pRtsp->sockStaticLocalPort = net_opensocket(SOCK_DGRAM, 0, 0, (struct sockaddr *) &sa)) == INVALID_SOCKET) { LOG(X_ERROR("Failed to open RTSP static local RTP port %d"), pRtsp->staticLocalPort); } else { if(net_setsocknonblock(pRtsp->sockStaticLocalPort, 1) < 0) { LOG(X_ERROR("Failed to listen on RTSP static local RTP port %d"), pRtsp->staticLocalPort); net_closesocket(&pRtsp->sockStaticLocalPort); } } //if(pRtsp->sockStaticLocalPort != INVALID_SOCKET) { // sain.sin_addr.s_addr = inet_addr("127.0.0.1"); // rc = sendto(pRtsp->sockStaticLocalPort, &sain, 1, 0, (struct sockaddr *) &sain, sizeof(sain)); // fprintf(stderr, "SENDTO:%d\n", rc); //} } // // Parse any CSV of quoted User-Agent matches which should try to force TCP interleaved mode // pRtsp->rtspForceTcpUAList.count = 0; if(pRtsp->rtspForceTcpUAList.str) { strutil_parse_csv(cbparse_entry_rtspua, pRtsp, pRtsp->rtspForceTcpUAList.str); } pRtsp->runMonitor = 2; memset(&startCtxt, 0, sizeof(startCtxt)); startCtxt.pRtsp = pRtsp; if((s = logutil_tid_lookup(pthread_self(), 0)) && s[0] != '\0') { snprintf(startCtxt.tid_tag, sizeof(startCtxt.tid_tag), "%s-rtspmon", s); } pthread_attr_init(&attrMonitor); pthread_attr_setdetachstate(&attrMonitor, PTHREAD_CREATE_DETACHED); if(pthread_create(&ptdMonitor, &attrMonitor, (void *) rtsp_monitor_proc, (void *) &startCtxt) != 0) { LOG(X_ERROR("Unable to create RTP monitor thread")); pRtsp->runMonitor = 0; if(pRtsp->psessions) { avc_free((void *) &pRtsp->psessions); } destroy_rtspgetsessions(pRtsp); pthread_mutex_destroy(&pRtsp->mtx); } while(pRtsp->runMonitor != 1 && pRtsp->runMonitor != -1) { usleep(5000); } return 0; }