Add support for rocJpegDecodeBatched API - part 1 of 2 (#31)
* Add initial support for batch decoding * Add support for reading and parsing the images in batches and allocating the output buffers * Add initial support for the rocJpegDecodeBatched API * use recursive_mutex to allow DecodeBatched and Decode functions called concurrently * code cleanup * Add a CTEST for jpegdecodebatched * modify the help message * code clean up
This commit is contained in:
@@ -208,6 +208,33 @@ RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle
|
||||
return rocjpeg_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes a batch of JPEG images using the rocJPEG library.
|
||||
*
|
||||
* Decodes a batch of JPEG images using the specified handle, stream handles, decode parameters, and destination images.
|
||||
*
|
||||
* @param handle The handle to the RocJpeg decoder.
|
||||
* @param jpeg_stream_handles An array of stream handles for the JPEG images to be decoded.
|
||||
* @param decode_params The decode parameters for the decoding process.
|
||||
* @param destinations An array of RocJpegImage structures to store the decoded images.
|
||||
* @return The status of the decoding process. Returns ROCJPEG_STATUS_SUCCESS if successful, or an error code otherwise.
|
||||
*/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecodeBatched(RocJpegHandle handle, RocJpegStreamHandle *jpeg_stream_handles, int batch_size, const RocJpegDecodeParams *decode_params, RocJpegImage *destinations) {
|
||||
if (handle == nullptr || jpeg_stream_handles == nullptr|| decode_params == nullptr || destinations == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
auto rocjpeg_handle = static_cast<RocJpegDecoderHandle*>(handle);
|
||||
try {
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->DecodeBatched(jpeg_stream_handles, batch_size, decode_params, destinations);
|
||||
} catch (const std::exception& e) {
|
||||
rocjpeg_handle->CaptureError(e.what());
|
||||
ERR(e.what());
|
||||
return ROCJPEG_STATUS_RUNTIME_ERROR;
|
||||
}
|
||||
|
||||
return rocjpeg_status;
|
||||
}
|
||||
/**
|
||||
* @brief Returns the error name corresponding to the given RocJpegStatus.
|
||||
*
|
||||
|
||||
+18
-2
@@ -102,7 +102,7 @@ RocJpegStatus RocJpegDecoder::InitializeDecoder() {
|
||||
* @return The status of the JPEG decoding operation.
|
||||
*/
|
||||
RocJpegStatus RocJpegDecoder::Decode(RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params, RocJpegImage *destination) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
if (jpeg_stream_handle == nullptr || decode_params == nullptr || destination == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
@@ -161,6 +161,22 @@ RocJpegStatus RocJpegDecoder::Decode(RocJpegStreamHandle jpeg_stream_handle, con
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a batch of JPEG streams using the specified decode parameters and stores the decoded images in the provided destinations.
|
||||
*
|
||||
* @param jpeg_streams An array of RocJpegStreamHandle objects representing the JPEG streams to be decoded.
|
||||
* @param batch_size The number of JPEG streams in the batch.
|
||||
* @param decode_params A pointer to RocJpegDecodeParams object containing the decode parameters.
|
||||
* @param destinations An array of RocJpegImage objects where the decoded images will be stored.
|
||||
* @return A RocJpegStatus value indicating the success or failure of the decoding operation.
|
||||
*/
|
||||
RocJpegStatus RocJpegDecoder::DecodeBatched(RocJpegStreamHandle *jpeg_streams, int batch_size, const RocJpegDecodeParams *decode_params, RocJpegImage *destinations) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
for(int i = 0; i < batch_size; i++) {
|
||||
CHECK_ROCJPEG(Decode(jpeg_streams[i], decode_params, &destinations[i]));
|
||||
}
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
/**
|
||||
* @brief Retrieves the image information from the JPEG stream.
|
||||
*
|
||||
@@ -176,7 +192,7 @@ RocJpegStatus RocJpegDecoder::Decode(RocJpegStreamHandle jpeg_stream_handle, con
|
||||
* or ROCJPEG_STATUS_INVALID_PARAMETER if any of the input parameters are invalid.
|
||||
*/
|
||||
RocJpegStatus RocJpegDecoder::GetImageInfo(RocJpegStreamHandle jpeg_stream_handle, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights){
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (jpeg_stream_handle == nullptr || num_components == nullptr || subsampling == nullptr || widths == nullptr || heights == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
+16
-1
@@ -84,6 +84,21 @@ public:
|
||||
*/
|
||||
RocJpegStatus Decode(RocJpegStreamHandle jpeg_stream, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
|
||||
/**
|
||||
* Decodes a batch of JPEG streams.
|
||||
*
|
||||
* This function decodes a batch of JPEG streams specified by `jpeg_streams` into a batch of destination images specified by `destinations`.
|
||||
* The number of JPEG streams in the batch is specified by `batch_size`.
|
||||
* The decoding parameters are specified by `decode_params`.
|
||||
*
|
||||
* @param jpeg_streams The array of JPEG stream handles.
|
||||
* @param batch_size The number of JPEG streams in the batch.
|
||||
* @param decode_params The decoding parameters.
|
||||
* @param destinations The array of destination images.
|
||||
* @return The status of the decoding operation.
|
||||
*/
|
||||
RocJpegStatus DecodeBatched(RocJpegStreamHandle *jpeg_streams, int batch_size, const RocJpegDecodeParams *decode_params, RocJpegImage *destinations);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Initializes the HIP framework.
|
||||
@@ -156,7 +171,7 @@ private:
|
||||
int device_id_; // ID of the device to be used
|
||||
hipDeviceProp_t hip_dev_prop_; // HIP device properties
|
||||
hipStream_t hip_stream_; // HIP stream
|
||||
std::mutex mutex_; // Mutex for thread safety
|
||||
std::recursive_mutex mutex_; // Mutex for thread safety
|
||||
RocJpegBackend backend_; // RocJpeg backend
|
||||
RocJpegVappiDecoder jpeg_vaapi_decoder_; // RocJpeg VAAPI decoder object
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user