[FFmpeg-cvslog] avcodec/mips: [loongson] refine optimization in h264_chroma.

2018-11-30 Thread Shiyou Yin
ffmpeg | branch: master | Shiyou Yin  | Tue Nov  6 
08:59:13 2018 +0800| [5982614af1f564ac05c1aa535cbd12cbbb2aa526] | committer: 
Michael Niedermayer

avcodec/mips: [loongson] refine optimization in h264_chroma.

Remove invalid operation in the case x and y all equal 0,
this refine made about 2% speedup for H264 decode on loongson platform.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5982614af1f564ac05c1aa535cbd12cbbb2aa526
---

 libavcodec/mips/h264chroma_mmi.c | 970 +--
 1 file changed, 426 insertions(+), 544 deletions(-)

diff --git a/libavcodec/mips/h264chroma_mmi.c b/libavcodec/mips/h264chroma_mmi.c
index 91b2cc470d..739dd7d4d6 100644
--- a/libavcodec/mips/h264chroma_mmi.c
+++ b/libavcodec/mips/h264chroma_mmi.c
@@ -30,74 +30,177 @@ void ff_put_h264_chroma_mc8_mmi(uint8_t *dst, uint8_t 
*src, ptrdiff_t stride,
 int h, int x, int y)
 {
 int A = 64, B, C, D, E;
-double ftmp[10];
+double ftmp[12];
 uint64_t tmp[1];
 
 if (!(x || y)) {
 /* x=0, y=0, A=64 */
 __asm__ volatile (
-"xor%[ftmp0],   %[ftmp0],   %[ftmp0]   \n\t"
-"dli%[tmp0],0x06   \n\t"
-"mtc1   %[tmp0],%[ftmp4]   \n\t"
-
 "1:\n\t"
+MMI_ULDC1(%[ftmp0], %[src], 0x00)
+PTR_ADDU   "%[src], %[src], %[stride]  \n\t"
 MMI_ULDC1(%[ftmp1], %[src], 0x00)
-"addi   %[h],   %[h],   -0x04  \n\t"
 PTR_ADDU   "%[src], %[src], %[stride]  \n\t"
-MMI_ULDC1(%[ftmp5], %[src], 0x00)
+MMI_ULDC1(%[ftmp2], %[src], 0x00)
 PTR_ADDU   "%[src], %[src], %[stride]  \n\t"
-MMI_ULDC1(%[ftmp6], %[src], 0x00)
+MMI_ULDC1(%[ftmp3], %[src], 0x00)
 PTR_ADDU   "%[src], %[src], %[stride]  \n\t"
-MMI_ULDC1(%[ftmp7], %[src], 0x00)
 
-"punpcklbh  %[ftmp2],   %[ftmp1],   %[ftmp0]   \n\t"
-"punpckhbh  %[ftmp3],   %[ftmp1],   %[ftmp0]   \n\t"
-"psllh  %[ftmp1],   %[ftmp2],   %[ftmp4]   \n\t"
-"psllh  %[ftmp2],   %[ftmp3],   %[ftmp4]   \n\t"
-"paddh  %[ftmp1],   %[ftmp1],   %[ff_pw_32]\n\t"
-"paddh  %[ftmp2],   %[ftmp2],   %[ff_pw_32]\n\t"
-"psrlh  %[ftmp1],   %[ftmp1],   %[ftmp4]   \n\t"
-"psrlh  %[ftmp2],   %[ftmp2],   %[ftmp4]   \n\t"
-"packushb   %[ftmp1],   %[ftmp1],   %[ftmp2]   \n\t"
-MMI_SDC1(%[ftmp1], %[dst], 0x00)
+"addi   %[h],   %[h],   -0x04  \n\t"
 
-"punpcklbh  %[ftmp2],   %[ftmp5],   %[ftmp0]   \n\t"
-"punpckhbh  %[ftmp3],   %[ftmp5],   %[ftmp0]   \n\t"
-"psllh  %[ftmp1],   %[ftmp2],   %[ftmp4]   \n\t"
-"psllh  %[ftmp2],   %[ftmp3],   %[ftmp4]   \n\t"
-"paddh  %[ftmp1],   %[ftmp1],   %[ff_pw_32]\n\t"
-"paddh  %[ftmp2],   %[ftmp2],   %[ff_pw_32]\n\t"
-"psrlh  %[ftmp1],   %[ftmp1],   %[ftmp4]   \n\t"
-"psrlh  %[ftmp2],   %[ftmp2],   %[ftmp4]   \n\t"
-"packushb   %[ftmp1],   %[ftmp1],   %[ftmp2]   \n\t"
+MMI_SDC1(%[ftmp0], %[dst], 0x00)
 PTR_ADDU   "%[dst], %[dst], %[stride]  \n\t"
 MMI_SDC1(%[ftmp1], %[dst], 0x00)
+PTR_ADDU   "%[dst], %[dst], %[stride]  \n\t"
+MMI_SDC1(%[ftmp2], %[dst], 0x00)
+PTR_ADDU   "%[dst], %[dst], %[stride]  \n\t"
+MMI_SDC1(%[ftmp3], %[dst], 0x00)
+PTR_ADDU   "%[dst], %[dst], %[stride]  \n\t"
+"bnez   %[h],   1b \n\t"
+: [ftmp0]"="(ftmp[0]),[ftmp1]"="(ftmp[1]),
+  [ftmp2]"="(ftmp[2]),[ftmp3]"="(ftmp[3]),
+  [dst]"+"(dst),  [src]"+"(src),
+  [h]"+"(h)
+: [stride]"r"((mips_reg)stride)
+: "memory"
+);
+} else if (x && y) {
+/* x!=0, y!=0 */
+D = x * y;
+B = (x << 3) - D;
+C = (y << 3) - D;
+A = 64 - D - B - C;
 
-"punpcklbh  %[ftmp2],   %[ftmp6],   %[ftmp0]   \n\t"
-"punpckhbh  %[ftmp3],   %[ftmp6],   %[ftmp0]   \n\t"
-"psllh  %[ftmp1],   %[ftmp2],   %[ftmp4]   \n\t"
-"psllh  %[ftmp2],   %[ftmp3], 

[FFmpeg-cvslog] avcodec/hevcdec: Check for overlapping slices

2018-11-30 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Fri 
Nov 16 20:03:01 2018 +0100| [1a89ae1df8585134b9524f736b71cee98de7895a] | 
committer: Michael Niedermayer

avcodec/hevcdec: Check for overlapping slices

Fixes: Timeout
Fixes: 
10108/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-6222384351674368

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1a89ae1df8585134b9524f736b71cee98de7895a
---

 libavcodec/hevcdec.c | 4 
 libavcodec/hevcdec.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index a3b5c8cb71..10bf2563c0 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2942,6 +2942,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 s->max_ra = INT_MIN;
 }
 
+s->overlap ++;
 ret = hevc_frame_start(s);
 if (ret < 0)
 return ret;
@@ -3020,6 +3021,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 s->ref = NULL;
 s->last_eos = s->eos;
 s->eos = 0;
+s->overlap = 0;
 
 /* split the input packet into NAL units, so we know the upper bound on the
  * number of slices in the frame */
@@ -3054,6 +3056,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 continue;
 
 ret = decode_nal_unit(s, nal);
+if (ret >= 0 && s->overlap > 2)
+ret = AVERROR_INVALIDDATA;
 if (ret < 0) {
 av_log(s->avctx, AV_LOG_WARNING,
"Error parsing NAL unit #%d.\n", i);
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index dd951aae06..b45969b7e2 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -430,6 +430,7 @@ typedef struct HEVCContext {
 int max_ra;
 int bs_width;
 int bs_height;
+int overlap;
 
 int is_decoded;
 int no_rasl_output_flag;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/truemotion2rt: Fix rounding in input size check

2018-11-30 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Nov 17 09:24:30 2018 +0100| [7f22a4ebc97817fd0968f5ea8295c9a59a6292e0] | 
committer: Michael Niedermayer

avcodec/truemotion2rt: Fix rounding in input size check

Fixes: Timeout
Fixes: 
11332/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TRUEMOTION2RT_fuzzer-5678456612847616

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7f22a4ebc97817fd0968f5ea8295c9a59a6292e0
---

 libavcodec/truemotion2rt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/truemotion2rt.c b/libavcodec/truemotion2rt.c
index 9df0b527bb..e3ab998fda 100644
--- a/libavcodec/truemotion2rt.c
+++ b/libavcodec/truemotion2rt.c
@@ -116,7 +116,7 @@ static int truemotion2rt_decode_frame(AVCodecContext 
*avctx, void *data,
 if (ret < 0)
 return ret;
 
-if (avctx->width / s->hscale * avctx->height * s->delta_size > avpkt->size 
* 8LL * 4)
+if ((avctx->width + s->hscale - 1)/ s->hscale * avctx->height * 
s->delta_size > avpkt->size * 8LL * 4)
 return AVERROR_INVALIDDATA;
 
 ret = init_get_bits8(gb, avpkt->data + ret, avpkt->size - ret);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] configure: enable mipsfpu for loongson platform.

2018-11-30 Thread Shiyou Yin
ffmpeg | branch: master | Shiyou Yin  | Thu Nov 29 
17:39:41 2018 +0800| [5c806d5b54a7a261569b4d3c2053a321dcf4445f] | committer: 
Michael Niedermayer

configure: enable mipsfpu for loongson platform.

mipsfpu supported by loongson 3a2000,3a3000,3a4000,2k1000, Fate tests passed.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5c806d5b54a7a261569b4d3c2053a321dcf4445f
---

 configure | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configure b/configure
index 3e9222ed1b..54b7e1119b 100755
--- a/configure
+++ b/configure
@@ -4848,7 +4848,6 @@ elif enabled mips; then
 enable fast_cmov
 enable fast_unaligned
 disable aligned_stack
-disable mipsfpu
 disable mipsdsp
 disable mipsdspr2
 # When gcc version less than 5.3.0, add 
-fno-expensive-optimizations flag.

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avformat/ac3dec: always skip junk bytes before sync bytes

2018-11-30 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Nov 25 12:15:51 
2018 +0100| [f09bbb8f087dc1780ce1fe236a7e27ae4e49fb14] | committer: Paul B Mahol

avformat/ac3dec: always skip junk bytes before sync bytes

Fixes #7278.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f09bbb8f087dc1780ce1fe236a7e27ae4e49fb14
---

 libavcodec/ac3dec.c  | 20 +---
 libavformat/ac3dec.c |  2 +-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 43b22b7654..71419458fa 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1467,7 +1467,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void 
*data,
 int buf_size, full_buf_size = avpkt->size;
 AC3DecodeContext *s = avctx->priv_data;
 int blk, ch, err, offset, ret;
-int got_independent_frame = 0;
+int skip = 0, got_independent_frame = 0;
 const uint8_t *channel_map;
 uint8_t extended_channel_map[EAC3_MAX_CHANNELS];
 const SHORTFLOAT *output[AC3_MAX_CHANNELS];
@@ -1477,6 +1477,14 @@ static int ac3_decode_frame(AVCodecContext * avctx, void 
*data,
 s->superframe_size = 0;
 
 buf_size = full_buf_size;
+while (buf_size > 2) {
+if (AV_RB16(buf) != 0x770B && AV_RL16(buf) != 0x770B) {
+buf += 1;
+buf_size -= 1;
+continue;
+}
+break;
+}
 /* copy input buffer to decoder context to avoid reading past the end
of the buffer, which can be caused by a damaged input stream. */
 if (buf_size >= 2 && AV_RB16(buf) == 0x770B) {
@@ -1637,6 +1645,11 @@ dependent_frame:
 AC3HeaderInfo hdr;
 int err;
 
+if (buf_size - s->frame_size <= 16) {
+skip = buf_size - s->frame_size;
+goto skip;
+}
+
 if ((ret = init_get_bits8(>gbc, buf + s->frame_size, buf_size - 
s->frame_size)) < 0)
 return ret;
 
@@ -1657,6 +1670,7 @@ dependent_frame:
 }
 }
 }
+skip:
 
 frame->decode_error_flags = err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0;
 
@@ -1796,9 +1810,9 @@ dependent_frame:
 *got_frame_ptr = 1;
 
 if (!s->superframe_size)
-return FFMIN(full_buf_size, s->frame_size);
+return FFMIN(full_buf_size, s->frame_size + skip);
 
-return FFMIN(full_buf_size, s->superframe_size);
+return FFMIN(full_buf_size, s->superframe_size + skip);
 }
 
 /**
diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 6f423ff7eb..2718061bdc 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -47,7 +47,7 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID 
expected_codec_id)
 uint16_t frame_size;
 int i, ret;
 
-if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8)) {
+if(!memcmp(buf2, "\x1\x10", 2)) {
 if (buf2 + 16 > end)
 break;
 buf2+=16;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] lavc/qsvenc: assert uninitialized pict_type

2018-11-30 Thread Linjie Fu
ffmpeg | branch: master | Linjie Fu  | Wed Nov 28 10:41:55 
2018 +0800| [67cdfcf694f840d215be940f82545c45c9be193a] | committer: Zhong Li

lavc/qsvenc: assert uninitialized pict_type

Assert in function ff_qsv_encode to avoid using uninitialized value:

FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pict_type = pict_type;
FF_ENABLE_DEPRECATION_WARNINGS

Signed-off-by: Linjie Fu 
Signed-off-by: Zhong Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=67cdfcf694f840d215be940f82545c45c9be193a
---

 libavcodec/qsvenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3946c1d837..7f4592f878 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1337,6 +1337,8 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 pict_type = AV_PICTURE_TYPE_P;
 else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & 
MFX_FRAMETYPE_xB)
 pict_type = AV_PICTURE_TYPE_B;
+else
+av_assert0(!"Uninitialized pict_type!");
 
 #if FF_API_CODED_FRAME
 FF_DISABLE_DEPRECATION_WARNINGS

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] lavc/qsvenc: add forced_idr option

2018-11-30 Thread Zhong Li
ffmpeg | branch: master | Zhong Li  | Thu Nov 29 16:29:00 
2018 +0800| [ac0bcd6b619479d56612b3938e8f00f5b88c0f10] | committer: Zhong Li

lavc/qsvenc: add forced_idr option

This option can be used to repect original input I/IDR frame type.

Reviewed-by: Mark Thompson 
Signed-off-by: Zhong Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ac0bcd6b619479d56612b3938e8f00f5b88c0f10
---

 libavcodec/qsvenc.c | 7 +++
 libavcodec/qsvenc.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 948751daf4..3946c1d837 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1192,6 +1192,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 if (qsv_frame) {
 surf = _frame->surface;
 enc_ctrl = _frame->enc_ctrl;
+memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl));
+
+if (frame->pict_type == AV_PICTURE_TYPE_I) {
+enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
+if (q->forced_idr)
+enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
+}
 }
 
 ret = av_new_packet(_pkt, q->packet_size);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 055b4a60fa..fbdc19900d 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -87,6 +87,7 @@
 { "adaptive_i", "Adaptive I-frame placement", 
OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_b", "Adaptive B-frame placement", 
OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
+{ "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,  1, VE 
}, \
 
 typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
  const AVFrame *frame, mfxEncodeCtrl* enc_ctrl);
@@ -168,6 +169,7 @@ typedef struct QSVEncContext {
 #endif
 char *load_plugins;
 SetEncodeCtrlCB *set_encode_ctrl_cb;
+int forced_idr;
 } QSVEncContext;
 
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] lavc/qsvenc: enable ICQ and ICQ_LA on Linux

2018-11-30 Thread Zhong Li
ffmpeg | branch: master | Zhong Li  | Thu Nov 29 16:28:59 
2018 +0800| [518b963d2c99ad03570b3224f76a1224c62e66e9] | committer: Zhong Li

lavc/qsvenc: enable ICQ and ICQ_LA on Linux

ICQ/ICQ_LA are enabled with MSDK V1.28

Reviewed-by: Mark Thompson 
Signed-off-by: Zhong Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=518b963d2c99ad03570b3224f76a1224c62e66e9
---

 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 50cc4267e7..055b4a60fa 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -53,7 +53,7 @@
 #define QSV_HAVE_MF 0
 #else
 #define QSV_HAVE_AVBR   0
-#define QSV_HAVE_ICQ0
+#define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   0
 #define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avformat/dashdec: add subtitle stream support

2018-11-30 Thread Steven Liu
ffmpeg | branch: master | Steven Liu  | Fri Nov 30 
16:39:19 2018 +0800| [ba71ebbbfa16f965477f40cf10ca1af5d6bc477d] | committer: 
Steven Liu

avformat/dashdec: add subtitle stream support

Signed-off-by: Steven Liu 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ba71ebbbfa16f965477f40cf10ca1af5d6bc477d
---

 libavformat/dashdec.c | 97 +++
 1 file changed, 90 insertions(+), 7 deletions(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index cf603bf075..1deb60ff21 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -140,6 +140,8 @@ typedef struct DASHContext {
 struct representation **videos;
 int n_audios;
 struct representation **audios;
+int n_subtitles;
+struct representation **subtitles;
 
 /* MediaPresentationDescription Attribute */
 uint64_t media_presentation_duration;
@@ -394,6 +396,17 @@ static void free_audio_list(DASHContext *c)
 c->n_audios = 0;
 }
 
