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

Commit 9bbde4c4 authored by Dharmaray Kundargi's avatar Dharmaray Kundargi Committed by Android (Google) Code Review
Browse files

Merge "videoeditor preview code on honeycomb" into honeycomb

parents 7c9d8018 643290dc
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2011 NXP Software
# Copyright (C) 2011 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.
#

LOCAL_PATH:= $(call my-dir)

#
# libvideoeditorplayer
#

include $(CLEAR_VARS)

LOCAL_MODULE:= libvideoeditorplayer

LOCAL_SRC_FILES:=          \
    VideoEditorTools.cpp \
    VideoEditorPlayer.cpp \
    PreviewPlayer.cpp \
    VideoEditorAudioPlayer.cpp \
    VideoEditorPreviewController.cpp \
    VideoEditorSRC.cpp \
    DummyAudioSource.cpp \
    DummyVideoSource.cpp \
    VideoEditorBGAudioProcessing.cpp \
    PreviewRenderer.cpp

LOCAL_MODULE_TAGS := development

LOCAL_STATIC_LIBRARIES := \
    libvideoeditor_osal \
    libstagefright_color_conversion



LOCAL_SHARED_LIBRARIES := \
    libbinder          \
    libutils           \
    libcutils          \
    libmedia           \
    libstagefright  \
    libstagefright_omx  \
    libstagefright_foundation \
    libsurfaceflinger_client \
    libaudioflinger \
    libui


LOCAL_C_INCLUDES += \
    $(TOP)/frameworks/base/core/jni \
    $(TOP)/frameworks/base/include \
    $(TOP)/frameworks/base/include/media \
    $(TOP)/frameworks/base/media/libmediaplayerservice \
    $(TOP)/frameworks/base/media/libstagefright \
    $(TOP)/frameworks/base/media/libstagefright/include \
    $(TOP)/frameworks/base/media/libstagefright/rtsp \
    $(JNI_H_INCLUDE) \
    $(call include-path-for, corecg graphics) \
    $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \
    $(TOP)/external/opencore/android \
    $(TOP)/vendor/qcom/proprietary/qdsp6/mm-core/omxcore/inc \
    $(TOP)/frameworks/media/libvideoeditor/osal/inc \
    $(TOP)/frameworks/media/libvideoeditor/vss/common/inc \
    $(TOP)/frameworks/media/libvideoeditor/vss/mcs/inc \
    $(TOP)/frameworks/media/libvideoeditor/vss/inc \
    $(TOP)/frameworks/media/libvideoeditor/vss/stagefrightshells/inc \
    $(TOP)/frameworks/media/libvideoeditor/lvpp \
    $(TOP)/frameworks/base/media/jni/mediaeditor \
    $(TOP)/frameworks/base/services/audioflinger


ifeq ($(TARGET_SIMULATOR),true)
else
    LOCAL_SHARED_LIBRARIES += libdl
endif

# All of the shared libraries we link against.
LOCAL_LDLIBS := \
    -lpthread -ldl

LOCAL_CFLAGS += -Wno-multichar \
     -DM4_ENABLE_RENDERINGMODE \
    -DUSE_STAGEFRIGHT_CODECS \
    -DUSE_STAGEFRIGHT_AUDIODEC \
    -DUSE_STAGEFRIGHT_VIDEODEC \
    -DUSE_STAGEFRIGHT_AUDIOENC \
    -DUSE_STAGEFRIGHT_VIDEOENC \
    -DUSE_STAGEFRIGHT_READERS \
    -DUSE_STAGEFRIGHT_3GPP_READER


# Don't prelink this library.  For more efficient code, you may want
# to add this library to the prelink map and set this to true.
LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)

#include $(call all-makefiles-under,$(LOCAL_PATH))
+193 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 NXP Software
 * Copyright (C) 2011 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 1
#define LOG_TAG "DummyAudioSource"
#include "utils/Log.h"

#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MetaData.h>


#include "DummyAudioSource.h"



/* Android includes*/
#include <utils/Log.h>
#include <memory.h>


/*---------------------*/
/*  DEBUG LEVEL SETUP  */
/*---------------------*/
#define LOG1 LOGE    /*ERRORS Logging*/
#define LOG2 LOGV    /*WARNING Logging*/
#define LOG3 //LOGV    /*COMMENTS Logging*/

/*---------------------*/
/*  CONSTANTS          */
/*---------------------*/


