Revision fd450a51

View differences:

libavformat/rtsp.c
582 582
        rtsp_st = rt->rtsp_streams[i];
583 583
        if (rtsp_st) {
584 584
            if (rtsp_st->transport_priv) {
585
                if (rt->transport == RTSP_TRANSPORT_RDT)
585
                if (s->oformat) {
586
                    AVFormatContext *rtpctx = rtsp_st->transport_priv;
587
                    av_write_trailer(rtpctx);
588
                    url_fclose(rtpctx->pb);
589
                    av_free(rtpctx->streams[0]);
590
                    av_free(rtpctx);
591
                } else if (rt->transport == RTSP_TRANSPORT_RDT)
586 592
                    ff_rdt_parse_close(rtsp_st->transport_priv);
587 593
                else
588 594
                    rtp_parse_close(rtsp_st->transport_priv);
......
602 608
    av_freep(&rt->auth_b64);
603 609
}
604 610

  
611
static void *rtsp_rtp_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle) {
612
    AVFormatContext *rtpctx;
613
    int ret;
614
    AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
615

  
616
    if (!rtp_format)
617
        return NULL;
618

  
619
    /* Allocate an AVFormatContext for each output stream */
620
    rtpctx = avformat_alloc_context();
621
    if (!rtpctx)
622
        return NULL;
623

  
624
    rtpctx->oformat = rtp_format;
625
    if (!av_new_stream(rtpctx, 0)) {
626
        av_free(rtpctx);
627
        return NULL;
628
    }
629
    /* Copy the max delay setting; the rtp muxer reads this. */
630
    rtpctx->max_delay = s->max_delay;
631
    /* Copy other stream parameters. */
632
    rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
633

  
634
    /* Remove the local codec, link to the original codec
635
     * context instead, to give the rtp muxer access to
636
     * codec parameters. */
637
    av_free(rtpctx->streams[0]->codec);
638
    rtpctx->streams[0]->codec = st->codec;
639

  
640
    url_fdopen(&rtpctx->pb, handle);
641
    ret = av_write_header(rtpctx);
642

  
643
    if (ret) {
644
        url_fclose(rtpctx->pb);
645
        av_free(rtpctx->streams[0]);
646
        av_free(rtpctx);
647
        return NULL;
648
    }
649

  
650
    /* Copy the RTP AVStream timebase back to the original AVStream */
651
    st->time_base = rtpctx->streams[0]->time_base;
652
    return rtpctx;
653
}
654

  
605 655
static int rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
606 656
{
607 657
    RTSPState *rt = s->priv_data;
......
613 663
    if (!st)
614 664
        s->ctx_flags |= AVFMTCTX_NOHEADER;
615 665

  
616
    if (rt->transport == RTSP_TRANSPORT_RDT)
666
    if (s->oformat) {
667
        rtsp_st->transport_priv = rtsp_rtp_mux_open(s, st, rtsp_st->rtp_handle);
668
        /* Ownage of rtp_handle is passed to the rtp mux context */
669
        rtsp_st->rtp_handle = NULL;
670
    } else if (rt->transport == RTSP_TRANSPORT_RDT)
617 671
        rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index,
618 672
                                            rtsp_st->dynamic_protocol_context,
619 673
                                            rtsp_st->dynamic_handler);
libavformat/rtsp.h
281 281
 */
282 282
typedef struct RTSPStream {
283 283
    URLContext *rtp_handle;   /**< RTP stream handle (if UDP) */
284
    void *transport_priv; /**< RTP/RDT parse context */
284
    void *transport_priv; /**< RTP/RDT parse context if input, RTP AVFormatContext if output */
285 285

  
286 286
    /** corresponding stream index, if any. -1 if none (MPEG2TS case) */
287 287
    int stream_index;

Also available in: Unified diff