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

Commit 05ca3bfb authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: create CodecBase interface (abstract class)

This abstracts out the ACodec dependency in MediaCodec.

Bug: 11784825
Change-Id: I0aa8b56c6414865fd4b0646e2c5bd1b62d030682
parent 2e8863b3
Loading
Loading
Loading
Loading
+33 −26
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <android/native_window.h>
#include <media/IOMX.h>
#include <media/stagefright/foundation/AHierarchicalStateMachine.h>
#include <media/stagefright/CodecBase.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <OMX_Audio.h>

@@ -32,42 +33,47 @@ namespace android {
struct ABuffer;
struct MemoryDealer;

struct ACodec : public AHierarchicalStateMachine {
struct ACodec : public AHierarchicalStateMachine, public CodecBase {
    enum {
        kWhatFillThisBuffer      = 'fill',
        kWhatDrainThisBuffer     = 'drai',
        kWhatEOS                 = 'eos ',
        kWhatShutdownCompleted   = 'scom',
        kWhatFlushCompleted      = 'fcom',
        kWhatOutputFormatChanged = 'outC',
        kWhatError               = 'erro',
        kWhatComponentAllocated  = 'cAll',
        kWhatComponentConfigured = 'cCon',
        kWhatInputSurfaceCreated = 'isfc',
        kWhatSignaledInputEOS    = 'seos',
        kWhatBuffersAllocated    = 'allc',
        kWhatOMXDied             = 'OMXd',
        kWhatFillThisBuffer      = CodecBase::kWhatFillThisBuffer,
        kWhatDrainThisBuffer     = CodecBase::kWhatDrainThisBuffer,
        kWhatEOS                 = CodecBase::kWhatEOS,
        kWhatShutdownCompleted   = CodecBase::kWhatShutdownCompleted,
        kWhatFlushCompleted      = CodecBase::kWhatFlushCompleted,
        kWhatOutputFormatChanged = CodecBase::kWhatOutputFormatChanged,
        kWhatError               = CodecBase::kWhatError,
        kWhatComponentAllocated  = CodecBase::kWhatComponentAllocated,
        kWhatComponentConfigured = CodecBase::kWhatComponentConfigured,
        kWhatInputSurfaceCreated = CodecBase::kWhatInputSurfaceCreated,
        kWhatSignaledInputEOS    = CodecBase::kWhatSignaledInputEOS,
        kWhatBuffersAllocated    = CodecBase::kWhatBuffersAllocated,
    };

    ACodec();

    void setNotificationMessage(const sp<AMessage> &msg);
    virtual void setNotificationMessage(const sp<AMessage> &msg);

    void initiateSetup(const sp<AMessage> &msg);
    void signalFlush();
    void signalResume();
    void initiateShutdown(bool keepComponentAllocated = false);

    void signalSetParameters(const sp<AMessage> &msg);
    void signalEndOfInputStream();
    virtual void initiateAllocateComponent(const sp<AMessage> &msg);
    virtual void initiateConfigureComponent(const sp<AMessage> &msg);
    virtual void initiateCreateInputSurface();
    virtual void initiateStart();
    virtual void initiateShutdown(bool keepComponentAllocated = false);

    void initiateAllocateComponent(const sp<AMessage> &msg);
    void initiateConfigureComponent(const sp<AMessage> &msg);
    void initiateCreateInputSurface();
    void initiateStart();
    virtual void signalFlush();
    virtual void signalResume();

    void signalRequestIDRFrame();
    virtual void signalSetParameters(const sp<AMessage> &msg);
    virtual void signalEndOfInputStream();
    virtual void signalRequestIDRFrame();

    struct PortDescription : public RefBase {
    // AHierarchicalStateMachine implements the message handling
    virtual void onMessageReceived(const sp<AMessage> &msg) {
        handleMessage(msg);
    }

    struct PortDescription : public CodecBase::PortDescription {
        size_t countBuffers();
        IOMX::buffer_id bufferIDAt(size_t index) const;
        sp<ABuffer> bufferAt(size_t index) const;
@@ -117,6 +123,7 @@ private:
        kWhatRequestIDRFrame         = 'ridr',
        kWhatSetParameters           = 'setP',
        kWhatSubmitOutputMetaDataBufferIfEOS = 'subm',
        kWhatOMXDied                 = 'OMXd',
    };

    enum {
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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 CODEC_BASE_H_

#define CODEC_BASE_H_

#include <stdint.h>
#include <media/IOMX.h>

#include <media/stagefright/foundation/AHandler.h>

namespace android {

struct ABuffer;

struct CodecBase : public AHandler {
    enum {
        kWhatFillThisBuffer      = 'fill',
        kWhatDrainThisBuffer     = 'drai',
        kWhatEOS                 = 'eos ',
        kWhatShutdownCompleted   = 'scom',
        kWhatFlushCompleted      = 'fcom',
        kWhatOutputFormatChanged = 'outC',
        kWhatError               = 'erro',
        kWhatComponentAllocated  = 'cAll',
        kWhatComponentConfigured = 'cCon',
        kWhatInputSurfaceCreated = 'isfc',
        kWhatSignaledInputEOS    = 'seos',
        kWhatBuffersAllocated    = 'allc',
    };

    virtual void setNotificationMessage(const sp<AMessage> &msg) = 0;

    virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0;
    virtual void initiateConfigureComponent(const sp<AMessage> &msg) = 0;
    virtual void initiateCreateInputSurface() = 0;
    virtual void initiateStart() = 0;
    virtual void initiateShutdown(bool keepComponentAllocated = false) = 0;

    // require an explicit message handler
    virtual void onMessageReceived(const sp<AMessage> &msg) = 0;

    virtual void signalFlush() = 0;
    virtual void signalResume() = 0;

    virtual void signalRequestIDRFrame() = 0;
    virtual void signalSetParameters(const sp<AMessage> &msg) = 0;
    virtual void signalEndOfInputStream() = 0;

    struct PortDescription : public RefBase {
        virtual size_t countBuffers() = 0;
        virtual IOMX::buffer_id bufferIDAt(size_t index) const = 0;
        virtual sp<ABuffer> bufferAt(size_t index) const = 0;

    protected:
        PortDescription();
        virtual ~PortDescription();

    private:
        DISALLOW_EVIL_CONSTRUCTORS(PortDescription);
    };

protected:
    CodecBase();
    virtual ~CodecBase();

private:
    DISALLOW_EVIL_CONSTRUCTORS(CodecBase);
};

}  // namespace android

#endif  // CODEC_BASE_H_
+2 −2
Original line number Diff line number Diff line
@@ -43,13 +43,13 @@ private:
    DISALLOW_EVIL_CONSTRUCTORS(AState);
};

struct AHierarchicalStateMachine : public AHandler {
struct AHierarchicalStateMachine {
    AHierarchicalStateMachine();

protected:
    virtual ~AHierarchicalStateMachine();

    virtual void onMessageReceived(const sp<AMessage> &msg);
    virtual void handleMessage(const sp<AMessage> &msg);

    // Only to be called in response to a message.
    void changeState(const sp<AState> &state);
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ LOCAL_SRC_FILES:= \
        CameraSource.cpp                  \
        CameraSourceTimeLapse.cpp         \
        ClockEstimator.cpp                \
        CodecBase.cpp                     \
        DataSource.cpp                    \
        DataURISource.cpp                 \
        DRMExtractor.cpp                  \
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "CodecBase"

#include <inttypes.h>

#include <media/stagefright/CodecBase.h>

namespace android {

CodecBase::CodecBase() {
}

CodecBase::~CodecBase() {
}

CodecBase::PortDescription::PortDescription() {
}

CodecBase::PortDescription::~PortDescription() {
}

}  // namespace android
Loading