Browse code

avformat/mux: support re-interleaving packets in ff_write_chained()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2014/07/25 05:39:22
Showing 9 changed files
... ...
@@ -549,7 +549,7 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt)
549 549
     os->last_ts = pkt->dts;
550 550
 
551 551
     os->packets_written++;
552
-    return ff_write_chained(os->ctx, pkt->stream_index - os->first_stream, pkt, s);
552
+    return ff_write_chained(os->ctx, pkt->stream_index - os->first_stream, pkt, s, 0);
553 553
 }
554 554
 
555 555
 static int hds_write_trailer(AVFormatContext *s)
... ...
@@ -302,7 +302,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
302 302
             return ret;
303 303
     }
304 304
 
305
-    ret = ff_write_chained(oc, pkt->stream_index, pkt, s);
305
+    ret = ff_write_chained(oc, pkt->stream_index, pkt, s, 0);
306 306
 
307 307
     return ret;
308 308
 }
... ...
@@ -134,10 +134,11 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
134 134
  * @param dst_stream the stream index within dst to write the packet to
135 135
  * @param pkt the packet to be written
136 136
  * @param src the muxer the packet originally was intended for
137
+ * @param interleave 0->use av_write_frame, 1->av_write_interleaved_frame
137 138
  * @return the value av_write_frame returned
138 139
  */
139 140
 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
140
-                     AVFormatContext *src);
141
+                     AVFormatContext *src, int interleave);
141 142
 
142 143
 /**
143 144
  * Get the length in bytes which is needed to store val as v.
... ...
@@ -422,7 +422,7 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
422 422
         sample_queue_push(&trk->sample_queue, pkt->data, pkt->size, sample);
423 423
 
424 424
     /* Feed the packet to the RTP muxer */
425
-    ff_write_chained(rtp_ctx, 0, pkt, s);
425
+    ff_write_chained(rtp_ctx, 0, pkt, s, 0);
426 426
 
427 427
     /* Fetch the output from the RTP muxer, open a new output buffer
428 428
      * for next time. */
... ...
@@ -960,7 +960,7 @@ int av_get_output_timestamp(struct AVFormatContext *s, int stream,
960 960
 }
961 961
 
962 962
 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
963
-                     AVFormatContext *src)
963
+                     AVFormatContext *src, int interleave)
964 964
 {
965 965
     AVPacket local_pkt;
966 966
     int ret;
... ...
@@ -980,7 +980,8 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
980 980
                                           src->streams[pkt->stream_index]->time_base,
981 981
                                           dst->streams[dst_stream]->time_base);
982 982
 
983
-    ret = av_write_frame(dst, &local_pkt);
983
+    if (interleave) ret = av_interleaved_write_frame(dst, &local_pkt);
984
+    else            ret = av_write_frame(dst, &local_pkt);
984 985
     pkt->buf = local_pkt.buf;
985 986
     pkt->destruct = local_pkt.destruct;
986 987
     return ret;
... ...
@@ -212,7 +212,7 @@ static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)
212 212
     rtsp_st = rt->rtsp_streams[pkt->stream_index];
213 213
     rtpctx = rtsp_st->transport_priv;
214 214
 
215
-    ret = ff_write_chained(rtpctx, 0, pkt, s);
215
+    ret = ff_write_chained(rtpctx, 0, pkt, s, 0);
216 216
     /* ff_write_chained does all the RTP packetization. If using TCP as
217 217
      * transport, rtpctx->pb is only a dyn_packet_buf that queues up the
218 218
      * packets, so we need to send them out on the TCP connection separately.
... ...
@@ -256,7 +256,7 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
256 256
         sap->last_time = now;
257 257
     }
258 258
     rtpctx = s->streams[pkt->stream_index]->priv_data;
259
-    return ff_write_chained(rtpctx, 0, pkt, s);
259
+    return ff_write_chained(rtpctx, 0, pkt, s, 0);
260 260
 }
261 261
 
262 262
 AVOutputFormat ff_sap_muxer = {
... ...
@@ -766,7 +766,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
766 766
            av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
767 767
            av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
768 768
 
769
-    ret = ff_write_chained(seg->avf, pkt->stream_index, pkt, s);
769
+    ret = ff_write_chained(seg->avf, pkt->stream_index, pkt, s, 0);
770 770
 
771 771
 fail:
772 772
     if (pkt->stream_index == seg->reference_stream_index) {
... ...
@@ -593,7 +593,7 @@ static int ism_write_packet(AVFormatContext *s, AVPacket *pkt)
593 593
     }
594 594
 
595 595
     os->packets_written++;
596
-    return ff_write_chained(os->ctx, 0, pkt, s);
596
+    return ff_write_chained(os->ctx, 0, pkt, s, 0);
597 597
 }
598 598
 
599 599
 static int ism_write_trailer(AVFormatContext *s)