namespace android {


/*---------------------*/
/*  SEEK SOURCE        */
/*---------------------*/

//static
sp<DummyAudioSource> DummyAudioSource::Create(int32_t samplingRate,
                                              int32_t channelCount,
                                              int64_t frameDurationUs,
                                              int64_t audioDurationUs) {
    LOG2("DummyAudioSource::Create ");
    sp<DummyAudioSource> aSource = new DummyAudioSource (samplingRate,
                                                         channelCount,
                                                         frameDurationUs,
                                                         audioDurationUs);
    return aSource;
}


DummyAudioSource::DummyAudioSource (int32_t samplingRate,
                                    int32_t channelCount,
                                    int64_t frameDurationUs,
                                    int64_t audioDurationUs):
    mSamplingRate(samplingRate),
    mChannelCount(channelCount),
    mFrameDurationUs(frameDurationUs),
    mAudioDurationUs(audioDurationUs),
    mTimeStampUs(0) ,
    mNumberOfSamplePerFrame(0),
    mBufferGroup(NULL){
    LOG2("DummyAudioSource::DummyAudioSource constructor START");
    /* Do nothing here? */
    LOG2("DummyAudioSource::DummyAudioSource");
    LOG2("DummyAudioSource:: mSamplingRate = %d",samplingRate);
    LOG2("DummyAudioSource:: mChannelCount = %d",channelCount);
    LOG2("DummyAudioSource:: frameDurationUs = %lld",frameDurationUs);
    LOG2("DummyAudioSource:: mAudioDurationUs = %lld",mAudioDurationUs);

    LOG2("DummyAudioSource::DummyAudioSource constructor END");
}


DummyAudioSource::~DummyAudioSource () {
    /* Do nothing here? */
    LOG2("DummyAudioSource::~DummyAudioSource");
}



status_t DummyAudioSource::start(MetaData *params) {
    status_t err = OK;
    LOG2("DummyAudioSource::start START");

    mTimeStampUs = 0;
    mNumberOfSamplePerFrame = (int32_t) ((1L * mSamplingRate * mFrameDurationUs)/1000000);
    mNumberOfSamplePerFrame = mNumberOfSamplePerFrame  * mChannelCount;

    mBufferGroup = new MediaBufferGroup;
    mBufferGroup->add_buffer(
            new MediaBuffer(mNumberOfSamplePerFrame * sizeof(int16_t)));

    LOG2("DummyAudioSource:: mNumberOfSamplePerFrame = %d",mNumberOfSamplePerFrame);
    LOG2("DummyAudioSource::start END");

    return err;
}


status_t DummyAudioSource::stop() {
    status_t err = OK;

    LOG2("DummyAudioSource::stop START");

    delete mBufferGroup;
    mBufferGroup = NULL;


    LOG2("DummyAudioSource::stop END");

    return err;
}


sp<MetaData> DummyAudioSource::getFormat() {
    LOG2("DummyAudioSource::getFormat");

    sp<MetaData> meta = new MetaData;

    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
    meta->setInt32(kKeyChannelCount, mChannelCount);
    meta->setInt32(kKeySampleRate, mSamplingRate);
    meta->setInt64(kKeyDuration, mFrameDurationUs);

     meta->setCString(kKeyDecoderComponent, "DummyAudioSource");

    return meta;
}

status_t DummyAudioSource::read( MediaBuffer **out, const MediaSource::ReadOptions *options) {
    status_t err            = OK;
    //LOG2("DummyAudioSource::read START");
    MediaBuffer *buffer;
    int32_t byteCount;
    int64_t seekTimeUs;
    ReadOptions::SeekMode mode;

    if (options && options->getSeekTo(&seekTimeUs, &mode)) {
        CHECK(seekTimeUs >= 0);
        mTimeStampUs = seekTimeUs;
     }

    if (mTimeStampUs >= mAudioDurationUs) {
        *out = NULL;
        return ERROR_END_OF_STREAM;
    }

    err = mBufferGroup->acquire_buffer(&buffer);
    if (err != OK) {
        return err;
    }

    uint8_t *inputPtr =
    ( uint8_t *)buffer->data() + buffer->range_offset();

    //TODO: replace with memset
    for (byteCount = 0; byteCount < (mNumberOfSamplePerFrame << 1); byteCount++) {
        inputPtr[byteCount] = 0;
    }

    buffer->set_range(buffer->range_offset(), (mNumberOfSamplePerFrame << 1));

    buffer->meta_data()->setInt64(kKeyTime, mTimeStampUs);
    LOG2("DummyAudioSource::read  Buffer_offset  = %d,"
            "Buffer_Size = %d, mTimeStampUs = %lld",
             buffer->range_offset(),buffer->size(),mTimeStampUs);
    mTimeStampUs = mTimeStampUs + mFrameDurationUs;
    *out = buffer;
    return err;
}

}// namespace android
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 NXP Software
 * Copyright (C) 2011 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 DUMMY_AUDIOSOURCE_H_

