1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef COMPUTEPIPE_RUNNER_INCLUDE_PREBUILT_INTERFACE_H_ 18 #define COMPUTEPIPE_RUNNER_INCLUDE_PREBUILT_INTERFACE_H_ 19 20 #include <cstddef> 21 #include <cstdint> 22 23 #define COMPUTEPIPE_RUNNER(a) PrebuiltComputepipeRunner_##a 24 25 extern "C" { 26 27 // Enum value to report the error code for function calls. 28 enum PrebuiltComputepipeRunner_ErrorCode { 29 SUCCESS = 0, 30 INTERNAL_ERROR, 31 INVALID_ARGUMENT, 32 ILLEGAL_STATE, 33 NO_MEMORY, 34 FATAL_ERROR, 35 ERROR_CODE_MAX, 36 }; 37 38 enum PrebuiltComputepipeRunner_PixelDataFormat { 39 RGB = 0, 40 RGBA = 1, 41 GRAY = 2, 42 PIXEL_DATA_FORMAT_MAX = 3, 43 }; 44 45 // Gets the version of the library. The runner should check if the version of 46 // the prebuilt matches the version of android runner for which it was built 47 // and fail out if needed. 48 const unsigned char* COMPUTEPIPE_RUNNER(GetVersion)(); 49 50 // Gets the error code. This API is necessary because the graph execution is 51 // asynchronous and even if the function calls to execute the graph succeed, it 52 // could fail at a later point in the execution of the graph. 53 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(GetErrorCode)(); 54 55 // Gets the graph error message from the graph. The return value is not the 56 // graph error code but the error code returned if the call to the function 57 // fails. 58 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(GetErrorMessage)( 59 unsigned char* error_msg_buffer, size_t error_msg_buffer_size, size_t* error_msg_size); 60 61 // Gets the supported graph config options. This is ideally generated once and 62 // cached for subsequent calls. 63 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(GetSupportedGraphConfigs)( 64 const void** config, size_t* config_size); 65 66 // Sets the graph configuration or updates it if an incomplete config is passed. 67 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(UpdateGraphConfig)( 68 const unsigned char* graph_config, size_t graph_config_size); 69 70 // Sets the stream contents. This can only be used after the graph has started 71 // running successfully. The contents of this stream are typically a serialized 72 // proto and would be deserialized and fed into the graph. 73 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(SetInputStreamData)( 74 int stream_index, int64_t timestamp, const unsigned char* stream_data, size_t stream_data_size); 75 76 // Sets the pixel data as stream contents. This can be set only after the graph 77 // has started running successfully. Pixel data should be copied within this 78 // function as there are no guarantess on the lifetime of the pixel data beyond 79 // the return of this function call. 80 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(SetInputStreamPixelData)( 81 int stream_index, int64_t timestamp, const uint8_t* pixels, int width, int height, int step, 82 int format); 83 84 // Sets a callback function for when a packet is generated. Note that a c-style 85 // function needs to be passed as no object context is being passed around here. 86 // The runner would be responsible for using the buffer provided in the callback 87 // immediately or copying it as there are no guarantees on its lifetime beyond 88 // the return of the callback. 89 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(SetOutputStreamCallback)( 90 void (*streamCallback)(void* cookie, int stream_index, int64_t timestamp, 91 const unsigned char* data, size_t data_size)); 92 93 // Sets a callback function for when new pixel data is generated. C-style 94 // function pointers need to passed as no object context is being passed around. 95 // The runner would be responsible for immediately copying out the data. The 96 // prebuilt is expected to pass contiguous data. 97 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(SetOutputPixelStreamCallback)( 98 void (*streamCallback)(void* cookie, int stream_index, int64_t timestamp, const uint8_t* pixels, 99 int width, int height, int step, int format)); 100 101 // Sets a callback function for when the graph terminates. 102 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(SetGraphTerminationCallback)( 103 void (*terminationCallback)(void* cookie, const unsigned char* termination_message, 104 size_t termination_message_size)); 105 106 // Starts the graph execution. Debugging can be enabled which will enable 107 // profiling. The profiling info can be obtained by calling getDebugInfo once 108 // the graph execution has stopped. 109 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(StartGraphExecution)(void* cookie, 110 bool debugging_enabled); 111 112 // Stops the graph execution. 113 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(StopGraphExecution)(bool flushOutputFrames); 114 115 // Resets the graph completely. Should be called only after graph execution has been stopped. 116 void COMPUTEPIPE_RUNNER(ResetGraph)(); 117 118 // Get debugging/profiling information. The function outputs the size of 119 // profiling information string and if the buffer size is larger than or equal 120 // to the size, then it copies it over to the buffer. Debugging info will be 121 // empty if the graph is started without debugging support. 122 PrebuiltComputepipeRunner_ErrorCode COMPUTEPIPE_RUNNER(GetDebugInfo)(unsigned char* debug_info, 123 size_t debug_info_buffer_size, 124 size_t* debug_info_size); 125 } 126 #endif // COMPUTEPIPE_RUNNER_INCLUDE_PREBUILT_INTERFACE_H_ 127