<!DOCTYPE html><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>

<style type="text/css">body { font-family:'DejaVu Sans Mono'; font-size:12px}</style>
</head>
<body style="MARGIN: 10px"><div>Hi,</div><div><br></div><div>No body had/have the same issue ?</div><div><br></div><div>Jérémy</div><div><br></div><div>Le Thu, 22 Aug 2013 10:44:26 +0200, Jeremy Lugagne <j.lugagne@spikenet-technology.com> a écrit:<br></div><br><blockquote style="margin: 0 0 0.80ex; border-left: #0000FF 2px solid; padding-left: 1ex">
<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></blockquote><br><br><br></body></html>