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

Commit 97ac9e6d authored by Ayushi Khopkar's avatar Ayushi Khopkar
Browse files

Separate g711 decoder from Codec2 plugin

g711 decoder is now built as separate static
library which is included in Codec2 plugin.

Test: Build libcodec2_soft_g711alawdec and libcodec2_soft_g711mlawdec
Bug: 151599224

Change-Id: Iaea9338a017a043f1614b63212708d6a94be8cb3
parent dd1fafd8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ cc_library_shared {

    srcs: ["C2SoftG711Dec.cpp"],

    static_libs: ["codecs_g711dec"],

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

    srcs: ["C2SoftG711Dec.cpp"],

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

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

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

namespace android {
@@ -224,53 +224,6 @@ c2_status_t C2SoftG711Dec::drain(
    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 {
public:
    C2SoftG711DecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
+0 −6
Original line number Diff line number Diff line
@@ -45,12 +45,6 @@ private:
    std::shared_ptr<IntfImpl> mIntf;
    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);
};

+38 −0
Original line number 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,

    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"],
}
+41 −0
Original line number 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