From 2b02671e808d82329946c17f401b8b05dabb1a0a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 7 Dec 2015 12:20:56 +0100 Subject: [PATCH 1/3] tools: added appveyor and travis folders --- .travis.yml | 12 ++++++------ appveyor.yml | 6 +++--- tools/{appveyor.build.bat => appveyor/build.bat} | 0 .../python.nosetests.bat} | 0 .../win.install.deps.bat} | 0 tools/{travis.build.sh => travis/build.sh} | 0 .../gcc.generate.coverage.sh} | 0 .../gcc.install.coverage.sh} | 0 .../linux.install.deps.sh} | 0 .../osx.install.deps.sh} | 0 .../python.nosetests.sh} | 0 11 files changed, 9 insertions(+), 9 deletions(-) rename tools/{appveyor.build.bat => appveyor/build.bat} (100%) rename tools/{appveyor.python.nosetests.bat => appveyor/python.nosetests.bat} (100%) rename tools/{appveyor.win.install.deps.bat => appveyor/win.install.deps.bat} (100%) rename tools/{travis.build.sh => travis/build.sh} (100%) rename tools/{travis.gcc.generate.coverage.sh => travis/gcc.generate.coverage.sh} (100%) rename tools/{travis.gcc.install.coverage.sh => travis/gcc.install.coverage.sh} (100%) rename tools/{travis.linux.install.deps.sh => travis/linux.install.deps.sh} (100%) rename tools/{travis.osx.install.deps.sh => travis/osx.install.deps.sh} (100%) rename tools/{travis.python.nosetests.sh => travis/python.nosetests.sh} (100%) diff --git a/.travis.yml b/.travis.yml index 785251ff..f92aef7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,22 +65,22 @@ before_script: - cd ${TRAVIS_BUILD_DIR} # install coverage tools - - if [ ${ENABLE_COVERAGE} ]; then ./tools/travis.gcc.install.coverage.sh; fi + - if [ ${ENABLE_COVERAGE} ]; then ./tools/travis/gcc.install.coverage.sh; fi # install avtranscoder dependencies - - if [ ${TRAVIS_OS_NAME} = "linux" ]; then ./tools/travis.linux.install.deps.sh; fi - - if [ ${TRAVIS_OS_NAME} = "osx" ]; then ./tools/travis.osx.install.deps.sh; fi + - if [ ${TRAVIS_OS_NAME} = "linux" ]; then ./tools/travis/linux.install.deps.sh; fi + - if [ ${TRAVIS_OS_NAME} = "osx" ]; then ./tools/travis/osx.install.deps.sh; fi script: # build - - ./tools/travis.build.sh + - ./tools/travis/build.sh # launch tests - - if [ ${DEPENDENCY_MODE} = "ffmpeg" ]; then ./tools/travis.python.nosetests.sh; fi + - if [ ${DEPENDENCY_MODE} = "ffmpeg" ]; then ./tools/travis/python.nosetests.sh; fi after_success: # generate coverage for coveralls - - if [ ${ENABLE_COVERAGE} ]; then ./tools/travis.gcc.generate.coverage.sh; fi + - if [ ${ENABLE_COVERAGE} ]; then ./tools/travis/gcc.generate.coverage.sh; fi before_deploy: # copy libbz2, external dependency of libavformat diff --git a/appveyor.yml b/appveyor.yml index 7da1a14a..dbb44d5d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,10 +13,10 @@ init: before_build: - choco install -y swig - - tools/appveyor.win.install.deps.bat + - tools/appveyor/win.install.deps.bat build_script: - - tools/appveyor.build.bat + - tools/appveyor/build.bat before_test: - set PATH=C:\Python27\scripts;%PATH% @@ -24,7 +24,7 @@ before_test: test_script: - cd .. - - tools/appveyor.python.nosetests.bat + - tools/appveyor/python.nosetests.bat on_failure: - type "C:\ProgramData\chocolatey\logs\chocolatey.log" diff --git a/tools/appveyor.build.bat b/tools/appveyor/build.bat similarity index 100% rename from tools/appveyor.build.bat rename to tools/appveyor/build.bat diff --git a/tools/appveyor.python.nosetests.bat b/tools/appveyor/python.nosetests.bat similarity index 100% rename from tools/appveyor.python.nosetests.bat rename to tools/appveyor/python.nosetests.bat diff --git a/tools/appveyor.win.install.deps.bat b/tools/appveyor/win.install.deps.bat similarity index 100% rename from tools/appveyor.win.install.deps.bat rename to tools/appveyor/win.install.deps.bat diff --git a/tools/travis.build.sh b/tools/travis/build.sh similarity index 100% rename from tools/travis.build.sh rename to tools/travis/build.sh diff --git a/tools/travis.gcc.generate.coverage.sh b/tools/travis/gcc.generate.coverage.sh similarity index 100% rename from tools/travis.gcc.generate.coverage.sh rename to tools/travis/gcc.generate.coverage.sh diff --git a/tools/travis.gcc.install.coverage.sh b/tools/travis/gcc.install.coverage.sh similarity index 100% rename from tools/travis.gcc.install.coverage.sh rename to tools/travis/gcc.install.coverage.sh diff --git a/tools/travis.linux.install.deps.sh b/tools/travis/linux.install.deps.sh similarity index 100% rename from tools/travis.linux.install.deps.sh rename to tools/travis/linux.install.deps.sh diff --git a/tools/travis.osx.install.deps.sh b/tools/travis/osx.install.deps.sh similarity index 100% rename from tools/travis.osx.install.deps.sh rename to tools/travis/osx.install.deps.sh diff --git a/tools/travis.python.nosetests.sh b/tools/travis/python.nosetests.sh similarity index 100% rename from tools/travis.python.nosetests.sh rename to tools/travis/python.nosetests.sh From 4b3064ed3807e7e8c6e90ac59350f02f9bca450f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 7 Dec 2015 14:09:26 +0100 Subject: [PATCH 2/3] tools: added format tools * In format folder. * Use clang-format --- tools/format/.clang-format | 19 +++++++++++++++++++ tools/format/format_all_files.sh | 5 +++++ 2 files changed, 24 insertions(+) create mode 100644 tools/format/.clang-format create mode 100755 tools/format/format_all_files.sh diff --git a/tools/format/.clang-format b/tools/format/.clang-format new file mode 100644 index 00000000..fa1d723e --- /dev/null +++ b/tools/format/.clang-format @@ -0,0 +1,19 @@ +--- +IndentWidth: 4 +UseTab: Never +ColumnLimit: 125 +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +BreakConstructorInitializersBeforeComma: true +IndentCaseLabels: true +BreakBeforeBraces: Allman +NamespaceIndentation: None +MaxEmptyLinesToKeep: 1 +KeepEmptyLinesAtTheStartOfBlocks: true +PointerAlignment: Left +SpaceBeforeParens: Never +SpaceBeforeAssignmentOperators: true +SpacesInParentheses: false +AlwaysBreakTemplateDeclarations: true +Standard: Auto +AccessModifierOffset: -4 diff --git a/tools/format/format_all_files.sh b/tools/format/format_all_files.sh new file mode 100755 index 00000000..6334a6d4 --- /dev/null +++ b/tools/format/format_all_files.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# src +find ../../src -type f \( -iname \*.?pp \) -exec clang-format -i {} \; +# apps +find ../../app -type f \( -iname \*.?pp \) -exec clang-format -i {} \; From c37bce90a4718c30e618ae99cafbf9e36228d21a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 15 Dec 2015 11:09:13 +0100 Subject: [PATCH 3/3] Updated style format of src and app folders --- app/avInfo/avInfo.cpp | 47 +- app/avMeta/avMeta.cpp | 94 +- app/avPlay/Window.cpp | 822 +++++++-------- app/avPlay/Window.hpp | 95 +- app/avPlay/main.cpp | 29 +- app/avProcessor/avProcessor.cpp | 266 ++--- src/AvTranscoder/Library.cpp | 211 ++-- src/AvTranscoder/Library.hpp | 31 +- src/AvTranscoder/Option.cpp | 383 ++++--- src/AvTranscoder/Option.hpp | 176 ++-- src/AvTranscoder/codec/AudioCodec.cpp | 27 +- src/AvTranscoder/codec/AudioCodec.hpp | 11 +- src/AvTranscoder/codec/DataCodec.cpp | 13 +- src/AvTranscoder/codec/DataCodec.hpp | 7 +- src/AvTranscoder/codec/ICodec.cpp | 212 ++-- src/AvTranscoder/codec/ICodec.hpp | 64 +- src/AvTranscoder/codec/VideoCodec.cpp | 39 +- src/AvTranscoder/codec/VideoCodec.hpp | 11 +- src/AvTranscoder/common.cpp | 11 +- src/AvTranscoder/common.hpp | 39 +- src/AvTranscoder/decoder/AudioDecoder.cpp | 273 +++-- src/AvTranscoder/decoder/AudioDecoder.hpp | 21 +- src/AvTranscoder/decoder/AudioGenerator.cpp | 85 +- src/AvTranscoder/decoder/AudioGenerator.hpp | 25 +- src/AvTranscoder/decoder/IDecoder.hpp | 75 +- src/AvTranscoder/decoder/VideoDecoder.cpp | 205 ++-- src/AvTranscoder/decoder/VideoDecoder.hpp | 21 +- src/AvTranscoder/decoder/VideoGenerator.cpp | 97 +- src/AvTranscoder/decoder/VideoGenerator.hpp | 25 +- src/AvTranscoder/encoder/AudioEncoder.cpp | 301 +++--- src/AvTranscoder/encoder/AudioEncoder.hpp | 22 +- src/AvTranscoder/encoder/IEncoder.hpp | 59 +- src/AvTranscoder/encoder/VideoEncoder.cpp | 295 +++--- src/AvTranscoder/encoder/VideoEncoder.hpp | 24 +- src/AvTranscoder/file/FormatContext.cpp | 295 +++--- src/AvTranscoder/file/FormatContext.hpp | 191 ++-- src/AvTranscoder/file/IOutputFile.hpp | 97 +- src/AvTranscoder/file/InputFile.cpp | 258 +++-- src/AvTranscoder/file/InputFile.hpp | 196 ++-- src/AvTranscoder/file/OutputFile.cpp | 493 +++++---- src/AvTranscoder/file/OutputFile.hpp | 177 ++-- src/AvTranscoder/file/util.hpp | 8 +- src/AvTranscoder/frame/AudioFrame.cpp | 75 +- src/AvTranscoder/frame/AudioFrame.hpp | 65 +- src/AvTranscoder/frame/Frame.cpp | 91 +- src/AvTranscoder/frame/Frame.hpp | 89 +- src/AvTranscoder/frame/VideoFrame.cpp | 69 +- src/AvTranscoder/frame/VideoFrame.hpp | 56 +- src/AvTranscoder/log.cpp | 87 +- src/AvTranscoder/log.hpp | 75 +- src/AvTranscoder/profile/ProfileLoader.cpp | 319 +++--- src/AvTranscoder/profile/ProfileLoader.hpp | 91 +- src/AvTranscoder/profile/util.hpp | 123 ++- src/AvTranscoder/progress/ConsoleProgress.cpp | 18 +- src/AvTranscoder/progress/ConsoleProgress.hpp | 5 +- src/AvTranscoder/progress/IProgress.hpp | 23 +- .../progress/NoDisplayProgress.hpp | 9 +- .../properties/AttachementProperties.hpp | 10 +- .../properties/AudioProperties.cpp | 201 ++-- .../properties/AudioProperties.hpp | 51 +- .../properties/DataProperties.cpp | 117 ++- .../properties/DataProperties.hpp | 10 +- .../properties/FileProperties.cpp | 521 +++++----- .../properties/FileProperties.hpp | 162 +-- src/AvTranscoder/properties/JsonWriter.cpp | 55 +- src/AvTranscoder/properties/JsonWriter.hpp | 129 +-- .../properties/PixelProperties.cpp | 472 +++++---- .../properties/PixelProperties.hpp | 121 ++- .../properties/StreamProperties.cpp | 158 ++- .../properties/StreamProperties.hpp | 65 +- .../properties/SubtitleProperties.hpp | 8 +- .../properties/UnknownProperties.hpp | 8 +- .../properties/VideoProperties.cpp | 804 ++++++++------- .../properties/VideoProperties.hpp | 170 +-- src/AvTranscoder/properties/print.cpp | 230 ++--- src/AvTranscoder/properties/print.hpp | 19 +- src/AvTranscoder/properties/util.cpp | 32 +- src/AvTranscoder/properties/util.hpp | 30 +- src/AvTranscoder/reader/AudioReader.cpp | 89 +- src/AvTranscoder/reader/AudioReader.hpp | 63 +- src/AvTranscoder/reader/IReader.cpp | 92 +- src/AvTranscoder/reader/IReader.hpp | 83 +- src/AvTranscoder/reader/VideoReader.cpp | 99 +- src/AvTranscoder/reader/VideoReader.hpp | 69 +- src/AvTranscoder/stat/AudioStat.hpp | 18 +- src/AvTranscoder/stat/ProcessStat.cpp | 9 +- src/AvTranscoder/stat/ProcessStat.hpp | 24 +- src/AvTranscoder/stat/VideoStat.cpp | 5 +- src/AvTranscoder/stat/VideoStat.hpp | 28 +- src/AvTranscoder/stream/IInputStream.hpp | 83 +- src/AvTranscoder/stream/IOutputStream.hpp | 62 +- src/AvTranscoder/stream/InputStream.cpp | 163 ++- src/AvTranscoder/stream/InputStream.hpp | 39 +- src/AvTranscoder/stream/OutputStream.cpp | 140 ++- src/AvTranscoder/stream/OutputStream.hpp | 41 +- src/AvTranscoder/system.hpp | 59 +- .../transcoder/StreamTranscoder.cpp | 968 +++++++++--------- .../transcoder/StreamTranscoder.hpp | 206 ++-- src/AvTranscoder/transcoder/Transcoder.cpp | 928 +++++++++-------- src/AvTranscoder/transcoder/Transcoder.hpp | 372 +++---- src/AvTranscoder/transform/AudioTransform.cpp | 135 +-- src/AvTranscoder/transform/AudioTransform.hpp | 27 +- src/AvTranscoder/transform/ITransform.hpp | 11 +- src/AvTranscoder/transform/VideoTransform.cpp | 124 ++- src/AvTranscoder/transform/VideoTransform.hpp | 25 +- src/AvTranscoder/util.cpp | 390 +++---- src/AvTranscoder/util.hpp | 21 +- 107 files changed, 7376 insertions(+), 7396 deletions(-) diff --git a/app/avInfo/avInfo.cpp b/app/avInfo/avInfo.cpp index 6cc6d0f0..5451193c 100644 --- a/app/avInfo/avInfo.cpp +++ b/app/avInfo/avInfo.cpp @@ -4,31 +4,32 @@ #include -int main( int argc, char** argv ) +int main(int argc, char** argv) { - avtranscoder::Libraries libs( avtranscoder::getLibraries() ); + avtranscoder::Libraries libs(avtranscoder::getLibraries()); - for( avtranscoder::Libraries::iterator library = libs.begin(); library != libs.end(); ++library ) - { - std::cout << std::left; - std::cout << std::setw( 15 ) << (*library).getName(); - std::cout << std::setw( 10 ) << (*library).getStringVersion(); - std::cout << std::setw( 30 ) << (*library).getLicense(); - std::cout << std::endl; - } + for(avtranscoder::Libraries::iterator library = libs.begin(); library != libs.end(); ++library) + { + std::cout << std::left; + std::cout << std::setw(15) << (*library).getName(); + std::cout << std::setw(10) << (*library).getStringVersion(); + std::cout << std::setw(30) << (*library).getLicense(); + std::cout << std::endl; + } - avtranscoder::preloadCodecsAndFormats(); + avtranscoder::preloadCodecsAndFormats(); - std::vector inputExtension = avtranscoder::getInputExtensions(); - std::vector outputExtension = avtranscoder::getOutputExtensions(); - - std::cout << "Supported input extensions: " << inputExtension.size() << std::endl; - for( std::vector::iterator it = inputExtension.begin(); it != inputExtension.end(); ++it ) - std::cout << *it << ", ";; - - std::cout << std::endl << std::endl << "Supported output extensions: " << outputExtension.size() << std::endl; - for( std::vector::iterator it = outputExtension.begin(); it != outputExtension.end(); ++it ) - std::cout << *it << ", "; - std::cout << std::endl; - return 0; + std::vector inputExtension = avtranscoder::getInputExtensions(); + std::vector outputExtension = avtranscoder::getOutputExtensions(); + + std::cout << "Supported input extensions: " << inputExtension.size() << std::endl; + for(std::vector::iterator it = inputExtension.begin(); it != inputExtension.end(); ++it) + std::cout << *it << ", "; + ; + + std::cout << std::endl << std::endl << "Supported output extensions: " << outputExtension.size() << std::endl; + for(std::vector::iterator it = outputExtension.begin(); it != outputExtension.end(); ++it) + std::cout << *it << ", "; + std::cout << std::endl; + return 0; } diff --git a/app/avMeta/avMeta.cpp b/app/avMeta/avMeta.cpp index 9aa0d2d3..f9439244 100644 --- a/app/avMeta/avMeta.cpp +++ b/app/avMeta/avMeta.cpp @@ -5,52 +5,52 @@ #include -int main( int argc, char** argv ) +int main(int argc, char** argv) { - bool toJson = false; - - std::string help; - help += "Usage\n"; - help += "\tavmeta INPUT_FILE [--json][--help]\n"; - help += "Command line options\n"; - help += "\t--json: print properties as json\n"; - - if( argc < 2 ) - { - std::cout << help << std::endl; - return( 1 ); - } - - // List command line arguments - std::vector< std::string > arguments; - for( int argument = 1; argument < argc; ++argument ) - { - arguments.push_back( argv[argument] ); - } - for( size_t argument = 0; argument < arguments.size(); ++argument ) - { - if( arguments.at( argument ) == "--help" ) - { - std::cout << help << std::endl; - return 0; - } - else if( arguments.at( argument ) == "--json" ) - { - toJson = true; - } - } - - avtranscoder::preloadCodecsAndFormats(); - avtranscoder::Logger::setLogLevel( AV_LOG_QUIET ); - - // analyse inputFile - avtranscoder::InputFile input( argv[1] ); - avtranscoder::NoDisplayProgress p; - input.analyse( p, avtranscoder::eAnalyseLevelFirstGop ); - - // display file properties - if( toJson ) - std::cout << input.getProperties().allPropertiesAsJson() << std::endl; - else - std::cout << input; + bool toJson = false; + + std::string help; + help += "Usage\n"; + help += "\tavmeta INPUT_FILE [--json][--help]\n"; + help += "Command line options\n"; + help += "\t--json: print properties as json\n"; + + if(argc < 2) + { + std::cout << help << std::endl; + return (1); + } + + // List command line arguments + std::vector arguments; + for(int argument = 1; argument < argc; ++argument) + { + arguments.push_back(argv[argument]); + } + for(size_t argument = 0; argument < arguments.size(); ++argument) + { + if(arguments.at(argument) == "--help") + { + std::cout << help << std::endl; + return 0; + } + else if(arguments.at(argument) == "--json") + { + toJson = true; + } + } + + avtranscoder::preloadCodecsAndFormats(); + avtranscoder::Logger::setLogLevel(AV_LOG_QUIET); + + // analyse inputFile + avtranscoder::InputFile input(argv[1]); + avtranscoder::NoDisplayProgress p; + input.analyse(p, avtranscoder::eAnalyseLevelFirstGop); + + // display file properties + if(toJson) + std::cout << input.getProperties().allPropertiesAsJson() << std::endl; + else + std::cout << input; } diff --git a/app/avPlay/Window.cpp b/app/avPlay/Window.cpp index fd611596..32e4f2f9 100644 --- a/app/avPlay/Window.cpp +++ b/app/avPlay/Window.cpp @@ -2,12 +2,12 @@ #include "Window.hpp" #ifdef __APPLE__ - #include - #include +#include +#include #else - #include - #include - #include +#include +#include +#include #endif #include @@ -20,8 +20,8 @@ size_t Window::_width = 0; size_t Window::_height = 0; int Window::_x1 = -1.0; -int Window::_x2 = 1.0; -int Window::_y1 = 1.0; +int Window::_x2 = 1.0; +int Window::_y1 = 1.0; int Window::_y2 = -1.0; int Window::_xMinViewport = 0; @@ -42,520 +42,538 @@ bool Window::_flip = false; bool Window::_flop = false; // channel properties -bool Window::_showRedChannel = false; +bool Window::_showRedChannel = false; bool Window::_showGreenChannel = false; -bool Window::_showBlueChannel = false; +bool Window::_showBlueChannel = false; bool Window::_showAlphaChannel = false; // image properties struct ImgProperties { - const char* data; - GLint internalFormat; - size_t width; - size_t height; - GLenum format; - GLenum type; - size_t component; + const char* data; + GLint internalFormat; + size_t width; + size_t height; + GLenum format; + GLenum type; + size_t component; }; ImgProperties _imageProperties; - -void loadNewTexture( const ImgProperties& properties ) +void loadNewTexture(const ImgProperties& properties) { - // loading texture - glTexImage2D( GL_TEXTURE_2D, 0, properties.internalFormat, properties.width, properties.height, 0, properties.format, properties.type, properties.data ); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + // loading texture + glTexImage2D(GL_TEXTURE_2D, 0, properties.internalFormat, properties.width, properties.height, 0, properties.format, + properties.type, properties.data); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); } -void loadNewTexture( const char* data, GLint internalFormat, size_t width, size_t height, GLenum format, GLenum type ) +void loadNewTexture(const char* data, GLint internalFormat, size_t width, size_t height, GLenum format, GLenum type) { - _imageProperties.data = data; - _imageProperties.internalFormat = internalFormat; - _imageProperties.width = width; - _imageProperties.height = height; - _imageProperties.format = format; - _imageProperties.type = type; - - switch( _imageProperties.format ) - { - case GL_LUMINANCE : _imageProperties.component = 1; break; - case GL_RGB : _imageProperties.component = 3; break; - case GL_RGBA : _imageProperties.component = 4; break; - } - - loadNewTexture( _imageProperties ); + _imageProperties.data = data; + _imageProperties.internalFormat = internalFormat; + _imageProperties.width = width; + _imageProperties.height = height; + _imageProperties.format = format; + _imageProperties.type = type; + + switch(_imageProperties.format) + { + case GL_LUMINANCE: + _imageProperties.component = 1; + break; + case GL_RGB: + _imageProperties.component = 3; + break; + case GL_RGBA: + _imageProperties.component = 4; + break; + } + + loadNewTexture(_imageProperties); } -Window::Window( avtranscoder::VideoReader& reader ) +Window::Window(avtranscoder::VideoReader& reader) { - _reader = &reader; - _width = _reader->getWidth(); - _height = _reader->getHeight(); - - char *argv[2] = { (char*)"", NULL }; - int argc = 1; - glutInit( &argc, argv ); - glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_RGBA | GLUT_MULTISAMPLE ); - glutInitWindowSize( _width, _height ); - glutInitWindowPosition( 0, 0 ); + _reader = &reader; + _width = _reader->getWidth(); + _height = _reader->getHeight(); + + char* argv[2] = {(char*)"", NULL}; + int argc = 1; + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_RGBA | GLUT_MULTISAMPLE); + glutInitWindowSize(_width, _height); + glutInitWindowPosition(0, 0); #ifdef GLUT_ACTION_ON_WINDOW_CLOSE - glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ); + glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); #endif - _windowId = glutCreateWindow("AV Player Viewer"); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f ); - glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + _windowId = glutCreateWindow("AV Player Viewer"); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - glutDisplayFunc ( display ); - glutKeyboardFunc( keyboard ); - glutSpecialFunc ( specialKeyboard ); - glutMouseFunc ( mouse ); - glutMotionFunc ( motion ); - glutReshapeFunc ( reshape ); + glutDisplayFunc(display); + glutKeyboardFunc(keyboard); + glutSpecialFunc(specialKeyboard); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutReshapeFunc(reshape); } void Window::launch() { - displayFirstFrame(); - glutMainLoop(); + displayFirstFrame(); + glutMainLoop(); } void Window::display() { - if( glutGetWindow() == 0 ) return; - glClearColor(0.0f, 0.0f, 0.0f, 0.0f ); - glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + if(glutGetWindow() == 0) + return; + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - glBegin (GL_QUADS); + glBegin(GL_QUADS); - float x1 = _x1; - float x2 = _x2; + float x1 = _x1; + float x2 = _x2; - float y1 = _y1; - float y2 = _y2; + float y1 = _y1; + float y2 = _y2; - if( _flip ) - { - y1 = -y1; - y2 = -y2; - } - if( _flop ) - { - x1 = -x1; - x2 = -x2; - } + if(_flip) + { + y1 = -y1; + y2 = -y2; + } + if(_flop) + { + x1 = -x1; + x2 = -x2; + } - glTexCoord2f( 0 , 0 ); - glVertex2f ( x1, y1 ); + glTexCoord2f(0, 0); + glVertex2f(x1, y1); - glTexCoord2f( 0, 1 ); - glVertex2f ( x1, y2 ); + glTexCoord2f(0, 1); + glVertex2f(x1, y2); - glTexCoord2f( 1, 1 ); - glVertex2f ( x2, y2 ); + glTexCoord2f(1, 1); + glVertex2f(x2, y2); - glTexCoord2f( 1, 0 ); - glVertex2f ( x2, y1 ); + glTexCoord2f(1, 0); + glVertex2f(x2, y1); - glEnd(); + glEnd(); - glutSwapBuffers(); + glutSwapBuffers(); } -void Window::keyboard( unsigned char k, int x, int y ) +void Window::keyboard(unsigned char k, int x, int y) { - bool shift= false; - if( glutGetModifiers() == GLUT_ACTIVE_SHIFT ) - { - shift = true; - } - - switch( k ) - { - case '\r': - glutDestroyWindow( _windowId ); - _windowId = 0; - break; - case 27: // ESCAPE key - glutDestroyWindow( _windowId ); - _windowId = 0; - break; - case 'i': - displayInformations(); - break; - case 'z': - glutReshapeWindow( _width, _height ); - _currentZoom = 1.0; - _x1 = -1.0; - _x2 = 1.0; - _y1 = 1.0; - _y2 = -1.0; - glutPostRedisplay(); - break; - case 'h': - displayHelp(); - break; - case 32: // spacebar - _play = ! _play; - loopPlaying(0); - break; - - case 'r': - showRedChannelTexture( ); - break; - case 'g': - showGreenChannelTexture( ); - break; - case 'b': - showBlueChannelTexture( ); - break; - case 'a': - showAlphaChannelTexture(); - break; - case 'H': - if( shift ) - { - _flop = ! _flop; - glutPostRedisplay(); - } - break; - case 'V': - if( shift ) - { - _flip = ! _flip; - glutPostRedisplay(); - } - break; - } + bool shift = false; + if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) + { + shift = true; + } + + switch(k) + { + case '\r': + glutDestroyWindow(_windowId); + _windowId = 0; + break; + case 27: // ESCAPE key + glutDestroyWindow(_windowId); + _windowId = 0; + break; + case 'i': + displayInformations(); + break; + case 'z': + glutReshapeWindow(_width, _height); + _currentZoom = 1.0; + _x1 = -1.0; + _x2 = 1.0; + _y1 = 1.0; + _y2 = -1.0; + glutPostRedisplay(); + break; + case 'h': + displayHelp(); + break; + case 32: // spacebar + _play = !_play; + loopPlaying(0); + break; + + case 'r': + showRedChannelTexture(); + break; + case 'g': + showGreenChannelTexture(); + break; + case 'b': + showBlueChannelTexture(); + break; + case 'a': + showAlphaChannelTexture(); + break; + case 'H': + if(shift) + { + _flop = !_flop; + glutPostRedisplay(); + } + break; + case 'V': + if(shift) + { + _flip = !_flip; + glutPostRedisplay(); + } + break; + } } -void Window::specialKeyboard( int k, int x, int y ) +void Window::specialKeyboard(int k, int x, int y) { - //std::cout << "k=" << k << " x=" << x << " y=" << y << std::endl; - switch (k) - { - case GLUT_KEY_UP: - // cursor move - break; - case GLUT_KEY_DOWN: - // cursor move - break; - case GLUT_KEY_LEFT: - // cursor move - displayPrevFrame(); - break; - case GLUT_KEY_RIGHT: - // cursor move - displayNextFrame(); - break; - case GLUT_KEY_HOME: - displayFirstFrame(); - case GLUT_KEY_END: - break; - case GLUT_KEY_F1: - displayHelp(); - break; - } + // std::cout << "k=" << k << " x=" << x << " y=" << y << std::endl; + switch(k) + { + case GLUT_KEY_UP: + // cursor move + break; + case GLUT_KEY_DOWN: + // cursor move + break; + case GLUT_KEY_LEFT: + // cursor move + displayPrevFrame(); + break; + case GLUT_KEY_RIGHT: + // cursor move + displayNextFrame(); + break; + case GLUT_KEY_HOME: + displayFirstFrame(); + case GLUT_KEY_END: + break; + case GLUT_KEY_F1: + displayHelp(); + break; + } } -void Window::mouse( int button, int state, int x, int y ) +void Window::mouse(int button, int state, int x, int y) { - if( state == 0 && button == 0 ) - { - int iX, iY; - - mapToImage(x, y, iX, iY); - - if( iX < 0 || iY < 0 || iX >= (int)_imageProperties.width || iY >= (int)_imageProperties.height ) - return; - - std::cout << "at " << std::setw(4) << iX << "," << std::setw(4) << (int)_imageProperties.height - iY << ": "; - - for( size_t i = 0; i < _imageProperties.component; i++ ) - { - size_t idx = ( iX + iY * _imageProperties.width ) * _imageProperties.component + i; - switch( _imageProperties.type ) - { - case GL_UNSIGNED_BYTE: - { - const unsigned char* d = (const unsigned char*) _imageProperties.data; - std::cout << std::setw(5) << (unsigned int) d[idx] ; - break; - } - case GL_UNSIGNED_SHORT: - { - const unsigned short* d = (const unsigned short*) _imageProperties.data; - std::cout << std::setw(7) << d[idx] ; - break; - } - case GL_FLOAT: - { - const float* d = (const float*) _imageProperties.data; - std::cout << std::setw(10) << d[idx] ; - break; - } - } - } - std::cout << std::endl; - } - if( state == 0 && ( button == 3 || button == 4 ) ) - { - int iX, iY, iX2, iY2; - - mapToImage(x, y, iX, iY); - - if(button == 3) - { - _currentZoom *= _factorZoom; - zoom( _factorZoom ); - } - else - { - _currentZoom /= _factorZoom; - zoom( 1.0 / _factorZoom ); - } - - mapToImage(x, y, iX2, iY2); - - move( ( _currentZoom / _imageProperties.width * 2) * (iX2 - iX), - ( _currentZoom / _imageProperties.height * 2) * (iY2 - iY)); - - glutPostRedisplay (); - } - - _xMouseRef = x; - _yMouseRef = y; + if(state == 0 && button == 0) + { + int iX, iY; + + mapToImage(x, y, iX, iY); + + if(iX < 0 || iY < 0 || iX >= (int)_imageProperties.width || iY >= (int)_imageProperties.height) + return; + + std::cout << "at " << std::setw(4) << iX << "," << std::setw(4) << (int)_imageProperties.height - iY << ": "; + + for(size_t i = 0; i < _imageProperties.component; i++) + { + size_t idx = (iX + iY * _imageProperties.width) * _imageProperties.component + i; + switch(_imageProperties.type) + { + case GL_UNSIGNED_BYTE: + { + const unsigned char* d = (const unsigned char*)_imageProperties.data; + std::cout << std::setw(5) << (unsigned int)d[idx]; + break; + } + case GL_UNSIGNED_SHORT: + { + const unsigned short* d = (const unsigned short*)_imageProperties.data; + std::cout << std::setw(7) << d[idx]; + break; + } + case GL_FLOAT: + { + const float* d = (const float*)_imageProperties.data; + std::cout << std::setw(10) << d[idx]; + break; + } + } + } + std::cout << std::endl; + } + if(state == 0 && (button == 3 || button == 4)) + { + int iX, iY, iX2, iY2; + + mapToImage(x, y, iX, iY); + + if(button == 3) + { + _currentZoom *= _factorZoom; + zoom(_factorZoom); + } + else + { + _currentZoom /= _factorZoom; + zoom(1.0 / _factorZoom); + } + + mapToImage(x, y, iX2, iY2); + + move((_currentZoom / _imageProperties.width * 2) * (iX2 - iX), + (_currentZoom / _imageProperties.height * 2) * (iY2 - iY)); + + glutPostRedisplay(); + } + + _xMouseRef = x; + _yMouseRef = y; } -void Window::motion( int x, int y ) +void Window::motion(int x, int y) { - float x_diff, y_diff; + float x_diff, y_diff; - x_diff = ( x - _xMouseRef ) / _currentZoom; - y_diff = ( _yMouseRef - y ) / _currentZoom; + x_diff = (x - _xMouseRef) / _currentZoom; + y_diff = (_yMouseRef - y) / _currentZoom; - if( _flip ) - { - y_diff *= -1.0; - } + if(_flip) + { + y_diff *= -1.0; + } - if( _flop ) - { - x_diff *= -1.0; - } + if(_flop) + { + x_diff *= -1.0; + } - move( _currentZoom / _imageProperties.width * 2 * x_diff, - _currentZoom / _imageProperties.height * 2 * y_diff ); + move(_currentZoom / _imageProperties.width * 2 * x_diff, _currentZoom / _imageProperties.height * 2 * y_diff); - _xMouseRef = x; - _yMouseRef = y; + _xMouseRef = x; + _yMouseRef = y; - glutPostRedisplay(); + glutPostRedisplay(); } -void Window::reshape( int width, int height ) +void Window::reshape(int width, int height) { - float w, h, xPos, yPos; - - if( (float) _width / _height > (float) width / height ) - { - w = width; - h = 1.0f * _height / _width * (float)width; - xPos = 0.0; - yPos = 0.5f * (height - h); - } - else - { - w = 1.0f * _width / _height * (float)height; - h = height; - xPos = 0.5f * (width - w); - yPos = 0.0; - } - - _xMinViewport = xPos; - _yMinViewport = yPos; - - _scale = w / _width; - - glViewport( (GLsizei) xPos, (GLsizei) yPos, (GLsizei) w, (GLsizei) h ); - glutReshapeWindow( width, height ); + float w, h, xPos, yPos; + + if((float)_width / _height > (float)width / height) + { + w = width; + h = 1.0f * _height / _width * (float)width; + xPos = 0.0; + yPos = 0.5f * (height - h); + } + else + { + w = 1.0f * _width / _height * (float)height; + h = height; + xPos = 0.5f * (width - w); + yPos = 0.0; + } + + _xMinViewport = xPos; + _yMinViewport = yPos; + + _scale = w / _width; + + glViewport((GLsizei)xPos, (GLsizei)yPos, (GLsizei)w, (GLsizei)h); + glutReshapeWindow(width, height); } void Window::displayHelp() { - static const std::string kViewerHelp = - "Av Player Viewer Help\n" \ - "i : information about image (dimensions, bit depth, channels) + video stream\n"\ - "z : zoom view to 1:1\n"\ - "h, F1 : print help\n" \ - "SHIFT + V : flip\n" \ - "SHIFT + H : flop\n" \ - "clic on image : print RGBA values\n" \ - "ESC, Return, Space : quit and continue process"; - std::cout << kViewerHelp << std::endl; + static const std::string kViewerHelp = + "Av Player Viewer Help\n" + "i : information about image (dimensions, bit depth, channels) + video stream\n" + "z : zoom view to 1:1\n" + "h, F1 : print help\n" + "SHIFT + V : flip\n" + "SHIFT + H : flop\n" + "clic on image : print RGBA values\n" + "ESC, Return, Space : quit and continue process"; + std::cout << kViewerHelp << std::endl; } void Window::displayInformations() { - std::string textureType; - switch( _imageProperties.format ) - { - case GL_LUMINANCE : textureType = "Gray "; break; - case GL_RGB : textureType = "RGB "; break; - case GL_RGBA : textureType = "RGBA "; break; - } - switch( _imageProperties.type ) - { - case GL_UNSIGNED_BYTE : textureType += "8 bits"; break; - case GL_UNSIGNED_SHORT : textureType += "16 bits"; break; - case GL_FLOAT : textureType += "32 float"; break; - } - std::cout << textureType << " " << _width << "x" << _height << std::endl; - - // stream info - _reader->printInfo(); + std::string textureType; + switch(_imageProperties.format) + { + case GL_LUMINANCE: + textureType = "Gray "; + break; + case GL_RGB: + textureType = "RGB "; + break; + case GL_RGBA: + textureType = "RGBA "; + break; + } + switch(_imageProperties.type) + { + case GL_UNSIGNED_BYTE: + textureType += "8 bits"; + break; + case GL_UNSIGNED_SHORT: + textureType += "16 bits"; + break; + case GL_FLOAT: + textureType += "32 float"; + break; + } + std::cout << textureType << " " << _width << "x" << _height << std::endl; + + // stream info + _reader->printInfo(); } -void Window::move( float x, float y ) +void Window::move(float x, float y) { - _x1 += x; - _x2 += x; - _y1 += y; - _y2 += y; + _x1 += x; + _x2 += x; + _y1 += y; + _y2 += y; } void Window::zoom(float factor) { - _x1 *= factor; - _x2 *= factor; - _y1 *= factor; - _y2 *= factor; + _x1 *= factor; + _x2 *= factor; + _y1 *= factor; + _y2 *= factor; } -void Window::mapToImage(int x, int y, int &iX, int &iY) +void Window::mapToImage(int x, int y, int& iX, int& iY) { - int mapX, mapY; - float mx, my; + int mapX, mapY; + float mx, my; - mapX = ( x - _xMinViewport ) / _scale; - mapY = ( y - _yMinViewport ) / _scale; + mapX = (x - _xMinViewport) / _scale; + mapY = (y - _yMinViewport) / _scale; - if( ! _flip ) - { - mapY = _imageProperties.height - mapY; - } + if(!_flip) + { + mapY = _imageProperties.height - mapY; + } - if( _flop ) - { - mapX = _imageProperties.width - mapX; - } + if(_flop) + { + mapX = _imageProperties.width - mapX; + } - mx = (float)mapX / (float)_imageProperties.width * 2.0 - 1.0; - iX = ((_x1 - mx) / (_currentZoom * 2.0) * (float)_imageProperties.width * -1.0) + 0.5; + mx = (float)mapX / (float)_imageProperties.width * 2.0 - 1.0; + iX = ((_x1 - mx) / (_currentZoom * 2.0) * (float)_imageProperties.width * -1.0) + 0.5; - my = (float)mapY / (float)_imageProperties.height * 2.0 - 1.0; - iY = ((_y1 - my) / (_currentZoom * 2.0) * (float)_imageProperties.height * -1.0) + 0.5; + my = (float)mapY / (float)_imageProperties.height * 2.0 - 1.0; + iY = ((_y1 - my) / (_currentZoom * 2.0) * (float)_imageProperties.height * -1.0) + 0.5; } -void Window::setTransfert( float red, float green, float blue, float alpha ) +void Window::setTransfert(float red, float green, float blue, float alpha) { - switch( _imageProperties.format ) - { - case GL_LUMINANCE : - return; - case GL_RGB : - glPixelTransferf( GL_RED_SCALE, red ); - glPixelTransferf( GL_GREEN_SCALE, green ); - glPixelTransferf( GL_BLUE_SCALE, blue ); - break; - case GL_RGBA : - glPixelTransferf( GL_RED_SCALE, red ); - glPixelTransferf( GL_GREEN_SCALE, green ); - glPixelTransferf( GL_BLUE_SCALE, blue ); - glPixelTransferf( GL_ALPHA_SCALE, alpha ); - break; - } + switch(_imageProperties.format) + { + case GL_LUMINANCE: + return; + case GL_RGB: + glPixelTransferf(GL_RED_SCALE, red); + glPixelTransferf(GL_GREEN_SCALE, green); + glPixelTransferf(GL_BLUE_SCALE, blue); + break; + case GL_RGBA: + glPixelTransferf(GL_RED_SCALE, red); + glPixelTransferf(GL_GREEN_SCALE, green); + glPixelTransferf(GL_BLUE_SCALE, blue); + glPixelTransferf(GL_ALPHA_SCALE, alpha); + break; + } } -void Window::displayChannelTexture( bool& channel, const float red, const float green, const float blue ) +void Window::displayChannelTexture(bool& channel, const float red, const float green, const float blue) { - ImgProperties p = _imageProperties; - if( ! channel ) - { - setTransfert( red, green, blue ); - _showRedChannel = false; - _showGreenChannel = false; - _showBlueChannel = false; - _showAlphaChannel = false; - channel = true; - } - else - { - setTransfert( 1.f, 1.f, 1.f ); - channel = false; - } - loadNewTexture( p ); - - glutPostRedisplay(); + ImgProperties p = _imageProperties; + if(!channel) + { + setTransfert(red, green, blue); + _showRedChannel = false; + _showGreenChannel = false; + _showBlueChannel = false; + _showAlphaChannel = false; + channel = true; + } + else + { + setTransfert(1.f, 1.f, 1.f); + channel = false; + } + loadNewTexture(p); + + glutPostRedisplay(); } -void Window::showRedChannelTexture( ) +void Window::showRedChannelTexture() { - displayChannelTexture( _showRedChannel, 1.f, 0.f, 0.f ); + displayChannelTexture(_showRedChannel, 1.f, 0.f, 0.f); } -void Window::showGreenChannelTexture( ) +void Window::showGreenChannelTexture() { - displayChannelTexture( _showGreenChannel, 0.f, 1.f, 0.f ); + displayChannelTexture(_showGreenChannel, 0.f, 1.f, 0.f); } -void Window::showBlueChannelTexture( ) +void Window::showBlueChannelTexture() { - displayChannelTexture( _showBlueChannel, 0.f, 0.f, 1.f ); + displayChannelTexture(_showBlueChannel, 0.f, 0.f, 1.f); } -void Window::showAlphaChannelTexture( ) +void Window::showAlphaChannelTexture() { - glutPostRedisplay (); + glutPostRedisplay(); } void Window::displayNextFrame() { - const char* buffer = (const char*)_reader->readNextFrame()->getData(); - loadNewTexture( buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE ); - display(); + const char* buffer = (const char*)_reader->readNextFrame()->getData(); + loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE); + display(); } void Window::displayPrevFrame() { - const char* buffer = (const char*)_reader->readPrevFrame()->getData(); - loadNewTexture( buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE ); - display(); + const char* buffer = (const char*)_reader->readPrevFrame()->getData(); + loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE); + display(); } void Window::displayFirstFrame() { - displayAtFrame( 0 ); + displayAtFrame(0); } -void Window::displayAtFrame( const size_t frame ) +void Window::displayAtFrame(const size_t frame) { - const char* buffer = (const char*)_reader->readFrameAt( frame )->getData(); - loadNewTexture( buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE ); - display(); + const char* buffer = (const char*)_reader->readFrameAt(frame)->getData(); + loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE); + display(); } -void Window::loopPlaying( int value ) +void Window::loopPlaying(int value) { - if( _play ) - glutTimerFunc( 40, &loopPlaying, 0 ); - displayNextFrame(); + if(_play) + glutTimerFunc(40, &loopPlaying, 0); + displayNextFrame(); } diff --git a/app/avPlay/Window.hpp b/app/avPlay/Window.hpp index c7c45e01..9f1ecb2e 100644 --- a/app/avPlay/Window.hpp +++ b/app/avPlay/Window.hpp @@ -8,74 +8,73 @@ class Window { public: - Window( avtranscoder::VideoReader& reader ); + Window(avtranscoder::VideoReader& reader); - void launch(); + void launch(); private: + static void display(); + static void keyboard(unsigned char k, int x, int y); + static void specialKeyboard(int k, int x, int y); + static void mouse(int button, int state, int x, int y); + static void motion(int x, int y); + static void reshape(int width, int height); - static void display(); - static void keyboard( unsigned char k, int x, int y ); - static void specialKeyboard( int k, int x, int y ); - static void mouse( int button, int state, int x, int y ); - static void motion( int x, int y ); - static void reshape( int width, int height ); + static void displayHelp(); + static void displayInformations(); + static void move(float x, float y); + static void zoom(float factor); + static void mapToImage(int x, int y, int& iX, int& iY); - static void displayHelp(); - static void displayInformations(); - static void move( float x, float y ); - static void zoom(float factor); - static void mapToImage(int x, int y, int &iX, int &iY); + static void setTransfert(float red, float green, float blue, float alpha = 1.f); - static void setTransfert( float red, float green, float blue, float alpha=1.f ); + static void displayChannelTexture(bool& channel, const float red, const float green, const float blue); - static void displayChannelTexture( bool& channel, const float red, const float green, const float blue ); + static void showRedChannelTexture(); + static void showGreenChannelTexture(); + static void showBlueChannelTexture(); + static void showAlphaChannelTexture(); - static void showRedChannelTexture(); - static void showGreenChannelTexture(); - static void showBlueChannelTexture(); - static void showAlphaChannelTexture(); + static void displayNextFrame(); + static void displayPrevFrame(); + static void displayFirstFrame(); + static void displayAtFrame(const size_t frame); - static void displayNextFrame(); - static void displayPrevFrame(); - static void displayFirstFrame(); - static void displayAtFrame( const size_t frame ); + static void loopPlaying(int value); - static void loopPlaying( int value ); + static avtranscoder::VideoReader* _reader; - static avtranscoder::VideoReader* _reader; + static size_t _width; + static size_t _height; - static size_t _width; - static size_t _height; + static int _x1; + static int _x2; + static int _y1; + static int _y2; - static int _x1; - static int _x2; - static int _y1; - static int _y2; + static int _xMinViewport; + static int _yMinViewport; - static int _xMinViewport; - static int _yMinViewport; + static int _xMouseRef; + static int _yMouseRef; - static int _xMouseRef; - static int _yMouseRef; + static int _windowId; - static int _windowId; + // viewing properties - zoom + static float _currentZoom; + static float _factorZoom; - // viewing properties - zoom - static float _currentZoom; - static float _factorZoom; + static float _scale; - static float _scale; + static bool _play; - static bool _play; - - static bool _flip; - static bool _flop; + static bool _flip; + static bool _flop; - static bool _showRedChannel; - static bool _showGreenChannel; - static bool _showBlueChannel; - static bool _showAlphaChannel; + static bool _showRedChannel; + static bool _showGreenChannel; + static bool _showBlueChannel; + static bool _showAlphaChannel; }; #endif \ No newline at end of file diff --git a/app/avPlay/main.cpp b/app/avPlay/main.cpp index 132dc55f..4dbb0e9a 100644 --- a/app/avPlay/main.cpp +++ b/app/avPlay/main.cpp @@ -3,22 +3,21 @@ #include "Window.hpp" - -int main( int argc, char** argv ) +int main(int argc, char** argv) { - avtranscoder::preloadCodecsAndFormats(); + avtranscoder::preloadCodecsAndFormats(); + + if(argc < 2) + { + std::cout << "avplay can play the given video media file." << std::endl; + std::cout << "Provide the filename and the streamIndex (0 by default)" << std::endl; + return (-1); + } - if(argc < 2) - { - std::cout << "avplay can play the given video media file." << std::endl; - std::cout << "Provide the filename and the streamIndex (0 by default)" << std::endl; - return( -1 ); - } + const std::string filename(argv[1]); + const size_t streamIndex = argc > 2 ? atoi(argv[2]) : 0; - const std::string filename(argv[1]); - const size_t streamIndex = argc > 2 ? atoi(argv[2]) : 0; - - avtranscoder::VideoReader reader( filename, streamIndex ); - Window window( reader ); - window.launch(); + avtranscoder::VideoReader reader(filename, streamIndex); + Window window(reader); + window.launch(); } diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 0660a4a5..fe94420f 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -21,141 +21,141 @@ static const std::string dummyAudioCodec = "pcm_s16le"; static bool useVideoGenerator = false; -void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder& transcoder ) +void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder& transcoder) { - std::ifstream configFile( configFilename.c_str(), std::ifstream::in ); - - std::string line; - while( std::getline( configFile, line ) ) - { - std::istringstream is_line( line ); - std::string filename; - if( std::getline( is_line, filename, '=' ) ) - { - std::string streamId; - if( std::getline( is_line, streamId, ':' ) ) - { - std::string transcodeProfile; - std::getline( is_line, transcodeProfile ); - - std::stringstream ss( streamId ); - size_t streamIndex = 0; - char separator; - int subStreamIndex = -1; - ss >> streamIndex; - ss >> separator; - if( separator == '.' ) - ss >> subStreamIndex; - - // dummy stream, need a ICodec (audio or video) - if( ! filename.length() ) - { - if( useVideoGenerator ) - { - // video - avtranscoder::VideoCodec inputCodec( avtranscoder::eCodecTypeEncoder, dummyVideoCodec ); - avtranscoder::VideoFrameDesc imageDesc( dummyWidth, dummyHeight, dummyPixelFormat ); - inputCodec.setImageParameters( imageDesc ); - - transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec ); - } - else - { - // audio - avtranscoder::AudioCodec inputCodec( avtranscoder::eCodecTypeEncoder, dummyAudioCodec ); - avtranscoder::AudioFrameDesc audioDesc( dummySampleRate, dummyChannels, dummySampleFormat ); - inputCodec.setAudioParameters( audioDesc ); - - transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec ); - } - } - else - { - transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile ); - } - } - } - } - - configFile.close(); + std::ifstream configFile(configFilename.c_str(), std::ifstream::in); + + std::string line; + while(std::getline(configFile, line)) + { + std::istringstream is_line(line); + std::string filename; + if(std::getline(is_line, filename, '=')) + { + std::string streamId; + if(std::getline(is_line, streamId, ':')) + { + std::string transcodeProfile; + std::getline(is_line, transcodeProfile); + + std::stringstream ss(streamId); + size_t streamIndex = 0; + char separator; + int subStreamIndex = -1; + ss >> streamIndex; + ss >> separator; + if(separator == '.') + ss >> subStreamIndex; + + // dummy stream, need a ICodec (audio or video) + if(!filename.length()) + { + if(useVideoGenerator) + { + // video + avtranscoder::VideoCodec inputCodec(avtranscoder::eCodecTypeEncoder, dummyVideoCodec); + avtranscoder::VideoFrameDesc imageDesc(dummyWidth, dummyHeight, dummyPixelFormat); + inputCodec.setImageParameters(imageDesc); + + transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec); + } + else + { + // audio + avtranscoder::AudioCodec inputCodec(avtranscoder::eCodecTypeEncoder, dummyAudioCodec); + avtranscoder::AudioFrameDesc audioDesc(dummySampleRate, dummyChannels, dummySampleFormat); + inputCodec.setAudioParameters(audioDesc); + + transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec); + } + } + else + { + transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile); + } + } + } + } + + configFile.close(); } -int main( int argc, char** argv ) +int main(int argc, char** argv) { - std::string help; - help += "Usage\n"; - help += "\tavprocessor CONFIG.TXT OUTPUT_FILE_NAME [--generate-black] [--verbose] [--logFile] [--help]\n"; - help += "CONFIG.TXT\n"; - help += "\tEach line will be one stream in the output.\n"; - help += "\tPattern of each line is:\n"; - help += "\t[inputFile]=STREAM_ID.[subStreamId]:[profileName]\n"; - help += "\tNo inputFile: will generate black image / audio silence (audio by default)\n"; - help += "\tNo subStreamId: will process of channels of the stream\n"; - help += "\tNo profileName: will rewrap the stream\n"; - help += "Command line options\n"; - help += "\t--generate-black: stream which not referred to an input, will generate an output video stream with black images (by default generate audio stream with silence)\n"; - help += "\t--verbose: set log level to AV_LOG_DEBUG\n"; - help += "\t--logFile: put log in 'avtranscoder.log' file\n"; - help += "\t--help: display this help\n"; - - // Preload FFmpeg context - avtranscoder::preloadCodecsAndFormats(); - avtranscoder::Logger::setLogLevel( AV_LOG_QUIET ); - - // List command line arguments - std::vector< std::string > arguments; - for( int argument = 1; argument < argc; ++argument ) - { - arguments.push_back( argv[argument] ); - } - for( size_t argument = 0; argument < arguments.size(); ++argument ) - { - if( arguments.at( argument ) == "--help" ) - { - std::cout << help << std::endl; - return 0; - } - else if( arguments.at( argument ) == "--generate-black" ) - { - useVideoGenerator = true; - } - else if( arguments.at( argument ) == "--verbose" ) - { - avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG ); - } - else if( arguments.at( argument ) == "--logFile" ) - { - avtranscoder::Logger::logInFile(); - } - } - - // Check required arguments - if( argc < 3 ) - { - std::cout << "avprocessor can rewrap or transcode inputs to create an output media file." << std::endl; - std::cout << "Use option --help to display help" << std::endl; - return( -1 ); - } - - try - { - std::string inputConfigFile( argv[1] ); - avtranscoder::OutputFile outputFile( argv[2] ); - - avtranscoder::Transcoder transcoder( outputFile ); - - parseConfigFile( inputConfigFile, transcoder ); - - avtranscoder::ConsoleProgress progress; - transcoder.process( progress ); - } - catch( std::exception& e ) - { - std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl; - } - catch( ... ) - { - std::cerr << "ERROR: during process, an unknown error occured" << std::endl; - } - + std::string help; + help += "Usage\n"; + help += "\tavprocessor CONFIG.TXT OUTPUT_FILE_NAME [--generate-black] [--verbose] [--logFile] [--help]\n"; + help += "CONFIG.TXT\n"; + help += "\tEach line will be one stream in the output.\n"; + help += "\tPattern of each line is:\n"; + help += "\t[inputFile]=STREAM_ID.[subStreamId]:[profileName]\n"; + help += "\tNo inputFile: will generate black image / audio silence (audio by default)\n"; + help += "\tNo subStreamId: will process of channels of the stream\n"; + help += "\tNo profileName: will rewrap the stream\n"; + help += "Command line options\n"; + help += "\t--generate-black: stream which not referred to an input, will generate an output video stream with black " + "images (by default generate audio stream with silence)\n"; + help += "\t--verbose: set log level to AV_LOG_DEBUG\n"; + help += "\t--logFile: put log in 'avtranscoder.log' file\n"; + help += "\t--help: display this help\n"; + + // Preload FFmpeg context + avtranscoder::preloadCodecsAndFormats(); + avtranscoder::Logger::setLogLevel(AV_LOG_QUIET); + + // List command line arguments + std::vector arguments; + for(int argument = 1; argument < argc; ++argument) + { + arguments.push_back(argv[argument]); + } + for(size_t argument = 0; argument < arguments.size(); ++argument) + { + if(arguments.at(argument) == "--help") + { + std::cout << help << std::endl; + return 0; + } + else if(arguments.at(argument) == "--generate-black") + { + useVideoGenerator = true; + } + else if(arguments.at(argument) == "--verbose") + { + avtranscoder::Logger::setLogLevel(AV_LOG_DEBUG); + } + else if(arguments.at(argument) == "--logFile") + { + avtranscoder::Logger::logInFile(); + } + } + + // Check required arguments + if(argc < 3) + { + std::cout << "avprocessor can rewrap or transcode inputs to create an output media file." << std::endl; + std::cout << "Use option --help to display help" << std::endl; + return (-1); + } + + try + { + std::string inputConfigFile(argv[1]); + avtranscoder::OutputFile outputFile(argv[2]); + + avtranscoder::Transcoder transcoder(outputFile); + + parseConfigFile(inputConfigFile, transcoder); + + avtranscoder::ConsoleProgress progress; + transcoder.process(progress); + } + catch(std::exception& e) + { + std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl; + } + catch(...) + { + std::cerr << "ERROR: during process, an unknown error occured" << std::endl; + } } diff --git a/src/AvTranscoder/Library.cpp b/src/AvTranscoder/Library.cpp index 4dc10915..299512ab 100644 --- a/src/AvTranscoder/Library.cpp +++ b/src/AvTranscoder/Library.cpp @@ -6,9 +6,9 @@ extern "C" { #include #include #ifdef AVTRANSCODER_LIBAV_DEPENDENCY - #include +#include #else - #include +#include #endif #include } @@ -20,150 +20,157 @@ extern "C" { namespace avtranscoder { -Library::Library( const std::string& name, const std::string& license, const size_t major, const size_t minor, const size_t release ) - : _name( name ) - , _licence( license ) - , _major( major ) - , _minor( minor ) - , _release( release ) +Library::Library(const std::string& name, const std::string& license, const size_t major, const size_t minor, + const size_t release) + : _name(name) + , _licence(license) + , _major(major) + , _minor(minor) + , _release(release) { } std::string Library::getName() { - return _name; + return _name; } std::vector Library::getVersion() { - std::vector version; - version.push_back( _major ); - version.push_back( _minor ); - version.push_back( _release ); - return version; + std::vector version; + version.push_back(_major); + version.push_back(_minor); + version.push_back(_release); + return version; } std::string Library::getStringVersion() { - std::stringstream version; - version << _major << "."; - version << _minor << "."; - version << _release; - return version.str(); + std::stringstream version; + version << _major << "."; + version << _minor << "."; + version << _release; + return version.str(); } size_t Library::getMajorVersion() { - return _major; + return _major; } size_t Library::getMinorVersion() { - return _minor; + return _minor; } size_t Library::getReleaseVersion() { - return _release; + return _release; } std::string Library::getLicense() { - return _licence; + return _licence; } Libraries getLibraries() { - Libraries libs; - - libs.push_back( Library( "avtranscoder", "GPL or LGPL version 3", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR, AVTRANSCODER_VERSION_MICRO ) ); - libs.push_back( Library( "avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO ) ); - libs.push_back( Library( "avformat", avformat_license(), LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO ) ); - libs.push_back( Library( "avcodec", avcodec_license(), LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO ) ); + Libraries libs; + + libs.push_back(Library("avtranscoder", "GPL or LGPL version 3", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR, + AVTRANSCODER_VERSION_MICRO)); + libs.push_back( + Library("avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO)); + libs.push_back(Library("avformat", avformat_license(), LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, + LIBAVFORMAT_VERSION_MICRO)); + libs.push_back( + Library("avcodec", avcodec_license(), LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO)); #ifdef AVTRANSCODER_LIBAV_DEPENDENCY - libs.push_back( Library( "avresample", avutil_license(), LIBAVRESAMPLE_VERSION_MAJOR, LIBAVRESAMPLE_VERSION_MINOR, LIBAVRESAMPLE_VERSION_MICRO ) ); + libs.push_back(Library("avresample", avutil_license(), LIBAVRESAMPLE_VERSION_MAJOR, LIBAVRESAMPLE_VERSION_MINOR, + LIBAVRESAMPLE_VERSION_MICRO)); #else - libs.push_back( Library( "swresample", avutil_license(), LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO ) ); + libs.push_back(Library("swresample", avutil_license(), LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, + LIBSWRESAMPLE_VERSION_MICRO)); #endif - libs.push_back( Library( "swscale", swscale_license(), LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO ) ); + libs.push_back( + Library("swscale", swscale_license(), LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO)); - return libs; + return libs; } std::vector getInputExtensions() { - std::vector extensions; - AVInputFormat* iFormat = NULL; - - while( ( iFormat = av_iformat_next( iFormat ) ) ) - { - if( iFormat->extensions != NULL ) - { - // parse extensions - std::string exts = std::string( iFormat->extensions ); - char* ext = strtok( const_cast( exts.c_str() ), "," ); - while( ext != NULL ) - { - extensions.push_back( std::string( ext ) ); - ext = strtok( NULL, "," ); - } - - // parse name (name's format defines (in general) extensions ) - // don't need to do it in recent LibAV/FFMpeg versions - exts = std::string( iFormat->name ); - ext = strtok( const_cast( exts.c_str() ), "," ); - while( ext != NULL ) - { - extensions.push_back( std::string( ext ) ); - ext = strtok( NULL, "," ); - } - } - } - // sort - std::sort( extensions.begin(), extensions.end() ); - // suppress duplicates - std::vector::iterator last = std::unique( extensions.begin(), extensions.end() ); - extensions.erase( last, extensions.end() ); - - return extensions; + std::vector extensions; + AVInputFormat* iFormat = NULL; + + while((iFormat = av_iformat_next(iFormat))) + { + if(iFormat->extensions != NULL) + { + // parse extensions + std::string exts = std::string(iFormat->extensions); + char* ext = strtok(const_cast(exts.c_str()), ","); + while(ext != NULL) + { + extensions.push_back(std::string(ext)); + ext = strtok(NULL, ","); + } + + // parse name (name's format defines (in general) extensions ) + // don't need to do it in recent LibAV/FFMpeg versions + exts = std::string(iFormat->name); + ext = strtok(const_cast(exts.c_str()), ","); + while(ext != NULL) + { + extensions.push_back(std::string(ext)); + ext = strtok(NULL, ","); + } + } + } + // sort + std::sort(extensions.begin(), extensions.end()); + // suppress duplicates + std::vector::iterator last = std::unique(extensions.begin(), extensions.end()); + extensions.erase(last, extensions.end()); + + return extensions; } std::vector getOutputExtensions() { - std::vector extensions; - AVOutputFormat* oFormat = NULL; - - while( ( oFormat = av_oformat_next( oFormat ) ) ) - { - if( oFormat->extensions != NULL ) - { - // parse extensions - std::string exts = std::string( oFormat->extensions ); - char* ext = strtok( const_cast( exts.c_str() ), "," ); - while( ext != NULL ) - { - extensions.push_back( std::string( ext ) ); - ext = strtok( NULL, "," ); - } - - // parse name (name's format defines (in general) extensions ) - // don't need to do it in recent LibAV/FFMpeg versions - exts = std::string( oFormat->name ); - ext = strtok( const_cast( exts.c_str() ), "," ); - while( ext != NULL ) - { - extensions.push_back( std::string( ext ) ); - ext = strtok( NULL, "," ); - } - } - } - // sort - std::sort( extensions.begin(), extensions.end() ); - // suppress duplicates - std::vector::iterator last = std::unique( extensions.begin(), extensions.end() ); - extensions.erase( last, extensions.end() ); - - return extensions; + std::vector extensions; + AVOutputFormat* oFormat = NULL; + + while((oFormat = av_oformat_next(oFormat))) + { + if(oFormat->extensions != NULL) + { + // parse extensions + std::string exts = std::string(oFormat->extensions); + char* ext = strtok(const_cast(exts.c_str()), ","); + while(ext != NULL) + { + extensions.push_back(std::string(ext)); + ext = strtok(NULL, ","); + } + + // parse name (name's format defines (in general) extensions ) + // don't need to do it in recent LibAV/FFMpeg versions + exts = std::string(oFormat->name); + ext = strtok(const_cast(exts.c_str()), ","); + while(ext != NULL) + { + extensions.push_back(std::string(ext)); + ext = strtok(NULL, ","); + } + } + } + // sort + std::sort(extensions.begin(), extensions.end()); + // suppress duplicates + std::vector::iterator last = std::unique(extensions.begin(), extensions.end()); + extensions.erase(last, extensions.end()); + + return extensions; } - } diff --git a/src/AvTranscoder/Library.hpp b/src/AvTranscoder/Library.hpp index 82219878..a1a71588 100644 --- a/src/AvTranscoder/Library.hpp +++ b/src/AvTranscoder/Library.hpp @@ -12,33 +12,34 @@ namespace avtranscoder class AvExport Library { public: - Library( const std::string& name, const std::string& license, const size_t major, const size_t minor, const size_t release ); + Library(const std::string& name, const std::string& license, const size_t major, const size_t minor, + const size_t release); - std::string getName(); + std::string getName(); - std::vector getVersion(); - std::string getStringVersion(); - size_t getMajorVersion(); - size_t getMinorVersion(); - size_t getReleaseVersion(); + std::vector getVersion(); + std::string getStringVersion(); + size_t getMajorVersion(); + size_t getMinorVersion(); + size_t getReleaseVersion(); + + std::string getLicense(); - std::string getLicense(); private: - std::string _name; - std::string _licence; - size_t _major; - size_t _minor; - size_t _release; + std::string _name; + std::string _licence; + size_t _major; + size_t _minor; + size_t _release; }; -typedef std::vector< Library > Libraries; +typedef std::vector Libraries; Libraries AvExport getLibraries(); std::vector AvExport getInputExtensions(); std::vector AvExport getOutputExtensions(); - } #endif diff --git a/src/AvTranscoder/Option.cpp b/src/AvTranscoder/Option.cpp index a6a6e48b..bd016ff8 100644 --- a/src/AvTranscoder/Option.cpp +++ b/src/AvTranscoder/Option.cpp @@ -11,294 +11,293 @@ extern "C" { namespace avtranscoder { -Option::Option( AVOption& avOption, void* avContext ) - : _avOption( &avOption ) - , _avContext( avContext ) - , _childOptions() - , _defaultChildIndex( 0 ) +Option::Option(AVOption& avOption, void* avContext) + : _avOption(&avOption) + , _avContext(avContext) + , _childOptions() + , _defaultChildIndex(0) { - _type = getTypeFromAVOption( getUnit(), _avOption->type ); + _type = getTypeFromAVOption(getUnit(), _avOption->type); } -EOptionBaseType Option::getTypeFromAVOption( const std::string& unit, const AVOptionType avType ) +EOptionBaseType Option::getTypeFromAVOption(const std::string& unit, const AVOptionType avType) { - if( ! unit.empty() && avType == AV_OPT_TYPE_FLAGS ) - return eOptionBaseTypeGroup; - else if( ! unit.empty() && ( avType == AV_OPT_TYPE_INT || avType == AV_OPT_TYPE_INT64 ) ) - return eOptionBaseTypeChoice; - else if( ! unit.empty() && avType == AV_OPT_TYPE_CONST ) - return eOptionBaseTypeChild; - - switch( avType ) - { - case AV_OPT_TYPE_FLAGS: - { - return eOptionBaseTypeBool; - } - case AV_OPT_TYPE_INT: - case AV_OPT_TYPE_INT64: - { - return eOptionBaseTypeInt; - } - case AV_OPT_TYPE_DOUBLE: - case AV_OPT_TYPE_FLOAT: - { - return eOptionBaseTypeDouble; - } - case AV_OPT_TYPE_STRING: - case AV_OPT_TYPE_BINARY: - { - return eOptionBaseTypeString; - } - case AV_OPT_TYPE_RATIONAL: - { - return eOptionBaseTypeRatio; - } - default: - { - return eOptionBaseTypeUnknown; - } - } - return eOptionBaseTypeUnknown; + if(!unit.empty() && avType == AV_OPT_TYPE_FLAGS) + return eOptionBaseTypeGroup; + else if(!unit.empty() && (avType == AV_OPT_TYPE_INT || avType == AV_OPT_TYPE_INT64)) + return eOptionBaseTypeChoice; + else if(!unit.empty() && avType == AV_OPT_TYPE_CONST) + return eOptionBaseTypeChild; + + switch(avType) + { + case AV_OPT_TYPE_FLAGS: + { + return eOptionBaseTypeBool; + } + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_INT64: + { + return eOptionBaseTypeInt; + } + case AV_OPT_TYPE_DOUBLE: + case AV_OPT_TYPE_FLOAT: + { + return eOptionBaseTypeDouble; + } + case AV_OPT_TYPE_STRING: + case AV_OPT_TYPE_BINARY: + { + return eOptionBaseTypeString; + } + case AV_OPT_TYPE_RATIONAL: + { + return eOptionBaseTypeRatio; + } + default: + { + return eOptionBaseTypeUnknown; + } + } + return eOptionBaseTypeUnknown; } EOptionBaseType Option::getType() const { - return _type; + return _type; } bool Option::getDefaultBool() const { - return _avOption->default_val.i64; + return _avOption->default_val.i64; } int Option::getDefaultInt() const { - return _avOption->default_val.i64; + return _avOption->default_val.i64; } double Option::getDefaultDouble() const { - return _avOption->default_val.dbl; + return _avOption->default_val.dbl; } std::string Option::getDefaultString() const { - return std::string( _avOption->default_val.str ? _avOption->default_val.str : "" ); + return std::string(_avOption->default_val.str ? _avOption->default_val.str : ""); } std::pair Option::getDefaultRatio() const { - return std::make_pair( _avOption->default_val.q.num, _avOption->default_val.q.den ); + return std::make_pair(_avOption->default_val.q.num, _avOption->default_val.q.den); } bool Option::getBool() const { - int64_t out_val; - int error = av_opt_get_int( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val ); - checkFFmpegGetOption( error ); + int64_t out_val; + int error = av_opt_get_int(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val); + checkFFmpegGetOption(error); - return out_val ? true : false; + return out_val ? true : false; } int Option::getInt() const { - int64_t out_val; - int error = av_opt_get_int( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val ); - checkFFmpegGetOption( error ); + int64_t out_val; + int error = av_opt_get_int(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val); + checkFFmpegGetOption(error); - return out_val; + return out_val; } double Option::getDouble() const { - double out_val; - int error = av_opt_get_double( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val ); - checkFFmpegGetOption( error ); + double out_val; + int error = av_opt_get_double(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val); + checkFFmpegGetOption(error); - return out_val; + return out_val; } std::string Option::getString() const { - void* out_val = av_malloc( 128 ); - int error = av_opt_get( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, (uint8_t**)&out_val ); + void* out_val = av_malloc(128); + int error = av_opt_get(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, (uint8_t**)&out_val); - std::string strValue( out_val ? reinterpret_cast( out_val ) : "" ); + std::string strValue(out_val ? reinterpret_cast(out_val) : ""); - av_free( out_val ); + av_free(out_val); - checkFFmpegGetOption( error ); + checkFFmpegGetOption(error); - return strValue; + return strValue; } std::pair Option::getRatio() const { - Rational out_val; - int error = av_opt_get_q( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val ); - checkFFmpegGetOption( error ); + Rational out_val; + int error = av_opt_get_q(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val); + checkFFmpegGetOption(error); - return std::make_pair( out_val.num, out_val.den ); + return std::make_pair(out_val.num, out_val.den); } -void Option::setFlag( const std::string& flag, const bool enable ) +void Option::setFlag(const std::string& flag, const bool enable) { - int64_t optVal; - int error = av_opt_get_int( _avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &optVal ); - checkFFmpegGetOption( error ); + int64_t optVal; + int error = av_opt_get_int(_avContext, getName().c_str(), AV_OPT_SEARCH_CHILDREN, &optVal); + checkFFmpegGetOption(error); - if( enable ) - optVal = optVal | _avOption->default_val.i64; - else - optVal = optVal &~ _avOption->default_val.i64; + if(enable) + optVal = optVal | _avOption->default_val.i64; + else + optVal = optVal & ~_avOption->default_val.i64; - error = av_opt_set_int( _avContext, getName().c_str(), optVal, AV_OPT_SEARCH_CHILDREN ); - checkFFmpegSetOption( error, flag ); + error = av_opt_set_int(_avContext, getName().c_str(), optVal, AV_OPT_SEARCH_CHILDREN); + checkFFmpegSetOption(error, flag); } -void Option::setBool( const bool value ) +void Option::setBool(const bool value) { - int error = av_opt_set_int( _avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN ); + int error = av_opt_set_int(_avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN); - std::ostringstream os; - os << ( value ? "true" : "false" ); - checkFFmpegSetOption( error, os.str() ); + std::ostringstream os; + os << (value ? "true" : "false"); + checkFFmpegSetOption(error, os.str()); } -void Option::setInt( const int value ) +void Option::setInt(const int value) { - int error = av_opt_set_int( _avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN ); + int error = av_opt_set_int(_avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN); - std::ostringstream os; - os << value; - checkFFmpegSetOption( error, os.str() ); + std::ostringstream os; + os << value; + checkFFmpegSetOption(error, os.str()); } -void Option::setDouble( const double value ) +void Option::setDouble(const double value) { - int error = av_opt_set_double( _avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN ); + int error = av_opt_set_double(_avContext, getName().c_str(), value, AV_OPT_SEARCH_CHILDREN); - std::ostringstream os; - os << value; - checkFFmpegSetOption( error, os.str() ); + std::ostringstream os; + os << value; + checkFFmpegSetOption(error, os.str()); } -void Option::setString( const std::string& value ) +void Option::setString(const std::string& value) { - int error = av_opt_set( _avContext, getName().c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN ); - checkFFmpegSetOption( error, value ); + int error = av_opt_set(_avContext, getName().c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN); + checkFFmpegSetOption(error, value); } -void Option::setRatio( const int num, const int den ) +void Option::setRatio(const int num, const int den) { - Rational ratio; - ratio.num = num; - ratio.den = den; - int error = av_opt_set_q( _avContext, getName().c_str(), ratio, AV_OPT_SEARCH_CHILDREN ); - - std::ostringstream os; - os << num << "/" << den; - checkFFmpegSetOption( error, os.str() ); + Rational ratio; + ratio.num = num; + ratio.den = den; + int error = av_opt_set_q(_avContext, getName().c_str(), ratio, AV_OPT_SEARCH_CHILDREN); + + std::ostringstream os; + os << num << "/" << den; + checkFFmpegSetOption(error, os.str()); } -void Option::appendChild( const Option& child ) +void Option::appendChild(const Option& child) { - _childOptions.push_back( child ); + _childOptions.push_back(child); } -void Option::checkFFmpegGetOption( const int ffmpegReturnCode ) const +void Option::checkFFmpegGetOption(const int ffmpegReturnCode) const { - if( ffmpegReturnCode ) - { - throw std::runtime_error( "unknown key " + getName() + ": " + getDescriptionFromErrorCode( ffmpegReturnCode ) ); - } + if(ffmpegReturnCode) + { + throw std::runtime_error("unknown key " + getName() + ": " + getDescriptionFromErrorCode(ffmpegReturnCode)); + } } -void Option::checkFFmpegSetOption( const int ffmpegReturnCode, const std::string& optionValue ) +void Option::checkFFmpegSetOption(const int ffmpegReturnCode, const std::string& optionValue) { - if( ffmpegReturnCode ) - { - throw std::runtime_error( "setting " + getName() + " parameter to " + optionValue + ": " + getDescriptionFromErrorCode( ffmpegReturnCode ) ); - } + if(ffmpegReturnCode) + { + throw std::runtime_error("setting " + getName() + " parameter to " + optionValue + ": " + + getDescriptionFromErrorCode(ffmpegReturnCode)); + } } -void loadOptions( OptionMap& outOptions, void* av_class, int req_flags ) +void loadOptions(OptionMap& outOptions, void* av_class, int req_flags) { - if( ! av_class ) - return; - - std::multimap optionUnitToParentName; - std::vector