Ticket #4929: nae.patch

File nae.patch, 3.8 KB (added by Nicolas, 11 years ago)

ffplay preclose function for tearing down rtsp

  • ffplay.c

    diff --git a/ffplay.c b/ffplay.c
    index 4a084b4..c47cc95 100644
    a b static void stream_component_close(VideoState *is, int stream_index)  
    11921192
    11931193static void stream_close(VideoState *is)
    11941194{
     1195    avformat_preclose_input(&is->ic);
     1196 
    11951197    /* XXX: use a special url_shutdown call to abort parse cleanly */
    11961198    is->abort_request = 1;
    11971199    SDL_WaitThread(is->read_tid, NULL);
  • libavformat/avformat.h

    diff --git a/libavformat/avformat.h b/libavformat/avformat.h
    index f3ffcfb..76d9402 100644
    a b typedef struct AVInputFormat {  
    693693    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
    694694
    695695    /**
     696     * The stream is going to be closed. The AVFormatContext and AVStreams are not
     697     * freed by this function
     698     */
     699    int (*read_preclose)(struct AVFormatContext *);
     700 
     701    /**
    696702     * Close the stream. The AVFormatContext and AVStreams are not
    697703     * freed by this function
    698704     */
    … … int av_read_play(AVFormatContext *s);  
    22312237int av_read_pause(AVFormatContext *s);
    22322238
    22332239/**
     2240 * Call before closing input AVFormatContext.
     2241 */
     2242void avformat_preclose_input(AVFormatContext **s);
     2243/**
     2244 * @}
     2245 */
     2246
     2247/**
    22342248 * Close an opened input AVFormatContext. Free it and all its contents
    22352249 * and set *s to NULL.
    22362250 */
  • libavformat/rtspdec.c

    diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
    index 3c0010e..17afd47 100644
    a b static const struct RTSPStatusMessage {  
    5353    { 0,                          "NULL"                             }
    5454};
    5555
    56 static int rtsp_read_close(AVFormatContext *s)
     56static int rtsp_read_preclose(AVFormatContext *s)
    5757{
    5858    RTSPState *rt = s->priv_data;
    5959
    60     if (!(rt->rtsp_flags & RTSP_FLAG_LISTEN))
    61         ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL);
     60    if (!(rt->rtsp_flags & RTSP_FLAG_LISTEN)) {
     61      ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL);
     62    }
     63    return 0;
     64}
    6265
     66static int rtsp_read_close(AVFormatContext *s)
     67{
     68    RTSPState *rt = s->priv_data;
     69       
    6370    ff_rtsp_close_streams(s);
    6471    ff_rtsp_close_connections(s);
    6572    ff_network_close();
    … … static int rtsp_read_play(AVFormatContext *s)  
    551558        ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL);
    552559        if (reply->status_code != RTSP_STATUS_OK) {
    553560            return ff_rtsp_averror(reply->status_code, -1);
    554         }
     561        }       
    555562        if (rt->transport == RTSP_TRANSPORT_RTP &&
    556563            reply->range_start != AV_NOPTS_VALUE) {
    557564            for (i = 0; i < rt->nb_rtsp_streams; i++) {
    … … int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply)  
    616623    }
    617624    if (!content)
    618625        return AVERROR_INVALIDDATA;
    619 
     626   
    620627    av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", content);
    621628    /* now we got the SDP description, we parse it */
    622629    ret = ff_sdp_parse(s, (const char *)content);
    … … AVInputFormat ff_rtsp_demuxer = {  
    966973    .read_probe     = rtsp_probe,
    967974    .read_header    = rtsp_read_header,
    968975    .read_packet    = rtsp_read_packet,
     976    .read_preclose  = rtsp_read_preclose,
    969977    .read_close     = rtsp_read_close,
    970978    .read_seek      = rtsp_read_seek,
    971979    .flags          = AVFMT_NOFILE,
  • libavformat/utils.c

    diff --git a/libavformat/utils.c b/libavformat/utils.c
    index 689473e..853fb59 100644
    a b void avformat_free_context(AVFormatContext *s)  
    37073707    av_free(s);
    37083708}
    37093709
     3710void avformat_preclose_input(AVFormatContext **ps)
     3711{
     3712    AVFormatContext *s;
     3713
     3714    if (!ps || !*ps)
     3715        return;
     3716
     3717    s  = *ps;
     3718   
     3719    if (s->iformat)
     3720        if (s->iformat->read_preclose)
     3721            s->iformat->read_preclose(s);
     3722}
     3723
    37103724void avformat_close_input(AVFormatContext **ps)
    37113725{
    37123726    AVFormatContext *s;