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

Commit 96e92b58 authored by Wei Jia's avatar Wei Jia
Browse files

MediaBuffer: ABuffer will release MediaBuffer when it's destructed.

Bug: 17454455
Change-Id: Ia423bcc2e1fa39137f114eac44912ed15357bb99
parent 086c1e3f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#define MEDIA_BUFFER_H_

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

#include <pthread.h>

#include <utils/Errors.h>
@@ -43,7 +45,7 @@ private:
    MediaBufferObserver &operator=(const MediaBufferObserver &);
};

class MediaBuffer {
class MediaBuffer : public MediaBufferBase {
public:
    // The underlying data remains the responsibility of the caller!
    MediaBuffer(void *data, size_t size);
@@ -56,10 +58,10 @@ public:

    // Decrements the reference count and returns the buffer to its
    // associated MediaBufferGroup if the reference count drops to 0.
    void release();
    virtual void release();

    // Increments the reference count.
    void add_ref();
    virtual void add_ref();

    void *data() const;
    size_t size() const;
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
namespace android {

struct AMessage;
class MediaBufferBase;

struct ABuffer : public RefBase {
    ABuffer(size_t capacity);
@@ -50,6 +51,9 @@ struct ABuffer : public RefBase {

    sp<AMessage> meta();

    MediaBufferBase *getMediaBufferBase();
    void setMediaBufferBase(MediaBufferBase *mediaBuffer);

protected:
    virtual ~ABuffer();

@@ -57,6 +61,8 @@ private:
    sp<AMessage> mFarewell;
    sp<AMessage> mMeta;

    MediaBufferBase *mMediaBufferBase;

    void *mData;
    size_t mCapacity;
    size_t mRangeOffset;
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright 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 MEDIA_BUFFER_BASE_H_

#define MEDIA_BUFFER_BASE_H_

namespace android {

class MediaBufferBase {
public:
    MediaBufferBase() {}

    virtual void release() = 0;
    virtual void add_ref() = 0;

protected:
    virtual ~MediaBufferBase() {}

private:
    MediaBufferBase(const MediaBufferBase &);
    MediaBufferBase &operator=(const MediaBufferBase &);
};

}  // namespace android

#endif  // MEDIA_BUFFER_BASE_H_
+1 −1
Original line number Diff line number Diff line
@@ -1097,8 +1097,8 @@ sp<ABuffer> NuPlayer::GenericSource::mediaBufferToABuffer(
    if (mIsWidevine && !audio) {
        // data is already provided in the buffer
        ab = new ABuffer(NULL, mb->range_length());
        ab->meta()->setPointer("mediaBuffer", mb);
        mb->add_ref();
        ab->setMediaBufferBase(mb);
    } else {
        ab = new ABuffer(outLength);
        memcpy(ab->data(),
+3 −18
Original line number Diff line number Diff line
@@ -283,14 +283,9 @@ void android::NuPlayer::Decoder::onInputBufferFilled(const sp<AMessage> &msg) {

    // handle widevine classic source - that fills an arbitrary input buffer
    MediaBuffer *mediaBuffer = NULL;
    if (hasBuffer && buffer->meta()->findPointer(
            "mediaBuffer", (void **)&mediaBuffer)) {
        if (mediaBuffer == NULL) {
            // received no actual buffer
            ALOGW("[%s] received null MediaBuffer %s",
                    mComponentName.c_str(), msg->debugString().c_str());
            buffer = NULL;
        } else {
    if (hasBuffer) {
        mediaBuffer = (MediaBuffer *)(buffer->getMediaBufferBase());
        if (mediaBuffer != NULL) {
            // likely filled another buffer than we requested: adjust buffer index
            size_t ix;
            for (ix = 0; ix < mInputBuffers.size(); ix++) {
@@ -598,16 +593,6 @@ void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) {
        {
            if (!isStaleReply(msg)) {
                onInputBufferFilled(msg);
            } else {
                /* release any MediaBuffer passed in the stale buffer */
                sp<ABuffer> buffer;
                MediaBuffer *mediaBuffer = NULL;
                if (msg->findBuffer("buffer", &buffer) &&
                    buffer->meta()->findPointer(
                            "mediaBuffer", (void **)&mediaBuffer) &&
                    mediaBuffer != NULL) {
                    mediaBuffer->release();
                }
            }

            break;
Loading