25 #include <binder/ProcessState.h>
26 #include <media/stagefright/MetaData.h>
27 #include <media/stagefright/MediaBufferGroup.h>
28 #include <media/stagefright/MediaDebug.h>
29 #include <media/stagefright/MediaDefs.h>
30 #include <media/stagefright/OMXClient.h>
31 #include <media/stagefright/OMXCodec.h>
32 #include <utils/List.h>
41 #define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00
43 using namespace android;
77 std::map<int64_t, TimeStamp> *
ts_map;
94 buf_group.add_buffer(
new MediaBuffer(
frame_size));
101 virtual status_t
start(MetaData *params) {
109 virtual status_t read(MediaBuffer **
buffer,
110 const MediaSource::ReadOptions *
options) {
114 if (s->thread_exited)
115 return ERROR_END_OF_STREAM;
118 while (s->in_queue->empty())
121 frame = *s->in_queue->begin();
125 ret = buf_group.acquire_buffer(buffer);
127 memcpy((*buffer)->data(), frame->
buffer, frame->
size);
128 (*buffer)->set_range(0, frame->
size);
129 (*buffer)->meta_data()->clear();
130 (*buffer)->meta_data()->setInt32(kKeyIsSyncFrame,frame->
key);
131 (*buffer)->meta_data()->setInt64(kKeyTime, frame->
time);
138 s->in_queue->erase(s->in_queue->begin());
164 int64_t out_frame_index = 0;
177 if (frame->
status == OK) {
178 sp<MetaData> outFormat = (*s->
decoder)->getFormat();
179 outFormat->findInt32(kKeyWidth , &w);
180 outFormat->findInt32(kKeyHeight, &h);
199 (w & 15 || h & 15)) {
200 if (((w + 15)&~15) * ((h + 15)&~15) * 3/2 == buffer->range_length()) {
215 src_data[0] = (
uint8_t*)buffer->data();
216 src_data[1] = src_data[0] + src_linesize[0] * h;
217 src_data[2] = src_data[1] + src_linesize[1] * -(-h>>pix_desc->log2_chroma_h);
219 src_data, src_linesize,
222 buffer->meta_data()->findInt64(kKeyTime, &out_frame_index);
223 if (out_frame_index && s->
ts_map->count(out_frame_index) > 0) {
226 s->
ts_map->erase(out_frame_index);
229 }
else if (frame->
status == INFO_FORMAT_CHANGED) {
259 sp<MetaData> meta, outFormat;
287 meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
288 meta->setInt32(kKeyWidth, avctx->
width);
289 meta->setInt32(kKeyHeight, avctx->
height);
292 android::ProcessState::self()->startThreadPool();
294 s->
source =
new sp<MediaSource>();
298 s->
ts_map =
new std::map<int64_t, TimeStamp>;
299 s->
client =
new OMXClient;
307 if (s->
client->connect() != OK) {
313 s->
decoder =
new sp<MediaSource>();
316 OMXCodec::kClientNeedsFramebuffer);
317 if ((*s->
decoder)->start() != OK) {
324 outFormat = (*s->
decoder)->getFormat();
325 outFormat->findInt32(kKeyColorFormat, &colorFormat);
327 colorFormat == OMX_COLOR_FormatYUV420SemiPlanar)
329 else if (colorFormat == OMX_COLOR_FormatYCbYCr)
331 else if (colorFormat == OMX_COLOR_FormatCbYCrY)
362 int orig_size = avpkt->
size;
371 if (avpkt && avpkt->
data) {
392 if (!
frame->buffer) {
400 frame->size = orig_size;
402 memcpy(
frame->buffer, ptr, orig_size);
410 frame->status = ERROR_END_OF_STREAM;
447 ret_frame =
frame->vframe;
451 if (
status == ERROR_END_OF_STREAM)
574 "libstagefright_h264",