Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
tests: add enocde input from decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
xuguangxin committed Nov 4, 2014
1 parent 6cd1906 commit ddd2a83
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 9 deletions.
7 changes: 4 additions & 3 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ endif
YAMI_ENCODE_LIBS = \
$(YAMI_COMMON_LIBS) \
$(top_builddir)/encoder/libyami_encoder.la \
$(YAMI_DECODE_LIBS) \
$(NULL)

V4L2_DECODE_LIBS = \
Expand Down Expand Up @@ -69,7 +70,7 @@ decodecapi_SOURCES += ../egl/egl_util.c ./egl/gles2_help.c
endif

encodecapi_LDADD = $(CAPI_ENCODE_LIBS)
encodecapi_SOURCES = encodecapi.c encodehelp.h encodeinput.cpp encodeInputCamera.cpp encodeInputCapi.cpp
encodecapi_SOURCES = encodecapi.c encodehelp.h encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp encodeInputCapi.cpp decodeinput.cpp
else
yamidecode_LDADD = $(YAMI_DECODE_LIBS)
yamidecode_SOURCES = decode.cpp decodehelp.h decodeinput.cpp decodeoutput.cpp
Expand All @@ -78,11 +79,11 @@ yamidecode_SOURCES += ../egl/egl_util.c ./egl/gles2_help.c
endif

yamiencode_LDADD = $(YAMI_ENCODE_LIBS)
yamiencode_SOURCES = encode.cpp encodeinput.cpp encodeInputCamera.cpp
yamiencode_SOURCES = encode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp decodeinput.cpp

v4l2decode_LDADD = $(V4L2_DECODE_LIBS)
v4l2decode_SOURCES = v4l2decode.cpp decodehelp.h decodeinput.cpp ../egl/egl_util.c ./egl/gles2_help.c

v4l2encode_LDADD = $(V4L2_ENCODE_LIBS)
v4l2encode_SOURCES = v4l2encode.cpp encodeinput.h encodeinput.cpp encodeInputCamera.cpp
v4l2encode_SOURCES = v4l2encode.cpp encodeinput.h encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp decodeinput.cpp
endif
6 changes: 3 additions & 3 deletions tests/decodeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ DecodeStreamInput::~DecodeStreamInput()
free(m_buffer);
}

