├── .clang-format
├── CMakeLists.txt
├── README.md
├── build
├── vsbuild.bat
└── vsclean.bat
├── cmake
├── common.cmake
├── helperfunctions.cmake
└── postbuildcopy.cmake
├── documentation
├── media
│ ├── FLM.PNG
│ ├── FLM_1.PNG
│ ├── FLM_10.PNG
│ ├── FLM_11.PNG
│ ├── FLM_2.PNG
│ ├── FLM_3.PNG
│ ├── FLM_4.PNG
│ ├── FLM_5.PNG
│ ├── FLM_6.PNG
│ ├── FLM_7.PNG
│ ├── FLM_8.PNG
│ ├── FLM_9.PNG
│ └── FLM_ZIP.PNG
└── users_guide.md
├── external
├── amf
│ ├── LICENSE.txt
│ └── public
│ │ ├── common
│ │ ├── AMFFactory.cpp
│ │ ├── AMFFactory.h
│ │ ├── AMFSTL.cpp
│ │ ├── AMFSTL.h
│ │ ├── ByteArray.h
│ │ ├── CurrentTimeImpl.cpp
│ │ ├── CurrentTimeImpl.h
│ │ ├── DataStream.h
│ │ ├── DataStreamFactory.cpp
│ │ ├── DataStreamFile.cpp
│ │ ├── DataStreamFile.h
│ │ ├── DataStreamMemory.cpp
│ │ ├── DataStreamMemory.h
│ │ ├── InterfaceImpl.h
│ │ ├── ObservableImpl.h
│ │ ├── PropertyStorageExImpl.cpp
│ │ ├── PropertyStorageExImpl.h
│ │ ├── PropertyStorageImpl.h
│ │ ├── Thread.cpp
│ │ ├── Thread.h
│ │ ├── TraceAdapter.cpp
│ │ ├── TraceAdapter.h
│ │ └── Windows
│ │ │ └── ThreadWindows.cpp
│ │ ├── include
│ │ ├── components
│ │ │ ├── ColorSpace.h
│ │ │ ├── Component.h
│ │ │ ├── ComponentCaps.h
│ │ │ ├── DisplayCapture.h
│ │ │ └── VideoConverter.h
│ │ └── core
│ │ │ ├── AudioBuffer.h
│ │ │ ├── Buffer.h
│ │ │ ├── Compute.h
│ │ │ ├── ComputeFactory.h
│ │ │ ├── Context.h
│ │ │ ├── CurrentTime.h
│ │ │ ├── Data.h
│ │ │ ├── Debug.h
│ │ │ ├── Factory.h
│ │ │ ├── Interface.h
│ │ │ ├── Plane.h
│ │ │ ├── Platform.h
│ │ │ ├── PropertyStorage.h
│ │ │ ├── PropertyStorageEx.h
│ │ │ ├── Result.h
│ │ │ ├── Surface.h
│ │ │ ├── Trace.h
│ │ │ ├── Variant.h
│ │ │ └── Version.h
│ │ └── src
│ │ └── components
│ │ └── DisplayCapture
│ │ ├── CaptureStats.h
│ │ ├── DDAPISource.cpp
│ │ ├── DDAPISource.h
│ │ ├── DisplayCaptureImpl.cpp
│ │ ├── DisplayCaptureImpl.h
│ │ └── DrawRectsBGRA.hlsl
└── ini
│ ├── LICENCE.txt
│ └── SimpleIni.h
├── license.txt
└── source
├── flm_backend
├── CMakeLists.txt
├── DrawRectsBGRA_64.h
├── flm.h
├── flm.ini
├── flm_capture_amf.cpp
├── flm_capture_amf.h
├── flm_capture_context.cpp
├── flm_capture_context.h
├── flm_capture_dxgi.cpp
├── flm_capture_dxgi.h
├── flm_keyboard.cpp
├── flm_keyboard.h
├── flm_mouse.cpp
├── flm_mouse.h
├── flm_pipeline.cpp
├── flm_pipeline.h
├── flm_timer.cpp
├── flm_timer.h
├── flm_user_interface.cpp
├── flm_user_interface.h
├── flm_utils.cpp
├── flm_utils.h
└── version.h
└── flm_cli
├── CMakeLists.txt
├── flm_help.h
├── main.cpp
├── main.h
└── resources
├── appicon.ico
├── mainapp.rc
└── resource.h
/.clang-format:
--------------------------------------------------------------------------------
1 | BasedOnStyle: Google
2 | IndentWidth: 4
3 | UseTab: Never
4 | ColumnLimit: 160
5 |
6 | Language: Cpp
7 | AccessModifierOffset: -4
8 | BreakBeforeBraces: Custom
9 | BraceWrapping:
10 | AfterCaseLabel: true
11 | AfterClass: true
12 | AfterControlStatement: true
13 | AfterEnum: true
14 | AfterFunction: true
15 | AfterNamespace: true
16 | AfterObjCDeclaration: true
17 | AfterStruct: true
18 | AfterUnion: true
19 | AfterExternBlock: false
20 | BeforeCatch: true
21 | BeforeElse: true
22 | IndentBraces: false
23 | SplitEmptyFunction: true
24 | SplitEmptyRecord: true
25 | SplitEmptyNamespace: true
26 | ConstructorInitializerAllOnOneLineOrOnePerLine : false
27 | BreakConstructorInitializers: BeforeComma
28 | DerivePointerAlignment: false
29 | IndentCaseLabels: false
30 | NamespaceIndentation: All
31 | AlignConsecutiveAssignments: true
32 | AlignConsecutiveDeclarations: true
33 | AlignEscapedNewlines: Left
34 | AlignTrailingComments: true
35 | AlignOperands: true
36 | AllowShortFunctionsOnASingleLine: false
37 | AllowShortIfStatementsOnASingleLine: false
38 | AllowShortLoopsOnASingleLine: false
39 | AllowShortBlocksOnASingleLine: false
40 | ReflowComments: false
41 | SortIncludes: false
42 | IncludeBlocks: Preserve
43 | SortUsingDeclarations: false
44 | BinPackArguments: false
45 | BinPackParameters: false
46 | ExperimentalAutoDetectBinPacking: false
47 | AllowAllParametersOfDeclarationOnNextLine: false
48 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
2 | #
3 | # FLM SDK
4 | #
5 |
6 | cmake_minimum_required(VERSION 3.10)
7 |
8 | if(POLICY CMP0091)
9 | cmake_policy(SET CMP0091 NEW)
10 | endif()
11 |
12 | if(POLICY CMP0076)
13 | cmake_policy(SET CMP0076 NEW)
14 | endif()
15 |
16 | project(FLM)
17 |
18 | # ------------------------------
19 | # Helper function for the build
20 | # ------------------------------
21 | include(cmake/helperfunctions.cmake)
22 |
23 | # -----------------------------------
24 | # Required for FLM
25 | # -----------------------------------
26 | find_package(Threads)
27 |
28 | # -----------------------------------
29 | # Set standard to c++17
30 | # -----------------------------------
31 | set(CMAKE_CXX_STANDARD 17)
32 | add_compile_definitions(_CMP_CPP17_=1)
33 | set_directory_properties(PROPERTIES VS_STARTUP_PROJECT flm)
34 |
35 | # -----------------------------------------------------------
36 | # enable multi-threaded compilation
37 | # -----------------------------------------------------------
38 | add_compile_options(/MP)
39 | add_compile_definitions(API_DX12)
40 |
41 | # -----------------------------------------------------------
42 | # Check for Visual Studio build tooling
43 | # -----------------------------------------------------------
44 | if(MSVC_TOOLSET_VERSION VERSION_LESS 142)
45 | message(FATAL_ERROR "Cannot find MSVC toolset version 142 or greater. Please make sure Visual Studio 2019 or newer installed")
46 | endif()
47 |
48 | # -----------------------------------------------------------
49 | # generate the output binary in the /bin directory
50 | # -----------------------------------------------------------
51 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/win/bin)
52 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/win/bin/lib) # Dynamic DLL's
53 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/win/bin/lib) # Static Libs
54 |
55 | # -----------------------------------------------------------
56 | # Helper for copy files
57 | # -----------------------------------------------------------
58 | macro(FLM_copy_to_output executable source dest)
59 | add_custom_command(TARGET ${executable} PRE_BUILD
60 | # COMMENT "Copying ${source} -> ${dest}"
61 | COMMAND ${CMAKE_COMMAND} -E copy_if_different
62 | ${source}
63 | ${dest}
64 | )
65 | endmacro()
66 |
67 |
68 | # -----------------------------------------------------------
69 | # Use solution folders.
70 | # -----------------------------------------------------------
71 | set_property(GLOBAL PROPERTY USE_FOLDERS ON)
72 |
73 | # -----------------------------------------------------------
74 | # CLI Application
75 | # -----------------------------------------------------------
76 | add_subdirectory(source/flm_cli)
77 |
78 | # -----------------------------------------------------------
79 | # Backend Lib
80 | # -----------------------------------------------------------
81 | add_subdirectory(source/flm_backend)
82 |
83 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # frame latency meter
4 | The performance of a gaming system is critical to the overall gaming experience. One of the key factors that can impact the performance of a gaming system is the latency of the mouse response time. Measuring the latency of the mouse response time is important to ensure that the gaming system is performing optimally. However, traditional methods of measuring the latency of the mouse response time can be expensive and require additional hardware.
5 |
6 | To address this issue, a software-based latency meter has been developed that is designed to measure the system mouse response times in games. This software-based solution is free and easy to use, making it a highly disruptive alternative to expensive hardware-based solutions.
7 |
8 | 
9 |
10 | Key Features:
11 |
12 | The software-based latency meter offers a range of key features that make it an ideal solution for measuring the latency of the mouse response time in games. These features include:
13 |
14 | - Measurement of the entire latency of the mouse response time, from the moment the mouse is moved to the moment the frame is displayed on the screen.
15 | - Includes options to use : Advanced Media Framework (AMF) capture codec, optimized for AMD GPU or Desktop Duplication (DXGI) screen capture codec for use on any GPU.
16 | - Runs on Windows platforms, making it accessible to a wide range of users.
17 | - Provides detailed statistics for latency and per frame measurements, which can be exported to a csv file for further analysis.
18 | - Allows users to configure hotkeys for enabling measurements, making it easy to use and customize.
19 | - Provides users to configure the screen capture region, making it easy to capture the relevant area of the screen.
20 | - User configurable keys to do sequenced frame captures to BMP files for capture codec diagnostics and validation
21 |
22 | The software-based latency meter offers a range of key features for measuring the latency of the mouse response time in games. By using AMF or DXGI desktop duplication for screen capture, the software-based latency meter is compatible with a wide range of gaming systems. It provides detailed statistics for per frame and latency measurements, which can be exported to a csv file for further analysis. With user-configurable hotkeys and screen capture regions, the software-based latency meter is easy to use and customize. Overall, the software-based latency meter is an ideal solution for users who want to measure the latency of the mouse response time in games without incurring additional costs.
23 |
24 | ## Quick Start
25 |
26 | Requirements Windows 10 or higher with DX11 and DX12 support, games should run in windowed mode for DXGI capture codec to work. AMF can run in full screen mode and high frame rates.
27 |
28 | **Step 1:** Configure your primary monitor to run the game on.
29 |
30 | Set the monitor to use free sync or have it set to an appropriate refresh rate try starting at 60Hz first.
31 |
32 | **Step 2:** Run flm.exe
33 |
34 | To see the capture region bounding box, press right Alt key.
35 | Note: The bounding box will only show if the game is running in window mode.
36 |
37 | Adjust the game scene placement so that the FLM capture region is situated in an area.
38 | where the scene transitions from dark to bright when the mouse is moved horizontally.
39 |
40 | **Step 3:** Run the game.
41 |
42 | Adjust the game scene placement so that the FLM capture region is situated in an area where the scene transitions from dark to bright when the mouse is moved horizontally.
43 |
44 | **Step 4:** Select start measurements key sequence (default is ALT+T).
45 |
46 | * Wait for the capture process to start, it may take a few seconds to start as FLM process data, you should see the mouse move left and right in rapid concession while the application records latency measurements. Some games may require you to press down on the mouse keys to move the mouse left and right. If the mouse movements are too small, adjust the scene location or change the mouse steps in flm.ini using "MouseHorizontalStep".
47 |
48 | * If you do not see any measurements or the measurements are slow, stop the measurements by pressing Alt+T and try another scene location with better contrast between left and right capture regions, if that fails review the adjust setting section for addition details on how to change the default settings.
49 |
50 | * By default, FLM starts in "RUN" work mode, in which the output shows latency[ms] and latency[frames] averages of 16 consecutive measurements. The current work mode can be changed for the current session via the settings dialog, or a new default work mode can be set by modifying the INI file
51 |
52 | fps = xxx.x | ................ | latency = xxx.x | frames = x.xxx
53 |
54 | * A running series of measurements will indicate the rate at which these latency measurements are occurring. If it is not moving or is slow - then stop the measurements (Step 5), change the game scene's location and retry. If you change the scene while the measurement is still running the average latency value will not be correct until it reaches a steady state value.
55 |
56 | **Step 5**: Select stop measurements and review the output.
57 |
58 | Start measurements.
59 | fps = xxx.x | ................ | latency = xxx.x | frames = x.xxx
60 | Stop measurements.
61 |
62 |
63 | ## To Build Project Solution Files
64 |
65 | ### Requirements
66 | - VS2022 installed
67 | - CMake v3.10 or higher
68 |
69 | ### Run this batch file once for setup in the build folder
70 |
71 | - vsbuild
72 |
73 | A build/win folder containing FLM.sln should have been generated
74 | Open the solution file and build the project files.
75 |
76 | ### Run this batch file to remove build/win and bin folders
77 | - vsclean
78 |
79 | ### Adding your own capture codec
80 | The FLM backend code is designed to add additional capture codecs, look at the capture entry code flm_capture_context and use the samples flm_capture_amf and flm_capture_dxgi as guides to developing your own specialized capture codec.
81 |
82 |
83 | ## Known Issues and Limitations
84 |
85 | ### Desktop Capture codec (DXGI) performance
86 | * Desktop capture is too slow when monitors refresh rate is set too high > 144 Hz.
87 | Try setting the monitor refresh rate to 60 Hz while you get accustomed to how FLM works, then try higher rates.
88 | * Certain games may limit the utilization of desktop duplication screen capture, making the option to use the DXGI codec inoperable.
89 | * DXGI capture codec must be running on the primary display, else frame capture will be too slow.
90 | * The current capture codecs are processing SAD measurements using CPU and may be too slow on some PC.
91 |
92 | ### No result shown
93 | * The default settings may not trigger latency measurements. Try adjustments to settings for ThresholdCoefficient and AVGFilter in the flm file.
94 | * FLM will not work using remote desktop connections.
95 |
96 | ### Latency results shown are too high
97 |
98 | * When games are running at high frame rates FLM measurements show higher values then those measured by hardware devices.
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/build/vsbuild.bat:
--------------------------------------------------------------------------------
1 | cd ..\
2 | set CurrDir=%CD%
3 | for %%* in (.) do set CurrDirName=%%~nx*
4 | IF EXIST %CurrDir%\build\win (rmdir build\win /s /q)
5 | mkdir build\win
6 |
7 | cd build\win
8 | cmake -G "Visual Studio 17 2022" ..\..\..\%CurrDirName%
9 | cd %CurrDir%
10 |
--------------------------------------------------------------------------------
/build/vsclean.bat:
--------------------------------------------------------------------------------
1 | set CurrDir=%CD%
2 | for %%* in (.) do set CurrDirName=%%~nx*
3 |
4 | del /s *.sdf
5 | del /s *.db
6 | del /s *.pdb
7 | del /s *.idb
8 | del /s *.ipch
9 | del /s *.user
10 | del /s *.opendb
11 | del /s *.orig
12 | del /s CMakeCache.txt
13 | del /s cmake_install.cmake
14 | del /s *.a
15 | del /s *.o
16 | del Makefile
17 | rmdir /s /q bin
18 | rmdir /s /q lib
19 |
20 | IF EXIST win (
21 | rmdir /s /q -r win
22 | )
23 |
24 | cd %CurrDir%
25 |
26 | FOR /d /r . %%d IN (CMakeFiles) DO @IF EXIST "%%d" rd /s /q "%%d"
27 | FOR /d /r . %%d IN (*_autogen) DO @IF EXIST "%%d" rd /s /q "%%d"
28 |
29 |
--------------------------------------------------------------------------------
/cmake/common.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Copies a set of files to a directory (only if they already don't exist or are different)
3 | # Usage example:
4 | # set(media_src ${CMAKE_CURRENT_SOURCE_DIR}/../../media/brdfLut.dds )
5 | # copyCommand("${media_src}" ${CMAKE_HOME_DIRECTORY}/bin)
6 | #
7 | # Sometimes a proper dependency between target and copied files cannot be created
8 | # and you should try copyTargetCommand() below instead
9 | #
10 | function(copyCommand list dest)
11 | foreach(fullFileName ${list})
12 | get_filename_component(file ${fullFileName} NAME)
13 | message("Generating custom command for ${fullFileName}")
14 | add_custom_command(
15 | OUTPUT ${dest}/${file}
16 | PRE_BUILD
17 | COMMAND ${CMAKE_COMMAND} -E make_directory ${dest}
18 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${fullFileName} ${dest}
19 | MAIN_DEPENDENCY ${fullFileName}
20 | COMMENT "Updating ${file} into ${dest}"
21 | )
22 | list(APPEND dest_files ${dest}/${file})
23 | endforeach()
24 |
25 | #return output file list
26 | set(copyCommand_dest_files ${dest_files} PARENT_SCOPE)
27 | endfunction()
28 |
29 | #
30 | # Same as copyCommand() but you can give a target name
31 | # This custom target will depend on all those copied files
32 | # Then the target can be properly set as a dependency of other executable or library
33 | # Usage example:
34 | # add_library(my_lib ...)
35 | # set(media_src ${CMAKE_CURRENT_SOURCE_DIR}/../../media/brdfLut.dds )
36 | # copyTargetCommand("${media_src}" ${CMAKE_HOME_DIRECTORY}/bin copied_media_src)
37 | # add_dependencies(my_lib copied_media_src)
38 | #
39 | function(copyTargetCommand list dest returned_target_name)
40 | set_property(GLOBAL PROPERTY USE_FOLDERS ON)
41 |
42 | foreach(fullFileName ${list})
43 | get_filename_component(file ${fullFileName} NAME)
44 | message("Generating custom command for ${fullFileName}")
45 | add_custom_command(
46 | OUTPUT ${dest}/${file}
47 | PRE_BUILD
48 | COMMAND ${CMAKE_COMMAND} -E make_directory ${dest}
49 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${fullFileName} ${dest}
50 | MAIN_DEPENDENCY ${fullFileName}
51 | COMMENT "Updating ${file} into ${dest}"
52 | )
53 | list(APPEND dest_list ${dest}/${file})
54 | endforeach()
55 |
56 | add_custom_target(${returned_target_name} DEPENDS "${dest_list}")
57 |
58 | set_target_properties(${returned_target_name} PROPERTIES FOLDER CopyTargets)
59 | endfunction()
60 |
--------------------------------------------------------------------------------
/cmake/helperfunctions.cmake:
--------------------------------------------------------------------------------
1 |
2 | # Host platform detection
3 | set(CMP_HOST_APPLE OFF)
4 | set(CMP_HOST_LINUX OFF)
5 | set(CMP_HOST_WINDOWS OFF)
6 |
7 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
8 | set(CMP_HOST_APPLE ON)
9 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
10 | set(CMP_HOST_LINUX ON)
11 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
12 | set(CMP_HOST_WINDOWS ON)
13 | else()
14 | message(FATAL_ERROR "Unknown platform")
15 | endif()
16 |
17 |
18 | # Helper function for setting persistent CMake options
19 | macro(cmp_option OPTION_NAME DESCRIPTION EXPRESSION)
20 | set(expression ${ARGV})
21 | list(REMOVE_AT expression 0)
22 | list(REMOVE_AT expression 0)
23 |
24 | if (${expression})
25 | set(${OPTION_NAME} ON CACHE BOOL ${DESCRIPTION} FORCE)
26 | add_compile_definitions(${OPTION_NAME}=1)
27 | else()
28 | set(${OPTION_NAME} OFF CACHE BOOL ${DESCRIPTION} FORCE)
29 | add_compile_definitions(${OPTION_NAME}=0)
30 | endif()
31 |
32 | message(STATUS "${OPTION_NAME} ${${OPTION_NAME}}")
33 | endmacro()
34 |
35 | # Helper function to gather transitive (potential shared/dynamic) dependencies of a target
36 | function(_get_transitive_dylibs _TARGET)
37 |
38 | # Clear variable for reuse
39 | if (NOT DEFINED _transitive_search_started)
40 | set(_transitive_search_started ON)
41 | unset(TRANSITIVE_DYLIBS)
42 | endif()
43 |
44 | # INTERFACE_LIBRARY targets can only have INTERFACE_LINK_LIBRARIES properties
45 | get_target_property(target_type ${_TARGET} TYPE)
46 | if(target_type STREQUAL "INTERFACE_LIBRARY")
47 | get_target_property(DEPENDENCIES ${_TARGET} INTERFACE_LINK_LIBRARIES)
48 | else()
49 | get_target_property(LINK_LIBRARIES ${_TARGET} LINK_LIBRARIES)
50 | get_target_property(INTERFACE_LINK_LIBRARIES ${_TARGET} INTERFACE_LINK_LIBRARIES)
51 | set(DEPENDENCIES ${LINK_LIBRARIES} ${INTERFACE_LINK_LIBRARIES})
52 | endif()
53 |
54 | # Collect transitive dependencies from target
55 | foreach(_DEP ${DEPENDENCIES})
56 | # Check to see if the dependency is a dynamic library
57 | string(REGEX MATCH ".*\\.(so|dll|dylib)(\\.[a-zA-Z0-9\\.]*)?$" dylib ${_DEP})
58 | if (NOT (dylib STREQUAL ""))
59 | list(APPEND TRANSITIVE_DYLIBS ${dylib})
60 | elseif(TARGET ${_DEP})
61 | # # Only traverse targets we have not visited before
62 | get_target_property(dep_type ${_DEP} TYPE)
63 | if(dep_type STREQUAL "INTERFACE_LIBRARY")
64 | # Marks the library for removal but prevents traversing it again
65 | set(DEP_FILE "${_DEP}.interface")
66 | else()
67 | set(DEP_FILE $)
68 | endif()
69 | list(FIND TRANSITIVE_DYLIBS ${DEP_FILE} DEP_IN_LIST)
70 | if (DEP_IN_LIST EQUAL -1)
71 | # Add the target to the list
72 | list(APPEND TRANSITIVE_DYLIBS ${DEP_FILE})
73 | # Get the targets dependencies
74 | _get_transitive_dylibs(${_DEP})
75 | endif()
76 | endif()
77 | endforeach()
78 |
79 | # Prune and publish list
80 | list(REMOVE_DUPLICATES TRANSITIVE_DYLIBS)
81 | set(TRANSITIVE_DYLIBS ${TRANSITIVE_DYLIBS} PARENT_SCOPE)
82 | endfunction()
83 |
84 | # Helper function to gather transitive (potential shared/dynamic) dependencies of a target
85 | function(get_transitive_dylibs _TARGET)
86 |
87 | _get_transitive_dylibs(${_TARGET})
88 |
89 | # Prune and publish list
90 | list(FILTER TRANSITIVE_DYLIBS EXCLUDE REGEX "\\.interface$")
91 | set(TRANSITIVE_DYLIBS ${TRANSITIVE_DYLIBS} PARENT_SCOPE)
92 | endfunction()
93 |
94 | # Helper function used to copy all dynamic libraries to an output directory
95 | function(executable_post_build_dylibs TARGET_NAME OUTPUT_DIR)
96 |
97 | # yields TRANSITIVE_DYLIBS
98 | get_transitive_dylibs(${TARGET_NAME})
99 |
100 | # Don't add the custom target if no dynamic libraries were found
101 | list(LENGTH TRANSITIVE_DYLIBS _NUM_DYLIBS)
102 | if(_NUM_DYLIBS GREATER 0)
103 | add_custom_command(
104 | TARGET ${TARGET_NAME}
105 | PRE_BUILD
106 | COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/PostBuildCopy.cmake "\"${TRANSITIVE_DYLIBS}\""
107 | ${OUTPUT_DIR}
108 | )
109 | endif()
110 | endfunction()
111 |
112 | macro(cmp_copy_to_output executable source dest)
113 | add_custom_command(TARGET ${executable} PRE_BUILD
114 | # COMMENT "Copying ${source} -> ${dest}"
115 | COMMAND ${CMAKE_COMMAND} -E copy_if_different
116 | ${source}
117 | ${dest}
118 | )
119 | endmacro()
120 |
121 | macro(cmp_execute_process COMMAND WORKING_DIR)
122 |
123 | set(CMD_MSG "")
124 | foreach(CMD ${${COMMAND}})
125 | set(CMD_MSG "${CMD_MSG}${CMD} ")
126 | endforeach()
127 |
128 | message(STATUS "Executing process: ${CMD_MSG}")
129 | execute_process(
130 | COMMAND ${${COMMAND}}
131 | WORKING_DIRECTORY ${WORKING_DIR}
132 | ERROR_VARIABLE _stderr
133 | OUTPUT_VARIABLE _stdout
134 | RESULT_VARIABLE _exit_code ENCODING UTF-8
135 | )
136 |
137 | if(NOT _exit_code EQUAL 0)
138 | message(STATUS ${_stdout})
139 | if(EXISTS ${VULKAN_OUTPUT_DIR})
140 | file(REMOVE_RECURSE ${VULKAN_OUTPUT_DIR})
141 | endif()
142 | message(FATAL_ERROR "Process exited with non 0 exit code: ${_exit_code}\n${_stderr}")
143 | endif()
144 |
145 | endmacro()
--------------------------------------------------------------------------------
/cmake/postbuildcopy.cmake:
--------------------------------------------------------------------------------
1 |
2 | # Parse out the provided arguments
3 | if (CMAKE_ARGC EQUAL 5)
4 | set(LIBS_LIST ${CMAKE_ARGV3})
5 | set(APP_OUTPUT ${CMAKE_ARGV4})
6 |
7 | list(LENGTH LIBS_LIST NUM_DYLIBS)
8 | if (NUM_DYLIBS GREATER 0)
9 |
10 | # Make the directory if it does not exist
11 | if (NOT EXISTS APP_OUTPUT)
12 | file(MAKE_DIRECTORY ${APP_OUTPUT})
13 | endif ()
14 |
15 | foreach (lib ${LIBS_LIST})
16 | string(REGEX MATCH ".*\\.(so|dll|dylib)(\\.[a-zA-Z0-9\\.]*)?$" dylib ${lib})
17 | if (NOT (dylib STREQUAL ""))
18 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${lib}" "${APP_OUTPUT}"
19 | # COMMAND_ECHO STDOUT
20 | ENCODING UTF-8
21 | OUTPUT_VARIABLE stdout
22 | RESULT_VARIABLE result
23 | )
24 | # Error handling
25 | if (NOT (result EQUAL 0))
26 | message(DEBUG "${stdout}")
27 | message(FATAL_ERROR "${result}")
28 | endif()
29 | get_filename_component(lib_basename "${lib}" NAME)
30 |
31 | # Get list of extensions
32 | get_filename_component(lib_exts "${lib}" EXT)
33 | string(REPLACE "." ";" lib_ext_list "${lib_exts}")
34 |
35 | get_filename_component(lib_symlink "${lib}" NAME_WE)
36 |
37 | # Create symlinks for all extensions
38 | foreach(lib_ext ${lib_ext_list})
39 | set(lib_symlink "${lib_symlink}.${lib_ext}")
40 | if (lib_symlink STREQUAL "${lib_basename}")
41 | continue()
42 | endif()
43 | execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${lib_basename}" "${lib_symlink}"
44 | # COMMAND_ECHO STDOUT
45 | WORKING_DIRECTORY "${APP_OUTPUT}"
46 | ENCODING UTF-8
47 | OUTPUT_VARIABLE stdout
48 | RESULT_VARIABLE result
49 | )
50 | # Error handling
51 | if (NOT (result EQUAL 0))
52 | message(DEBUG "${stdout}")
53 | message(FATAL_ERROR "${result}")
54 | endif()
55 | endforeach()
56 | endif()
57 | endforeach ()
58 |
59 | endif ()
60 | else ()
61 | message(FATAL_ERROR "Unexpected number of arguments")
62 | endif ()
63 |
--------------------------------------------------------------------------------
/documentation/media/FLM.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_1.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_10.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_10.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_11.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_11.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_2.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_3.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_4.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_4.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_5.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_5.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_6.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_6.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_7.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_7.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_8.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_8.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_9.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_9.PNG
--------------------------------------------------------------------------------
/documentation/media/FLM_ZIP.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/documentation/media/FLM_ZIP.PNG
--------------------------------------------------------------------------------
/external/amf/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT license
2 |
3 | Copyright (c) 2016-2024 Advanced Micro Devices, Inc. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/external/amf/public/common/AMFFactory.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_AMFFactory_h
24 | #define AMF_AMFFactory_h
25 |
26 | #pragma once
27 |
28 | #include "../include/core/Factory.h"
29 | #include
30 | #include
31 |
32 |
33 | class AMFFactoryHelper
34 | {
35 | public:
36 | AMFFactoryHelper();
37 | virtual ~AMFFactoryHelper();
38 |
39 | AMF_RESULT Init(const wchar_t* dllName = NULL);
40 | AMF_RESULT Terminate();
41 |
42 | AMF_RESULT LoadExternalComponent(amf::AMFContext* pContext, const wchar_t* dll, const char* function, void* reserved, amf::AMFComponent** ppComponent);
43 | AMF_RESULT UnLoadExternalComponent(const wchar_t* dll);
44 |
45 | amf::AMFFactory* GetFactory();
46 | amf::AMFDebug* GetDebug();
47 | amf::AMFTrace* GetTrace();
48 |
49 | amf_uint64 AMFQueryVersion();
50 |
51 | amf_handle GetAMFDLLHandle() { return m_hDLLHandle; }
52 | protected:
53 | struct ComponentHolder
54 | {
55 | amf_handle m_hDLLHandle;
56 | amf_long m_iRefCount;
57 | std::wstring m_DLL;
58 |
59 | ComponentHolder()
60 | {
61 | m_hDLLHandle = NULL;
62 | m_iRefCount = 0;
63 | }
64 | };
65 |
66 | amf_handle m_hDLLHandle;
67 | amf::AMFFactory* m_pFactory;
68 | amf::AMFDebug* m_pDebug;
69 | amf::AMFTrace* m_pTrace;
70 | amf_uint64 m_AMFRuntimeVersion;
71 |
72 | amf_long m_iRefCount;
73 |
74 | std::vector m_extComponents;
75 | };
76 |
77 | extern ::AMFFactoryHelper g_AMFFactory;
78 | #endif // AMF_AMFFactory_h
--------------------------------------------------------------------------------
/external/amf/public/common/ByteArray.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_ByteArray_h
24 | #define AMF_ByteArray_h
25 |
26 |
27 | #pragma once
28 | #include "../include/core/Platform.h"
29 | #define INIT_ARRAY_SIZE 1024
30 | #define ARRAY_MAX_SIZE (1LL << 60LL) // extremely large maximum size
31 | //------------------------------------------------------------------------
32 | class AMFByteArray
33 | {
34 | protected:
35 | amf_uint8 *m_pData;
36 | amf_size m_iSize;
37 | amf_size m_iMaxSize;
38 | public:
39 | AMFByteArray() : m_pData(0), m_iSize(0), m_iMaxSize(0)
40 | {
41 | }
42 | AMFByteArray(const AMFByteArray &other) : m_pData(0), m_iSize(0), m_iMaxSize(0)
43 | {
44 | *this = other;
45 | }
46 | AMFByteArray(amf_size num) : m_pData(0), m_iSize(0), m_iMaxSize(0)
47 | {
48 | SetSize(num);
49 | }
50 | virtual ~AMFByteArray()
51 | {
52 | if (m_pData != 0)
53 | {
54 | delete[] m_pData;
55 | }
56 | }
57 | void SetSize(amf_size num)
58 | {
59 | if (num == m_iSize)
60 | {
61 | return;
62 | }
63 | if (num < m_iSize)
64 | {
65 | memset(m_pData + num, 0, m_iMaxSize - num);
66 | }
67 | else if (num > m_iMaxSize)
68 | {
69 | // This is done to prevent the following error from surfacing
70 | // for the pNewData allocation on some compilers:
71 | // -Werror=alloc-size-larger-than=
72 | amf_size newSize = (num / INIT_ARRAY_SIZE) * INIT_ARRAY_SIZE + INIT_ARRAY_SIZE;
73 | if (newSize > ARRAY_MAX_SIZE)
74 | {
75 | return;
76 | }
77 | m_iMaxSize = newSize;
78 |
79 | amf_uint8 *pNewData = new amf_uint8[m_iMaxSize];
80 | memset(pNewData, 0, m_iMaxSize);
81 | if (m_pData != NULL)
82 | {
83 | memcpy(pNewData, m_pData, m_iSize);
84 | delete[] m_pData;
85 | }
86 | m_pData = pNewData;
87 | }
88 | m_iSize = num;
89 | }
90 | void Copy(const AMFByteArray &old)
91 | {
92 | if (m_iMaxSize < old.m_iSize)
93 | {
94 | m_iMaxSize = old.m_iMaxSize;
95 | if (m_pData != NULL)
96 | {
97 | delete[] m_pData;
98 | }
99 | m_pData = new amf_uint8[m_iMaxSize];
100 | memset(m_pData, 0, m_iMaxSize);
101 | }
102 | memcpy(m_pData, old.m_pData, old.m_iSize);
103 | m_iSize = old.m_iSize;
104 | }
105 | amf_uint8 operator[] (amf_size iPos) const
106 | {
107 | return m_pData[iPos];
108 | }
109 | amf_uint8& operator[] (amf_size iPos)
110 | {
111 | return m_pData[iPos];
112 | }
113 | AMFByteArray& operator=(const AMFByteArray &other)
114 | {
115 | SetSize(other.GetSize());
116 | if (GetSize() > 0)
117 | {
118 | memcpy(GetData(), other.GetData(), GetSize());
119 | }
120 | return *this;
121 | }
122 | amf_uint8 *GetData() const { return m_pData; }
123 | amf_size GetSize() const { return m_iSize; }
124 | };
125 | #endif // AMF_ByteArray_h
--------------------------------------------------------------------------------
/external/amf/public/common/CurrentTimeImpl.cpp:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #include "CurrentTimeImpl.h"
24 |
25 | namespace amf
26 | {
27 |
28 | //-------------------------------------------------------------------------------------------------
29 | AMFCurrentTimeImpl::AMFCurrentTimeImpl()
30 | : m_timeOfFirstCall(-1)
31 | {
32 | }
33 |
34 | //-------------------------------------------------------------------------------------------------
35 | AMFCurrentTimeImpl::~AMFCurrentTimeImpl()
36 | {
37 | m_timeOfFirstCall = -1;
38 | }
39 |
40 | //-------------------------------------------------------------------------------------------------
41 | amf_pts AMF_STD_CALL AMFCurrentTimeImpl::Get()
42 | {
43 | amf::AMFLock lock(&m_sync);
44 |
45 | // We want pts time to start at 0 and subsequent
46 | // times to be relative to that
47 | if (m_timeOfFirstCall < 0)
48 | {
49 | m_timeOfFirstCall = amf_high_precision_clock();
50 | return 0;
51 | }
52 | return (amf_high_precision_clock() - m_timeOfFirstCall); // In nanoseconds
53 | }
54 |
55 | //-------------------------------------------------------------------------------------------------
56 | void AMF_STD_CALL AMFCurrentTimeImpl::Reset()
57 | {
58 | m_timeOfFirstCall = -1;
59 | }
60 | }
--------------------------------------------------------------------------------
/external/amf/public/common/CurrentTimeImpl.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_CurrentTimeImpl_h
24 | #define AMF_CurrentTimeImpl_h
25 |
26 | #include "../include/core/CurrentTime.h"
27 | #include "InterfaceImpl.h"
28 | #include "Thread.h"
29 |
30 | namespace amf
31 | {
32 |
33 | class AMFCurrentTimeImpl : public AMFInterfaceImpl
34 | {
35 | public:
36 | AMFCurrentTimeImpl();
37 | ~AMFCurrentTimeImpl();
38 |
39 | AMF_BEGIN_INTERFACE_MAP
40 | AMF_INTERFACE_ENTRY(AMFCurrentTime)
41 | AMF_END_INTERFACE_MAP
42 |
43 | virtual amf_pts AMF_STD_CALL Get();
44 |
45 | virtual void AMF_STD_CALL Reset();
46 |
47 | private:
48 | amf_pts m_timeOfFirstCall;
49 | mutable AMFCriticalSection m_sync;
50 | };
51 |
52 | //----------------------------------------------------------------------------------------------
53 | // smart pointer
54 | //----------------------------------------------------------------------------------------------
55 | typedef AMFInterfacePtr_T AMFCurrentTimePtr;
56 | //----------------------------------------------------------------------------------------------}
57 | }
58 | #endif // AMF_CurrentTimeImpl_h
--------------------------------------------------------------------------------
/external/amf/public/common/DataStream.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | /**
24 | ***************************************************************************************************
25 | * @file DataStream.h
26 | * @brief AMFDataStream declaration
27 | ***************************************************************************************************
28 | */
29 | #ifndef AMF_DataStream_h
30 | #define AMF_DataStream_h
31 | #pragma once
32 |
33 | #include "../include/core/Interface.h"
34 |
35 | namespace amf
36 | {
37 | // currently supports only
38 | // file://
39 | // memory://
40 |
41 | // eventually can be extended with:
42 | // rtsp://
43 | // rtmp://
44 | // http://
45 | // etc
46 |
47 | //----------------------------------------------------------------------------------------------
48 | enum AMF_STREAM_OPEN
49 | {
50 | AMFSO_READ = 0,
51 | AMFSO_WRITE = 1,
52 | AMFSO_READ_WRITE = 2,
53 | AMFSO_APPEND = 3,
54 | };
55 | //----------------------------------------------------------------------------------------------
56 | enum AMF_FILE_SHARE
57 | {
58 | AMFFS_EXCLUSIVE = 0,
59 | AMFFS_SHARE_READ = 1,
60 | AMFFS_SHARE_WRITE = 2,
61 | AMFFS_SHARE_READ_WRITE = 3,
62 | };
63 | //----------------------------------------------------------------------------------------------
64 | enum AMF_SEEK_ORIGIN
65 | {
66 | AMF_SEEK_BEGIN = 0,
67 | AMF_SEEK_CURRENT = 1,
68 | AMF_SEEK_END = 2,
69 | };
70 | //----------------------------------------------------------------------------------------------
71 | // AMFDataStream interface
72 | //----------------------------------------------------------------------------------------------
73 | class AMF_NO_VTABLE AMFDataStream : public AMFInterface
74 | {
75 | public:
76 | AMF_DECLARE_IID(0xdb08fe70, 0xb743, 0x4c26, 0xb2, 0x77, 0xa5, 0xc8, 0xe8, 0x14, 0xda, 0x4)
77 |
78 | // interface
79 | virtual AMF_RESULT AMF_STD_CALL Open(const wchar_t* pFileUrl, AMF_STREAM_OPEN eOpenType, AMF_FILE_SHARE eShareType) = 0;
80 | virtual AMF_RESULT AMF_STD_CALL Close() = 0;
81 | virtual AMF_RESULT AMF_STD_CALL Read(void* pData, amf_size iSize, amf_size* pRead) = 0;
82 | virtual AMF_RESULT AMF_STD_CALL Write(const void* pData, amf_size iSize, amf_size* pWritten) = 0;
83 | virtual AMF_RESULT AMF_STD_CALL Seek(AMF_SEEK_ORIGIN eOrigin, amf_int64 iPosition, amf_int64* pNewPosition) = 0;
84 | virtual AMF_RESULT AMF_STD_CALL GetPosition(amf_int64* pPosition) = 0;
85 | virtual AMF_RESULT AMF_STD_CALL GetSize(amf_int64* pSize) = 0;
86 | virtual bool AMF_STD_CALL IsSeekable() = 0;
87 |
88 | static AMF_RESULT AMF_STD_CALL OpenDataStream(const wchar_t* pFileUrl, AMF_STREAM_OPEN eOpenType, AMF_FILE_SHARE eShareType, AMFDataStream** str);
89 |
90 | };
91 | //----------------------------------------------------------------------------------------------
92 | // smart pointer
93 | //----------------------------------------------------------------------------------------------
94 | typedef AMFInterfacePtr_T AMFDataStreamPtr;
95 | //----------------------------------------------------------------------------------------------
96 |
97 | } //namespace amf
98 |
99 | #endif // AMF_DataStream_h
--------------------------------------------------------------------------------
/external/amf/public/common/DataStreamFactory.cpp:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #include "DataStream.h"
24 | #include "DataStreamMemory.h"
25 | #include "DataStreamFile.h"
26 | #include "TraceAdapter.h"
27 | #include
28 |
29 | using namespace amf;
30 |
31 |
32 | //-------------------------------------------------------------------------------------------------
33 | AMF_RESULT AMF_STD_CALL amf::AMFDataStream::OpenDataStream(const wchar_t* pFileUrl, AMF_STREAM_OPEN eOpenType, AMF_FILE_SHARE eShareType, AMFDataStream** str)
34 | {
35 | AMF_RETURN_IF_FALSE(pFileUrl != NULL, AMF_INVALID_ARG);
36 |
37 | AMF_RESULT res = AMF_NOT_SUPPORTED;
38 | std::wstring url(pFileUrl);
39 |
40 | std::wstring protocol;
41 | std::wstring path;
42 | std::wstring::size_type found_pos = url.find(L"://", 0);
43 | if(found_pos != std::wstring::npos)
44 | {
45 | protocol = url.substr(0, found_pos);
46 | path = url.substr(found_pos + 3);
47 | }
48 | else
49 | {
50 | protocol = L"file";
51 | path = url;
52 | }
53 | AMFDataStreamPtr ptr = NULL;
54 | if(protocol == L"file")
55 | {
56 | ptr = new AMFDataStreamFileImpl;
57 | res = AMF_OK;
58 | }
59 | if(protocol == L"memory")
60 | {
61 | ptr = new AMFDataStreamMemoryImpl();
62 | res = AMF_OK;
63 | }
64 | if( res == AMF_OK )
65 | {
66 | res = ptr->Open(path.c_str(), eOpenType, eShareType);
67 | if( res != AMF_OK )
68 | {
69 | return res;
70 | }
71 | *str = ptr.Detach();
72 | return AMF_OK;
73 | }
74 | return res;
75 | }
76 | //-------------------------------------------------------------------------------------------------
77 |
--------------------------------------------------------------------------------
/external/amf/public/common/DataStreamFile.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_DataStreamFile_h
24 | #define AMF_DataStreamFile_h
25 |
26 | #pragma once
27 |
28 | #include "DataStream.h"
29 | #include "InterfaceImpl.h"
30 | #include "AMFSTL.h"
31 | #include
32 |
33 | namespace amf
34 | {
35 | class AMFDataStreamFileImpl : public AMFInterfaceImpl
36 | {
37 | public:
38 | AMFDataStreamFileImpl();
39 | virtual ~AMFDataStreamFileImpl();
40 | // interface
41 | virtual AMF_RESULT AMF_STD_CALL Close();
42 | virtual AMF_RESULT AMF_STD_CALL Read(void* pData, amf_size iSize, amf_size* pRead);
43 | virtual AMF_RESULT AMF_STD_CALL Write(const void* pData, amf_size iSize, amf_size* pWritten);
44 | virtual AMF_RESULT AMF_STD_CALL Seek(AMF_SEEK_ORIGIN eOrigin, amf_int64 iPosition, amf_int64* pNewPosition);
45 | virtual AMF_RESULT AMF_STD_CALL GetPosition(amf_int64* pPosition);
46 | virtual AMF_RESULT AMF_STD_CALL GetSize(amf_int64* pSize);
47 | virtual bool AMF_STD_CALL IsSeekable();
48 |
49 | // local
50 | // aways pass full URL just in case
51 | virtual AMF_RESULT AMF_STD_CALL Open(const wchar_t* pFilePath, AMF_STREAM_OPEN eOpenType, AMF_FILE_SHARE eShareType);
52 | protected:
53 | int m_iFileDescriptor;
54 | amf_wstring m_Path;
55 | };
56 | } //namespace amf
57 | #endif // AMF_DataStreamFile_h
--------------------------------------------------------------------------------
/external/amf/public/common/DataStreamMemory.cpp:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #include "Thread.h"
24 | #include "TraceAdapter.h"
25 | #include "DataStreamMemory.h"
26 |
27 | using namespace amf;
28 |
29 | #define AMF_FACILITY L"AMFDataStreamMemoryImpl"
30 |
31 | //-------------------------------------------------------------------------------------------------
32 | AMFDataStreamMemoryImpl::AMFDataStreamMemoryImpl()
33 | : m_pMemory(NULL),
34 | m_uiMemorySize(0),
35 | m_uiAllocatedSize(0),
36 | m_pos(0)
37 | {}
38 | //-------------------------------------------------------------------------------------------------
39 | AMFDataStreamMemoryImpl::~AMFDataStreamMemoryImpl()
40 | {
41 | Close();
42 | }
43 | //-------------------------------------------------------------------------------------------------
44 | // interface
45 | //-------------------------------------------------------------------------------------------------
46 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::Close()
47 | {
48 | if(m_pMemory != NULL)
49 | {
50 | amf_virtual_free(m_pMemory);
51 | }
52 | m_pMemory = NULL,
53 | m_uiMemorySize = 0,
54 | m_uiAllocatedSize = 0,
55 | m_pos = 0;
56 | return AMF_OK;
57 | }
58 | //-------------------------------------------------------------------------------------------------
59 | AMF_RESULT AMFDataStreamMemoryImpl::Realloc(amf_size iSize)
60 | {
61 | if(iSize > m_uiMemorySize)
62 | {
63 | amf_uint8* pNewMemory = (amf_uint8*)amf_virtual_alloc(iSize);
64 | if(pNewMemory == NULL)
65 | {
66 | return AMF_OUT_OF_MEMORY;
67 | }
68 | m_uiAllocatedSize = iSize;
69 | if(m_pMemory != NULL)
70 | {
71 | memcpy(pNewMemory, m_pMemory, m_uiMemorySize);
72 | amf_virtual_free(m_pMemory);
73 | }
74 |
75 | m_pMemory = pNewMemory;
76 | }
77 | m_uiMemorySize = iSize;
78 | if(m_pos > m_uiMemorySize)
79 | {
80 | m_pos = m_uiMemorySize;
81 | }
82 | return AMF_OK;
83 | }
84 | //-------------------------------------------------------------------------------------------------
85 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::Read(void* pData, amf_size iSize, amf_size* pRead)
86 | {
87 | AMF_RETURN_IF_FALSE(pData != NULL, AMF_INVALID_POINTER, L"Read() - pData==NULL");
88 | AMF_RETURN_IF_FALSE(m_pMemory != NULL, AMF_NOT_INITIALIZED, L"Read() - Stream is not allocated");
89 |
90 | amf_size toRead = AMF_MIN(iSize, m_uiMemorySize - m_pos);
91 | memcpy(pData, m_pMemory + m_pos, toRead);
92 | m_pos += toRead;
93 | if(pRead != NULL)
94 | {
95 | *pRead = toRead;
96 | }
97 | return AMF_OK;
98 | }
99 | //-------------------------------------------------------------------------------------------------
100 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::Write(const void* pData, amf_size iSize, amf_size* pWritten)
101 | {
102 | AMF_RETURN_IF_FALSE(pData != NULL, AMF_INVALID_POINTER, L"Write() - pData==NULL");
103 | AMF_RETURN_IF_FAILED(Realloc(m_pos + iSize), L"Write() - Stream is not allocated");
104 |
105 | amf_size toWrite = AMF_MIN(iSize, m_uiMemorySize - m_pos);
106 | memcpy(m_pMemory + m_pos, pData, toWrite);
107 | m_pos += toWrite;
108 | if(pWritten != NULL)
109 | {
110 | *pWritten = toWrite;
111 | }
112 | return AMF_OK;
113 | }
114 | //-------------------------------------------------------------------------------------------------
115 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::Seek(AMF_SEEK_ORIGIN eOrigin, amf_int64 iPosition, amf_int64* pNewPosition)
116 | {
117 | switch(eOrigin)
118 | {
119 | case AMF_SEEK_BEGIN:
120 | m_pos = (amf_size)iPosition;
121 | break;
122 |
123 | case AMF_SEEK_CURRENT:
124 | m_pos += (amf_size)iPosition;
125 | break;
126 |
127 | case AMF_SEEK_END:
128 | m_pos = m_uiMemorySize - (amf_size)iPosition;
129 | break;
130 | }
131 |
132 | if(m_pos > m_uiMemorySize)
133 | {
134 | m_pos = m_uiMemorySize;
135 | }
136 | if(pNewPosition != NULL)
137 | {
138 | *pNewPosition = m_pos;
139 | }
140 | return AMF_OK;
141 | }
142 | //-------------------------------------------------------------------------------------------------
143 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::GetPosition(amf_int64* pPosition)
144 | {
145 | AMF_RETURN_IF_FALSE(pPosition != NULL, AMF_INVALID_POINTER, L"GetPosition() - pPosition==NULL");
146 | *pPosition = m_pos;
147 | return AMF_OK;
148 | }
149 | //-------------------------------------------------------------------------------------------------
150 | AMF_RESULT AMF_STD_CALL AMFDataStreamMemoryImpl::GetSize(amf_int64* pSize)
151 | {
152 | AMF_RETURN_IF_FALSE(pSize != NULL, AMF_INVALID_POINTER, L"GetPosition() - pSize==NULL");
153 | *pSize = m_uiMemorySize;
154 | return AMF_OK;
155 | }
156 | //-------------------------------------------------------------------------------------------------
157 | bool AMF_STD_CALL AMFDataStreamMemoryImpl::IsSeekable()
158 | {
159 | return true;
160 | }
161 | //-------------------------------------------------------------------------------------------------
162 | //-------------------------------------------------------------------------------------------------
163 | //-------------------------------------------------------------------------------------------------
164 | //-------------------------------------------------------------------------------------------------
165 | //-------------------------------------------------------------------------------------------------
166 |
--------------------------------------------------------------------------------
/external/amf/public/common/DataStreamMemory.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_DataStreamMemory_h
24 | #define AMF_DataStreamMemory_h
25 |
26 | #pragma once
27 |
28 | #include "DataStream.h"
29 | #include "InterfaceImpl.h"
30 |
31 | namespace amf
32 | {
33 | class AMFDataStreamMemoryImpl : public AMFInterfaceImpl
34 | {
35 | public:
36 | AMFDataStreamMemoryImpl();
37 | virtual ~AMFDataStreamMemoryImpl();
38 | // interface
39 | virtual AMF_RESULT AMF_STD_CALL Open(const wchar_t* /*pFileUrl*/, AMF_STREAM_OPEN /*eOpenType*/, AMF_FILE_SHARE /*eShareType*/)
40 | {
41 | //pFileUrl;
42 | //eOpenType;
43 | //eShareType;
44 | return AMF_OK;
45 | }
46 | virtual AMF_RESULT AMF_STD_CALL Close();
47 | virtual AMF_RESULT AMF_STD_CALL Read(void* pData, amf_size iSize, amf_size* pRead);
48 | virtual AMF_RESULT AMF_STD_CALL Write(const void* pData, amf_size iSize, amf_size* pWritten);
49 | virtual AMF_RESULT AMF_STD_CALL Seek(AMF_SEEK_ORIGIN eOrigin, amf_int64 iPosition, amf_int64* pNewPosition);
50 | virtual AMF_RESULT AMF_STD_CALL GetPosition(amf_int64* pPosition);
51 | virtual AMF_RESULT AMF_STD_CALL GetSize(amf_int64* pSize);
52 | virtual bool AMF_STD_CALL IsSeekable();
53 |
54 | protected:
55 | AMF_RESULT Realloc(amf_size iSize);
56 |
57 | amf_uint8* m_pMemory;
58 | amf_size m_uiMemorySize;
59 | amf_size m_uiAllocatedSize;
60 | amf_size m_pos;
61 | private:
62 | AMFDataStreamMemoryImpl(const AMFDataStreamMemoryImpl&);
63 | AMFDataStreamMemoryImpl& operator=(const AMFDataStreamMemoryImpl&);
64 | };
65 | } //namespace amf
66 |
67 | #endif // AMF_DataStreamMemory_h
--------------------------------------------------------------------------------
/external/amf/public/common/InterfaceImpl.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_InterfaceImpl_h
24 | #define AMF_InterfaceImpl_h
25 |
26 | #pragma once
27 |
28 | #include "../include/core/Interface.h"
29 | #include "Thread.h"
30 |
31 | #pragma warning(disable : 4511)
32 | namespace amf
33 | {
34 | #define AMF_BEGIN_INTERFACE_MAP \
35 | virtual AMF_RESULT AMF_STD_CALL QueryInterface(const amf::AMFGuid & interfaceID, void** ppInterface) \
36 | { \
37 | AMF_RESULT err = AMF_NO_INTERFACE; \
38 |
39 |
40 | #define AMF_INTERFACE_ENTRY(T) \
41 | if(AMFCompareGUIDs(interfaceID, T::IID())) \
42 | { \
43 | *ppInterface = (void*)static_cast(this); \
44 | this->Acquire(); \
45 | err = AMF_OK; \
46 | } \
47 | else \
48 |
49 | #define AMF_INTERFACE_ENTRY_THIS(T, _TI) \
50 | if(AMFCompareGUIDs(interfaceID, T::IID())) \
51 | { \
52 | *ppInterface = (void*)static_cast(static_cast<_TI*>(this)); \
53 | this->Acquire(); \
54 | err = AMF_OK; \
55 | } \
56 | else \
57 |
58 | #define AMF_INTERFACE_MULTI_ENTRY(T) \
59 | if(AMFCompareGUIDs(interfaceID, T::IID())) \
60 | { \
61 | *ppInterface = (void*)static_cast(this); \
62 | AcquireInternal(); \
63 | err = AMF_OK; \
64 | } \
65 | else \
66 |
67 | #define AMF_INTERFACE_CHAIN_ENTRY(T) \
68 | if(static_cast(*this).T::QueryInterface(interfaceID, ppInterface) == AMF_OK) \
69 | {err = AMF_OK;} \
70 | else \
71 |
72 | //good as an example but we should not use aggregate pattern without big reason - very hard to debug
73 | #define AMF_INTERFACE_AGREGATED_ENTRY(T, _Ptr) \
74 | if(AMFCompareGUIDs(interfaceID, T::IID())) \
75 | { \
76 | T* ptr = static_cast(_Ptr); \
77 | *ppInterface = (void*)ptr; \
78 | ptr->Acquire(); \
79 | err = AMF_OK; \
80 | } \
81 | else \
82 |
83 | #define AMF_INTERFACE_CHAIN_AGREGATED_ENTRY(T, _Ptr) \
84 | if(err = static_cast(_Ptr)->QueryInterface(interfaceID, ppInterface)) { \
85 | } \
86 | else \
87 |
88 | #define AMF_END_INTERFACE_MAP \
89 | {} \
90 | return err; \
91 | } \
92 |
93 |
94 | //---------------------------------------------------------------
95 | class AMFInterfaceBase
96 | {
97 | protected:
98 | amf_long m_refCount;
99 | virtual ~AMFInterfaceBase()
100 | #if __GNUC__ == 11 //WORKAROUND for gcc-11 bug
101 | __attribute__ ((noinline))
102 | #endif
103 | {}
104 | public:
105 | AMFInterfaceBase() : m_refCount(0)
106 | {}
107 | virtual amf_long AMF_STD_CALL AcquireInternal()
108 | {
109 | amf_long newVal = amf_atomic_inc(&m_refCount);
110 | return newVal;
111 | }
112 | virtual amf_long AMF_STD_CALL ReleaseInternal()
113 | {
114 | amf_long newVal = amf_atomic_dec(&m_refCount);
115 | if(newVal == 0)
116 | {
117 | delete this;
118 | }
119 | return newVal;
120 | }
121 | virtual amf_long AMF_STD_CALL RefCountInternal()
122 | {
123 | return m_refCount;
124 | }
125 | };
126 | //---------------------------------------------------------------
127 | template
128 | class AMFInterfaceImpl : public _Base, public AMFInterfaceBase
129 | {
130 | protected:
131 | virtual ~AMFInterfaceImpl()
132 | {}
133 | public:
134 | AMFInterfaceImpl(_Param1 param1, _Param2 param2, _Param3 param3) : _Base(param1, param2, param3)
135 | {}
136 | AMFInterfaceImpl(_Param1 param1, _Param2 param2) : _Base(param1, param2)
137 | {}
138 | AMFInterfaceImpl(_Param1 param1) : _Base(param1)
139 | {}
140 | AMFInterfaceImpl()
141 | {}
142 | virtual amf_long AMF_STD_CALL Acquire()
143 | {
144 | return AMFInterfaceBase::AcquireInternal();
145 | }
146 | virtual amf_long AMF_STD_CALL Release()
147 | {
148 | return AMFInterfaceBase::ReleaseInternal();
149 | }
150 | virtual amf_long AMF_STD_CALL RefCount()
151 | {
152 | return AMFInterfaceBase::RefCountInternal();
153 | }
154 |
155 | AMF_BEGIN_INTERFACE_MAP
156 | AMF_INTERFACE_ENTRY(AMFInterface)
157 | AMF_INTERFACE_ENTRY(_Base)
158 | AMF_END_INTERFACE_MAP
159 | };
160 |
161 | //---------------------------------------------------------------
162 | template
163 | class AMFInterfaceMultiImpl : public _Base
164 | {
165 | protected:
166 | virtual ~AMFInterfaceMultiImpl()
167 | {}
168 | public:
169 | AMFInterfaceMultiImpl(_Param1 param1, _Param2 param2, _Param3 param3, _Param4 param4, _Param5 param5, _Param6 param6) : _Base(param1, param2, param3, param4, param5, param6)
170 | {}
171 | AMFInterfaceMultiImpl(_Param1 param1, _Param2 param2, _Param3 param3, _Param4 param4, _Param5 param5) : _Base(param1, param2, param3, param4, param5)
172 | {}
173 | AMFInterfaceMultiImpl(_Param1 param1, _Param2 param2, _Param3 param3, _Param4 param4) : _Base(param1, param2, param3, param4)
174 | {}
175 | AMFInterfaceMultiImpl(_Param1 param1, _Param2 param2, _Param3 param3) : _Base(param1, param2, param3)
176 | {}
177 | AMFInterfaceMultiImpl(_Param1 param1, _Param2 param2) : _Base(param1, param2)
178 | {}
179 | AMFInterfaceMultiImpl(_Param1 param1) : _Base(param1)
180 | {}
181 | AMFInterfaceMultiImpl()
182 | {}
183 | virtual amf_long AMF_STD_CALL Acquire()
184 | {
185 | return AMFInterfaceBase::AcquireInternal();
186 | }
187 | virtual amf_long AMF_STD_CALL Release()
188 | {
189 | return AMFInterfaceBase::ReleaseInternal();
190 | }
191 | virtual amf_long AMF_STD_CALL RefCount()
192 | {
193 | return AMFInterfaceBase::RefCountInternal();
194 | }
195 |
196 | AMF_BEGIN_INTERFACE_MAP
197 | AMF_INTERFACE_ENTRY_THIS(AMFInterface, _BaseInterface)
198 | AMF_INTERFACE_CHAIN_ENTRY(_Base)
199 | AMF_END_INTERFACE_MAP
200 | };
201 |
202 |
203 | } // namespace amf
204 | #endif // AMF_InterfaceImpl_h
--------------------------------------------------------------------------------
/external/amf/public/common/ObservableImpl.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | /**
24 | ***************************************************************************************************
25 | * @file ObservableImpl.h
26 | * @brief AMFObservableImpl common template declaration
27 | ***************************************************************************************************
28 | */
29 | #ifndef AMF_ObservableImpl_h
30 | #define AMF_ObservableImpl_h
31 | #pragma once
32 |
33 | #include "Thread.h"
34 | #include
35 |
36 | namespace amf
37 | {
38 | template
39 | class AMFObservableImpl
40 | {
41 | private:
42 | typedef std::list ObserversList;
43 | ObserversList m_observers;
44 | public:
45 | AMFObservableImpl() : m_observers()
46 | {}
47 | virtual ~AMFObservableImpl()
48 | {
49 | assert(m_observers.size() == 0);
50 | }
51 | virtual void AMF_STD_CALL AddObserver(Observer* pObserver)
52 | {
53 | if (pObserver == nullptr)
54 | {
55 | return;
56 | }
57 |
58 | amf_bool found = false;
59 | AMFLock lock(&m_sc);
60 |
61 | for (typename ObserversList::iterator it = m_observers.begin(); it != m_observers.end(); it++)
62 | {
63 | if (*it == pObserver)
64 | {
65 | found = true;
66 | break;
67 | }
68 | }
69 | if (found == false)
70 | {
71 | m_observers.push_back(pObserver);
72 | }
73 | }
74 |
75 | virtual void AMF_STD_CALL RemoveObserver(Observer* pObserver)
76 | {
77 | AMFLock lock(&m_sc);
78 | m_observers.remove(pObserver);
79 | }
80 |
81 | protected:
82 | void AMF_STD_CALL ClearObservers()
83 | {
84 | AMFLock lock(&m_sc);
85 | m_observers.clear();
86 | }
87 |
88 | void AMF_STD_CALL NotifyObservers(void (AMF_STD_CALL Observer::* pEvent)())
89 | {
90 | ObserversList tempList;
91 | {
92 | AMFLock lock(&m_sc);
93 | tempList = m_observers;
94 | }
95 | for (typename ObserversList::iterator it = tempList.begin(); it != tempList.end(); ++it)
96 | {
97 | Observer* pObserver = *it;
98 | (pObserver->*pEvent)();
99 | }
100 | }
101 |
102 | template
103 | void AMF_STD_CALL NotifyObservers(void (AMF_STD_CALL Observer::* pEvent)(TArg0), TArg0 arg0)
104 | {
105 | ObserversList tempList;
106 | {
107 | AMFLock lock(&m_sc);
108 | tempList = m_observers;
109 | }
110 | for (typename ObserversList::iterator it = tempList.begin(); it != tempList.end(); ++it)
111 | {
112 | Observer* pObserver = *it;
113 | (pObserver->*pEvent)(arg0);
114 | }
115 | }
116 | template
117 | void AMF_STD_CALL NotifyObservers(void (AMF_STD_CALL Observer::* pEvent)(TArg0, TArg1), TArg0 arg0, TArg1 arg1)
118 | {
119 | ObserversList tempList;
120 | {
121 | AMFLock lock(&m_sc);
122 | tempList = m_observers;
123 | }
124 | for (typename ObserversList::iterator it = tempList.begin(); it != tempList.end(); it++)
125 | {
126 | Observer* pObserver = *it;
127 | (pObserver->*pEvent)(arg0, arg1);
128 | }
129 | }
130 | private:
131 | AMFCriticalSection m_sc;
132 | };
133 | }
134 | #endif //AMF_ObservableImpl_h
135 |
--------------------------------------------------------------------------------
/external/amf/public/include/components/ColorSpace.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | //-------------------------------------------------------------------------------------------------
24 | // Color Spacedeclaration
25 | //-------------------------------------------------------------------------------------------------
26 | #ifndef AMF_ColorSpace_h
27 | #define AMF_ColorSpace_h
28 | #pragma once
29 |
30 | #include "../core/Platform.h"
31 |
32 | // YUV <--> RGB conversion matrix with range
33 | typedef enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM
34 | {
35 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN =-1,
36 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_601 = 0, // studio range
37 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_709 = 1, // studio range
38 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020 = 2, // studio range
39 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_JPEG = 3, // full range 601
40 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE_G22_BT709 = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709,
41 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE_G10_SCRGB = 4,
42 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE_G10_BT709 = 5,
43 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE_G10_BT2020 = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020,
44 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE_G2084_BT2020 = 6,
45 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601 = AMF_VIDEO_CONVERTER_COLOR_PROFILE_JPEG, // full range
46 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709 = 7, // full range
47 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020 = 8, // full range
48 | AMF_VIDEO_CONVERTER_COLOR_PROFILE_COUNT
49 | } AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM;
50 |
51 | typedef enum AMF_COLOR_PRIMARIES_ENUM // as in VUI color_primaries AVC and HEVC
52 | {
53 | AMF_COLOR_PRIMARIES_UNDEFINED = 0,
54 | AMF_COLOR_PRIMARIES_BT709 = 1,
55 | AMF_COLOR_PRIMARIES_UNSPECIFIED = 2,
56 | AMF_COLOR_PRIMARIES_RESERVED = 3,
57 | AMF_COLOR_PRIMARIES_BT470M = 4,
58 | AMF_COLOR_PRIMARIES_BT470BG = 5,
59 | AMF_COLOR_PRIMARIES_SMPTE170M = 6,
60 | AMF_COLOR_PRIMARIES_SMPTE240M = 7,
61 | AMF_COLOR_PRIMARIES_FILM = 8,
62 | AMF_COLOR_PRIMARIES_BT2020 = 9,
63 | AMF_COLOR_PRIMARIES_SMPTE428 = 10,
64 | AMF_COLOR_PRIMARIES_SMPTE431 = 11,
65 | AMF_COLOR_PRIMARIES_SMPTE432 = 12,
66 | AMF_COLOR_PRIMARIES_JEDEC_P22 = 22,
67 | AMF_COLOR_PRIMARIES_CCCS = 1000, // Common Composition Color Space or scRGB
68 | } AMF_COLOR_PRIMARIES_ENUM;
69 |
70 | typedef enum AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM // as in VUI transfer_characteristic AVC and HEVC
71 | {
72 | AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED = 0,
73 | AMF_COLOR_TRANSFER_CHARACTERISTIC_BT709 = 1, //BT709
74 | AMF_COLOR_TRANSFER_CHARACTERISTIC_UNSPECIFIED = 2,
75 | AMF_COLOR_TRANSFER_CHARACTERISTIC_RESERVED = 3,
76 | AMF_COLOR_TRANSFER_CHARACTERISTIC_GAMMA22 = 4, //BT470_M
77 | AMF_COLOR_TRANSFER_CHARACTERISTIC_GAMMA28 = 5, //BT470
78 | AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE170M = 6, //BT601
79 | AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE240M = 7, //SMPTE 240M
80 | AMF_COLOR_TRANSFER_CHARACTERISTIC_LINEAR = 8,
81 | AMF_COLOR_TRANSFER_CHARACTERISTIC_LOG = 9, //LOG10
82 | AMF_COLOR_TRANSFER_CHARACTERISTIC_LOG_SQRT = 10,//LOG10 SQRT
83 | AMF_COLOR_TRANSFER_CHARACTERISTIC_IEC61966_2_4 = 11,
84 | AMF_COLOR_TRANSFER_CHARACTERISTIC_BT1361_ECG = 12,
85 | AMF_COLOR_TRANSFER_CHARACTERISTIC_IEC61966_2_1 = 13,
86 | AMF_COLOR_TRANSFER_CHARACTERISTIC_BT2020_10 = 14, //BT709
87 | AMF_COLOR_TRANSFER_CHARACTERISTIC_BT2020_12 = 15, //BT709
88 | AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE2084 = 16, //PQ
89 | AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE428 = 17,
90 | AMF_COLOR_TRANSFER_CHARACTERISTIC_ARIB_STD_B67 = 18, //HLG
91 | } AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM;
92 |
93 | typedef enum AMF_COLOR_BIT_DEPTH_ENUM
94 | {
95 | AMF_COLOR_BIT_DEPTH_UNDEFINED = 0,
96 | AMF_COLOR_BIT_DEPTH_8 = 8,
97 | AMF_COLOR_BIT_DEPTH_10 = 10,
98 | } AMF_COLOR_BIT_DEPTH_ENUM;
99 |
100 | typedef struct AMFHDRMetadata
101 | {
102 | amf_uint16 redPrimary[2]; // normalized to 50000
103 | amf_uint16 greenPrimary[2]; // normalized to 50000
104 | amf_uint16 bluePrimary[2]; // normalized to 50000
105 | amf_uint16 whitePoint[2]; // normalized to 50000
106 | amf_uint32 maxMasteringLuminance; // normalized to 10000
107 | amf_uint32 minMasteringLuminance; // normalized to 10000
108 | amf_uint16 maxContentLightLevel; // nit value
109 | amf_uint16 maxFrameAverageLightLevel; // nit value
110 | } AMFHDRMetadata;
111 |
112 |
113 | typedef enum AMF_COLOR_RANGE_ENUM
114 | {
115 | AMF_COLOR_RANGE_UNDEFINED = 0,
116 | AMF_COLOR_RANGE_STUDIO = 1,
117 | AMF_COLOR_RANGE_FULL = 2,
118 | } AMF_COLOR_RANGE_ENUM;
119 |
120 |
121 | // these properties can be set on input or outout surface
122 | // IDs are the same as in decoder properties
123 | // can be used to dynamically pass color data between components:
124 | // Decoder, Capture, Encoder. Presenter etc.
125 | #define AMF_VIDEO_COLOR_TRANSFER_CHARACTERISTIC L"ColorTransferChar" // amf_int64(AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM); default = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED, ISO/IEC 23001-8_2013 Section 7.2 See ColorSpace.h for enum
126 | #define AMF_VIDEO_COLOR_PRIMARIES L"ColorPrimaries" // amf_int64(AMF_COLOR_PRIMARIES_ENUM); default = AMF_COLOR_PRIMARIES_UNDEFINED, ISO/IEC 23001-8_2013 Section 7.1 See ColorSpace.h for enum
127 | #define AMF_VIDEO_COLOR_RANGE L"ColorRange" // amf_int64(AMF_COLOR_RANGE_ENUM) default = AMF_COLOR_RANGE_UNDEFINED
128 | #define AMF_VIDEO_COLOR_HDR_METADATA L"HdrMetadata" // AMFBuffer containing AMFHDRMetadata; default NULL
129 |
130 | #endif //#ifndef AMF_ColorSpace_h
131 |
--------------------------------------------------------------------------------
/external/amf/public/include/components/ComponentCaps.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_ComponentCaps_h
24 | #define AMF_ComponentCaps_h
25 |
26 | #pragma once
27 |
28 | #include "../core/Interface.h"
29 | #include "../core/PropertyStorage.h"
30 | #include "../core/Surface.h"
31 |
32 | #if defined(__cplusplus)
33 | namespace amf
34 | {
35 | #endif
36 | typedef enum AMF_ACCELERATION_TYPE
37 | {
38 | AMF_ACCEL_NOT_SUPPORTED = -1,
39 | AMF_ACCEL_HARDWARE,
40 | AMF_ACCEL_GPU,
41 | AMF_ACCEL_SOFTWARE
42 | } AMF_ACCELERATION_TYPE;
43 | //----------------------------------------------------------------------------------------------
44 | // AMFIOCaps interface
45 | //----------------------------------------------------------------------------------------------
46 | #if defined(__cplusplus)
47 | class AMF_NO_VTABLE AMFIOCaps : public AMFInterface
48 | {
49 | public:
50 | // Get supported resolution ranges in pixels/lines:
51 | virtual void AMF_STD_CALL GetWidthRange(amf_int32* minWidth, amf_int32* maxWidth) const = 0;
52 | virtual void AMF_STD_CALL GetHeightRange(amf_int32* minHeight, amf_int32* maxHeight) const = 0;
53 |
54 | // Get memory alignment in lines: Vertical aligmnent should be multiples of this number
55 | virtual amf_int32 AMF_STD_CALL GetVertAlign() const = 0;
56 |
57 | // Enumerate supported surface pixel formats
58 | virtual amf_int32 AMF_STD_CALL GetNumOfFormats() const = 0;
59 | virtual AMF_RESULT AMF_STD_CALL GetFormatAt(amf_int32 index, AMF_SURFACE_FORMAT* format, amf_bool* native) const = 0;
60 |
61 | // Enumerate supported memory types
62 | virtual amf_int32 AMF_STD_CALL GetNumOfMemoryTypes() const = 0;
63 | virtual AMF_RESULT AMF_STD_CALL GetMemoryTypeAt(amf_int32 index, AMF_MEMORY_TYPE* memType, amf_bool* native) const = 0;
64 |
65 | virtual amf_bool AMF_STD_CALL IsInterlacedSupported() const = 0;
66 | };
67 | //----------------------------------------------------------------------------------------------
68 | // smart pointer
69 | //----------------------------------------------------------------------------------------------
70 | typedef AMFInterfacePtr_T AMFIOCapsPtr;
71 | #else // #if defined(__cplusplus)
72 | typedef struct AMFIOCaps AMFIOCaps;
73 |
74 | typedef struct AMFIOCapsVtbl
75 | {
76 | // AMFInterface interface
77 | amf_long (AMF_STD_CALL *Acquire)(AMFIOCaps* pThis);
78 | amf_long (AMF_STD_CALL *Release)(AMFIOCaps* pThis);
79 | enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFIOCaps* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
80 |
81 | // AMFIOCaps interface
82 | // Get supported resolution ranges in pixels/lines:
83 | void (AMF_STD_CALL *GetWidthRange)(AMFIOCaps* pThis, amf_int32* minWidth, amf_int32* maxWidth);
84 | void (AMF_STD_CALL *GetHeightRange)(AMFIOCaps* pThis, amf_int32* minHeight, amf_int32* maxHeight);
85 |
86 | // Get memory alignment in lines: Vertical aligmnent should be multiples of this number
87 | amf_int32 (AMF_STD_CALL *GetVertAlign)(AMFIOCaps* pThis);
88 |
89 | // Enumerate supported surface pixel formats
90 | amf_int32 (AMF_STD_CALL *GetNumOfFormats)(AMFIOCaps* pThis);
91 | AMF_RESULT (AMF_STD_CALL *GetFormatAt)(AMFIOCaps* pThis, amf_int32 index, AMF_SURFACE_FORMAT* format, amf_bool* native);
92 |
93 | // Enumerate supported memory types
94 | amf_int32 (AMF_STD_CALL *GetNumOfMemoryTypes)(AMFIOCaps* pThis);
95 | AMF_RESULT (AMF_STD_CALL *GetMemoryTypeAt)(AMFIOCaps* pThis, amf_int32 index, AMF_MEMORY_TYPE* memType, amf_bool* native);
96 |
97 | amf_bool (AMF_STD_CALL *IsInterlacedSupported)(AMFIOCaps* pThis);
98 | } AMFIOCapsVtbl;
99 |
100 | struct AMFIOCaps
101 | {
102 | const AMFIOCapsVtbl *pVtbl;
103 | };
104 |
105 | #endif // #if defined(__cplusplus)
106 |
107 | //----------------------------------------------------------------------------------------------
108 | // AMFCaps interface - base interface for every h/w module supported by Capability Manager
109 | //----------------------------------------------------------------------------------------------
110 | #if defined(__cplusplus)
111 | class AMF_NO_VTABLE AMFCaps : public AMFPropertyStorage
112 | {
113 | public:
114 | virtual AMF_ACCELERATION_TYPE AMF_STD_CALL GetAccelerationType() const = 0;
115 | virtual AMF_RESULT AMF_STD_CALL GetInputCaps(AMFIOCaps** input) = 0;
116 | virtual AMF_RESULT AMF_STD_CALL GetOutputCaps(AMFIOCaps** output) = 0;
117 | };
118 | //----------------------------------------------------------------------------------------------
119 | // smart pointer
120 | //----------------------------------------------------------------------------------------------
121 | typedef AMFInterfacePtr_T AMFCapsPtr;
122 | #else // #if defined(__cplusplus)
123 | typedef struct AMFCaps AMFCaps;
124 |
125 | typedef struct AMFCapsVtbl
126 | {
127 | // AMFInterface interface
128 | amf_long (AMF_STD_CALL *Acquire)(AMFCaps* pThis);
129 | amf_long (AMF_STD_CALL *Release)(AMFCaps* pThis);
130 | enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFCaps* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
131 |
132 | // AMFPropertyStorage interface
133 | AMF_RESULT (AMF_STD_CALL *SetProperty)(AMFCaps* pThis, const wchar_t* name, AMFVariantStruct value);
134 | AMF_RESULT (AMF_STD_CALL *GetProperty)(AMFCaps* pThis, const wchar_t* name, AMFVariantStruct* pValue);
135 | amf_bool (AMF_STD_CALL *HasProperty)(AMFCaps* pThis, const wchar_t* name);
136 | amf_size (AMF_STD_CALL *GetPropertyCount)(AMFCaps* pThis);
137 | AMF_RESULT (AMF_STD_CALL *GetPropertyAt)(AMFCaps* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
138 | AMF_RESULT (AMF_STD_CALL *Clear)(AMFCaps* pThis);
139 | AMF_RESULT (AMF_STD_CALL *AddTo)(AMFCaps* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
140 | AMF_RESULT (AMF_STD_CALL *CopyTo)(AMFCaps* pThis, AMFPropertyStorage* pDest, amf_bool deep);
141 | void (AMF_STD_CALL *AddObserver)(AMFCaps* pThis, AMFPropertyStorageObserver* pObserver);
142 | void (AMF_STD_CALL *RemoveObserver)(AMFCaps* pThis, AMFPropertyStorageObserver* pObserver);
143 |
144 | // AMFCaps interface
145 |
146 | AMF_ACCELERATION_TYPE (AMF_STD_CALL *GetAccelerationType)(AMFCaps* pThis);
147 | AMF_RESULT (AMF_STD_CALL *GetInputCaps)(AMFCaps* pThis, AMFIOCaps** input);
148 | AMF_RESULT (AMF_STD_CALL *GetOutputCaps)(AMFCaps* pThis, AMFIOCaps** output);
149 | } AMFCapsVtbl;
150 |
151 | struct AMFCaps
152 | {
153 | const AMFCapsVtbl *pVtbl;
154 | };
155 | #endif // #if defined(__cplusplus)
156 |
157 | //----------------------------------------------------------------------------------------------
158 | #if defined(__cplusplus)
159 | }
160 | #endif
161 |
162 | #endif //#ifndef AMF_ComponentCaps_h
163 |
--------------------------------------------------------------------------------
/external/amf/public/include/components/DisplayCapture.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | //-------------------------------------------------------------------------------------------------
24 | // Desktop duplication interface declaration
25 | //-------------------------------------------------------------------------------------------------
26 |
27 | #ifndef AMF_DisplayCapture_h
28 | #define AMF_DisplayCapture_h
29 | #pragma once
30 |
31 | #include "Component.h"
32 |
33 | extern "C"
34 | {
35 | // To create capture component with Desktop Duplication API use this function
36 | AMF_RESULT AMF_CDECL_CALL AMFCreateComponentDisplayCapture(amf::AMFContext* pContext, void* reserved, amf::AMFComponent** ppComponent);
37 | }
38 |
39 | // To create AMD Direct Capture component use this component ID with AMFFactory::CreateComponent()
40 | #define AMFDisplayCapture L"AMFDisplayCapture"
41 |
42 | // Static properties
43 | //
44 | typedef enum AMF_DISPLAYCAPTURE_MODE_ENUM
45 | {
46 | AMF_DISPLAYCAPTURE_MODE_KEEP_FRAMERATE = 0, // capture component maintains the frame rate and returns current visible surface
47 | AMF_DISPLAYCAPTURE_MODE_WAIT_FOR_PRESENT = 1, // capture component waits for flip (present) event
48 | AMF_DISPLAYCAPTURE_MODE_GET_CURRENT_SURFACE = 2, // returns current visible surface immediately
49 | } AMF_DISPLAYCAPTURE_MODE_ENUM;
50 |
51 |
52 | #define AMF_DISPLAYCAPTURE_MONITOR_INDEX L"MonitorIndex" // amf_int64, default = 0, Index of the display monitor; is determined by using EnumAdapters() in DXGI.
53 | #define AMF_DISPLAYCAPTURE_MODE L"CaptureMode" // amf_int64(AMF_DISPLAYCAPTURE_MODE_ENUM), default = AMF_DISPLAYCAPTURE_MODE_FRAMERATE, controls wait logic
54 | #define AMF_DISPLAYCAPTURE_FRAMERATE L"FrameRate" // AMFRate, default = (0, 1) Capture framerate, if 0 - capture rate will be driven by flip event from fullscreen app or DWM
55 | #define AMF_DISPLAYCAPTURE_CURRENT_TIME_INTERFACE L"CurrentTimeInterface" // AMFInterface(AMFCurrentTime) Optional interface object for providing timestamps.
56 | #define AMF_DISPLAYCAPTURE_FORMAT L"CurrentFormat" // amf_int64(AMF_SURFACE_FORMAT) Capture format - read-only
57 | #define AMF_DISPLAYCAPTURE_RESOLUTION L"Resolution" // AMFSize - screen resolution - read-only
58 | #define AMF_DISPLAYCAPTURE_DUPLICATEOUTPUT L"DuplicateOutput" // amf_bool, default = false, output AMF surface is a copy of captured
59 | #define AMF_DISPLAYCAPTURE_DESKTOP_RECT L"DesktopRect" // AMFRect - rect of the capture desktop - read-only
60 | #define AMF_DISPLAYCAPTURE_ENABLE_DIRTY_RECTS L"EnableDirtyRects" // amf_bool, default = false, enable dirty rectangles attached to output as AMF_DISPLAYCAPTURE_DIRTY_RECTS
61 | #define AMF_DISPLAYCAPTURE_DRAW_DIRTY_RECTS L"DrawDirtyRects" // amf_bool, default = false, copies capture output and draws dirty rectangles with red - for debugging only
62 | #define AMF_DISPLAYCAPTURE_ROTATION L"Rotation" // amf_int64(AMF_ROTATION_ENUM); default = AMF_ROTATION_NONE, monitor rotation state
63 |
64 | // Properties that can be set on output AMFSurface
65 | #define AMF_DISPLAYCAPTURE_DIRTY_RECTS L"DirtyRects" // AMFInterface*(AMFBuffer*) - array of AMFRect(s)
66 | #define AMF_DISPLAYCAPTURE_FRAME_INDEX L"FrameIndex" // amf_int64; default = 0, index of presented frame since capture started
67 | #define AMF_DISPLAYCAPTURE_FRAME_FLIP_TIMESTAMP L"FlipTimesamp" // amf_int64; default = 0, flip timestmap of presented frame
68 | // see Surface.h
69 | //#define AMF_SURFACE_ROTATION L"Rotation" // amf_int64(AMF_ROTATION_ENUM); default = AMF_ROTATION_NONE, can be set on surfaces - the same value as AMF_DISPLAYCAPTURE_ROTATION
70 |
71 | #endif // #ifndef AMF_DisplayCapture_h
72 |
--------------------------------------------------------------------------------
/external/amf/public/include/components/VideoConverter.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | //-------------------------------------------------------------------------------------------------
24 | // AMFFVideoConverter interface declaration
25 | //-------------------------------------------------------------------------------------------------
26 | #ifndef AMF_VideoConverter_h
27 | #define AMF_VideoConverter_h
28 | #pragma once
29 |
30 | #include "Component.h"
31 | #include "ColorSpace.h"
32 |
33 | #define AMFVideoConverter L"AMFVideoConverter"
34 |
35 | enum AMF_VIDEO_CONVERTER_SCALE_ENUM
36 | {
37 | AMF_VIDEO_CONVERTER_SCALE_INVALID = -1,
38 | AMF_VIDEO_CONVERTER_SCALE_BILINEAR = 0,
39 | AMF_VIDEO_CONVERTER_SCALE_BICUBIC = 1
40 | };
41 |
42 | enum AMF_VIDEO_CONVERTER_TONEMAPPING_ENUM
43 | {
44 | AMF_VIDEO_CONVERTER_TONEMAPPING_COPY = 0,
45 | AMF_VIDEO_CONVERTER_TONEMAPPING_AMD = 1,
46 | AMF_VIDEO_CONVERTER_TONEMAPPING_LINEAR = 2,
47 | AMF_VIDEO_CONVERTER_TONEMAPPING_GAMMA = 3,
48 | AMF_VIDEO_CONVERTER_TONEMAPPING_REINHARD = 4,
49 | AMF_VIDEO_CONVERTER_TONEMAPPING_2390 = 5,
50 | };
51 |
52 |
53 |
54 | #define AMF_VIDEO_CONVERTER_OUTPUT_FORMAT L"OutputFormat" // Values : AMF_SURFACE_NV12 or AMF_SURFACE_BGRA or AMF_SURFACE_YUV420P
55 | #define AMF_VIDEO_CONVERTER_MEMORY_TYPE L"MemoryType" // Values : AMF_MEMORY_DX11 or AMF_MEMORY_DX9 or AMF_MEMORY_UNKNOWN (get from input type)
56 | #define AMF_VIDEO_CONVERTER_COMPUTE_DEVICE L"ComputeDevice" // Values : AMF_MEMORY_COMPUTE_FOR_DX9 enumeration
57 |
58 | #define AMF_VIDEO_CONVERTER_OUTPUT_SIZE L"OutputSize" // AMFSize (default=0,0) width in pixels. default means no scaling
59 | #define AMF_VIDEO_CONVERTER_OUTPUT_RECT L"OutputRect" // AMFRect (default=0, 0, 0, 0) rectangle in pixels. default means no rect
60 | #define AMF_VIDEO_CONVERTER_SCALE L"ScaleType" // amf_int64(AMF_VIDEO_CONVERTER_SCALE_ENUM); default = AMF_VIDEO_CONVERTER_SCALE_BILINEAR
61 | #define AMF_VIDEO_CONVERTER_FORCE_OUTPUT_SURFACE_SIZE L"ForceOutputSurfaceSize" // bool (default=false) Force output size from output surface
62 |
63 | #define AMF_VIDEO_CONVERTER_KEEP_ASPECT_RATIO L"KeepAspectRatio" // bool (default=false) Keep aspect ratio if scaling.
64 | #define AMF_VIDEO_CONVERTER_FILL L"Fill" // bool (default=false) fill area out of ROI.
65 | #define AMF_VIDEO_CONVERTER_FILL_COLOR L"FillColor" // AMFColor
66 |
67 | //-------------------------------------------------------------------------------------------------
68 | // SDR color conversion
69 | //-------------------------------------------------------------------------------------------------
70 | #define AMF_VIDEO_CONVERTER_COLOR_PROFILE L"ColorProfile" // amf_int64(AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM); default = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN - mean AUTO
71 | #define AMF_VIDEO_CONVERTER_LINEAR_RGB L"LinearRGB" // bool (default=false) Convert to/from linear RGB instead of sRGB using AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC or by default AMF_VIDEO_CONVERTER_TRANSFER_CHARACTERISTIC
72 |
73 | //-------------------------------------------------------------------------------------------------
74 | // HDR color conversion
75 | //-------------------------------------------------------------------------------------------------
76 | // AMF_VIDEO_CONVERTER_COLOR_PROFILE is used to define color space conversion
77 |
78 | // HDR data - can be set on converter or respectively on input and output surfaces (output surface via custom allocator)
79 | // if present, HDR_METADATA primary color overwrites COLOR_PRIMARIES
80 |
81 | // these properties can be set on converter component to configure input and output
82 | // these properties overwrite properties set on surface - see below
83 | #define AMF_VIDEO_CONVERTER_INPUT_TRANSFER_CHARACTERISTIC L"InputTransferChar" // amf_int64(AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM); default = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED, ISO/IEC 23001-8_2013 7.2 See ColorSpace.h for enum
84 | #define AMF_VIDEO_CONVERTER_INPUT_COLOR_PRIMARIES L"InputColorPrimaries" // amf_int64(AMF_COLOR_PRIMARIES_ENUM); default = AMF_COLOR_PRIMARIES_UNDEFINED, ISO/IEC 23001-8_2013 7.1 See ColorSpace.h for enum
85 | #define AMF_VIDEO_CONVERTER_INPUT_COLOR_RANGE L"InputColorRange" // amf_int64(AMF_COLOR_RANGE_ENUM) default = AMF_COLOR_RANGE_UNDEFINED
86 | #define AMF_VIDEO_CONVERTER_INPUT_HDR_METADATA L"InputHdrMetadata" // AMFBuffer containing AMFHDRMetadata; default NULL
87 | #define AMF_VIDEO_CONVERTER_INPUT_TONEMAPPING L"InputTonemapping" // amf_int64(AMF_VIDEO_CONVERTER_TONEMAPPING_ENUM) default = AMF_VIDEO_CONVERTER_TONEMAPPING_LINEAR
88 |
89 | #define AMF_VIDEO_CONVERTER_OUTPUT_TRANSFER_CHARACTERISTIC L"OutputTransferChar" // amf_int64(AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM); default = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED, ISO/IEC 23001-8_2013 7.2 See ColorSpace.h for enum
90 | #define AMF_VIDEO_CONVERTER_OUTPUT_COLOR_PRIMARIES L"OutputColorPrimaries" // amf_int64(AMF_COLOR_PRIMARIES_ENUM); default = AMF_COLOR_PRIMARIES_UNDEFINED, ISO/IEC 23001-8_2013 7.1 See ColorSpace.h for enum
91 | #define AMF_VIDEO_CONVERTER_OUTPUT_COLOR_RANGE L"OutputColorRange" // amf_int64(AMF_COLOR_RANGE_ENUM) default = AMF_COLOR_RANGE_UNDEFINED
92 | #define AMF_VIDEO_CONVERTER_OUTPUT_HDR_METADATA L"OutputHdrMetadata" // AMFBuffer containing AMFHDRMetadata; default NULL
93 | #define AMF_VIDEO_CONVERTER_OUTPUT_TONEMAPPING L"OutputTonemapping" // amf_int64(AMF_VIDEO_CONVERTER_TONEMAPPING_ENUM) default = AMF_VIDEO_CONVERTER_TONEMAPPING_AMD
94 |
95 | // these properties can be set on input or outout surface See ColorSpace.h
96 | // the same as decoder properties set on input surface - see below
97 | //#define AMF_VIDEO_COLOR_TRANSFER_CHARACTERISTIC L"ColorTransferChar" // amf_int64(AMF_COLOR_TRANSFER_CHARACTERISTIC_ENUM); default = AMF_COLOR_TRANSFER_CHARACTERISTIC_UNDEFINED, ISO/IEC 23001-8_2013 7.2 See ColorSpace.h for enum
98 | //#define AMF_VIDEO_COLOR_PRIMARIES L"ColorPrimaries" // amf_int64(AMF_COLOR_PRIMARIES_ENUM); default = AMF_COLOR_PRIMARIES_UNDEFINED, ISO/IEC 23001-8_2013 7.1 See ColorSpace.h for enum
99 | //#define AMF_VIDEO_COLOR_RANGE L"ColorRange" // amf_int64(AMF_COLOR_RANGE_ENUM) default = AMF_COLOR_RANGE_UNDEFINED
100 | //#define AMF_VIDEO_COLOR_HDR_METADATA L"HdrMetadata" // AMFBuffer containing AMFHDRMetadata; default NULL
101 |
102 | // If decoder properties can be set on input see VideoDecoder.h
103 | // AMF_VIDEO_DECODER_COLOR_TRANSFER_CHARACTERISTIC
104 | // AMF_VIDEO_DECODER_COLOR_PRIMARIES
105 | // AMF_VIDEO_DECODER_COLOR_RANGE
106 | // AMF_VIDEO_DECODER_HDR_METADATA
107 |
108 | #define AMF_VIDEO_CONVERTER_USE_DECODER_HDR_METADATA L"UseDecoderHDRMetadata" // bool (default=true) enables use of decoder / surface input color properties above
109 |
110 |
111 | #endif //#ifndef AMF_VideoConverter_h
112 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/ComputeFactory.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_ComputeFactory_h
24 | #define AMF_ComputeFactory_h
25 | #pragma once
26 |
27 | #include "Compute.h"
28 |
29 | #if defined(__cplusplus)
30 | namespace amf
31 | {
32 | #endif
33 | // compute device audio capabilities accessed via GetProperties() from AMFComputeDevice
34 | #define AMF_DEVICE_NAME L"DeviceName" // char*, string, device name
35 | #define AMF_DRIVER_VERSION_NAME L"DriverVersion" // char*, string, driver version
36 | #define AMF_AUDIO_CONVOLUTION_MAX_STREAMS L"ConvolutionMaxStreams" // amf_int64, maximum number of audio streams supported in realtime
37 | #define AMF_AUDIO_CONVOLUTION_LENGTH L"ConvolutionLength" // amf_int64, length of convolution in samples
38 | #define AMF_AUDIO_CONVOLUTION_BUFFER_SIZE L"ConvolutionBufferSize" // amf_int64, buffer size in samples
39 | #define AMF_AUDIO_CONVOLUTION_SAMPLE_RATE L"ConvolutionSampleRate" // amf_int64, sample rate
40 |
41 | #if defined(__cplusplus)
42 | class AMF_NO_VTABLE AMFComputeDevice : public AMFPropertyStorage
43 | {
44 | public:
45 | AMF_DECLARE_IID(0xb79d7cf6, 0x2c5c, 0x4deb, 0xb8, 0x96, 0xa2, 0x9e, 0xbe, 0xa6, 0xe3, 0x97)
46 |
47 | virtual void* AMF_STD_CALL GetNativePlatform() = 0;
48 | virtual void* AMF_STD_CALL GetNativeDeviceID() = 0;
49 | virtual void* AMF_STD_CALL GetNativeContext() = 0;
50 |
51 | virtual AMF_RESULT AMF_STD_CALL CreateCompute(void *reserved, AMFCompute **ppCompute) = 0;
52 | virtual AMF_RESULT AMF_STD_CALL CreateComputeEx(void* pCommandQueue, AMFCompute **ppCompute) = 0;
53 | };
54 | //----------------------------------------------------------------------------------------------
55 | // smart pointer
56 | //----------------------------------------------------------------------------------------------
57 | typedef AMFInterfacePtr_T AMFComputeDevicePtr;
58 | #else // #if defined(__cplusplus)
59 | AMF_DECLARE_IID(AMFComputeDevice, 0xb79d7cf6, 0x2c5c, 0x4deb, 0xb8, 0x96, 0xa2, 0x9e, 0xbe, 0xa6, 0xe3, 0x97)
60 | typedef struct AMFComputeDevice AMFComputeDevice;
61 |
62 | typedef struct AMFComputeDeviceVtbl
63 | {
64 | // AMFInterface interface
65 | amf_long (AMF_STD_CALL *Acquire)(AMFComputeDevice* pThis);
66 | amf_long (AMF_STD_CALL *Release)(AMFComputeDevice* pThis);
67 | enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFComputeDevice* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
68 |
69 | // AMFPropertyStorage interface
70 | AMF_RESULT (AMF_STD_CALL *SetProperty)(AMFComputeDevice* pThis, const wchar_t* name, AMFVariantStruct value);
71 | AMF_RESULT (AMF_STD_CALL *GetProperty)(AMFComputeDevice* pThis, const wchar_t* name, AMFVariantStruct* pValue);
72 | amf_bool (AMF_STD_CALL *HasProperty)(AMFComputeDevice* pThis, const wchar_t* name);
73 | amf_size (AMF_STD_CALL *GetPropertyCount)(AMFComputeDevice* pThis);
74 | AMF_RESULT (AMF_STD_CALL *GetPropertyAt)(AMFComputeDevice* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
75 | AMF_RESULT (AMF_STD_CALL *Clear)(AMFComputeDevice* pThis);
76 | AMF_RESULT (AMF_STD_CALL *AddTo)(AMFComputeDevice* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
77 | AMF_RESULT (AMF_STD_CALL *CopyTo)(AMFComputeDevice* pThis, AMFPropertyStorage* pDest, amf_bool deep);
78 | void (AMF_STD_CALL *AddObserver)(AMFComputeDevice* pThis, AMFPropertyStorageObserver* pObserver);
79 | void (AMF_STD_CALL *RemoveObserver)(AMFComputeDevice* pThis, AMFPropertyStorageObserver* pObserver);
80 |
81 | // AMFComputeDevice interface
82 | void* (AMF_STD_CALL *GetNativePlatform)(AMFComputeDevice* pThis);
83 | void* (AMF_STD_CALL *GetNativeDeviceID)(AMFComputeDevice* pThis);
84 | void* (AMF_STD_CALL *GetNativeContext)(AMFComputeDevice* pThis);
85 |
86 | AMF_RESULT (AMF_STD_CALL *CreateCompute)(AMFComputeDevice* pThis, void *reserved, AMFCompute **ppCompute);
87 | AMF_RESULT (AMF_STD_CALL *CreateComputeEx)(AMFComputeDevice* pThis, void* pCommandQueue, AMFCompute **ppCompute);
88 |
89 | } AMFComputeDeviceVtbl;
90 |
91 | struct AMFComputeDevice
92 | {
93 | const AMFComputeDeviceVtbl *pVtbl;
94 | };
95 | #endif // #if defined(__cplusplus)
96 | //----------------------------------------------------------------------------------------------
97 | #if defined(__cplusplus)
98 | class AMF_NO_VTABLE AMFComputeFactory : public AMFInterface
99 | {
100 | public:
101 | AMF_DECLARE_IID(0xe3c24bd7, 0x2d83, 0x416c, 0x8c, 0x4e, 0xfd, 0x13, 0xca, 0x86, 0xf4, 0xd0)
102 |
103 | virtual amf_int32 AMF_STD_CALL GetDeviceCount() = 0;
104 | virtual AMF_RESULT AMF_STD_CALL GetDeviceAt(amf_int32 index, AMFComputeDevice **ppDevice) = 0;
105 | };
106 | //----------------------------------------------------------------------------------------------
107 | // smart pointer
108 | //----------------------------------------------------------------------------------------------
109 | typedef AMFInterfacePtr_T AMFComputeFactoryPtr;
110 | #else // #if defined(__cplusplus)
111 | AMF_DECLARE_IID(AMFComputeFactory, 0xe3c24bd7, 0x2d83, 0x416c, 0x8c, 0x4e, 0xfd, 0x13, 0xca, 0x86, 0xf4, 0xd0)
112 | typedef struct AMFComputeFactory AMFComputeFactory;
113 |
114 | typedef struct AMFComputeFactoryVtbl
115 | {
116 | // AMFInterface interface
117 | amf_long (AMF_STD_CALL *Acquire)(AMFComputeFactory* pThis);
118 | amf_long (AMF_STD_CALL *Release)(AMFComputeFactory* pThis);
119 | enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFComputeFactory* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
120 |
121 | // AMFComputeFactory interface
122 | amf_int32 (AMF_STD_CALL *GetDeviceCount)(AMFComputeFactory* pThis);
123 | AMF_RESULT (AMF_STD_CALL *GetDeviceAt)(AMFComputeFactory* pThis, amf_int32 index, AMFComputeDevice **ppDevice);
124 | } AMFComputeFactoryVtbl;
125 |
126 | struct AMFComputeFactory
127 | {
128 | const AMFComputeFactoryVtbl *pVtbl;
129 | };
130 | #endif // #if defined(__cplusplus)
131 |
132 | //----------------------------------------------------------------------------------------------
133 | #if defined(__cplusplus)
134 | } // namespace amf
135 | #endif
136 |
137 | #endif // AMF_ComputeFactory_h
138 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/CurrentTime.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_CurrentTime_h
24 | #define AMF_CurrentTime_h
25 |
26 | #include "Platform.h"
27 | #include "Interface.h"
28 |
29 | namespace amf
30 | {
31 | // Current time interface class. This interface object can be passed
32 | // as a property to components requiring synchronized timing. The
33 | // implementation is:
34 | // - first call to Get() starts time and returns 0
35 | // - subsequent calls to Get() returns values relative to 0
36 | // - Reset() puts time back at 0 at next Get() call
37 | //
38 | class AMF_NO_VTABLE AMFCurrentTime : public AMFInterface
39 | {
40 | public:
41 |
42 | virtual amf_pts AMF_STD_CALL Get() = 0;
43 |
44 | virtual void AMF_STD_CALL Reset() = 0;
45 | };
46 |
47 | //----------------------------------------------------------------------------------------------
48 | // smart pointer
49 | //----------------------------------------------------------------------------------------------
50 | typedef AMFInterfacePtr_T AMFCurrentTimePtr;
51 | //----------------------------------------------------------------------------------------------}
52 | }
53 | #endif // AMF_CurrentTime_h
54 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/Debug.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_Debug_h
24 | #define AMF_Debug_h
25 | #pragma once
26 |
27 | #include "Platform.h"
28 | #include "Result.h"
29 |
30 | #if defined(__cplusplus)
31 | namespace amf
32 | {
33 | #endif
34 | //----------------------------------------------------------------------------------------------
35 | // AMFDebug interface - singleton
36 | //----------------------------------------------------------------------------------------------
37 | #if defined(__cplusplus)
38 | class AMF_NO_VTABLE AMFDebug
39 | {
40 | public:
41 | virtual void AMF_STD_CALL EnablePerformanceMonitor(amf_bool enable) = 0;
42 | virtual amf_bool AMF_STD_CALL PerformanceMonitorEnabled() = 0;
43 | virtual void AMF_STD_CALL AssertsEnable(amf_bool enable) = 0;
44 | virtual amf_bool AMF_STD_CALL AssertsEnabled() = 0;
45 | };
46 | #else // #if defined(__cplusplus)
47 | typedef struct AMFDebug AMFDebug;
48 | typedef struct AMFDebugVtbl
49 | {
50 | // AMFDebug interface
51 | void (AMF_STD_CALL *EnablePerformanceMonitor)(AMFDebug* pThis, amf_bool enable);
52 | amf_bool (AMF_STD_CALL *PerformanceMonitorEnabled)(AMFDebug* pThis);
53 | void (AMF_STD_CALL *AssertsEnable)(AMFDebug* pThis, amf_bool enable);
54 | amf_bool (AMF_STD_CALL *AssertsEnabled)(AMFDebug* pThis);
55 | } AMFDebugVtbl;
56 |
57 | struct AMFDebug
58 | {
59 | const AMFDebugVtbl *pVtbl;
60 | };
61 |
62 | #endif // #if defined(__cplusplus)
63 | //----------------------------------------------------------------------------------------------
64 | #if defined(__cplusplus)
65 | }
66 | #endif
67 |
68 | #endif // AMF_Debug_h
69 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/Factory.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_Factory_h
24 | #define AMF_Factory_h
25 | #pragma once
26 |
27 | #include "Platform.h"
28 | #include "Version.h"
29 | #include "Result.h"
30 | #include "Context.h"
31 | #include "Debug.h"
32 | #include "Trace.h"
33 | #include "Compute.h"
34 |
35 | #include "../components/Component.h"
36 |
37 | #if defined(__cplusplus)
38 |
39 | namespace amf
40 | {
41 | #endif
42 | //----------------------------------------------------------------------------------------------
43 | // AMFFactory interface - singleton
44 | //----------------------------------------------------------------------------------------------
45 | #if defined(__cplusplus)
46 | class AMF_NO_VTABLE AMFFactory
47 | {
48 | public:
49 | virtual AMF_RESULT AMF_STD_CALL CreateContext(AMFContext** ppContext) = 0;
50 | virtual AMF_RESULT AMF_STD_CALL CreateComponent(AMFContext* pContext, const wchar_t* id, AMFComponent** ppComponent) = 0;
51 | virtual AMF_RESULT AMF_STD_CALL SetCacheFolder(const wchar_t* path) = 0;
52 | virtual const wchar_t* AMF_STD_CALL GetCacheFolder() = 0;
53 | virtual AMF_RESULT AMF_STD_CALL GetDebug(AMFDebug** ppDebug) = 0;
54 | virtual AMF_RESULT AMF_STD_CALL GetTrace(AMFTrace** ppTrace) = 0;
55 | virtual AMF_RESULT AMF_STD_CALL GetPrograms(AMFPrograms** ppPrograms) = 0;
56 | };
57 | #else
58 | typedef struct AMFFactory AMFFactory;
59 |
60 | typedef struct AMFFactoryVtbl
61 | {
62 | AMF_RESULT (AMF_STD_CALL *CreateContext)(AMFFactory* pThis, AMFContext** ppContext);
63 | AMF_RESULT (AMF_STD_CALL *CreateComponent)(AMFFactory* pThis, AMFContext* pContext, const wchar_t* id, AMFComponent** ppComponent);
64 | AMF_RESULT (AMF_STD_CALL *SetCacheFolder)(AMFFactory* pThis, const wchar_t* path);
65 | const wchar_t* (AMF_STD_CALL *GetCacheFolder)(AMFFactory* pThis);
66 | AMF_RESULT (AMF_STD_CALL *GetDebug)(AMFFactory* pThis, AMFDebug** ppDebug);
67 | AMF_RESULT (AMF_STD_CALL *GetTrace)(AMFFactory* pThis, AMFTrace** ppTrace);
68 | AMF_RESULT (AMF_STD_CALL *GetPrograms)(AMFFactory* pThis, AMFPrograms** ppPrograms);
69 | } AMFFactoryVtbl;
70 |
71 | struct AMFFactory
72 | {
73 | const AMFFactoryVtbl *pVtbl;
74 | };
75 |
76 | #endif
77 | #if defined(__cplusplus)
78 | }
79 | #endif
80 |
81 | //----------------------------------------------------------------------------------------------
82 | // DLL entry points
83 | //----------------------------------------------------------------------------------------------
84 |
85 | #define AMF_INIT_FUNCTION_NAME "AMFInit"
86 | #define AMF_QUERY_VERSION_FUNCTION_NAME "AMFQueryVersion"
87 |
88 | #if defined(__cplusplus)
89 | extern "C"
90 | {
91 | typedef AMF_RESULT (AMF_CDECL_CALL *AMFInit_Fn)(amf_uint64 version, amf::AMFFactory **ppFactory);
92 | typedef AMF_RESULT (AMF_CDECL_CALL *AMFQueryVersion_Fn)(amf_uint64 *pVersion);
93 | }
94 | #else
95 | typedef AMF_RESULT (AMF_CDECL_CALL *AMFInit_Fn)(amf_uint64 version, AMFFactory **ppFactory);
96 | typedef AMF_RESULT (AMF_CDECL_CALL *AMFQueryVersion_Fn)(amf_uint64 *pVersion);
97 | #endif
98 |
99 | #if defined(_WIN32)
100 | #if defined(_M_AMD64)
101 | #define AMF_DLL_NAME L"amfrt64.dll"
102 | #define AMF_DLL_NAMEA "amfrt64.dll"
103 | #else
104 | #define AMF_DLL_NAME L"amfrt32.dll"
105 | #define AMF_DLL_NAMEA "amfrt32.dll"
106 | #endif
107 | #elif defined(__ANDROID__) && !defined(AMF_ANDROID_ENCODER)
108 | #define AMF_DLL_NAME L"libamf.so"
109 | #define AMF_DLL_NAMEA "libamf.so"
110 | #elif defined(__APPLE__)
111 | #define AMF_DLL_NAME L"libamfrt.framework/libamfrt"
112 | #define AMF_DLL_NAMEA "libamfrt.framework/libamfrt"
113 | #elif defined(__linux__)
114 | #if defined(__x86_64__) || defined(__aarch64__)
115 | #define AMF_DLL_NAME L"libamfrt64.so.1"
116 | #define AMF_DLL_NAMEA "libamfrt64.so.1"
117 | #else
118 | #define AMF_DLL_NAME L"libamfrt32.so.1"
119 | #define AMF_DLL_NAMEA "libamfrt32.so.1"
120 | #endif
121 | #endif
122 | //----------------------------------------------------------------------------------------------
123 | #endif // AMF_Factory_h
124 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/Plane.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_Plane_h
24 | #define AMF_Plane_h
25 | #pragma once
26 |
27 | #include "Interface.h"
28 |
29 | #if defined(__cplusplus)
30 | namespace amf
31 | {
32 | #endif
33 | //---------------------------------------------------------------------------------------------
34 | typedef enum AMF_PLANE_TYPE
35 | {
36 | AMF_PLANE_UNKNOWN = 0,
37 | AMF_PLANE_PACKED = 1, // for all packed formats: BGRA, YUY2, etc
38 | AMF_PLANE_Y = 2,
39 | AMF_PLANE_UV = 3,
40 | AMF_PLANE_U = 4,
41 | AMF_PLANE_V = 5,
42 | } AMF_PLANE_TYPE;
43 | //---------------------------------------------------------------------------------------------
44 | // AMFPlane interface
45 | //---------------------------------------------------------------------------------------------
46 | #if defined(__cplusplus)
47 | class AMF_NO_VTABLE AMFPlane : public AMFInterface
48 | {
49 | public:
50 | AMF_DECLARE_IID(0xbede1aa6, 0xd8fa, 0x4625, 0x94, 0x65, 0x6c, 0x82, 0xc4, 0x37, 0x71, 0x2e)
51 |
52 | virtual AMF_PLANE_TYPE AMF_STD_CALL GetType() = 0;
53 | virtual void* AMF_STD_CALL GetNative() = 0;
54 | virtual amf_int32 AMF_STD_CALL GetPixelSizeInBytes() = 0;
55 | virtual amf_int32 AMF_STD_CALL GetOffsetX() = 0;
56 | virtual amf_int32 AMF_STD_CALL GetOffsetY() = 0;
57 | virtual amf_int32 AMF_STD_CALL GetWidth() = 0;
58 | virtual amf_int32 AMF_STD_CALL GetHeight() = 0;
59 | virtual amf_int32 AMF_STD_CALL GetHPitch() = 0;
60 | virtual amf_int32 AMF_STD_CALL GetVPitch() = 0;
61 | virtual bool AMF_STD_CALL IsTiled() = 0;
62 | };
63 | //----------------------------------------------------------------------------------------------
64 | // smart pointer
65 | //----------------------------------------------------------------------------------------------
66 | typedef AMFInterfacePtr_T AMFPlanePtr;
67 | //----------------------------------------------------------------------------------------------
68 | #else // #if defined(__cplusplus)
69 | AMF_DECLARE_IID(AMFPlane, 0xbede1aa6, 0xd8fa, 0x4625, 0x94, 0x65, 0x6c, 0x82, 0xc4, 0x37, 0x71, 0x2e)
70 | typedef struct AMFPlane AMFPlane;
71 | typedef struct AMFPlaneVtbl
72 | {
73 | // AMFInterface interface
74 | amf_long (AMF_STD_CALL *Acquire)(AMFPlane* pThis);
75 | amf_long (AMF_STD_CALL *Release)(AMFPlane* pThis);
76 | enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFPlane* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
77 |
78 | // AMFPlane interface
79 | AMF_PLANE_TYPE (AMF_STD_CALL *GetType)(AMFPlane* pThis);
80 | void* (AMF_STD_CALL *GetNative)(AMFPlane* pThis);
81 | amf_int32 (AMF_STD_CALL *GetPixelSizeInBytes)(AMFPlane* pThis);
82 | amf_int32 (AMF_STD_CALL *GetOffsetX)(AMFPlane* pThis);
83 | amf_int32 (AMF_STD_CALL *GetOffsetY)(AMFPlane* pThis);
84 | amf_int32 (AMF_STD_CALL *GetWidth)(AMFPlane* pThis);
85 | amf_int32 (AMF_STD_CALL *GetHeight)(AMFPlane* pThis);
86 | amf_int32 (AMF_STD_CALL *GetHPitch)(AMFPlane* pThis);
87 | amf_int32 (AMF_STD_CALL *GetVPitch)(AMFPlane* pThis);
88 | amf_bool (AMF_STD_CALL *IsTiled)(AMFPlane* pThis);
89 |
90 | } AMFPlaneVtbl;
91 |
92 | struct AMFPlane
93 | {
94 | const AMFPlaneVtbl *pVtbl;
95 | };
96 | #endif // #if defined(__cplusplus)
97 |
98 | #if defined(__cplusplus)
99 | } // namespace amf
100 | #endif
101 |
102 | #endif //#ifndef AMF_Plane_h
103 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/Result.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #ifndef AMF_Result_h
24 | #define AMF_Result_h
25 | #pragma once
26 |
27 | #include "Platform.h"
28 |
29 | //----------------------------------------------------------------------------------------------
30 | // result codes
31 | //----------------------------------------------------------------------------------------------
32 |
33 | typedef enum AMF_RESULT
34 | {
35 | AMF_OK = 0,
36 | AMF_FAIL ,
37 |
38 | // common errors
39 | AMF_UNEXPECTED ,
40 |
41 | AMF_ACCESS_DENIED ,
42 | AMF_INVALID_ARG ,
43 | AMF_OUT_OF_RANGE ,
44 |
45 | AMF_OUT_OF_MEMORY ,
46 | AMF_INVALID_POINTER ,
47 |
48 | AMF_NO_INTERFACE ,
49 | AMF_NOT_IMPLEMENTED ,
50 | AMF_NOT_SUPPORTED ,
51 | AMF_NOT_FOUND ,
52 |
53 | AMF_ALREADY_INITIALIZED ,
54 | AMF_NOT_INITIALIZED ,
55 |
56 | AMF_INVALID_FORMAT ,// invalid data format
57 |
58 | AMF_WRONG_STATE ,
59 | AMF_FILE_NOT_OPEN ,// cannot open file
60 |
61 | // device common codes
62 | AMF_NO_DEVICE ,
63 |
64 | // device directx
65 | AMF_DIRECTX_FAILED ,
66 | // device opencl
67 | AMF_OPENCL_FAILED ,
68 | // device opengl
69 | AMF_GLX_FAILED ,//failed to use GLX
70 | // device XV
71 | AMF_XV_FAILED , //failed to use Xv extension
72 | // device alsa
73 | AMF_ALSA_FAILED ,//failed to use ALSA
74 |
75 | // component common codes
76 |
77 | //result codes
78 | AMF_EOF ,
79 | AMF_REPEAT ,
80 | AMF_INPUT_FULL ,//returned by AMFComponent::SubmitInput if input queue is full
81 | AMF_RESOLUTION_CHANGED ,//resolution changed client needs to Drain/Terminate/Init
82 | AMF_RESOLUTION_UPDATED ,//resolution changed in adaptive mode. New ROI will be set on output on newly decoded frames
83 |
84 | //error codes
85 | AMF_INVALID_DATA_TYPE ,//invalid data type
86 | AMF_INVALID_RESOLUTION ,//invalid resolution (width or height)
87 | AMF_CODEC_NOT_SUPPORTED ,//codec not supported
88 | AMF_SURFACE_FORMAT_NOT_SUPPORTED ,//surface format not supported
89 | AMF_SURFACE_MUST_BE_SHARED ,//surface should be shared (DX11: (MiscFlags & D3D11_RESOURCE_MISC_SHARED) == 0, DX9: No shared handle found)
90 |
91 | // component video decoder
92 | AMF_DECODER_NOT_PRESENT ,//failed to create the decoder
93 | AMF_DECODER_SURFACE_ALLOCATION_FAILED ,//failed to create the surface for decoding
94 | AMF_DECODER_NO_FREE_SURFACES ,
95 |
96 | // component video encoder
97 | AMF_ENCODER_NOT_PRESENT ,//failed to create the encoder
98 |
99 | // component video processor
100 |
101 | // component video conveter
102 |
103 | // component dem
104 | AMF_DEM_ERROR ,
105 | AMF_DEM_PROPERTY_READONLY ,
106 | AMF_DEM_REMOTE_DISPLAY_CREATE_FAILED ,
107 | AMF_DEM_START_ENCODING_FAILED ,
108 | AMF_DEM_QUERY_OUTPUT_FAILED ,
109 |
110 | // component TAN
111 | AMF_TAN_CLIPPING_WAS_REQUIRED , // Resulting data was truncated to meet output type's value limits.
112 | AMF_TAN_UNSUPPORTED_VERSION , // Not supported version requested, solely for TANCreateContext().
113 |
114 | AMF_NEED_MORE_INPUT ,//returned by AMFComponent::SubmitInput did not produce a buffer because more input submissions are required.
115 |
116 | // device vulkan
117 | AMF_VULKAN_FAILED ,
118 | } AMF_RESULT;
119 |
120 | #endif //#ifndef AMF_Result_h
121 |
--------------------------------------------------------------------------------
/external/amf/public/include/core/Version.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | /**
24 | ***************************************************************************************************
25 | * @file Version.h
26 | * @brief Version declaration
27 | ***************************************************************************************************
28 | */
29 | #ifndef AMF_Version_h
30 | #define AMF_Version_h
31 | #pragma once
32 |
33 | #include "Platform.h"
34 |
35 | #define AMF_MAKE_FULL_VERSION(VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, VERSION_BUILD_NUM) ( ((amf_uint64)(VERSION_MAJOR) << 48ull) | ((amf_uint64)(VERSION_MINOR) << 32ull) | ((amf_uint64)(VERSION_RELEASE) << 16ull) | (amf_uint64)(VERSION_BUILD_NUM))
36 |
37 | #define AMF_GET_MAJOR_VERSION(x) ((x >> 48ull) & 0xFFFF)
38 | #define AMF_GET_MINOR_VERSION(x) ((x >> 32ull) & 0xFFFF)
39 | #define AMF_GET_SUBMINOR_VERSION(x) ((x >> 16ull) & 0xFFFF)
40 | #define AMF_GET_BUILD_VERSION(x) ((x >> 0ull) & 0xFFFF)
41 |
42 | #define AMF_VERSION_MAJOR 1
43 | #define AMF_VERSION_MINOR 4
44 | #define AMF_VERSION_RELEASE 34
45 | #define AMF_VERSION_BUILD_NUM 0
46 |
47 | #define AMF_FULL_VERSION AMF_MAKE_FULL_VERSION(AMF_VERSION_MAJOR, AMF_VERSION_MINOR, AMF_VERSION_RELEASE, AMF_VERSION_BUILD_NUM)
48 |
49 | #endif //#ifndef AMF_Version_h
50 |
--------------------------------------------------------------------------------
/external/amf/public/src/components/DisplayCapture/CaptureStats.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #pragma once
24 |
25 | #include
26 | #include
27 |
28 | #include "public/include/core/Platform.h"
29 |
30 | namespace amf
31 | {
32 | // Utility class for tracking capture information
33 | class CaptureStats
34 | {
35 | public:
36 | CaptureStats()
37 | : m_outfileFilename("")
38 | , m_summary("")
39 | , m_minDuration(MAXLONG)
40 | , m_maxDuration(0)
41 | , m_averageDuration(-1)
42 | , m_samples(0)
43 | {
44 | }
45 |
46 | ~CaptureStats()
47 | {
48 | }
49 |
50 | void Init(const std::string& outputFilename, const std::string& summary)
51 | {
52 | m_outfileFilename = outputFilename;
53 | m_summary = summary;
54 | }
55 |
56 | void Reinit()
57 | {
58 | m_minDuration = MAXLONG;
59 | m_maxDuration = 0;
60 | m_averageDuration = -1;
61 | m_samples = 0;
62 | }
63 |
64 | void Terminate()
65 | {
66 | amf_pts tmp;
67 | std::ofstream file;
68 | file.open(m_outfileFilename);
69 | file << m_summary << std::endl;
70 | tmp = m_averageDuration / 10000; // to ms
71 | file << "\t" << "Average Duration (ms) " << tmp << std::endl;
72 | tmp = m_minDuration / 10000; // to ms
73 | file << "\t" << "Minimum Duration (ms) " << tmp << std::endl;
74 | tmp = m_maxDuration / 10000; // to ms
75 | file << "\t" << "Maximum Duration (ms) " << tmp << std::endl;
76 | file << "\t" << "Samples " << m_samples << std::endl;
77 | file.close();
78 | }
79 |
80 | void addDuration(amf_pts duration)
81 | {
82 | // Filter any bad values
83 | if (duration <= 0)
84 | {
85 | return;
86 | }
87 | //
88 | if (duration < m_minDuration)
89 | {
90 | m_minDuration = duration;
91 | }
92 | if (duration > m_maxDuration)
93 | {
94 | m_maxDuration = duration;
95 | }
96 | //
97 | m_averageDuration = (m_averageDuration < 0) ? duration : (m_averageDuration + duration) / 2;
98 | m_samples++;
99 | }
100 |
101 | private:
102 | std::string m_outfileFilename;
103 | std::string m_summary;
104 |
105 | amf_pts m_minDuration;
106 | amf_pts m_maxDuration;
107 | amf_pts m_averageDuration;
108 | unsigned m_samples;
109 | };
110 | }
111 |
112 | // Define is turned on if the class is included.
113 | #define WANT_CAPTURE_STATS
114 |
--------------------------------------------------------------------------------
/external/amf/public/src/components/DisplayCapture/DDAPISource.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #if !defined(WIN32_LEAN_AND_MEAN)
24 | #define WIN32_LEAN_AND_MEAN
25 | #endif
26 |
27 | #include "../../../include/core/Context.h"
28 | #include "../../../common/InterfaceImpl.h"
29 | #include "../../../common/PropertyStorageImpl.h"
30 | #include "public/include/components/DisplayCapture.h"
31 |
32 | #define USE_DUPLICATEOUTPUT1
33 |
34 | #include
35 | #ifdef USE_DUPLICATEOUTPUT1
36 | // Requires Windows SDK 10.0.10586
37 | #include
38 | #include
39 | #else
40 | #include
41 | #endif
42 | #include
43 |
44 |
45 | namespace amf
46 | {
47 | class AMFDDAPISourceImpl : public
48 | AMFInterfaceImpl< AMFInterface >,
49 | public amf::AMFSurfaceObserver
50 | {
51 | public:
52 | AMFDDAPISourceImpl(AMFContext* pContext);
53 | ~AMFDDAPISourceImpl();
54 |
55 | AMF_RESULT InitDisplayCapture(uint32_t displayMonitorIndex, amf_pts frameDuration, bool bEnableDirtyRects);
56 | AMF_RESULT TerminateDisplayCapture();
57 |
58 | AMF_RESULT AcquireSurface(bool bCopyOutputSurface, amf::AMFSurface **pSurface);
59 |
60 | AMFSize GetResolution();
61 |
62 | AMFRect GetDesktopRect();
63 | AMF_ROTATION_ENUM GetRotation();
64 | void SetMode(AMF_DISPLAYCAPTURE_MODE_ENUM mode);
65 |
66 | // AMFSurfaceObserver interface
67 | virtual void AMF_STD_CALL OnSurfaceDataRelease(AMFSurface* pSurface);
68 |
69 | private:
70 | // Utility methods
71 | AMF_RESULT GetHDRInformation(AMFSurface* pSurface);
72 | AMF_RESULT GetNewDuplicator();
73 |
74 | // When we are done with a texture, we push it onto a free list
75 | // We must track the AMF surfaces in case Terminate() is called
76 | // before the surface is released
77 | amf_list< AMFSurface* > m_freeCopySurfaces;
78 |
79 | AMFContextPtr m_pContext;
80 | AMFComputePtr m_pCompute;
81 |
82 | mutable AMFCriticalSection m_sync;
83 |
84 | ATL::CComPtr m_displayDuplicator;
85 |
86 | ATL::CComQIPtr m_deviceAMF;
87 | ATL::CComPtr m_contextAMF;
88 | ATL::CComPtr < ID3D11Texture2D > m_acquiredTextureAMF;
89 |
90 | volatile bool m_bAcquired;
91 | DXGI_OUTPUT_DESC m_outputDescription;
92 |
93 | amf_pts m_frameDuration; // in 100 of nanosec
94 | amf_pts m_lastPts;
95 |
96 | amf_int64 m_iFrameCount;
97 |
98 | #ifdef USE_DUPLICATEOUTPUT1
99 | ATL::CComPtr m_dxgiOutput5;
100 | #else
101 | ATL::CComPtr m_dxgiOutput1;
102 | #endif
103 | amf_vector m_DirtyRects;
104 | amf_vector m_MoveRects;
105 |
106 | bool m_bEnableDirtyRects;
107 | AMF_DISPLAYCAPTURE_MODE_ENUM m_eCaptureMode;
108 | };
109 | typedef AMFInterfacePtr_T AMFDDAPISourceImplPtr;
110 | } //namespace amf
111 |
--------------------------------------------------------------------------------
/external/amf/public/src/components/DisplayCapture/DisplayCaptureImpl.h:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #pragma once
24 | #include "../../../include/components/Component.h"
25 | #include "../../../include/components/DisplayCapture.h"
26 | #include "../../../common/PropertyStorageExImpl.h"
27 | #include "../../../include/core/Context.h"
28 | #include "../../../common/ByteArray.h"
29 | #include "../../../include/core/CurrentTime.h"
30 | #include "DDAPISource.h"
31 |
32 | namespace amf
33 | {
34 | //-------------------------------------------------------------------------------
35 | typedef AMFPropertyStorageExImpl baseclassCompositorProperty;
36 | //-------------------------------------------------------------------------------
37 | //-------------------------------------------------------------------------------------------------
38 |
39 | class AMFDisplayCaptureImpl :
40 | public AMFInterfaceBase,
41 | public AMFPropertyStorageExImpl
42 | {
43 | public:
44 | // Interface access
45 | AMF_BEGIN_INTERFACE_MAP
46 | AMF_INTERFACE_MULTI_ENTRY(AMFComponent)
47 | AMF_INTERFACE_CHAIN_ENTRY(baseclassCompositorProperty)
48 | AMF_END_INTERFACE_MAP
49 |
50 |
51 | AMFDisplayCaptureImpl(AMFContext* pContext);
52 | virtual ~AMFDisplayCaptureImpl();
53 |
54 | // AMFComponent interface
55 | virtual AMF_RESULT AMF_STD_CALL Init(AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height);
56 | virtual AMF_RESULT AMF_STD_CALL ReInit(amf_int32 width, amf_int32 height);
57 | virtual AMF_RESULT AMF_STD_CALL Terminate();
58 | virtual AMF_RESULT AMF_STD_CALL Drain();
59 | virtual AMF_RESULT AMF_STD_CALL Flush();
60 |
61 | virtual AMF_RESULT AMF_STD_CALL SubmitInput(AMFData* pData);
62 | virtual AMF_RESULT AMF_STD_CALL QueryOutput(AMFData** ppData);
63 | virtual AMFContext* AMF_STD_CALL GetContext() { return m_pContext; }
64 | virtual AMF_RESULT AMF_STD_CALL SetOutputDataAllocatorCB(AMFDataAllocatorCB* /*callback*/) { return AMF_NOT_SUPPORTED; }
65 |
66 | virtual AMF_RESULT AMF_STD_CALL GetCaps(AMFCaps** ppCaps);
67 | virtual AMF_RESULT AMF_STD_CALL Optimize(AMFComponentOptimizationCallback* pCallback);
68 |
69 | virtual void AMF_STD_CALL OnPropertyChanged(const wchar_t* pName);
70 | private:
71 | AMF_RESULT AMF_STD_CALL InitDrawDirtyRects();
72 | AMF_RESULT AMF_STD_CALL TerminateDrawDirtyRects();
73 | AMF_RESULT AMF_STD_CALL DrawDirtyRects(AMFSurfacePtr& surface);
74 |
75 | amf_pts GetCurrentPts() const;
76 | void SetEOF(bool eof) { m_eof = eof; }
77 | bool GetEOF() const { return m_eof; }
78 | mutable AMFCriticalSection m_sync;
79 | AMFContext1Ptr m_pContext;
80 | AMFDDAPISourceImplPtr m_pDesktopDuplication;
81 | AMFCurrentTimePtr m_pCurrentTime;
82 | bool m_eof;
83 | amf_pts m_lastStartPts;
84 | AMFRate m_frameRate;
85 | bool m_bCopyOutputSurface;
86 |
87 | bool m_bDrawDirtyRects;
88 | AMFComputePtr m_pComputeDevice;
89 | AMFComputeKernelPtr m_pDirtyRectsKernel;
90 | AMFBufferPtr m_pDirtyRectsBuffer;
91 | AMF_ROTATION_ENUM m_eRotation;
92 |
93 | // No copy or assign
94 | AMFDisplayCaptureImpl(const AMFDisplayCaptureImpl&);
95 | AMFDisplayCaptureImpl& operator=(const AMFDisplayCaptureImpl&);
96 | };
97 |
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/external/amf/public/src/components/DisplayCapture/DrawRectsBGRA.hlsl:
--------------------------------------------------------------------------------
1 | // MIT license
2 | //
3 | // Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved.
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | Texture2D imageInRGBA : register(t0);
24 | Buffer Rectangles : register(t1);
25 | RWTexture2D imageOutRGBA : register(u0);
26 |
27 | cbuffer Params : register(b0)
28 | {
29 | uint count;
30 | };
31 | //-------------------------------------------------------------------------------------------------
32 | [numthreads(8, 8, 1)]
33 | void main(uint3 coord : SV_DispatchThreadID)
34 | {
35 | uint2 idOut = uint2(coord.x, coord.y);
36 |
37 | uint2 imageSize;
38 | imageOutRGBA.GetDimensions(imageSize.x, imageSize.y);
39 |
40 | if (idOut.x >= imageSize.x || idOut.y >= imageSize.y)
41 | {
42 | return;
43 | }
44 |
45 | float4 color = imageInRGBA[idOut];
46 |
47 | for (uint i = 0; i < count; i++)
48 | {
49 | uint4 rect = Rectangles[i];
50 |
51 | if (idOut.x >= rect.x && idOut.y >= rect.y && idOut.x < rect.z && idOut.y < rect.w)
52 | {
53 | color.x = 1.0f;
54 | break;
55 | }
56 | }
57 | imageOutRGBA[idOut] = color;
58 | }
59 |
--------------------------------------------------------------------------------
/external/ini/LICENCE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2006-2022 Brodie Thiesfield
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files(the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions :
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/source/flm_backend/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #=============================================================================
2 | # Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | # @author AMD Developer Tools Team
4 | # @file CMakeLists.txt
5 | # @brief FLM Backend Lib CMakeLists file.
6 | #=============================================================================
7 |
8 | add_library(flm_backend STATIC)
9 |
10 | include(${PROJECT_SOURCE_DIR}/cmake/common.cmake)
11 |
12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") # AMF warnings
13 |
14 | set(FLM_SOURCE_SDK
15 | flm.h
16 | flm_utils.h
17 | flm_utils.cpp
18 | flm_user_interface.h
19 | flm_user_interface.cpp
20 | flm_timer.h
21 | flm_timer.cpp
22 | flm_keyboard.h
23 | flm_keyboard.cpp
24 | flm_mouse.h
25 | flm_mouse.cpp
26 | flm_capture_context.h
27 | flm_capture_context.cpp
28 | flm_capture_amf.h
29 | flm_capture_amf.cpp
30 | flm_capture_dxgi.h
31 | flm_capture_dxgi.cpp
32 | flm_pipeline.h
33 | flm_pipeline.cpp
34 | )
35 |
36 | set(FLM_SOURCE_INI
37 | ${PROJECT_SOURCE_DIR}/external/ini/simpleIni.h
38 | )
39 |
40 | set(FLM_SOURCE_AMF_COMMON
41 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/AMFFactory.h
42 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/AMFFactory.cpp
43 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/AMFSTL.h
44 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/AMFSTL.cpp
45 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/CurrentTimeImpl.h
46 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/CurrentTimeImpl.cpp
47 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/DataStreamFactory.cpp
48 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/PropertyStorageExImpl.h
49 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/PropertyStorageExImpl.cpp
50 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/Thread.h
51 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/Thread.cpp
52 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/TraceAdapter.h
53 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/TraceAdapter.cpp
54 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/DataStreamFile.h
55 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/DataStreamFile.cpp
56 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/DataStreamMemory.h
57 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/DataStreamMemory.cpp
58 | ${PROJECT_SOURCE_DIR}/external/amf/public/common/Windows/ThreadWindows.cpp
59 | )
60 |
61 | set(FLM_SOURCE_AMF_COMPONENTS
62 | ${PROJECT_SOURCE_DIR}/external/amf/public/src/components/DisplayCapture/DDAPISource.h
63 | ${PROJECT_SOURCE_DIR}/external/amf/public/src/components/DisplayCapture/DDAPISource.cpp
64 | ${PROJECT_SOURCE_DIR}/external/amf/public/src/components/DisplayCapture/DisplayCaptureImpl.h
65 | ${PROJECT_SOURCE_DIR}/external/amf/public/src/components/DisplayCapture/DisplayCaptureImpl.cpp
66 | )
67 |
68 |
69 | set(FLM_CONFIG_INI
70 | ${PROJECT_SOURCE_DIR}/source/flm_backend/flm.ini
71 | )
72 |
73 | source_group("external/amf/common" FILES ${FLM_SOURCE_AMF_COMMON})
74 | source_group("external/amf/components" FILES ${FLM_SOURCE_AMF_COMPONENTS})
75 | source_group("external/ini" FILES ${FLM_SOURCE_INI})
76 | source_group("shaders" FILES ${FLM_SHADERS})
77 | source_group("ini_data" FILES ${FLM_CONFIG_INI})
78 | source_group("source" FILES ${FLM_SOURCE_SDK})
79 |
80 | target_sources( flm_backend PRIVATE
81 | ${FLM_SOURCE_SDK}
82 | ${FLM_SOURCE_AMF_COMMON}
83 | ${FLM_SOURCE_AMF_COMPONENTS}
84 | ${FLM_SOURCE_INI}
85 | ${FLM_CONFIG_INI}
86 | )
87 |
88 | target_include_directories(flm_backend PUBLIC
89 |
90 | # SDK
91 | ${PROJECT_SOURCE_DIR}/source/flm_backend
92 |
93 | # External Clones
94 | ${PROJECT_SOURCE_DIR}/external
95 | ${PROJECT_SOURCE_DIR}/external/ini
96 | ${PROJECT_SOURCE_DIR}/external/amf
97 | )
98 |
99 | # copy json
100 | copyCommand("${FLM_CONFIG_INI}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<$:debug>$<$:release>/")
101 |
102 | set_target_properties(flm_backend PROPERTIES
103 | FOLDER "libs"
104 | OUTPUT_NAME "flm_backend$<$:d>"
105 | )
106 |
107 |
--------------------------------------------------------------------------------
/source/flm_backend/flm.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm.h
5 | /// @brief FLM user pipeline definitions
6 | //=============================================================================
7 |
8 | #ifndef FLM_H
9 | #define FLM_H
10 |
11 | #include
12 | #include
13 | #include "stdint.h"
14 | #include "version.h"
15 |
16 | // #define FLM_DEBUG_CODE
17 |
18 | #define USE_FRAME_LOCK_AMF
19 | #define USE_FRAME_LOCK_DXGI
20 |
21 | #if defined(WIN32) || defined(_WIN64)
22 | #define FLM_API __cdecl
23 | #else
24 | #define FLM_API
25 | #endif
26 |
27 | #define APP_NAME_STRING "Frame latency meter"
28 |
29 | #define PROCESSOR_YIELD_CYCLES 120
30 |
31 | enum class FLM_GPU_VENDOR_TYPE
32 | {
33 | UNKNOWN = 0,
34 | AMD = 1,
35 | NVIDIA = 2,
36 | INTEL = 3
37 | };
38 |
39 | enum class FLM_CAPTURE_CODEC_TYPE
40 | {
41 | AUTO = 0,
42 | AMF = 1,
43 | DXGI = 2,
44 | };
45 |
46 | enum class FLM_PRINT_LEVEL
47 | {
48 | RUN,
49 | ACCUMULATED,
50 | OPERATIONAL,
51 | PRINT_DEBUG,
52 | PRINT_LEVEL_COUNT
53 | };
54 |
55 | //#define MOUSE_EVENT_TYPE_SIZE 2
56 | enum FLM_MOUSE_EVENT_TYPE
57 | {
58 | MOUSE_MOVE = 0,
59 | MOUSE_CLICK = 1,
60 | MOUSE_EVENT_TYPE_SIZE
61 | };
62 |
63 | enum class FLM_PROCESS_MESSAGE_TYPE
64 | {
65 | PRINT,
66 | STATUS,
67 | ERROR_MESSAGE
68 | };
69 |
70 | enum class FLM_PROCESS_STATUS
71 | {
72 | CLOSE = 0,
73 | WAIT_FOR_START,
74 | PROCESSING
75 | };
76 |
77 | enum class FLM_STATUS
78 | {
79 | OK,
80 | FAILED,
81 | INIT_FAILED,
82 | TIMER_INIT_FAILED,
83 | CAPTURE_PROCESS_FRAME,
84 | CAPTURE_TIMEOUT,
85 | CAPTURE_RETRY,
86 | CAPTURE_INIT_FAILED,
87 | CAPTURE_ERROR_EXPECTED,
88 | CAPTURE_ERROR_UNEXPECTED,
89 | CAPTURE_REPEAT,
90 | CREATE_MOUSE_THREAD_FAILED,
91 | CREATE_KEYBOARD_THREAD_FAILED,
92 | CREATE_CAPTURE_THREAD_FAILED,
93 | MEMORY_ALLOCATION_ERROR,
94 | VENDOR_NOT_SUPPORTED,
95 | STATUS_COUNT
96 | };
97 |
98 | struct FLM_PIXEL_DATA
99 | {
100 | uint8_t* data;
101 | int32_t height;
102 | int32_t width;
103 | int32_t pitchH;
104 | int32_t pixelSizeInBytes;
105 | uint32_t format;
106 | int64_t timestamp; // QueryPerformance time stamp for the frame, set internally by capture codecs
107 | };
108 |
109 | class FLM_TELEMETRY_DATA
110 | {
111 | public:
112 | float fps = 0.0f; // Average framerate
113 | float fpsOdd = 0.0f; // Average framerate for odd frames
114 | float fpsEven = 0.0f; // Average framerate for even frames
115 | float accLatency = 0.0f; // latency [ms] accumulated over ALL measurements since the current capture session began
116 | float accFrames = 0.0f; // latency [frames] accumulated over ALL measurements since the last capture session began
117 | float accFps = 0.0f; // framerate accumulated over ALL measurements since the last capture session began
118 | float rowLatency = 0.0f; // latency [ms] averaged over the current row
119 | float rowFrames = 0.0f; // latency [frames] averaged over the current row.
120 | std::vector lMeasurementMS; // the latencies[ms] for individual frames, size set by config MeasurementsPerLine
121 |
122 | void Reset()
123 | {
124 | FLM_TELEMETRY_DATA zeroObject;
125 | *this = zeroObject;
126 | }
127 | };
128 |
129 | struct FLM_RUNTIME_OPTIONS
130 | {
131 | bool appWindowTopMost = false; // true sets to stay on top of all window stacks
132 | FLM_PRINT_LEVEL printLevel = FLM_PRINT_LEVEL::RUN; // Print measurement status 0:Run 1:Average 2:Operational 3:Debug
133 | FLM_MOUSE_EVENT_TYPE mouseEventType = FLM_MOUSE_EVENT_TYPE::MOUSE_MOVE;
134 | bool captureRegionChanged = false; // set to true if user set a new capture region, FLM must reinitialize capture device if true
135 | bool saveUserSettings = false; // Changes in UI that needs to be updated in ini file for next app run
136 | int iCaptureX = 0; // pixel co-ordinates
137 | int iCaptureY = 0; // pixel co-ordinates
138 | int iCaptureWidth = 0; // pixel co-ordinates
139 | int iCaptureHeight = 0; // pixel co-ordinates
140 |
141 | // Calibration offset for mouse click latency measurements
142 | // This offset provides a closer value to the actual system level latency
143 | // and is set to be constant for FLM measurements around 1/2 frame rates
144 | // this is not a linear relationship with monitors refresh rate near lower and upper ranges
145 | // (rates < 60 Hz and > 120 Hz), values may vary according to monitor types and settings
146 | // Users can set these ranges via ini file
147 | float biasOffset = 0.0f;
148 | bool autoBias = false;
149 | int monitorRefreshRate = 60; // Default 60Hz
150 |
151 | // Threshold values used to end the measurement cycle of the mouse to frame latency measurement
152 | float thresholdCoefficient[MOUSE_EVENT_TYPE_SIZE] = {0.0f, 0.0f};
153 |
154 | bool showOptions = false;
155 | bool minimizeApp = false;
156 | bool gameUsesFrameGeneration = false; // enable this to add extra wait time delay when using the mouse move option
157 |
158 | int initAMFUsingDX12 = 0; // Set to 1 for AMF to use DX12 instead of DX11 (default)
159 |
160 | };
161 |
162 | // function for messages provided during processing
163 | typedef void ProgressCallback(FLM_PROCESS_MESSAGE_TYPE messagetype, const char* progress);
164 |
165 | class FLM_Context
166 | {
167 | public:
168 | // Main code
169 | virtual FLM_STATUS Init(FLM_CAPTURE_CODEC_TYPE codec) = 0;
170 | virtual FLM_PROCESS_STATUS Process() = 0;
171 | virtual void Close() = 0;
172 |
173 | // Status
174 | virtual void SetUserProcessCallback(ProgressCallback Info) = 0;
175 | virtual std::string GetErrorStr() = 0;
176 | virtual FLM_GPU_VENDOR_TYPE GetGPUVendorType() = 0;
177 | virtual FLM_CAPTURE_CODEC_TYPE GetCodec() = 0;
178 |
179 | // User assigned app keys
180 | virtual std::string GetToggleKeyNames() = 0;
181 | virtual std::string GetAppExitKeyNames() = 0;
182 |
183 | // Full frame capture surface sizes
184 | virtual int GetBackBufferWidth() = 0;
185 | virtual int GetBackBufferHeight() = 0;
186 |
187 | FLM_RUNTIME_OPTIONS m_runtimeOptions;
188 | };
189 |
190 | // Class Factory Interface
191 | extern "C" FLM_Context* CreateFLMContext();
192 |
193 | #define CAPTURE_FRAMES_ON_SEPARATE_THREAD 1
194 |
195 | #endif
196 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_capture_amf.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_capture_amf.h
5 | /// @brief FLM AMF capture interface header
6 | //=============================================================================
7 |
8 | #ifndef FLM_CAPTURE_AMF_H
9 | #define FLM_CAPTURE_AMF_H
10 |
11 | #include
12 | #include
13 |
14 | #pragma warning(push)
15 | #pragma warning(disable : 4996)
16 |
17 | #include "public/common/AMFFactory.h"
18 | #include "public/include/components/DisplayCapture.h"
19 | #include "public/include/components/VideoConverter.h"
20 |
21 | #pragma warning(pop)
22 |
23 | #include "flm.h"
24 | #include "flm_utils.h"
25 | #include "flm_capture_context.h"
26 |
27 | extern ProgressCallback* g_pUserCallBack;
28 |
29 | class FLM_Capture_AMF : public FLM_Capture_Context
30 | {
31 | public:
32 | FLM_Capture_AMF(FLM_RUNTIME_OPTIONS *runtimeOptions);
33 | ~FLM_Capture_AMF();
34 |
35 | int CalculateSAD();
36 | unsigned int GetImageFormat();
37 | bool GetConverterOutput(int64_t* pTimeStamp, int64_t* pFrameIdx);
38 | FLM_STATUS GetFrame();
39 | FLM_STATUS GetFrameBuffer(FLM_PIXEL_DATA& pixelData);
40 | FLM_STATUS InitCaptureDevice(unsigned int OutputAdapter, FLM_Timer_AMF* timer);
41 | bool InitContext(FLM_GPU_VENDOR_TYPE vendor);
42 | void Release();
43 | FLM_STATUS ReleaseFrameBuffer(FLM_PIXEL_DATA& pixelData);
44 | void SaveCaptureSurface(uint32_t file_counter);
45 |
46 | private:
47 | void AMF_SaveImage(const char* filename, amf::AMFPlane* plane);
48 | int GetConvertersCount();
49 | AMF_RESULT InitConverters();
50 | AMF_RESULT InitSurfaces();
51 | void ReleaseDisplay();
52 | void ReleaseSurfaces();
53 | void ReleaseConverters();
54 | AMF_RESULT UpdateFormat();
55 |
56 | amf::AMFSurfacePtr m_pHostSurface0; // This is the CPU-accessible surface 0
57 | amf::AMFSurfacePtr m_pHostSurface1; // This is the CPU-accessible surface 1
58 | amf::AMFSurfacePtr m_pTargetHostSurface; //current captured surface either m_pHostSurface0 or m_pHostSurface1
59 | amf::AMFContextPtr m_pContext;
60 | amf::AMFComponentPtr m_pDisplayCapture;
61 |
62 | const static int MAX_CONVERTERS = 16; // Up to 16 converters
63 | int m_iNumConverters = MAX_CONVERTERS;
64 | bool m_bLatestSurfaceIs1 = false;
65 | bool m_bHostSurfaceInit = false;
66 |
67 | amf::AMFComponentPtr m_ppConverters[MAX_CONVERTERS];
68 | amf::AMFDataPtr m_ppConverterOutputs[MAX_CONVERTERS];
69 |
70 | FLM_GPU_VENDOR_TYPE m_vendor = FLM_GPU_VENDOR_TYPE::UNKNOWN;
71 |
72 | protected:
73 | FLM_Capture_AMF(); // hide the default constructor
74 | };
75 |
76 | #endif
--------------------------------------------------------------------------------
/source/flm_backend/flm_capture_context.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_capture_context.h
5 | /// @brief user pipeline definitions
6 | //=============================================================================
7 |
8 | #ifndef FLM_CAPTURE_CONTEXT_H
9 | #define FLM_CAPTURE_CONTEXT_H
10 |
11 | #include "flm.h"
12 | #include "flm_utils.h"
13 | #include "flm_timer.h"
14 |
15 | #include "ini/SimpleIni.h"
16 |
17 | extern ProgressCallback* g_pUserCallBack;
18 |
19 | struct FLM_CAPTURE_SETTINGS
20 | {
21 | float fStartX = 0.25f;
22 | float fStartY = 0.0f;
23 | float fCaptureWidth = 0.75f; // size = 3/4 of bufferWidth
24 | float fCaptureHeight = 0.125f; // size = 1/8 of bufferHeight
25 | std::string captureFileName = "captured_frame"; // file name for saved frames to image, exclude file extension
26 | int iAVGFilterFrames = 100; // Can be set by user via ini
27 | int iFilmGrainThreshold = 4; // film grain
28 | };
29 |
30 | class FLM_Capture_Context
31 | {
32 | public:
33 | virtual int CalculateSAD() = 0;
34 | virtual bool GetConverterOutput(int64_t* pTimeStamp, int64_t* pFrameIdx) = 0;
35 | virtual FLM_STATUS GetFrame() = 0;
36 | virtual unsigned int GetImageFormat() = 0;
37 | virtual FLM_STATUS InitCaptureDevice(unsigned int OutputAdapter, FLM_Timer_AMF* timer) = 0;
38 | virtual bool InitContext(FLM_GPU_VENDOR_TYPE vendor) = 0;
39 | virtual void Release() = 0;
40 | virtual FLM_STATUS ReleaseFrameBuffer(FLM_PIXEL_DATA& pixelData) = 0;
41 | virtual void SaveCaptureSurface(uint32_t file_counter) = 0;
42 |
43 | FLM_RUNTIME_OPTIONS* m_pRuntimeOptions = nullptr;
44 | FLM_CAPTURE_SETTINGS m_setting;
45 |
46 | bool m_bFrameLocked = false; // GetFrame() sets this to true, will not capture a new frame until flag is reset by CopyImage
47 | int8_t m_iCurrentFrame = 0;
48 | int8_t m_iCurrentFrameHold = -1;
49 | int32_t m_iOutputAdapter = 0; // 0: default primary monitor, else 1..n where n is total number of monitors
50 | bool m_bNeedToRebuildPipeline = false; // Processing
51 |
52 | // Normalized co-ordinates for display resolution width(0..1) and height = (0..1)
53 | // or pixel position and size when values range < 0.0 or > 1.0
54 | int m_iDownScale = 2;
55 |
56 | uint32_t m_iBackBufferFormat = 0; // This varies according to capture codecs been used AMF, DXGI, ...
57 | uint32_t m_iBackBufferWidth = 0; // Display width
58 | uint32_t m_iBackBufferHeight = 0; // Display height
59 | int m_iCaptureOriginX = 0;
60 | int m_iCaptureOriginY = 0;
61 | int32_t m_iCaptureWidth = 0; // capture width in pixel coordinates (can be smaller then full frame buffer size)
62 | int32_t m_iCaptureHeight = 0; // capture height in pixel coordinates (can be smaller then full frame buffer size)
63 | int m_iUserSetOutputAdapter = 0;
64 | std::string m_displayName = "";
65 | HANDLE m_hEventFrameReady = 0;
66 | HDC m_screenHDC = 0;
67 | float m_fBackgroundSAD = 0.0f;
68 | bool m_bDoCaptureFrames = true;
69 |
70 | float m_fCumulativeFrameTimesMS = 0.0f;
71 | int m_iCumulativeFrameTimeSamples = 0;
72 | float m_fMovingAverageFrameTimeMS = 0.0f; // not strictly a moving average - it is implemented via IIR rather than FIR filter
73 | float m_fMovingAverageOddFramesTimeMS = 0.0f; // not strictly a moving average - it is implemented via IIR rather than FIR filter
74 | float m_fMovingAverageEvenFramesTimeMS = 0.0f; // not strictly a moving average - it is implemented via IIR rather than FIR filter
75 | bool m_bTerminateCaptureThread = false;
76 | bool m_bExitCaptureThread = false;
77 |
78 | //samples are needed to get within 1% of the final value
79 | float m_fAVGFilterAlpha = 0.0f; // Result of CalculateFilterAlpha() for m_iAVGFilterFrames
80 | float m_fClickFilterAlpha = 0.0f; // Result of CalculateFilterAlpha()
81 |
82 | bool AcquireFrameAndDownscaleToHost(int64_t* pTimeStamp, int64_t* pFrameIdx);
83 | void ClearCaptureRegion();
84 | void RedrawMainScreen();
85 | void DisplayThreadFunction();
86 | int GetThresholdedSAD(int64_t frameIdx, int iSAD, float fThresholdMultiplierCoeff);
87 | bool InitCapture(FLM_Timer_AMF& m_timer);
88 | void InitSettings();
89 | void ResetState();
90 | void TextDC(int x, int y, const char* Format, ...);
91 | void SaveAsBitmap(const char* filename, FLM_PIXEL_DATA pixelData, bool vertFlip);
92 | void ShowCaptureRegion(COLORREF color);
93 | void UpdateAverageFrameTime(int64_t iiTimeStamp, int64_t iiFrameIdx);
94 |
95 | private:
96 | FLM_STATUS LoadUserSettings();
97 | FLM_STATUS SaveUserSettings();
98 | static float CalculateFilterAlpha(int iNumIterations);
99 | };
100 |
101 | #endif
102 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_capture_dxgi.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_capture_dxgi.h
5 | /// @brief FLM DXGI desktop capture interface header
6 | //=============================================================================
7 |
8 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
9 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
10 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
11 | // PARTICULAR PURPOSE.
12 | //
13 | // Copyright (c) Microsoft Corporation. All rights reserved
14 | // File: DuplicationManager.h
15 |
16 | #ifndef FLM_DXGI_H
17 | #define FLM_DXGI_H
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include "flm.h"
28 | #include "flm_utils.h"
29 | #include "flm_capture_context.h"
30 |
31 | #define ACQUIRE_FRAME_CAPTURE_TIMEOUT 1000
32 |
33 | extern HRESULT SystemTransitionsExpectedErrors[];
34 | extern HRESULT CreateDuplicationExpectedErrors[];
35 | extern HRESULT FrameInfoExpectedErrors[];
36 | extern HRESULT AcquireFrameExpectedError[];
37 | extern HRESULT EnumOutputsExpectedErrors[];
38 |
39 | //
40 | // Handles the task of duplicating an output.
41 | //
42 | class FLM_Capture_DXGI : public FLM_Capture_Context
43 | {
44 | public:
45 | FLM_Capture_DXGI(FLM_RUNTIME_OPTIONS *runtimeOptions);
46 | ~FLM_Capture_DXGI();
47 |
48 | FLM_STATUS GetFrame();
49 | FLM_STATUS ReleaseFrameBuffer(FLM_PIXEL_DATA& pixelData);
50 | FLM_STATUS InitCaptureDevice(unsigned int MonitorToCapture, FLM_Timer_AMF* timer);
51 | unsigned int GetImageFormat();
52 | int CalculateSAD();
53 | bool GetConverterOutput(int64_t* pTimeSmp, int64_t* pFrameIdx);
54 | void Release();
55 | void SaveCaptureSurface(uint32_t file_counter);
56 | bool InitContext(FLM_GPU_VENDOR_TYPE vendor);
57 |
58 | private:
59 | DXGI_OUTDUPL_FRAME_INFO m_frameInfo; // Current captured frame info obtained from GetFrame()
60 | FLM_PIXEL_DATA m_pixelData[2] = {};
61 | int m_iGetFrameInstance = 0; // Tracks AcquireNextFrame increments on success
62 | int64_t m_iiFreqCountPerSecond = 0;
63 | int32_t m_iImagePitch = 0;
64 | IDXGIResource* m_pDesktopResource = nullptr;
65 | ID3D11Device* m_pD3D11Device = nullptr; // DirectX adapter object created to interface with GPU
66 | ID3D11DeviceContext* m_pD3D11DeviceContext = nullptr; // Object interface to the adapter
67 | ID3D11Texture2D* m_pDestGPUCopy[2] = {nullptr, nullptr}; // Copy of acquired desktop resource on GPU used to copy data to CPU memory
68 | IDXGIOutputDuplication* m_pDXGIOutputDuplication = nullptr; // DXGI Desktop duplication API
69 | ID3D11Texture2D* m_pAcquiredDesktopImage[2] = {nullptr, nullptr}; // Buffer acquired GPU desktop frames
70 | DXGI_OUTPUT_DESC m_outputDescriptor; // Information about the display frame been captured
71 |
72 | bool CopyImage(FLM_PIXEL_DATA& pixelData);
73 | FLM_STATUS CreateD3D11Device();
74 | void DoneWithAcquiredFrame(bool nextFrame);
75 | FLM_STATUS ProcessFailure(ID3D11Device* Device, std::string str, HRESULT hr, HRESULT* ExpectedErrors = nullptr);
76 |
77 | protected:
78 | FLM_Capture_DXGI(); // hide the default constructor
79 | };
80 |
81 | #endif
--------------------------------------------------------------------------------
/source/flm_backend/flm_keyboard.cpp:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_keyboard.cpp
5 | /// @brief FLM code interface to keyboard
6 | //=============================================================================
7 |
8 | #include "flm_keyboard.h"
9 | #include "flm_utils.h"
10 |
11 | VK_KEY_PAIRS vk_key_pairs[VK_KEY_PAIRS_SIZE] = {{VK_MENU, "ALT"}, {VK_CONTROL, "CTRL"}, {VK_SHIFT, "SHIFT"}, {VK_LMENU, "LALT"},
12 | {VK_RMENU, "RALT"}, {VK_LCONTROL, "LCTRL"}, {VK_RCONTROL, "RCTRL"}, {VK_LSHIFT, "LSHIFT"},
13 | {VK_RSHIFT, "RSHIFT"}, {VK_RETURN, "ENTER"}, {VK_LEFT, "LEFT"}, {VK_UP, "UP"},
14 | {VK_RIGHT, "RIGHT"}, {VK_DOWN, "DOWN"}, {VK_ADD, "ADD"}, {VK_SUBTRACT, "SUBTRACT"},
15 | {VK_F1, "F1"}, {VK_F2, "F2"}, {VK_F3, "F3"}, {VK_F4, "F4"},
16 | {VK_F5, "F5"}, {VK_F6, "F6"}, {VK_F7, "F7"}, {VK_F8, "F8"},
17 | {VK_F9, "F9"}, {VK_F10, "F10"}, {VK_F11, "F11"}, {VK_F12, "F12"}};
18 |
19 | std::string FLM_Keyboard::GetErrorMessage()
20 | {
21 | return m_errorMessage;
22 | }
23 |
24 | void FLM_Keyboard::PrintMessage(const char* Format, ...)
25 | {
26 | // define a pointer to save argument list
27 | va_list args;
28 | char buff[1024];
29 |
30 | // process the arguments into our debug buffer
31 | va_start(args, Format);
32 | #ifdef _WIN32
33 | vsprintf_s(buff, Format, args);
34 | #else
35 | vsprint(buff, 1024, Format, args);
36 | #endif
37 | va_end(args);
38 |
39 | m_errorMessage = buff;
40 | }
41 |
42 | std::string FLM_Keyboard::GetVKCodeKeyName(uint8_t vkCode)
43 | {
44 | #define STRING_SIZE 256
45 | char lpString[STRING_SIZE];
46 | UINT sc = MapVirtualKeyW((UINT)vkCode, 0);
47 |
48 | LPARAM lParam;
49 | // if using extended keys add 0x1 << 24
50 | lParam = (LPARAM)sc << 16;
51 | lParam |= (LPARAM)0x1 << 25;
52 | if (GetKeyNameTextA((LONG)lParam, lpString, STRING_SIZE) != 0)
53 | {
54 | return (lpString);
55 | }
56 |
57 | return ("");
58 | }
59 |
60 | std::string FLM_Keyboard::GetKeyName(uint8_t vkCode)
61 | {
62 | for (int i = 0; i < VK_KEY_PAIRS_SIZE; i++)
63 | {
64 | if (vk_key_pairs[i].key == vkCode)
65 | {
66 | return (vk_key_pairs[i].keyname);
67 | }
68 | }
69 | // Other keys not listed, mostly single char unless user assigned unsupported flame keys
70 | return (GetVKCodeKeyName(vkCode));
71 | }
72 |
73 | bool FLM_Keyboard::AssignKey(std::string token, uint8_t& key)
74 | {
75 | if (token.size() == 1)
76 | {
77 | key = token[0];
78 | return true;
79 | }
80 |
81 | for (int i = 0; i < VK_KEY_PAIRS_SIZE; i++)
82 | {
83 | if (token.compare(vk_key_pairs[i].keyname) == 0)
84 | {
85 | key = vk_key_pairs[i].key;
86 | return true;
87 | }
88 | }
89 | return false;
90 | }
91 |
92 | bool FLM_Keyboard::SetKeys(std::string userKey, uint8_t key[3])
93 | {
94 | std::string inputKey = userKey;
95 | key[0] = key[1] = key[2] = 0;
96 |
97 | // convert to upper
98 | std::transform(inputKey.begin(), inputKey.end(), inputKey.begin(), ::toupper);
99 |
100 | std::string delimiter = "+";
101 | int pos = (int)inputKey.find(delimiter);
102 |
103 | // Single key
104 | if (pos <= 0)
105 | {
106 | if (AssignKey(inputKey, key[0]) == false)
107 | {
108 | PrintMessage("Unknown key assignment [%s] in [%s]\n", inputKey.c_str(), userKey.c_str());
109 | return false;
110 | }
111 | return true;
112 | }
113 |
114 | // More then 1 key
115 | std::string token[3] = {"", "", ""};
116 | token[0] = inputKey.substr(0, pos);
117 | std::string temp = inputKey.substr(pos + delimiter.size(), inputKey.size());
118 | pos = (int)temp.find(delimiter);
119 | // check for any 3rd key
120 | if (pos >= 0)
121 | {
122 | token[1] = temp.substr(0, pos);
123 | token[2] = temp.substr(pos + delimiter.size(), temp.size());
124 | }
125 | else
126 | {
127 | token[1] = temp;
128 | }
129 |
130 | for (int i = 0; i < 3; i++)
131 | {
132 | if (token[i].size() > 0)
133 | {
134 | if (AssignKey(token[i], key[i]) == false)
135 | {
136 | PrintMessage("Unknown key assignment [%s] in [%s]\n", token[i].c_str(), userKey.c_str());
137 | return false;
138 | }
139 | }
140 | else
141 | {
142 | if (i < 1)
143 | {
144 | PrintMessage("Error minimum of 2 key sequence is required in [%s]\n", userKey.c_str());
145 | return false;
146 | }
147 | }
148 | }
149 |
150 | return true;
151 | }
152 |
153 | bool FLM_Keyboard::KeyCombinationPressed(uint8_t keys[3])
154 | {
155 | // Will remain true as long as the user holds the keys down
156 | if (KEY_DOWN(keys[0]))
157 | {
158 | if (keys[2] > 0)
159 | return (KEY_DOWN(keys[0]) && KEY_DOWN(keys[1]) && KEY_DOWN(keys[2]));
160 | else if (keys[1] > 0)
161 | return (KEY_DOWN(keys[0]) && KEY_DOWN(keys[1]));
162 | return true;
163 | }
164 |
165 | return false;
166 | }
167 |
168 | void FLM_Keyboard::ClearKeyboardBuffer()
169 | {
170 | while (_kbhit())
171 | {
172 | int ch = _getch();
173 | }
174 | }
175 |
176 |
177 | bool FLM_Keyboard::AnyKeyboardHit()
178 | {
179 | return _kbhit() > 0;
180 | }
181 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_keyboard.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_keyboard.h
5 | /// @brief FLM interface to set and get keyboard keys
6 | //=============================================================================
7 |
8 | #ifndef FLM_KEYBOARD_H
9 | #define FLM_KEYBOARD_H
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | struct VK_KEY_PAIRS
17 | {
18 | uint8_t key;
19 | const char* keyname;
20 | };
21 |
22 | #define VK_KEY_PAIRS_SIZE 28
23 |
24 | class FLM_Keyboard
25 | {
26 | public:
27 | bool AnyKeyboardHit();
28 | bool AssignKey(std::string token, uint8_t& key);
29 | void ClearKeyboardBuffer();
30 | std::string GetErrorMessage();
31 | std::string GetKeyName(uint8_t vkCode);
32 | bool KeyCombinationPressed(uint8_t keys[3]);
33 | bool SetKeys(std::string userKey, uint8_t key[3]);
34 |
35 | private:
36 | std::string m_errorMessage;
37 |
38 | std::string GetVKCodeKeyName(uint8_t vkCode);
39 | void PrintMessage(const char* Format, ...);
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_mouse.cpp:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_mouse.cpp
5 | /// @brief FLM code interface to mouse
6 | //=============================================================================
7 |
8 | #include "flm_mouse.h"
9 | #include "flm_utils.h"
10 |
11 |
12 | std::string FLM_Mouse::GetErrorMessage()
13 | {
14 | return m_errorMessage;
15 | }
16 |
17 | void FLM_Mouse::PrintMessage(const char* Format, ...)
18 | {
19 | // define a pointer to save argument list
20 | va_list args;
21 | char buff[1024];
22 |
23 | // process the arguments into our debug buffer
24 | va_start(args, Format);
25 | #ifdef _WIN32
26 | vsprintf_s(buff, Format, args);
27 | #else
28 | vsprint(buff, 1024, Format, args);
29 | #endif
30 | va_end(args);
31 |
32 | m_errorMessage = buff;
33 | }
34 |
35 |
36 | bool FLM_Mouse::IsButtonDown(uint8_t key)
37 | {
38 | if (KEY_DOWN(key))
39 | return true;
40 | return false;
41 | }
42 |
43 | bool FLM_Mouse::IsButtonPressed(uint8_t key)
44 | {
45 | if (IsButtonDown(key))
46 | {
47 | while (IsButtonDown(key));
48 | return true;
49 | }
50 | return false;
51 | }
52 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_mouse.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_mouse.h
5 | /// @brief FLM interface to get mouse button states
6 | //=============================================================================
7 |
8 | #ifndef FLAME_MOUSE_H
9 | #define FLAME_MOUSE_H
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #define MOUSE_LEFT_BUTTON VK_LBUTTON
17 | #define MOUSE_MIDDLE_BUTTON VK_MBUTTON
18 | #define MOUSE_RIGHT_BUTTON VK_RBUTTON
19 |
20 |
21 | class FLM_Mouse
22 | {
23 | public:
24 | bool IsButtonDown(uint8_t key);
25 | bool IsButtonPressed(uint8_t key);
26 | std::string GetErrorMessage();
27 |
28 | private:
29 | std::string m_errorMessage;
30 | void PrintMessage(const char* Format, ...);
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_pipeline.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_pipeline.h
5 | /// @brief FLM pipeline interface header
6 | //=============================================================================
7 |
8 | #ifndef FLM_PIPELINE_H
9 | #define FLM_PIPELINE_H
10 |
11 | #include "flm.h"
12 | #include "flm_utils.h"
13 | #include "flm_timer.h"
14 | #include "flm_keyboard.h"
15 | #include "flm_mouse.h"
16 |
17 | #include "flm_capture_AMF.h"
18 | #include "flm_capture_DXGI.h"
19 |
20 | #include
21 | #include "ini/SimpleIni.h"
22 |
23 | struct FLM_PIPELINE_SETTINGS
24 | {
25 | bool showBoundingBox = true; // Show a frame capture region using dimensions set in "CAPTURE" section, set 0 to disable, 1 to enable
26 | bool showAdvancedMeasurements = false; // mode to show stats like odd,even and AVG, RUN latency measurements
27 | float extraWaitMilliseconds = 10.0f; // Number of milliseconds to wait after motion has been detected, before starting the next measurement
28 | int extraWaitFrames = 1; //
29 | float extraWaitMillisecondsFG = 20.0f; // The extra wait frames are needed to prevent locking onto the double frequency and also to prevent problems with motion blur
30 | int extraWaitFramesFG = 3; //
31 | std::string measurementKeys = "ALT+T"; // Use both keys combined to start and stop measurements
32 | std::string appExitKeys = "ALT+Q"; // Use both keys combined to exit application
33 | std::string captureSurfaceKeys = "RSHIFT+ENTER"; // capture the current frame to file, the file name is set in "CAPTURE" option using "CaptureFile"
34 | std::string validateCaptureKeys = "LSHIFT+ENTER"; // Capture a sequence of frames numbered set in ValidateCaptureNumOfFrames to BMP files
35 | bool saveToFile = true; // Sets saving measurements to a specified CSV file
36 | std::string outputFileName = "fml_latency.csv"; // File to save measurements
37 | unsigned int iNumMeasurementsPerLine = 16; // Number of measurements taken before averaging. Default 16 Range:1 to 32
38 | int iNumDequantizationPhases = 2; // This introduces a very small periodic phase shift to work around the quantization
39 | int validateCaptureNumOfFrames = 32; // Number of frames to capture
40 | int iMouseHorizontalStep = 50; // Mouse horizontal step size , can be adjusted if game requires a wider value
41 | float monitorCalibration_240Hz = 0.0;
42 | float monitorCalibration_144Hz = 0.0;
43 | float monitorCalibration_120Hz = 0.0;
44 | float monitorCalibration_60Hz = 0.0;
45 | float monitorCalibration_50Hz = 0.0;
46 | float monitorCalibration_24Hz = 0.0;
47 | };
48 |
49 | class FLM_Pipeline : public FLM_Context
50 | {
51 | public:
52 | FLM_STATUS Init(FLM_CAPTURE_CODEC_TYPE codec);
53 | FLM_PROCESS_STATUS Process();
54 | void Close();
55 |
56 | void SetUserProcessCallback(ProgressCallback Info);
57 | std::string GetErrorStr();
58 | FLM_GPU_VENDOR_TYPE GetGPUVendorType();
59 | FLM_CAPTURE_CODEC_TYPE GetCodec() { return m_codec; }
60 | void ResetState();
61 | std::string GetToggleKeyNames();
62 | std::string GetAppExitKeyNames();
63 | int GetBackBufferWidth();
64 | int GetBackBufferHeight();
65 | void ProcessKeyboardCommands();
66 | void SendMouseMove();
67 | bool WaitForFrameDetection();
68 | FLM_STATUS loadUserSettings();
69 | FLM_STATUS saveUserSettings();
70 |
71 | FLM_PIPELINE_SETTINGS m_setting;
72 |
73 | HWND m_hWnd = GetConsoleWindow();
74 |
75 | private:
76 | FLM_STATUS InitSettings();
77 | FLM_STATUS SetCodec(std::string codec);
78 | void UpdateAverageLatency(float fLatencyMS);
79 | void StartMeasurements();
80 | void StopMeasurements();
81 | float CalculateAutoRefreshScanOffset();
82 | bool isRunningOnPrimaryDisplay();
83 |
84 | FLM_TELEMETRY_DATA m_telemetry;
85 | FLM_Keyboard m_keyboard;
86 | FLM_Timer_AMF m_timer;
87 | FLM_Performance_Timer m_timer_performance;
88 | FLM_Mouse m_mouse;
89 | FLM_Capture_Context* m_capture = NULL;
90 | FLM_CAPTURE_CODEC_TYPE m_codec = FLM_CAPTURE_CODEC_TYPE::AUTO;
91 | bool m_bValidateCaptureLoop = false; // when set will run a validation capture loop that save current captured latency frame used in SAD
92 | bool m_bVirtualTerminalEnabled = false; // This is set to true if windows virtual terminal escape char is supported
93 |
94 | // Thread termination
95 | bool m_bTerminateMouseThread = false;
96 | bool m_bTerminateKeyboardThread = false;
97 | bool m_bExitMouseThread = false;
98 | bool m_bExitKeyboardThread = false;
99 | bool m_bExitApp = false;
100 |
101 | static DWORD WINAPI MouseEventThreadFunctionStub(LPVOID lpParameter);
102 | static DWORD WINAPI KeyboardListenThreadFunctionStub(LPVOID lpParameter);
103 | static DWORD WINAPI CaptureDisplayThreadFunctionStub(LPVOID lpParameter);
104 |
105 | void MouseEventThreadFunction();
106 | void KeyboardListenThreadFunction();
107 |
108 | // configurable outputs
109 | void CreateCSV();
110 | void CloseCSV();
111 | void SaveTelemetryCSV();
112 | void PrintStream(const char* format, ...);
113 | void PrintAverageTelemetry(float fFrameLatencyMS);
114 | void PrintOperationalTelemetry(float fFrameLatencyMS, bool bFull);
115 | void PrintDebugTelemetry(float fFrameLatencyMS);
116 |
117 | int m_iUserSetVendorType = 0;
118 | float m_fCumulativeLatencyTimesMS = 0.0f;
119 | int m_iCumulativeLatencySamples = 0;
120 | float m_fAccumulatedLatencyMS = 0.0f;
121 | float m_fAccumulatedFrameTimeMS = 0.0f;
122 | bool m_bMeasuringInProgress = false; // State of latency measurements
123 | HANDLE m_eventMovementDetected = NULL;
124 | bool m_bMouseClickDetected = false;
125 | int64_t m_iiMouseMoveEventTime = 0;
126 | int m_iMeasurementPhaseCounter = 0;
127 | int m_iDequantizingPhaseCounter = 0;
128 | int64_t m_iiMotionDetectedFrameFlipTime = 0;
129 | int m_iSkipMeasurementsOnInitCount = 0;
130 |
131 | // set by user as defined in FLM_PIPELINE_SETTINGS and override from json
132 | int m_iSetVendor = 0; // 0 using GetGPUVendorType else set vendor to FLM_GPU_VENDOR_TYPE (1 = AMD 2 = Nvidia 3 = Intel)
133 | unsigned char m_measurementKeys[3] = {0, 0, 0};
134 | unsigned char m_appExitKeys[3] = {0, 0, 0};
135 | unsigned char m_captureSurfaceKeys[3] = {0, 0, 0};
136 | unsigned char m_validateCaptureKeys[3] = {0, 0, 0};
137 | FILE* m_outputFile = NULL;
138 |
139 | // testCapture Options
140 | int m_validateCounter = 0;
141 |
142 | // Variables used in the MainLoop():
143 |
144 | int64_t m_iiFrameTimeStampPrev = 0;
145 | int64_t m_iiFrameTimeStamp = 0;
146 | int64_t m_iiFrameIdx = 0;
147 | int64_t m_iiFrameIdxPrev = 0;
148 |
149 | float m_fLatestMeasuredLatencyMS = 0.0f;
150 | int m_iSAD = 0;
151 | int m_iThSAD = 0;
152 | int m_iThSADPrev = 0;
153 | float m_autoRefreshScanOffset = 0.0f;
154 |
155 | // Threads
156 |
157 | HANDLE m_hMouseThread = NULL;
158 | HANDLE m_hKbdThread = NULL;
159 | HANDLE m_hCaptureThread = NULL;
160 | };
161 |
162 | #endif
163 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_timer.cpp:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_timer.cpp
5 | /// @brief FLM High precision timer
6 | //=============================================================================
7 |
8 | #include "flm_timer.h"
9 | #pragma comment(lib, "Winmm.lib")
10 |
11 | bool FLM_Timer_AMF::Init()
12 | {
13 | QueryPerformanceFrequency((LARGE_INTEGER*)&m_iiFreqCountPerSecond);
14 | m_iiCountPerOneMS = m_iiFreqCountPerSecond / 1000;
15 |
16 | #ifdef USE_AMF_TIMER
17 | m_pAMF_CurrentTimer = new amf::AMFCurrentTimeImpl();
18 | if (m_pAMF_CurrentTimer == NULL)
19 | return false;
20 | #endif
21 |
22 | return true;
23 | }
24 |
25 | #ifdef USE_AMF_TIMER
26 | int64_t FLM_Timer_AMF::UpdateAmfTimeToPerformanceCounterOffset()
27 | {
28 | if (m_pAMF_CurrentTimer == NULL)
29 | return 0;
30 |
31 | int64_t iiTime1;
32 | QueryPerformanceCounter((LARGE_INTEGER*)&iiTime1);
33 | int64_t iiAmfNow = m_pAMF_CurrentTimer->Get(); // This command takes about 500 nSec
34 | int64_t iiTime2;
35 | QueryPerformanceCounter((LARGE_INTEGER*)&iiTime2);
36 |
37 | int64_t iiNow = (iiTime1 + iiTime2 + 1) / 2; // Average time to compare to iiAmfNow
38 |
39 | // Note: for the current amf version, m_iiFreqCountPerSecond == AMF_SECOND...
40 | int64_t iiAmfNowInTicks = (iiAmfNow * m_iiFreqCountPerSecond + AMF_SECOND / 2) / AMF_SECOND; //with rounding...
41 |
42 | m_iiAmfTimeToPerformanceCounterTimeOffset = iiNow - iiAmfNowInTicks;
43 |
44 | // We need this because of the Sleep(1) used in PrecisionSleepUntilTimestamp().
45 | // amf_increase_timer_precision();
46 |
47 | return m_iiAmfTimeToPerformanceCounterTimeOffset;
48 | }
49 |
50 | int64_t FLM_Timer_AMF::TranslateAmfTimeToPerformanceCounter(int64_t iiAmfTime)
51 | {
52 | int64_t iiAmfTimeInTicks = (iiAmfTime * m_iiFreqCountPerSecond + AMF_SECOND / 2) / AMF_SECOND; //with rounding...
53 | int64_t iiTime = iiAmfTimeInTicks + m_iiAmfTimeToPerformanceCounterTimeOffset;
54 | return iiTime;
55 | }
56 | #endif
57 |
58 | void FLM_Timer_AMF::PrecisionSleepUntilTimestamp(int64_t iiSleepEnd)
59 | {
60 | int64_t iiNow;
61 | QueryPerformanceCounter((LARGE_INTEGER*)&iiNow);
62 |
63 | while (iiNow < iiSleepEnd)
64 | {
65 | if ((iiSleepEnd - iiNow) > 17 * m_iiCountPerOneMS) // More than 17 ms remaining? Sleep(1) (default resolution is about 16 ms)
66 | {
67 | Sleep(1);
68 | }
69 | else if ((iiSleepEnd - iiNow) >
70 | 4 * m_iiCountPerOneMS) // (3 should be enough) More than 4 ms remaining? Sleep(1) with higher precision context switching
71 | {
72 | timeBeginPeriod(1);
73 | Sleep(1);
74 | timeEndPeriod(1);
75 | }
76 | else if ((iiSleepEnd - iiNow) > m_iiCountPerOneMS / 5) // More than 0.2ms (2000 ticks) remaining? Sleep(0)
77 | {
78 | Sleep(0);
79 | }
80 | else
81 | {
82 | //for (int i = 0; i < PROCESSOR_YIELD_CYCLES; i++)
83 | // YieldProcessor();
84 | #define y YieldProcessor()
85 | y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;
86 | y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;
87 | y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;y;
88 | #undef y
89 | }
90 | if (iiNow < iiSleepEnd)
91 | QueryPerformanceCounter((LARGE_INTEGER*)&iiNow);
92 | }
93 | }
94 | //#pragma optimize("", on)
95 |
96 | void FLM_Timer_AMF::PrecisionSleepMS(float fTimeToSleepMS, int64_t iiSleepStart)
97 | {
98 | // FlamePrint("PrecisionSleepMS %4.4f ms\n",fTimeToSleepMS);
99 |
100 | int64_t iiNow;
101 | QueryPerformanceCounter((LARGE_INTEGER*)&iiNow);
102 |
103 | if (iiSleepStart == 0)
104 | iiSleepStart = iiNow;
105 |
106 | int64_t iiSleepEnd = iiSleepStart + int64_t(fTimeToSleepMS * m_iiCountPerOneMS);
107 |
108 | // Sanity check
109 | if (iiSleepEnd >= iiNow)
110 | PrecisionSleepUntilTimestamp(iiSleepEnd);
111 | //else
112 | // printf("#"); // debug
113 | }
114 |
115 | void FLM_Timer_AMF::Close()
116 | {
117 | }
118 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_timer.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_timer.h
5 | /// @brief FLM High precision timer interface
6 | //=============================================================================
7 |
8 | #ifndef FLM_TIMER_H
9 | #define FLM_TIMER_H
10 |
11 | #define USE_AMF_TIMER
12 |
13 | #include "flm.h"
14 |
15 | #ifdef USE_AMF_TIMER
16 | #pragma warning(push)
17 | #pragma warning(disable : 4996)
18 | #include "public/common/CurrentTimeImpl.h"
19 | #pragma warning(pop)
20 |
21 | using namespace amf;
22 | #else
23 | #include
24 | #endif
25 |
26 | static int depth = 0;
27 | static int debug_stack_level = 2;
28 |
29 | class FLM_Profile_Timer
30 | {
31 | public:
32 | FLM_Profile_Timer(std::string caller)
33 | {
34 | m_caller = caller;
35 | depth++;
36 | QueryPerformanceFrequency(&m_freqCountPerSecond);
37 | QueryPerformanceCounter(&m_start);
38 | }
39 |
40 | ~FLM_Profile_Timer()
41 | {
42 | LARGE_INTEGER now;
43 | QueryPerformanceCounter(&now);
44 | LARGE_INTEGER diff_us;
45 | diff_us.QuadPart = now.QuadPart - m_start.QuadPart;
46 | diff_us.QuadPart *= 1000000;
47 | diff_us.QuadPart /= m_freqCountPerSecond.QuadPart;
48 | depth--;
49 | printf("%2d %*s %-s %6.6f ms\n",depth, depth*4," ", m_caller.c_str(), diff_us.QuadPart / 1000.0);
50 |
51 | }
52 |
53 | private:
54 | std::string m_caller;
55 | LARGE_INTEGER m_freqCountPerSecond = {1, 1};
56 | LARGE_INTEGER m_start = {0, 0};
57 | };
58 |
59 |
60 | class FLM_Performance_Timer
61 | {
62 | public:
63 | FLM_Performance_Timer()
64 | {
65 | QueryPerformanceFrequency(&m_freqCountPerSecond);
66 | Start();
67 | }
68 |
69 | LONGLONG now()
70 | {
71 | LARGE_INTEGER now;
72 | QueryPerformanceCounter(&now);
73 | return now.QuadPart;
74 | }
75 |
76 | void Start()
77 | {
78 | QueryPerformanceCounter(&m_start);
79 | }
80 |
81 | double Stop_ms()
82 | {
83 | LARGE_INTEGER diff_us;
84 | LARGE_INTEGER now;
85 | QueryPerformanceCounter(&now);
86 | diff_us.QuadPart = now.QuadPart - m_start.QuadPart;
87 | diff_us.QuadPart *= 1000000;
88 | diff_us.QuadPart /= m_freqCountPerSecond.QuadPart;
89 | return diff_us.QuadPart / 1000.0;
90 | }
91 |
92 | LARGE_INTEGER GetFrequency()
93 | {
94 | return m_freqCountPerSecond;
95 | }
96 |
97 | private:
98 | LARGE_INTEGER m_freqCountPerSecond = {1, 1};
99 | LARGE_INTEGER m_start = {0, 0};
100 | };
101 |
102 | class FLM_Timer_AMF
103 | {
104 | public:
105 | bool Init();
106 | void Close();
107 |
108 | #ifdef USE_AMF_TIMER
109 | amf::AMFCurrentTimePtr GetCurrentTimer()
110 | {
111 | if (m_pAMF_CurrentTimer.GetPtr() != nullptr)
112 | return m_pAMF_CurrentTimer;
113 | else
114 | return nullptr;
115 | }
116 |
117 | amf_pts now()
118 | {
119 | if (m_pAMF_CurrentTimer.GetPtr() != nullptr)
120 | return m_pAMF_CurrentTimer->Get();
121 | else
122 | return 0;
123 | }
124 |
125 | int64_t UpdateAmfTimeToPerformanceCounterOffset();
126 | int64_t TranslateAmfTimeToPerformanceCounter(int64_t iiAmfTime);
127 | #endif
128 |
129 | void PrecisionSleepMS(float fTimeToSleepMS, int64_t iiSleepStart);
130 |
131 | private:
132 | void PrecisionSleepUntilTimestamp(int64_t iiSleepEnd);
133 |
134 | #ifdef USE_AMF_TIMER
135 | amf::AMFCurrentTimePtr m_pAMF_CurrentTimer;
136 | #endif
137 |
138 | int64_t m_iiFreqCountPerSecond = 0;
139 | int64_t m_iiCountPerOneMS = 0;
140 | int64_t m_iiAmfTimeToPerformanceCounterTimeOffset = 0;
141 | };
142 |
143 | #endif
144 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_user_interface.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_user_interface.h
5 | /// @brief FLM UI Options used by console application
6 | //=============================================================================
7 | #ifndef FLM_USER_INTERFACE_H
8 | #define FLM_USER_INTERFACE_H
9 |
10 | #include
11 | #include "windowsx.h"
12 | #include "stdio.h"
13 | #include
14 | #include
15 | #include
16 |
17 | #include "flm.h"
18 | #include "flm_utils.h"
19 |
20 | #define HIDE_MINIMIZE_APP_TOGGLE
21 |
22 | #define IDC_BUTTON_CLOSE 1600
23 | #define IDC_BUTTON_SAVE 1601
24 |
25 | #define IDC_GRPBUTTONS 1700
26 | #define IDC_RADIO_DISPLAY_RUN 1701
27 | #define IDC_RADIO_DISPLAY_AVERAGE 1702
28 | #define IDC_RADIO_DISPLAY_OPERATIONAL 1703
29 | #define IDC_CAPTURE_REGION 1706
30 |
31 | #define IDC_RADIO_MOUSE_MOVE 1801
32 | #define IDC_RADIO_MOUSE_CLICK 1802
33 | #define IDC_EDIT_BIAS 1803
34 | #define IDC_CHECK_AUTO_BIAS 1804
35 | #define IDC_EDIT_THRESHOLD 1805
36 | #define IDC_CHECK_MINIMIZE_APP 1806
37 | #define IDC_CHECK_FRAME_GEN 1807
38 |
39 | #define FLM_OPTIONS_WINDOW_HEIGHT 325
40 | #define FLM_OPTIONS_WINDOW_WIDTH 450
41 | #define MAX_EDIT_TXT 20
42 |
43 | struct FLM_UI_SETTINGS
44 | {
45 | HWND hWndConsole = NULL;
46 | HWND hWndUser = NULL;
47 | FLM_RUNTIME_OPTIONS* runtimeOptions = NULL;
48 | HWND hWndLatencyDisplay[3] = {};
49 | HWND hWndMouseClick[2] = {};
50 | HWND hWndButton = NULL;
51 | HBRUSH hbrBkgnd = NULL;
52 | HBRUSH hbrBkgndCaptureRegion = NULL;
53 | HWND hWndRegion = NULL;
54 | HWND hWndEditBias = NULL;
55 | HWND hWndEditThreshold = NULL;
56 | bool processWindowRegion = false;
57 | bool ui_showing = false;
58 | bool capture_region_showing = false;
59 | HWND hWndAutoBias = NULL;
60 | HWND hWndMinimizeApp = NULL;
61 | HWND hWndGameHasFG = NULL;
62 | INT maxWidth = 4096;
63 | INT maxHeight = 4096;
64 | char editTextBias[MAX_EDIT_TXT];
65 | char editTextThreshold[MAX_EDIT_TXT];
66 | };
67 |
68 | class FLM_USER_INTERFACE
69 | {
70 | public:
71 | int ThreadMain();
72 | void Init(FLM_RUNTIME_OPTIONS* displayOption, HANDLE hUserInterfaceThread);
73 | void ShowUI(int x, int y);
74 | void HideUI();
75 | void CloseUI();
76 |
77 | private:
78 | void UpdateRunTimeOptions();
79 | HANDLE m_hUserInterfaceThread;
80 | };
81 |
82 | extern FLM_UI_SETTINGS g_ui;
83 | extern FLM_USER_INTERFACE g_user_interface;
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_utils.cpp:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_utils.h
5 | /// @brief FLM Common API
6 | //=============================================================================
7 |
8 | #include "flm_utils.h"
9 |
10 | static std::vector g_flm_error_message; // shared across multiple classes and accessible in FLM_Pipeline class
11 | static HANDLE g_hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
12 |
13 | // Last In Fist Out (LIFO) instance of an errors, remove the errors from list until empty
14 | std::string FlmGetErrorStr()
15 | {
16 | std::string flm_err;
17 | if (g_flm_error_message.size() > 0)
18 | {
19 | flm_err = g_flm_error_message[g_flm_error_message.size() - 1];
20 | g_flm_error_message.pop_back();
21 | }
22 | else
23 | flm_err = "";
24 | return flm_err.c_str();
25 | }
26 |
27 | void FlmClearErrorStr()
28 | {
29 | g_flm_error_message.clear();
30 | }
31 |
32 | HANDLE FlmGetConsoleHandle()
33 | {
34 | return g_hConsoleOutput;
35 | }
36 |
37 | std::string FlmFormatStr(const char* Format, ...)
38 | {
39 | // define a pointer to save argument list
40 | va_list args;
41 | char buff[1024];
42 |
43 | // process the arguments into our debug buffer
44 | va_start(args, Format);
45 | #ifdef _WIN32
46 | vsprintf_s(buff, Format, args);
47 | #else
48 | vsprint(buff, 1024, Format, args);
49 | #endif
50 | va_end(args);
51 |
52 | return (buff);
53 | }
54 |
55 | void FlmPrint(const char* Format, ...)
56 | {
57 | // define a pointer to save argument list
58 | va_list args;
59 | char buff[1024];
60 |
61 | // process the arguments into our debug buffer
62 | va_start(args, Format);
63 | #ifdef _WIN32
64 | vsprintf_s(buff, Format, args);
65 | #else
66 | vsprint(buff, 1024, Format, args);
67 | #endif
68 | va_end(args);
69 |
70 | // select stream output
71 | printf(buff);
72 | }
73 |
74 | void FlmPrintError(const char* Format, ...)
75 | {
76 | // define a pointer to save argument list
77 | va_list args;
78 | char buff[1024];
79 |
80 | // process the arguments into our debug buffer
81 | va_start(args, Format);
82 | #ifdef _WIN32
83 | vsprintf_s(buff, Format, args);
84 | #else
85 | vsprint(buff, 1024, Format, args);
86 | #endif
87 | va_end(args);
88 |
89 | g_flm_error_message.push_back(buff);
90 |
91 | // Use FLMPrint for this, if its a none exit print message
92 | // printf("FLM Error: ");
93 | // printf(buff);
94 | // printf("\n");
95 | }
96 |
97 | void FlmPrintStaticPos(const char* Format, ...)
98 | {
99 | // define a pointer to save argument list
100 | va_list args;
101 | char buff[1024];
102 |
103 | // process the arguments into our debug buffer
104 | va_start(args, Format);
105 | #ifdef _WIN32
106 | vsprintf_s(buff, Format, args);
107 | #else
108 | vsprint(buff, 1024, Format, args);
109 | #endif
110 | va_end(args);
111 |
112 | CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
113 | CONSOLE_CURSOR_INFO cursorInfo;
114 | GetConsoleCursorInfo(g_hConsoleOutput, &cursorInfo);
115 | cursorInfo.bVisible = false;
116 | SetConsoleCursorInfo(g_hConsoleOutput, &cursorInfo);
117 |
118 | if (GetConsoleScreenBufferInfo(g_hConsoleOutput, &ConsoleScreenBufferInfo))
119 | {
120 | COORD coord;
121 | coord.X = ConsoleScreenBufferInfo.dwCursorPosition.X;
122 | coord.Y = ConsoleScreenBufferInfo.dwCursorPosition.Y;
123 |
124 | printf(buff);
125 | SetConsoleCursorPosition(g_hConsoleOutput, coord);
126 | }
127 | else
128 | printf(buff);
129 |
130 | cursorInfo.bVisible = true;
131 | SetConsoleCursorInfo(g_hConsoleOutput, &cursorInfo);
132 | }
133 |
134 | void FlmPrintClearEndOfLine()
135 | {
136 | CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
137 |
138 | if (GetConsoleScreenBufferInfo(g_hConsoleOutput, &ConsoleScreenBufferInfo))
139 | {
140 | COORD coord = {};
141 | coord.X = ConsoleScreenBufferInfo.dwCursorPosition.X;
142 | coord.Y = ConsoleScreenBufferInfo.dwCursorPosition.Y;
143 | int len;
144 | if ((ConsoleScreenBufferInfo.dwMaximumWindowSize.X - ConsoleScreenBufferInfo.dwCursorPosition.X) > 0)
145 | len = ConsoleScreenBufferInfo.dwMaximumWindowSize.X - ConsoleScreenBufferInfo.dwCursorPosition.X;
146 | else
147 | len = 1;
148 | std::string sformat = "%";
149 | std::string spaces = std::to_string(len);
150 | sformat.append(spaces);
151 | sformat.append("s");
152 | printf(sformat.c_str(), " ");
153 | SetConsoleCursorPosition(g_hConsoleOutput, coord);
154 | }
155 | }
156 |
157 | bool FlmIsFloatNumber(const std::string& string)
158 | {
159 | if (string.length() < 1)
160 | return false;
161 |
162 | if (string.length() == 1)
163 | {
164 | if (string[0] == '.')
165 | return false;
166 | }
167 |
168 | bool decimalPoint = false;
169 | std::string::const_iterator it = string.begin();
170 | if (string.length() > 0)
171 | {
172 | if ((string[0] == '+') || (string[0] == '-'))
173 | it++;
174 | }
175 |
176 | while(it != string.end()){
177 | if(*it == '.')
178 | {
179 | if(!decimalPoint) decimalPoint = true;
180 | else break;
181 | }
182 | else
183 | if(!std::isdigit(*it))
184 | break;
185 | ++it;
186 | }
187 |
188 | return (it == string.end());
189 | }
190 |
--------------------------------------------------------------------------------
/source/flm_backend/flm_utils.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file flm_utils.h
5 | /// @brief FLM Common API
6 | //=============================================================================
7 | #ifndef FLM_UTILS_H
8 | #define FLM_UTILS_H
9 |
10 | #include "Windows.h"
11 | #include "string"
12 | #include "vector"
13 |
14 | #define KEY_DOWN(key) ((GetAsyncKeyState(key) & 0x8000) != 0)
15 | #define IF_CONDITION_BECOMES_TRUE(condition) { bool kd = (condition); static bool pr_kd = kd; if (kd && !pr_kd) bDo = true; else bDo = false; pr_kd = kd; } if( bDo )
16 |
17 | extern std::string FlmFormatStr(const char* Format, ...);
18 | extern void FlmPrint(const char* Format, ...);
19 | extern void FlmPrintError(const char* Format, ...);
20 | extern void FlmPrintStaticPos(const char* Format, ...);
21 | extern void FlmPrintClearEndOfLine();
22 | extern std::string FlmGetErrorStr();
23 | extern HANDLE FlmGetConsoleHandle();
24 | extern void FlmClearErrorStr();
25 | extern bool FlmIsFloatNumber(const std::string& string);
26 | #endif
27 |
--------------------------------------------------------------------------------
/source/flm_backend/version.h:
--------------------------------------------------------------------------------
1 | //=====================================================================
2 | // Copyright 2016-2024 (c), Advanced Micro Devices, Inc. All rights reserved.
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files(the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions :
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 | //
22 | //=====================================================================
23 |
24 | // Version.h : version numbers
25 | //
26 | // SDK Jenkins
27 | // VERSION_MAJOR_MAJOR MAJOR
28 | // VERSION_MAJOR_MINOR MINOR
29 | // VERSION_MINOR_MAJOR BUILD
30 | // VERSION_MINOR_MINOR UPDATE
31 | //
32 |
33 | #if !defined(_VERSION_H_INCLUDED_)
34 | #define _VERSION_H_INCLUDED_
35 |
36 | #define VERSION_MAJOR_MAJOR 1
37 | #define VERSION_MAJOR_MINOR 0
38 | #define VERSION_MINOR_MAJOR 0
39 | #define VERSION_MINOR_MINOR 0
40 | #define VERSION VERSION_MAJOR_MAJOR, VERSION_MAJOR_MINOR, VERSION_MINOR_MAJOR, VERSION_MINOR_MINOR
41 | #define VERSION_TEXT "1.0.0"
42 | #define VERSION_TEXT_SHORT "1.0"
43 |
44 | #endif // _VERSION_H_INCLUDED_
45 |
--------------------------------------------------------------------------------
/source/flm_cli/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #=============================================================================
2 | # Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | # @author AMD Developer Tools Team
4 | # @file CMakeLists.txt
5 | # @brief FLM CLI CMakeLists file.
6 | #=============================================================================
7 |
8 | cmake_minimum_required(VERSION 3.10)
9 | cmake_policy(SET CMP0091 NEW)
10 |
11 |
12 | set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
13 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") # sets multi-threaded dynamically-linked runtime library
14 |
15 | link_directories(
16 | ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
17 | )
18 |
19 | set(FLM_SOURCE_MAIN
20 | main.h
21 | main.cpp
22 | flm_help.h
23 | ${PROJECT_SOURCE_DIR}/source/flm_backend/version.h
24 | )
25 |
26 | file(GLOB_RECURSE RESOURCES
27 | resources/*
28 | )
29 |
30 | # setup target binary
31 | add_executable(flm
32 | ${FLM_SOURCE_MAIN}
33 | ${RESOURCES}
34 | )
35 |
36 | source_group("source" FILES ${FLM_SOURCE_MAIN})
37 | source_group("resource" FILES ${RESOURCES})
38 |
39 | target_include_directories(flm PUBLIC
40 | ./
41 | ${PROJECT_SOURCE_DIR}/source/flm_backend
42 | ${PROJECT_SOURCE_DIR}/external/amf/amf
43 | )
44 |
45 | # add link time dependencies
46 | target_link_libraries(flm PRIVATE
47 | flm_backend$<$:d>
48 | )
49 |
50 | add_dependencies(flm
51 | flm_backend
52 | )
53 |
54 | set_target_properties(flm PROPERTIES
55 | FOLDER "application"
56 | VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<$:debug>$<$:release>" # host applications working folder
57 | )
--------------------------------------------------------------------------------
/source/flm_cli/flm_help.h:
--------------------------------------------------------------------------------
1 |
2 | std::vector flm_help = {
3 | {"=== How to run a test ==="},
4 | {""},
5 | {"Step 1: Configure your primary monitor to run the game on."},
6 | {" Set the monitor to use free sync or have it set to an appropriate refresh rate."},
7 | {"Step 2: Run flm.exe"},
8 | {" when you press the right Alt key, you should see a yellow capture region box."},
9 | {"Step 3: Run the game"},
10 | {" Adjust the game scene placement so that the FLM capture region is situated in an area"},
11 | {" where the scene transitions from dark to bright when the mouse is moved horizontally."},
12 | {" Note: The bounding box will only show if the game is running in window mode."},
13 | {"Step 4: Select start measurements key sequence (default is ALT+T)"},
14 | {" Wait for the capture process to start, it may take a few seconds to start as FLM process data"},
15 | {" you should see the mouse move left and right in rapid concession while the application records"},
16 | {" latency measurements.Some games may require you to press down on the mouse keys to move the mouse"},
17 | {" left and right."},
18 | {" Console output will show the running latency and frame latency when FLM detects a change"},
19 | {""},
20 | {" RUN: .|.. FPS xx.xx, Latency xxx.x ms, x.xx frames"},
21 | {""},
22 | {" A running series of dots and a vertical bar will indicate at what rate these"},
23 | {" latency measurements are occurring."},
24 | {"Step 5: Select stop measurements and review the console outputs values."},
25 | {""},
26 | {" Starting measuring"},
27 | {" RUN: .... FPS xx.xx, Latency xxx.x ms, x.xx frames"},
28 | {" Stopped measuring "},
29 | {""},
30 | {"=== How to change the capture codec for a test ==="},
31 | {""},
32 | {" Running flm.exe with no command line option, will auto detect the systems vendor and GPU,"},
33 | {" then it will select the best capture codec to use."},
34 | {" if you want to override this feature, simply specify the capture codec to use in the command line."},
35 | {""},
36 | {" Capture codec options:"},
37 | {""},
38 | {" -AMF : Capture frames using AMF codec (Default option, works only for AMD GPU's)"},
39 | {" -DXGI : Capture frames using DXGI codec (Works on any GPU connected to main display)"},
40 | {""},
41 | {" Runtime options:"},
42 | {""},
43 | {" -FG : Use this flag when measurements are for games with frame generation enabled."},
44 | {""},
45 | {" Example usage:"},
46 | {""},
47 | {" flm.exe -DXGI"},
48 | {""},
49 | {" Will use the desktop capture codec, which will run on any GPU supported by DX11"},
50 | {""},
51 | {" For more details on this amd more see the users guide."},
52 | };
53 |
--------------------------------------------------------------------------------
/source/flm_cli/main.h:
--------------------------------------------------------------------------------
1 | //=============================================================================
2 | // Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 | /// @author AMD Developer Tools Team
4 | /// @file main.h
5 | /// @brief cli main header
6 | //=============================================================================
7 |
8 | #ifndef MAIN_H
9 | #define MAIN_H
10 |
11 | #include "flm.h"
12 | #include "flm_help.h"
13 | #include "flm_user_interface.h"
14 |
15 |
16 | typedef struct FLM_CLI_OPTIONS_TYPE
17 | {
18 | bool showHelp = false;
19 | bool enableFG = false;
20 | FLM_GPU_VENDOR_TYPE vendor = FLM_GPU_VENDOR_TYPE::UNKNOWN;
21 | FLM_CAPTURE_CODEC_TYPE captureUsing = (FLM_CAPTURE_CODEC_TYPE)(-1);
22 | } FLM_CLI_OPTIONS;
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/source/flm_cli/resources/appicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/source/flm_cli/resources/appicon.ico
--------------------------------------------------------------------------------
/source/flm_cli/resources/mainapp.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/source/flm_cli/resources/mainapp.rc
--------------------------------------------------------------------------------
/source/flm_cli/resources/resource.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GPUOpen-Tools/frame_latency_meter/9e266459af2a0a63633634b209c81bc23897570b/source/flm_cli/resources/resource.h
--------------------------------------------------------------------------------