From d81499ed3d0c7e165845a63464c0051faccd3e43 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Sun, 11 Sep 2011 19:04:51 +0200
Subject: [PATCH 01/15] Support raw dvdsub palette as stored on normal dvd's

This is how the palette is stored on dvd's. Currently
only xbmc passes the palette information to libavcodec
this way.
---
 libavcodec/dvdsubdec.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index ffb2bcc..fc2adde 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -64,6 +64,24 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *
     }
 }
 
+static void ayvu_to_argb(const uint8_t *ayvu, uint32_t *argb, int num_values)
+{
+    uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
+    uint8_t r, g, b;
+    int i, y, cb, cr, a;
+    int r_add, g_add, b_add;
+
+    for (i = num_values; i > 0; i--) {
+        a = *ayvu++;
+        y = *ayvu++;
+        cr = *ayvu++;
+        cb = *ayvu++;
+        YUV_TO_RGB1_CCIR(cb, cr);
+        YUV_TO_RGB2_CCIR(r, g, b, y);
+        *argb++ = (a << 24) | (r << 16) | (g << 8) | b;
+    }
+}
+
 static int decode_run_2bit(GetBitContext *gb, int *color)
 {
     unsigned int v, t;
@@ -707,6 +725,12 @@ static av_cold int dvdsub_init(AVCodecContext *avctx)
         parse_ifo_palette(ctx, ctx->ifo_str);
     if (ctx->palette_str)
         parse_palette(ctx, ctx->palette_str);
+
+    if (!ctx->has_palette && avctx->extradata_size == 64) {
+        ayvu_to_argb((uint8_t*)avctx->extradata, ctx->palette, 16);
+        ctx->has_palette = 1;
+    }
+
     if (ctx->has_palette) {
         int i;
         av_log(avctx, AV_LOG_DEBUG, "palette:");

From 609ed71bf6b1e5e72802b935b44903a266d6d7d4 Mon Sep 17 00:00:00 2001
From: Cory Fields <theuni-nospam-@xbmc.org>
Date: Mon, 28 Jun 2010 01:55:31 -0400
Subject: [PATCH 02/15] if av_read_packet returns AVERROR_IO, we are done.
 ffmpeg's codecs might or might not handle returning any completed demuxed
 packets correctly

---
 libavformat/utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 1467f31..fb0bc21 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1319,6 +1319,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
         if (ret < 0) {
             if (ret == AVERROR(EAGAIN))
                 return ret;
+            if (ret == AVERROR(EIO))
+                return ret;
             /* flush the parsers */
             for (i = 0; i < s->nb_streams; i++) {
                 st = s->streams[i];

From f509b8930a71d1200b1437fb65ff779bbdd1ca86 Mon Sep 17 00:00:00 2001
From: Cory Fields <theuni-nospam-@xbmc.org>
Date: Mon, 28 Jun 2010 02:10:50 -0400
Subject: [PATCH 03/15] added: Ticket #7187, TV Teletext support for DVB EBU
 Teletext streams

---
 libavcodec/avcodec.h | 4 ++++
 libavformat/mpegts.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 575dae1..4ea6e5a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -524,6 +524,10 @@ enum AVCodecID {
     AV_CODEC_ID_PJS        = MKBETAG('P','h','J','S'),
     AV_CODEC_ID_ASS        = MKBETAG('A','S','S',' '),  ///< ASS as defined in Matroska
 
+    /* data codecs */
+    AV_CODEC_ID_VBI_DATA= 0x17500,
+    AV_CODEC_ID_VBI_TELETEXT,
+
     /* other specific kind of codecs (generally used for attachments) */
     AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
     AV_CODEC_ID_TTF = 0x18000,
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 9e9ad47..74a9cc5 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -731,6 +731,8 @@ static const StreamType DESC_types[] = {
     { 0x7b, AVMEDIA_TYPE_AUDIO,    AV_CODEC_ID_DTS          },
     { 0x56, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_DVB_TELETEXT },
     { 0x59, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */
+    { 0x45, AVMEDIA_TYPE_DATA,         AV_CODEC_ID_VBI_DATA }, /* VBI Data descriptor */
+    { 0x46, AVMEDIA_TYPE_DATA,     AV_CODEC_ID_VBI_TELETEXT }, /* VBI Teletext descriptor */
     { 0 },
 };
 

From 43a21520a07cc98957146816db857ea1dd63f926 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Sun, 18 Sep 2011 19:16:34 +0200
Subject: [PATCH 04/15] Don't accept mpegts PMT that isn't current

---
 libavformat/mpegts.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 74a9cc5..3c8d99b 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -573,6 +573,7 @@ typedef struct SectionHeader {
     uint8_t tid;
     uint16_t id;
     uint8_t version;
+    uint8_t current;
     uint8_t sec_num;
     uint8_t last_sec_num;
 } SectionHeader;
@@ -644,6 +645,7 @@ static int parse_section_header(SectionHeader *h,
     val = get8(pp, p_end);
     if (val < 0)
         return val;
+    h->current = val & 0x1;
     h->version = (val >> 1) & 0x1f;
     val = get8(pp, p_end);
     if (val < 0)
@@ -1973,6 +1975,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
         return;
     if (ts->skip_changes)
         return;
+    if (!h->current)
+        return;
 
     ts->stream->ts_id = h->id;
 

From de503ed6757c7e0f09acd032bed04a2414874087 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Sun, 18 Sep 2011 19:17:23 +0200
Subject: [PATCH 05/15] Don't reparse PMT unless it's version has changed

---
 libavformat/mpegts.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 3c8d99b..88e5638 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -87,6 +87,7 @@ struct MpegTSFilter {
     int es_id;
     int last_cc; /* last cc code (-1 if first packet) */
     int64_t last_pcr;
+    int last_version; /* last version of data on this pid */
     enum MpegTSFilterType type;
     union {
         MpegTSPESFilter pes_filter;
@@ -449,6 +450,7 @@ static MpegTSFilter *mpegts_open_filter(MpegTSContext *ts, unsigned int pid,
     filter->es_id   = -1;
     filter->last_cc = -1;
     filter->last_pcr= -1;
+    filter->last_version = -1;
 
     return filter;
 }
@@ -1977,6 +1979,10 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
         return;
     if (!h->current)
         return;
+    if (h->version == filter->last_version)
+        return;
+    filter->last_version = h->version;
+    av_dlog(ts->stream, "version=%d\n", filter->last_version);
 
     ts->stream->ts_id = h->id;
 

From 2905dd6f7acdb839ec0bf20636eae6c4f98058e9 Mon Sep 17 00:00:00 2001
From: Cory Fields <theuni-nospam-@xbmc.org>
Date: Fri, 9 Jul 2010 16:43:31 -0400
Subject: [PATCH 06/15] Read PID timestamps as well as PCR timestamps to find
 location in mpegts stream

---
 libavformat/mpegts.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 88e5638..56cb44f 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2464,6 +2464,44 @@ static void seek_back(AVFormatContext *s, AVIOContext *pb, int64_t pos) {
         av_log(s, pb->seekable ? AV_LOG_ERROR : AV_LOG_INFO, "Unable to seek back to the start\n");
 }
 
+static int parse_timestamp(int64_t *ts, const uint8_t *buf)
+{
+    int afc, flags;
+    const uint8_t *p;
+
+    if(!(buf[1] & 0x40)) /* must be a start packet */
+        return -1;
+
+    afc = (buf[3] >> 4) & 3;
+    p = buf + 4;
+    if (afc == 0 || afc == 2) /* invalid or only adaption field */
+        return -1;
+    if (afc == 3)
+        p += p[0] + 1;
+    if (p >= buf + TS_PACKET_SIZE)
+        return -1;
+
+    if (p[0] != 0x00 || p[1] != 0x00 || p[2] != 0x01)  /* packet_start_code_prefix */
+        return -1;
+
+    flags = p[3] | 0x100; /* stream type */
+    if (!((flags >= 0x1c0 && flags <= 0x1df) ||
+          (flags >= 0x1e0 && flags <= 0x1ef) ||
+          (flags == 0x1bd) || (flags == 0x1fd)))
+        return -1;
+
+    flags = p[7];
+    if ((flags & 0xc0) == 0x80) {
+        *ts = ff_parse_pes_pts(p+9);
+        return 0;
+    } else if ((flags & 0xc0) == 0xc0) {
+        *ts = ff_parse_pes_pts(p+9+5);
+        return 0;
+    }
+    return -1;
+}
+
+
 static int mpegts_read_header(AVFormatContext *s)
 {
     MpegTSContext *ts = s->priv_data;
@@ -2664,6 +2702,7 @@ static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
     uint8_t buf[TS_PACKET_SIZE];
     int pcr_l, pcr_pid =
         ((PESContext *)s->streams[stream_index]->priv_data)->pcr_pid;
+    int pid = ((PESContext*)s->streams[stream_index]->priv_data)->pid;
     int pos47 = ts->pos47_full % ts->raw_packet_size;
     pos =
         ((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) *
@@ -2685,6 +2724,11 @@ static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
             *ppos = pos;
             return timestamp;
         }
+        if ((pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pid) &&
+            parse_timestamp(&timestamp, buf) == 0) {
+            *ppos = pos;
+            return timestamp;
+        }
         pos += ts->raw_packet_size;
     }
 
@@ -2784,7 +2828,7 @@ AVInputFormat ff_mpegts_demuxer = {
     .read_header    = mpegts_read_header,
     .read_packet    = mpegts_read_packet,
     .read_close     = mpegts_read_close,
-    .read_timestamp = mpegts_get_dts,
+    .read_timestamp = mpegts_get_pcr,
     .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
     .priv_class     = &mpegts_class,
 };
@@ -2796,7 +2840,7 @@ AVInputFormat ff_mpegtsraw_demuxer = {
     .read_header    = mpegts_read_header,
     .read_packet    = mpegts_raw_read_packet,
     .read_close     = mpegts_read_close,
-    .read_timestamp = mpegts_get_dts,
+    .read_timestamp = mpegts_get_pcr,
     .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
     .priv_class     = &mpegtsraw_class,
 };

From d8c13412948c24c3b474f4a0f879af795392cb08 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Sat, 22 Oct 2011 19:01:38 +0200
Subject: [PATCH 07/15] Get stream durations using read_timestamp

---
 libavformat/utils.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index fb0bc21..e48e3bb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2384,6 +2384,41 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
 #define DURATION_MAX_READ_SIZE 250000LL
 #define DURATION_MAX_RETRY 4
 
+static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset)
+{
+    AVStream *st;
+    int i, step= 1024;
+    int64_t ts, pos;
+
+    for(i=0;i<ic->nb_streams;i++) {
+        st = ic->streams[i];
+
+        pos = 0;
+        ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE);
+        if (ts == AV_NOPTS_VALUE)
+            continue;
+        if (st->start_time > ts || st->start_time == AV_NOPTS_VALUE)
+            st->start_time = ts;
+
+        pos = avio_size(ic->pb) - 1;
+        do {
+            pos -= step;
+            ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step);
+            step += step;
+        } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE);
+
+        if (ts == AV_NOPTS_VALUE)
+            continue;
+
+        if (st->duration < ts - st->start_time || st->duration == AV_NOPTS_VALUE)
+            st->duration = ts - st->start_time;
+    }
+
+    fill_all_stream_timings(ic);
+
+    avio_seek(ic->pb, old_offset, SEEK_SET);
+}
+
 /* only usable for MPEG-PS streams */
 static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 {
@@ -2534,6 +2569,10 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
          * the components */
         fill_all_stream_timings(ic);
         ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM;
+    } else if (ic->iformat->read_timestamp && 
+        file_size && ic->pb->seekable) {
+        /* get accurate estimate from the PTSes */
+        av_estimate_timings_from_pts2(ic, old_offset);
     } else {
         /* less precise: use bitrate info */
         estimate_timings_from_bit_rate(ic);

From 3815ee4ab3a546d0251f8b4381bdf5c4752b8cee Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Wed, 8 Dec 2010 14:03:43 +0000
Subject: [PATCH 08/15] changed: allow 4 second skew between streams in mov
 before attempting to seek

---
 libavformat/mov.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index de4004f..a5babb7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4189,8 +4189,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
             if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) ||
                 (s->pb->seekable &&
                  ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb &&
-                 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
-                  (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
+                 ((FFABS(best_dts - dts) <= 4*AV_TIME_BASE && current_sample->pos < sample->pos) ||
+                  (FFABS(best_dts - dts) > 4*AV_TIME_BASE && dts < best_dts)))))) {
                 sample = current_sample;
                 best_dts = dts;
                 *st = avst;

From 3d83b4730868612b8aac5f51a85ce61cd18f46c8 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Fri, 26 Nov 2010 20:56:48 +0000
Subject: [PATCH 09/15] fixed: memleak in mpegts demuxer on some malformed (??)
 mpegts files with too large pes packets

at-visions sample file brokenStream.mpg
---
 libavformat/mpegts.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 56cb44f..b68a73a 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -834,6 +834,10 @@ static void reset_pes_packet_state(PESContext *pes)
 
 static void new_pes_packet(PESContext *pes, AVPacket *pkt)
 {
+    if(pkt->data) {
+      av_log(pes->stream, AV_LOG_ERROR, "ignoring previously allocated packet on stream %d\n", pkt->stream_index);
+      av_free_packet(pkt);
+    }
     av_init_packet(pkt);
 
     pkt->buf  = pes->buffer;
@@ -2655,6 +2659,8 @@ static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->size = -1;
     ts->pkt = pkt;
+    ts->pkt->data = NULL;
+
     ret = handle_packets(ts, 0);
     if (ret < 0) {
         av_free_packet(ts->pkt);

From bdf8c821a63ff30681ee2a18de1f7774d7611d27 Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Mon, 28 Jun 2010 21:26:54 +0000
Subject: [PATCH 10/15] Speed up mpegts av_find_stream_info

---
 libavformat/mpegts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b68a73a..336d869 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -996,7 +996,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
                         goto skip;
 
                     /* stream not present in PMT */
-                    if (!pes->st) {
+                    if (ts->auto_guess && !pes->st) {
                         if (ts->skip_changes)
                             goto skip;
 

From 23e9ea7c3964417e15b83745d2fd6341952cc4a3 Mon Sep 17 00:00:00 2001
From: marc <mhocking@ubuntu-desktop.(none)>
Date: Mon, 18 Feb 2013 17:18:18 +0000
Subject: [PATCH 11/15] dxva-h264 Fix dxva playback of streams that don't start
 with an I-Frame.

---
 libavcodec/dxva2_h264.c | 8 ++++++++
 libavcodec/h264.c       | 1 +
 libavcodec/h264.h       | 2 ++
 libavcodec/h264_slice.c | 1 +
 4 files changed, 12 insertions(+)

diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index 6deccc3..85b25fd 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -451,6 +451,14 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx)
 
     if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
         return -1;
+
+    // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs
+    if (!h->got_first_iframe) {
+        if (!(ctx_pic->pp.wBitFields & (1 << 15)))
+            return -1;
+        h->got_first_iframe = 1;
+    }
+
     ret = ff_dxva2_common_end_frame(avctx, &h->cur_pic_ptr->f,
                                     &ctx_pic->pp, sizeof(ctx_pic->pp),
                                     &ctx_pic->qm, sizeof(ctx_pic->qm),
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index a32366e..cbb5385 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1093,6 +1093,7 @@ void ff_h264_flush_change(H264Context *h)
     h->list_count = 0;
     h->current_slice = 0;
     h->mmco_reset = 1;
+    h->got_first_iframe = 0;
 }
 
 /* forget old pics after a seek */
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index b260d55..5cb7851 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -741,6 +741,8 @@ typedef struct H264Context {
     int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
     int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
 
+    int got_first_iframe;
+
     // Timestamp stuff
     int sei_buffering_period_present;   ///< Buffering period SEI flag
     int initial_cpb_removal_delay[32];  ///< Initial timestamps for CPBs
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index d8b7bc7..5f80858 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1175,6 +1175,7 @@ static int h264_slice_header_init(H264Context *h, int reinit)
         ff_h264_free_tables(h, 0);
     h->first_field           = 0;
     h->prev_interlaced_frame = 1;
+    h->got_first_iframe = 0;
 
     init_scan_tables(h);
     ret = ff_h264_alloc_tables(h);

From d3112c920a04c24f4b92ab0f67a4275ff4a0c64f Mon Sep 17 00:00:00 2001
From: wsnipex <wsnipex@a1.net>
Date: Mon, 16 Feb 2015 09:58:28 +0100
Subject: [PATCH 12/15] only check for a git rev if the src tree is in a git
 repo

fixes the version string when building from the kodi depends src tree
---
 version.sh | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/version.sh b/version.sh
index f9754eb..cc23f80 100755
--- a/version.sh
+++ b/version.sh
@@ -2,30 +2,32 @@
 
 # Usage: version.sh <ffmpeg-root-dir> <output-version.h> <extra-version>
 
+if [ -d $1/.git ]; then  # only check for a git rev, if the src tree is in a git repo
 # check for git short hash
-if ! test "$revision"; then
+  if ! test "$revision"; then
     if (cd "$1" && grep git RELEASE 2> /dev/null >/dev/null) ; then
         revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
     else
         revision=$(cd "$1" && git describe --tags --always 2> /dev/null)
     fi
-fi
+  fi
+
+  # Shallow Git clones (--depth) do not have the N tag:
+  # use 'git-YYYY-MM-DD-hhhhhhh'.
+  test "$revision" || revision=$(cd "$1" &&
+    git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
 
-# Shallow Git clones (--depth) do not have the N tag:
-# use 'git-YYYY-MM-DD-hhhhhhh'.
-test "$revision" || revision=$(cd "$1" &&
-  git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
-
-# Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
-# ffmpeg-HEAD-hhhhhhh.
-if [ -z "$revision" ]; then
-  srcdir=$(cd "$1" && pwd)
-  case "$srcdir" in
-    */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
-      git_hash="${srcdir##*-}";;
-    */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
-      git_hash="${srcdir##*-}";;
-  esac
+  # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
+  # ffmpeg-HEAD-hhhhhhh.
+  if [ -z "$revision" ]; then
+    srcdir=$(cd "$1" && pwd)
+    case "$srcdir" in
+      */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
+        git_hash="${srcdir##*-}";;
+      */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
+        git_hash="${srcdir##*-}";;
+    esac
+  fi
 fi
 
 # no revision number found

From 3bb6304898994e4278263edd879f07e59ab1fd6f Mon Sep 17 00:00:00 2001
From: Rainer Hochecker <fernetmenta@online.de>
Date: Thu, 12 Mar 2015 12:49:48 +0100
Subject: [PATCH 13/15] hevc: avoid unnecessary calls to get_format

---
 libavcodec/hevc.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index b7ad29a..77b0c0c 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -280,7 +280,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
     return 0;
 }
 
-static int set_sps(HEVCContext *s, const HEVCSPS *sps)
+static int set_sps(HEVCContext *s, const HEVCSPS *sps, enum AVPixelFormat pix_fmt)
 {
     #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL)
     enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
@@ -304,13 +304,18 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 #endif
     }
 
-    *fmt++ = sps->pix_fmt;
-    *fmt = AV_PIX_FMT_NONE;
+    if (pix_fmt == AV_PIX_FMT_NONE) {
+        *fmt++ = sps->pix_fmt;
+        *fmt = AV_PIX_FMT_NONE;
 
-    ret = ff_thread_get_format(s->avctx, pix_fmts);
-    if (ret < 0)
-        goto fail;
-    s->avctx->pix_fmt = ret;
+        ret = ff_thread_get_format(s->avctx, pix_fmts);
+        if (ret < 0)
+            goto fail;
+        s->avctx->pix_fmt = ret;
+    }
+    else {
+        s->avctx->pix_fmt = pix_fmt;
+    }
 
     ff_set_sar(s->avctx, sps->vui.sar);
 
@@ -420,7 +425,7 @@ static int hls_slice_header(HEVCContext *s)
                 sh->no_output_of_prior_pics_flag = 0;
         }
         ff_hevc_clear_refs(s);
-        ret = set_sps(s, s->sps);
+        ret = set_sps(s, s->sps, AV_PIX_FMT_NONE);
         if (ret < 0)
             return ret;
 
@@ -3335,7 +3340,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
     }
 
     if (s->sps != s0->sps)
-        if ((ret = set_sps(s, s0->sps)) < 0)
+        if ((ret = set_sps(s, s0->sps, src->pix_fmt)) < 0)
             return ret;
 
     s->seq_decode = s0->seq_decode;

From 5eac38c7f2593c2e8aced6907e4f283f91e48691 Mon Sep 17 00:00:00 2001
From: Rainer Hochecker <fernetmenta@online.de>
Date: Thu, 2 Apr 2015 13:43:06 +0200
Subject: [PATCH 14/15] vda: fix h264 decoding for avcC,vda wants the entire
 buffer

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
---
 libavcodec/h264.c     |  2 +-
 libavcodec/vda_h264.c | 20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index cbb5385..6529d98 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1596,7 +1596,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
                         decode_postinit(h, nal_index >= nals_needed);
 
                     if (h->avctx->hwaccel &&
-                        (ret = h->avctx->hwaccel->start_frame(h->avctx, NULL, 0)) < 0)
+                        (ret = h->avctx->hwaccel->start_frame(h->avctx, buf, buf_size)) < 0)
                         return ret;
                     if (CONFIG_H264_VDPAU_DECODER &&
                         h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
diff --git a/libavcodec/vda_h264.c b/libavcodec/vda_h264.c
index 081c366..b6b9ab4 100644
--- a/libavcodec/vda_h264.c
+++ b/libavcodec/vda_h264.c
@@ -320,9 +320,20 @@ static int vda_h264_start_frame(AVCodecContext *avctx,
                                 uint32_t size)
 {
     VDAContext *vda = avctx->internal->hwaccel_priv_data;
-
-    vda->bitstream_size = 0;
-
+    H264Context *h  = avctx->priv_data;
+
+    if (h->is_avc == 1) {
+        void *tmp;
+        vda->bitstream_size = 0;
+        tmp = av_fast_realloc(vda->bitstream,
+                              &vda->allocated_size,
+                              size);
+        vda->bitstream = tmp;
+        memcpy(vda->bitstream, buffer, size);
+        vda->bitstream_size = size;
+    } else {
+        vda->bitstream_size = 0;
+    }
     return 0;
 }
 
@@ -333,6 +344,9 @@ static int vda_h264_decode_slice(AVCodecContext *avctx,
     VDAContext *vda       = avctx->internal->hwaccel_priv_data;
     void *tmp;
 
+    if (h->is_avc == 1)
+        return 0;
+
     tmp = av_fast_realloc(vda->bitstream,
                           &vda->allocated_size,
                           vda->bitstream_size + size + 4);

From e1bde78b7cc95cb13da6c91555d141e37a85b692 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Thu, 2 Apr 2015 15:58:02 +0200
Subject: [PATCH 15/15] avcodec/vda_h264: try to fix build

Found-by: Stefano Pigozzi
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
---
 libavcodec/vda_h264.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/vda_h264.c b/libavcodec/vda_h264.c
index b6b9ab4..2a18330 100644
--- a/libavcodec/vda_h264.c
+++ b/libavcodec/vda_h264.c
@@ -342,6 +342,7 @@ static int vda_h264_decode_slice(AVCodecContext *avctx,
                                  uint32_t size)
 {
     VDAContext *vda       = avctx->internal->hwaccel_priv_data;
+    H264Context *h  = avctx->priv_data;
     void *tmp;
 
     if (h->is_avc == 1)
