Browse code

avcodec/wmapro: redone stream selection for XMA1/2

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2017/01/19 20:29:41
Showing 1 changed files
... ...
@@ -1635,7 +1635,7 @@ static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s,
1635 1635
                 num_bits_prev_frame);
1636 1636
 
1637 1637
         /** check for packet loss */
1638
-        if (avctx->codec_id != AV_CODEC_ID_XMA2 && !s->packet_loss &&
1638
+        if (avctx->codec_id == AV_CODEC_ID_WMAPRO && !s->packet_loss &&
1639 1639
             ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1640 1640
             s->packet_loss = 1;
1641 1641
             av_log(avctx, AV_LOG_ERROR,
... ...
@@ -1764,19 +1764,32 @@ static int xma_decode_packet(AVCodecContext *avctx, void *data,
1764 1764
         s->xma[s->current_stream].packet_loss) {
1765 1765
         int bret;
1766 1766
 
1767
-        if (s->xma[0].skip_packets == 0) {
1767
+        if (s->xma[s->current_stream].skip_packets == 0) {
1768
+            ;
1769
+        } else if (s->xma[0].skip_packets == 0 && avctx->channels >= 2) {
1768 1770
             s->current_stream = 0;
1769
-        } else if (s->xma[1].skip_packets == 0) {
1771
+        } else if (s->xma[1].skip_packets == 0 && avctx->channels >= 4) {
1770 1772
             s->current_stream = 1;
1771
-        } else if (s->xma[2].skip_packets == 0) {
1773
+        } else if (s->xma[2].skip_packets == 0 && avctx->channels >= 6) {
1772 1774
             s->current_stream = 2;
1773
-        } else if (s->xma[3].skip_packets == 0) {
1775
+        } else if (s->xma[3].skip_packets == 0 && avctx->channels == 8) {
1774 1776
             s->current_stream = 3;
1775 1777
         } else {
1776
-            s->current_stream++;
1777
-            if (s->current_stream >= avctx->channels / 2)
1778
-                s->current_stream = 0;
1778
+            int min[2];
1779
+
1780
+            min[0] = s->xma[0].skip_packets;
1781
+            min[1] = i = 0;
1782
+
1783
+            for (i = 1; i < avctx->channels / 2; i++) {
1784
+                if (s->xma[i].skip_packets < min[0]) {
1785
+                    min[1] = i;
1786
+                    min[0] = s->xma[i].skip_packets;
1787
+                }
1788
+            }
1789
+
1790
+            s->current_stream = min[1];
1779 1791
         }
1792
+
1780 1793
         for (i = 0; i < avctx->channels / 2; i++) {
1781 1794
             s->xma[i].skip_packets = FFMAX(0, s->xma[i].skip_packets - 1);
1782 1795
         }