Finish new api for pixels and change project tree

This commit is contained in:
jfmcarreira committed 2014-11-12 00:18:37 +00:00
1 parent 3ed163a44f
commit a8958a1e43
97 files changed
+456 -677

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
###
### CMakeLists for playuver lib component
###
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} )
ADD_OPTION(USE_OPENCV "Add OpenCV support" OFF )
ADD_OPTION(USE_FFMPEG "Add FFMPEG support" OFF )
ADD_OPTION(USE_PIXFC "Add PIXFC support" OFF )
set(plaYUver_Lib_SRCS
# Frame
PlaYUVerFrame.cpp
PlaYUVerFramePixelFormats.cpp
# Stream
PlaYUVerStream.cpp
)
set(plaYUver_Lib_HEADERS
PlaYUVerFrame.h
PlaYUVerStream.h
)
INCLUDE( LibPixfc.cmake )
CONFIGURE_FILE( PlaYUVerConfig.cmake.in ${CMAKE_BINARY_DIR}/PlaYUVerConfig.cmake @ONLY)
ADD_LIBRARY( PlaYUVerLib ${plaYUver_Lib_SRCS} )
TARGET_LINK_LIBRARIES( PlaYUVerLib ${LINKER_LIBS} )
INSTALL(FILES ${plaYUver_Lib_HEADERS} DESTINATION include )
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libPlaYUVerLib.a DESTINATION lib )
+290
View File
@@ -0,0 +1,290 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file LibMemory.cpp
* \brief Memory allocation functions
*/
#ifndef __LIBMEMORY_H__
#define __LIBMEMORY_H__
#include <cstdio>
#include <cstdlib>
#include <cstring>
namespace plaYUVer
{
typedef void Void;
typedef char Char;
typedef int Int;
typedef size_t SizeT;
#ifdef _MSC_VER
typedef __int64 Int64;
#if _MSC_VER <= 1200 // MS VC6
typedef __int64 UInt64; // MS VC6 does not support unsigned __int64 to double conversion
#else
typedef unsigned __int64 UInt64;
#endif
#else
typedef long long Int64;
typedef unsigned long long UInt64;
#endif
static inline void* mem_malloc( size_t nitems )
{
void *d;
if( ( d = malloc( nitems ) ) == NULL )
{
return NULL;
}
return d;
}
static inline void mem_free( void *ptr )
{
if( ptr != NULL )
{
free( ptr );
ptr = NULL;
}
}
static inline Void* xMallocMem( SizeT nitems )
{
Void *d;
if( ( d = malloc( nitems ) ) == NULL )
{
printf( "malloc failed.\n" );
return NULL;
}
return d;
}
static inline Void* xCallocMem( SizeT nitems, SizeT size )
{
size_t padded_size = nitems * size;
Void *d = xMallocMem( padded_size );
memset( d, 0, ( int )padded_size );
return d;
}
static inline Void xFreePointer( Void *pointer )
{
if( pointer != NULL )
{
free( pointer );
pointer = NULL;
}
}
static inline Void xFreeMem( Void *mem )
{
xFreePointer( mem );
}
template<typename T>
Int getMem1D( T **array1D, Int dim0 )
{
if( ( *array1D = ( T* )xCallocMem( dim0, sizeof(T) ) ) == NULL )
return 0;
return ( sizeof(T*) + dim0 * sizeof(T) );
}
template<typename T>
Int getMem2D( T*** array2D, Int dim0, Int dim1 )
{
Int i;
if( ( *array2D = ( T** )xMallocMem( dim0 * sizeof(T*) ) ) == NULL )
printf( "get_mem2Dint: array2D" );
if( ( *( *array2D ) = ( T* )xCallocMem( dim0 * dim1, sizeof(T) ) ) == NULL )
printf( "get_mem2Dint: array2D" );
for( i = 1; i < dim0; i++ )
( *array2D )[i] = ( *array2D )[i - 1] + dim1;
return dim0 * ( sizeof(T*) + dim1 * sizeof(T) );
}
template<typename T>
Int getMem3D( T**** array3D, Int dim0, Int dim1, Int dim2 )
{
Int i, mem_size = dim0 * sizeof(T**);
if( ( ( *array3D ) = ( T*** )xMallocMem( dim0 * sizeof(T**) ) ) == NULL )
printf( "get_mem3Dint: array3D" );
mem_size += getMem2D( *array3D, dim0 * dim1, dim2 );
for( i = 1; i < dim0; i++ )
( *array3D )[i] = ( *array3D )[i - 1] + dim1;
return mem_size;
}
template<typename T>
Int getMem4D( T***** array4D, Int dim0, Int dim1, Int dim2, Int dim3 )
{
int i, mem_size = dim0 * sizeof(int***);
if( ( ( *array4D ) = ( T**** )xMallocMem( dim0 * sizeof(T***) ) ) == NULL )
printf( "get_mem4Dint: array4D" );
mem_size += getMem3D( *array4D, dim0 * dim1, dim2, dim3 );
for( i = 1; i < dim0; i++ )
( *array4D )[i] = ( *array4D )[i - 1] + dim1;
return mem_size;
}
template<typename T>
Int getMem5D( T****** array5D, Int dim0, Int dim1, Int dim2, Int dim3, Int dim4 )
{
int i, mem_size = dim0 * sizeof(T****);
if( ( ( *array5D ) = ( T***** )xMallocMem( dim0 * sizeof(T****) ) ) == NULL )
printf( "get_mem5Dint: array5D" );
mem_size += getMem4D( *array5D, dim0 * dim1, dim2, dim3, dim4 );
for( i = 1; i < dim0; i++ )
( *array5D )[i] = ( *array5D )[i - 1] + dim1;
return mem_size;
}
template<typename T>
Int getMem3ImageComponents( T**** array3D, Int dim1, Int dim2, Int ratioDim1Chroma, Int ratioDim2Chroma )
{
Int dim0 = 3;
Int i, mem_size = ( dim1 * dim2 + dim1 / ratioDim1Chroma * dim2 / ratioDim2Chroma * 2 ) * sizeof(T);
mem_size += getMem2D<T*>( array3D, dim0, dim1 );
if( ( ( *array3D )[0][0] = ( T* )xCallocMem( dim1 * dim2 + dim1 / ratioDim1Chroma * dim2 / ratioDim2Chroma * 2, sizeof(T) ) ) == NULL )
printf( "getMem3DImageComponents: array1D" );
// Luma
for( i = 1; i < dim1; i++ )
( *array3D )[0][i] = ( *array3D )[0][i - 1] + dim2;
// Chroma
( *array3D )[1][0] = ( *array3D )[0][0] + dim2 * dim1;
for( i = 1; i < dim1 / ratioDim1Chroma; i++ )
( *array3D )[1][i] = ( *array3D )[1][i - 1] + dim2 / ratioDim2Chroma;
( *array3D )[2][0] = ( *array3D )[1][0] + dim2 / ratioDim2Chroma * dim1 / ratioDim1Chroma;
for( i = 1; i < dim1 / ratioDim1Chroma; i++ )
( *array3D )[2][i] = ( *array3D )[2][i - 1] + dim2 / ratioDim2Chroma;
return mem_size;
}
template<typename T>
Void freeMem1D( T *array1D )
{
if( array1D )
{
mem_free( array1D );
}
}
template<typename T>
Void freeMem2D( T** array2D )
{
if( array2D )
{
if( *array2D )
xFreeMem( *array2D );
else
printf( "free_mem2Dint: trying to free unused memory" );
xFreeMem( array2D );
}
else
{
printf( "free_mem2Dint: trying to free unused memory" );
}
}
template<typename T>
Void freeMem3D( T*** array3D )
{
if( array3D )
{
freeMem2D( *array3D );
xFreeMem( array3D );
}
else
{
printf( "free_mem3Dint: trying to free unused memory" );
}
}
template<typename T>
Void freeMem4D( T**** array4D )
{
if( array4D )
{
freeMem3D( *array4D );
xFreeMem( array4D );
}
else
{
printf( "free_mem4Dint: trying to free unused memory" );
}
}
template<typename T>
Void freeMem5D( T***** array5D )
{
if( array5D )
{
freeMem4D( *array5D );
xFreeMem( array5D );
}
else
{
printf( "free_mem5Dint: trying to free unused memory" );
}
}
template<typename T>
Void freeMem3ImageComponents( T*** array3D )
{
if( array3D )
{
if( **array3D )
xFreeMem( **array3D );
freeMem2D<T*>( array3D );
}
}
} // NAMESPACE
#endif // __LIBMEMORY_H__
+16
View File
@@ -0,0 +1,16 @@
#####################################################################################
# Pixfc-sse library cmake file
######################################################################################
# https://code.google.com/p/pixfc-sse/
# svn checkout http://pixfc-sse.googlecode.com/svn/trunk/ pixfc-sse
# Add to folder external
IF( USE_PIXFC )
IF(EXISTS "${EXTERNAL_SRC}/pixfc-sse/build/src/libpixfc-sse.a")
INCLUDE_DIRECTORIES( ${EXTERNAL_SRC}/pixfc-sse/include )
LIST(APPEND LINKER_LIBS ${EXTERNAL_SRC}/pixfc-sse/build/src/libpixfc-sse.a )
LIST(APPEND LINKER_LIBS rt)
ELSE()
SET( USE_PIXFC OFF )
ENDIF()
ENDIF()
+74
View File
@@ -0,0 +1,74 @@
# ===================================================================================================================
# The PlaYUVer Libs CMake configuration file
#
# ** File generated automatically, do not modify **
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# find_package(PlaYUVer REQUIRED)
# include_directories(${PLAYUVER_INCLUDE_DIRS})
# target_link_libraries(MY_TARGET_NAME ${PLAYUVER_LINKER_LIBS})
#
# Or you can search for specific PlaYUVer modules:
#
# find_package(PlaYUVer REQUIRED Frame Stream)
#
# If the module is found then PLAYUVER_<MODULE>_FOUND is set to TRUE.
#
# This file will define the following variables:
# - PLAYUVER_LINKER_LIBS : The list of all imported targets for OpenCV modules.
# - PLAYUVER_CXX_FLAGS
# - PLAYUVER_INCLUDE_DIRS : The PlaYUVer include directories.
# - PLAYUVER_COMPUTE_CAPABILITIES : The version of compute capability
# - PLAYUVER_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API
# - PLAYUVER_VERSION : The version of this PlaYUVer build: "@PLAYUVER_VERSION@"
# - PLAYUVER_VERSION_MAJOR : Major version part of PLAYUVER_VERSION: "@PLAYUVER_VERSION_MAJOR@"
# - PLAYUVER_VERSION_MINOR : Minor version part of PLAYUVER_VERSION: "@PLAYUVER_VERSION_MINOR@"
# - PLAYUVER_VERSION_PATCH : Patch version part of PLAYUVER_VERSION: "@PLAYUVER_VERSION_PATCH@"
#
# ===================================================================================================================
# ======================================================
# Variables:
# ======================================================
SET(PLAYUVER_VERSION @PLAYUVER_VERSION@)
SET(PLAYUVER_VERSION_MAJOR @PLAYUVER_VERSION_MAJOR@)
SET(PLAYUVER_VERSION_MINOR @PLAYUVER_VERSION_MINOR@)
SET(PLAYUVER_VERSION_PATCH @PLAYUVER_VERSION_PATCH@)
SET( PLAYUVER_LINKER_LIBS "" )
SET( PLAYUVER_CXX_FLAGS "" )
SET( PLAYUVER_INCLUDE_DIRS "" )
LIST(APPEND PLAYUVER_LINKER_LIBS "PlaYUVerLib" )
LIST(APPEND PLAYUVER_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include )
# ======================================================
# PlaYUVer dependencies:
# ======================================================
SET( PLAYUVER_HAS_OPENCV @USE_OPENCV@ )
SET( PLAYUVER_HAS_QT4 @USE_QT4@ )
IF( PLAYUVER_HAS_QT4 )
FIND_PACKAGE( Qt4 REQUIRED QtCore )
IF( NOT QT4_FOUND)
SET(USE_QT4 FALSE)
ENDIF()
INCLUDE( ${QT_USE_FILE} )
ADD_DEFINITIONS( ${QT_DEFINITIONS} )
LIST(APPEND PLAYUVER_LIBS ${QT_LIBRARIES} )
ELSE()
FIND_PACKAGE( Qt5Core REQUIRED )
LIST(APPEND PLAYUVER_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} )
LIST(APPEND PLAYUVER_CXX_FLAGS ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} )
LIST(APPEND PLAYUVER_LINKER_LIBS ${Qt5Core_LIBRARIES} )
ENDIF()
IF( PLAYUVER_HAS_OPENCV )
FIND_PACKAGE( OpenCV )
LIST(APPEND PLAYUVER_LINKER_LIBS ${OpenCV_LIBRARIES} )
ENDIF()
+151
View File
@@ -0,0 +1,151 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file TypeDef.h
* \brief Define basic types, new types and enumerations
*/
#ifndef __TYPEDEF_H__
#define __TYPEDEF_H__
#ifdef PLAYUVER
#include "config.h"
#endif
#include <string>
namespace plaYUVer
{
// ====================================================================================================================
// Basic type redefinition
// ====================================================================================================================
typedef void Void;
typedef bool Bool;
typedef char Char;
typedef unsigned char UChar;
typedef short Short;
typedef unsigned short UShort;
typedef int Int;
typedef unsigned int UInt;
typedef double Double;
typedef float Float;
// ====================================================================================================================
// 64-bit integer type
// ====================================================================================================================
#ifdef _MSC_VER
typedef __int64 Int64;
#if _MSC_VER <= 1200 // MS VC6
typedef __int64 UInt64; // MS VC6 does not support unsigned __int64 to double conversion
#else
typedef unsigned __int64 UInt64;
#endif
#else
typedef long long Int64;
typedef unsigned long long UInt64;
#endif
// ====================================================================================================================
// Type definition
// ====================================================================================================================
typedef UChar Pel; ///< 8-bit pixel type
//typedef Short Pel; ///< 16-bit pixel type
// ====================================================================================================================
// Limits definition
// ====================================================================================================================
#define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
#define MAX_INT 2147483647 ///< max. value of signed 32-bit integer
#define MAX_INT64 0x7FFFFFFFFFFFFFFFLL ///< max. value of signed 64-bit integer
#define MAX_DOUBLE 1.7e+308 ///< max. value of double-type value
// ====================================================================================================================
// Macro functions
// ====================================================================================================================
#define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free
#if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
#define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 )
#define xFree( ptr ) _aligned_free ( ptr )
#define xMemSet( type, len, ptr )
#else
#define xMemSet( type, len, ptr ) memset ( ptr, 0, (len)*sizeof(type) )
#define xMalloc( type, len ) malloc ( sizeof(type)*(len) )
#define xFree( ptr ) free ( ptr )
#endif
// ====================================================================================================================
// Qt functions
// ====================================================================================================================
#if( QT_VERSION_PLAYUVER == 4 )
#define QStringLiteral QString::fromUtf8
#endif
// ====================================================================================================================
// PlaYUVer definitions
// ====================================================================================================================
enum YUVcomponent
{
LUMA = 0,
CHROMA_U,
CHROMA_V,
};
enum RGBcomponent
{
COLOR_R = 0,
COLOR_G,
COLOR_B,
};
//typedef struct __pixel_definition
//{
// Int color_space;
// union
// {
// Pel Luma;
// Pel ColorR;
// };
// union
// {
// Pel ChromaU;
// Pel ColorG;
// };
// union
// {
// Pel ChromaV;
// Pel ColorB;
// };
//}Pixel;
} // NAMESPACE
#endif // __TYPEDEF_H__
+600
View File
@@ -0,0 +1,600 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFrame.cpp
* \brief Video Frame handling
*/
#include "config.h"
#include <cstdio>
#include "LibMemory.h"
#include "PlaYUVerFrame.h"
#include "PlaYUVerFramePixelFormats.h"
#ifdef USE_FFMPEG
#include "LibAvContextHandle.h"
#endif
#ifdef USE_OPENCV
#include <opencv2/opencv.hpp>
#endif
#ifdef USE_PIXFC
#include "pixfc-sse.h"
#endif
namespace plaYUVer
{
Int PlaYUVerFrame::isRGBorYUVorGray( Int pixel_format )
{
switch( pixel_format )
{
case GRAY:
return COLOR_GRAY;
break;
case YUV420p:
case YUV444p:
case YUV422p:
case YUYV422:
return COLOR_YUV;
break;
case RGB8:
return COLOR_RGB;
break;
}
return COLOR_INVALID;
}
QStringList PlaYUVerFrame::supportedPixelFormatListNames()
{
QStringList formats;
Int numberFormats = PLAYUVER_NUMBER_FORMATS;
for( Int i = 0; i < numberFormats; i++ )
{
formats << g_PlaYUVerFramePelFormatsList[i].name;
}
return formats;
}
PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format )
{
init( width, height, pel_format );
}
PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other )
{
init( other->getWidth(), other->getHeight(), other->getPelFormat() );
copyFrom( other );
}
PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, QRect area )
{
adjustSelectedAreaDims( area, other->getPelFormat() );
init( area.width(), area.height(), other->getPelFormat() );
copyFrom( other, area.x(), area.y() );
}
PlaYUVerFrame::~PlaYUVerFrame()
{
if( m_pppcInputPel )
freeMem3ImageComponents<Pel>( m_pppcInputPel );
if( m_pcRGB32 )
freeMem1D( m_pcRGB32 );
closePixfc();
}
Void PlaYUVerFrame::adjustSelectedAreaDims( QRect &area, Int pel_format )
{
Int posX = area.x();
Int posY = area.y();
Int width = area.width();
Int height = area.height();
switch( pel_format )
{
case YUV420p:
if( posX % 2 )
area.setX( posX - 1 );
if( posY % 2 )
area.setY( posY - 1 );
if( ( posX + width ) % 2 )
area.setWidth( ( posX + width ) - area.x() + 1 );
else
area.setWidth( ( posX + width ) - area.x() );
if( ( posY + height ) % 2 )
area.setHeight( ( posY + height ) - area.y() + 1 );
else
area.setHeight( ( posY + height ) - area.y() );
break;
case YUV444p:
break;
case YUV422p:
case YUYV422:
if( posX % 2 )
area.setX( posX - 1 );
if( ( posX + width ) % 2 )
area.setWidth( ( posX + width ) - area.x() + 1 );
else
area.setWidth( ( posX + width ) - area.x() );
break;
case GRAY:
break;
case RGB8:
break;
default:
break;
}
}
Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format )
{
m_pppcInputPel = NULL;
m_pcRGB32 = NULL;
m_uiWidth = width;
m_uiHeight = height;
m_iPixelFormat = pel_format;
m_iNumberChannels = 3;
m_iBitsChannels = 8;
Int max_bits_per_pel = sizeof(Pel) * 8;
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || m_iBitsChannels > max_bits_per_pel )
{
return;
}
m_pcPelFormat = &( g_PlaYUVerFramePelFormatsList[pel_format] );
m_bHasRGBPel = false;
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
{
getMem3ImageComponents<Pel>( &m_pppcInputPel, m_uiHeight, m_uiWidth, 1, 1 );
}
else
{
getMem3ImageComponents<Pel>( &m_pppcInputPel, m_uiHeight, m_uiWidth, m_pcPelFormat->ratioChromaHeight, m_pcPelFormat->ratioChromaWidth );
}
getMem1D( &m_pcRGB32, m_uiHeight * m_uiWidth * 4 );
openPixfc();
}
Int PlaYUVerFrame::getColorSpace() const
{
return m_pcPelFormat->colorSpace;
}
Int PlaYUVerFrame::getNumberChannels() const
{
return m_pcPelFormat->numberChannels;
}
UInt64 PlaYUVerFrame::getBytesPerFrame()
{
return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
}
UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat )
{
PlaYUVerFramePelFormat* pcPelFormat = &( g_PlaYUVerFramePelFormatsList[iPixelFormat] );
UInt64 numberBytes = uiWidth * uiHeight;
if( pcPelFormat->numberChannels > 1 )
{
numberBytes += ( pcPelFormat->numberChannels - 1 ) * ( uiWidth * uiHeight ) / ( pcPelFormat->ratioChromaWidth * pcPelFormat->ratioChromaHeight );
}
return numberBytes;
}
UInt PlaYUVerFrame::getChromaWidth() const
{
return m_pcPelFormat->ratioChromaWidth > 0 ? m_uiWidth / m_pcPelFormat->ratioChromaWidth : 0;
}
UInt PlaYUVerFrame::getChromaHeight() const
{
return m_pcPelFormat->ratioChromaHeight > 0 ? m_uiHeight / m_pcPelFormat->ratioChromaHeight : 0;
}
UInt PlaYUVerFrame::getChromaLength() const
{
return getChromaWidth() * getChromaHeight();
}
Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
{
if( uiBuffSize != getBytesPerFrame() )
return;
m_pcPelFormat->frameFromBuffer( Buff, m_pppcInputPel, m_uiWidth, m_uiHeight );
m_bHasRGBPel = false;
fillRGBBuffer();
}
Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer )
{
m_pcPelFormat->bufferFromFrame( m_pppcInputPel, output_buffer, m_uiWidth, m_uiHeight );
}
Void PlaYUVerFrame::fillRGBBuffer()
{
if( m_bHasRGBPel )
return;
m_pcPelFormat->fillRGBbuffer( m_pppcInputPel, m_pcRGB32, m_uiWidth, m_uiHeight );
m_bHasRGBPel = true;
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame )
{
if( m_iPixelFormat != input_frame->getPelFormat() && m_uiWidth == input_frame->getWidth() && m_uiHeight == input_frame->getHeight() )
return;
m_bHasRGBPel = false;
memcpy( *m_pppcInputPel[LUMA], input_frame->getPelBufferYUV()[LUMA][0], getBytesPerFrame() * sizeof(Pel) );
}
Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos )
{
if( m_iPixelFormat != input_frame->getPelFormat() )
return;
m_bHasRGBPel = false;
Pel ***pInput = input_frame->getPelBufferYUV();
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->ratioChromaHeight : 1;
Int ratioW = ch > 0 ? m_pcPelFormat->ratioChromaWidth : 1;
for( UInt i = 0; i < m_uiHeight / ratioH; i++ )
{
memcpy( m_pppcInputPel[ch][i], &( pInput[ch][yPos / ratioH + i][xPos / ratioW] ), m_uiWidth / ratioW * sizeof(Pel) );
}
}
}
PlaYUVerFrame::Pixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, Int eColorSpace )
{
PlaYUVerFrame::Pixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->ratioChromaHeight : 1;
Int ratioW = ch > 0 ? m_pcPelFormat->ratioChromaWidth : 1;
PixelValue.Components()[ch] = m_pppcInputPel[ch][yPos / ratioH][xPos / ratioW];
}
return ConvertPixel( PixelValue, eColorSpace );
}
PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( PlaYUVerFrame::Pixel inputPixel, Int eOutputSpace )
{
Int outA, outB, outC;
PlaYUVerFrame::Pixel outPixel(COLOR_INVALID, 0, 0, 0);
if( inputPixel.ColorSpace() == eOutputSpace || eOutputSpace == COLOR_ARGB || eOutputSpace == COLOR_GRAY )
return inputPixel;
if( eOutputSpace == COLOR_RGB )
{
yuvToRgb<Int>( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC );
outPixel.R() = outA;
outPixel.G() = outB;
outPixel.B() = outC;
}
if( eOutputSpace == COLOR_YUV )
{
rgbToYuv<Int>( inputPixel.R(), inputPixel.G(), inputPixel.B(), outA, outB, outC );
outPixel.Y() = outA;
outPixel.Cb() = outB;
outPixel.Cr() = outC;
}
return outPixel;
}
/*
**************************************************************
* Interface to other libs
**************************************************************
*/
Void PlaYUVerFrame::openPixfc()
{
#ifdef USE_PIXFC
m_pcPixfc = NULL;
PixFcPixelFormat input_format = PixFcYUV420P;
PixFcFlag flags = (PixFcFlag)(PixFcFlag_Default + PixFcFlag_NNbResamplingOnly);
UInt input_row_size = m_uiWidth;
if (create_pixfc(&m_pcPixfc, input_format, PixFcRGB24, m_uiWidth, m_uiHeight, input_row_size, m_uiWidth * 3, flags ) != 0)
{
fprintf(stderr, "Error creating struct pixfc\n");
m_pcPixfc = NULL;
return;
}
#endif
}
Void PlaYUVerFrame::closePixfc()
{
#ifdef USE_PIXFC
if( m_pcPixfc )
destroy_pixfc(m_pcPixfc);
#endif
}
Void PlaYUVerFrame::FrametoRGB8Pixfc()
{
#ifdef USE_PIXFC
switch( m_iPixelFormat )
{
case YUV420p:
m_pcPixfc->convert(m_pcPixfc, m_pppcInputPel, m_pcRGB32);
break;
case YUV422p:
break;
case YUV444p:
case YUYV422:
m_pcPixfc->convert(m_pcPixfc, m_pppcInputPel, m_pcRGB32);
break;
case GRAY:
break;
case RGB8:
break;
default:
// No action.
break;
}
m_bHasRGBPel = true;
#endif
}
Void PlaYUVerFrame::getCvMat( Void** ppCvFrame )
{
#ifdef USE_OPENCV
Int cvType = CV_8UC3;
switch( m_iPixelFormat )
{
case YUV420p:
case YUV444p:
case YUV422p:
case YUYV422:
cvType = CV_8UC4;
break;
case GRAY:
cvType = CV_8UC1;
break;
case RGB8:
cvType = CV_8UC3;
break;
default:
break;
}
cv::Mat *pcCvFrame = new cv::Mat( m_uiHeight, m_uiWidth, cvType );
if( m_iPixelFormat != GRAY )
{
fillRGBBuffer();
memcpy( pcCvFrame->data, m_pcRGB32, m_uiWidth * m_uiHeight * 4 * sizeof(UChar) );
}
else
{
memcpy( pcCvFrame->data, &( m_pppcInputPel[LUMA][0][0] ), m_uiWidth * m_uiHeight * sizeof(Pel) );
}
*ppCvFrame = pcCvFrame;
#endif
}
Void PlaYUVerFrame::fromCvMat( Void* voidFrame )
{
#ifdef USE_OPENCV
cv::Mat* opencvFrame = (cv::Mat*)voidFrame;
if( m_iPixelFormat == NO_FMT )
{
switch( opencvFrame->channels() )
{
case 1:
m_iPixelFormat = GRAY;
break;
case 4:
m_iPixelFormat = RGB8;
break;
default:
return;
}
}
if( !isValid() )
{
init( opencvFrame->cols, opencvFrame->rows, m_iPixelFormat );
}
m_bHasRGBPel = false;
if( m_iPixelFormat != GRAY )
{
Pel* pInputPelY = m_pppcInputPel[LUMA][0];
Pel* pInputPelU = m_pppcInputPel[CHROMA_U][0];
Pel* pInputPelV = m_pppcInputPel[CHROMA_V][0];
Pel* pcRGBPelInterlaced = m_pcRGB32;
memcpy( pcRGBPelInterlaced, opencvFrame->data, m_uiWidth * m_uiHeight * 4 * sizeof(Pel) );
UInt* buff = (UInt*)pcRGBPelInterlaced;
for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ )
{
*pInputPelY++ = pelRed( *buff );
*pInputPelU++ = pelGreen( *buff );
*pInputPelV++ = pelBlue( *buff++ );
}
m_bHasRGBPel = true;
}
else
{
memcpy( m_pppcInputPel[LUMA][0], opencvFrame->data, m_uiWidth * m_uiHeight * sizeof(Pel) );
}
#endif
}
/*
**************************************************************
* Quality Related Function API
**************************************************************
*/
Double PlaYUVerFrame::getQuality( Int Metric, PlaYUVerFrame* Org, Int component )
{
switch( Metric )
{
case PSNR_METRIC:
return getPSNR( Org, component );
break;
case MSE_METRIC:
return getMSE( Org, component );
break;
case SSIM_METRIC:
return getSSIM( Org, component );
break;
default:
assert( 0 );
};
return 0;
}
Double PlaYUVerFrame::getMSE( PlaYUVerFrame* Org, Int component )
{
Pel* pPelYUV = getPelBufferYUV()[component][0];
Pel* pOrgPelYUV = Org->getPelBufferYUV()[component][0];
Int aux_pel_1, aux_pel_2;
Int diff = 0;
Double ssd = 0;
UInt numberOfPixels = 0;
if( component == LUMA )
{
numberOfPixels = Org->getHeight() * Org->getWidth();
}
else
{
numberOfPixels = getChromaLength();
}
for( UInt i = 0; i < numberOfPixels; i++ )
{
aux_pel_1 = *pPelYUV++;
aux_pel_2 = *pOrgPelYUV++;
diff = aux_pel_1 - aux_pel_2;
ssd += ( Double )( diff * diff );
}
if( ssd == 0.0 )
{
return 0.0;
}
return ssd / ( Org->getWidth() * Org->getHeight() );
}
Double PlaYUVerFrame::getPSNR( PlaYUVerFrame* Org, Int component )
{
Double dPSNR = 100;
Double dMSE = getMSE( Org, component );
if( dMSE != 0 )
dPSNR = 10 * log10( 65025 / dMSE );
return dPSNR;
}
float compute_ssim( Pel **refImg, Pel **encImg, Int width, Int height, Int win_width, Int win_height, Int max_pel_value_comp, Int overlapSize )
{
static const float K1 = 0.01f, K2 = 0.03f;
float max_pix_value_sqd;
float C1, C2;
float win_pixels = ( float )( win_width * win_height );
#ifdef UNBIASED_VARIANCE
float win_pixels_bias = win_pixels - 1;
#else
float win_pixels_bias = win_pixels;
#endif
float mb_ssim, meanOrg, meanEnc;
float varOrg, varEnc, covOrgEnc;
int imeanOrg, imeanEnc, ivarOrg, ivarEnc, icovOrgEnc;
float cur_distortion = 0.0;
int i, j, n, m, win_cnt = 0;
max_pix_value_sqd = ( float )( max_pel_value_comp * max_pel_value_comp );
C1 = K1 * K1 * max_pix_value_sqd;
C2 = K2 * K2 * max_pix_value_sqd;
for( j = 0; j <= height - win_height; j += overlapSize )
{
for( i = 0; i <= width - win_width; i += overlapSize )
{
imeanOrg = 0;
imeanEnc = 0;
ivarOrg = 0;
ivarEnc = 0;
icovOrgEnc = 0;
for( n = j; n < j + win_height; n++ )
{
for( m = i; m < i + win_width; m++ )
{
imeanOrg += refImg[n][m];
imeanEnc += encImg[n][m];
ivarOrg += refImg[n][m] * refImg[n][m];
ivarEnc += encImg[n][m] * encImg[n][m];
icovOrgEnc += refImg[n][m] * encImg[n][m];
}
}
meanOrg = ( float )imeanOrg / win_pixels;
meanEnc = ( float )imeanEnc / win_pixels;
varOrg = ( ( float )ivarOrg - ( ( float )imeanOrg ) * meanOrg ) / win_pixels_bias;
varEnc = ( ( float )ivarEnc - ( ( float )imeanEnc ) * meanEnc ) / win_pixels_bias;
covOrgEnc = ( ( float )icovOrgEnc - ( ( float )imeanOrg ) * meanEnc ) / win_pixels_bias;
mb_ssim = ( float )( ( 2.0 * meanOrg * meanEnc + C1 ) * ( 2.0 * covOrgEnc + C2 ) );
mb_ssim /= ( float )( meanOrg * meanOrg + meanEnc * meanEnc + C1 ) * ( varOrg + varEnc + C2 );
cur_distortion += mb_ssim;
win_cnt++;
}
}
cur_distortion /= ( float )win_cnt;
if( cur_distortion >= 1.0 && cur_distortion < 1.01 ) // avoid float accuracy problem at very low QP(e.g.2)
cur_distortion = 1.0;
return cur_distortion;
}
Double PlaYUVerFrame::getSSIM( PlaYUVerFrame* Org, Int component )
{
Double dSSIM = 1;
if( component == LUMA )
{
dSSIM = compute_ssim( m_pppcInputPel[component], Org->getPelBufferYUV()[component], m_uiWidth, m_uiHeight, 8, 8, 255, 8 );
}
else
{
dSSIM = compute_ssim( m_pppcInputPel[component], Org->getPelBufferYUV()[component], getChromaWidth(), getChromaHeight(), 4, 4, 255, 8 );
}
return dSSIM;
}
} // NAMESPACE
+219
View File
@@ -0,0 +1,219 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFrame.h
* \brief Video Frame handling
*/
#ifndef __PLAYUVERFRAME_H__
#define __PLAYUVERFRAME_H__
#include "PlaYUVerDefs.h"
#include <iostream>
#include <cstdio>
#include <cassert>
#include <QtCore>
class PixFcSSE;
namespace plaYUVer
{
class PlaYUVerFrame
{
public:
class Pixel
{
private:
Int m_iColorSpace;
Pel PixelComponents[3];
public:
Pixel()
{
m_iColorSpace = PlaYUVerFrame::COLOR_INVALID;
PixelComponents[0] = 0;
PixelComponents[1] = 0;
PixelComponents[2] = 0;
}
Pixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 )
{
m_iColorSpace = ColorSpace == PlaYUVerFrame::GRAY ? PlaYUVerFrame::COLOR_YUV : ColorSpace;
PixelComponents[0] = c0;
PixelComponents[1] = c1;
PixelComponents[2] = c2;
}
Int ColorSpace() { return m_iColorSpace; }
Pel* Components() { return PixelComponents; }
Pel& Y() { return PixelComponents[0]; }
Pel& Cb() { return PixelComponents[1]; }
Pel& Cr() { return PixelComponents[2]; }
Pel& R() { return PixelComponents[0]; }
Pel& G() { return PixelComponents[1]; }
Pel& B() { return PixelComponents[2]; }
};
enum ColorSpace
{
COLOR_INVALID = -1,
COLOR_YUV = 0,
COLOR_RGB,
COLOR_ARGB,
COLOR_GRAY,
};
enum PixelFormats
{
NO_FMT = -1,
YUV420p = 0,
YUV444p,
YUV422p,
YUYV422,
GRAY,
RGB8,
NUMBER_FORMATS
};
static Int isRGBorYUVorGray( Int pixel_format );
static QStringList supportedPixelFormatListNames();
PlaYUVerFrame( UInt width = 0, UInt height = 0, Int pel_format = 0 );
PlaYUVerFrame( PlaYUVerFrame * );
PlaYUVerFrame( PlaYUVerFrame *, QRect area );
~PlaYUVerFrame();
UInt64 getBytesPerFrame();
static UInt64 getBytesPerFrame( UInt, UInt, Int );
Int getColorSpace() const;
Int getNumberChannels() const;
UInt getChromaWidth() const;
UInt getChromaHeight() const;
UInt getChromaLength() const;
Void frameFromBuffer( Pel*, UInt64 );
Void frameToBuffer( Pel* );
Void fillRGBBuffer();
Void copyFrom( PlaYUVerFrame* );
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
PlaYUVerFrame::Pixel getPixelValue( Int, Int, Int );
static PlaYUVerFrame::Pixel ConvertPixel( Pixel, Int );
UInt getWidth() const
{
return m_uiWidth;
}
UInt getHeight() const
{
return m_uiHeight;
}
Int getPelFormat() const
{
return m_iPixelFormat;
}
Int getBitsChannel() const
{
return m_iBitsChannels;
}
Bool isValid() const
{
return ( m_uiWidth > 0 ) && ( m_uiHeight > 0 ) && ( m_iPixelFormat >= 0 );
}
Bool haveSameFmt( PlaYUVerFrame* other ) const
{
return ( m_uiWidth == other->getWidth() ) && ( m_uiHeight == other->getHeight() ) && ( m_iPixelFormat == other->getPelFormat() );
}
Pel*** getPelBufferYUV() const
{
return m_pppcInputPel;
}
Pel*** getPelBufferYUV()
{
m_bHasRGBPel = false;
return m_pppcInputPel;
}
UChar* getRGBBuffer() const
{
return m_pcRGB32;
}
/**
* Interface to other libs
*/
Void getCvMat( Void** );
Void fromCvMat( Void* );
/**
* Quality metrics interface
*/
enum QualityMetrics
{
NO_METRIC = -1,
PSNR_METRIC = 0,
MSE_METRIC,
SSIM_METRIC,
NUMBER_METRICS,
};
static QStringList supportedQualityMetricsList()
{
QStringList metrics;
metrics << "PSNR"
<< "MSE"
<< "SSIM" // SSIM
;
assert( metrics.size() == NUMBER_METRICS );
return metrics;
}
Double getQuality( Int Metric, PlaYUVerFrame* Org, Int component );
Double getMSE( PlaYUVerFrame* Org, Int component );
Double getPSNR( PlaYUVerFrame* Org, Int component );
Double getSSIM( PlaYUVerFrame* Org, Int component );
private:
struct structPlaYUVerFramePelFormat* m_pcPelFormat;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPixelFormat;
Int m_iNumberChannels;
Int m_iBitsChannels;
Bool m_bHasRGBPel;
Pel*** m_pppcInputPel;
UChar* m_pcRGB32;
Void adjustSelectedAreaDims( QRect &area, Int pel_format );
Void init( UInt width, UInt height, Int pel_format );
Void openPixfc();
Void closePixfc();
PixFcSSE* m_pcPixfc;
Void FrametoRGB8Pixfc();
};
} // NAMESPACE
#endif // __PLAYUVERFRAME_H__
+347
View File
@@ -0,0 +1,347 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFramePixelFormats.cpp
* \brief Handling the pixel formats definition
*/
#include "config.h"
#include <cstdio>
#include "LibMemory.h"
#ifdef USE_FFMPEG
#include "LibAvContextHandle.h"
#endif
#include "PlaYUVerFramePixelFormats.h"
namespace plaYUVer
{
/*
**************************************************************
* Handle different pel formats
* Interface to generalise into one struct the pixel formats
**************************************************************
*/
#ifdef USE_FFMPEG
#define ADD_FFMPEG_PEL_FMT( fmt ) fmt
#else
#define ADD_FFMPEG_PEL_FMT( fmt ) 0
#endif
/**
* YUV Formats
* Progressive and interlaces
*/
Void frameFromBufferYUVProgressive( Pel* in, Pel ***out, UInt width, UInt height, UInt ratioChroma )
{
memcpy( &out[LUMA][0][0], in, width * height * sizeof(Pel) );
memcpy( &out[CHROMA_U][0][0], in + width * height, width * height / ratioChroma * sizeof(Pel) );
memcpy( &out[CHROMA_V][0][0], in + width * height + width * height / ratioChroma, width * height / ratioChroma * sizeof(Pel) );
}
Void bufferFromFrameYUVProgressive( Pel*** in, Pel *out, UInt width, UInt height, UInt ratioChroma )
{
memcpy( out, &in[LUMA][0][0], width * height * sizeof(Pel) );
memcpy( out + width * height, &in[CHROMA_U][0][0], width * height / ratioChroma * sizeof(Pel) );
memcpy( out + width * height + width * height / ratioChroma, &in[CHROMA_V][0][0], width * height / ratioChroma * sizeof(Pel) );
}
Void fillRGBbufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt ratioChromaHor, UInt ratioChromaVer )
{
Pel** pY = in[LUMA];
Pel** pU = in[CHROMA_U];
Pel** pV = in[CHROMA_V];
Int iY, iU, iV, iR, iG, iB;
UInt* buff = ( UInt* )out;
for( UInt y = 0; y < height; y++ )
{
for( UInt x = 0; x < width; x++ )
{
// Pixel (x, y).
iY = pY[y][x];
iU = pU[y >> ratioChromaVer][x >> ratioChromaHor] - 128;
iV = pV[y >> ratioChromaVer][x >> ratioChromaHor] - 128;
yuvToRgb<Int>( iY, iU, iV, iR, iG, iB );
*buff = pelRgb( iR, iG, iB );
buff++;
}
}
}
/**
* YUV420p 12 bits per pixel
*/
Void frameFromBufferYUV420p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 4 );
}
Void bufferFromFrameYUV420p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 4 );
}
Void fillRGBbufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
{
fillRGBbufferYUV( in, out, width, height, 1, 1 );
}
PlaYUVerFramePelFormat yuv420p =
{
"YUV420p",
PlaYUVerFrame::COLOR_YUV,
3,
2,
2,
frameFromBufferYUV420p,
bufferFromFrameYUV420p,
fillRGBbufferYUV420p,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV420P ), };
/**
* YUV444p 24 bits per pixel
*/
Void frameFromBufferYUV444p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 1 );
}
Void bufferFromFrameYUV444p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 1 );
}
Void fillRGBbufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height )
{
fillRGBbufferYUV( in, out, width, height, 0, 0 );
}
PlaYUVerFramePelFormat yuv444p =
{
"YUV444p",
PlaYUVerFrame::COLOR_YUV,
3,
1,
1,
frameFromBufferYUV444p,
bufferFromFrameYUV444p,
fillRGBbufferYUV444p,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV444P ), };
/**
* YUV422p 16 bits per pixel
*/
Void frameFromBufferYUV422p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 2 );
}
Void bufferFromFrameYUV422p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 2 );
}
Void fillRGBbufferYUV422( Pel*** in, UChar* out, UInt width, UInt height )
{
fillRGBbufferYUV( in, out, width, height, 1, 0 );
}
PlaYUVerFramePelFormat yuv422p =
{
"YUV422p",
PlaYUVerFrame::COLOR_YUV,
3,
2,
1,
frameFromBufferYUV422p,
bufferFromFrameYUV422p,
fillRGBbufferYUV422,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV422P ), };
/**
* YUYV422 16 bits per pixel
*/
Void frameFromBufferYUYV422( Pel *in, Pel*** out, UInt width, UInt height )
{
Pel* pY = out[LUMA][0];
Pel* pU = out[CHROMA_U][0];
Pel* pV = out[CHROMA_V][0];
for( UInt i = 0; i < width * height / 2; i++ )
{
*pY++ = *in++;
*pU++ = *in++;
*pY++ = *in++;
*pV++ = *in++;
}
}
Void bufferFromFrameYUYV422( Pel ***in, Pel* out, UInt width, UInt height )
{
Pel* pY = in[LUMA][0];
Pel* pU = in[CHROMA_U][0];
Pel* pV = in[CHROMA_V][0];
for( UInt i = 0; i < height * width / 2; i++ )
{
*out++ = *pY++;
*out++ = *pU++;
*out++ = *pY++;
*out++ = *pV++;
}
}
PlaYUVerFramePelFormat yuyv422 =
{
"YUYV422",
PlaYUVerFrame::COLOR_YUV,
3,
2,
1,
frameFromBufferYUYV422,
bufferFromFrameYUYV422,
fillRGBbufferYUV422,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUYV422 ), };
/**
* Gray Format
*/
Void frameFromBufferGray( Pel *in, Pel*** out, UInt width, UInt height )
{
memcpy( &out[LUMA][0][0], in, width * height * sizeof(Pel) );
}
Void bufferFromFrameGray( Pel ***in, Pel* out, UInt width, UInt height )
{
memcpy( out, &in[LUMA][0][0], width * height * sizeof(Pel) );
}
Void fillRGBbufferGray( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel *inPel = in[0][0];
Pel iY;
UInt* buff = ( UInt* )out;
for( UInt i = 0; i < height * width; i++ )
{
iY = *inPel;
*buff++ = pelRgb( iY, iY, iY );
inPel++;
}
}
PlaYUVerFramePelFormat gray =
{
"GRAY",
PlaYUVerFrame::COLOR_GRAY,
1,
0,
0,
frameFromBufferGray,
bufferFromFrameGray,
fillRGBbufferGray,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ), };
/**
* RGB formats
* Interlaced
*/
Void frameFromBufferRGB( Pel *in, Pel*** out, UInt64 size, Pel* pFirst, Pel* pSecond, Pel* pthird )
{
for( UInt i = 0; i < size; i++ )
{
*pFirst++ = *in++;
*pSecond++ = *in++;
*pthird++ = *in++;
}
}
Void bufferFromFrameRGB( Pel ***in, Pel* out, UInt64 size, Pel* pFirst, Pel* pSecond, Pel* pthird )
{
for( UInt i = 0; i < size; i++ )
{
*out++ = *pFirst++;
*out++ = *pSecond++;
*out++ = *pthird++;
}
}
Void fillRGBbufferRGB( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel* pR = in[COLOR_R][0];
Pel* pG = in[COLOR_G][0];
Pel* pB = in[COLOR_B][0];
Int iR, iG, iB;
UInt* buff = ( UInt* )out;
for( UInt i = 0; i < height * width; i++ )
{
iR = *pR++;
iG = *pG++;
iB = *pB++;
*buff++ = pelRgb( iR, iG, iB );
}
}
/** RGB 8 bits per pixel / 3 channels */
Void frameFromBufferRGB24( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferRGB( in, out, width * height, out[COLOR_R][0], out[COLOR_G][0], out[COLOR_B][0] );
}
Void bufferFromFrameRGB24( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameRGB( in, out, width * height, in[COLOR_R][0], in[COLOR_G][0], in[COLOR_B][0] );
}
PlaYUVerFramePelFormat rgb24 =
{
"RGB24",
PlaYUVerFrame::COLOR_RGB,
3,
1,
1,
frameFromBufferRGB24,
bufferFromFrameRGB24,
fillRGBbufferRGB,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_RGB24 ), };
/** BGR 8 bits per pixel / 3 channels */
Void frameFromBufferBGR24( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferRGB( in, out, width * height, out[COLOR_B][0], out[COLOR_G][0], out[COLOR_R][0] );
}
Void bufferFromFrameBGR24( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameRGB( in, out, width * height, in[COLOR_B][0], in[COLOR_G][0], in[COLOR_R][0] );
}
PlaYUVerFramePelFormat BGR24 =
{
"BRG24",
PlaYUVerFrame::COLOR_RGB,
3,
1,
1,
frameFromBufferBGR24,
bufferFromFrameBGR24,
fillRGBbufferRGB,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_BGR24 ), };
PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS] =
{
yuv420p,
yuv444p,
yuv422p,
yuyv422,
gray,
rgb24,
BGR24, };
} // NAMESPACE
+110
View File
@@ -0,0 +1,110 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFramePixelFormats.h
* \brief Handling the pixel formats definition
*/
#ifndef __PLAYUVERFRAMEPIXELFORMATS_H__
#define __PLAYUVERFRAMEPIXELFORMATS_H__
#include "PlaYUVerDefs.h"
#include "PlaYUVerFrame.h"
namespace plaYUVer
{
template<typename T>
Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB )
{
iR = iY + 1402 * iV / 1000;
iG = iY - ( 101004 * iU + 209599 * iV ) / 293500;
iB = iY + 1772 * iU / 1000;
if( iR < 0 )
iR = 0;
if( iG < 0 )
iG = 0;
if( iB < 0 )
iB = 0;
if( iR > 255 )
iR = 255;
if( iG > 255 )
iG = 255;
if( iB > 255 )
iB = 255;
}
template<typename T>
Void rgbToYuv( T iR, T iG, T iB, T &iY, T &iU, T &iV )
{
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000;
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772;
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402;
}
inline Int pelRed( UInt rgb ) // get red part of RGB
{
return ( ( rgb >> 16 ) & 0xff );
}
inline Int pelGreen( UInt rgb ) // get green part of RGB
{
return ( ( rgb >> 8 ) & 0xff );
}
inline Int pelBlue( UInt rgb ) // get blue part of RGB
{
return ( rgb & 0xff );
}
inline Int pelAlpha( UInt rgb ) // get alpha part of RGBA
{
return rgb >> 24;
}
inline UInt pelRgb( Int r, Int g, Int b ) // set RGB value
{
return ( 0xffu << 24 ) | ( ( r & 0xff ) << 16 ) | ( ( g & 0xff ) << 8 ) | ( b & 0xff );
}
struct structPlaYUVerFramePelFormat
{
const Char* name;
Int colorSpace;
UInt numberChannels;
Int ratioChromaWidth;
Int ratioChromaHeight;
Void (*frameFromBuffer)( Pel *in, Pel*** out, UInt width, UInt height );
Void (*bufferFromFrame)( Pel ***in, Pel* out, UInt width, UInt height );
Void (*fillRGBbuffer)( Pel*** in, UChar* out, UInt width, UInt height );
Int ffmpegPelFormat;
};
typedef struct structPlaYUVerFramePelFormat PlaYUVerFramePelFormat;
#define PLAYUVER_NUMBER_FORMATS 7
extern PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS];
} // NAMESPACE
#endif // __PLAYUVERFRAMEPIXELFORMATS_H__
+694
View File
@@ -0,0 +1,694 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerStream.cpp
* \brief Input stream handling
*/
#include "config.h"
#include <cstdio>
#include "LibMemory.h"
#include "PlaYUVerStream.h"
#include <QImage>
#ifdef USE_FFMPEG
#include "LibAvContextHandle.h"
#endif
namespace plaYUVer
{
QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array )
{
PlaYUVerStreamInfo d;
out << array.size();
for( Int i = 0; i < array.size(); i++ )
{
d = array.at( i );
out << d.m_cFilename << d.m_uiWidth
<< d.m_uiHeight
<< d.m_iPelFormat
<< d.m_uiFrameRate;
}
return out;
}
QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& array )
{
PlaYUVerStreamInfo d;
Int array_size;
in >> array_size;
for( Int i = 0; i < array_size; i++ )
{
in >> d.m_cFilename;
in >> d.m_uiWidth;
in >> d.m_uiHeight;
in >> d.m_iPelFormat;
in >> d.m_uiFrameRate;
array.append( d );
}
return in;
}
Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename )
{
for( Int i = 0; i < array.size(); i++ )
if( array.at( i ).m_cFilename == filename )
return i;
return -1;
}
PlaYUVerStream::PlaYUVerStream()
{
m_bInit = false;
m_bIsInput = true;
m_bIsOpened = false;
m_bLoadAll = false;
m_iErrorStatus = 0;
m_pFile = NULL;
m_uiWidth = 0;
m_uiHeight = 0;
m_uiTotalFrameNum = 0;
m_iCurrFrameNum = -1;
m_iPixelFormat = -1;
m_uiFrameRate = 30;
m_iFileFormat = INVALID_INPUT;
m_pStreamBuffer = NULL;
m_cFilename = QString( "" );
m_cStreamInformationString = QString( "" );
m_pcCurrFrame = NULL;
m_pcNextFrame = NULL;
m_ppcFrameBuffer = NULL;
m_uiFrameBufferSize = 2;
m_uiFrameBufferIndex = 0;
#ifdef USE_FFMPEG
m_cLibAvContext = new LibAvContextHandle;
#endif
}
PlaYUVerStream::~PlaYUVerStream()
{
close();
}
Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput )
{
Bool avStatus = false;
if( m_bInit )
{
close();
}
m_bInit = false;
m_bIsInput = bInput;
m_cFilename = filename;
m_uiWidth = width;
m_uiHeight = height;
m_iPixelFormat = input_format;
m_uiFrameRate = frame_rate;
if( m_bIsInput )
{
m_iFileFormat = INVALID_INPUT;
QStringList formatsExt = PlaYUVerStream::supportedReadFormatsExt();
QString currExt = QFileInfo( filename ).suffix();
if( formatsExt.contains( currExt ) )
{
m_iFileFormat = formatsExt.indexOf( currExt );
}
if( m_iFileFormat == INVALID_INPUT )
{
close();
return m_bInit;
}
m_cFormatName = PlaYUVerStream::supportedReadFormatsExt().at( m_iFileFormat ).toUpper();
#ifdef USE_FFMPEG
if( m_iFileFormat != YUVINPUT )
{
avStatus = m_cLibAvContext->initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, m_uiTotalFrameNum );
m_cCodedName = QString::fromUtf8( m_cLibAvContext->getCodecName() ).toUpper();
}
#endif
#if 0
if( !avStatus )
{
switch( m_iFileFormat )
{
case PGMINPUT:
break;
}
}
#endif
m_uiFrameBufferSize = 2;
}
else
{
m_iFileFormat = YUVOUTPUT;
m_uiFrameBufferSize = 1;
}
if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 )
{
qDebug( ) << "Incorrect configuration";
close();
return m_bInit;
}
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
if( !m_ppcFrameBuffer[i] )
{
qDebug( ) << "Cannot allocated frame buffer";
close();
return m_bInit;
}
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
if( !avStatus )
{
if( !openFile() )
{
close();
return m_bInit;
}
m_cFormatName = QString::fromUtf8( "YUV" );
m_cCodedName = QString::fromUtf8( "Raw Video" );
}
if( !avStatus && m_iFileFormat == YUVINPUT )
{
if( m_bIsInput )
{
fseek( m_pFile, 0, SEEK_END );
UInt64 fileSize = ftell( m_pFile );
#if 0
if( fileSize % frame_bytes_input )
{
Int remaining = fileSize % frame_bytes_input;
qDebug( ) << "Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )";
close();
return m_bInit;
}
#endif
m_uiTotalFrameNum = fileSize / frame_bytes_input;
fseek( m_pFile, 0, SEEK_SET );
}
}
if( m_bIsInput && m_uiTotalFrameNum <= 0 )
{
qDebug( ) << "Incorrect configuration: less than one frame";
close();
return m_bInit;
}
if( !getMem1D<Pel>( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) )
{
close();
return m_bInit;
}
m_cStreamInformationString = QString( "[" );
m_cStreamInformationString.append( m_cFormatName );
m_cStreamInformationString.append( QString( " / " ) );
m_cStreamInformationString.append( m_cCodedName );
m_cStreamInformationString.append( QString( " / " ) );
m_cStreamInformationString.append( PlaYUVerFrame::supportedPixelFormatListNames().at( m_iPixelFormat ) );
m_cStreamInformationString.append( "] " );
m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() );
m_sStreamInfo.m_cFilename = m_cFilename;
m_sStreamInfo.m_uiWidth = m_uiWidth;
m_sStreamInfo.m_uiHeight = m_uiHeight;
m_sStreamInfo.m_iPelFormat = m_iPixelFormat;
m_sStreamInfo.m_uiFrameRate = m_uiFrameRate;
m_iCurrFrameNum = -1;
m_bInit = true;
seekInput( 0 );
m_bInit = true;
return m_bInit;
}
Bool PlaYUVerStream::openFile()
{
m_pFile = NULL;
Char *filename = new char[m_cFilename.length() + 1];
memcpy( filename, m_cFilename.toUtf8().constData(), m_cFilename.length() + 1 * sizeof(char) );
m_pFile = fopen( filename, m_bIsInput ? "rb" : "wb" );
delete[] filename;
if( m_pFile == NULL )
{
return false;
}
fseek( m_pFile, m_iCurrFrameNum >= 0 ? m_iCurrFrameNum : 0, SEEK_SET );
return true;
}
Void PlaYUVerStream::closeFile()
{
if( m_pFile )
fclose( m_pFile );
}
Void PlaYUVerStream::close()
{
if( !m_bInit )
return;
closeFile();
#ifdef USE_FFMPEG
m_cLibAvContext->closeAvFormat();
#endif
if( m_ppcFrameBuffer )
{
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
if( m_ppcFrameBuffer[i] )
delete m_ppcFrameBuffer[i];
m_ppcFrameBuffer[i] = NULL;
}
freeMem1D<PlaYUVerFrame*>( m_ppcFrameBuffer );
m_ppcFrameBuffer = NULL;
}
if( m_pStreamBuffer )
freeMem1D<Pel>( m_pStreamBuffer );
m_bLoadAll = false;
m_bInit = false;
}
Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate )
{
if( m_bInit )
{
rWidth = m_uiWidth;
rHeight = m_uiHeight;
rInputFormat = m_iPixelFormat;
rFrameRate = m_uiFrameRate;
}
else
{
rWidth = 0;
rHeight = 0;
rInputFormat = PlaYUVerFrame::YUV420p;
rFrameRate = 30;
}
}
Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate )
{
Bool bRet = false;
QString FilenameShort = QFileInfo( filename ).fileName();
QString fileExtension = QFileInfo( filename ).suffix();
if( !fileExtension.compare( "yuv" ) )
{
bRet = true;
// Guess pixel format
QStringList formats_list = PlaYUVerFrame::supportedPixelFormatListNames();
for( Int i = 0; i < formats_list.size(); i++ )
{
if( FilenameShort.contains( formats_list.at( i ), Qt::CaseInsensitive ) )
{
rInputFormat = i;
break;
}
}
if( rWidth == 0 || rHeight == 0 )
{
// Guess resolution - match resolution name
Int iMatch = -1;
QStringList stdResName = standardResolutionSizes().stringListName;
for( Int i = 0; i < stdResName.size(); i++ )
{
if( FilenameShort.contains( stdResName.at( i ) ) )
{
if( iMatch >= 0 )
{
if( stdResName.at( i ).size() > stdResName.at( iMatch ).size() )
{
iMatch = i;
}
}
else
{
iMatch = i;
}
}
}
if( iMatch >= 0 )
{
rWidth = standardResolutionSizes().sizeResolution.at( iMatch ).width();
rHeight = standardResolutionSizes().sizeResolution.at( iMatch ).height();
}
// Guess resolution - match %dx%d
#if( QT_VERSION_PLAYUVER == 5 )
QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort );
if( resolutionMatch.hasMatch() )
{
QString resolutionString = resolutionMatch.captured( 0 );
if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) )
{
resolutionString.remove( "_" );
QStringList resolutionArgs = resolutionString.split( "x" );
qDebug( ) << "Found resolution = " << resolutionArgs;
if( resolutionArgs.size() == 2 )
{
rWidth = resolutionArgs.at( 0 ).toUInt();
rHeight = resolutionArgs.at( 1 ).toUInt();
}
}
}
#endif
}
// Guess resolution by file size
if( rWidth == 0 && rHeight == 0 )
{
Char *filename_char = new char[filename.length() + 1];
memcpy( filename_char, filename.toUtf8().constData(), filename.length() + 1 * sizeof(char) );
FILE* pF = fopen( filename_char, "rb" );
fseek( pF, 0, SEEK_END );
UInt64 uiFileSize = ftell( pF );
fclose( pF );
delete[] filename_char;
if( pF != NULL )
{
Int count = 0, module, frame_bytes, match;
QVector<QSize> sizeResolution = standardResolutionSizes().sizeResolution;
for( Int i = 0; i < sizeResolution.size(); i++ )
{
frame_bytes = PlaYUVerFrame::getBytesPerFrame( sizeResolution.at( i ).width(), sizeResolution.at( i ).height(), rInputFormat );
module = uiFileSize % frame_bytes;
if( module == 0 )
{
match = i;
count++;
}
}
if( count == 1 )
{
rWidth = sizeResolution.at( match ).width();
rHeight = sizeResolution.at( match ).height();
}
}
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
bRet = false;
}
return bRet;
}
Void PlaYUVerStream::loadAll()
{
if( m_bLoadAll || !m_bIsInput )
return;
if( m_ppcFrameBuffer )
{
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
if( m_ppcFrameBuffer[i] )
delete m_ppcFrameBuffer[i];
m_ppcFrameBuffer[i] = NULL;
}
freeMem1D<PlaYUVerFrame*>( m_ppcFrameBuffer );
m_ppcFrameBuffer = NULL;
}
m_uiFrameBufferSize = m_uiTotalFrameNum;
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
if( !m_ppcFrameBuffer[i] )
{
close();
}
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
m_iCurrFrameNum = -1;
seekInput( 0 );
setNextFrame();
for( UInt i = m_uiFrameBufferIndex; i < m_uiFrameBufferSize; i++ )
{
readFrame();
setNextFrame();
}
m_bLoadAll = true;
seekInput( 0 );
}
Void PlaYUVerStream::getDuration( Int* duration_array )
{
Int hours, mins, secs;
#ifdef USE_FFMPEG
if( m_cLibAvContext->getStatus() )
{
secs = m_cLibAvContext->getStreamDuration();
}
else
#endif
{
secs = m_uiTotalFrameNum / m_uiFrameRate;
}
mins = secs / 60;
secs %= 60;
hours = mins / 60;
mins %= 60;
*duration_array++ = hours;
*duration_array++ = mins;
*duration_array++ = secs;
}
Void PlaYUVerStream::readFrame()
{
if( !m_bInit || !m_bIsInput )
return;
if( m_iCurrFrameNum + 1 >= ( Int64 )m_uiTotalFrameNum )
{
m_iErrorStatus = LAST_FRAME;
m_pcNextFrame = NULL;
return;
}
if( m_bLoadAll )
{
return;
}
#ifdef USE_FFMPEG
if( m_cLibAvContext->getStatus() )
{
if( !m_cLibAvContext->decodeAvFormat() )
{
m_iErrorStatus = READING;
return;
}
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize );
}
else
#endif
{
UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame();
UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
m_iErrorStatus = READING;
qDebug( ) << " Reading error !!!"
<< endl;
return;
}
m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read );
}
m_pcNextFrame->fillRGBBuffer();
return;
}
Void PlaYUVerStream::writeFrame()
{
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
m_pcCurrFrame->frameToBuffer( m_pStreamBuffer );
UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
m_iErrorStatus = WRITING;
}
return;
}
Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
{
UInt64 frame_bytes_input = pcFrame->getBytesPerFrame();
pcFrame->frameToBuffer( m_pStreamBuffer );
UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
m_iErrorStatus = WRITING;
}
return;
}
Bool PlaYUVerStream::saveFrame( const QString& filename )
{
return saveFrame( filename, m_pcCurrFrame );
}
Bool PlaYUVerStream::saveFrame( const QString& filename, PlaYUVerFrame *saveFrame )
{
Int iFileFormat = INVALID_OUTPUT;
QStringList formatsExt = PlaYUVerStream::supportedSaveFormatsExt();
QString currExt = QFileInfo( filename ).suffix();
if( formatsExt.contains( currExt ) )
{
iFileFormat = formatsExt.indexOf( currExt );
}
if( iFileFormat < TOTAL_OUTPUT_FORMATS )
{
PlaYUVerStream auxFrameStream;
if( !auxFrameStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), 1, false ) )
{
return false;
}
auxFrameStream.writeFrame( saveFrame );
auxFrameStream.close();
return true;
}
else
{
saveFrame->fillRGBBuffer();
QImage qimg = QImage( saveFrame->getRGBBuffer(), saveFrame->getWidth(), saveFrame->getHeight(), QImage::Format_RGB32 );
return qimg.save( filename );
}
return false;
}
Void PlaYUVerStream::setNextFrame()
{
if( m_pcNextFrame )
{
m_pcCurrFrame = m_pcNextFrame;
m_iCurrFrameNum++;
m_uiFrameBufferIndex++;
if( m_uiFrameBufferIndex == m_uiFrameBufferSize )
{
m_uiFrameBufferIndex = 0;
}
m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
}
else
{
m_iErrorStatus = END_OF_SEQ;
seekInput( 0 );
}
}
PlaYUVerFrame* PlaYUVerStream::getCurrFrame( PlaYUVerFrame *pyuv_image )
{
if( pyuv_image == NULL )
pyuv_image = new PlaYUVerFrame( m_pcCurrFrame );
else
pyuv_image->copyFrom( m_pcCurrFrame );
return pyuv_image;
}
PlaYUVerFrame* PlaYUVerStream::getCurrFrame()
{
return m_pcCurrFrame;
}
Bool PlaYUVerStream::seekInput( UInt64 new_frame_num )
{
if( !m_bInit || new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum || ( Int64 )new_frame_num == m_iCurrFrameNum )
return false;
m_iCurrFrameNum = new_frame_num - 1;
if( m_bLoadAll )
{
m_uiFrameBufferIndex = new_frame_num;
m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
setNextFrame();
return true;
}
#ifdef USE_FFMPEG
if( m_cLibAvContext->getStatus() )
{
m_cLibAvContext->seekAvFormat( new_frame_num );
}
else
#endif
{
UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame();
UInt64 nbytes_seek = frame_bytes_input * new_frame_num;
fseek( m_pFile, nbytes_seek, SEEK_SET );
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
readFrame();
setNextFrame();
if( m_uiTotalFrameNum > 1 )
readFrame();
return true;
}
Bool PlaYUVerStream::checkErrors( Int error_type )
{
if( m_iErrorStatus == error_type )
{
m_iErrorStatus = NO_STREAM_ERROR;
return true;
}
if( m_iErrorStatus == error_type )
{
m_iErrorStatus = NO_STREAM_ERROR;
return true;
}
return false;
}
} // NAMESPACE
+327
View File
@@ -0,0 +1,327 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerStream.h
* \brief Input stream handling
*/
#ifndef __PLAYUVERSTREAM_H__
#define __PLAYUVERSTREAM_H__
#include "PlaYUVerDefs.h"
#include <iostream>
#include <cstdio>
#include <QtCore>
#include "PlaYUVerFrame.h"
namespace plaYUVer
{
class LibAvContextHandle;
typedef struct
{
QString m_cFilename;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPelFormat;
UInt m_uiFrameRate;
}PlaYUVerStreamInfo;
typedef QVector<PlaYUVerStreamInfo> PlaYUVerStreamInfoVector;
QDataStream& operator<<(QDataStream& out, const PlaYUVerStreamInfoVector& d);
QDataStream& operator>>(QDataStream& in, PlaYUVerStreamInfoVector& d);
Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename );
class PlaYUVerStream
{
private:
Bool m_bInit;
Bool m_bIsInput;
Bool m_bIsOpened;
Bool m_bLoadAll;
Int m_iErrorStatus;
PlaYUVerStreamInfo m_sStreamInfo;
LibAvContextHandle* m_cLibAvContext;
QString m_cFilename;
QString m_cFormatName;
QString m_cCodedName;
QString m_cStreamInformationString;
FILE* m_pFile; /**< The input file pointer >*/
Int m_iFileFormat;
Int m_iPixelFormat;
Pel* m_pStreamBuffer;
UInt m_uiFrameBufferSize;
PlaYUVerFrame **m_ppcFrameBuffer;
PlaYUVerFrame *m_pcCurrFrame;
PlaYUVerFrame *m_pcNextFrame;
UInt m_uiFrameBufferIndex;
UInt m_uiWidth;
UInt m_uiHeight;
UInt m_uiFrameRate;
UInt64 m_uiTotalFrameNum;
Int64 m_iCurrFrameNum;
public:
PlaYUVerStream();
~PlaYUVerStream();
enum PlaYUVerStreamInputFormats
{
INVALID_INPUT = -1,
YUVINPUT = 0,
#ifdef USE_FFMPEG
AVIINPUT,
MP4INPUT,
WMVINPUT,
PGMINPUT,
PNGINPUT,
BMPINPUT,
JPEGINPUT,
#endif
TOTAL_INPUT_FORMATS
};
static QStringList supportedReadFormatsExt()
{
QStringList formatsExt;
formatsExt << "yuv" // Raw video
#ifdef USE_FFMPEG
<< "avi" // Audio video interleaved
<< "mp4"// MP4
<< "wmv"// Windows media video
<< "pgm"
<< "png"
<< "bmp"
<< "jpg"
#endif
;
assert( formatsExt.size() == TOTAL_INPUT_FORMATS );
return formatsExt;
}
static QStringList supportedReadFormatsName()
{
QStringList formatsName;
formatsName << "Raw video"
#ifdef USE_FFMPEG
<< "Audio video interleaved"
<< "MPEG4"
<< "Windows media video"
<< "Portable Grayscale Map"
<< "Portable Network Graphics"
<< "Windows Bitmap"
<< "Joint Photographic Experts Group"
#endif
;
assert( formatsName.size() == TOTAL_INPUT_FORMATS );
return formatsName;
}
enum PlaYUVerStreamOutputFormats
{
INVALID_OUTPUT = -1,
YUVOUTPUT = 0,
TOTAL_OUTPUT_FORMATS
};
static QStringList supportedWriteFormatsExt()
{
QStringList formatsExt;
formatsExt << "yuv" // raw video
;
assert( formatsExt.size() == TOTAL_OUTPUT_FORMATS );
return formatsExt;
}
static QStringList supportedWriteFormatsName()
{
QStringList formatsName;
formatsName << "Raw video";
assert( formatsName.size() == TOTAL_OUTPUT_FORMATS );
return formatsName;
}
static QStringList supportedSaveFormatsExt()
{
QStringList formatsExt;
formatsExt << supportedWriteFormatsExt()
<< "bmp"
<< "jpeg"
<< "png" // portable network graphics
;
formatsExt.removeDuplicates();
return formatsExt;
}
static QStringList supportedSaveFormatsName()
{
QStringList formatsName;
formatsName << supportedWriteFormatsName()
<< "Windows Bitmap"
<< "Joint Photographic Experts Group"
<< "Portable Network Graphics";
formatsName.removeDuplicates();
return formatsName;
}
#define REGIST_STANDARD_RESOLUTION( name, width, height) \
stdRes.stringListName.append( QString( name ) ); \
stdRes.stringListFullName.append( QString( "%1 (%2x%3)" ).arg( name ).arg( width ).arg( height ) ); \
stdRes.sizeResolution.append( QSize( width, height ) )
struct StandardResolution
{
QStringList stringListName;
QStringList stringListFullName;
QVector<QSize> sizeResolution;
};
static struct StandardResolution standardResolutionSizes()
{
struct StandardResolution stdRes;
REGIST_STANDARD_RESOLUTION( "CIF", 352, 288 );
REGIST_STANDARD_RESOLUTION( "VGA", 640, 480 );
REGIST_STANDARD_RESOLUTION( "WVGA", 832, 480 );
REGIST_STANDARD_RESOLUTION( "XVGA", 1024, 768 );
REGIST_STANDARD_RESOLUTION( "HD", 1280, 720 );
REGIST_STANDARD_RESOLUTION( "SXGA-", 1280, 900 );
REGIST_STANDARD_RESOLUTION( "SXGA", 1280, 1024 );
REGIST_STANDARD_RESOLUTION( "WSXGA", 1440, 900 );
REGIST_STANDARD_RESOLUTION( "FullHD", 1920, 1080 );
REGIST_STANDARD_RESOLUTION( "WQXGA", 2560, 1600 );
REGIST_STANDARD_RESOLUTION( "UltraHD", 3840, 2160 );
REGIST_STANDARD_RESOLUTION( "8K", 8192, 4608 );
return stdRes;
}
enum PlaYUVerStreamErrors
{
NO_STREAM_ERROR = 0,
READING,
WRITING,
LAST_FRAME,
END_OF_SEQ,
};
Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput = true );
Void close();
Bool openFile();
Void closeFile();
static Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void loadAll();
Void readFrame();
Void writeFrame();
Void writeFrame( PlaYUVerFrame *pcFrame );
Bool saveFrame( const QString& filename );
static Bool saveFrame( const QString& filename, PlaYUVerFrame *saveFrame );
Void setNextFrame();
PlaYUVerFrame* getCurrFrame();
PlaYUVerFrame* getCurrFrame( PlaYUVerFrame * );
Bool seekInput( UInt64 new_frame_num );
Bool checkErrors( Int error_type );
Bool isInit()
{
return m_bInit;
}
QString getFileName()
{
return m_cFilename;
}
QString getStreamInformationString()
{
return m_cStreamInformationString;
}
QString getFormatName()
{
return m_cFormatName;
}
QString getCodecName()
{
return m_cCodedName;
}
UInt getFrameNum()
{
return m_uiTotalFrameNum;
}
UInt getWidth() const
{
return m_uiWidth;
}
UInt getHeight() const
{
return m_uiHeight;
}
Int getCurrFrameNum()
{
return m_iCurrFrameNum;
}
UInt getFrameRate()
{
return m_uiFrameRate;
}
Void getDuration( Int* duration_array );
Void setWidth( UInt new_width )
{
if( new_width > 0 && new_width % 2 == 0 )
{
m_uiWidth = new_width;
}
}
Void setHeight( UInt new_height )
{
if( new_height > 0 && new_height % 2 == 0 )
{
m_uiHeight = new_height;
}
}
PlaYUVerStreamInfo getStreamInfo()
{
return m_sStreamInfo;
}
};
} // NAMESPACE
Q_DECLARE_METATYPE(plaYUVer::PlaYUVerStreamInfo);
Q_DECLARE_METATYPE(plaYUVer::PlaYUVerStreamInfoVector);
#endif // __PLAYUVERSTREAM_H__
+277
View File
@@ -0,0 +1,277 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file LibAvContextHandle.cpp
* \brief Interface with libav libs
*/
#include <cstdio>
#include "LibAvContextHandle.h"
#include "PlaYUVerFrame.h"
#include "PlaYUVerFramePixelFormats.h"
#include "LibMemory.h"
namespace plaYUVer
{
static int open_codec_context( int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type )
{
int ret;
AVStream *st;
AVCodecContext *dec_ctx = NULL;
AVCodec *dec = NULL;
ret = av_find_best_stream( fmt_ctx, type, -1, -1, NULL, 0 );
if( ret < 0 )
{
return ret;
}
else
{
*stream_idx = ret;
st = fmt_ctx->streams[*stream_idx];
/* find decoder for the stream */
dec_ctx = st->codec;
dec = avcodec_find_decoder( dec_ctx->codec_id );
if( !dec )
{
printf( "Failed to find %s codec\n", av_get_media_type_string( type ) );
return ret;
}
if( ( ret = avcodec_open2( dec_ctx, dec, NULL ) ) < 0 )
{
printf( "Failed to open %s codec\n", av_get_media_type_string( type ) );
return ret;
}
}
return 0;
}
Void LibAvContextHandle::closeAvFormat()
{
if( m_bHasStream )
{
if( video_dec_ctx )
avcodec_close( video_dec_ctx );
if( fmt_ctx )
avformat_close_input( &fmt_ctx );
av_free( frame );
//av_free( video_dst_data[0] );
}
m_bHasStream = false;
}
Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& frame_rate, UInt64& num_frames )
{
fmt_ctx = NULL;
video_dec_ctx = NULL;
video_stream = NULL;
// video_dst_data[0] = NULL;
// video_dst_data[1] = NULL;
// video_dst_data[2] = NULL;
// video_dst_data[3] = NULL;
video_stream_idx = -1;
frame = NULL;
m_bHasStream = false;
char *src_filename = filename;
AVDictionary *format_opts = NULL;
/* register all formats and codecs */
av_register_all();
if( width > 0 && height > 0 )
{
Char aux_string[10];
sprintf( aux_string, "%dx%d", width, height );
av_dict_set( &format_opts, "video_size", aux_string, 0 );
}
Int ffmpeg_pel_format = g_PlaYUVerFramePelFormatsList[pixel_format].ffmpegPelFormat;
if( ffmpeg_pel_format >= 0 )
{
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AVPixelFormat( ffmpeg_pel_format ) ), 0 );
}
/* open input file, and allocate format context */
if( avformat_open_input( &fmt_ctx, src_filename, NULL, &format_opts ) < 0 )
{
//qDebug( ) << " Could not open source file %s !!!" << filename << endl;
return false;
}
/* retrieve stream information */
if( avformat_find_stream_info( fmt_ctx, NULL ) < 0 )
{
//qDebug( ) << " Could not find stream information !!!" << endl;
return false;
}
if( open_codec_context( &video_stream_idx, fmt_ctx, AVMEDIA_TYPE_VIDEO ) >= 0 )
{
video_stream = fmt_ctx->streams[video_stream_idx];
video_dec_ctx = video_stream->codec;
// /* allocate image where the decoded image will be put */
// ret = av_image_alloc( video_dst_data, video_dst_linesize, video_dec_ctx->width, video_dec_ctx->height, video_dec_ctx->pix_fmt, 1 );
// if( ret < 0 )
// {
// //qDebug( ) << " Could not allocate raw video buffer !!!" << endl;
// closeAvFormat();
// return false;
// }
// video_dst_bufsize = ret;
m_uiFrameBufferSize = av_image_get_buffer_size( video_dec_ctx->pix_fmt, video_dec_ctx->width, video_dec_ctx->height, 1);
getMem1D( &m_pchFrameBuffer, m_uiFrameBufferSize );
}
const char *codec_name = avcodec_get_name( video_dec_ctx->codec_id );
sprintf( m_acCodecName, "%s", codec_name );
Double fr = 30;
if( video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num )
fr = av_q2d( video_stream->avg_frame_rate );
#if FF_API_R_FRAME_RATE
else if( video_stream->r_frame_rate.den && video_stream->r_frame_rate.num )
fr = av_q2d( video_stream->r_frame_rate );
#endif
else if( video_stream->time_base.den && video_stream->time_base.num )
fr = 1 / av_q2d( video_stream->time_base );
else if( video_stream->codec->time_base.den && video_stream->codec->time_base.num )
fr = 1 / av_q2d( video_stream->codec->time_base );
frame_rate = ( UInt )fr;
if( fmt_ctx->duration != AV_NOPTS_VALUE )
{
Int64 duration = fmt_ctx->duration + 5000;
m_uiSecs = duration / AV_TIME_BASE;
num_frames = m_uiSecs * frame_rate;
m_uiMicroSec = duration % AV_TIME_BASE;
num_frames = num_frames == 0 ? 1 : num_frames;
}
else
{
num_frames = 0;
}
width = video_dec_ctx->width;
height = video_dec_ctx->height;
pixel_format = PlaYUVerFrame::NO_FMT;
for( Int i = 0; i < PLAYUVER_NUMBER_FORMATS; i++ )
{
if( g_PlaYUVerFramePelFormatsList[i].ffmpegPelFormat == video_dec_ctx->pix_fmt )
{
pixel_format = i;
break;
}
}
/* dump input information to stderr */
av_dump_format( fmt_ctx, 0, src_filename, 0 );
if( !video_stream )
{
//qDebug( ) << " Could not find audio or video stream in the input, aborting !!!" << endl;
closeAvFormat();
return false;
}
#if( LIBAVFORMAT_VERSION_MAJOR >= 55 )
frame = av_frame_alloc();
#else
frame = avcodec_alloc_frame();
#endif
if( !frame )
{
//qDebug( ) << " Could not allocate frame !!!" << endl;
//ret = AVERROR( ENOMEM );
closeAvFormat();
return false;
}
/* initialize packet, set data to NULL, let the demuxer fill it */
av_init_packet( &pkt );
pkt.data = NULL;
pkt.size = 0;
m_bHasStream = true;
return true;
}
Bool LibAvContextHandle::decodeAvFormat()
{
Int got_frame;
/* read frames from the file */
while( av_read_frame( fmt_ctx, &pkt ) >= 0 )
{
if( pkt.stream_index == video_stream_idx )
{
/* decode video frame */
Int ret = avcodec_decode_video2( video_dec_ctx, frame, &got_frame, &pkt );
if( ret < 0 )
{
fprintf( stderr, "Error decoding video frame\n" );
return false;
}
if( got_frame )
{
av_image_copy_to_buffer( m_pchFrameBuffer, m_uiFrameBufferSize,
frame->data,frame->linesize, video_dec_ctx->pix_fmt, video_dec_ctx->width,
video_dec_ctx->height, 1);
/* copy decoded frame to destination buffer:
* this is required since rawvideo expects non aligned data */
// av_image_copy( video_dst_data, video_dst_linesize, ( const uint8_t ** )( frame->data ), frame->linesize, video_dec_ctx->pix_fmt, video_dec_ctx->width,
// video_dec_ctx->height );
}
}
av_free_packet( &pkt );
if( got_frame )
return true;
}
return false;
// /* flush cached frames */
// pkt.data = NULL;
// pkt.size = 0;
// do
// {
// decode_packet( &got_frame, 1 );
// }
// while( got_frame );
return true;
}
Void LibAvContextHandle::seekAvFormat( UInt64 frame_num )
{
av_seek_frame( fmt_ctx, video_stream_idx, frame_num, AVSEEK_FLAG_FRAME );
}
} // NAMESPACE
+102
View File
@@ -0,0 +1,102 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file LibAvContextHandle.h
* \brief Interface with libav libs
*/
#ifndef __LIBAVCONTEXTHANDLE_H__
#define __LIBAVCONTEXTHANDLE_H__
#include <inttypes.h>
#ifndef __PRI64_PREFIX
#define __PRI64_PREFIX "l"
#endif
#ifndef PRId64
#define PRId64 __PRI64_PREFIX "d"
#endif
extern "C"
{
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
//#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
}
#include "PlaYUVerDefs.h"
namespace plaYUVer
{
class LibAvContextHandle
{
public:
LibAvContextHandle() :
m_bHasStream( false )
{
}
Bool initAvFormat( char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& frame_rate, UInt64& num_frames );
Void closeAvFormat();
Bool decodeAvFormat();
Void seekAvFormat( UInt64 frame_num );
Bool getStatus()
{
return m_bHasStream;
}
Char* getCodecName()
{
return m_acCodecName;
}
UInt getStreamDuration( )
{
return m_uiSecs;
}
// uint8_t *video_dst_data[4];
// int video_dst_linesize[4];
// int video_dst_bufsize;
UChar* m_pchFrameBuffer;
UInt64 m_uiFrameBufferSize;
private:
AVFormatContext *fmt_ctx;
AVCodecContext *video_dec_ctx;
AVStream *video_stream;
Int video_stream_idx;
AVFrame *frame;
AVPacket pkt;
Bool m_bHasStream;
Char m_acCodecName[20];
UInt m_uiSecs;
UInt m_uiMicroSec;
};
} // NAMESPACE
#endif // __LIBAVCONTEXTHANDLE_H__