blob: 42a732bfccccf064f8e1e98c1b9ba9dd34e2a3fd [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
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
41namespace android {
42
43
44sp<DummyVideoSource> DummyVideoSource::Create (
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -080045 uint32_t width, uint32_t height,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080046 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
54DummyVideoSource::DummyVideoSource (
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -080055 uint32_t width, uint32_t height,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080056 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
69DummyVideoSource::~DummyVideoSource () {
70 /* Do nothing here? */
71 LOG2("DummyVideoSource::~DummyVideoSource");
72}
73
74
75
76status_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
94status_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
108sp<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
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -0800122status_t DummyVideoSource::read(
123 MediaBuffer **out,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800124 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;
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -0800136 M4OSA_clockGetTime(&mImagePlayStartTime, 1000); //1000 time scale for time in ms
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800137 }
138
Basavapatna Dattaguru100d0182011-03-04 09:48:24 -0800139 if ((mImageSeekTime == mImageClipDuration) || (mFrameTimeUs == (int64_t)mImageClipDuration)) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800140 LOG2("DummyVideoSource::read() End of stream reached; return NULL buffer");
141 *out = NULL;
142 return ERROR_END_OF_STREAM;
143 }
144
145 buffer = new MediaBuffer(mImageBuffer, (mFrameWidth*mFrameHeight*1.5));
146
147 //set timestamp of buffer
148 if (mIsFirstImageFrame) {
149 M4OSA_clockGetTime(&mImagePlayStartTime, 1000); //1000 time scale for time in ms
150 mFrameTimeUs = (mImageSeekTime + 1);
151 LOG2("DummyVideoSource::read() jpg 1st frame timeUs = %lld, begin cut time = %ld", mFrameTimeUs, mImageSeekTime);
152 mIsFirstImageFrame = false;
153 } else {
154 M4OSA_Time currentTimeMs;
155 M4OSA_clockGetTime(&currentTimeMs, 1000);
156
157 mFrameTimeUs = mImageSeekTime + (currentTimeMs - mImagePlayStartTime)*1000;
158 LOG2("DummyVideoSource::read() jpg frame timeUs = %lld", mFrameTimeUs);
159 }
160 buffer->meta_data()->setInt64(kKeyTime, mFrameTimeUs);
161 buffer->set_range(buffer->range_offset(), mFrameWidth*mFrameHeight*1.5);
162 *out = buffer;
163 return err;
164}
165
166}// namespace android