|
Packit |
1244b8 |
/*
|
|
Packit |
1244b8 |
* Copyright (C) 2015 Intel Corporation. All rights reserved.
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1244b8 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1244b8 |
* You may obtain a copy of the License at
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1244b8 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1244b8 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1244b8 |
* See the License for the specific language governing permissions and
|
|
Packit |
1244b8 |
* limitations under the License.
|
|
Packit |
1244b8 |
*/
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
1244b8 |
#include "config.h"
|
|
Packit |
1244b8 |
#endif
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
#include "surfacepool.h"
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
#include "common/log.h"
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
namespace YamiMediaCodec{
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
SharedPtr<SurfacePool>
|
|
Packit |
1244b8 |
SurfacePool::create(const SharedPtr<SurfaceAllocator>& alloc,
|
|
Packit |
1244b8 |
uint32_t fourcc, uint32_t width, uint32_t height, uint32_t size)
|
|
Packit |
1244b8 |
{
|
|
Packit |
1244b8 |
SharedPtr<SurfacePool> pool(new SurfacePool);
|
|
Packit |
1244b8 |
if (YAMI_SUCCESS != pool->init(alloc, fourcc, width, height, size))
|
|
Packit |
1244b8 |
pool.reset();
|
|
Packit |
1244b8 |
return pool;
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
SurfacePool::SurfacePool()
|
|
Packit |
1244b8 |
{
|
|
Packit |
1244b8 |
memset(&m_params, 0, sizeof(m_params));
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
YamiStatus SurfacePool::init(const SharedPtr<SurfaceAllocator>& alloc,
|
|
Packit |
1244b8 |
uint32_t fourcc, uint32_t width, uint32_t height, uint32_t size)
|
|
Packit |
1244b8 |
{
|
|
Packit |
1244b8 |
m_params.fourcc = fourcc;
|
|
Packit |
1244b8 |
m_params.width = width;
|
|
Packit |
1244b8 |
m_params.height = height;
|
|
Packit |
1244b8 |
m_params.size = size;
|
|
Packit |
1244b8 |
YamiStatus status = alloc->alloc(alloc.get(), &m_params);
|
|
Packit |
1244b8 |
if (status != YAMI_SUCCESS)
|
|
Packit |
1244b8 |
return status;
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
//prepare surfaces for pool
|
|
Packit |
1244b8 |
std::deque<SurfacePtr> surfaces;
|
|
Packit |
1244b8 |
for (uint32_t i = 0; i < m_params.size; i++) {
|
|
Packit |
1244b8 |
SurfacePtr s(new VaapiSurface(m_params.surfaces[i], width, height, fourcc));
|
|
Packit |
1244b8 |
surfaces.push_back(s);
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
m_pool.reset(new VideoPool<VaapiSurface>(surfaces));
|
|
Packit |
1244b8 |
if (!m_pool) {
|
|
Packit |
1244b8 |
ERROR("failed to create Surface Pool");
|
|
Packit |
1244b8 |
return YAMI_OUT_MEMORY;
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
m_alloc = alloc;
|
|
Packit |
1244b8 |
return YAMI_SUCCESS;
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
SurfacePool::~SurfacePool()
|
|
Packit |
1244b8 |
{
|
|
Packit |
1244b8 |
if (m_alloc) {
|
|
Packit |
1244b8 |
m_alloc->free(m_alloc.get(), &m_params);
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
SurfacePtr SurfacePool::alloc()
|
|
Packit |
1244b8 |
{
|
|
Packit |
1244b8 |
return m_pool->alloc();
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
} //YamiMediaCodec
|