Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19abd4d4 authored by Kris Alder's avatar Kris Alder Committed by Gerrit Code Review
Browse files

Merge changes I14498bf3,I719fc648,Iaea9338a

* changes:
  Added g711alaw_dec_fuzzer and g711mlaw_dec_fuzzer
  g711dec: Add host support
  Separate g711 decoder from Codec2 plugin
parents 04f759bf 81747aa7
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -7,6 +7,8 @@ cc_library_shared {


    srcs: ["C2SoftG711Dec.cpp"],
    srcs: ["C2SoftG711Dec.cpp"],


    static_libs: ["codecs_g711dec"],

    cflags: [
    cflags: [
        "-DALAW",
        "-DALAW",
    ],
    ],
@@ -20,4 +22,6 @@ cc_library_shared {
    ],
    ],


    srcs: ["C2SoftG711Dec.cpp"],
    srcs: ["C2SoftG711Dec.cpp"],

    static_libs: ["codecs_g711dec"],
}
}
+1 −48
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@


#include <C2PlatformSupport.h>
#include <C2PlatformSupport.h>
#include <SimpleC2Interface.h>
#include <SimpleC2Interface.h>

#include <g711Dec.h>
#include "C2SoftG711Dec.h"
#include "C2SoftG711Dec.h"


namespace android {
namespace android {
@@ -224,53 +224,6 @@ c2_status_t C2SoftG711Dec::drain(
    return C2_OK;
    return C2_OK;
}
}


#ifdef ALAW
void C2SoftG711Dec::DecodeALaw(
        int16_t *out, const uint8_t *in, size_t inSize) {
    while (inSize > 0) {
        inSize--;
        int32_t x = *in++;

        int32_t ix = x ^ 0x55;
        ix &= 0x7f;

        int32_t iexp = ix >> 4;
        int32_t mant = ix & 0x0f;

        if (iexp > 0) {
            mant += 16;
        }

        mant = (mant << 4) + 8;

        if (iexp > 1) {
            mant = mant << (iexp - 1);
        }

        *out++ = (x > 127) ? mant : -mant;
    }
}
#else
void C2SoftG711Dec::DecodeMLaw(
        int16_t *out, const uint8_t *in, size_t inSize) {
    while (inSize > 0) {
        inSize--;
        int32_t x = *in++;

        int32_t mantissa = ~x;
        int32_t exponent = (mantissa >> 4) & 7;
        int32_t segment = exponent + 1;
        mantissa &= 0x0f;

        int32_t step = 4 << segment;

        int32_t abs = (0x80l << exponent) + step * mantissa + step / 2 - 4 * 33;

        *out++ = (x < 0x80) ? -abs : abs;
    }
}
#endif

class C2SoftG711DecFactory : public C2ComponentFactory {
class C2SoftG711DecFactory : public C2ComponentFactory {
public:
public:
    C2SoftG711DecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
    C2SoftG711DecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
+0 −6
Original line number Original line Diff line number Diff line
@@ -45,12 +45,6 @@ private:
    std::shared_ptr<IntfImpl> mIntf;
    std::shared_ptr<IntfImpl> mIntf;
    bool mSignalledOutputEos;
    bool mSignalledOutputEos;


#ifdef ALAW
    void DecodeALaw(int16_t *out, const uint8_t *in, size_t inSize);
#else
    void DecodeMLaw(int16_t *out, const uint8_t *in, size_t inSize);
#endif

    C2_DO_NOT_COPY(C2SoftG711Dec);
    C2_DO_NOT_COPY(C2SoftG711Dec);
};
};


+45 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

cc_library_static {
    name: "codecs_g711dec",
    vendor_available: true,
    host_supported: true,

    srcs: [
        "g711DecAlaw.cpp",
        "g711DecMlaw.cpp",
    ],

    export_include_dirs: ["."],

    cflags: ["-Werror"],

    sanitize: {
        misc_undefined: [
            "signed-integer-overflow",
            "unsigned-integer-overflow",
        ],
        cfi: true,
    },
    apex_available: ["com.android.media.swcodec"],

    target: {
        darwin: {
            enabled: false,
        },
    },
}
+41 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef G711_DEC_H_
#define G711_DEC_H_

/**
 * @file g711Dec.h
 * @brief g711 Decoder API: DecodeALaw and DecodeMLaw
 */

/** Decodes input bytes of size inSize according to ALAW
 *
 * @param [in] out <tt>int16_t*</tt>: output buffer to be filled with decoded bytes.
 * @param [in] in <tt>const uint8_t*</tt>: input buffer containing bytes to be decoded.
 * @param [in] inSize <tt>size_t</tt>: size of the input buffer.
 */
void DecodeALaw(int16_t *out, const uint8_t *in, size_t inSize);

/** Decodes input bytes of size inSize according to MLAW
 *
 * @param [in] out <tt>int16_t*</tt>: output buffer to be filled with decoded bytes.
 * @param [in] in <tt>const uint8_t*</tt>: input buffer containing bytes to be decoded.
 * @param [in] inSize <tt>size_t</tt>: size of the input buffer.
 */
void DecodeMLaw(int16_t *out, const uint8_t *in, size_t inSize);

#endif  // G711_DECODER_H_
Loading