Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright (C) 2011 NXP Software
|
| 3 | * Copyright (C) 2011 The Android Open Source Project
|
| 4 | *
|
| 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 | * you may not use this file except in compliance with the License.
|
| 7 | * You may obtain a copy of the License at
|
| 8 | *
|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 10 | *
|
| 11 | * Unless required by applicable law or agreed to in writing, software
|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 | * See the License for the specific language governing permissions and
|
| 15 | * limitations under the License.
|
| 16 | */
|
| 17 |
|
| 18 | #define LOG_NDEBUG 1
|
| 19 | #define LOG_TAG "DummyVideoSource"
|
| 20 | #include "utils/Log.h"
|
| 21 |
|
| 22 | #include <media/stagefright/MediaErrors.h>
|
| 23 | #include <media/stagefright/MediaDebug.h>
|
| 24 | #include <media/stagefright/MediaDefs.h>
|
| 25 | #include <media/stagefright/MediaBuffer.h>
|
| 26 | #include <media/stagefright/MediaBufferGroup.h>
|
| 27 | #include <media/stagefright/MetaData.h>
|
| 28 |
|
| 29 | #include "DummyVideoSource.h"
|
| 30 |
|
| 31 | /* Android includes*/
|
| 32 | #include <utils/Log.h>
|
| 33 | #include <memory.h>
|
| 34 |
|
| 35 |
|
| 36 | #define LOG1 LOGE /*ERRORS Logging*/
|
| 37 | #define LOG2 LOGV /*WARNING Logging*/
|
| 38 | #define LOG3 //LOGV /*COMMENTS Logging*/
|
| 39 |
|
| 40 |
|
| 41 | namespace android {
|
| 42 |
|
| 43 |
|
| 44 | sp<DummyVideoSource> DummyVideoSource::Create (
|
| 45 | uint32_t width, uint32_t height,
|
| 46 | uint64_t clipDuration, const char *imageUri) {
|
| 47 | LOG2("DummyVideoSource::Create ");
|
| 48 | sp<DummyVideoSource> vSource = new DummyVideoSource (
|
| 49 | width, height, clipDuration, imageUri);
|
| 50 | return vSource;
|
| 51 | }
|
| 52 |
|
| 53 |
|
| 54 | DummyVideoSource::DummyVideoSource (
|
| 55 | uint32_t width, uint32_t height,
|
| 56 | uint64_t clipDuration, const char *imageUri) {
|
| 57 |
|
| 58 | LOG2("DummyVideoSource::DummyVideoSource constructor START");
|
| 59 | mFrameWidth = width;
|
| 60 | mFrameHeight = height;
|
| 61 | mImageClipDuration = clipDuration;
|
| 62 | mUri = imageUri;
|
| 63 | mImageBuffer = NULL;
|
| 64 |
|
| 65 | LOG2("DummyVideoSource::DummyVideoSource constructor END");
|
| 66 | }
|
| 67 |
|
| 68 |
|
| 69 | DummyVideoSource::~DummyVideoSource () {
|
| 70 | /* Do nothing here? */
|
| 71 | LOG2("DummyVideoSource::~DummyVideoSource");
|
| 72 | }
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 | status_t DummyVideoSource::start(MetaData *params) {
|
| 77 | status_t err = OK;
|
| 78 | LOG2("DummyVideoSource::start START, %s", mUri);
|
| 79 | //get the frame buffer from the rgb file and store into a MediaBuffer
|
| 80 | err = LvGetImageThumbNail((const char *)mUri,
|
| 81 | mFrameHeight , mFrameWidth ,
|
| 82 | (M4OSA_Void **)&mImageBuffer);
|
| 83 |
|
| 84 | mIsFirstImageFrame = true;
|
| 85 | mImageSeekTime = 0;
|
| 86 | mImagePlayStartTime = 0;
|
| 87 | mFrameTimeUs = 0;
|
| 88 | LOG2("DummyVideoSource::start END");
|
| 89 |
|
| 90 | return err;
|
| 91 | }
|
| 92 |
|
| 93 |
|
| 94 | status_t DummyVideoSource::stop() {
|
| 95 | status_t err = OK;
|
| 96 |
|
| 97 | LOG2("DummyVideoSource::stop START");
|
| 98 | if (mImageBuffer != NULL) {
|
| 99 | M4OSA_free((M4OSA_MemAddr32)mImageBuffer);
|
| 100 | mImageBuffer = NULL;
|
| 101 | }
|
| 102 | LOG2("DummyVideoSource::stop END");
|
| 103 |
|
| 104 | return err;
|
| 105 | }
|
| 106 |
|
| 107 |
|
| 108 | sp<MetaData> DummyVideoSource::getFormat() {
|
| 109 | LOG2("DummyVideoSource::getFormat");
|
| 110 |
|
| 111 | sp<MetaData> meta = new MetaData;
|
| 112 |
|
| 113 | meta->setInt32(kKeyColorFormat, OMX_COLOR_FormatYUV420Planar);
|
| 114 | meta->setInt32(kKeyWidth, mFrameWidth);
|
| 115 | meta->setInt32(kKeyHeight, mFrameHeight);
|
| 116 | meta->setInt64(kKeyDuration, mImageClipDuration);
|
| 117 | meta->setCString(kKeyDecoderComponent, "DummyVideoSource");
|
| 118 |
|
| 119 | return meta;
|
| 120 | }
|
| 121 |
|
| 122 | status_t DummyVideoSource::read(
|
| 123 | MediaBuffer **out,
|
| 124 | const MediaSource::ReadOptions *options) {
|
| 125 | status_t err = OK;
|
| 126 | MediaBuffer *buffer;
|
| 127 | LOG2("DummyVideoSource::read START");
|
| 128 |
|
| 129 | bool seeking = false;
|
| 130 | int64_t seekTimeUs;
|
| 131 | ReadOptions::SeekMode seekMode;
|
| 132 |
|
| 133 | if (options && options->getSeekTo(&seekTimeUs, &seekMode)) {
|
| 134 | seeking = true;
|
| 135 | mImageSeekTime = seekTimeUs;
|
| 136 | }
|
| 137 |
|
| 138 | if ((mImageSeekTime == mImageClipDuration) || (mFrameTimeUs == mImageClipDuration)) {
|
| 139 | LOG2("DummyVideoSource::read() End of stream reached; return NULL buffer");
|
| 140 | *out = NULL;
|
| 141 | return ERROR_END_OF_STREAM;
|
| 142 | }
|
| 143 |
|
| 144 | buffer = new MediaBuffer(mImageBuffer, (mFrameWidth*mFrameHeight*1.5));
|
| 145 |
|
| 146 | //set timestamp of buffer
|
| 147 | if (mIsFirstImageFrame) {
|
| 148 | M4OSA_clockGetTime(&mImagePlayStartTime, 1000); //1000 time scale for time in ms
|
| 149 | mFrameTimeUs = (mImageSeekTime + 1);
|
| 150 | LOG2("DummyVideoSource::read() jpg 1st frame timeUs = %lld, begin cut time = %ld", mFrameTimeUs, mImageSeekTime);
|
| 151 | mIsFirstImageFrame = false;
|
| 152 | } else {
|
| 153 | M4OSA_Time currentTimeMs;
|
| 154 | M4OSA_clockGetTime(¤tTimeMs, 1000);
|
| 155 |
|
| 156 | mFrameTimeUs = mImageSeekTime + (currentTimeMs - mImagePlayStartTime)*1000;
|
| 157 | LOG2("DummyVideoSource::read() jpg frame timeUs = %lld", mFrameTimeUs);
|
| 158 | }
|
| 159 | buffer->meta_data()->setInt64(kKeyTime, mFrameTimeUs);
|
| 160 | buffer->set_range(buffer->range_offset(), mFrameWidth*mFrameHeight*1.5);
|
| 161 | *out = buffer;
|
| 162 | return err;
|
| 163 | }
|
| 164 |
|
| 165 | }// namespace android
|