Skip to content

Commit

Permalink
refact: tests, move surface map from ColorConvert to utils
Browse files Browse the repository at this point in the history
EncodeInputDecoder and other places need this
  • Loading branch information
xuguangxin committed Mar 1, 2016
1 parent 877bb1e commit 9dc50fa
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 21 deletions.
25 changes: 4 additions & 21 deletions tests/decodeoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "common/log.h"
#include "common/utils.h"
#include "vaapi/vaapiutils.h"
#include "vaapi/vaapiimageutils.h"

#if __ENABLE_MD5__
#include <openssl/md5.h>
Expand All @@ -55,7 +56,7 @@
#include <stdio.h>
#include <assert.h>

using YamiMediaCodec::checkVaapiStatus;
using namespace YamiMediaCodec;
using std::vector;

bool DecodeOutput::init()
Expand Down Expand Up @@ -144,7 +145,7 @@ class ColorConvert {
return false;
}
VAImage image;
uint8_t* p = map(src->surface, image);
uint8_t* p = mapSurfaceToImage(*m_display, src->surface, image);
if (!p) {
ERROR("failed to map VAImage");
return false;
Expand All @@ -156,7 +157,7 @@ class ColorConvert {
copyY(dest, p, image.offsets[0], width, height, image.pitches[0]);
copyUV(dest, p, image.offsets[1], width, height, image.pitches[1]);
copyUV(dest, p, image.offsets[1] + 1, width, height, image.pitches[1]);
unmap(image);
unmapImage(*m_display, image);
return true;
}

Expand Down Expand Up @@ -187,24 +188,6 @@ class ColorConvert {
}

}
uint8_t* map(intptr_t surface, VAImage& image)
{
uint8_t* p = NULL;
VAStatus status = vaDeriveImage(*m_display, (VASurfaceID)surface, &image);
if (!checkVaapiStatus(status, "vaDeriveImage"))
return NULL;
status = vaMapBuffer(*m_display, image.buf, (void**)&p);
if (!checkVaapiStatus(status, "vaMapBuffer")) {
checkVaapiStatus(vaDestroyImage(*m_display, image.image_id), "vaDestroyImage");
return NULL;
}
return p;
}
void unmap(const VAImage& image)
{
checkVaapiStatus(vaUnmapBuffer(*m_display, image.buf), "vaUnmapBuffer");
checkVaapiStatus(vaDestroyImage(*m_display, image.image_id), "vaDestroyImage");
}

bool init(uint32_t width, uint32_t height)
{
Expand Down
1 change: 1 addition & 0 deletions vaapi/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LOCAL_SRC_FILES := \
vaapibuffer.cpp \
vaapiimage.cpp \
vaapisurface.cpp\
vaapiimageutils.cpp \
vaapiutils.cpp \
vaapidisplay.cpp \
vaapicontext.cpp \
Expand Down
2 changes: 2 additions & 0 deletions vaapi/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ libyami_vaapi_source_c = \
vaapibuffer.cpp \
vaapiimage.cpp \
vaapisurface.cpp\
vaapiimageutils.cpp \
vaapiutils.cpp \
vaapidisplay.cpp \
vaapicontext.cpp \
Expand All @@ -17,6 +18,7 @@ libyami_vaapi_source_h_priv = \
vaapibuffer.h \
vaapiimage.h \
vaapisurface.h \
vaapiimageutils.h \
vaapiutils.h \
vaapitypes.h \
vaapidisplay.h \
Expand Down
53 changes: 53 additions & 0 deletions vaapi/vaapiimageutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* vaapiimageutils.cpp - vaapi image utils
*
* Copyright (C) 2011-2014 Intel Corporation
* Author: Xu Guangxin<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "vaapiimageutils.h"

#include "vaapiutils.h"

namespace YamiMediaCodec{

uint8_t* mapSurfaceToImage(VADisplay display, intptr_t surface, VAImage& image)
{
uint8_t* p = NULL;
VAStatus status = vaDeriveImage(display, (VASurfaceID)surface, &image);
if (!checkVaapiStatus(status, "vaDeriveImage"))
return NULL;
status = vaMapBuffer(display, image.buf, (void**)&p);
if (!checkVaapiStatus(status, "vaMapBuffer")) {
checkVaapiStatus(vaDestroyImage(display, image.image_id), "vaDestroyImage");
return NULL;
}
return p;
}

void unmapImage(VADisplay display, const VAImage& image)
{
checkVaapiStatus(vaUnmapBuffer(display, image.buf), "vaUnmapBuffer");
checkVaapiStatus(vaDestroyImage(display, image.image_id), "vaDestroyImage");
}

}
32 changes: 32 additions & 0 deletions vaapi/vaapiimageutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* vaapiimageutils.h - vaapi image utils
*
* Copyright (C) 2011-2014 Intel Corporation
* Author: Xu Guangxin<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include <stdint.h>
#include <va/va.h>

namespace YamiMediaCodec{

uint8_t* mapSurfaceToImage(VADisplay display, intptr_t surface, VAImage& image);

void unmapImage(VADisplay display, const VAImage& image);

} //namespace YamiMediaCodec

1 comment on commit 9dc50fa

@lizhong1008
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.