I think you should check first whether the codec exists in the context
object or not.
So the closing of context object should be as follows:

void my_close_stream(AVFormatContext *fc, AVCodecContext *ctx)
{
             if (ctx)
             {
                  if(ctx->codec != NULL)
                         avcodec_close(ctx);
                  av_free(ctx);
                  ctx = NULL;

             }

// Same conditions can be checked for closing format context also.
             if (fc)
             {
                         av_close_input_file(fc);
             }
}

Regards
Deepti




|---------+------------------------------->
|         |           Michael Edenfield   |
|         |           <[email protected]> |
|         |           Sent by:            |
|         |           libav-user-boun...@m|
|         |           playerhq.hu         |
|         |                               |
|         |                               |
|         |           10/14/2010 05:35 AM |
|         |           Please respond to   |
|         |           Libav* user         |
|         |           questions and       |
|         |           discussions         |
|         |                               |
|---------+------------------------------->
  
>------------------------------------------------------------------------------------------------------------------------------|
  |                                                                             
                                                 |
  |       To:       [email protected]                                     
                                                 |
  |       cc:                                                                   
                                                 |
  |       Subject:  [libav-user] How to properly close open contexts            
                                                 |
  
>------------------------------------------------------------------------------------------------------------------------------|




It has been suggested to me that my recent problems with segfaults are the
result of me trying to close things I shouldn't be touching.  I can
completely
believe that, since I'm really just guessing about that methods I should be

calling.  So hopefully someone here can point me in the right direction.

I'm opening the AVFormatContext and AVCodecContext like this (excluding my
error handling and some extra header stuff I have to do before connecting):

void my_open_url(AVFormatContext **fc, const char *url)
{
  URLContext *uc = NULL;
  AVInputFormat *fmt = NULL;
  ByteIOContext *pb = NULL;

  url_alloc(&uc, url, URL_RDONLY);
  url_connect(uc);
  url_fdopen(&pb, uc);
  ff_probe_input_buffer(&pb, &fmt, url, NULL, 0, 0);
  av_open_input_stream(fc, pb, url, fmt, NULL);
}

void my_open_stream(AVFormatContext  *fc, int idx)
{
             AVCodecContext *ctx = fc->streams[idx]->codec;
             AVCodec *codec = avcodec_find_decoder(ctx->codec_id);
             avcodec_open(ctx, codec);
}

I'm trying to close these two contexts like this:

void my_close_stream(AVFormatContext *fc, AVCodecContext *ctx)
{
             if (ctx)
             {
                         avcodec_close(ctx);
             }

             if (fc)
             {
                         av_close_input_file(fc);
             }
}

As far as I can tell, I'm doing the correct amount of cleaning up behind
myself, but both of those close methods segfault every time.  The segfaults

seems to be caused by items that should be allocated normally suddenly
becoming invalid, but I can't figure out why.  I'm using ffmpeg inside of a

JNI object, which may be doing who knows what with my memory allocations,
but
the problem *only* manifests on close (playback works fine).  Does anyone
have
any experience with this kind of problem?

--Mike
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user






Help save paper - do you need to print this email ? 
     
This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual(s) or entity addressed above. If you are 
not the intended recipient of this e-mail, then (i) please notify us at 
[email protected] (ii) do not use the information contained  & 
(iii) delete it from your system . E-mail communications are not secure. Though 
efforts have been taken to ensure that this communication has not been tampered 
with; however,  Canon India Pvt Ltd. is not responsible for any changes made to 
the contents of or any attachments to this message without its consent. 
All information contained in this message which are not of an official nature 
shall not be deemed as given or endorsed by Canon India Pvt. Ltd.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to