Hi,

I'm grabbing frame from an ip camera with the rtsp protocol but I have an 
issue, I can't release the stream. I mean, my camera is limited at 4 connexions 
in a same time but if start 4 connections/disconnections one after the other, I 
have the error "453 Not enough Bandwidth" on av_read_play(). So my question is, 
how to stop properly the connection to avoid this issue. Here is my testing 
code, I used wireshark to track messages and the "TEARDOWN" message is sent but 
not used.

Code :
#include <QtCore/QCoreApplication>
#include <QDebug>

extern "C" {
  #include <libavcodec/avcodec.h>
  #include <libavformat/avformat.h>
  #include <libswscale/swscale.h>
}

bool grab()
{
  // Declarations
  AVPacket packet;
  AVFrame *pFrame;
  AVFrame *pFrameRGB = NULL;
  int numBytes;
  AVDictionary *optionsDict = NULL;
  struct SwsContext *sws_ctx = NULL;
  uint8_t *buffer = NULL;
  AVFormatContext *pFormatCtx;
  AVCodecContext *vCodecCtxp;
  int videoStream;
  int res;
  // Init libav
  av_register_all();
  avformat_network_init();
  pFormatCtx = avformat_alloc_context();

  // Open stream
  res = avformat_open_input(&pFormatCtx, "rtsp://192.168.1.28/h264", NULL, 0);
  if(res!=0)
    return false; // Couldn't open file
  videoStream=-1;
  if(avformat_find_stream_info(pFormatCtx,NULL) < 0){
    return false;
  }
  for(int i=0; i<pFormatCtx->nb_streams; i++) {
    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO && 
videoStream < 0) {
      videoStream=i;
    }
  }
  vCodecCtxp = pFormatCtx->streams[videoStream]->codec;

  AVCodec *videoCodec;
  videoCodec=avcodec_find_decoder(vCodecCtxp->codec_id);

  res = avcodec_open2(vCodecCtxp, videoCodec, 0);
  if(res != 0){
    return false;
  }

  // Start playing
  res = av_read_play(pFormatCtx);
  if(res != 0){
    return false;
  }

  // Stop playing and clean
  res =  av_read_pause(pFormatCtx);
  if(res != 0){
    return false;
  }
  pFormatCtx->streams[videoStream]->discard = AVDISCARD_ALL;

  avcodec_close(vCodecCtxp);
  avformat_close_input(&pFormatCtx);

  avformat_network_deinit();
  return true;
}

int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);
  bool ok = true;
  for(int i = 0; ok && i < 6; i++){
    ok = grab();
    if(ok)
      qDebug() << i << "************************** - OK";
    else
      qDebug() << i << "************************** - PB";
  }
  if(ok)
    qDebug() << "It works";
  else
    qDebug() << "TEST FAILED !";
  return a.exec();
}

Results :
0 ************************** - OK 
1 ************************** - OK 
2 ************************** - PB 
TEST FAILED !

Thank you for your help.

Jérémy



Ce courriel (de même que les fichiers joints) est strictement réservé à l'usage 
de la personne ou de l'entité à qui il est adressé et peut contenir de 
l'information privilégiée et confidentielle. Toute divulgation, distribution ou 
copie de ce courriel est strictement prohibée. Si vous avez reçu ce courriel 
par erreur, veuillez nous en aviser sur-le-champ, détruire toutes les copies et 
le supprimer de votre système informatique.
 
 This communication (including any files transmitted with it) is intended 
solely for the person or entity to whom it is addressed, and may contain 
confidential or privileged information. The disclosure, distribution or copying 
of this message is strictly forbidden. Should you have received this 
communication in error, kindly contact the sender promptly, destroy any copies 
and delete this message from your computer system.
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to