[FFmpeg-cvslog] avcodec/rka: add u8 sample format support

Paul B Mahol git at videolan.org
Mon Feb 13 22:14:22 EET 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Feb 13 21:03:13 2023 +0100| [052674f3ce17139de73ea00bb690584240b0478a] | committer: Paul B Mahol

avcodec/rka: add u8 sample format support

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

 libavcodec/rka.c | 89 ++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 54 insertions(+), 35 deletions(-)

diff --git a/libavcodec/rka.c b/libavcodec/rka.c
index 435fd10a3b..f479942832 100644
--- a/libavcodec/rka.c
+++ b/libavcodec/rka.c
@@ -857,26 +857,28 @@ static int rka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (s->channels == 2) {
         int16_t *l16 = (int16_t *)frame->extended_data[0];
         int16_t *r16 = (int16_t *)frame->extended_data[1];
+        uint8_t *l8 = frame->extended_data[0];
+        uint8_t *r8 = frame->extended_data[1];
 
-        switch (avctx->sample_fmt) {
-        case AV_SAMPLE_FMT_S16P:
-            for (int n = 0; n < frame->nb_samples;) {
-                ret = decode_ch_samples(avctx, &s->ch[0]);
-                if (ret == 0) {
-                    frame->nb_samples = n;
-                    break;
-                }
-                if (ret < 0 || n + ret > frame->nb_samples)
-                    return AVERROR_INVALIDDATA;
+        for (int n = 0; n < frame->nb_samples;) {
+            ret = decode_ch_samples(avctx, &s->ch[0]);
+            if (ret == 0) {
+                frame->nb_samples = n;
+                break;
+            }
+            if (ret < 0 || n + ret > frame->nb_samples)
+                return AVERROR_INVALIDDATA;
 
-                ret = decode_ch_samples(avctx, &s->ch[1]);
-                if (ret == 0) {
-                    frame->nb_samples = n;
-                    break;
-                }
-                if (ret < 0 || n + ret > frame->nb_samples)
-                    return AVERROR_INVALIDDATA;
+            ret = decode_ch_samples(avctx, &s->ch[1]);
+            if (ret == 0) {
+                frame->nb_samples = n;
+                break;
+            }
+            if (ret < 0 || n + ret > frame->nb_samples)
+                return AVERROR_INVALIDDATA;
 
+            switch (avctx->sample_fmt) {
+            case AV_SAMPLE_FMT_S16P:
                 for (int i = 0; i < ret; i++) {
                     int l = s->ch[0].buf0[2560 + i];
                     int r = s->ch[1].buf0[2560 + i];
@@ -884,38 +886,55 @@ static int rka_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                     l16[n + i] = (l * 2 + r + 1) >> 1;
                     r16[n + i] = (l * 2 - r + 1) >> 1;
                 }
+                break;
+            case AV_SAMPLE_FMT_U8P:
+                for (int i = 0; i < ret; i++) {
+                    int l = s->ch[0].buf0[2560 + i];
+                    int r = s->ch[1].buf0[2560 + i];
 
-                n += ret;
+                    l8[n + i] = ((l * 2 + r + 1) >> 1) + 0x7f;
+                    r8[n + i] = ((l * 2 - r + 1) >> 1) + 0x7f;
+                }
+                break;
+            default:
+                return AVERROR_INVALIDDATA;
             }
-            break;
-        default:
-            return AVERROR_INVALIDDATA;
+
+            n += ret;
         }
     } else {
         int16_t *m16 = (int16_t *)frame->data[0];
+        uint8_t *m8 = frame->data[0];
 
-        switch (avctx->sample_fmt) {
-        case AV_SAMPLE_FMT_S16P:
-            for (int n = 0; n < frame->nb_samples;) {
-                ret = decode_ch_samples(avctx, &s->ch[0]);
-                if (ret == 0) {
-                    frame->nb_samples = n;
-                    break;
-                }
-                if (ret < 0 || n + ret > frame->nb_samples)
-                    return AVERROR_INVALIDDATA;
+        for (int n = 0; n < frame->nb_samples;) {
+            ret = decode_ch_samples(avctx, &s->ch[0]);
+            if (ret == 0) {
+                frame->nb_samples = n;
+                break;
+            }
+            if (ret < 0 || n + ret > frame->nb_samples)
+                return AVERROR_INVALIDDATA;
 
+            switch (avctx->sample_fmt) {
+            case AV_SAMPLE_FMT_S16P:
                 for (int i = 0; i < ret; i++) {
                     int m = s->ch[0].buf0[2560 + i];
 
                     m16[n + i] = m;
                 }
+                break;
+            case AV_SAMPLE_FMT_U8P:
+                for (int i = 0; i < ret; i++) {
+                    int m = s->ch[0].buf0[2560 + i];
 
-                n += ret;
+                    m8[n + i] = m + 0x7f;
+                }
+                break;
+            default:
+                return AVERROR_INVALIDDATA;
             }
-            break;
-        default:
-            return AVERROR_INVALIDDATA;
+
+            n += ret;
         }
     }
 



More information about the ffmpeg-cvslog mailing list