+static void free_subtitle_list(DASHContext *c)
+{
+int i;
+for (i = 0; i < c->n_subtitles; i++) {
+struct representation *pls = c->subtitles[i];
+free_representation(pls);
+}
+av_freep(>subtitles);
+c->n_subtitles = 0;
+}
+
 static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
 AVDictionary *opts, AVDictionary *opts2, int *is_http)
 {
@@ -565,6 +578,8 @@ static enum AVMediaType get_content_type(xmlNodePtr node)
 type = AVMEDIA_TYPE_VIDEO;
 } else if (av_stristr((const char *)val, "audio")) {
 type = AVMEDIA_TYPE_AUDIO;
+} else if (av_stristr((const char *)val, "text")) {
+type = AVMEDIA_TYPE_SUBTITLE;
 }
 xmlFree(val);
 }
@@ -818,6 +833,7 @@ static int parse_manifest_representation(AVFormatContext 
*s, const char *url,
  xmlNodePtr 
adaptionset_supplementalproperty_node)
 {
 int32_t ret = 0;
+int32_t subtitle_rep_idx = 0;
 int32_t audio_rep_idx = 0;
 int32_t video_rep_idx = 0;
 DASHContext *c = s->priv_data;
@@ -854,7 +870,7 @@ static int parse_manifest_representation(AVFormatContext 
*s, const char *url,
 type = get_content_type(adaptionset_node);
 if (type == AVMEDIA_TYPE_UNKNOWN) {
 av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported 
representation type\n", url);
-} else if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) {
+} else if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || 
type == AVMEDIA_TYPE_SUBTITLE) {
 // convert selected representation to our internal struct
 rep = av_mallocz(sizeof(struct representation));
 if (!rep) {
@@ -1048,18 +1064,29 @@ static int 
parse_manifest_representation(AVFormatContext *s, const char *url,
 av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate 
'%s'\n", rep_framerate_val);
 }
 
-if (type == AVMEDIA_TYPE_VIDEO) {
-rep->rep_idx = video_rep_idx;
-dynarray_add(>videos, >n_videos, rep);
-} else {
-rep->rep_idx = audio_rep_idx;
-dynarray_add(>audios, >n_audios, rep);
+switch (type) {
+case AVMEDIA_TYPE_VIDEO:
+rep->rep_idx = video_rep_idx;
+dynarray_add(>videos, >n_videos, rep);
+break;
+case AVMEDIA_TYPE_AUDIO:
+rep->rep_idx = audio_rep_idx;
+dynarray_add(>audios, >n_audios, rep);
+break;
+case AVMEDIA_TYPE_SUBTITLE:
+rep->rep_idx = subtitle_rep_idx;
+dynarray_add(>subtitles, >n_subtitles, rep);
+break;
+default:
+av_log(s, AV_LOG_WARNING, "Unsupported the stream type 
%d\n", type);
+break;
 }
 }
 }
 
 video_rep_idx += type == AVMEDIA_TYPE_VIDEO;
 audio_rep_idx += type == AVMEDIA_TYPE_AUDIO;
+subtitle_rep_idx += type == AVMEDIA_TYPE_SUBTITLE;
 
 end:
 if (rep_id_val)
@@ -1441,6 +1468,8 @@ static int refresh_manifest(AVFormatContext *s)
 struct representation **videos = c->videos;
 int n_audios = c->n_audios;
 struct representation **audios = c->audios;
+int n_subtitles = c->n_subtitles;
+struct representation **subtitles = c->subtitles;
 char *base_url = c->base_url;
 
 c->base_url = NULL;
@@ -1448,6 +1477,8 @@ static int refresh_manifest(AVFormatContext *s)
 c->videos = NULL;
 c->n_audios = 0;
 c->audios = NULL;
+c->n_subtitles = 0;
+c->subtitles = NULL;
 ret = parse_manifest(s, s->url, NULL);
 if (ret)
 goto finish;
@@ -1464,6 +1495,12 @@ static int refresh_manifest(AVFormatContext *s)
n_audios,