#define DUMMY_AUDIOSOURCE_H_

#include <utils/RefBase.h>
#include <utils/threads.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/DataSource.h>


namespace android {


class MediaBuffer;
class MetaData;
struct MediaBufferGroup;



struct DummyAudioSource : public MediaSource {

public:
    static sp<DummyAudioSource> Create(int32_t samplingRate,
                                       int32_t channelCount,
                                       int64_t frameDurationUs,
                                       int64_t audioDurationUs);
    virtual status_t start(MetaData *params = NULL);
    virtual status_t stop();
    virtual sp<MetaData> getFormat();
    virtual status_t read (MediaBuffer **buffer, 
                            const MediaSource::ReadOptions *options = NULL);

protected:
    DummyAudioSource (int32_t samplingRate,
                      int32_t channelCount,
                      int64_t frameDurationUs,
                      int64_t audioDurationUs);
    virtual ~DummyAudioSource();

private:
    int32_t mSamplingRate;
    int32_t mChannelCount;
    int64_t mFrameDurationUs;
    int32_t mNumberOfSamplePerFrame;
    int64_t mAudioDurationUs;
    int64_t mTimeStampUs;
    int32_t mNbBuffer;
    MediaBufferGroup *mBufferGroup;

    DummyAudioSource(const DummyAudioSource &);
    DummyAudioSource &operator=(const DummyAudioSource &);

};

}//namespace android


#endif //DUMMY_AUDIOSOURCE_H_
+165 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 NXP Software
 * Copyright (C) 2011 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 1
#define LOG_TAG "DummyVideoSource"
#include "utils/Log.h"

#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MetaData.h>

#include "DummyVideoSource.h"

/* Android includes*/
#include <utils/Log.h>
#include <memory.h>


#define LOG1 LOGE    /*ERRORS Logging*/
#define LOG2 LOGV    /*WARNING Logging*/
#define LOG3 //LOGV    /*COMMENTS Logging*/