bool DecodeStreamInput::initInput(char* fileName)
bool DecodeStreamInput::initInput(const char* fileName)
{
m_fp = fopen(fileName, "r");
if (!m_fp) {
Expand All @@ -60,13 +60,13 @@ bool DecodeStreamInput::initInput(char* fileName)
return init();
}

DecodeStreamInput* DecodeStreamInput::create(char* fileName)
DecodeStreamInput* DecodeStreamInput::create(const char* fileName)
{
DecodeStreamInput* input = NULL;
IVideoDecoder* decoder;
if(fileName==NULL)
return NULL;
char *ext = strrchr(fileName,'.');
const char *ext = strrchr(fileName,'.');
if(ext==NULL)
return NULL;
ext++;//h264;264;jsv;avc;26l;jvt;ivf
Expand Down
4 changes: 2 additions & 2 deletions tests/decodeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class DecodeStreamInput {
static const int CacheBufferSize = 4 * MaxNaluSize;
DecodeStreamInput();
virtual ~DecodeStreamInput();
static DecodeStreamInput * create(char* fileName);
bool initInput(char* fileName);
static DecodeStreamInput * create(const char* fileName);
bool initInput(const char* fileName);
virtual bool isEOS() {return m_parseToEOS;}
virtual const char * getMimeType() = 0;
virtual bool init() = 0;
Expand Down
122 changes: 122 additions & 0 deletions tests/encodeInputDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* encodeInputDecoder.cpp - use decoder as encoder input
*
* Copyright (C) 2011-2014 Intel Corporation
* Author: Xu Guangxin <guangxin.xu@intel.com>
*
* 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 "common/log.h"
#include "encodeInputDecoder.h"
#include "assert.h"

EncodeStreamInputDecoder::~EncodeStreamInputDecoder()
{
if (m_decoder) {
m_decoder->stop();
releaseVideoDecoder(m_decoder);
}
delete m_input;
}

bool EncodeStreamInputDecoder::init(const char* /*inputFileName*/, uint32_t /*fourcc*/, int /* width */, int /*height*/)
{
assert(m_input && "invalid input");
m_decoder = createVideoDecoder(m_input->getMimeType());
if (!m_decoder)
return false;
m_fourcc = VA_FOURCC_NV12;

VideoConfigBuffer configBuffer;
memset(&configBuffer,0,sizeof(VideoConfigBuffer));
configBuffer.profile = VAProfileNone;
Decode_Status status = m_decoder->start(&configBuffer);
assert(status == DECODE_SUCCESS);

while (!m_width || !m_height) {
if (!decodeOneFrame())
return false;
}
return true;
}

bool EncodeStreamInputDecoder::decodeOneFrame()
{
if (!m_input || !m_decoder)
return false;
VideoDecodeBuffer inputBuffer;
if (!m_input->getNextDecodeUnit(inputBuffer)) {
m_isEOS = true;
return true;
}
Decode_Status status = m_decoder->decode(&inputBuffer);
if (status == DECODE_FORMAT_CHANGE) {
const VideoFormatInfo *formatInfo = m_decoder->getFormatInfo();
m_width = formatInfo->width;
m_height = formatInfo->height;
//send again
status = m_decoder->decode(&inputBuffer);;
}
if (status != DECODE_SUCCESS) {
ERROR("decode failed status = %d", status);
return false;
}
return true;
}

bool EncodeStreamInputDecoder::getOneFrameInput(VideoFrameRawData &inputBuffer)
{
if (!m_decoder)
return false;
bool drain = false;
if (m_input->isEOS()) {
m_isEOS = true;
drain = true;
}
Decode_Status status;
do {
memset(&inputBuffer, 0, sizeof(inputBuffer));
inputBuffer.memoryType = VIDEO_DATA_MEMORY_TYPE_RAW_POINTER;
inputBuffer.fourcc = m_fourcc;
status = m_decoder->getOutput(&inputBuffer, drain);
inputBuffer.flags = 0;
if (status == RENDER_NO_AVAILABLE_FRAME) {
if (m_isEOS)
return false;
if (!decodeOneFrame())
return false;
}
} while (status == RENDER_NO_AVAILABLE_FRAME);
return status == RENDER_SUCCESS;
}

bool EncodeStreamInputDecoder::recycleOneFrameInput(VideoFrameRawData &inputBuffer)
{
if (!m_decoder)
return false;
m_decoder->renderDone(&inputBuffer);
return true;
}

bool EncodeStreamInputDecoder::isEOS()
{
return m_isEOS;
}
46 changes: 46 additions & 0 deletions tests/encodeInputDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* encodeInputDecoder.h - use decoder as encoder input
*
* Copyright (C) 2011-2014 Intel Corporation
* Author: Xu Guangxin <guangxin.xu@intel.com>
*
* 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
*/
#ifndef encodeInputDecoder_h
#define encodeInputDecoder_h

#include "decodeinput.h"
#include "encodeinput.h"

#include "VideoDecoderHost.h"

using namespace YamiMediaCodec;

class EncodeStreamInputDecoder : public EncodeStreamInput {
public:
EncodeStreamInputDecoder(DecodeStreamInput* input):m_input(input), m_decoder(NULL), m_isEOS(false){}
~EncodeStreamInputDecoder();
virtual bool init(const char* inputFileName, uint32_t fourcc, int width, int height);
virtual bool getOneFrameInput(VideoFrameRawData &inputBuffer);
virtual bool recycleOneFrameInput(VideoFrameRawData &inputBuffer);
virtual bool isEOS();
private:
bool decodeOneFrame();
DecodeStreamInput* m_input;
IVideoDecoder* m_decoder;
bool m_isEOS;
};
#endif
6 changes: 5 additions & 1 deletion tests/encodeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "common/utils.h"

#include "encodeinput.h"
#include "encodeInputDecoder.h"

using namespace YamiMediaCodec;

Expand All @@ -42,7 +43,10 @@ EncodeStreamInput * EncodeStreamInput::create(const char* inputFileName, uint32_
if (!inputFileName)
return NULL;

if (!strncmp(inputFileName, "/dev/video", strlen("/dev/video"))) {
DecodeStreamInput* decodeInput = DecodeStreamInput::create(inputFileName);
if (decodeInput) {
input = new EncodeStreamInputDecoder(decodeInput);
} else if (!strncmp(inputFileName, "/dev/video", strlen("/dev/video"))) {
input = new EncodeStreamInputCamera;
} else {
input = new EncodeStreamInputFile;
Expand Down
5 changes: 5 additions & 0 deletions tests/encodeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef encodeinput_h
#define encodeinput_h

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down Expand Up @@ -132,3 +135,5 @@ class EncodeStreamOutputVP8 : public EncodeStreamOutput {
};

bool createOutputBuffer(VideoEncOutputBuffer* outputBuffer, int maxOutSize);

#endif

0 comments on commit ddd2a83

Please sign in to comment.