Browse code

hls, segment: fix splitting for audio-only streams.

CC:libav-stable@libav.org

Anton Khirnov authored on 2013/04/26 16:54:59
Showing 2 changed files
... ...
@@ -250,18 +250,20 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
250 250
     AVFormatContext *oc = hls->avf;
251 251
     AVStream *st = s->streams[pkt->stream_index];
252 252
     int64_t end_pts = hls->recording_time * hls->number;
253
-    int ret;
253
+    int ret, can_split = 1;
254 254
 
255 255
     if (hls->start_pts == AV_NOPTS_VALUE) {
256 256
         hls->start_pts = pkt->pts;
257 257
         hls->end_pts   = pkt->pts;
258 258
     }
259 259
 
260
-    if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)      &&
261
-        av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
262
-                      end_pts, AV_TIME_BASE_Q) >= 0 &&
263
-        pkt->flags & AV_PKT_FLAG_KEY) {
260
+    if (hls->has_video) {
261
+        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
262
+                    pkt->flags & AV_PKT_FLAG_KEY;
263
+    }
264 264
 
265
+    if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
266
+                                   end_pts, AV_TIME_BASE_Q) >= 0) {
265 267
         ret = append_entry(hls, av_rescale(pkt->pts - hls->end_pts,
266 268
                                            st->time_base.num,
267 269
                                            st->time_base.den));
... ...
@@ -272,13 +272,15 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
272 272
     AVFormatContext *oc = seg->avf;
273 273
     AVStream *st = s->streams[pkt->stream_index];
274 274
     int64_t end_pts = seg->recording_time * seg->number;
275
-    int ret;
275
+    int ret, can_split = 1;
276 276
 
277
-    if ((seg->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
278
-        av_compare_ts(pkt->pts, st->time_base,
279
-                      end_pts, AV_TIME_BASE_Q) >= 0 &&
280
-        pkt->flags & AV_PKT_FLAG_KEY) {
277
+    if (seg->has_video) {
278
+        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
279
+                    pkt->flags & AV_PKT_FLAG_KEY;
280
+    }
281 281
 
282
+    if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,
283
+                                   AV_TIME_BASE_Q) >= 0) {
282 284
         av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n",
283 285
                pkt->stream_index, pkt->pts);
284 286