1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
* Copyright (C) 2009 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.
*/
#include <binder/MemoryHeapBase.h>
#include <binder/MemoryHeapPmem.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/QComHardwareRenderer.h>
#include <ui/ISurface.h>
namespace android {
////////////////////////////////////////////////////////////////////////////////
typedef struct PLATFORM_PRIVATE_ENTRY
{
/* Entry type */
uint32_t type;
/* Pointer to platform specific entry */
void *entry;
} PLATFORM_PRIVATE_ENTRY;
typedef struct PLATFORM_PRIVATE_LIST
{
/* Number of entries */
uint32_t nEntries;
/* Pointer to array of platform specific entries *
* Contiguous block of PLATFORM_PRIVATE_ENTRY elements */
PLATFORM_PRIVATE_ENTRY *entryList;
} PLATFORM_PRIVATE_LIST;
// data structures for tunneling buffers
typedef struct PLATFORM_PRIVATE_PMEM_INFO
{
/* pmem file descriptor */
uint32_t pmem_fd;
uint32_t offset;
} PLATFORM_PRIVATE_PMEM_INFO;
#define PLATFORM_PRIVATE_PMEM 1
QComHardwareRenderer::QComHardwareRenderer(
const sp<ISurface> &surface,
size_t displayWidth, size_t displayHeight,
size_t decodedWidth, size_t decodedHeight)
: mISurface(surface),
mDisplayWidth(displayWidth),
mDisplayHeight(displayHeight),
mDecodedWidth(decodedWidth),
mDecodedHeight(decodedHeight),
mFrameSize((mDecodedWidth * mDecodedHeight * 3) / 2) {
CHECK(mISurface.get() != NULL);
CHECK(mDecodedWidth > 0);
CHECK(mDecodedHeight > 0);
}
QComHardwareRenderer::~QComHardwareRenderer() {
mISurface->unregisterBuffers();
}
void QComHardwareRenderer::render(
const void *data, size_t size, void *platformPrivate) {
size_t offset;
if (!getOffset(platformPrivate, &offset)) {
return;
}
mISurface->postBuffer(offset);
// Since we cannot tell how long it'll take until surface flinger
// has displayed the data onscreen, we'll just have to guess...
// We must not return the buffer to the decoder before it's been displayed.
usleep(25000);
}
bool QComHardwareRenderer::getOffset(void *platformPrivate, size_t *offset) {
*offset = 0;
PLATFORM_PRIVATE_LIST *list = (PLATFORM_PRIVATE_LIST *)platformPrivate;
for (uint32_t i = 0; i < list->nEntries; ++i) {
if (list->entryList[i].type != PLATFORM_PRIVATE_PMEM) {
continue;
}
PLATFORM_PRIVATE_PMEM_INFO *info =
(PLATFORM_PRIVATE_PMEM_INFO *)list->entryList[i].entry;
if (info != NULL) {
if (mMemoryHeap.get() == NULL) {
publishBuffers(info->pmem_fd);
}
if (mMemoryHeap.get() == NULL) {
return false;
}
*offset = info->offset;
return true;
}
}
return false;
}
void QComHardwareRenderer::publishBuffers(uint32_t pmem_fd) {
sp<MemoryHeapBase> master =
reinterpret_cast<MemoryHeapBase *>(pmem_fd);
master->setDevice("/dev/pmem");
uint32_t heap_flags = master->getFlags() & MemoryHeapBase::NO_CACHING;
mMemoryHeap = new MemoryHeapPmem(master, heap_flags);
mMemoryHeap->slap();
ISurface::BufferHeap bufferHeap(
mDisplayWidth, mDisplayHeight,
mDecodedWidth, mDecodedHeight,
PIXEL_FORMAT_YCbCr_420_SP,
mMemoryHeap);
status_t err = mISurface->registerBuffers(bufferHeap);
CHECK_EQ(err, OK);
}
} // namespace android
|