<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 10.00.9200.16660">
<STYLE>
BLOCKQUOTE {
MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em; MARGIN-TOP: 0px
}
OL {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
UL {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
P {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
BODY {
FONT-FAMILY: Segoe UI; COLOR: #000000; LINE-HEIGHT: 1.5
}
</STYLE>
</HEAD>
<BODY style="MARGIN: 10px">
<DIV>Hello all,</DIV>
<DIV> </DIV>
<DIV>I'm using the libav to grab images from a network camera with the rtsp
protocol but I have an issue. When I release the stream, my camera don't release
resources for the sessions, so when I do 4 tests with my applications I must
restart the camera because I have no more slot.</DIV>
<DIV> </DIV>
<DIV>This is how I open the stream :</DIV>
<DIV><code></DIV>
<DIV>
<DIV> AVFormatContext *pFormatCtx;</DIV>
<DIV> AVCodecContext* vCodecCtxp;</DIV>
<DIV> AVPacket packet;</DIV>
<DIV> AVFrame *pFrame;</DIV>
<DIV> AVFrame *pFrameRGB = NULL;</DIV>
<DIV> int numBytes;</DIV>
<DIV> AVDictionary *optionsDict = NULL;</DIV>
<DIV> struct SwsContext *sws_ctx = NULL;</DIV>
<DIV> uint8_t *buffer = NULL;</DIV>
<DIV> AVCodec *videoCodec;</DIV>
<DIV> </DIV>
<DIV> av_register_all();</DIV>
<DIV> avformat_network_init();</DIV>
<DIV> pFormatCtx = avformat_alloc_context();</DIV>
<DIV> if(avformat_open_input(&pFormatCtx, qPrintable(url), NULL, 0)!=0)</DIV>
<DIV> return false; // Couldn't open file</DIV>
<DIV> videoStream=-1;</DIV>
<DIV> </DIV>
<DIV> if(avformat_find_stream_info(pFormatCtx,NULL) < 0){</DIV>
<DIV> return false;</DIV>
<DIV> }</DIV>
<DIV> for(int i=0; i<pFormatCtx->nb_streams; i++) {</DIV>
<DIV> if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO && videoStream < 0) {</DIV>
<DIV> videoStream=i;</DIV>
<DIV> }</DIV>
<DIV> }</DIV>
<DIV> vCodecCtxp = pFormatCtx->streams[videoStream]->codec;</DIV>
<DIV> </DIV>
<DIV> // Allocate an AVFrame structure</DIV>
<DIV> pFrameRGB = avcodec_alloc_frame();</DIV>
<DIV> pFrame = avcodec_alloc_frame();</DIV>
<DIV> if(pFrameRGB==NULL) return ;</DIV>
<DIV> </DIV>
<DIV> // Determine required buffer size and allocate buffer</DIV>
<DIV> numBytes=avpicture_get_size(PIX_FMT_RGB24, vCodecCtxp->width, vCodecCtxp->height);</DIV>
<DIV> buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));</DIV>
<DIV> </DIV>
<DIV> sws_ctx = sws_getContext(vCodecCtxp->width, vCodecCtxp->height, vCodecCtxp->pix_fmt, vCodecCtxp->width, vCodecCtxp->height, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL );</DIV>
<DIV> </DIV>
<DIV> // Assign appropriate parts of buffer to image planes in pFrameRGB. Note that pFrameRGB is an AVFrame, but AVFrame is a superset of AVPicture</DIV>
<DIV> avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, vCodecCtxp->width, vCodecCtxp->height);</DIV>
<DIV> </DIV>
<DIV> // Assign appropriate parts of buffer to image planes in pFrameRGB. Note that pFrameRGB is an AVFrame, but AVFrame is a superset of AVPicture</DIV>
<DIV> int res = avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, vCodecCtxp->width, vCodecCtxp->height);</DIV>
<DIV> </DIV>
<DIV> videoCodec=avcodec_find_decoder(vCodecCtxp->codec_id);</DIV>
<DIV> avcodec_open2(vCodecCtxp, videoCodec, 0);</DIV>
<DIV> </DIV>
<DIV> av_read_play(pFormatCtx);</DIV>
<DIV></code></DIV>
<DIV> </DIV>
<DIV>And how I close it :</DIV>
<DIV><code></DIV>
<DIV>
<DIV> av_free(pFrameRGB);</DIV>
<DIV> av_free(buffer);</DIV>
<DIV> av_free(pFrame);</DIV>
<DIV> sws_freeContext(sws_ctx);</DIV>
<DIV> avformat_close_input(&pFormatCtx);</DIV></DIV>
<DIV></code></DIV>
<DIV> </DIV>
<DIV>Do i forgetting something to close properly my stream ? Because when I
watch what messages are sent to the camera I see the TEARDOWN message.</DIV>
<DIV> </DIV>
<DIV>Thanks in advance,</DIV>
<DIV> </DIV>
<DIV>Jeremy L.</DIV></DIV></BODY></HTML>