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