├── .gitignore ├── .travis.yml ├── Android.mk ├── LICENSE ├── Makefile.am ├── README.md ├── autogen.sh ├── common.mk ├── common ├── NonCopyable.h ├── PooledFrameAllocator.h ├── VaapiUtils.h ├── common_def.h ├── condition.h ├── lock.h ├── log.h ├── utils.h └── videopool.h ├── configure.ac ├── doc ├── Makefile.am ├── yamidecode.1 ├── yamiencode.1 ├── yamiinfo.1 ├── yamitranscode.1 └── yamivpp.1 ├── egl ├── egl_util.c ├── egl_util.h └── egl_vaapi_image.h ├── examples ├── Android.mk ├── Makefile.am ├── androidplayer.cpp ├── blend.cpp ├── bumpbox.h ├── font.h ├── grid.cpp └── simpleplayer.cpp ├── tests ├── Android.mk ├── Makefile.am ├── V4L2Device.cpp ├── V4L2Device.h ├── V4L2Renderer.cpp ├── V4L2Renderer.h ├── decode.cpp ├── decodeInputCapi.cpp ├── decodeInputCapi.h ├── decodeOutputCapi.cpp ├── decodeOutputCapi.h ├── decodecapi.c ├── decodehelp.cpp ├── decodehelp.h ├── decodeinput.cpp ├── decodeinput.h ├── decodeinputavformat.cpp ├── decodeinputavformat.h ├── decodeoutput.cpp ├── decodeoutput.h ├── egl │ ├── Makefile │ ├── gles2_help.c │ ├── gles2_help.h │ └── simple-gles2.c ├── encode.cpp ├── encodeInputCamera.cpp ├── encodeInputCapi.cpp ├── encodeInputCapi.h ├── encodeInputDecoder.cpp ├── encodeInputDecoder.h ├── encodeInputSurface.cpp ├── encodecapi.c ├── encodehelp.h ├── encodeinput.cpp ├── encodeinput.h ├── md5.c ├── md5.h ├── v4l2decode.cpp ├── v4l2encode.cpp ├── videopool.cpp ├── vpp.cpp ├── vppinputasync.cpp ├── vppinputasync.h ├── vppinputdecode.cpp ├── vppinputdecode.h ├── vppinputdecodecapi.cpp ├── vppinputdecodecapi.h ├── vppinputoutput.cpp ├── vppinputoutput.h ├── vppoutputencode.cpp ├── vppoutputencode.h ├── yamiinfo.cpp └── yamitranscode.cpp ├── testscripts ├── Makefile.am ├── autotest.py ├── psnr.cpp ├── replace.sh ├── ssim_test.py ├── unit_test.sh └── yamilib.py └── vaapi └── vaapidisplay.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | sudo: required 3 | 4 | language: c++ 5 | compiler: g++ 6 | os: linux 7 | 8 | before_install: 9 | - test "${TRAVIS_BRANCH}" != 'coverity_scan' -o "${TRAVIS_JOB_NUMBER##*.}" = '1' || exit 0 10 | - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- 11 | - pip install --user cpp-coveralls 12 | - sudo apt-get -qq update 13 | - sudo apt-get install -y build-essential 14 | - sudo apt-get install -y autoconf 15 | - sudo apt-get install -y automake 16 | - sudo apt-get install -y libtool 17 | - sudo apt-get install -y m4 18 | - sudo apt-get install -y lcov 19 | - sudo apt-get install -y perl 20 | - sudo apt-get install -y pkg-config 21 | - sudo apt-get install -y libdrm-dev 22 | - sudo apt-get install -y autoconf 23 | - sudo apt-get install -y libegl1-mesa-dev 24 | - sudo apt-get install -y libgl1-mesa-dev 25 | - sudo apt-get install -y libwayland-dev 26 | - sudo apt-get install -y libx11-dev 27 | - sudo apt-get install -y libxext-dev 28 | - sudo apt-get install -y libxfixes-dev 29 | - sudo apt-get install -y intel-gpu-tools 30 | - sudo apt-get install -y cifs-utils 31 | - sudo apt-get install -y yasm 32 | - sudo apt-get install -y libghc-x11-dev 33 | - sudo apt-get install -y libxmuu-dev 34 | - sudo apt-get install -y libxfixes-dev 35 | - sudo apt-get install -y libxcb-glx0-dev 36 | - sudo apt-get install -y libgegl-dev 37 | - sudo apt-get install -y libcogl-gles2-dev 38 | - sudo apt-get install -y libv4l-0 39 | - sudo apt-get install -y libv4l-dev 40 | 41 | 42 | 43 | - git clone https://github.com/intel/libva.git 44 | - (cd libva && ./autogen.sh && ./configure && sudo make install) 45 | - git clone https://github.com/intel/libyami.git 46 | - (cd libyami && ./autogen.sh && make -j8 && sudo make install) 47 | 48 | 49 | 50 | install: 51 | - git clone https://github.com/intel/libyami-utils.git 52 | - (cd libyami-utils && ./autogen.sh && make -j8 && sudo make install) 53 | 54 | addons: 55 | coverity_scan: 56 | project: 57 | name: "intel/libyami-utils" 58 | description: "Build submitted via Travis CI" 59 | notification_email: 531669721@sjtu.edu.cn 60 | build_command_prepend: "./autogen.sh; ./configure --prefix=/opt/yami" 61 | build_command: "make -j8" 62 | branch_pattern: coverity_scan 63 | 64 | script: 65 | - if [[ "${COVERITY_SCAN_BRANCH}" == 1 ]]; 66 | then 67 | echo "Don't build on coverty_scan branch."; 68 | exit 0; 69 | fi 70 | - ./autogen.sh --prefix=/opt/yami 71 | - make -j8 ; sudo make install 72 | 73 | #after_success: 74 | # - coveralls --exclude lib --exclude tests --gcov-options '\-lp' 75 | 76 | notifications: 77 | # Emails are sent to the committer's git-configured email address by default, 78 | # but only if they have access to the repository. To enable Travis on your 79 | # public project, just go to travis-ci.org and flip the switch on for 80 | # your project. To configure your git email address, use: 81 | # git config --global user.email me@example.com 82 | email: 83 | on_success: always 84 | on_failure: always 85 | 86 | # Slack notifications 87 | # 88 | 89 | 90 | # IRC notifications disabled by default. 91 | # Uncomment next 5 lines to send notifications to chat.freenode.net#caffe 92 | # irc: 93 | # channels: 94 | # - "chat.freenode.net#intel-media" 95 | # template: 96 | # - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" 97 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | LIBYAMICODEC_PATH := $(LOCAL_PATH) 3 | include $(CLEAR_VARS) 4 | include $(LIBYAMICODEC_PATH)/common.mk 5 | 6 | include $(LIBYAMICODEC_PATH)/tests/Android.mk 7 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} 16 | 17 | AUTOMAKE_OPTIONS = foreign 18 | 19 | # Extra clean files so that maintainer-clean removes *everything* 20 | DISTCLEANFILES = \ 21 | aclocal.m4 autom4te.cache compile config.guess config.sub \ 22 | configure config.h.in config.h.in~ depcomp install-sh ltmain.sh \ 23 | Makefile.in missing 24 | 25 | SUBDIRS = examples tests testscripts doc 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT. 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | [![Build Status](https://travis-ci.org/intel/libyami-utils.svg?branch=master)](https://travis-ci.org/intel/libyami-utils) 11 | [![Coverity Scan Build Status](https://scan.coverity.com/projects/11605/badge.svg)](https://scan.coverity.com/projects/01org-libyami-utils) 12 | 13 | 14 | libyami-utils 15 | ------------- 16 | Applications and Scripts for libyami. 17 | 18 | You can find libyami in https://github.com/01org/libyami 19 | * Copyright (C) 2011-2016 Intel Corporation 20 | 21 | 22 | License 23 | ------- 24 | libyami-utils is available under the terms of the 25 | Apache License 2.0 26 | 27 | 28 | Overview 29 | -------- 30 | libyami-utils consists of directories 31 | 32 | * `tests`: sample decoder/encoder/vpp applications 33 | * `testscripts`: conformance test scripts 34 | * `examples`: simpleplayer and video wall demo 35 | 36 | 37 | Requirements 38 | ------------ 39 | Hardware requirements 40 | * Intel (core) Sandybridge, Ivybridge, Haswell, Broadwell, Skylake, Kabylake 41 | * Intel (atom) Baytrail, Braswell, Apollolake 42 | 43 | 44 | Sources 45 | ------- 46 | Git repository is available at: 47 | 48 | 49 | 50 | 51 | Simple api demo application 52 | --------------------------- 53 | https://github.com/01org/libyami-utils/blob/master/examples/simpleplayer.cpp 54 | 55 | 56 | Build instructions 57 | ------------------ 58 | https://github.com/01org/libyami/wiki/Build 59 | 60 | 61 | Contributing 62 | ------------ 63 | Create pull request at https://github.com/01org/libyami-utils/compare 64 | 65 | 66 | Code style 67 | ---------- 68 | https://github.com/01org/libyami/wiki/Coding-Style 69 | 70 | 71 | Review process 72 | -------------- 73 | Create pull requests at 74 | 75 | 76 | Mail list 77 | --------- 78 | libyami@lists.01.org 79 | 80 | 81 | Reporting Bugs 82 | -------------- 83 | Bugs can be reported in libyami-utils issue list at: 84 | 85 | 86 | 87 | 88 | Reporting a security issue 89 | -------------------------- 90 | Please mail to secure-opensource@intel.com directly for security issue 91 | 92 | 93 | FAQ 94 | --- 95 | https://github.com/01org/libyami/wiki/FAQ 96 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | PROJECT="libyami-utils" 16 | 17 | test -n "$srcdir" || srcdir="`dirname \"$0\"`" 18 | test -n "$srcdir" || srcdir=. 19 | 20 | if ! test -f "$srcdir/configure.ac"; then 21 | echo "Failed to find the top-level $PROJECT directory" 22 | exit 1 23 | fi 24 | 25 | olddir="`pwd`" 26 | cd "$srcdir" 27 | 28 | mkdir -p m4 29 | 30 | AUTORECONF=`which autoreconf` 31 | if test -z $AUTORECONF; then 32 | echo "*** No autoreconf found ***" 33 | exit 1 34 | else 35 | autoreconf -v --install || exit $? 36 | fi 37 | 38 | cd "$olddir" 39 | 40 | if test -z "$NOCONFIGURE"; then 41 | $srcdir/configure "$@" && echo "***Now type 'make' to compile $PROJECT***" 42 | fi 43 | -------------------------------------------------------------------------------- /common.mk: -------------------------------------------------------------------------------- 1 | LOCAL_CFLAGS := -D__ENABLE_DEBUG__ -Wno-sign-compare -Wno-unused-parameter -O2 2 | LOCAL_CPPFLAGS := -D__ENABLE_DEBUG__ -Wno-sign-compare -Wno-unused-parameter -O2 3 | 4 | ENABLE-V4L2-OPS=true 5 | -------------------------------------------------------------------------------- /common/NonCopyable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef NoCopyable_h 18 | #define NoCopyable_h 19 | 20 | #ifndef DISALLOW_COPY_AND_ASSIGN 21 | #define DISALLOW_COPY_AND_ASSIGN(className) \ 22 | className(const className&); \ 23 | className& operator=(const className&); 24 | #endif 25 | 26 | #endif //NoCopyable_h 27 | -------------------------------------------------------------------------------- /common/PooledFrameAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef PooledFrameAllocator_h 18 | #define PooledFrameAllocator_h 19 | 20 | #include 21 | #include 22 | #include 23 | #include "common/videopool.h" 24 | 25 | 26 | namespace YamiMediaCodec { 27 | 28 | class FrameAllocator 29 | { 30 | public: 31 | virtual bool setFormat(uint32_t fourcc, int width, int height) = 0; 32 | virtual SharedPtr alloc() = 0; 33 | virtual ~FrameAllocator() {} 34 | }; 35 | 36 | class PooledFrameAllocator : public FrameAllocator 37 | { 38 | public: 39 | PooledFrameAllocator(const SharedPtr& display, int poolsize); 40 | bool setFormat(uint32_t fourcc, int width, int height); 41 | SharedPtr alloc(); 42 | 43 | private: 44 | SharedPtr m_display; 45 | SharedPtr > m_pool; 46 | int m_poolsize; 47 | }; 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /common/VaapiUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef VaapiUtils_h 18 | #define VaapiUtils_h 19 | 20 | #include "common/log.h" 21 | #include 22 | 23 | namespace YamiMediaCodec { 24 | 25 | uint8_t* mapSurfaceToImage(VADisplay display, intptr_t surface, VAImage& image); 26 | 27 | void unmapImage(VADisplay display, const VAImage& image); 28 | uint32_t getRtFormat(uint32_t fourcc); 29 | 30 | #define checkVaapiStatus(status, prompt) \ 31 | ( \ 32 | { \ 33 | bool ret; \ 34 | ret = (status == VA_STATUS_SUCCESS); \ 35 | if (!ret) \ 36 | ERROR("%s: %s", prompt, vaErrorStr(status)); \ 37 | ret; \ 38 | }) 39 | } 40 | 41 | #endif //VaapiUtils_h 42 | -------------------------------------------------------------------------------- /common/common_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __COMMON_DEF_H__ 18 | #define __COMMON_DEF_H__ 19 | 20 | #ifndef BOOL 21 | #define BOOL int 22 | #endif 23 | 24 | #ifndef TRUE 25 | #define TRUE 1 26 | #endif 27 | 28 | #ifndef FALSE 29 | #define FALSE 0 30 | #endif 31 | 32 | #ifndef CHAR_BIT 33 | #define CHAR_BIT 8 34 | #endif 35 | 36 | #ifndef N_ELEMENTS 37 | #define N_ELEMENTS(array) (sizeof(array)/sizeof(array[0])) 38 | #endif 39 | 40 | #ifndef ALIGN_POW2 41 | #define ALIGN_POW2(a, b) ((a + (b - 1)) & ~(b - 1)) 42 | #endif 43 | 44 | #ifndef ALIGN8 45 | #define ALIGN8(a) ALIGN_POW2(a, 8) 46 | #endif 47 | 48 | #ifndef ALIGN16 49 | #define ALIGN16(a) ALIGN_POW2(a, 16) 50 | #endif 51 | 52 | #ifndef ALIGN32 53 | #define ALIGN32(a) ALIGN_POW2(a, 32) 54 | #endif 55 | 56 | #ifndef RETURN_IF_FAIL 57 | #define RETURN_IF_FAIL(condition) \ 58 | do{ \ 59 | if (!(condition)) \ 60 | return; \ 61 | }while(0) 62 | #endif 63 | 64 | #ifndef RETURN_VAL_IF_FAIL 65 | #define RETURN_VAL_IF_FAIL(condition, value) \ 66 | do{ \ 67 | if (!(condition)) \ 68 | return (value); \ 69 | }while(0) 70 | #endif 71 | 72 | #define PARAMETER_ASSIGN(a, b) memcpy(&(a), &(b), sizeof(b)) 73 | #endif //__COMMON_DEF_H__ 74 | -------------------------------------------------------------------------------- /common/condition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef condition_h 17 | #define condition_h 18 | 19 | #include "NonCopyable.h" 20 | #include "lock.h" 21 | 22 | #include 23 | 24 | namespace YamiMediaCodec{ 25 | 26 | class Condition 27 | { 28 | public: 29 | explicit Condition(Lock& lock):m_lock(lock) 30 | { 31 | pthread_cond_init(&m_cond, NULL); 32 | } 33 | 34 | ~Condition() 35 | { 36 | pthread_cond_destroy(&m_cond); 37 | } 38 | 39 | void wait() 40 | { 41 | pthread_cond_wait(&m_cond, &m_lock.m_lock); 42 | } 43 | 44 | void signal() 45 | { 46 | pthread_cond_signal(&m_cond); 47 | } 48 | 49 | void broadcast() 50 | { 51 | pthread_cond_broadcast(&m_cond); 52 | } 53 | 54 | private: 55 | Lock& m_lock; 56 | pthread_cond_t m_cond; 57 | DISALLOW_COPY_AND_ASSIGN(Condition); 58 | 59 | }; 60 | 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /common/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef lock_h 17 | #define lock_h 18 | 19 | #include "NonCopyable.h" 20 | #include 21 | 22 | namespace YamiMediaCodec{ 23 | 24 | class Lock 25 | { 26 | public: 27 | Lock() 28 | { 29 | pthread_mutex_init(&m_lock, NULL); 30 | } 31 | 32 | ~Lock() 33 | { 34 | pthread_mutex_destroy(&m_lock); 35 | } 36 | 37 | void acquire() 38 | { 39 | pthread_mutex_lock(&m_lock); 40 | } 41 | 42 | void release() 43 | { 44 | pthread_mutex_unlock(&m_lock); 45 | } 46 | 47 | void tryLock() 48 | { 49 | pthread_mutex_trylock(&m_lock); 50 | } 51 | 52 | friend class Condition; 53 | 54 | private: 55 | pthread_mutex_t m_lock; 56 | DISALLOW_COPY_AND_ASSIGN(Lock); 57 | }; 58 | 59 | class AutoLock 60 | { 61 | public: 62 | explicit AutoLock(Lock& lock) : m_lock(lock) 63 | { 64 | m_lock.acquire(); 65 | } 66 | ~AutoLock() 67 | { 68 | m_lock.release(); 69 | } 70 | Lock& m_lock; 71 | private: 72 | DISALLOW_COPY_AND_ASSIGN(AutoLock); 73 | }; 74 | 75 | }; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /common/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Intel Coperation.. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __LOG_H__ 18 | #define __LOG_H__ 19 | 20 | #if (defined(ANDROID) && defined(__USE_LOGCAT__)) 21 | #include 22 | #define ERROR(...) 23 | #define INFO(...) 24 | #define WARNING(...) 25 | #define DEBUG(...) 26 | 27 | #ifndef PRINT_FOURCC 28 | #define DEBUG_FOURCC(promptStr, fourcc) 29 | #endif 30 | 31 | #else 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #define GETTID() syscall(__NR_gettid) 40 | 41 | extern int yamiLogFlag; 42 | extern FILE* yamiLogFn; 43 | extern int isInit; 44 | 45 | #ifndef YAMIMESSAGE 46 | #define yamiMessage(stream, format, ...) do {\ 47 | fprintf(stream, format, ##__VA_ARGS__); \ 48 | }while (0) 49 | #endif 50 | 51 | #define YAMI_DEBUG_MESSAGE(LEVEL, prefix, format, ...) \ 52 | do {\ 53 | if (yamiLogFlag >= YAMI_LOG_##LEVEL) { \ 54 | const char* name = strrchr(__FILE__, '/'); \ 55 | name = (name ? (name + 1) : __FILE__); \ 56 | yamiMessage(yamiLogFn, "libyami %s %ld (%s, %d): " format "\n", #prefix, (long int)GETTID(), name, __LINE__, ##__VA_ARGS__); \ 57 | } \ 58 | } while (0) 59 | 60 | #ifndef ERROR 61 | #define ERROR(format, ...) YAMI_DEBUG_MESSAGE(ERROR, error, format, ##__VA_ARGS__) 62 | #endif 63 | 64 | #ifdef __ENABLE_DEBUG__ 65 | 66 | #ifndef WARNING 67 | #define WARNING(format, ...) YAMI_DEBUG_MESSAGE(WARNING, warning, format, ##__VA_ARGS__) 68 | #endif 69 | 70 | #ifndef INFO 71 | #define INFO(format, ...) YAMI_DEBUG_MESSAGE(INFO, info, format, ##__VA_ARGS__) 72 | #endif 73 | 74 | #ifndef DEBUG 75 | #define DEBUG(format, ...) YAMI_DEBUG_MESSAGE(DEBUG, debug, format, ##__VA_ARGS__) 76 | #endif 77 | 78 | #ifndef DEBUG_ 79 | #define DEBUG_(format, ...) DEBUG(format, ##__VA_ARGS__) 80 | #endif 81 | 82 | #ifndef DEBUG_FOURCC 83 | #define DEBUG_FOURCC(promptStr, fourcc) do { \ 84 | if (yamiLogFlag >= YAMI_LOG_DEBUG) { \ 85 | uint32_t i_fourcc = fourcc; \ 86 | char *ptr = (char*)(&(i_fourcc)); \ 87 | DEBUG("%s, fourcc: 0x%x, %c%c%c%c\n", promptStr, i_fourcc, *(ptr), *(ptr+1), *(ptr+2), *(ptr+3)); \ 88 | } \ 89 | } while(0) 90 | #endif 91 | 92 | #else //__ENABLE_DEBUG__ 93 | #ifndef INFO 94 | #define INFO(format, ...) 95 | #endif 96 | 97 | #ifndef WARNING 98 | #define WARNING(format, ...) 99 | #endif 100 | 101 | #ifndef DEBUG 102 | #define DEBUG(format, ...) 103 | #endif 104 | 105 | #ifndef PRINT_FOURCC 106 | #define DEBUG_FOURCC(promptStr, fourcc) 107 | #endif 108 | 109 | #endif //__ENABLE_DEBUG__ 110 | #endif //__ANDROID 111 | 112 | #ifndef ASSERT 113 | #define ASSERT(expr) \ 114 | do { \ 115 | if (!(expr)) { \ 116 | ERROR("assert fails"); \ 117 | assert(0 && (expr)); \ 118 | } \ 119 | } while (0) 120 | #endif 121 | 122 | #define YAMI_LOG_ERROR 0x1 123 | #define YAMI_LOG_WARNING 0x2 124 | #define YAMI_LOG_INFO 0x3 125 | #define YAMI_LOG_DEBUG 0x4 126 | 127 | #endif //__LOG_H__ 128 | -------------------------------------------------------------------------------- /common/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef utils_h 17 | #define utils_h 18 | 19 | #include 20 | 21 | #include 22 | 23 | #ifndef VA_FOURCC_I420 24 | #define VA_FOURCC_I420 VA_FOURCC('I','4','2','0') 25 | #endif 26 | 27 | namespace YamiMediaCodec{ 28 | 29 | uint32_t guessFourcc(const char* fileName); 30 | 31 | bool guessResolution(const char* filename, int& w, int& h); 32 | 33 | bool getPlaneResolution(uint32_t fourcc, uint32_t pixelWidth, uint32_t pixelHeight, uint32_t byteWidth[3], uint32_t byteHeight[3], uint32_t& planes); 34 | 35 | bool fillFrameRawData(VideoFrameRawData* frame, uint32_t fourcc, uint32_t width, uint32_t height, uint8_t* data); 36 | 37 | class CalcFps 38 | { 39 | public: 40 | CalcFps() { m_timeStart = 0;}; 41 | void setAnchor(); 42 | float fps(uint32_t frameCount); 43 | 44 | private: 45 | uint64_t m_timeStart; 46 | }; 47 | 48 | //slim version of CalcFps, hide all fps all fps detials. 49 | class FpsCalc 50 | { 51 | public: 52 | FpsCalc(); 53 | void addFrame(); 54 | void log(); 55 | private: 56 | int m_frames; 57 | uint64_t m_start; 58 | uint64_t m_netStart; 59 | static const int NET_FPS_START = 5; 60 | }; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /common/videopool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef videopool_h 17 | #define videopool_h 18 | #include "VideoCommonDefs.h" 19 | #include "common/lock.h" 20 | #include 21 | 22 | namespace YamiMediaCodec{ 23 | 24 | template 25 | class VideoPool : public EnableSharedFromThis > 26 | { 27 | public: 28 | VideoPool(std::deque >& buffers) 29 | { 30 | m_holder.swap(buffers); 31 | for (size_t i = 0; i < m_holder.size(); i++) { 32 | m_freed.push_back(m_holder[i].get()); 33 | } 34 | } 35 | 36 | SharedPtr alloc() 37 | { 38 | SharedPtr ret; 39 | AutoLock _l(m_lock); 40 | if (!m_freed.empty()) { 41 | T* p = m_freed.front(); 42 | m_freed.pop_front(); 43 | ret.reset(p, Recycler(this->shared_from_this())); 44 | } 45 | return ret; 46 | } 47 | 48 | private: 49 | 50 | void recycle(T* ptr) 51 | { 52 | AutoLock _l(m_lock); 53 | m_freed.push_back(ptr); 54 | } 55 | 56 | class Recycler 57 | { 58 | public: 59 | Recycler(const SharedPtr >& pool) 60 | :m_pool(pool) 61 | { 62 | } 63 | void operator()(T* ptr) const 64 | { 65 | m_pool->recycle(ptr); 66 | } 67 | private: 68 | SharedPtr > m_pool; 69 | }; 70 | 71 | Lock m_lock; 72 | std::deque m_freed; 73 | std::deque > m_holder; 74 | }; 75 | 76 | }; 77 | #endif //videopool_h 78 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | man1_MANS = yamidecode.1 \ 2 | yamiencode.1 \ 3 | yamiinfo.1 \ 4 | yamitranscode.1 \ 5 | yamivpp.1 6 | 7 | -------------------------------------------------------------------------------- /doc/yamidecode.1: -------------------------------------------------------------------------------- 1 | .TH YAMIDECODE "1" "October 2016" "yamidecode" "User Commands" 2 | .SH NAME 3 | yamidecode \- decode application based on libyami 4 | .SH DESCRIPTION 5 | This program decode the video bitstream and display/dump video content 6 | .SH OPTIONS 7 | -i media file to decode 8 | -w wait before quit, 0:no-wait, 1:auto(jpeg wait), 2:wait 9 | -o dumped output dir 10 | -n specify how many frames to be decoded 11 | -m specify render mode. 12 | --capi: use the codec capi to encode or decode, default(false) -------------------------------------------------------------------------------- /doc/yamiencode.1: -------------------------------------------------------------------------------- 1 | .TH YAMIDECODE "1" "October 2016" "yamiencode" "User Commands" 2 | .SH NAME 3 | yamiencode \- encode application based on libyami 4 | .SH DESCRIPTION 5 | This program encode the raw YUV file to video bitstream 6 | .SH OPTIONS 7 | -i load YUV from a file 8 | -W -H 9 | -o optional 10 | -b optional 11 | -f optional 12 | -c 13 | -s 14 | -N 15 | --qp optional 16 | --rcmode optional 17 | --ipperiod <0 (I frame only) | 1 (I and P frames) | N (I,P and B frames, B frame number is N-1)> optional 18 | --intraperiod optional 19 | --refnum optional 20 | --idrinterval optional 21 | --lowpower optional -------------------------------------------------------------------------------- /doc/yamiinfo.1: -------------------------------------------------------------------------------- 1 | .TH YAMIINFO "1" "October 2016" "yamiinfo" "User Commands" 2 | .SH NAME 3 | yamiinfo \- display supported features and capabilities by yami 4 | .SH DESCRIPTION 5 | This program displays information from about the libyami library. 6 | It will show detailed decoders, encoders and vpp information supported by yami. 7 | -------------------------------------------------------------------------------- /doc/yamitranscode.1: -------------------------------------------------------------------------------- 1 | .TH YAMITRANSCODE "1" "October 2016" "yamitranscode" "User Commands" 2 | .SH NAME 3 | yamitranscode \- transcode application base on libyami 4 | .SH DESCRIPTION 5 | This program transcode video bitstream to different codec. 6 | .SH OPTIONS 7 | -i load a raw yuv file or a compressed video file 8 | -W -H 9 | -o optional 10 | -b optional 11 | -f optional 12 | -c 13 | -s 14 | -N 15 | -t optional 16 | --qp optional 17 | --rcmode optional 18 | --ipperiod <0 (I frame only) | 1 (I and P frames) | N (I,P and B frames, B frame number is N-1)> optional 19 | --intraperiod optional 20 | --refnum optional 21 | --idrinterval optional 22 | --disable-cabac optional 26 | --deblockbetadiv2 optional 27 | --qpip optional 28 | --qpib optional 29 | --priorityid optional 30 | --ow optional 31 | --oh optional 32 | --btl0 optional 33 | --btl1 optional 34 | --btl2 optional 35 | --btl3 optional 36 | -------------------------------------------------------------------------------- /doc/yamivpp.1: -------------------------------------------------------------------------------- 1 | .TH YAMIVPP "1" "October 2016" "yamivpp" "User Commands" 2 | .SH NAME 3 | yamivpp \- vpp application base on libyami 4 | .SH DESCRIPTION 5 | This program do video post process on yuv file, support scaling and CSC 6 | Guess size and color format from file name. i420, yv12 and nv12 are supported 7 | .SH OPTIONS 8 | -s optional, sharpening level 9 | --dn optional, denoise level 10 | --di , optional, deinterlace mode, only support bob -------------------------------------------------------------------------------- /egl/egl_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include "egl_util.h" 22 | #include "common/log.h" 23 | #if __ENABLE_DMABUF__ 24 | #include "libdrm/drm_fourcc.h" 25 | #endif 26 | 27 | static PFNEGLCREATEIMAGEKHRPROC createImageProc = NULL; 28 | static PFNEGLDESTROYIMAGEKHRPROC destroyImageProc = NULL; 29 | 30 | EGLImageKHR createImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, 31 | EGLClientBuffer buffer, const EGLint *attrib_list) 32 | { 33 | if (!createImageProc) { 34 | createImageProc = (void *) eglGetProcAddress("eglCreateImageKHR"); 35 | } 36 | return createImageProc(dpy, ctx, target, buffer, attrib_list); 37 | } 38 | 39 | EGLBoolean destroyImage(EGLDisplay dpy, EGLImageKHR image) 40 | { 41 | if (!destroyImageProc) { 42 | destroyImageProc = (void *) eglGetProcAddress("eglDestroyImageKHR"); 43 | } 44 | return destroyImageProc(dpy, image); 45 | } 46 | 47 | static EGLImageKHR createEglImageFromDrmBuffer(EGLDisplay eglDisplay, EGLContext eglContext, uint32_t drmName, int width, int height, int pitch) 48 | { 49 | EGLImageKHR eglImage = EGL_NO_IMAGE_KHR; 50 | EGLint attribs[] = { 51 | EGL_WIDTH, width, 52 | EGL_HEIGHT, height, 53 | EGL_DRM_BUFFER_STRIDE_MESA, pitch/4, 54 | EGL_DRM_BUFFER_FORMAT_MESA, 55 | EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, 56 | EGL_DRM_BUFFER_USE_MESA, 57 | EGL_DRM_BUFFER_USE_SHARE_MESA, 58 | EGL_NONE 59 | }; 60 | 61 | eglImage = createImage(eglDisplay, eglContext, EGL_DRM_BUFFER_MESA, 62 | (EGLClientBuffer)(intptr_t)drmName, attribs); 63 | return eglImage; 64 | } 65 | 66 | static EGLImageKHR createEglImageFromDmaBuf(EGLDisplay eglDisplay, EGLContext eglContext, uint32_t dmaBuf, int width, int height, int pitch) 67 | { 68 | EGLImageKHR eglImage = EGL_NO_IMAGE_KHR; 69 | #if __ENABLE_DMABUF__ 70 | EGLint attribs[] = { 71 | EGL_WIDTH, width, 72 | EGL_HEIGHT, height, 73 | EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_XRGB8888, 74 | EGL_DMA_BUF_PLANE0_FD_EXT, dmaBuf, 75 | EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, 76 | EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch, 77 | EGL_NONE 78 | }; 79 | 80 | eglImage = createImage(eglDisplay, EGL_NO_CONTEXT, 81 | EGL_LINUX_DMA_BUF_EXT, NULL, attribs); 82 | ASSERT(eglImage != EGL_NO_IMAGE_KHR); 83 | return eglImage; 84 | #else 85 | ERROR("dma_buf is enabled with --enable-dmabuf option"); 86 | return eglImage; 87 | #endif 88 | } 89 | 90 | EGLImageKHR createEglImageFromHandle(EGLDisplay eglDisplay, EGLContext eglContext, VideoDataMemoryType type, uint32_t handle, int width, int height, int pitch) 91 | { 92 | EGLImageKHR eglImage = EGL_NO_IMAGE_KHR; 93 | if (type == VIDEO_DATA_MEMORY_TYPE_DRM_NAME) 94 | eglImage = createEglImageFromDrmBuffer(eglDisplay, eglContext, handle, width, height, pitch); 95 | else if (type == VIDEO_DATA_MEMORY_TYPE_DMA_BUF) 96 | eglImage = createEglImageFromDmaBuf(eglDisplay, eglContext, handle, width, height, pitch); 97 | 98 | return eglImage; 99 | } 100 | -------------------------------------------------------------------------------- /egl/egl_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __EGL_UTIL_H__ 18 | #define __EGL_UTIL_H__ 19 | #include 20 | #include 21 | 22 | #include 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | EGLImageKHR createImage(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint *); 28 | EGLBoolean destroyImage(EGLDisplay, EGLImageKHR); 29 | EGLImageKHR createEglImageFromHandle(EGLDisplay eglDisplay, EGLContext eglContext, VideoDataMemoryType type, uint32_t dmaBuf, int width, int height, int pitch); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /* __cplusplus */ 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /egl/egl_vaapi_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef egl_vaapi_image_h 18 | #define egl_vaapi_image_h 19 | 20 | #include 21 | #define EGL_EGLEXT_PROTOTYPES 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace YamiMediaCodec { 28 | 29 | class EglVaapiImage 30 | { 31 | public: 32 | EglVaapiImage(VADisplay, int width, int height); 33 | bool init(); 34 | EGLImageKHR createEglImage(EGLDisplay, EGLContext, VideoDataMemoryType); 35 | bool blt(const SharedPtr& src); 36 | bool exportFrame(VideoDataMemoryType memoryType, VideoFrameRawData &frame); 37 | ~EglVaapiImage(); 38 | private: 39 | bool acquireBufferHandle(VideoDataMemoryType); 40 | VADisplay m_display; 41 | VAImageFormat m_format; 42 | VAImage m_image; 43 | VABufferInfo m_bufferInfo; 44 | 45 | int m_width; 46 | int m_height; 47 | bool m_inited; 48 | bool m_acquired; // acquired buffer handle 49 | VideoFrameRawData m_frameInfo; 50 | 51 | EGLImageKHR m_eglImage; 52 | }; 53 | 54 | }//namespace YamiMediaCodec 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /examples/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | include $(LOCAL_PATH)/../common.mk 5 | 6 | LOCAL_SRC_FILES := \ 7 | ../tests/decodeinput.cpp \ 8 | ../tests/vppinputoutput.cpp \ 9 | androidplayer.cpp 10 | 11 | LOCAL_C_INCLUDES:= \ 12 | $(LOCAL_PATH)/.. \ 13 | $(LOCAL_PATH)/../interface \ 14 | $(LOCAL_PATH)/../tests \ 15 | external/libcxx/include \ 16 | $(TARGET_OUT_HEADERS)/libva 17 | 18 | LOCAL_SHARED_LIBRARIES := \ 19 | libutils \ 20 | liblog \ 21 | libc++ \ 22 | libva \ 23 | libva-android \ 24 | libgui \ 25 | libui \ 26 | libhardware \ 27 | libyami \ 28 | 29 | LOCAL_PROPRIETARY_MODULE := true 30 | LOCAL_MODULE := androidplayer 31 | include $(BUILD_EXECUTABLE) 32 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = 2 | 3 | if ENABLE_X11 4 | bin_PROGRAMS += simpleplayer 5 | 6 | if BUILD_OCL_BLENDER 7 | bin_PROGRAMS += blend 8 | endif 9 | 10 | endif 11 | 12 | if ENABLE_DMABUF 13 | bin_PROGRAMS += grid 14 | endif 15 | 16 | #to compile within yocto 17 | extra_includes = \ 18 | -I$(top_srcdir) \ 19 | $(NULL) 20 | 21 | YAMI_COMMON_CFLAGS = \ 22 | -I../tests \ 23 | $(LIBYAMI_CFLAGS) \ 24 | $(LIBVA_CFLAGS) \ 25 | $(extra_includes) \ 26 | $(NULL) 27 | 28 | DECODE_INPUT_SOURCES = \ 29 | ../tests/decodeinput.cpp \ 30 | $(NULL) 31 | 32 | if ENABLE_AVFORMAT 33 | DECODE_INPUT_SOURCES += ../tests/decodeinputavformat.cpp 34 | YAMI_COMMON_CFLAGS += -D__STDC_CONSTANT_MACROS \ 35 | $(LIBAVFORMAT_CFLAGS) 36 | endif 37 | 38 | VPP_INPUT_SOURCES = \ 39 | $(DECODE_INPUT_SOURCES) \ 40 | ../tests/vppinputdecode.cpp \ 41 | ../tests/vppinputasync.cpp \ 42 | ../tests/vppoutputencode.cpp \ 43 | ../tests/encodeinput.cpp \ 44 | ../tests/encodeInputDecoder.cpp \ 45 | ../tests/encodeInputCamera.cpp \ 46 | $(NULL) 47 | 48 | YAMI_COMMON_LIBS = \ 49 | $(LIBVA_LIBS) \ 50 | $(LIBVA_DRM_LIBS) \ 51 | $(LIBYAMI_LIBS) \ 52 | $(NULL) 53 | 54 | if ENABLE_X11 55 | YAMI_COMMON_LIBS += $(LIBVA_X11_LIBS) -lX11 56 | endif 57 | 58 | YAMI_DECODE_LIBS = \ 59 | $(YAMI_COMMON_LIBS) \ 60 | $(NULL) 61 | 62 | if ENABLE_EGL 63 | YAMI_DECODE_LIBS += $(LIBEGL_LIBS) $(LIBGLES2_LIBS) 64 | endif 65 | 66 | if ENABLE_AVFORMAT 67 | YAMI_DECODE_LIBS += $(LIBAVFORMAT_LIBS) 68 | endif 69 | 70 | YAMI_ENCODE_LIBS = \ 71 | $(YAMI_DECODE_LIBS) \ 72 | $(NULL) 73 | 74 | VPP_INPUT_LIBS = \ 75 | $(LIBYAMI_LIBS) \ 76 | $(YAMI_ENCODE_LIBS) \ 77 | $(NULL) 78 | 79 | VPP_INPUT_CFLAGS = \ 80 | $(LIBVA_CFLAGS) \ 81 | $(NULL) 82 | 83 | if ENABLE_X11 84 | simpleplayer_LDADD = $(YAMI_DECODE_LIBS) 85 | simpleplayer_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 86 | simpleplayer_SOURCES = simpleplayer.cpp $(DECODE_INPUT_SOURCES) 87 | 88 | blend_LDADD = $(VPP_INPUT_LIBS) -lpthread 89 | blend_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 90 | blend_SOURCES = blend.cpp $(VPP_INPUT_SOURCES) 91 | endif 92 | 93 | if ENABLE_DMABUF 94 | grid_LDADD = $(VPP_INPUT_LIBS) $(LIBDRM_LIBS) -lpthread 95 | grid_CPPFLAGS = $(LIBDRM_CFLAGS) $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 96 | grid_SOURCES = grid.cpp $(VPP_INPUT_SOURCES) 97 | endif 98 | 99 | #autotools distclean will try to do rm -rf ../tests/.deps which results 100 | #on failure, instead specify instructions here 101 | distclean: 102 | -rm -rf ./.deps 103 | -rm -rf ./.libs 104 | -rm -rf ./*.o 105 | -rm -rf Makefile 106 | -test -z "" || rm -f 107 | -rm -rf ${bin_PROGRAMS} 108 | -------------------------------------------------------------------------------- /examples/bumpbox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2016 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef bumpbox_h 17 | #define bumpbox_h 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | /// class to hide box bump logical 24 | /// the inner rect will bump back when it hit outerrect. 25 | /// 26 | class BumpBox 27 | { 28 | public: 29 | 30 | BumpBox(uint32_t outerWidth, uint32_t outerHeight, uint32_t width, uint32_t height, uint32_t step = 5) 31 | :m_width(width), m_height(height) 32 | { 33 | assert(outerWidth > width && outerHeight > height); 34 | m_xMax = outerWidth - width; 35 | m_yMax = outerHeight - height; 36 | m_x = rand() % m_xMax; 37 | m_y = rand() % m_yMax; 38 | 39 | //generate dx, dy 40 | uint32_t a = rand()%255 + 1; 41 | uint32_t b = rand()%255 + 1; 42 | double c2 = a*a + b*b; 43 | double c = sqrt(c2); 44 | m_dx = genSign() * (a / c * step); 45 | m_dy = genSign() * (b / c * step); 46 | // printf("(%d, %d, %d, %d)\r\n", outerWidth, outerWidth, width, height); 47 | //printf("a = %d, b = %d, c = %f, a/c = %f\r\n", a, b, c, a/c); 48 | } 49 | void getPos(uint32_t& x, uint32_t& y, uint32_t& width, uint32_t& height) 50 | { 51 | width = m_width; 52 | height = m_height; 53 | //step 54 | m_x += m_dx; 55 | m_y += m_dy; 56 | 57 | //clip 58 | if (clip(m_x, 0, m_xMax)) 59 | m_dx = -m_dx; 60 | if (clip(m_y, 0, m_yMax)) 61 | m_dy = -m_dy; 62 | //now we get the pos 63 | x = m_x; 64 | y = m_y; 65 | 66 | } 67 | private: 68 | bool clip(int& a, int left, int right) 69 | { 70 | if (a <= left) { 71 | a = left; 72 | return true; 73 | } 74 | else if (a >= right) { 75 | a = right; 76 | return true; 77 | } 78 | return false; 79 | 80 | } 81 | int genSign() 82 | { 83 | int ret = rand() % 2; 84 | if (!ret) 85 | ret = -1; 86 | return ret; 87 | } 88 | int32_t m_x; 89 | int32_t m_y; 90 | double m_dx; 91 | double m_dy; 92 | uint32_t m_xMax; 93 | uint32_t m_yMax; 94 | uint32_t m_width; 95 | uint32_t m_height; 96 | 97 | }; 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /examples/simpleplayer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include "tests/decodeinput.h" 21 | #include "common/log.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | using namespace YamiMediaCodec; 32 | 33 | class SimplePlayer 34 | { 35 | public: 36 | bool init(int argc, char** argv) 37 | { 38 | if (argc != 2) { 39 | printf("usage: simpleplayer xxx.264\n"); 40 | return false; 41 | } 42 | m_input.reset(DecodeInput::create(argv[1])); 43 | if (!m_input) { 44 | fprintf(stderr, "failed to open %s", argv[1]); 45 | return false; 46 | } 47 | 48 | //init decoder 49 | m_decoder.reset(createVideoDecoder(m_input->getMimeType()), releaseVideoDecoder); 50 | if (!m_decoder) { 51 | fprintf(stderr, "failed create decoder for %s", m_input->getMimeType()); 52 | return false; 53 | } 54 | 55 | if (!initDisplay()) { 56 | return false; 57 | } 58 | //set native display 59 | m_decoder->setNativeDisplay(m_nativeDisplay.get()); 60 | return true; 61 | } 62 | bool run() 63 | { 64 | VideoConfigBuffer configBuffer; 65 | memset(&configBuffer, 0, sizeof(configBuffer)); 66 | configBuffer.profile = VAProfileNone; 67 | const string codecData = m_input->getCodecData(); 68 | if (codecData.size()) { 69 | configBuffer.data = (uint8_t*)codecData.data(); 70 | configBuffer.size = codecData.size(); 71 | } 72 | 73 | Decode_Status status = m_decoder->start(&configBuffer); 74 | assert(status == DECODE_SUCCESS); 75 | 76 | VideoDecodeBuffer inputBuffer; 77 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 78 | 79 | while (m_input->getNextDecodeUnit(inputBuffer)) { 80 | status = m_decoder->decode(&inputBuffer); 81 | if (DECODE_FORMAT_CHANGE == status) { 82 | //drain old buffers 83 | renderOutputs(); 84 | const VideoFormatInfo *formatInfo = m_decoder->getFormatInfo(); 85 | resizeWindow(formatInfo->width, formatInfo->height); 86 | //resend the buffer 87 | status = m_decoder->decode(&inputBuffer); 88 | } 89 | if(status == DECODE_SUCCESS) { 90 | renderOutputs(); 91 | } else { 92 | ERROR("decode error status = %d", status); 93 | break; 94 | } 95 | } 96 | m_decoder->stop(); 97 | return true; 98 | } 99 | SimplePlayer():m_window(0), m_width(0), m_height(0) {} 100 | ~SimplePlayer() 101 | { 102 | if (m_nativeDisplay) { 103 | vaTerminate(m_vaDisplay); 104 | } 105 | if (m_window) { 106 | XDestroyWindow(m_display.get(), m_window); 107 | } 108 | } 109 | private: 110 | void renderOutputs() 111 | { 112 | VAStatus status = VA_STATUS_SUCCESS; 113 | do { 114 | SharedPtr frame = m_decoder->getOutput(); 115 | if (!frame) 116 | break; 117 | status = vaPutSurface(m_vaDisplay, (VASurfaceID)frame->surface, 118 | m_window, 0, 0, m_width, m_height, 0, 0, m_width, m_height, 119 | NULL, 0, 0); 120 | if (status != VA_STATUS_SUCCESS) { 121 | ERROR("vaPutSurface return %d", status); 122 | break; 123 | } 124 | } while (1); 125 | } 126 | bool initDisplay() 127 | { 128 | Display* display = XOpenDisplay(NULL); 129 | if (!display) { 130 | fprintf(stderr, "Failed to XOpenDisplay \n"); 131 | return false; 132 | } 133 | m_display.reset(display, XCloseDisplay); 134 | m_vaDisplay = vaGetDisplay(m_display.get()); 135 | int major, minor; 136 | VAStatus status; 137 | status = vaInitialize(m_vaDisplay, &major, &minor); 138 | if (status != VA_STATUS_SUCCESS) { 139 | fprintf(stderr, "init va failed status = %d", status); 140 | return false; 141 | } 142 | m_nativeDisplay.reset(new NativeDisplay); 143 | m_nativeDisplay->type = NATIVE_DISPLAY_VA; 144 | m_nativeDisplay->handle = (intptr_t)m_vaDisplay; 145 | return true; 146 | } 147 | void resizeWindow(int width, int height) 148 | { 149 | Display* display = m_display.get(); 150 | if (m_window) { 151 | //todo, resize window; 152 | } else { 153 | DefaultScreen(display); 154 | 155 | XSetWindowAttributes x11WindowAttrib; 156 | x11WindowAttrib.event_mask = KeyPressMask; 157 | m_window = XCreateWindow(display, DefaultRootWindow(display), 158 | 0, 0, width, height, 0, CopyFromParent, InputOutput, 159 | CopyFromParent, CWEventMask, &x11WindowAttrib); 160 | XMapWindow(display, m_window); 161 | } 162 | XSync(display, false); 163 | { 164 | DEBUG("m_window=%lu", m_window); 165 | XWindowAttributes wattr; 166 | XGetWindowAttributes(display, m_window, &wattr); 167 | } 168 | m_width = width; 169 | m_height = height; 170 | } 171 | SharedPtr m_display; 172 | SharedPtr m_nativeDisplay; 173 | VADisplay m_vaDisplay; 174 | Window m_window; 175 | SharedPtr m_decoder; 176 | SharedPtr m_input; 177 | int m_width, m_height; 178 | }; 179 | 180 | int main(int argc, char** argv) 181 | { 182 | 183 | SimplePlayer player; 184 | if (!player.init(argc, argv)) { 185 | ERROR("init player failed with %s", argv[1]); 186 | return -1; 187 | } 188 | if (!player.run()){ 189 | ERROR("run simple player failed"); 190 | return -1; 191 | } 192 | printf("play file done\n"); 193 | return 0; 194 | 195 | } 196 | 197 | -------------------------------------------------------------------------------- /tests/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | #libinputoutput 4 | include $(CLEAR_VARS) 5 | include $(LOCAL_PATH)/../common.mk 6 | 7 | LOCAL_SRC_FILES := \ 8 | decodeinput.cpp \ 9 | decodeoutput.cpp \ 10 | encodeinput.cpp \ 11 | vppinputdecode.cpp \ 12 | vppinputdecodecapi.cpp \ 13 | vppinputoutput.cpp \ 14 | vppoutputencode.cpp \ 15 | vppinputasync.cpp \ 16 | md5.c \ 17 | 18 | LOCAL_C_INCLUDES := \ 19 | $(LOCAL_PATH)/.. \ 20 | $(LOCAL_PATH)/../interface \ 21 | $(LOCAL_PATH)/../tests \ 22 | external/libcxx/include \ 23 | $(TARGET_OUT_HEADERS)/libva 24 | 25 | LOCAL_SHARED_LIBRARIES := \ 26 | libutils \ 27 | liblog \ 28 | libc++ \ 29 | libva \ 30 | libva-android \ 31 | libgui \ 32 | libhardware \ 33 | libyami \ 34 | 35 | LOCAL_CPPFLAGS += \ 36 | -frtti 37 | 38 | 39 | LOCAL_PROPRIETARY_MODULE := true 40 | 41 | LOCAL_MODULE := libinputoutput 42 | include $(BUILD_STATIC_LIBRARY) 43 | 44 | 45 | ###yamidecode 46 | include $(CLEAR_VARS) 47 | include $(LOCAL_PATH)/../common.mk 48 | LOCAL_SRC_FILES := \ 49 | decodehelp.cpp \ 50 | decode.cpp \ 51 | 52 | LOCAL_C_INCLUDES := \ 53 | $(LOCAL_PATH)/.. \ 54 | $(LOCAL_PATH)/../interface \ 55 | $(LOCAL_PATH)/../tests \ 56 | external/libcxx/include \ 57 | $(TARGET_OUT_HEADERS)/libva 58 | 59 | LOCAL_SHARED_LIBRARIES := \ 60 | libutils \ 61 | liblog \ 62 | libc++ \ 63 | libva \ 64 | libva-android \ 65 | libgui \ 66 | libhardware \ 67 | libyami \ 68 | 69 | LOCAL_CPPFLAGS += \ 70 | -frtti 71 | 72 | LOCAL_MULTILIB := both 73 | LOCAL_STATIC_LIBRARIES := libinputoutput 74 | LOCAL_PROPRIETARY_MODULE := true 75 | LOCAL_MODULE := yamidecode 76 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 77 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 78 | include $(BUILD_EXECUTABLE) 79 | 80 | 81 | ###yamivpp 82 | include $(CLEAR_VARS) 83 | include $(LOCAL_PATH)/../common.mk 84 | LOCAL_SRC_FILES := \ 85 | vpp.cpp \ 86 | 87 | LOCAL_C_INCLUDES := \ 88 | $(LOCAL_PATH)/.. \ 89 | $(LOCAL_PATH)/../interface \ 90 | $(LOCAL_PATH)/../tests \ 91 | external/libcxx/include \ 92 | $(TARGET_OUT_HEADERS)/libva 93 | 94 | LOCAL_SHARED_LIBRARIES := \ 95 | libutils \ 96 | liblog \ 97 | libc++ \ 98 | libva \ 99 | libva-android \ 100 | libgui \ 101 | libhardware \ 102 | libyami \ 103 | 104 | LOCAL_CPPFLAGS += \ 105 | -frtti 106 | 107 | LOCAL_MULTILIB := both 108 | LOCAL_STATIC_LIBRARIES := libinputoutput 109 | LOCAL_PROPRIETARY_MODULE := true 110 | LOCAL_MODULE := yamivpp 111 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 112 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 113 | include $(BUILD_EXECUTABLE) 114 | 115 | 116 | ###yamiencode 117 | include $(CLEAR_VARS) 118 | include $(LOCAL_PATH)/../common.mk 119 | LOCAL_SRC_FILES := \ 120 | encode.cpp \ 121 | 122 | LOCAL_C_INCLUDES := \ 123 | $(LOCAL_PATH)/.. \ 124 | $(LOCAL_PATH)/../interface \ 125 | $(LOCAL_PATH)/../tests \ 126 | external/libcxx/include \ 127 | $(TARGET_OUT_HEADERS)/libva 128 | 129 | LOCAL_SHARED_LIBRARIES := \ 130 | libutils \ 131 | liblog \ 132 | libc++ \ 133 | libva \ 134 | libva-android \ 135 | libgui \ 136 | libhardware \ 137 | libyami \ 138 | 139 | LOCAL_CPPFLAGS += \ 140 | -frtti 141 | 142 | LOCAL_MULTILIB := both 143 | LOCAL_STATIC_LIBRARIES := libinputoutput 144 | LOCAL_PROPRIETARY_MODULE := true 145 | LOCAL_MODULE := yamiencode 146 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 147 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 148 | 149 | include $(BUILD_EXECUTABLE) 150 | 151 | 152 | ###yamitranscode 153 | include $(CLEAR_VARS) 154 | include $(LOCAL_PATH)/../common.mk 155 | LOCAL_SRC_FILES := \ 156 | yamitranscode.cpp \ 157 | 158 | LOCAL_C_INCLUDES := \ 159 | $(LOCAL_PATH)/.. \ 160 | $(LOCAL_PATH)/../interface \ 161 | $(LOCAL_PATH)/../tests \ 162 | external/libcxx/include \ 163 | $(TARGET_OUT_HEADERS)/libva 164 | 165 | LOCAL_SHARED_LIBRARIES := \ 166 | libutils \ 167 | liblog \ 168 | libc++ \ 169 | libva \ 170 | libva-android \ 171 | libgui \ 172 | libhardware \ 173 | libyami \ 174 | 175 | LOCAL_CPPFLAGS += \ 176 | -frtti 177 | 178 | LOCAL_MULTILIB := both 179 | LOCAL_STATIC_LIBRARIES := libinputoutput 180 | LOCAL_PROPRIETARY_MODULE := true 181 | LOCAL_MODULE := yamitranscode 182 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 183 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 184 | 185 | include $(BUILD_EXECUTABLE) 186 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = yamidecode yamiencode yamivpp yamitranscode 2 | if ENABLE_V4L2 3 | bin_PROGRAMS += v4l2encode v4l2decode 4 | endif 5 | 6 | #to compile within yocto 7 | extra_includes = \ 8 | -I$(top_srcdir) \ 9 | $(NULL) 10 | 11 | YAMI_COMMON_CFLAGS = \ 12 | $(LIBVA_CFLAGS) \ 13 | $(LIBYAMI_CFLAGS) \ 14 | $(extra_includes) \ 15 | $(NULL) 16 | 17 | DECODE_INPUT_SOURCES = \ 18 | decodeinput.cpp \ 19 | $(NULL) 20 | 21 | YAMI_COMMON_LIBS = \ 22 | $(LIBVA_LIBS) \ 23 | $(LIBVA_DRM_LIBS) \ 24 | $(LIBYAMI_LIBS) \ 25 | $(NULL) 26 | 27 | YAMI_DECODE_LIBS = \ 28 | $(YAMI_COMMON_LIBS) \ 29 | $(NULL) 30 | 31 | if ENABLE_V4L2 32 | YAMI_COMMON_CFLAGS += \ 33 | $(LIBYAMIV4L2_CFLAGS) \ 34 | $(NULL) 35 | 36 | YAMI_COMMON_LIBS += \ 37 | $(LIBYAMIV4L2_LIBS) \ 38 | $(NULL) 39 | endif 40 | 41 | if ENABLE_AVFORMAT 42 | DECODE_INPUT_SOURCES += decodeinputavformat.cpp 43 | YAMI_COMMON_CFLAGS += -D__STDC_CONSTANT_MACROS \ 44 | $(LIBAVFORMAT_CFLAGS) 45 | YAMI_DECODE_LIBS += $(LIBAVFORMAT_LIBS) 46 | endif 47 | 48 | if ENABLE_X11 49 | YAMI_COMMON_LIBS += $(LIBVA_X11_LIBS) -lX11 50 | endif 51 | 52 | if ENABLE_WAYLAND 53 | YAMI_COMMON_LIBS += $(LIBVA_WAYLAND_LIBS) 54 | endif 55 | if ENABLE_EGL 56 | YAMI_DECODE_LIBS += $(LIBEGL_LIBS) $(LIBGLES2_LIBS) 57 | endif 58 | 59 | if HAVE_LIBBSD 60 | YAMI_DECODE_LIBS += $(LIBBSD_LIBS) 61 | endif 62 | 63 | YAMI_ENCODE_LIBS = \ 64 | $(YAMI_DECODE_LIBS) \ 65 | $(NULL) 66 | 67 | V4L2_DECODE_LIBS = \ 68 | $(YAMI_DECODE_LIBS) \ 69 | $(NULL) 70 | 71 | V4L2_DECODE_LIBS += $(LIBEGL_LIBS) $(LIBGLES2_LIBS) 72 | 73 | V4L2_ENCODE_LIBS = \ 74 | $(YAMI_ENCODE_LIBS) \ 75 | $(NULL) 76 | 77 | CAPI_DECODE_LIBS = \ 78 | $(YAMI_DECODE_LIBS) \ 79 | $(NULL) 80 | 81 | CAPI_ENCODE_LIBS = \ 82 | $(YAMI_ENCODE_LIBS) \ 83 | $(NULL) 84 | 85 | YAMI_VPP_LIBS = \ 86 | $(YAMI_DECODE_LIBS) \ 87 | $(YAMI_ENCODE_LIBS) \ 88 | $(NULL) 89 | 90 | YAMI_VPP_CFLAGS = \ 91 | $(LIBVA_CFLAGS) \ 92 | $(NULL) 93 | 94 | yamidecode_LDADD = $(YAMI_VPP_LIBS) 95 | yamidecode_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 96 | yamidecode_SOURCES = decode.cpp decodehelp.cpp $(DECODE_INPUT_SOURCES) decodeoutput.cpp vppinputoutput.cpp vppinputdecode.cpp vppoutputencode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp vppinputdecodecapi.cpp md5.c 97 | if ENABLE_EGL 98 | yamidecode_SOURCES += ../egl/egl_util.c ./egl/gles2_help.c 99 | endif 100 | 101 | yamiencode_LDADD = $(YAMI_ENCODE_LIBS) 102 | yamiencode_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 103 | yamiencode_SOURCES = encode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp $(DECODE_INPUT_SOURCES) 104 | 105 | v4l2decode_LDADD = $(V4L2_DECODE_LIBS) 106 | v4l2decode_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 107 | v4l2decode_SOURCES = v4l2decode.cpp V4L2Renderer.cpp V4L2Device.cpp decodehelp.cpp $(DECODE_INPUT_SOURCES) 108 | 109 | if ENABLE_EGL 110 | v4l2decode_SOURCES += ./egl/gles2_help.c 111 | endif 112 | v4l2decode_LDADD += -ldl 113 | 114 | 115 | v4l2encode_LDADD = $(V4L2_ENCODE_LIBS) 116 | v4l2encode_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 117 | v4l2encode_SOURCES = v4l2encode.cpp encodeinput.h encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp $(DECODE_INPUT_SOURCES) 118 | 119 | yamivpp_LDADD = $(YAMI_VPP_LIBS) 120 | yamivpp_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 121 | yamivpp_SOURCES = vppinputdecode.cpp vppinputoutput.cpp vppoutputencode.cpp vpp.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp $(DECODE_INPUT_SOURCES) vppinputdecodecapi.cpp 122 | 123 | yamitranscode_LDADD = $(YAMI_VPP_LIBS) 124 | yamitranscode_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 125 | yamitranscode_LDFLAGS = -pthread $(AM_LDFLAGS) 126 | yamitranscode_SOURCES = vppinputdecode.cpp vppinputoutput.cpp vppoutputencode.cpp yamitranscode.cpp encodeinput.cpp encodeInputCamera.cpp encodeInputDecoder.cpp $(DECODE_INPUT_SOURCES) vppinputasync.cpp vppinputdecodecapi.cpp 127 | 128 | bin_PROGRAMS += yamiinfo 129 | yamiinfo_SOURCES = yamiinfo.cpp 130 | yamiinfo_CPPFLAGS = $(YAMI_COMMON_CFLAGS) $(AM_CPPFLAGS) 131 | yamiinfo_LDADD = $(YAMI_COMMON_LIBS) 132 | yamiinfo_LDFLAGS = -Wl,--no-as-needed \ 133 | $(AM_LDFLAGS) \ 134 | $(NULL) 135 | -------------------------------------------------------------------------------- /tests/V4L2Device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include "V4L2Device.h" 21 | 22 | #include "common/log.h" 23 | #include "common/common_def.h" 24 | #include 25 | #include 26 | 27 | #ifdef __ENABLE_V4L2_OPS__ 28 | 29 | #include "v4l2codec_device_ops.h" 30 | #include 31 | #include 32 | 33 | #define SIMULATE_V4L2_OP(OP, ...) \ 34 | do { \ 35 | if (!m_ops.m##OP##Func) \ 36 | return -1; \ 37 | return m_ops.m##OP##Func(m_fd, ##__VA_ARGS__); \ 38 | } while (0) 39 | 40 | struct TypeEntry { 41 | VideoDataMemoryType type; 42 | const char* str; 43 | }; 44 | 45 | const static TypeEntry g_entrys[] = { 46 | { VIDEO_DATA_MEMORY_TYPE_DRM_NAME, "drm-name" }, 47 | { VIDEO_DATA_MEMORY_TYPE_DMA_BUF, "dma-buf" }, 48 | { VIDEO_DATA_MEMORY_TYPE_ANDROID_BUFFER_HANDLE, "android-buffer-handle" }, 49 | { VIDEO_DATA_MEMORY_TYPE_EXTERNAL_DMA_BUF, "external-dma-buf" } 50 | 51 | }; 52 | 53 | const char* frameTypeToString(VideoDataMemoryType type) 54 | { 55 | for (size_t i = 0; i < N_ELEMENTS(g_entrys); i++) { 56 | if (type == g_entrys[i].type) 57 | return g_entrys[i].str; 58 | } 59 | ASSERT(0 && "not support yet"); 60 | return NULL; 61 | } 62 | 63 | class V4L2DeviceOps : public V4L2Device { 64 | public: 65 | bool open(const char* name, int32_t flags) 66 | { 67 | if (!m_ops.mOpenFunc) 68 | return false; 69 | m_fd = m_ops.mOpenFunc(name, flags); 70 | return m_fd != -1; 71 | } 72 | 73 | int32_t close() 74 | { 75 | SIMULATE_V4L2_OP(Close); 76 | } 77 | 78 | int32_t ioctl(int32_t cmd, void* arg) 79 | { 80 | SIMULATE_V4L2_OP(Ioctl, cmd, arg); 81 | } 82 | 83 | int32_t poll(bool pollDevice, bool* eventPending) 84 | { 85 | SIMULATE_V4L2_OP(Poll, pollDevice, eventPending); 86 | } 87 | 88 | int32_t setDevicePollInterrupt() 89 | { 90 | SIMULATE_V4L2_OP(SetDevicePollInterrupt); 91 | } 92 | 93 | int32_t clearDevicePollInterrupt() 94 | { 95 | SIMULATE_V4L2_OP(ClearDevicePollInterrupt); 96 | } 97 | 98 | void* mmap(void* addr, size_t length, int32_t prot, 99 | int32_t flags, unsigned int offset) 100 | { 101 | if (!m_ops.mMmapFunc) 102 | return NULL; 103 | 104 | return m_ops.mMmapFunc(addr, length, prot, flags, m_fd, offset); 105 | } 106 | 107 | int32_t munmap(void* addr, size_t length) 108 | { 109 | if (!m_ops.mMunmapFunc) 110 | return -1; 111 | 112 | return m_ops.mMunmapFunc(addr, length); 113 | } 114 | 115 | int32_t setFrameMemoryType(VideoDataMemoryType type) 116 | { 117 | const char* str = frameTypeToString(type); 118 | if (str) 119 | SIMULATE_V4L2_OP(SetParameter, "frame-memory-type", str); 120 | return -1; 121 | } 122 | 123 | #if __ENABLE_EGL__ 124 | int32_t useEglImage(/*EGLDisplay*/ void* eglDisplay, /*EGLContext*/ void* eglContext, 125 | uint32_t bufferIndex, void* eglImage) 126 | { 127 | SIMULATE_V4L2_OP(UseEglImage, eglDisplay, eglContext, bufferIndex, eglImage); 128 | } 129 | 130 | int32_t setDrmFd(int drmFd) 131 | { 132 | ASSERT(0 && "not supported yet"); 133 | return -1; 134 | } 135 | #endif 136 | 137 | #if __ENABLE_WAYLAND__ 138 | int32_t setWaylandDisplay(struct wl_display* wlDisplay) 139 | { 140 | char displayStr[32]; 141 | sprintf(displayStr, "%" PRIu64 "", (uint64_t)(wlDisplay)); 142 | SIMULATE_V4L2_OP(SetParameter, "wayland-display", displayStr); 143 | } 144 | #endif 145 | 146 | #if __ENABLE_X11__ 147 | /// it should be called before driver initialization (immediate after _Open()). 148 | int32_t setXDisplay(Display* x11Display) 149 | { 150 | char displayStr[32]; 151 | sprintf(displayStr, "%" PRIu64 "", (uint64_t)x11Display); 152 | SIMULATE_V4L2_OP(SetParameter, "x11-display", displayStr); 153 | } 154 | #endif 155 | 156 | V4L2DeviceOps() 157 | : m_handle(NULL) 158 | { 159 | memset(&m_ops, 0, sizeof(m_ops)); 160 | } 161 | 162 | ~V4L2DeviceOps() 163 | { 164 | if (m_handle) 165 | dlclose(m_handle); 166 | } 167 | 168 | protected: 169 | bool init() 170 | { 171 | const char* libName = "libyami_v4l2.so"; 172 | m_handle = dlopen(libName, RTLD_NOW | RTLD_GLOBAL); 173 | if (!m_handle) { 174 | ERROR("dlopen failed for %s", libName); 175 | return false; 176 | } 177 | 178 | V4l2codecOperationInitFunc initFunc = NULL; 179 | initFunc = (V4l2codecOperationInitFunc)dlsym(RTLD_DEFAULT, "v4l2codecOperationInit"); 180 | 181 | if (!initFunc) { 182 | ERROR("fail to dlsym v4l2codecOperationInit\n"); 183 | return false; 184 | } 185 | 186 | INIT_V4L2CODEC_OPS_SIZE_VERSION(&m_ops); 187 | if (!initFunc(&m_ops)) { 188 | ERROR("fail to init v4l2 device operation func pointers\n"); 189 | return false; 190 | } 191 | 192 | int isVersionMatch = 0; 193 | IS_V4L2CODEC_OPS_VERSION_MATCH(m_ops.mVersion, isVersionMatch); 194 | if (!isVersionMatch) { 195 | ERROR("V4l2CodecOps interface version doesn't match\n"); 196 | return false; 197 | } 198 | if (m_ops.mSize != sizeof(V4l2CodecOps)) { 199 | ERROR("V4l2CodecOps interface data structure size doesn't match\n"); 200 | return false; 201 | } 202 | return true; 203 | } 204 | 205 | private: 206 | void* m_handle; 207 | V4l2CodecOps m_ops; 208 | }; 209 | #undef SIMULATE_V4L2_OP 210 | 211 | #else 212 | 213 | #include 214 | 215 | class V4L2DeviceYami : public V4L2Device { 216 | public: 217 | bool open(const char* name, int32_t flags) 218 | { 219 | m_fd = YamiV4L2_Open(name, flags); 220 | return m_fd != -1; 221 | } 222 | int32_t close() 223 | { 224 | return YamiV4L2_Close(m_fd); 225 | } 226 | int32_t ioctl(int32_t cmd, void* arg) 227 | { 228 | return YamiV4L2_Ioctl(m_fd, cmd, arg); 229 | } 230 | int32_t poll(bool pollDevice, bool* eventPending) 231 | { 232 | return YamiV4L2_Poll(m_fd, pollDevice, eventPending); 233 | } 234 | int32_t setDevicePollInterrupt() 235 | { 236 | return YamiV4L2_SetDevicePollInterrupt(m_fd); 237 | } 238 | int32_t clearDevicePollInterrupt() 239 | { 240 | return YamiV4L2_ClearDevicePollInterrupt(m_fd); 241 | } 242 | void* mmap(void* addr, size_t length, int32_t prot, 243 | int32_t flags, unsigned int offset) 244 | { 245 | return YamiV4L2_Mmap(addr, length, prot, flags, m_fd, offset); 246 | } 247 | int32_t munmap(void* addr, size_t length) 248 | { 249 | return YamiV4L2_Munmap(addr, length); 250 | } 251 | int32_t setFrameMemoryType(VideoDataMemoryType type) 252 | { 253 | return YamiV4L2_FrameMemoryType(m_fd, type); 254 | } 255 | 256 | #if __ENABLE_EGL__ 257 | int32_t useEglImage(/*EGLDisplay*/ void* eglDisplay, /*EGLContext*/ void* eglContext, 258 | uint32_t bufferIndex, void* eglImage) 259 | { 260 | return YamiV4L2_UseEglImage(m_fd, eglDisplay, eglContext, bufferIndex, eglImage); 261 | } 262 | int32_t setDrmFd(int drmFd) 263 | { 264 | return YamiV4L2_SetDrmFd(m_fd, drmFd); 265 | } 266 | #endif 267 | 268 | #if __ENABLE_WAYLAND__ 269 | int32_t setWaylandDisplay(struct wl_display* wlDisplay) 270 | { 271 | return YamiV4L2_SetWaylandDisplay(m_fd, wlDisplay); 272 | } 273 | #endif 274 | 275 | #if __ENABLE_X11__ 276 | /// it should be called before driver initialization (immediate after _Open()). 277 | int32_t setXDisplay(Display* x11Display) 278 | { 279 | return YamiV4L2_SetXDisplay(m_fd, x11Display); 280 | } 281 | #endif 282 | 283 | protected: 284 | bool init() 285 | { 286 | return true; 287 | } 288 | }; 289 | #endif //__ENABLE_V4L2_OPS__ 290 | 291 | SharedPtr V4L2Device::Create() 292 | { 293 | SharedPtr device; 294 | #ifdef __ENABLE_V4L2_OPS__ 295 | device.reset(new V4L2DeviceOps); 296 | #else 297 | device.reset(new V4L2DeviceYami); 298 | #endif 299 | if (!device->init()) 300 | device.reset(); 301 | return device; 302 | } 303 | -------------------------------------------------------------------------------- /tests/V4L2Device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef V4L2Device_h 17 | #define V4L2Device_h 18 | 19 | #include 20 | #if __ENABLE_X11__ 21 | #include 22 | #endif 23 | 24 | #if __ENABLE_EGL__ 25 | #include 26 | #endif 27 | 28 | class V4L2Device { 29 | public: 30 | static SharedPtr Create(); 31 | virtual bool open(const char* name, int32_t flags) = 0; 32 | virtual int32_t close() = 0; 33 | virtual int32_t ioctl(int32_t cmd, void* arg) = 0; 34 | virtual int32_t poll(bool pollDevice, bool* eventPending) = 0; 35 | virtual int32_t setDevicePollInterrupt() = 0; 36 | virtual int32_t clearDevicePollInterrupt() = 0; 37 | virtual void* mmap(void* addr, size_t length, int32_t prot, 38 | int32_t flags, unsigned int offset) 39 | = 0; 40 | virtual int32_t munmap(void* addr, size_t length) = 0; 41 | virtual int32_t setFrameMemoryType(VideoDataMemoryType memory_type) = 0; 42 | 43 | #if __ENABLE_EGL__ 44 | virtual int32_t useEglImage(/*EGLDisplay*/ void* eglDisplay, /*EGLContext*/ void* eglContext, 45 | uint32_t bufferIndex, void* eglImage) 46 | = 0; 47 | virtual int32_t setDrmFd(int drmFd) = 0; 48 | #endif 49 | 50 | #if __ENABLE_WAYLAND__ 51 | virtual int32_t setWaylandDisplay(struct wl_display* wlDisplay) = 0; 52 | #endif 53 | 54 | #if __ENABLE_X11__ 55 | /// it should be called before driver initialization (immediate after _Open()). 56 | virtual int32_t setXDisplay(Display* x11Display) = 0; 57 | #endif 58 | protected: 59 | virtual bool init() = 0; 60 | int m_fd; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /tests/V4L2Renderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | class V4L2Device; 21 | class V4L2Renderer { 22 | public: 23 | static SharedPtr create(const SharedPtr&, VideoDataMemoryType memoryType); 24 | virtual bool setDisplay() = 0; 25 | virtual bool setupOutputBuffers(uint32_t wdith, uint32_t height, uint32_t dpbSize = 0) = 0; 26 | bool renderOneFrame(); 27 | virtual bool queueOutputBuffers() = 0; 28 | bool onFormatChanged(); 29 | 30 | protected: 31 | V4L2Renderer(const SharedPtr&, VideoDataMemoryType memoryType); 32 | virtual ~V4L2Renderer(){}; 33 | bool getDpbSize(uint32_t& dpbSize); 34 | bool requestBuffers(uint32_t& count); 35 | bool queueBuffer(uint32_t index, unsigned long userptr = 0); 36 | bool dequeBuffer(uint32_t& index); 37 | virtual bool render(uint32_t& index) = 0; 38 | virtual bool queueOutputBuffersAtStart(uint32_t count) = 0; 39 | virtual bool resizeWindow(uint32_t width, uint32_t height) = 0; 40 | virtual void destroyOutputBuffers() = 0; 41 | 42 | SharedPtr m_device; 43 | VideoDataMemoryType m_memoryType; 44 | uint32_t m_dpbSize; 45 | uint32_t m_width; 46 | uint32_t m_height; 47 | 48 | private: 49 | void streamOff(bool off); 50 | bool getSurfaceGeometry(uint32_t& width, uint32_t& height, uint32_t& dpbSize); 51 | }; 52 | -------------------------------------------------------------------------------- /tests/decode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include "vppinputdecodecapi.h" 21 | #include "vppinputdecode.h" 22 | #include "decodeoutput.h" 23 | #include "decodehelp.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | SharedPtr createInput(DecodeParameter& para, SharedPtr& display) 32 | { 33 | SharedPtr input(VppInput::create(para.inputFile, para.renderFourcc, para.width, para.height, para.useCAPI)); 34 | if (!input) { 35 | fprintf(stderr, "VppInput create failed.\n"); 36 | return input; 37 | } 38 | if(para.useCAPI){ 39 | SharedPtr inputDecode = DynamicPointerCast(input); 40 | if (inputDecode && inputDecode->config(*display)) 41 | return input; 42 | }else{ 43 | SharedPtr inputDecode = DynamicPointerCast(input); 44 | if (inputDecode) { 45 | inputDecode->setTargetLayer(para.temporalLayer); 46 | inputDecode->setLowLatency(para.enableLowLatency); 47 | if (inputDecode->config(*display)) 48 | return input; 49 | } 50 | } 51 | input.reset(); 52 | fprintf(stderr, "VppInputDecode config failed.\n"); 53 | return input; 54 | } 55 | 56 | class DecodeTest { 57 | public: 58 | bool init(int argc, char** argv) 59 | { 60 | if (!processCmdLine(argc, argv, &m_params)) { 61 | fprintf(stderr, "process arguments failed.\n"); 62 | return false; 63 | } 64 | m_output.reset(DecodeOutput::create(m_params.renderMode, m_params.renderFourcc, m_params.inputFile, m_params.outputFile.c_str())); 65 | if (!m_output) { 66 | fprintf(stderr, "DecodeOutput::create failed.\n"); 67 | return false; 68 | } 69 | m_nativeDisplay = m_output->nativeDisplay(); 70 | m_vppInput = createInput(m_params, m_nativeDisplay); 71 | 72 | if (!m_nativeDisplay || !m_vppInput) { 73 | fprintf(stderr, "DecodeTest init failed.\n"); 74 | return false; 75 | } 76 | return true; 77 | } 78 | bool run() 79 | { 80 | FpsCalc fps; 81 | SharedPtr src; 82 | uint32_t count = 0; 83 | while (m_vppInput->read(src)) { 84 | if (!m_output->output(src)) 85 | break; 86 | count++; 87 | fps.addFrame(); 88 | if (count == m_params.renderFrames) 89 | break; 90 | } 91 | fps.log(); 92 | 93 | possibleWait(m_vppInput->getMimeType(), &m_params); 94 | 95 | return true; 96 | } 97 | 98 | private: 99 | SharedPtr m_output; 100 | SharedPtr m_nativeDisplay; 101 | SharedPtr m_vppInput; 102 | DecodeParameter m_params; 103 | }; 104 | 105 | int main(int argc, char* argv[]) 106 | { 107 | DecodeTest decode; 108 | if (!decode.init(argc, argv)) 109 | return 1; 110 | decode.run(); 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /tests/decodeInputCapi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include "decodeInputCapi.h" 22 | #include "decodeinput.h" 23 | 24 | using namespace YamiMediaCodec; 25 | 26 | DecodeInputHandler createDecodeInput(char *fileName) 27 | { 28 | return DecodeInput::create(fileName); 29 | } 30 | 31 | const char * getMimeType(DecodeInputHandler input) 32 | { 33 | if(input) 34 | return ((DecodeInput*)input)->getMimeType(); 35 | else 36 | return NULL; 37 | } 38 | 39 | bool decodeInputIsEOS(DecodeInputHandler input) 40 | { 41 | if(input) 42 | return ((DecodeInput*)input)->isEOS(); 43 | else 44 | return false; 45 | } 46 | 47 | bool getNextDecodeUnit(DecodeInputHandler input, VideoDecodeBuffer *inputbuffer) 48 | { 49 | if(input) 50 | return ((DecodeInput*)input)->getNextDecodeUnit(*inputbuffer); 51 | else 52 | return false; 53 | } 54 | 55 | void releaseDecodeInput(DecodeInputHandler input) 56 | { 57 | if(input) 58 | delete (DecodeInput*)input; 59 | } 60 | -------------------------------------------------------------------------------- /tests/decodeInputCapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef void* DecodeInputHandler; 27 | 28 | DecodeInputHandler createDecodeInput(char *fileName); 29 | 30 | const char * getMimeType(DecodeInputHandler input); 31 | 32 | bool decodeInputIsEOS(DecodeInputHandler input); 33 | 34 | bool getNextDecodeUnit(DecodeInputHandler input, VideoDecodeBuffer *inputbuffer); 35 | 36 | void releaseDecodeInput(DecodeInputHandler input); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /tests/decodeOutputCapi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include "decodeOutputCapi.h" 22 | #include "decodeoutput.h" 23 | 24 | using namespace YamiMediaCodec; 25 | 26 | DecodeOutputHandler createDecodeOutput(DecodeHandler decoder, int renderMode) 27 | { 28 | if (!decoder) 29 | return NULL; 30 | IVideoDecoder* dec = reinterpret_cast(decoder); 31 | DecodeOutput* out = DecodeOutput::create(dec, renderMode); 32 | return reinterpret_cast(out); 33 | } 34 | 35 | bool decodeOutputSetVideoSize(DecodeOutputHandler output, int width , int height) 36 | { 37 | if (!output) 38 | return false; 39 | DecodeOutput* out = reinterpret_cast(output); 40 | return out->setVideoSize(width, height); 41 | } 42 | 43 | int renderOutputFrames(DecodeOutputHandler output, uint32_t maxframes, bool drain) 44 | { 45 | if (!output) 46 | return -1; 47 | DecodeOutput* out = reinterpret_cast(output); 48 | if(out->renderFrameCount() != maxframes) 49 | renderOutputFrames(out, maxframes, drain); 50 | return out->renderFrameCount(); 51 | } 52 | 53 | void releaseDecodeOutput(DecodeOutputHandler output) 54 | { 55 | if (!output) 56 | return; 57 | DecodeOutput* out = reinterpret_cast(output); 58 | delete out; 59 | } 60 | 61 | bool configDecodeOutput(DecodeOutputHandler output) 62 | { 63 | if (!output) 64 | return false; 65 | DecodeOutput* out = reinterpret_cast(output); 66 | return configDecodeOutput(out); 67 | } 68 | -------------------------------------------------------------------------------- /tests/decodeOutputCapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | struct DecodeOutputTag 24 | { 25 | }; 26 | 27 | typedef struct DecodeOutputTag* DecodeOutputHandler; 28 | 29 | 30 | 31 | DecodeOutputHandler createDecodeOutput(DecodeHandler decoder, int renderMode); 32 | bool configDecodeOutput(DecodeOutputHandler output); 33 | bool decodeOutputSetVideoSize(DecodeOutputHandler output, int width , int height); 34 | int renderOutputFrames(DecodeOutputHandler output, uint32_t maxframes, bool drain); 35 | void releaseDecodeOutput(DecodeOutputHandler output); 36 | 37 | 38 | 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /tests/decodecapi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #ifdef __ENABLE_X11__ 25 | #include 26 | #endif 27 | #include 28 | #include "decodeInputCapi.h" 29 | #include "decodeOutputCapi.h" 30 | #include "decodehelp.h" 31 | 32 | int main(int argc, char** argv) 33 | { 34 | int frames = 0; 35 | DecodeHandler decoder = NULL; 36 | DecodeInputHandler input = NULL; 37 | DecodeOutputHandler output = NULL; 38 | VideoDecodeBuffer inputBuffer; 39 | VideoConfigBuffer configBuffer; 40 | const VideoFormatInfo *formatInfo = NULL; 41 | Decode_Status status; 42 | 43 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 44 | 45 | if (!process_cmdline(argc, argv)) 46 | return -1; 47 | 48 | input = createDecodeInput(inputFileName); 49 | 50 | if (input == NULL) { 51 | fprintf(stderr, "fail to init input stream\n"); 52 | return -1; 53 | } 54 | 55 | decoder = createDecoder(getMimeType(input)); 56 | assert(decoder != NULL); 57 | 58 | output = createDecodeOutput(decoder, renderMode); 59 | assert(output != NULL); 60 | if (!configDecodeOutput(output)) { 61 | fprintf(stderr, "fail to config decoder output"); 62 | return -1; 63 | } 64 | 65 | if (renderMode == 0) { 66 | NativeDisplay nativeDisplay; 67 | nativeDisplay.type = NATIVE_DISPLAY_DRM; 68 | nativeDisplay.handle = 0; 69 | decodeSetNativeDisplay(decoder, &nativeDisplay); 70 | } else { 71 | // TODO, XXX, NativeDisplay should set here, not output->setVideoSize(). 72 | } 73 | 74 | memset(&configBuffer,0,sizeof(VideoConfigBuffer)); 75 | configBuffer.profile = VAProfileNone; 76 | 77 | status = decodeStart(decoder, &configBuffer); 78 | assert(status == DECODE_SUCCESS); 79 | 80 | while(!decodeInputIsEOS(input)) 81 | { 82 | if (getNextDecodeUnit(input, &inputBuffer)) 83 | status = decode(decoder, &inputBuffer); 84 | else 85 | break; 86 | 87 | 88 | if (DECODE_FORMAT_CHANGE == status) { 89 | formatInfo = getFormatInfo(decoder); 90 | if (!decodeOutputSetVideoSize(output, formatInfo->width, formatInfo->height)) { 91 | assert(0 && "set video size failed"); 92 | } 93 | status = decode(decoder, &inputBuffer); 94 | } 95 | 96 | frames = renderOutputFrames(output, frameCount, false); 97 | if((frames == -1) || (frames == frameCount)) 98 | break; 99 | } 100 | 101 | renderOutputFrames(output, frameCount, true); 102 | 103 | possibleWait(getMimeType(input)); 104 | 105 | decodeStop(decoder); 106 | releaseDecoder(decoder); 107 | 108 | if(input) 109 | releaseDecodeInput(input); 110 | if (output) 111 | releaseDecodeOutput(output); 112 | if (dumpOutputName) 113 | free(dumpOutputName); 114 | 115 | 116 | fprintf(stderr, "decode done\n"); 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /tests/decodehelp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | #include "decodehelp.h" 21 | 22 | #include "common/utils.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace YamiMediaCodec; 34 | 35 | static void printHelp(const char* app) 36 | { 37 | printf("%s \n", app); 38 | printf(" -i media file to decode\n"); 39 | printf(" -w wait before quit: 0:no-wait, 1:auto(jpeg wait), 2:wait\n"); 40 | printf(" -f dumped fourcc [*]\n"); 41 | printf(" -o dumped output dir\n"); 42 | printf(" -n specify how many frames to be decoded\n"); 43 | printf(" -m \n"); 44 | printf(" -2: print MD5 by per frame and the whole decoded file MD5\n"); 45 | printf(" -1: skip video rendering [*]\n"); 46 | printf(" 0: dump video frame to file [*]\n"); 47 | printf(" 1: render to X window [*]\n"); 48 | printf(" 2: texture: render to Pixmap + texture from Pixmap [*]\n"); 49 | printf(" 3: texture: export video frame as drm name (RGBX) + texture from drm name\n"); 50 | printf(" 4: texture: export video frame as dma_buf(RGBX) + texutre from dma_buf\n"); 51 | printf(" 5: texture: export video frame as dma_buf(NV12) + texture from dma_buf. not implement yet\n"); 52 | printf(" 6: use external dma buf for decode and display, only v4l2decode support this\n"); 53 | printf(" [*] v4l2decode doesn't support the option\n"); 54 | printf(" --capi: use the codec capi to encode or decode, default(false)\n"); 55 | printf(" --temporal-layer: decode SVC-T stream up to given layer, default 0, only vp8 support\n"); 56 | printf(" 0: decode all layers\n"); 57 | printf(" N>0: decode the first N layers\n"); 58 | printf(" --lowlatency: if set this flag to true, AVC decoder will output the ready frames ASAP\n"); 59 | } 60 | 61 | bool processCmdLine(int argc, char** argv, DecodeParameter* parameters) 62 | { 63 | int32_t option_index; 64 | bool isSetFourcc = false; 65 | std::string outputFile; 66 | parameters->renderFrames = UINT_MAX; 67 | parameters->waitBeforeQuit = 1; 68 | parameters->renderMode = 1; 69 | parameters->inputFile = NULL; 70 | parameters->useCAPI = false; 71 | parameters->temporalLayer = 0; 72 | parameters->spacialLayer = 0; 73 | parameters->qualityLayer = 0; 74 | parameters->enableLowLatency = false; 75 | 76 | const struct option long_opts[] = { 77 | { "help", no_argument, NULL, 'h' }, 78 | { "capi", no_argument, NULL, 0 }, 79 | { "temporal-layer", required_argument, NULL, 0 }, 80 | { "lowlatency", no_argument, 0, 0 }, 81 | { NULL, no_argument, NULL, 0 } 82 | }; 83 | 84 | char opt; 85 | while ((opt = getopt_long_only(argc, argv, "h:m:n:i:f:o:w:?", long_opts,&option_index)) != -1){ 86 | switch (opt) { 87 | case 'h': 88 | case '?': 89 | printHelp(argv[0]); 90 | return false; 91 | case 'i': 92 | parameters->inputFile = optarg; 93 | break; 94 | case 'w': 95 | parameters->waitBeforeQuit = atoi(optarg); 96 | break; 97 | case 'm': 98 | parameters->renderMode = atoi(optarg); 99 | break; 100 | case 'n': 101 | parameters->renderFrames = atoi(optarg); 102 | break; 103 | case 'f': 104 | if (strlen(optarg) == 4) { 105 | parameters->renderFourcc = YAMI_FOURCC(toupper(optarg[0]), toupper(optarg[1]), toupper(optarg[2]), toupper(optarg[3])); 106 | isSetFourcc = true; 107 | } 108 | else { 109 | fprintf(stderr, "invalid fourcc: %s\n", optarg); 110 | return false; 111 | } 112 | break; 113 | case 'o': 114 | outputFile = optarg; 115 | break; 116 | case 0: 117 | switch (option_index) { 118 | case 1: 119 | parameters->useCAPI = true; 120 | break; 121 | case 2: 122 | parameters->temporalLayer = atoi(optarg); 123 | break; 124 | case 3: 125 | parameters->enableLowLatency = true; 126 | break; 127 | default: 128 | printHelp(argv[0]); 129 | break; 130 | } 131 | break; 132 | default: 133 | printHelp(argv[0]); 134 | break; 135 | } 136 | } 137 | if (optind < argc) { 138 | int indexOpt = optind; 139 | printf("unrecognized option: "); 140 | while (indexOpt < argc) 141 | printf("%s ", argv[indexOpt++]); 142 | printf("\n"); 143 | printHelp(argv[0]); 144 | return false; 145 | } 146 | 147 | if (!parameters->inputFile) { 148 | fprintf(stderr, "no input media file specified.\n"); 149 | return false; 150 | } 151 | if (outputFile.empty()) 152 | outputFile = "./"; 153 | parameters->outputFile = outputFile; 154 | if (!isSetFourcc) 155 | parameters->renderFourcc = guessFourcc(parameters->outputFile.c_str()); 156 | int width, height; 157 | if (guessResolution(parameters->inputFile, width, height)) { 158 | parameters->width = width; 159 | parameters->height = height; 160 | } 161 | return true; 162 | } 163 | 164 | bool possibleWait(const char* mimeType, const DecodeParameter* parameters) 165 | { 166 | // waitBeforeQuit 0:nowait, 1:auto(jpeg wait), 2:wait 167 | switch (parameters->waitBeforeQuit) { 168 | case 0: 169 | break; 170 | case 1: 171 | if (parameters->renderMode == 0 || strcmp(mimeType, YAMI_MIME_JPEG)) 172 | break; 173 | case 2: 174 | fprintf(stdout, "press any key to continue ..."); 175 | getchar(); 176 | break; 177 | default: 178 | break; 179 | } 180 | 181 | return true; 182 | } 183 | -------------------------------------------------------------------------------- /tests/decodehelp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef decodehelp_h 17 | #define decodehelp_h 18 | 19 | #include 20 | #include 21 | 22 | typedef struct DecodeParameter { 23 | char* inputFile; 24 | int width; 25 | int height; 26 | short renderMode; 27 | short waitBeforeQuit; 28 | uint32_t renderFrames; 29 | uint32_t renderFourcc; 30 | std::string outputFile; 31 | bool useCAPI; 32 | uint32_t temporalLayer; 33 | uint32_t spacialLayer; 34 | uint32_t qualityLayer; 35 | 36 | //if set this flag to true, AVC decoder will output the ready frames ASAP. 37 | bool enableLowLatency; 38 | } StreamParameter; 39 | 40 | bool processCmdLine(int argc, char** argv, DecodeParameter* parameters); 41 | 42 | bool possibleWait(const char* mimeType, const DecodeParameter* parameters); 43 | 44 | #endif //decodehelp_h 45 | -------------------------------------------------------------------------------- /tests/decodeinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef decodeinput_h 17 | #define decodeinput_h 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using std::string; 25 | class DecodeInput { 26 | public: 27 | DecodeInput(); 28 | virtual ~DecodeInput() {} 29 | static DecodeInput * create(const char* fileName); 30 | virtual bool isEOS() = 0; 31 | virtual const char * getMimeType() = 0; 32 | virtual bool getNextDecodeUnit(VideoDecodeBuffer &inputBuffer) = 0; 33 | virtual const string& getCodecData() = 0; 34 | virtual uint16_t getWidth() {return m_width;} 35 | virtual uint16_t getHeight() {return m_height;} 36 | 37 | protected: 38 | virtual bool initInput(const char* fileName) = 0; 39 | virtual void setResolution(const uint16_t width, const uint16_t height); 40 | uint16_t m_width; 41 | uint16_t m_height; 42 | 43 | }; 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /tests/decodeinputavformat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include "decodeinputavformat.h" 21 | #include "common/common_def.h" 22 | #include "common/log.h" 23 | #include 24 | 25 | #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 39, 100) 26 | #define av_packet_unref av_free_packet 27 | #endif 28 | 29 | DecodeInputAvFormat::DecodeInputAvFormat() 30 | :m_format(NULL),m_videoId(-1), m_codecId(AV_CODEC_ID_NONE), m_isEos(true) 31 | { 32 | #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100) 33 | av_register_all(); 34 | #endif 35 | 36 | av_init_packet(&m_packet); 37 | } 38 | 39 | bool DecodeInputAvFormat::initInput(const char* fileName) 40 | { 41 | uint16_t width = 0, height = 0; 42 | int ret = avformat_open_input(&m_format, fileName, NULL, NULL); 43 | if (ret) 44 | goto error; 45 | uint32_t i; 46 | for (i = 0; i < m_format->nb_streams; ++i) { 47 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 33, 100) 48 | AVCodecParameters* codec = m_format->streams[i]->codecpar; 49 | #else 50 | AVCodecContext* codec = m_format->streams[i]->codec; 51 | #endif 52 | //VP9: width and height of the IVF header,VP8: width and height is zero 53 | if (AVMEDIA_TYPE_VIDEO == codec->codec_type) { 54 | width = codec->width; 55 | height = codec->height; 56 | break; 57 | } 58 | } 59 | 60 | ret = avformat_find_stream_info(m_format, NULL); 61 | if (ret < 0) 62 | goto error; 63 | for (i = 0; i < m_format->nb_streams; i++) 64 | { 65 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 33, 100) 66 | AVCodecParameters* codec = m_format->streams[i]->codecpar; 67 | #else 68 | AVCodecContext* codec = m_format->streams[i]->codec; 69 | #endif 70 | if (AVMEDIA_TYPE_VIDEO == codec->codec_type) { 71 | m_codecId = codec->codec_id; 72 | if (codec->extradata && codec->extradata_size) 73 | m_codecData.append((char*)codec->extradata, codec->extradata_size); 74 | m_videoId = i; 75 | //VP9: display_width and display_height of the first frame 76 | if (codec->width > width) 77 | width = codec->width; 78 | if (codec->height > height) 79 | height = codec->height; 80 | setResolution(width, height); 81 | break; 82 | } 83 | } 84 | if (i == m_format->nb_streams) { 85 | ERROR("no video stream"); 86 | goto error; 87 | } 88 | m_isEos = false; 89 | return true; 90 | error: 91 | if (m_format) 92 | avformat_close_input(&m_format); 93 | return false; 94 | 95 | } 96 | 97 | struct MimeEntry 98 | { 99 | AVCodecID id; 100 | const char* mime; 101 | }; 102 | 103 | static const MimeEntry MimeEntrys[] = { 104 | AV_CODEC_ID_MPEG2VIDEO, YAMI_MIME_MPEG2, 105 | AV_CODEC_ID_VP8, YAMI_MIME_VP8, 106 | 107 | #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 40, 0) 108 | AV_CODEC_ID_VP9, YAMI_MIME_VP9, 109 | #endif 110 | 111 | AV_CODEC_ID_H264, YAMI_MIME_H264, 112 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 39, 100) 113 | AV_CODEC_ID_H265, YAMI_MIME_H265, 114 | #endif 115 | AV_CODEC_ID_WMV3, YAMI_MIME_VC1, 116 | AV_CODEC_ID_VC1, YAMI_MIME_VC1 117 | }; 118 | 119 | const char * DecodeInputAvFormat::getMimeType() 120 | { 121 | for (size_t i = 0; i < N_ELEMENTS(MimeEntrys); i++) { 122 | if (MimeEntrys[i].id == m_codecId) 123 | return MimeEntrys[i].mime; 124 | } 125 | return "unknow"; 126 | } 127 | 128 | bool DecodeInputAvFormat::getNextDecodeUnit(VideoDecodeBuffer &inputBuffer) 129 | { 130 | if (!m_format || m_isEos) 131 | return false; 132 | int ret; 133 | while (1) { 134 | //free old packet 135 | av_packet_unref(&m_packet); 136 | 137 | ret = av_read_frame(m_format, &m_packet); 138 | if (ret) { 139 | m_isEos = true; 140 | return false; 141 | } 142 | if (m_packet.stream_index == m_videoId) { 143 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 144 | inputBuffer.data = m_packet.data; 145 | inputBuffer.size = m_packet.size; 146 | inputBuffer.timeStamp = m_packet.dts; 147 | inputBuffer.flag = VIDEO_DECODE_BUFFER_FLAG_FRAME_END; 148 | return true; 149 | } 150 | } 151 | return false; 152 | } 153 | 154 | const string& DecodeInputAvFormat::getCodecData() 155 | { 156 | return m_codecData; 157 | } 158 | 159 | DecodeInputAvFormat::~DecodeInputAvFormat() 160 | { 161 | if (m_format) { 162 | av_packet_unref(&m_packet); 163 | avformat_close_input(&m_format); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /tests/decodeinputavformat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef decodeinputavformat_h 18 | #define decodeinputavformat_h 19 | 20 | #include "decodeinput.h" 21 | extern "C" { 22 | #include 23 | #include 24 | #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(54, 51, 100) 25 | typedef CodecID AVCodecID; 26 | #define AV_CODEC_ID_NONE CODEC_ID_NONE 27 | #define AV_CODEC_ID_VP8 CODEC_ID_VP8 28 | #define AV_CODEC_ID_H264 CODEC_ID_H264 29 | #define AV_CODEC_ID_WMV3 CODEC_ID_WMV3 30 | #define AV_CODEC_ID_VC1 CODEC_ID_VC1 31 | #endif 32 | } 33 | 34 | class DecodeInputAvFormat : public DecodeInput 35 | { 36 | public: 37 | DecodeInputAvFormat(); 38 | virtual ~DecodeInputAvFormat(); 39 | virtual bool isEOS() { return m_isEos; } 40 | virtual const char * getMimeType(); 41 | virtual bool getNextDecodeUnit(VideoDecodeBuffer &inputBuffer); 42 | virtual const string& getCodecData(); 43 | 44 | protected: 45 | virtual bool initInput(const char* fileName); 46 | private: 47 | AVFormatContext* m_format; 48 | int m_videoId; 49 | AVCodecID m_codecId; 50 | AVPacket m_packet; 51 | bool m_isEos; 52 | string m_codecData; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /tests/decodeoutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef decodeoutput_h 18 | #define decodeoutput_h 19 | 20 | #include "vppinputoutput.h" 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | class DecodeOutput 27 | { 28 | public: 29 | static DecodeOutput* create(int renderMode, uint32_t fourcc, const char* inputFile, const char* outputFile); 30 | virtual bool output(const SharedPtr& frame) = 0; 31 | SharedPtr nativeDisplay(); 32 | virtual ~DecodeOutput() {} 33 | protected: 34 | virtual bool setVideoSize(uint32_t with, uint32_t height); 35 | 36 | virtual bool init(); 37 | 38 | uint32_t m_width; 39 | uint32_t m_height; 40 | SharedPtr m_vaDisplay; 41 | SharedPtr m_nativeDisplay; 42 | }; 43 | 44 | #endif //decodeoutput_h 45 | -------------------------------------------------------------------------------- /tests/egl/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc gles2_help.c simple-gles2.c -g -o simple-gles2 `pkg-config --cflags --libs x11 egl glesv2 gl` -DUSE_INTERNAL_LOG 3 | clean: 4 | rm -f simple-gl 5 | -------------------------------------------------------------------------------- /tests/egl/gles2_help.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gles2_help.h - utility to set up gles2 drawing context 3 | * 4 | * Copyright (C) 2014 Intel Corporation 5 | * Author: Zhao, Halley 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301 USA 21 | */ 22 | #ifndef __GLES2_HELP_H__ 23 | #define __GLES2_HELP_H__ 24 | 25 | #if __ENABLE_X11__ 26 | #include 27 | #endif 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "egl/egl_util.h" 34 | 35 | typedef struct { 36 | EGLDisplay display; 37 | EGLConfig config; 38 | EGLContext context; 39 | EGLSurface surface; 40 | } EGLContext_t; 41 | 42 | typedef struct { 43 | GLuint vertexShader; 44 | GLuint fragShader; 45 | GLuint program; 46 | GLint attrPosition; 47 | GLint attrTexCoord; 48 | GLint uniformTex[3]; 49 | int texCount; 50 | } GLProgram; 51 | 52 | typedef struct { 53 | EGLContext_t eglContext; 54 | GLProgram *glProgram; 55 | } EGLContextType; 56 | 57 | #ifdef __cplusplus 58 | extern "C" { 59 | #endif /* __cplusplus */ 60 | 61 | EGLContextType* eglInit(Display *x11Display, XID window, uint32_t fourcc, int isExternalTexture); 62 | void eglRelease(EGLContextType *context); 63 | GLuint createTextureFromPixmap(EGLContextType *context, XID pixmap); 64 | int drawTextures(EGLContextType *context, GLenum target, GLuint *textureIds, int texCount); 65 | void imageTargetTexture2D(EGLenum, EGLImageKHR); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif /* __cplusplus */ 70 | #endif /* __GLES2_HELP_H__ */ 71 | -------------------------------------------------------------------------------- /tests/egl/simple-gles2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * simple-gles2.c - simple example to draw texture with gles v2 3 | * 4 | * Copyright (C) 2013-2014 Intel Corporation 5 | * Author: Zhao, Halley 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include "gles2_help.h" 24 | #include 25 | #include 26 | #include 27 | #include "EGL/eglext.h" 28 | 29 | #define ERROR printf 30 | #define INFO printf 31 | #define DEBUG printf 32 | #define EGL_CHECK_RESULT_RET(result, promptStr, ret) do { \ 33 | if (result != EGL_TRUE) { \ 34 | ERROR("%s failed", promptStr); \ 35 | return ret; \ 36 | } \ 37 | }while(0) 38 | #define CHECK_HANDLE_RET(handle, invalid, promptStr, ret) do { \ 39 | if (handle == invalid) { \ 40 | ERROR("%s failed", promptStr); \ 41 | return ret; \ 42 | } \ 43 | } while(0) 44 | 45 | static GLuint 46 | createTestTexture( ) 47 | { 48 | GLuint textureId; 49 | // 2x2 Image, 4 bytes per pixel (R, G, B, A) 50 | GLubyte pixels[4 * 4] = 51 | { 52 | 255, 0, 0, 255, // Red 53 | 0, 255, 0, 255, // Green 54 | 0, 0, 255, 255, // Blue 55 | 255, 255, 255, 255, // White 56 | }; 57 | 58 | glGenTextures(1, &textureId ); 59 | glBindTexture(GL_TEXTURE_2D, textureId); 60 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 61 | 62 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 63 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 64 | return textureId; 65 | } 66 | 67 | static XID 68 | createPixmap(Display *x11Display, Window win ) 69 | { 70 | GC gr_context1, gr_context2; 71 | XGCValues gr_values; 72 | int screen; 73 | int i, j; 74 | 75 | screen = DefaultScreen(x11Display); 76 | XID pixmap = XCreatePixmap(x11Display, RootWindow(x11Display, screen), 256, 256, 24); 77 | 78 | gr_values.function = GXcopy; 79 | gr_values.plane_mask = AllPlanes; 80 | gr_values.foreground = BlackPixel(x11Display,screen); 81 | gr_values.background = WhitePixel(x11Display,screen); 82 | gr_context1=XCreateGC(x11Display,win, 83 | GCFunction | GCPlaneMask | GCForeground | GCBackground, 84 | &gr_values); 85 | 86 | gr_values.function = GXxor; 87 | gr_values.foreground = WhitePixel(x11Display,screen); 88 | gr_values.background = BlackPixel(x11Display,screen); 89 | gr_context2=XCreateGC(x11Display,win, 90 | GCFunction | GCPlaneMask | GCForeground | GCBackground, 91 | &gr_values); 92 | for (i=0; i<16; i++) 93 | for (j=0; j<16; j++) { 94 | if ((i+j)%2) 95 | XFillRectangle(x11Display, pixmap, gr_context1, i*16, j*16, 16, 16); 96 | else 97 | XFillRectangle(x11Display, pixmap, gr_context2, i*16, j*16, 16, 16); 98 | } 99 | 100 | return pixmap; 101 | } 102 | 103 | int main() { 104 | EGLContextType *context = NULL; 105 | // X display and window 106 | Display * x11Display = XOpenDisplay(NULL); 107 | CHECK_HANDLE_RET(x11Display, NULL, "XOpenDisplay", -1); 108 | Window x11RootWindow = DefaultRootWindow(x11Display); 109 | 110 | // may remove the attrib 111 | XSetWindowAttributes x11WindowAttrib; 112 | x11WindowAttrib.event_mask = ExposureMask | KeyPressMask; 113 | 114 | // create with video size, simplify it 115 | Window x11Window = XCreateWindow(x11Display, x11RootWindow, 116 | 0, 0, 800, 600, 0, CopyFromParent, InputOutput, 117 | CopyFromParent, CWEventMask, &x11WindowAttrib); 118 | XMapWindow(x11Display, x11Window); 119 | XSync(x11Display, 0); 120 | 121 | context = eglInit(x11Display, x11Window, 0, 0); 122 | // GLuint textureId = createTestTexture(); 123 | XID pixmap = createPixmap(x11Display, x11Window); 124 | GLuint textureId = createTextureFromPixmap(context, pixmap); 125 | drawTextures(context, &textureId, 1); 126 | 127 | EGLBoolean running = EGL_TRUE; 128 | while (running) { 129 | XEvent x_event; 130 | XNextEvent(x11Display, &x_event); 131 | switch (x_event.type) { 132 | case Expose: 133 | glClear(GL_COLOR_BUFFER_BIT 134 | | GL_DEPTH_BUFFER_BIT 135 | ); 136 | drawTextures(context, &textureId, 1); 137 | break; 138 | case KeyPress: 139 | running = EGL_FALSE; 140 | break; 141 | default: 142 | break; 143 | } 144 | } 145 | 146 | XUnmapWindow(x11Display, x11Window); 147 | XDestroyWindow(x11Display, x11Window); 148 | XCloseDisplay(x11Display); 149 | INFO("exit successfully"); 150 | return 0; 151 | } 152 | 153 | 154 | -------------------------------------------------------------------------------- /tests/encode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #define __STDC_FORMAT_MACROS 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #if __ENABLE_X11__ 28 | #include 29 | #endif 30 | #include "common/log.h" 31 | #include 32 | #include "encodeinput.h" 33 | #include "encodehelp.h" 34 | 35 | using namespace YamiMediaCodec; 36 | 37 | int main(int argc, char** argv) 38 | { 39 | IVideoEncoder *encoder = NULL; 40 | uint32_t maxOutSize = 0; 41 | EncodeInput* input; 42 | EncodeOutput* output; 43 | Encode_Status status; 44 | VideoFrameRawData inputBuffer; 45 | VideoEncOutputBuffer outputBuffer; 46 | int encodeFrameCount = 0; 47 | 48 | memset(&outputBuffer, 0, sizeof(VideoEncOutputBuffer)); 49 | if (!process_cmdline(argc, argv)) 50 | return -1; 51 | 52 | DEBUG("inputFourcc: %.4s codec is %s", (char*)(&(inputFourcc)), codec); 53 | input = EncodeInput::create(inputFileName, inputFourcc, videoWidth, videoHeight); 54 | if (!input) { 55 | fprintf (stderr, "fail to init input stream\n"); 56 | return -1; 57 | } 58 | 59 | videoWidth = input->getWidth(); 60 | videoHeight = input->getHeight(); 61 | if (YAMI_FOURCC_P010 == input->getFourcc()) 62 | bitDepth = 10; 63 | 64 | output = EncodeOutput::create(outputFileName, videoWidth, videoHeight, fps, codec); 65 | if (!output) { 66 | fprintf (stderr, "fail to init output stream\n"); 67 | delete input; 68 | return -1; 69 | } 70 | 71 | encoder = createVideoEncoder(output->getMimeType()); 72 | assert(encoder != NULL); 73 | 74 | NativeDisplay nativeDisplay; 75 | nativeDisplay.type = NATIVE_DISPLAY_DRM; 76 | nativeDisplay.handle = -1; 77 | encoder->setNativeDisplay(&nativeDisplay); 78 | 79 | //configure encoding parameters 80 | VideoParamsCommon encVideoParams; 81 | encVideoParams.size = sizeof(VideoParamsCommon); 82 | encoder->getParameters(VideoParamsTypeCommon, &encVideoParams); 83 | setEncoderParameters(&encVideoParams); 84 | encVideoParams.size = sizeof(VideoParamsCommon); 85 | encoder->setParameters(VideoParamsTypeCommon, &encVideoParams); 86 | 87 | VideoParamsHRD encVideoParamsHRD; 88 | encVideoParamsHRD.size = sizeof(VideoParamsHRD); 89 | encoder->getParameters(VideoParamsTypeHRD, &encVideoParamsHRD); 90 | setEncoderParameterHRD(&encVideoParamsHRD); 91 | encVideoParamsHRD.size = sizeof(VideoParamsHRD); 92 | encoder->setParameters(VideoParamsTypeHRD, &encVideoParamsHRD); 93 | 94 | if (qualityLevel != VIDEO_PARAMS_QUALITYLEVEL_NONE) { 95 | VideoParamsQualityLevel encVideoParamsQualityLevel; 96 | encVideoParamsQualityLevel.size = sizeof(VideoParamsQualityLevel); 97 | encoder->getParameters(VideoParamsTypeQualityLevel, &encVideoParamsQualityLevel); 98 | encVideoParamsQualityLevel.level = qualityLevel; 99 | encVideoParamsQualityLevel.size = sizeof(VideoParamsQualityLevel); 100 | encoder->setParameters(VideoParamsTypeQualityLevel, &encVideoParamsQualityLevel); 101 | } 102 | 103 | // configure AVC encoding parameters 104 | VideoParamsAVC encVideoParamsAVC; 105 | if (!strcmp(output->getMimeType(), YAMI_MIME_H264)) { 106 | encVideoParamsAVC.size = sizeof(VideoParamsAVC); 107 | encoder->getParameters(VideoParamsTypeAVC, &encVideoParamsAVC); 108 | encVideoParamsAVC.idrInterval = idrInterval; 109 | encVideoParamsAVC.size = sizeof(VideoParamsAVC); 110 | encoder->setParameters(VideoParamsTypeAVC, &encVideoParamsAVC); 111 | } 112 | 113 | // configure VP9 encoding parameters 114 | VideoParamsVP9 encVideoParamsVP9; 115 | if (!strcmp(output->getMimeType(), YAMI_MIME_VP9)) { 116 | encoder->getParameters(VideoParamsTypeVP9, &encVideoParamsVP9); 117 | encVideoParamsVP9.referenceMode = referenceMode; 118 | encoder->setParameters(VideoParamsTypeVP9, &encVideoParamsVP9); 119 | } 120 | 121 | VideoConfigAVCStreamFormat streamFormat; 122 | streamFormat.size = sizeof(VideoConfigAVCStreamFormat); 123 | streamFormat.streamFormat = AVC_STREAM_FORMAT_ANNEXB; 124 | encoder->setParameters(VideoConfigTypeAVCStreamFormat, &streamFormat); 125 | 126 | status = encoder->start(); 127 | assert(status == ENCODE_SUCCESS); 128 | 129 | //init output buffer 130 | encoder->getMaxOutSize(&maxOutSize); 131 | 132 | #ifdef __BUILD_GET_MV__ 133 | uint32_t size; 134 | VideoEncMVBuffer MVBuffer; 135 | MVFp = fopen("feimv.bin","wb"); 136 | encoder->getMVBufferSize(&size); 137 | if (!createMVBuffer(&MVBuffer, size)) { 138 | fprintf (stderr, "fail to create MV buffer\n"); 139 | return -1; 140 | } 141 | #endif 142 | if (!createOutputBuffer(&outputBuffer, maxOutSize)) { 143 | fprintf (stderr, "fail to create output\n"); 144 | delete input; 145 | delete output; 146 | return -1; 147 | } 148 | uint64_t i = 0; 149 | while (!input->isEOS()) 150 | { 151 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 152 | if (input->getOneFrameInput(inputBuffer)) { 153 | inputBuffer.timeStamp = i++; 154 | status = encoder->encode(&inputBuffer); 155 | ASSERT(status == ENCODE_SUCCESS); 156 | input->recycleOneFrameInput(inputBuffer); 157 | } 158 | else 159 | break; 160 | 161 | //get the output buffer 162 | do { 163 | #ifndef __BUILD_GET_MV__ 164 | status = encoder->getOutput(&outputBuffer, false); 165 | #else 166 | status = encoder->getOutput(&outputBuffer, &MVBuffer, false); 167 | #endif 168 | if (status == ENCODE_SUCCESS 169 | && output->write(outputBuffer.data, outputBuffer.dataSize)) { 170 | DEBUG("timeStamp(PTS) : " 171 | "%" PRIu64, 172 | outputBuffer.timeStamp); 173 | DEBUG("output data size %d", outputBuffer.dataSize); 174 | } 175 | #ifdef __BUILD_GET_MV__ 176 | if (status == ENCODE_SUCCESS) { 177 | fwrite(MVBuffer.data, MVBuffer.bufferSize, 1, MVFp); 178 | } 179 | #endif 180 | if (status == ENCODE_BUFFER_TOO_SMALL) { 181 | maxOutSize = (maxOutSize * 3) / 2; 182 | if (!createOutputBuffer(&outputBuffer, maxOutSize)) { 183 | fprintf(stderr, "fail to create output\n"); 184 | goto error1; 185 | } 186 | } 187 | } while (status != ENCODE_BUFFER_NO_MORE); 188 | 189 | encodeFrameCount++; 190 | 191 | if (frameCount && encodeFrameCount >= frameCount) 192 | break; 193 | } 194 | 195 | // drain the output buffer 196 | encoder->flush(); 197 | do { 198 | #ifndef __BUILD_GET_MV__ 199 | status = encoder->getOutput(&outputBuffer, true); 200 | #else 201 | status = encoder->getOutput(&outputBuffer, &MVBuffer, true); 202 | #endif 203 | if (status == ENCODE_SUCCESS 204 | && output->write(outputBuffer.data, outputBuffer.dataSize)) { 205 | DEBUG("timeStamp(PTS) : " "%" PRIu64 "\n", outputBuffer.timeStamp); 206 | } 207 | #ifdef __BUILD_GET_MV__ 208 | if (status == ENCODE_SUCCESS) { 209 | fwrite(MVBuffer.data, MVBuffer.bufferSize, 1, MVFp); 210 | } 211 | #endif 212 | if (status == ENCODE_BUFFER_TOO_SMALL) { 213 | maxOutSize = (maxOutSize * 3) / 2; 214 | if (!createOutputBuffer(&outputBuffer, maxOutSize)) { 215 | fprintf(stderr, "fail to create output\n"); 216 | goto error1; 217 | } 218 | } 219 | } while (status != ENCODE_BUFFER_NO_MORE); 220 | 221 | error1: 222 | encoder->stop(); 223 | releaseVideoEncoder(encoder); 224 | free(outputBuffer.data); 225 | delete output; 226 | delete input; 227 | #ifdef __BUILD_GET_MV__ 228 | free(MVBuffer.data); 229 | fclose(MVFp); 230 | #endif 231 | fprintf(stderr, "encode done\n"); 232 | return 0; 233 | } 234 | -------------------------------------------------------------------------------- /tests/encodeInputCapi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | #include 22 | #include "encodeInputCapi.h" 23 | #include "encodeinput.h" 24 | 25 | using namespace YamiMediaCodec; 26 | 27 | EncodeInputHandler createEncodeInput(const char * inputFileName, uint32_t fourcc, int width, int height) 28 | { 29 | return EncodeInput::create(inputFileName, fourcc, width, height); 30 | } 31 | 32 | EncodeOutputHandler createEncodeOutput(const char* outputFileName, int width, int height, int fps) 33 | { 34 | return EncodeOutput::create(outputFileName, width, height, fps); 35 | } 36 | 37 | bool encodeInputIsEOS(EncodeInputHandler input) 38 | { 39 | if(input) 40 | return ((EncodeInput*)input)->isEOS(); 41 | else 42 | return false; 43 | } 44 | 45 | const char * getOutputMimeType(EncodeOutputHandler output) 46 | { 47 | if(output) 48 | return ((EncodeOutput*)output)->getMimeType(); 49 | else 50 | return NULL; 51 | } 52 | 53 | bool initInput(EncodeInputHandler input, const char* inputFileName, uint32_t fourcc, const int width, const int height) 54 | { 55 | return ((EncodeInput*)input)->init(inputFileName, fourcc, width, height); 56 | } 57 | 58 | int getInputWidth(EncodeInputHandler input) 59 | { 60 | if (input) 61 | return ((EncodeInput*)input)->getWidth(); 62 | return 0; 63 | } 64 | 65 | int getInputHeight(EncodeInputHandler input) 66 | { 67 | if (input) 68 | return ((EncodeInput*)input)->getHeight(); 69 | return 0; 70 | } 71 | 72 | bool getOneFrameInput(EncodeInputHandler input, VideoFrameRawData *inputBuffer) 73 | { 74 | if(input) 75 | return ((EncodeInput*)input)->getOneFrameInput(*inputBuffer); 76 | else 77 | return false; 78 | } 79 | 80 | bool recycleOneFrameInput(EncodeInputHandler input, VideoFrameRawData *inputBuffer) 81 | { 82 | if(input) 83 | return ((EncodeInput*)input)->recycleOneFrameInput(*inputBuffer); 84 | else 85 | return false; 86 | } 87 | 88 | bool writeOutput(EncodeOutputHandler output, void* data, int size) 89 | { 90 | if(output) 91 | return ((EncodeOutput*)output)->write(data, size); 92 | else 93 | return false; 94 | } 95 | 96 | void releaseEncodeInput(EncodeInputHandler input) 97 | { 98 | if(input) 99 | delete ((EncodeInput*)input); 100 | } 101 | 102 | void releaseEncodeOutput(EncodeOutputHandler output) 103 | { 104 | if(output) 105 | delete ((EncodeOutput*)output); 106 | } 107 | 108 | bool createOutputBuffer(VideoEncOutputBuffer* outputBuffer, int maxOutSize) 109 | { 110 | outputBuffer->data = static_cast(malloc(maxOutSize)); 111 | if (!outputBuffer->data) 112 | return false; 113 | outputBuffer->bufferSize = maxOutSize; 114 | outputBuffer->format = OUTPUT_EVERYTHING; 115 | return true; 116 | } 117 | -------------------------------------------------------------------------------- /tests/encodeInputCapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef void* EncodeInputHandler; 27 | typedef void* EncodeOutputHandler; 28 | 29 | EncodeInputHandler createEncodeInput(const char * inputFileName, uint32_t fourcc, int width, int height); 30 | 31 | EncodeOutputHandler createEncodeOutput(const char* outputFileName, int width, int height, int fps = 30); 32 | 33 | bool encodeInputIsEOS(EncodeInputHandler input); 34 | 35 | const char * getOutputMimeType(EncodeOutputHandler output); 36 | 37 | bool initInput(EncodeInputHandler input, const char* inputFileName, uint32_t fourcc, const int width, const int height); 38 | 39 | int getInputWidth(EncodeInputHandler input); 40 | 41 | int getInputHeight(EncodeInputHandler input); 42 | 43 | bool getOneFrameInput(EncodeInputHandler input, VideoFrameRawData *inputBuffer); 44 | 45 | bool recycleOneFrameInput(EncodeInputHandler input, VideoFrameRawData *inputBuffer); 46 | 47 | bool writeOutput(EncodeOutputHandler output, void* data, int size); 48 | 49 | void releaseEncodeInput(EncodeInputHandler input); 50 | 51 | void releaseEncodeOutput(EncodeOutputHandler output); 52 | 53 | bool createOutputBuffer(VideoEncOutputBuffer* outputBuffer, int maxOutSize); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /tests/encodeInputDecoder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include "encodeInputDecoder.h" 22 | #include "common/log.h" 23 | #include "common/VaapiUtils.h" 24 | #include "assert.h" 25 | 26 | EncodeInputDecoder::EncodeInputDecoder(DecodeInput* input) 27 | : m_input(input) 28 | , m_decoder(NULL) 29 | , m_isEOS(false) 30 | , m_id(0) 31 | { 32 | } 33 | EncodeInputDecoder::~EncodeInputDecoder() 34 | { 35 | if (m_decoder) { 36 | m_decoder->stop(); 37 | releaseVideoDecoder(m_decoder); 38 | } 39 | delete m_input; 40 | } 41 | 42 | bool EncodeInputDecoder::init(const char* /*inputFileName*/, uint32_t /*fourcc*/, int /* width */, int /*height*/) 43 | { 44 | assert(m_input && "invalid input"); 45 | m_decoder = createVideoDecoder(m_input->getMimeType()); 46 | if (!m_decoder) 47 | return false; 48 | m_fourcc = VA_FOURCC_NV12; 49 | 50 | VideoConfigBuffer configBuffer; 51 | memset(&configBuffer,0,sizeof(VideoConfigBuffer)); 52 | configBuffer.profile = VAProfileNone; 53 | Decode_Status status = m_decoder->start(&configBuffer); 54 | assert(status == DECODE_SUCCESS); 55 | 56 | while (!m_width || !m_height) { 57 | if (!decodeOneFrame()) 58 | return false; 59 | } 60 | return true; 61 | } 62 | 63 | bool EncodeInputDecoder::decodeOneFrame() 64 | { 65 | if (!m_input || !m_decoder) 66 | return false; 67 | 68 | VideoDecodeBuffer inputBuffer; 69 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 70 | 71 | if (!m_input->getNextDecodeUnit(inputBuffer)) { 72 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 73 | //flush decoder 74 | m_decoder->decode(&inputBuffer); 75 | m_isEOS = true; 76 | return true; 77 | } 78 | Decode_Status status = m_decoder->decode(&inputBuffer); 79 | if (status == DECODE_FORMAT_CHANGE) { 80 | const VideoFormatInfo *formatInfo = m_decoder->getFormatInfo(); 81 | m_width = formatInfo->width; 82 | m_height = formatInfo->height; 83 | //send again 84 | status = m_decoder->decode(&inputBuffer);; 85 | } 86 | if (status != DECODE_SUCCESS) { 87 | ERROR("decode failed status = %d", status); 88 | return false; 89 | } 90 | return true; 91 | } 92 | 93 | class MyRawImage { 94 | public: 95 | static SharedPtr create(VADisplay display, const SharedPtr& frame, VideoFrameRawData& inputBuffer) 96 | { 97 | SharedPtr image; 98 | if (!frame) 99 | return image; 100 | image.reset(new MyRawImage(display, frame)); 101 | if (!image->init(inputBuffer)) { 102 | image.reset(); 103 | } 104 | return image; 105 | } 106 | ~MyRawImage() 107 | { 108 | if (m_frame) { 109 | unmapImage(m_display, m_image); 110 | } 111 | } 112 | 113 | private: 114 | MyRawImage(VADisplay display, const SharedPtr& frame) 115 | : m_display(display) 116 | , m_frame(frame) 117 | { 118 | } 119 | 120 | VAImage m_image; 121 | VADisplay m_display; 122 | SharedPtr m_frame; 123 | bool init(VideoFrameRawData& inputBuffer) 124 | { 125 | uint8_t* p = mapSurfaceToImage(m_display, m_frame->surface, m_image); 126 | if (!p) { 127 | m_frame.reset(); 128 | return false; 129 | } 130 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 131 | inputBuffer.memoryType = VIDEO_DATA_MEMORY_TYPE_RAW_POINTER; 132 | inputBuffer.fourcc = m_frame->fourcc; 133 | inputBuffer.handle = (intptr_t)p; 134 | memcpy(inputBuffer.pitch, m_image.pitches, sizeof(inputBuffer.pitch)); 135 | memcpy(inputBuffer.offset, m_image.offsets, sizeof(inputBuffer.offset)); 136 | inputBuffer.timeStamp = m_frame->timeStamp; 137 | inputBuffer.flags = m_frame->flags; 138 | inputBuffer.width = m_frame->crop.width; 139 | inputBuffer.height = m_frame->crop.height; 140 | return true; 141 | } 142 | DISALLOW_COPY_AND_ASSIGN(MyRawImage) 143 | }; 144 | 145 | bool EncodeInputDecoder::getOneFrameInput(VideoFrameRawData &inputBuffer) 146 | { 147 | if (!m_decoder) 148 | return false; 149 | if (m_input->isEOS()) { 150 | m_isEOS = true; 151 | } 152 | SharedPtr frame; 153 | do { 154 | frame = m_decoder->getOutput(); 155 | if (frame) { 156 | SharedPtr image = MyRawImage::create(m_decoder->getDisplayID(), frame, inputBuffer); 157 | if (!image) 158 | return false; 159 | inputBuffer.internalID = m_id; 160 | m_images[m_id++] = image; 161 | } 162 | else { 163 | if (m_isEOS) 164 | return false; 165 | if (!decodeOneFrame()) 166 | return false; 167 | } 168 | } while (!frame); 169 | return true; 170 | } 171 | 172 | bool EncodeInputDecoder::recycleOneFrameInput(VideoFrameRawData &inputBuffer) 173 | { 174 | if (!m_decoder) 175 | return false; 176 | m_images.erase(inputBuffer.internalID); 177 | return true; 178 | } 179 | 180 | bool EncodeInputDecoder::isEOS() 181 | { 182 | return m_isEOS; 183 | } 184 | -------------------------------------------------------------------------------- /tests/encodeInputDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef encodeInputDecoder_h 17 | #define encodeInputDecoder_h 18 | 19 | #include "decodeinput.h" 20 | #include "encodeinput.h" 21 | 22 | #include 23 | #include 24 | 25 | using namespace YamiMediaCodec; 26 | 27 | class MyRawImage; 28 | class EncodeInputDecoder : public EncodeInput { 29 | public: 30 | EncodeInputDecoder(DecodeInput* input); 31 | ~EncodeInputDecoder(); 32 | virtual bool init(const char* inputFileName, uint32_t fourcc, int width, int height); 33 | virtual bool getOneFrameInput(VideoFrameRawData &inputBuffer); 34 | virtual bool recycleOneFrameInput(VideoFrameRawData &inputBuffer); 35 | virtual bool isEOS(); 36 | private: 37 | bool decodeOneFrame(); 38 | DecodeInput* m_input; 39 | IVideoDecoder* m_decoder; 40 | bool m_isEOS; 41 | 42 | typedef std::map > ImageMap; 43 | 44 | ImageMap m_images; 45 | uint32_t m_id; 46 | DISALLOW_COPY_AND_ASSIGN(EncodeInputDecoder); 47 | }; 48 | #endif 49 | -------------------------------------------------------------------------------- /tests/encodeInputSurface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "common/log.h" 28 | #include "encodeinput.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define GET_ANATIVEWINDOW(w) w.get() 39 | #define CAST_ANATIVEWINDOW(w) (w) 40 | 41 | #define CHECK_RET(ret, str) \ 42 | do { \ 43 | if (ret) { \ 44 | ERROR("%s failed: (%d)\n", str, ret); \ 45 | return false; \ 46 | } \ 47 | } while (0) 48 | 49 | bool EncodeInputSurface::init(const char* inputFileName, uint32_t fourcc, int width, int height) 50 | { 51 | m_width = width; 52 | m_height = height; 53 | 54 | int surfaceWidth = width; 55 | int surfaceHeight = height; 56 | static sp client = new SurfaceComposerClient(); 57 | //create surface 58 | static sp surfaceCtl = client->createSurface(String8("testsurface"), 59 | surfaceWidth, surfaceHeight, HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL, 0); 60 | DEBUG("create surface with size %dx%d, format: 0x%x", surfaceWidth, surfaceHeight, HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL); 61 | 62 | // configure surface 63 | SurfaceComposerClient::openGlobalTransaction(); 64 | surfaceCtl->setLayer(100000); 65 | surfaceCtl->setPosition(100, 100); 66 | surfaceCtl->setSize(surfaceWidth, surfaceHeight); 67 | SurfaceComposerClient::closeGlobalTransaction(); 68 | 69 | m_surface = surfaceCtl->getSurface(); 70 | mNativeWindow = m_surface; 71 | 72 | int bufWidth = width; 73 | int bufHeight = height; 74 | int ret; 75 | 76 | INFO("set buffers geometry %dx%d\n", width, height); 77 | ret = native_window_set_buffers_dimensions(GET_ANATIVEWINDOW(mNativeWindow), width, height); 78 | CHECK_RET(ret, "native_window_set_buffers_dimensions"); 79 | 80 | uint32_t format = HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL; 81 | INFO("set buffers format %x\n", format); 82 | ret = native_window_set_buffers_format(GET_ANATIVEWINDOW(mNativeWindow), format); 83 | CHECK_RET(ret, "native_window_set_buffers_format"); 84 | 85 | INFO("set buffer usage\n"); 86 | ret = native_window_set_usage(GET_ANATIVEWINDOW(mNativeWindow), 87 | GRALLOC_USAGE_HW_VIDEO_ENCODER | GRALLOC_USAGE_HW_TEXTURE); 88 | CHECK_RET(ret, "native_window_set_usage"); 89 | 90 | INFO("set buffer count %d\n", m_bufferCount); 91 | ret = native_window_set_buffer_count(GET_ANATIVEWINDOW(mNativeWindow), m_bufferCount); 92 | CHECK_RET(ret, "native_window_set_buffer_count"); 93 | 94 | prepareInputBuffer(); 95 | return true; 96 | } 97 | 98 | static int NV12_Generator_Planar(int width, int height, 99 | uint8_t* Y_start, int Y_pitch, uint8_t* UV_start, int UV_pitch) 100 | { 101 | static int row_shift = 0; 102 | int block_width = 8; 103 | int row = 0, col = 0; 104 | uint8_t uv_color = 0; 105 | uint8_t uv_step = 8 * 256 / height + 1; 106 | 107 | /* create Y plane data */ 108 | for (row = 0; row < height; row++) { 109 | uint8_t* Y_row = Y_start + row * Y_pitch; 110 | int xpos, ypos; 111 | 112 | ypos = (row / block_width) & 0x1; 113 | for (col = 0; col < width; col++) { 114 | xpos = ((row_shift + col) / block_width) & 0x1; 115 | if ((xpos == ypos)) 116 | Y_row[col] = 0xeb; 117 | else 118 | Y_row[col] = 0x10; 119 | } 120 | } 121 | 122 | /* create UV plane data */ 123 | for (row = 0; row < height / 2; row++) { 124 | uint8_t* UV_row = UV_start + row * UV_pitch; 125 | uv_color += uv_step; 126 | memset(UV_row, uv_color, width); 127 | } 128 | 129 | row_shift++; 130 | if (row_shift == 16) 131 | row_shift = 0; 132 | 133 | return 0; 134 | } 135 | 136 | static void fillSourceBuffer(uint8_t* data, int width, int height /* assumed pitch*/) 137 | { 138 | 139 | uint8_t *y_start, *uv_start; 140 | int y_pitch, uv_pitch; 141 | 142 | // FIXME, we don't use the real picth 143 | y_start = data; 144 | uv_start = data + width * height; 145 | y_pitch = width; 146 | uv_pitch = width; 147 | 148 | NV12_Generator_Planar(width, height, y_start, y_pitch, uv_start, uv_pitch); 149 | } 150 | 151 | bool EncodeInputSurface::prepareInputBuffer() 152 | { 153 | int i; 154 | int ret; 155 | ANativeWindowBuffer* anb = NULL; 156 | INFO("init %d input surfaces, this can take some time\n", m_bufferCount); 157 | 158 | for (i = 0; i < m_bufferCount; i++) { 159 | void* ptr = NULL; 160 | anb = NULL; 161 | ret = native_window_dequeue_buffer_and_wait(GET_ANATIVEWINDOW(mNativeWindow), &anb); 162 | if (ret != 0) { 163 | ERROR("native_window_dequeue_Buffer failed: (%d)\n", ret); 164 | return false; 165 | } 166 | 167 | sp graphicBuffer = new GraphicBuffer(anb, false); 168 | graphicBuffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN, &ptr); 169 | 170 | DEBUG("ptr: %p, m_width: %d, m_height: %d\n", ptr, m_width, m_height); 171 | fillSourceBuffer((uint8_t*)ptr, m_width, m_height); 172 | 173 | graphicBuffer->unlock(); 174 | DEBUG("%d, fille anb: %p done\n", i, anb); 175 | 176 | mBufferInfo.push(anb); 177 | } 178 | 179 | for (i = 0; i < 2; i++) { 180 | anb = mBufferInfo.front(); 181 | DEBUG("cancelBuffer: %d, and: %p\n", i, anb); 182 | ret = CAST_ANATIVEWINDOW(mNativeWindow)->cancelBuffer(GET_ANATIVEWINDOW(mNativeWindow), anb, -1); 183 | mBufferInfo.pop(); 184 | CHECK_RET(ret, "cancelBuffer"); 185 | } 186 | 187 | INFO("init input surface finished\n"); 188 | 189 | return true; 190 | } 191 | 192 | bool EncodeInputSurface::getOneFrameInput(VideoFrameRawData& inputBuffer) 193 | { 194 | ANativeWindowBuffer* anb = NULL; 195 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 196 | inputBuffer.memoryType = VIDEO_DATA_MEMORY_TYPE_ANDROID_BUFFER_HANDLE; 197 | 198 | anb = mBufferInfo.front(); 199 | mBufferInfo.pop(); 200 | DEBUG("queueBuffer anb: %p\n", anb); 201 | int ret = GET_ANATIVEWINDOW(mNativeWindow)->queueBuffer(GET_ANATIVEWINDOW(mNativeWindow), anb, -1); 202 | if (ret != 0) { 203 | ERROR("queueBuffer failed: %s (%d)", strerror(-ret), -ret); 204 | return false; 205 | } 206 | 207 | ret = native_window_dequeue_buffer_and_wait( 208 | GET_ANATIVEWINDOW(mNativeWindow), &anb); 209 | if (ret != 0) { 210 | ERROR("native_window_dequeue_Buffer failed: (%d)\n", ret); 211 | return false; 212 | } 213 | 214 | inputBuffer.handle = (intptr_t)anb->handle; 215 | DEBUG("get ANativeWindowBuffer: %p from surface to encode\n", anb); 216 | // FIXME, push it to queue after finish encoding 217 | mBufferInfo.push(anb); 218 | 219 | return true; 220 | } 221 | -------------------------------------------------------------------------------- /tests/encodecapi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "common/log.h" 27 | #include 28 | #include "encodeInputCapi.h" 29 | #include "encodehelp.h" 30 | 31 | int main(int argc, char** argv) 32 | { 33 | EncodeHandler encoder = NULL; 34 | uint32_t maxOutSize = 0; 35 | EncodeInputHandler input; 36 | EncodeOutputHandler output; 37 | Encode_Status status; 38 | VideoFrameRawData inputBuffer; 39 | VideoEncOutputBuffer outputBuffer; 40 | int encodeFrameCount = 0; 41 | 42 | if (!process_cmdline(argc, argv)) 43 | return -1; 44 | 45 | DEBUG("inputFourcc: %.4s", (char*)(&inputFourcc)); 46 | input = createEncodeInput(inputFileName, inputFourcc, videoWidth, videoHeight); 47 | 48 | if (!input) { 49 | fprintf (stderr, "fail to init input stream\n"); 50 | return -1; 51 | } 52 | 53 | videoWidth = getInputWidth(input); 54 | videoHeight = getInputHeight(input); 55 | 56 | output = createEncodeOutput(outputFileName, videoWidth, videoHeight, fps); 57 | if(!output) { 58 | fprintf(stderr, "fail to init ourput stream\n"); 59 | return -1; 60 | } 61 | 62 | encoder = createEncoder(getOutputMimeType(output)); 63 | assert(encoder != NULL); 64 | 65 | NativeDisplay nativeDisplay; 66 | nativeDisplay.type = NATIVE_DISPLAY_DRM; 67 | nativeDisplay.handle = 0; 68 | encodeSetNativeDisplay(encoder, &nativeDisplay); 69 | 70 | //configure encoding parameters 71 | VideoParamsCommon encVideoParams; 72 | encVideoParams.size = sizeof(VideoParamsCommon); 73 | encodeGetParameters(encoder, VideoParamsTypeCommon, &encVideoParams); 74 | setEncoderParameters(&encVideoParams); 75 | encVideoParams.size = sizeof(VideoParamsCommon); 76 | encodeSetParameters(encoder, VideoParamsTypeCommon, &encVideoParams); 77 | 78 | VideoConfigAVCStreamFormat streamFormat; 79 | streamFormat.size = sizeof(VideoConfigAVCStreamFormat); 80 | streamFormat.streamFormat = AVC_STREAM_FORMAT_ANNEXB; 81 | encodeSetParameters(encoder, VideoConfigTypeAVCStreamFormat, &streamFormat); 82 | 83 | status = encodeStart(encoder); 84 | assert(status == ENCODE_SUCCESS); 85 | 86 | //init output buffer 87 | encodeGetMaxOutSize(encoder, &maxOutSize); 88 | 89 | if (!createOutputBuffer(&outputBuffer, maxOutSize)) { 90 | fprintf (stderr, "fail to init input stream\n"); 91 | return -1; 92 | } 93 | 94 | while (!encodeInputIsEOS(input)) 95 | { 96 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 97 | if (getOneFrameInput(input, &inputBuffer)){ 98 | status = encodeEncodeRawData(encoder, &inputBuffer); 99 | recycleOneFrameInput(input, &inputBuffer); 100 | } 101 | else 102 | break; 103 | 104 | //get the output buffer 105 | do { 106 | status = encodeGetOutput(encoder, &outputBuffer, false); 107 | if (status == ENCODE_SUCCESS 108 | && !writeOutput(output, outputBuffer.data, outputBuffer.dataSize)) 109 | assert(0); 110 | } while (status != ENCODE_BUFFER_NO_MORE); 111 | 112 | if (frameCount && encodeFrameCount++ > frameCount) 113 | break; 114 | } 115 | 116 | // drain the output buffer 117 | do { 118 | status = encodeGetOutput(encoder, &outputBuffer, true); 119 | if (status == ENCODE_SUCCESS 120 | && !writeOutput(output, outputBuffer.data, outputBuffer.dataSize)) 121 | assert(0); 122 | } while (status != ENCODE_BUFFER_NO_MORE); 123 | 124 | encodeStop(encoder); 125 | releaseEncoder(encoder); 126 | releaseEncodeInput(input); 127 | releaseEncodeOutput(output); 128 | free(outputBuffer.data); 129 | 130 | fprintf(stderr, "encode done\n"); 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /tests/encodeinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef encodeinput_h 17 | #define encodeinput_h 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include "config.h" 21 | #endif 22 | 23 | #include 24 | #include "common/NonCopyable.h" 25 | #include 26 | #include 27 | #include 28 | 29 | //android headers change so faster, we can't catch up 30 | //so disalbe surface input temporarily, if someone needed, we will bring it back. 31 | #if 0 32 | #include 33 | #include 34 | #include 35 | #include 36 | using namespace android; 37 | #endif 38 | 39 | using namespace YamiMediaCodec; 40 | 41 | class EncodeInput; 42 | class EncodeInputFile; 43 | class EncodeInputCamera; 44 | class EncodeInput { 45 | public: 46 | static EncodeInput* create(const char* inputFileName, uint32_t fourcc, int width, int height); 47 | EncodeInput() : m_width(0), m_height(0), m_frameSize(0) {}; 48 | virtual ~EncodeInput() {}; 49 | virtual bool init(const char* inputFileName, uint32_t fourcc, int width, int height) = 0; 50 | virtual bool getOneFrameInput(VideoFrameRawData &inputBuffer) = 0; 51 | virtual bool recycleOneFrameInput(VideoFrameRawData &inputBuffer) {return true;}; 52 | virtual bool isEOS() = 0; 53 | int getWidth() { return m_width;} 54 | int getHeight() { return m_height;} 55 | uint32_t getFourcc() { return m_fourcc; } 56 | 57 | protected: 58 | uint32_t m_fourcc; 59 | uint32_t m_width; 60 | uint32_t m_height; 61 | size_t m_frameSize; 62 | }; 63 | 64 | class EncodeInputFile : public EncodeInput { 65 | public: 66 | EncodeInputFile(); 67 | ~EncodeInputFile(); 68 | virtual bool init(const char* inputFileName, uint32_t fourcc, int width, int height); 69 | virtual bool getOneFrameInput(VideoFrameRawData &inputBuffer); 70 | virtual bool isEOS() {return m_readToEOS;} 71 | 72 | protected: 73 | std::ifstream m_ifs; 74 | uint8_t *m_buffer; 75 | bool m_readToEOS; 76 | private: 77 | DISALLOW_COPY_AND_ASSIGN(EncodeInputFile); 78 | }; 79 | 80 | class EncodeInputCamera : public EncodeInput { 81 | public: 82 | enum CameraDataMode{ 83 | CAMERA_DATA_MODE_MMAP, 84 | // CAMERA_DATA_MODE_DMABUF_MMAP, 85 | // CAMERA_DATA_MODE_USRPTR, 86 | // CAMERA_DATA_MODE_DMABUF_USRPTR, 87 | }; 88 | EncodeInputCamera() :m_frameBufferCount(5), m_frameBufferSize(0), m_dataMode(CAMERA_DATA_MODE_MMAP) {}; 89 | ~EncodeInputCamera(); 90 | virtual bool init(const char* cameraPath, uint32_t fourcc, int width, int height); 91 | bool setDataMode(CameraDataMode mode = CAMERA_DATA_MODE_MMAP) {m_dataMode = mode; return true;}; 92 | 93 | virtual bool getOneFrameInput(VideoFrameRawData &inputBuffer); 94 | virtual bool recycleOneFrameInput(VideoFrameRawData &inputBuffer); 95 | virtual bool isEOS() { return false; } 96 | // void getSupportedResolution(); 97 | private: 98 | int m_fd; 99 | std::vector m_frameBuffers; 100 | uint32_t m_frameBufferCount; 101 | uint32_t m_frameBufferSize; 102 | CameraDataMode m_dataMode; 103 | 104 | bool openDevice(); 105 | bool initDevice(const char *cameraDevicePath); 106 | bool initMmap(); 107 | bool startCapture(); 108 | int32_t dequeFrame(); 109 | bool enqueFrame(int32_t index); 110 | bool stopCapture(); 111 | bool uninitDevice(); 112 | 113 | }; 114 | 115 | #if 0 116 | #define SURFACE_BUFFER_COUNT 5 117 | class EncodeInputSurface : public EncodeInput { 118 | public: 119 | EncodeInputSurface() { m_bufferCount = SURFACE_BUFFER_COUNT; } 120 | ~EncodeInputSurface(){}; 121 | virtual bool init(const char* inputFileName, uint32_t fourcc, int width, int height); 122 | virtual bool getOneFrameInput(VideoFrameRawData& inputBuffer); 123 | virtual bool isEOS() { return false; } 124 | 125 | protected: 126 | int m_bufferCount; 127 | sp m_surface; 128 | sp mNativeWindow; 129 | std::queue mBufferInfo; 130 | 131 | private: 132 | bool prepareInputBuffer(); 133 | DISALLOW_COPY_AND_ASSIGN(EncodeInputSurface); 134 | }; 135 | #endif 136 | 137 | class EncodeOutput { 138 | public: 139 | EncodeOutput(); 140 | virtual ~EncodeOutput(); 141 | static EncodeOutput* create(const char* outputFileName, int width, 142 | int height, int fps = 30, const char* codecName = NULL); 143 | virtual bool write(void* data, int size); 144 | virtual const char* getMimeType() = 0; 145 | protected: 146 | virtual bool init(const char* outputFileName, int width, int height, int fps = 30); 147 | std::ofstream m_ofs; 148 | }; 149 | 150 | class EncodeOutputH264 : public EncodeOutput 151 | { 152 | virtual const char* getMimeType(); 153 | }; 154 | 155 | class EncodeOutputVPX : public EncodeOutput { 156 | public: 157 | EncodeOutputVPX(); 158 | ~EncodeOutputVPX(); 159 | virtual const char* getMimeType() = 0; 160 | virtual bool write(void* data, int size); 161 | protected: 162 | virtual bool init(const char* outputFileName, int width, int height, int fps = 30); 163 | uint32_t getFourcc() {return m_fourcc;}; 164 | void setFourcc(uint32_t fourcc) {m_fourcc = fourcc;}; 165 | private: 166 | void getIVFFileHeader(uint8_t* header, int width, int height, int fps = 30); 167 | int m_frameCount; 168 | uint32_t m_fourcc; 169 | 170 | }; 171 | 172 | class EncodeOutputVP8 : public EncodeOutputVPX { 173 | public: 174 | EncodeOutputVP8(); 175 | virtual const char* getMimeType(); 176 | }; 177 | 178 | class EncodeOutputVP9 : public EncodeOutputVPX { 179 | public: 180 | EncodeOutputVP9(); 181 | virtual const char* getMimeType(); 182 | }; 183 | 184 | class EncodeStreamOutputJpeg : public EncodeOutput 185 | { 186 | virtual const char* getMimeType(); 187 | }; 188 | 189 | class EncodeOutputHEVC : public EncodeOutput 190 | { 191 | virtual const char* getMimeType(); 192 | }; 193 | 194 | bool createOutputBuffer(VideoEncOutputBuffer* outputBuffer, int maxOutSize); 195 | #ifdef __BUILD_GET_MV__ 196 | bool createMVBuffer(VideoEncMVBuffer* MVBuffer, int Size); 197 | #endif 198 | #endif 199 | -------------------------------------------------------------------------------- /tests/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #ifdef HAVE_OPENSSL 30 | #include 31 | #elif defined(HAVE_LIBBSD) 32 | 33 | // including bsd/md5.h produces a warning with __bounded__ attribute,+#include "md5.h" 34 | // libyami-utils chooses to ignore this particular warning by pushing the+} 35 | // current environment, ignoring attributes and then poping to restore the 36 | // environment. 37 | #pragma GCC diagnostic push 38 | #pragma GCC diagnostic ignored "-Wattributes" 39 | #include 40 | #pragma GCC diagnostic pop 41 | #ifndef _BSD_MD5_H 42 | #define _BSD_MD5_H 43 | #define MD5_Init MD5Init 44 | #define MD5_Update MD5Update 45 | #define MD5_Final MD5Final 46 | #endif 47 | 48 | #elif !defined(_MD5_H) 49 | #define _MD5_H 50 | 51 | /* Any 32-bit or wider unsigned integer data type will do */ 52 | typedef unsigned int MD5_u32plus; 53 | 54 | typedef struct { 55 | MD5_u32plus lo, hi; 56 | MD5_u32plus a, b, c, d; 57 | unsigned char buffer[64]; 58 | MD5_u32plus block[16]; 59 | } MD5_CTX; 60 | 61 | extern void MD5_Init(MD5_CTX *ctx); 62 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 63 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /tests/videopool.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/libyami-utils/3d730dc4da9c29aa0d15539433245b3ab271f971/tests/videopool.cpp -------------------------------------------------------------------------------- /tests/vppinputasync.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "vppinputasync.h" 17 | 18 | VppInputAsync::VppInputAsync() 19 | :m_cond(m_lock), m_eos(false), 20 | m_queueSize(0),m_quit(false) 21 | { 22 | } 23 | 24 | 25 | SharedPtr 26 | VppInputAsync::create(const SharedPtr& input, uint32_t queueSize) 27 | { 28 | SharedPtr ret; 29 | 30 | if (!input || !queueSize) 31 | return ret; 32 | SharedPtr async(new VppInputAsync()); 33 | if (!async->init(input, queueSize)) { 34 | ERROR("init VppInputAsync failed"); 35 | return ret; 36 | } 37 | ret = async; 38 | return ret; 39 | } 40 | 41 | void* VppInputAsync::start(void* async) 42 | { 43 | VppInputAsync* input = (VppInputAsync*)async; 44 | input->loop(); 45 | return NULL; 46 | } 47 | 48 | void VppInputAsync::loop() 49 | { 50 | while (1) { 51 | { 52 | AutoLock lock(m_lock); 53 | while (m_queue.size() >= m_queueSize) { 54 | m_cond.wait(); 55 | if (m_quit) 56 | return; 57 | } 58 | 59 | } 60 | SharedPtr frame; 61 | bool ret = m_input->read(frame); 62 | AutoLock lock(m_lock); 63 | if (!ret) { 64 | m_eos = true; 65 | return; 66 | } 67 | m_queue.push_back(frame); 68 | m_cond.signal(); 69 | } 70 | } 71 | 72 | bool VppInputAsync::init(const SharedPtr& input, uint32_t queueSize) 73 | { 74 | m_input = input; 75 | m_queueSize = queueSize; 76 | if (pthread_create(&m_thread, NULL, start, this)) { 77 | ERROR("create thread failed"); 78 | return false; 79 | } 80 | return true; 81 | 82 | } 83 | 84 | bool VppInputAsync::read(SharedPtr& frame) 85 | { 86 | AutoLock lock(m_lock); 87 | while (m_queue.empty()) { 88 | if (m_eos) 89 | return false; 90 | m_cond.wait(); 91 | } 92 | frame = m_queue.front(); 93 | m_queue.pop_front(); 94 | m_cond.signal(); 95 | return true; 96 | } 97 | 98 | VppInputAsync::~VppInputAsync() 99 | { 100 | { 101 | AutoLock lock(m_lock); 102 | m_quit = true; 103 | m_cond.signal(); 104 | } 105 | pthread_join(m_thread, NULL); 106 | } 107 | 108 | bool VppInputAsync::init(const char* inputFileName, uint32_t fourcc, int width, int height) 109 | { 110 | assert(0 && "no need for this"); 111 | return false; 112 | } -------------------------------------------------------------------------------- /tests/vppinputasync.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef vppinputasync_h 17 | #define vppinputasync_h 18 | #include "common/condition.h" 19 | #include "common/lock.h" 20 | #include 21 | 22 | #include "vppinputoutput.h" 23 | 24 | using namespace YamiMediaCodec; 25 | class VppInputAsync : public VppInput 26 | { 27 | public: 28 | 29 | bool read(SharedPtr& frame); 30 | 31 | static SharedPtr 32 | create(const SharedPtr& input, uint32_t queueSize); 33 | 34 | VppInputAsync(); 35 | virtual ~VppInputAsync(); 36 | virtual int getWidth() { return m_input->getWidth(); } 37 | virtual int getHeight() { return m_input->getHeight(); } 38 | virtual uint32_t getFourcc() { return m_input->getFourcc(); } 39 | 40 | const char *getMimeType() const { return m_input->getMimeType(); } 41 | 42 | //do not use this 43 | bool init(const char* inputFileName, uint32_t fourcc, int width, int height); 44 | private: 45 | bool init(const SharedPtr& input, uint32_t queueSize); 46 | static void* start(void* async); 47 | void loop(); 48 | 49 | Condition m_cond; 50 | Lock m_lock; 51 | SharedPtr m_input; 52 | bool m_eos; 53 | 54 | typedef std::deque > FrameQueue; 55 | FrameQueue m_queue; 56 | uint32_t m_queueSize; 57 | 58 | pthread_t m_thread; 59 | bool m_quit; 60 | 61 | }; 62 | #endif //vppinputasync_h 63 | -------------------------------------------------------------------------------- /tests/vppinputdecode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "tests/vppinputdecode.h" 17 | 18 | bool VppInputDecode::init(const char* inputFileName, uint32_t /*fourcc*/, int /*width*/, int /*height*/) 19 | { 20 | m_input.reset(DecodeInput::create(inputFileName)); 21 | if (!m_input) 22 | return false; 23 | m_decoder.reset(createVideoDecoder(m_input->getMimeType()), releaseVideoDecoder); 24 | if (!m_decoder) { 25 | fprintf(stderr, "failed create decoder for %s", m_input->getMimeType()); 26 | return false; 27 | } 28 | return true; 29 | } 30 | 31 | bool VppInputDecode::config(NativeDisplay& nativeDisplay) 32 | { 33 | m_decoder->setNativeDisplay(&nativeDisplay); 34 | 35 | VideoConfigBuffer configBuffer; 36 | memset(&configBuffer, 0, sizeof(configBuffer)); 37 | configBuffer.profile = VAProfileNone; 38 | const string codecData = m_input->getCodecData(); 39 | if (codecData.size()) { 40 | configBuffer.data = (uint8_t*)codecData.data(); 41 | configBuffer.size = codecData.size(); 42 | } 43 | configBuffer.width = m_input->getWidth(); 44 | configBuffer.height = m_input->getHeight(); 45 | configBuffer.temporalLayer = m_temporalLayer; 46 | configBuffer.enableLowLatency = m_enableLowLatency; 47 | Decode_Status status = m_decoder->start(&configBuffer); 48 | if (status == DECODE_SUCCESS) { 49 | //read first frame to update width height 50 | if (!read(m_first)) 51 | status = DECODE_FAIL; 52 | } 53 | return status == DECODE_SUCCESS; 54 | } 55 | 56 | bool VppInputDecode::read(SharedPtr& frame) 57 | { 58 | if (m_first) { 59 | frame = m_first; 60 | m_first.reset(); 61 | return true; 62 | } 63 | 64 | while (1) { 65 | frame = m_decoder->getOutput(); 66 | if (frame) 67 | return true; 68 | if (m_error || m_eos) 69 | return false; 70 | 71 | VideoDecodeBuffer inputBuffer; 72 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 73 | 74 | Decode_Status status = DECODE_FAIL; 75 | if (m_input->getNextDecodeUnit(inputBuffer)) { 76 | status = m_decoder->decode(&inputBuffer); 77 | if (DECODE_FORMAT_CHANGE == status) { 78 | 79 | //update width height 80 | const VideoFormatInfo* info = m_decoder->getFormatInfo(); 81 | m_width = info->width; 82 | m_height = info->height; 83 | m_fourcc = info->fourcc; 84 | 85 | //resend the buffer 86 | status = m_decoder->decode(&inputBuffer); 87 | } 88 | } else { /*EOS, need to flush*/ 89 | inputBuffer.data = NULL; 90 | inputBuffer.size = 0; 91 | status = m_decoder->decode(&inputBuffer); 92 | m_eos = true; 93 | } 94 | if (status < 0) { /* fatal error */ 95 | fprintf(stderr, "got fatal error %d\n", status); 96 | m_error = true; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /tests/vppinputdecode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef vppinputdecode_h 17 | #define vppinputdecode_h 18 | #include 19 | #include "decodeinput.h" 20 | 21 | #include "vppinputoutput.h" 22 | 23 | class VppInputDecode : public VppInput 24 | { 25 | public: 26 | VppInputDecode() 27 | : m_eos(false) 28 | , m_error(false) 29 | { 30 | } 31 | bool init(const char* inputFileName, uint32_t fourcc = 0, int width = 0, int height = 0); 32 | bool read(SharedPtr& frame); 33 | const char *getMimeType() const { return m_input->getMimeType(); } 34 | 35 | bool config(NativeDisplay& nativeDisplay); 36 | void setTargetLayer(uint32_t temporal = 0, uint32_t spacial = 0, uint32_t quality = 0) 37 | { 38 | m_temporalLayer = temporal; 39 | m_spacialLayer = spacial; 40 | m_qualityLayer = quality; 41 | } 42 | void setLowLatency(bool lowLatency = false) 43 | { 44 | m_enableLowLatency = lowLatency; 45 | } 46 | virtual ~VppInputDecode() {} 47 | private: 48 | bool m_eos; 49 | bool m_error; 50 | SharedPtr m_decoder; 51 | SharedPtr m_input; 52 | SharedPtr m_first; 53 | //m_xxxLayer layer number, 0: decode all layers, >0: decode up to target layer. 54 | uint32_t m_temporalLayer; 55 | uint32_t m_spacialLayer; 56 | uint32_t m_qualityLayer; 57 | 58 | //if set this flag to true, AVC decoder will output the ready frames ASAP. 59 | bool m_enableLowLatency; 60 | }; 61 | #endif //vppinputdecode_h 62 | 63 | -------------------------------------------------------------------------------- /tests/vppinputdecodecapi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include "vppinputdecodecapi.h" 22 | 23 | static void freeFrame(VideoFrame* frame) 24 | { 25 | frame->free(frame); 26 | } 27 | 28 | VppInputDecodeCapi::~VppInputDecodeCapi() 29 | { 30 | decodeStop(m_decoder); 31 | releaseDecoder(m_decoder); 32 | } 33 | 34 | bool VppInputDecodeCapi::init(const char* inputFileName, uint32_t /*fourcc*/, int /*width*/, int /*height*/) 35 | { 36 | m_input.reset(DecodeInput::create(inputFileName)); 37 | if (!m_input) 38 | return false; 39 | m_decoder = createDecoder(m_input->getMimeType()); 40 | if (!m_decoder) { 41 | fprintf(stderr, "failed create decoder for %s", m_input->getMimeType()); 42 | return false; 43 | } 44 | return true; 45 | } 46 | 47 | bool VppInputDecodeCapi::config(NativeDisplay& nativeDisplay) 48 | { 49 | decodeSetNativeDisplay(m_decoder, &nativeDisplay); 50 | 51 | VideoConfigBuffer configBuffer; 52 | memset(&configBuffer, 0, sizeof(configBuffer)); 53 | configBuffer.profile = VAProfileNone; 54 | const string codecData = m_input->getCodecData(); 55 | if (codecData.size()) { 56 | configBuffer.data = (uint8_t*)codecData.data(); 57 | configBuffer.size = codecData.size(); 58 | } 59 | configBuffer.width = m_input->getWidth(); 60 | configBuffer.height = m_input->getHeight(); 61 | Decode_Status status = decodeStart(m_decoder, &configBuffer); 62 | return status == DECODE_SUCCESS; 63 | } 64 | 65 | bool VppInputDecodeCapi::read(SharedPtr& frame) 66 | { 67 | while (1) { 68 | VideoFrame* tmp = decodeGetOutput(m_decoder); 69 | if (tmp) { 70 | frame.reset(tmp, freeFrame); 71 | return true; 72 | } 73 | if (m_error || m_eos) 74 | return false; 75 | 76 | VideoDecodeBuffer inputBuffer; 77 | memset(&inputBuffer, 0, sizeof(inputBuffer)); 78 | 79 | Decode_Status status = DECODE_FAIL; 80 | if (m_input->getNextDecodeUnit(inputBuffer)) { 81 | status = decodeDecode(m_decoder, &inputBuffer); 82 | if (DECODE_FORMAT_CHANGE == status) { 83 | const VideoFormatInfo* info = decodeGetFormatInfo(m_decoder); 84 | ERROR("resolution changed to %dx%d", info->width, info->height); 85 | //resend the buffer 86 | status = decodeDecode(m_decoder, &inputBuffer); 87 | } 88 | } 89 | else { /*EOS, need to flush*/ 90 | inputBuffer.data = NULL; 91 | inputBuffer.size = 0; 92 | decodeDecode(m_decoder, &inputBuffer); 93 | m_eos = true; 94 | } 95 | if (status < 0) { /* fatal error */ 96 | fprintf(stderr, "got fatal error %d\n", status); 97 | m_error = true; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /tests/vppinputdecodecapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef vppinputdecodecapi_h 18 | #define vppinputdecodecapi_h 19 | 20 | #include "decodeinput.h" 21 | #include "vppinputoutput.h" 22 | #include 23 | 24 | class VppInputDecodeCapi : public VppInput { 25 | public: 26 | VppInputDecodeCapi() 27 | : m_eos(false) 28 | , m_error(false) 29 | { 30 | } 31 | ~VppInputDecodeCapi(); 32 | 33 | bool init(const char* inputFileName, uint32_t fourcc = 0, int width = 0, int height = 0); 34 | bool read(SharedPtr& frame); 35 | const char *getMimeType() const { return m_input->getMimeType(); } 36 | bool config(NativeDisplay& nativeDisplay); 37 | 38 | private: 39 | bool m_eos; 40 | bool m_error; 41 | DecodeHandler m_decoder; 42 | SharedPtr m_input; 43 | }; 44 | 45 | #endif //vppinputdecodecapi_h 46 | -------------------------------------------------------------------------------- /tests/vppinputoutput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "common/log.h" 28 | #include "common/lock.h" 29 | #include "vppinputoutput.h" 30 | #include "vppoutputencode.h" 31 | #include "vppinputdecode.h" 32 | #include "vppinputdecodecapi.h" 33 | using namespace YamiMediaCodec; 34 | 35 | #ifndef ANDROID 36 | SharedPtr createVADisplay() 37 | { 38 | SharedPtr display; 39 | int fd = open("/dev/dri/renderD128", O_RDWR); 40 | if (fd < 0) { 41 | ERROR("can't open /dev/dri/renderD128, try to /dev/dri/card0"); 42 | fd = open("/dev/dri/card0", O_RDWR); 43 | } 44 | if (fd < 0) { 45 | ERROR("can't open drm device"); 46 | return display; 47 | } 48 | VADisplay vadisplay = vaGetDisplayDRM(fd); 49 | int majorVersion, minorVersion; 50 | VAStatus vaStatus = vaInitialize(vadisplay, &majorVersion, &minorVersion); 51 | if (vaStatus != VA_STATUS_SUCCESS) { 52 | ERROR("va init failed, status = %d", vaStatus); 53 | close(fd); 54 | return display; 55 | } 56 | display.reset(new VADisplay(vadisplay), VADisplayDeleter(fd)); 57 | return display; 58 | } 59 | #else 60 | #include 61 | struct AndroidDisplayDeleter 62 | { 63 | AndroidDisplayDeleter() {} 64 | void operator()(VADisplay* display) 65 | { 66 | vaTerminate(*display); 67 | delete display; 68 | } 69 | }; 70 | 71 | #define ANDROID_DISPLAY 0x18C34078 72 | SharedPtr createVADisplay() 73 | { 74 | SharedPtr display; 75 | unsigned int magic = ANDROID_DISPLAY; 76 | VADisplay vadisplay = vaGetDisplay(&magic); 77 | int majorVersion, minorVersion; 78 | VAStatus vaStatus = vaInitialize(vadisplay, &majorVersion, &minorVersion); 79 | if (vaStatus != VA_STATUS_SUCCESS) { 80 | ERROR("va init failed, status = %d", vaStatus); 81 | return display; 82 | } 83 | display.reset(new VADisplay(vadisplay), AndroidDisplayDeleter()); 84 | return display; 85 | } 86 | #endif 87 | 88 | SharedPtr VppInput::create(const char* inputFileName, uint32_t fourcc, int width, int height, bool useCAPI) 89 | { 90 | SharedPtr input; 91 | if (!inputFileName) 92 | return input; 93 | 94 | if(useCAPI) 95 | input.reset(new VppInputDecodeCapi); 96 | else 97 | input.reset(new VppInputDecode); 98 | if(input->init(inputFileName, fourcc, width, height)) 99 | return input; 100 | input.reset(new VppInputFile); 101 | if (input->init(inputFileName, fourcc, width, height)) 102 | return input; 103 | 104 | ERROR("Wrong input file format %s?", inputFileName); 105 | input.reset(); 106 | return input; 107 | } 108 | 109 | VppInputFile::VppInputFile() 110 | : m_ifs() 111 | , m_readToEOS(false) 112 | { 113 | } 114 | 115 | bool VppInputFile::config(const SharedPtr& allocator, const SharedPtr& reader) 116 | { 117 | if (!allocator->setFormat(m_fourcc, m_width, m_height)) { 118 | ERROR("set format to %x, %dx%d failed", m_fourcc, m_width, m_height); 119 | return false; 120 | } 121 | m_reader = reader; 122 | m_allocator = allocator; 123 | return true; 124 | } 125 | 126 | static bool guessFormat(const char* filename, uint32_t& fourcc, int& width, int& height) 127 | { 128 | if (!width || !height) { 129 | if (!guessResolution(filename, width, height)) { 130 | ERROR("failed to guess input width and height\n"); 131 | return false; 132 | } 133 | } 134 | if (!fourcc) 135 | fourcc = guessFourcc(filename); 136 | 137 | return true; 138 | } 139 | 140 | bool VppInputFile::init(const char* inputFileName, uint32_t fourcc, int width, int height) 141 | { 142 | if(!fourcc || !width || !height) 143 | if (!guessFormat(inputFileName, fourcc, width, height)) 144 | return false; 145 | 146 | m_width = width; 147 | m_height = height; 148 | m_fourcc = fourcc; 149 | 150 | m_ifs.open(inputFileName); 151 | if (!m_ifs) { 152 | fprintf(stderr, "fail to open input file: %s", inputFileName); 153 | return false; 154 | } 155 | return true; 156 | } 157 | 158 | bool VppInputFile::read(SharedPtr& frame) 159 | { 160 | if (!m_allocator || !m_reader) { 161 | ERROR("config VppInputFile with allocator and reader, please!"); 162 | return false; 163 | } 164 | if (m_readToEOS) 165 | return false; 166 | 167 | frame = m_allocator->alloc(); 168 | if (!frame) { 169 | ERROR("allocate frame failed"); 170 | return false; 171 | } 172 | 173 | if (!m_reader->read(m_ifs, frame)) 174 | m_readToEOS = true; 175 | return !m_readToEOS; 176 | } 177 | 178 | VppInputFile::~VppInputFile() 179 | { 180 | } 181 | 182 | VppOutput::VppOutput() 183 | :m_fourcc(0), m_width(0), m_height(0) 184 | { 185 | } 186 | 187 | SharedPtr VppOutput::create(const char* outputFileName, 188 | uint32_t fourcc, int width, int height, 189 | const char* codecName, int fps) 190 | { 191 | SharedPtr output; 192 | if (!outputFileName) { 193 | ERROR("invalid output file name"); 194 | return output; 195 | } 196 | output.reset(new VppOutputEncode); 197 | if (output->init(outputFileName, fourcc, width, height, codecName, fps)) 198 | return output; 199 | output.reset(new VppOutputFile); 200 | if (output->init(outputFileName, fourcc, width, height, codecName)) 201 | return output; 202 | ERROR("can't open %s, wrong extension?",outputFileName); 203 | output.reset(); 204 | return output; 205 | } 206 | 207 | 208 | bool VppOutput::getFormat(uint32_t& fourcc, int& width, int& height) 209 | { 210 | fourcc = m_fourcc; 211 | width = m_width; 212 | height = m_height; 213 | return true; 214 | } 215 | 216 | bool VppOutputFile::init(const char* outputFileName, uint32_t fourcc, int width, 217 | int height, const char* /*codecName*/, int fps) 218 | { 219 | if (!outputFileName) { 220 | ERROR("output file name is null"); 221 | return false; 222 | } 223 | if (!fourcc || !width || !height) { 224 | if (!guessFormat(outputFileName, fourcc, width, height)) { 225 | ERROR("can't guess format from %s", outputFileName); 226 | return false; 227 | } 228 | } 229 | m_fourcc = fourcc; 230 | m_width = width; 231 | m_height = height; 232 | m_ofs.open(outputFileName, std::ofstream::out | std::ofstream::binary 233 | | std::ofstream::trunc); 234 | if (!m_ofs) { 235 | ERROR("fail to open input file: %s", outputFileName); 236 | return false; 237 | } 238 | return true; 239 | } 240 | 241 | bool VppOutputFile::config(const SharedPtr& writer) 242 | { 243 | m_writer = writer; 244 | return true; 245 | } 246 | 247 | 248 | VppOutputFile::~VppOutputFile() 249 | { 250 | } 251 | 252 | bool VppOutputFile::output(const SharedPtr& frame) 253 | { 254 | return write(frame); 255 | } 256 | 257 | bool VppOutputFile::write(const SharedPtr& frame) 258 | { 259 | if (!m_writer) { 260 | ERROR("config with writer please!"); 261 | return false; 262 | } 263 | if (!frame) 264 | return true; 265 | return m_writer->write(m_ofs, frame); 266 | } 267 | 268 | VppOutputFile::VppOutputFile() 269 | :m_ofs() 270 | { 271 | } 272 | -------------------------------------------------------------------------------- /tests/vppinputoutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef vppinputoutput_h 17 | #define vppinputoutput_h 18 | 19 | #include "common/log.h" 20 | #include "common/utils.h" 21 | #include "common/VaapiUtils.h" 22 | #include "common/PooledFrameAllocator.h" 23 | #include 24 | 25 | #include 26 | #ifndef ANDROID 27 | #include 28 | #endif 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace YamiMediaCodec; 36 | 37 | struct VADisplayDeleter 38 | { 39 | VADisplayDeleter(int fd):m_fd(fd) {} 40 | void operator()(VADisplay* display) 41 | { 42 | vaTerminate(*display); 43 | delete display; 44 | close(m_fd); 45 | } 46 | private: 47 | int m_fd; 48 | }; 49 | 50 | SharedPtr createVADisplay(); 51 | 52 | 53 | //virtual bool setFormat(uint32_t fourcc, int width, int height) = 0; 54 | class FrameReader 55 | { 56 | public: 57 | virtual bool read(std::ifstream&, const SharedPtr& frame) = 0; 58 | virtual ~FrameReader() {} 59 | }; 60 | 61 | class FrameWriter 62 | { 63 | public: 64 | virtual bool write(std::ofstream&, const SharedPtr& frame) = 0; 65 | virtual ~FrameWriter() {} 66 | }; 67 | 68 | template 69 | class VaapiFrameIO 70 | { 71 | public: 72 | typedef bool (*FileIoFunc)(char* ptr, int size, T& fs); 73 | VaapiFrameIO(const SharedPtr& display, FileIoFunc io) 74 | :m_display(display), m_io(io) 75 | { 76 | 77 | }; 78 | bool doIO(T& fs, const SharedPtr& frame) 79 | { 80 | if (!fs || !fs.is_open() || !frame) { 81 | ERROR("invalid param"); 82 | return false; 83 | } 84 | VASurfaceID surface = (VASurfaceID)frame->surface; 85 | VAImage image; 86 | 87 | VAStatus status = vaDeriveImage(*m_display,surface,&image); 88 | if (status != VA_STATUS_SUCCESS) { 89 | ERROR("vaDeriveImage failed = %d", status); 90 | return false; 91 | } 92 | uint32_t byteWidth[3], byteHeight[3], planes; 93 | uint32_t byteX[3], byteY[3]; 94 | //image.width is not equal to frame->crop.width. 95 | //for supporting VPG Driver, use YV12 to replace I420 96 | if (!getPlaneResolution(frame->fourcc, frame->crop.width, frame->crop.height, byteWidth, byteHeight, planes)) { 97 | ERROR("get plane reoslution failed for %x, %dx%d", frame->fourcc, frame->crop.width, frame->crop.height); 98 | return false; 99 | } 100 | if (!getPlaneResolution(frame->fourcc, frame->crop.x, frame->crop.y, byteX, byteY, planes)) { 101 | ERROR("get left-top coordinate(%d,%d) failed", frame->crop.x, frame->crop.y); 102 | return false; 103 | } 104 | char* buf; 105 | status = vaMapBuffer(*m_display, image.buf, (void**)&buf); 106 | if (status != VA_STATUS_SUCCESS) { 107 | vaDestroyImage(*m_display, image.image_id); 108 | ERROR("vaMapBuffer failed = %d", status); 109 | return false; 110 | } 111 | bool ret = true; 112 | for (uint32_t i = 0; i < planes; i++) { 113 | char* ptr = buf + image.offsets[i]; 114 | ptr += image.pitches[i] * byteY[i]; 115 | int w = byteWidth[i]; 116 | for (uint32_t j = 0; j < byteHeight[i]; j++) { 117 | ret = m_io(ptr + byteX[i], w, fs); 118 | if (!ret) 119 | goto out; 120 | ptr += image.pitches[i]; 121 | } 122 | } 123 | out: 124 | vaUnmapBuffer(*m_display, image.buf); 125 | vaDestroyImage(*m_display, image.image_id); 126 | return ret; 127 | 128 | } 129 | private: 130 | SharedPtr m_display; 131 | FileIoFunc m_io; 132 | }; 133 | 134 | 135 | class VaapiFrameReader:public FrameReader 136 | { 137 | public: 138 | VaapiFrameReader(const SharedPtr& display) 139 | :m_frameio(new VaapiFrameIO(display, readFromFile)) 140 | { 141 | } 142 | bool read(std::ifstream& ifs, const SharedPtr& frame) 143 | { 144 | return m_frameio->doIO(ifs, frame); 145 | } 146 | private: 147 | SharedPtr< VaapiFrameIO > m_frameio; 148 | static bool readFromFile(char* ptr, int size, std::ifstream& ifs) 149 | { 150 | return ifs.read(ptr, size).good(); 151 | } 152 | }; 153 | 154 | class VaapiFrameWriter:public FrameWriter 155 | { 156 | public: 157 | VaapiFrameWriter(const SharedPtr& display) 158 | :m_frameio(new VaapiFrameIO(display, writeToFile)) 159 | { 160 | } 161 | bool write(std::ofstream& ofs, const SharedPtr& frame) 162 | { 163 | return m_frameio->doIO(ofs, frame); 164 | } 165 | private: 166 | SharedPtr< VaapiFrameIO > m_frameio; 167 | static bool writeToFile(char* ptr, int size, std::ofstream& ofs) 168 | { 169 | return ofs.write(ptr, size).good(); 170 | } 171 | }; 172 | //vaapi related operation end 173 | 174 | class VppInput; 175 | class VppInputFile; 176 | 177 | class VppInput { 178 | public: 179 | static SharedPtr 180 | create(const char* inputFileName, uint32_t fourcc = 0, int width = 0, int height = 0, bool useCAPI = false); 181 | virtual bool init(const char* inputFileName = 0, uint32_t fourcc = 0, int width = 0, int height = 0) = 0; 182 | virtual bool read(SharedPtr& frame) = 0; 183 | virtual const char * getMimeType() const = 0; 184 | virtual int getWidth() { return m_width; } 185 | virtual int getHeight() { return m_height; } 186 | virtual uint32_t getFourcc() { return m_fourcc; } 187 | 188 | virtual ~VppInput() {} 189 | protected: 190 | uint32_t m_fourcc; 191 | int m_width; 192 | int m_height; 193 | }; 194 | 195 | class VppInputFile : public VppInput { 196 | public: 197 | //inherit VppInput 198 | bool init(const char* inputFileName, uint32_t fourcc, int width, int height); 199 | virtual bool read(SharedPtr& frame); 200 | const char *getMimeType() const { return "unknown"; } 201 | bool config(const SharedPtr& allocator, const SharedPtr& reader); 202 | VppInputFile(); 203 | ~VppInputFile(); 204 | protected: 205 | std::ifstream m_ifs; 206 | bool m_readToEOS; 207 | SharedPtr m_reader; 208 | SharedPtr m_allocator; 209 | }; 210 | 211 | class VppOutput 212 | { 213 | public: 214 | static SharedPtr create(const char* outputFileName, 215 | uint32_t fourcc = 0, int width = 0, 216 | int height = 0, 217 | const char* codecName = NULL, 218 | int fps = 30); 219 | bool getFormat(uint32_t& fourcc, int& width, int& height); 220 | virtual bool output(const SharedPtr& frame) = 0; 221 | VppOutput(); 222 | virtual ~VppOutput(){} 223 | protected: 224 | virtual bool init(const char* outputFileName, uint32_t fourcc, int width, 225 | int height, const char* codecName, int fps = 30) 226 | = 0; 227 | uint32_t m_fourcc; 228 | int m_width; 229 | int m_height; 230 | }; 231 | 232 | class VppOutputFile : public VppOutput 233 | { 234 | public: 235 | bool config(const SharedPtr& writer); 236 | 237 | //inherit VppOutput 238 | bool output(const SharedPtr& frame); 239 | virtual ~VppOutputFile(); 240 | VppOutputFile(); 241 | protected: 242 | virtual bool init(const char* outputFileName, uint32_t fourcc, int width, 243 | int height, const char* codecName, int fps = 30); 244 | 245 | private: 246 | bool write(const SharedPtr& frame); 247 | SharedPtr m_writer; 248 | std::ofstream m_ofs; 249 | }; 250 | 251 | #endif //vppinputoutput_h 252 | -------------------------------------------------------------------------------- /tests/vppoutputencode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef vppoutputencode_h 17 | #define vppoutputencode_h 18 | #include 19 | #include "encodeinput.h" 20 | #include 21 | #include 22 | 23 | #include "vppinputoutput.h" 24 | using std::string; 25 | 26 | struct EncodeParamsVP9 { 27 | EncodeParamsVP9(); 28 | uint32_t referenceMode; // Reference mode scheme, <0 | 1> 29 | }; 30 | 31 | class EncodeParams { 32 | public: 33 | EncodeParams(); 34 | 35 | VideoRateControl rcMode; 36 | int32_t initQp; 37 | int32_t bitRate; 38 | int32_t fps; 39 | int32_t ipPeriod; 40 | int32_t intraPeriod; 41 | int32_t numRefFrames; 42 | int32_t idrInterval; 43 | string codec; 44 | bool enableCabac; 45 | bool enableDct8x8; 46 | bool enableDeblockFilter; 47 | int8_t deblockAlphaOffsetDiv2; //same as slice_alpha_c0_offset_div2 defined in h264 spec 7.4.3 48 | int8_t deblockBetaOffsetDiv2; //same as slice_beta_offset_div2 defined in h264 spec 7.4.3 49 | int8_t diffQPIP;// P frame qp minus initQP 50 | int8_t diffQPIB;// B frame qp minus initQP 51 | uint32_t temporalLayerNum; // svc-t temporal layer number 52 | uint32_t priorityId; // h264 priority_id in prefix nal unit 53 | EncodeParamsVP9 m_encParamsVP9; 54 | uint32_t layerBitRate[TEMPORAL_LAYER_LENGTH_MAX]; // specify each scalable layer bitrate 55 | bool enableLowPower; 56 | uint32_t targetPercentage; 57 | uint32_t windowSize; // use for HRD CPB length in ms 58 | unsigned int initBufferFullness; /* in bits */ 59 | unsigned int bufferSize; /* in bits */ 60 | uint32_t qualityLevel; 61 | }; 62 | 63 | class TranscodeParams 64 | { 65 | public: 66 | TranscodeParams(); 67 | 68 | EncodeParams m_encParams; 69 | uint32_t frameCount; 70 | uint32_t iWidth; /*input video width*/ 71 | uint32_t iHeight; /*input vide height*/ 72 | uint32_t oWidth; /*output video width*/ 73 | uint32_t oHeight; /*output vide height*/ 74 | uint32_t fourcc; 75 | string inputFileName; 76 | string outputFileName; 77 | }; 78 | 79 | class VppOutputEncode : public VppOutput 80 | { 81 | public: 82 | virtual bool output(const SharedPtr& frame); 83 | virtual ~VppOutputEncode(){} 84 | bool config(NativeDisplay& nativeDisplay, const EncodeParams* encParam = NULL); 85 | protected: 86 | virtual bool init(const char* outputFileName, uint32_t fourcc, int width, 87 | int height, const char* codecName, int fps = 30); 88 | 89 | private: 90 | void initOuputBuffer(); 91 | const char* m_mime; 92 | SharedPtr m_encoder; 93 | VideoEncOutputBuffer m_outputBuffer; 94 | std::vector m_buffer; 95 | SharedPtr m_output; 96 | }; 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /tests/yamiinfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2015 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "config.h" 19 | #endif 20 | 21 | #include 22 | #include 23 | 24 | using namespace YamiMediaCodec; 25 | 26 | void printInfo(const char* name, const std::vector& vector) 27 | { 28 | std::cout << std::endl << name << ":" << std::endl; 29 | for (size_t i(0); i < vector.size(); ++i) { 30 | std::cout << "\t" << vector[i] << std::endl; 31 | } 32 | } 33 | 34 | void printApiVersion() 35 | { 36 | uint32_t api; 37 | yamiGetApiVersion(&api); 38 | 39 | //uint32 just for print format 40 | uint32_t major = api >> 24; 41 | uint32_t minor = (api >> 16) & 0xff; 42 | uint32_t micro = (api >> 8) & 0xff; 43 | 44 | std::cout << "API: " << major << "." << minor << "." << micro << std::endl; 45 | } 46 | 47 | int main(int argc, const char** argv) 48 | { 49 | 50 | std::cout << PACKAGE_STRING << " - " << PACKAGE_URL << std::endl; 51 | 52 | std::cout< 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define NORMAL_PSNR 35 23 | #define MAX_WIDTH 8192 24 | #define MAX_HEIGHT 4320 25 | static unsigned char *bufferyuv1 = NULL; 26 | static unsigned char *bufferyuv2 = NULL; 27 | 28 | static void print_help(const char* app) 29 | { 30 | printf("%s \n", app); 31 | printf(" -i raw yuv file by software decoder\n"); 32 | printf(" -o raw yuv file by hardward decoder\n"); 33 | printf(" -W width of video\n"); 34 | printf(" -H height of video\n"); 35 | } 36 | 37 | int 38 | psnr_calculate(char *filename1, char *filename2, const char *eachpsnr, const char *psnrresult, 39 | int width, int height, int standardpsnr) 40 | { 41 | int size1,size2; 42 | char videofile[512] = {0}; 43 | FILE * fpraw1=NULL; 44 | FILE * fpraw2=NULL; 45 | FILE * fpeachpsnr=NULL; 46 | FILE * fppsnrresult = NULL; 47 | double sum=0; 48 | double mse=0; 49 | double psny=0; 50 | double psnu=0; 51 | double psnv=0; 52 | double psnrsumy=0; 53 | double psnrsumu=0; 54 | double psnrsumv=0; 55 | double avgy; 56 | double avgu; 57 | double avgv; 58 | 59 | char *path = NULL ; 60 | int framecount=0; 61 | int uvWidth = (width+1)/2; 62 | int uvHeight = (height+1)/2; 63 | int sizey = width*height; 64 | int sizeuv = uvWidth*uvHeight; 65 | 66 | fppsnrresult = fopen(psnrresult,"ab+"); 67 | if (NULL==fppsnrresult) 68 | { 69 | printf("open result psnr fail\n"); 70 | goto error; 71 | } 72 | 73 | fpraw1=fopen(filename1,"rb"); 74 | if (NULL==fpraw1) 75 | { 76 | printf("open ref yuv fail\n"); 77 | fprintf(fppsnrresult,"open %s fail\n",filename1); 78 | goto error; 79 | } 80 | fpraw2=fopen(filename2,"rb"); 81 | if (NULL==fpraw2) 82 | { 83 | printf("open decode yuv fail\n"); 84 | fprintf(fppsnrresult,"open %s fail\n",filename2); 85 | goto error; 86 | } 87 | fpeachpsnr=fopen(eachpsnr,"wb"); 88 | 89 | if (NULL==fpeachpsnr) 90 | { 91 | printf("open record psnr fail\n"); 92 | fprintf(fppsnrresult,"open %s fail\n",eachpsnr); 93 | goto error; 94 | } 95 | 96 | if (!bufferyuv1) 97 | bufferyuv1 = (unsigned char*)malloc(sizey); 98 | if (!bufferyuv2) 99 | bufferyuv2 = (unsigned char*)malloc(sizey); 100 | if (!bufferyuv1 || !bufferyuv2) { 101 | goto error; 102 | } 103 | 104 | while(1) 105 | { 106 | int i, j; 107 | //calc psnr of y 108 | sum=0; 109 | size1=fread(bufferyuv1,sizeof(char),sizey,fpraw1); 110 | size2=fread(bufferyuv2,sizeof(char),sizey,fpraw2); 111 | if ((0==size1) || (0==size2) || (size1!=size2)) 112 | break; 113 | for(i = 0;i MAX_WIDTH) || (height > MAX_HEIGHT)) { 256 | printf("input width and height is invalid\n"); 257 | return -1; 258 | } 259 | printf(" filename1 %s\n filename2 %s\n result %s \n",filename1,filename2,psnrresult); 260 | return psnr_calculate(filename1,filename2,eachpsnr,psnrresult,width,height,standardpsnr); 261 | } 262 | -------------------------------------------------------------------------------- /testscripts/replace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MV="mv -f" 4 | 5 | replace() 6 | { 7 | if [ ! -f "$1" ]; then 8 | echo "can't read $1: No such file or directory" 9 | exit 1 10 | fi 11 | 12 | sed -i '/[<]gst\/gstconfig.h[>]/d' "$1" 13 | sed -i 's/[<]gst\/codecparsers\/gstmpegvideoparser.h[>]/"mpegvideoparser.h"/g' "$1" 14 | sed -i 's/[<]gst\/codecparsers\/gstvp8parser.h[>]/"vp8parser.h"/g' "$1" 15 | sed -i 's/[<]glib.h[>]/"commondef.h"/g' "$1" 16 | sed -i 's/guint##bits/uint##bits##_t/g' "$1" 17 | 18 | #rename temporarily, will be recovery at the end of this script 19 | sed -i 's/GST_READ_##upper/YAMI_READ_##upper/g' "$1" 20 | sed -i 's/GST_READ_UINT##bits/YAMI_READ_UINT##bits/g' "$1" 21 | sed -i 's/GST_PUT/YAMI_PUT/g' "$1" 22 | sed -i 's/GST_WRITE/YAMI_WRITE/g' "$1" 23 | sed -i 's/GST_READ/YAMI_READ/g' "$1" 24 | sed -i 's/_gst_debug_category_new/_yami_debug_category_new/g' "$1" 25 | 26 | sed -i 's/[<]gst\/gst.h[>]/"gst\/gst.h"/g' "$1" 27 | sed -i 's/\/INFO/g' "$1" 28 | #remove gst and gst_, ignore case 29 | sed -i "s/[gG][sS][Tt]_\?//g" "$1" 30 | 31 | #replace data type integer 32 | sed -i 's/gboolean/bool/g' "$1" 33 | sed -i 's/gchar/char/g' "$1" 34 | sed -i 's/guchar/unsigned char/g' "$1" 35 | sed -i 's/\/uint8_t/g' "$1" 36 | sed -i 's/\/int8_t/g' "$1" 37 | sed -i 's/\/int16_t/g' "$1" 38 | sed -i 's/\/uint16_t/g' "$1" 39 | sed -i 's/\/int32_t/g' "$1" 40 | sed -i 's/\/uint32_t/g' "$1" 41 | sed -i 's/\/int32_t/g' "$1" 42 | sed -i 's/\/uint32_t/g' "$1" 43 | sed -i 's/\/size_t/g' "$1" 44 | sed -i 's/\/uint64_t/g' "$1" 45 | sed -i 's/\/int64_t/g' "$1" 46 | #float 47 | sed -i 's/gfloat/float/g' "$1" 48 | sed -i 's/\/double/g' "$1" 49 | #pointer 50 | sed -i 's/\/void*/g' "$1" 51 | sed -i 's/\/const void*/g' "$1" 52 | #include header file 53 | sed -i 's/[<]\/base\/bitreader.h[>]/"bitreader.h"/g' "$1" 54 | sed -i 's/[<]\/base\/bytereader.h[>]/"bytereader.h"/g' "$1" 55 | sed -i 's/[<]\/base\/bitwriter.h[>]/"bitwriter.h"/g' "$1" 56 | sed -i 's/[<]\/base\/bytewriter.h[>]/"bytewriter.h"/g' "$1" 57 | 58 | #recovery change at the begining 59 | sed -i 's/YAMI_READ_##upper/GST_READ_##upper/g' "$1" 60 | sed -i 's/YAMI_READ_UINT##bits/GST_READ_UINT##bits/g' "$1" 61 | sed -i 's/YAMI_PUT/GST_PUT/g' "$1" 62 | sed -i 's/YAMI_WRITE/GST_WRITE/g' "$1" 63 | sed -i 's/YAMI_READ/GST_READ/g' "$1" 64 | sed -i 's/_yami_debug_category_new/_gst_debug_category_new/g' "$1" 65 | 66 | #change file name 67 | RENAME=`echo "$1" | sed "s/[g,G][s,S][T,t]_\?//g"` 68 | if [ "$1" != "$RENAME" ]; then 69 | echo "Rename file $1 to $RENAME" 70 | $MV "$1" "$RENAME" 71 | fi 72 | } 73 | 74 | for file in `ls`; do 75 | if [ "$file" != "replace.sh" ]; then 76 | echo "Begin -------------- $file ----------" 77 | replace $file 78 | echo "End ---\n" 79 | fi 80 | done 81 | -------------------------------------------------------------------------------- /testscripts/ssim_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | #This script will compare ssim value between libyami and ffmpeg. 4 | #Firstly, it will generate yuv using yamidecode, then it will compare the ssim with ffmpeg. Mini version for ffmpeg is 2.8 5 | #Example commands: 6 | # ssim_test.py directory 7 | # ssim_test.py file 8 | 9 | import subprocess 10 | import re 11 | import glob, os 12 | import sys 13 | from os.path import join, getsize 14 | 15 | def isCandidate(f): 16 | filename, ext = os.path.splitext(f) 17 | ext = ext.lower() 18 | supported = [ 19 | ".jpeg" 20 | , ".jpg" 21 | , ".vc1" 22 | , ".rcv" 23 | , ".mpeg" 24 | , ".mpg" 25 | , ".mpeg2" 26 | , ".mjpg" 27 | , ".mjpeg" 28 | ] 29 | return ext in supported 30 | 31 | def testYami(f, log): 32 | output = None if log else subprocess.DEVNULL 33 | yamidecode = os.path.dirname(os.path.realpath(__file__)) + "/../tests/yamidecode" 34 | r = subprocess.call(yamidecode + r" -i "+ f + " -f i420 -m 0 ", stdout=output, stderr=output, shell=True) 35 | if r != 0: 36 | print("yami return "+str(r)); 37 | return r == 0 38 | 39 | def getFmt(f): 40 | filename, ext = os.path.splitext(f) 41 | if ".I420" == ext: 42 | return "yuvj420p" 43 | if ".422H" == ext: 44 | return "yuvj422p" 45 | if ".422V" == ext: 46 | return "yuvj440p" 47 | if ".444P" == ext: 48 | return "yuvj444p" 49 | return "" 50 | 51 | def getYuvFile(src): 52 | dirname, basename = os.path.split(src) 53 | files = glob.glob(basename+"_*") 54 | if len(files) == 0: 55 | print("no yuv for "+src) 56 | return None 57 | return files[0] 58 | 59 | def getFileInfo(file): 60 | m=re.search("(?P\d+)x(?P\d+)", file); 61 | w = int(m.group("width")) 62 | h = int(m.group("height")) 63 | if w == 0 or h == 0: 64 | return 0, 0, "" 65 | return w, h, getFmt(file) 66 | 67 | def info(cmd, log): 68 | a = " All:" 69 | for line in cmd.stdout: 70 | l = line.decode("utf8"); 71 | if (log): 72 | print(l) 73 | if "error" in l.lower(): 74 | print(l) 75 | return False 76 | if a in l: 77 | t = l.split(a) 78 | t = t[1].split(" ") 79 | if (float(t[0]) > 0.99): 80 | return True; 81 | return False; 82 | 83 | def verify(yuv, f, log): 84 | 85 | w, h, fmt = getFileInfo(yuv) 86 | cmd = subprocess.Popen(r"ffmpeg -f rawvideo -video_size " + str(w) + "x" + str(h) +" -pix_fmt "+ fmt + " -i " + yuv + " -i " + f + ' -lavfi "ssim;[0:v][1:v]psnr" -f null -', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 87 | return info(cmd, log) 88 | 89 | def test(f, log = False): 90 | if not testYami(f, log): 91 | return False 92 | 93 | yuv = getYuvFile(f); 94 | if yuv is None: 95 | return False 96 | ret = verify(yuv, f, log) 97 | os.remove(yuv) 98 | print(f, end = " ") 99 | print("pass" if ret else "failed") 100 | return ret 101 | 102 | if len(sys.argv)!=2: 103 | print(sys.argv[0] + " directory") 104 | 105 | dir = sys.argv[1] 106 | #test file 107 | if os.path.isfile(dir): 108 | test(dir, True) 109 | sys.exit(0) 110 | 111 | #test directory 112 | total = 0 113 | failed = 0 114 | for root, dirs, files in os.walk(dir): 115 | for f in files: 116 | if isCandidate(f): 117 | total += 1 118 | pss = test(join(root, f)) 119 | failed += not pss 120 | print("total = "+ str(total) +", failed = "+ str(failed)) 121 | -------------------------------------------------------------------------------- /vaapi/vaapidisplay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef vaapidisplay_h 18 | #define vaapidisplay_h 19 | 20 | #include 21 | #include 22 | #ifdef HAVE_VA_X11 23 | #include 24 | #endif 25 | #ifndef ANDROID 26 | #include 27 | #endif 28 | #include 29 | #include "common/lock.h" 30 | #include "common/NonCopyable.h" 31 | 32 | ///abstract for all display, x11, wayland, ozone, android etc. 33 | namespace YamiMediaCodec { 34 | #ifndef VA_FOURCC_I420 35 | #define VA_FOURCC_I420 VA_FOURCC('I', '4', '2', '0') 36 | #endif 37 | class NativeDisplayBase; 38 | class VaapiDisplay; 39 | typedef SharedPtr DisplayPtr; 40 | class VaapiDisplay { 41 | typedef SharedPtr NativeDisplayPtr; 42 | friend class DisplayCache; 43 | friend class VaapiDisplayTest; 44 | 45 | public: 46 | virtual ~VaapiDisplay(); 47 | //FIXME: add more create functions. 48 | static DisplayPtr create(const NativeDisplay& display); 49 | virtual bool setRotation(int degree); 50 | VADisplay getID() const { return m_vaDisplay; } 51 | const VAImageFormat* getVaFormat(uint32_t fourcc); 52 | 53 | protected: 54 | /// for display cache management. 55 | virtual bool isCompatible(const NativeDisplay& other); 56 | 57 | private: 58 | VaapiDisplay(const NativeDisplayPtr& nativeDisplay, VADisplay vaDisplay) 59 | : m_vaDisplay(vaDisplay) 60 | , m_nativeDisplay(nativeDisplay){}; 61 | 62 | Lock m_lock; 63 | VADisplay m_vaDisplay; 64 | NativeDisplayPtr m_nativeDisplay; 65 | std::vector m_vaImageFormats; 66 | 67 | DISALLOW_COPY_AND_ASSIGN(VaapiDisplay); 68 | }; 69 | } 70 | #endif 71 | --------------------------------------------------------------------------------