namespace android {


sp<DummyVideoSource> DummyVideoSource::Create (
            uint32_t width, uint32_t height, 
            uint64_t clipDuration, const char *imageUri) {
    LOG2("DummyVideoSource::Create ");
    sp<DummyVideoSource> vSource = new DummyVideoSource (
                         width, height, clipDuration, imageUri);
    return vSource;
}


DummyVideoSource::DummyVideoSource (
            uint32_t width, uint32_t height, 
            uint64_t clipDuration, const char *imageUri) {

    LOG2("DummyVideoSource::DummyVideoSource constructor START");
    mFrameWidth = width;
    mFrameHeight = height;
    mImageClipDuration = clipDuration;
    mUri = imageUri;
    mImageBuffer = NULL;

    LOG2("DummyVideoSource::DummyVideoSource constructor END");
}


DummyVideoSource::~DummyVideoSource () {
    /* Do nothing here? */
    LOG2("DummyVideoSource::~DummyVideoSource");
}



status_t DummyVideoSource::start(MetaData *params) {
    status_t err = OK;
    LOG2("DummyVideoSource::start START, %s", mUri);
    //get the frame buffer from the rgb file and store into a MediaBuffer
    err = LvGetImageThumbNail((const char *)mUri,
                          mFrameHeight , mFrameWidth ,
                          (M4OSA_Void **)&mImageBuffer);

    mIsFirstImageFrame = true;
    mImageSeekTime = 0;
    mImagePlayStartTime = 0;
    mFrameTimeUs = 0;
    LOG2("DummyVideoSource::start END");

    return err;
}


status_t DummyVideoSource::stop() {
    status_t err = OK;

    LOG2("DummyVideoSource::stop START");
    if (mImageBuffer != NULL) {
        M4OSA_free((M4OSA_MemAddr32)mImageBuffer);
        mImageBuffer = NULL;
    }
    LOG2("DummyVideoSource::stop END");

    return err;
}


sp<MetaData> DummyVideoSource::getFormat() {
    LOG2("DummyVideoSource::getFormat");

    sp<MetaData> meta = new MetaData;

    meta->setInt32(kKeyColorFormat, OMX_COLOR_FormatYUV420Planar);
    meta->setInt32(kKeyWidth, mFrameWidth);
    meta->setInt32(kKeyHeight, mFrameHeight);
    meta->setInt64(kKeyDuration, mImageClipDuration);
    meta->setCString(kKeyDecoderComponent, "DummyVideoSource");

    return meta;
}

status_t DummyVideoSource::read( 
                        MediaBuffer **out, 
                        const MediaSource::ReadOptions *options) {
    status_t err = OK;
    MediaBuffer *buffer;
    LOG2("DummyVideoSource::read START");

    bool seeking = false;
    int64_t seekTimeUs;
    ReadOptions::SeekMode seekMode;

    if (options && options->getSeekTo(&seekTimeUs, &seekMode)) {
        seeking = true;
        mImageSeekTime = seekTimeUs;
    }

    if ((mImageSeekTime == mImageClipDuration) || (mFrameTimeUs == mImageClipDuration)) {
        LOG2("DummyVideoSource::read() End of stream reached; return NULL buffer");
        *out = NULL;
        return ERROR_END_OF_STREAM;
    }

    buffer = new MediaBuffer(mImageBuffer, (mFrameWidth*mFrameHeight*1.5));

    //set timestamp of buffer
    if (mIsFirstImageFrame) {
        M4OSA_clockGetTime(&mImagePlayStartTime, 1000); //1000 time scale for time in ms
        mFrameTimeUs =  (mImageSeekTime + 1);
        LOG2("DummyVideoSource::read() jpg 1st frame timeUs = %lld, begin cut time = %ld", mFrameTimeUs, mImageSeekTime);
        mIsFirstImageFrame = false;
    } else {
        M4OSA_Time  currentTimeMs;
        M4OSA_clockGetTime(&currentTimeMs, 1000);

        mFrameTimeUs = mImageSeekTime + (currentTimeMs - mImagePlayStartTime)*1000;
        LOG2("DummyVideoSource::read() jpg frame timeUs = %lld", mFrameTimeUs);
    }
    buffer->meta_data()->setInt64(kKeyTime, mFrameTimeUs);
    buffer->set_range(buffer->range_offset(), mFrameWidth*mFrameHeight*1.5);
    *out = buffer;
    return err;
}

}// namespace android
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 NXP Software
 * Copyright (C) 2011 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 DUMMY_VIDEOSOURCE_H_

#define DUMMY_VIDEOSOURCE_H_

#include <utils/RefBase.h>
#include <utils/threads.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/DataSource.h>
#include "OMX_IVCommon.h"
#include "VideoEditorTools.h"
#include "M4OSA_Clock.h"
#include "M4OSA_Time.h"
#include "M4OSA_Types.h"


namespace android {


class  MediaBuffer;
class  MetaData;
struct MediaBufferGroup;

struct DummyVideoSource : public MediaSource {

public:
    static sp<DummyVideoSource> Create(uint32_t width, 
                                       uint32_t height, 
                                       uint64_t clipDuration, 
                                       const char *imageUri);

    virtual status_t start(MetaData *params = NULL);
    virtual status_t stop();
    virtual sp<MetaData> getFormat();
    virtual status_t read(MediaBuffer **buffer, 
                          const MediaSource::ReadOptions *options = NULL);

protected:
    DummyVideoSource (uint32_t width, uint32_t height, 
                      uint64_t clipDuration, const char *imageUri);
    virtual ~DummyVideoSource();

private:
    uint32_t mFrameWidth;
    uint32_t mFrameHeight;
    uint64_t mImageClipDuration;
    const char *mUri;
    int64_t mFrameTimeUs;
    MediaBufferGroup *mBufferGroup;
    bool mIsFirstImageFrame;
    void *mImageBuffer;
    M4OSA_Time mImagePlayStartTime;
    uint32_t mImageSeekTime;

    DummyVideoSource(const DummyVideoSource &);
    DummyVideoSource &operator=(const DummyVideoSource &);

};


}//namespace android


#endif //DUMMY_VIDEOSOURCE_H_
Loading