Add support for new APIs for parsing jpeg streams independently from decoder APIs (#24)
* Add support for new APIs for parsing jpeg streams independently from decoder APIs
* Update document and code clean-up
* code clean-up
[ROCm/rocjpeg commit: e73ec1412c]
Este commit está contenido en:
@@ -152,10 +152,42 @@ typedef enum {
|
||||
ROCJPEG_BACKEND_HYBRID = 1
|
||||
} RocJpegBackend;
|
||||
|
||||
|
||||
/*****************************************************/
|
||||
//! The "opaque JPEG stream identifier" is a handle that is used to parse and store a JPEG stream.
|
||||
//! This handle is created by calling "rocjpegStreamCreate". By using this handle, we only need to parse a JPEG stream
|
||||
//! once by calling "rocJpegStreamParse" and can retrieve the stream's information in subsequent API calls such as "rocJpegGetImageInfo" and "rocJpegDecode" (see below).
|
||||
/*****************************************************/
|
||||
typedef void* RocJpegStreamHandle;
|
||||
|
||||
/*****************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle);
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Create the rocJPEG stream parser handle. This handle is used to parse and retrieve the information from the JPEG stream.
|
||||
//! IN/OUT jpeg_stream_handle: the rocjpeg stream handle.
|
||||
/*****************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle);
|
||||
|
||||
/*****************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle);
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Parses a jpeg stream and stores the information from the stream to be used in subsequent API calls for retrieving the image information and decoding it.
|
||||
//! IN data: Pointer to the buffer containing the jpeg stream data to be parsed.
|
||||
//! IN length: Length of the jpeg image buffer.
|
||||
//! IN/OUT jpeg_stream_handle: The jpeg stream parser handle that is used to parse and store the information from the input data buffer.
|
||||
/*****************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle);
|
||||
|
||||
/*****************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle);
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Release the stream parser object and resources.
|
||||
//! IN/OUT jpeg_stream_handle: instance handle to release
|
||||
/*****************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle);
|
||||
|
||||
/*****************************************************/
|
||||
// Opaque library handle identifier.
|
||||
//struct RocJpegDecoderHandle;
|
||||
//typedef struct RocJpegDecoderHandle* RocJpegHandle;
|
||||
//! Used in subsequent API calls after rocJpegCreate
|
||||
/*****************************************************/
|
||||
typedef void *RocJpegHandle;
|
||||
@@ -168,7 +200,7 @@ typedef void *RocJpegHandle;
|
||||
//! IN backend : Backend to use.
|
||||
//! IN device_id : the GPU device id for which a decoder should be created. For example, use 0 for the first GPU device,
|
||||
//! and 1 for the second GPU device on the system, etc.
|
||||
//! IN/OUT handle : rocjpeg handle, jpeg decoder instance to use for
|
||||
//! IN/OUT handle : rocjpeg handle, jpeg decoder instance to use for.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, RocJpegHandle *handle);
|
||||
|
||||
@@ -187,15 +219,14 @@ RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle);
|
||||
//! If less than ROCJPEG_MAX_COMPONENT channels are encoded, then zeros would be set to absent channels information
|
||||
//! If the image is 3-channel, all three groups are valid.
|
||||
//! IN handle : rocJpeg handle
|
||||
//! IN data : Pointer to the buffer containing the jpeg stream data to be decoded.
|
||||
//! IN length : Length of the jpeg image buffer.
|
||||
//! IN jpeg_stream_handle: The handle for the jpeg stream parser to retrieve information from a previously parsed jpeg stream.
|
||||
//! OUT num_component : Number of channels in the decoded output image
|
||||
//! OUT subsampling : Chroma subsampling used in this JPEG, see RocJpegChromaSubsampling.
|
||||
//! OUT widths : pointer to ROCJPEG_MAX_COMPONENT of uint32_t, returns width of each channel.
|
||||
//! OUT heights : pointer to ROCJPEG_MAX_COMPONENT of uint32_t, returns height of each channel.
|
||||
//! \return ROCJPEG_STATUS_SUCCESS if successful
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t *data, size_t length, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights);
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights);
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, RocJpegOutputFormat output_format, RocJpegImage *destination, hipStream_t stream);
|
||||
@@ -206,13 +237,12 @@ RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t
|
||||
//! and minimum required memory buffer for each plane is plane_height * plane_pitch where plane_pitch >= plane_width for
|
||||
//! planar output formats and plane_pitch >= plane_width * num_components for interleaved output format.
|
||||
//! IN handle : rocJpeg handle
|
||||
//! IN data : Pointer to the buffer containing the jpeg stream to be decoded.
|
||||
//! IN length : Length of the jpeg image buffer.
|
||||
//! IN jpeg_stream_handle: The handle for the jpeg stream parser to retrieve information from a previously parsed jpeg stream and decode it.
|
||||
//! IN decode_params : Decode parameters. See RocJpegDecodeParams for description
|
||||
//! IN/OUT destination : Pointer to structure with information about output buffers. See RocJpegImage description.
|
||||
//! \return ROCJPEG_STATUS_SUCCESS if successful
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecodeBatchedInitialize(RocJpegHandle handle, int batch_size, int max_cpu_threads, RocJpegOutputFormat output_format);
|
||||
|
||||
@@ -37,7 +37,39 @@ The API takes in the following arguments:
|
||||
* A decoder handle, which is returned by ``rocJpegCreate()`` and must be retained for the entire decode session,
|
||||
as it is passed along with the other decoding APIs.
|
||||
|
||||
3. Retrieve the image info
|
||||
3. Create a JPEG stream parser
|
||||
====================================================
|
||||
|
||||
The ``rocJpegStreamCreate`` function creates a JPEG stream parser object and returns a handle upon successful creation. This handle is used to parse and retrieve the information from the JPEG stream.
|
||||
|
||||
Below is the signature of the ``rocJpegStreamCreate`` function:
|
||||
|
||||
.. code:: cpp
|
||||
|
||||
RocJpegStatus rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle);
|
||||
|
||||
The API takes in the following arguments:
|
||||
|
||||
* A JPEG stream handle, which is returned by ``rocJpegStreamCreate``. This handle can be used by the user to parse the JPEG stream and retrieve the information from the stream.
|
||||
|
||||
4. Parse a JPEG stream and store its information
|
||||
====================================================
|
||||
|
||||
The ``rocJpegStreamParse`` function parses a jpeg stream and stores the information from the stream to be used in subsequent API calls for retrieving the image information and decoding it.
|
||||
|
||||
Below is the signature of the ``rocJpegStreamParse`` function:
|
||||
|
||||
.. code:: cpp
|
||||
|
||||
RocJpegStatus rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle);
|
||||
|
||||
The API takes in the following arguments:
|
||||
|
||||
* A pointer to the JPEG data buffer.
|
||||
* The length of the JPEG data buffer.
|
||||
* The JPEG stream handle, which is returned by ``rocJpegStreamCreate``. This handle is used to parse the JPEG stream and retrieve the information from the stream.
|
||||
|
||||
5. Retrieve the image info
|
||||
====================================================
|
||||
``rocJpegGetImageInfo()`` retrieves the image info, including number of components, width and height of each component, and chroma subsampling.
|
||||
For each image to be decoded, pass the JPEG data pointer and data length to the ``rocJpegGetImageInfo()`` function. This function is thread safe.
|
||||
@@ -48,8 +80,7 @@ Below is the signature of ``rocJpegGetImageInfo()`` function:
|
||||
|
||||
RocJpegStatus rocJpegGetImageInfo(
|
||||
RocJpegHandle handle,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
RocJpegStreamHandle jpeg_stream_handle,
|
||||
uint8_t *num_components,
|
||||
RocJpegChromaSubsampling *subsampling,
|
||||
uint32_t *widths,
|
||||
@@ -75,7 +106,7 @@ list is composed of the chroma subsampling property retrieved from the JPEG imag
|
||||
The VCN hardware-accelerated JPEG decoder in AMD GPUs only supports decoding JPEG images with ``ROCJPEG_CSS_444``, ``ROCJPEG_CSS_422``,
|
||||
``ROCJPEG_CSS_420``, and ``ROCJPEG_CSS_400`` chroma subsampling.
|
||||
|
||||
4. Decode a JPEG stream
|
||||
6. Decode a JPEG stream
|
||||
====================================================
|
||||
``rocJpegDecode()`` decodes single image based on the backend used to create the rocJpeg handle in rocJpegCreate API. For each image to be decoded,
|
||||
pass the JPEG data pointer and data length to the ``rocJpegDecode()`` function. This function is thread safe.
|
||||
@@ -86,8 +117,7 @@ See the signature of this function below:
|
||||
|
||||
RocJpegStatus rocJpegDecode(
|
||||
RocJpegHandle handle,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
RocJpegStreamHandle jpeg_stream_handle,
|
||||
const RocJpegDecodeParams *decode_params,
|
||||
RocJpegImage *destination);
|
||||
|
||||
@@ -146,12 +176,17 @@ the required size for the output buffers for a single decode JPEG. To optimally
|
||||
"ROCJPEG_OUTPUT_Y", "Any of the supported chroma subsampling", "destination.pitch[0] = widths[0]", "destination.channel[0] = destination.pitch[0] * heights[0]"
|
||||
"ROCJPEG_OUTPUT_RGB", "Any of the supported chroma subsampling", "destination.pitch[0] = widths[0] * 3", "destination.channel[0] = destination.pitch[0] * heights[0]"
|
||||
"ROCJPEG_OUTPUT_RGB_PLANAR", "Any of the supported chroma subsampling", "destination.pitch[c] = widths[c] for c = 0, 1, 2", "destination.channel[c] = destination.pitch[c] * heights[c] for c = 0, 1, 2"
|
||||
5. Destroy the decoder
|
||||
7. Destroy the decoder
|
||||
====================================================
|
||||
|
||||
You must call the ``rocJpegDestroy()`` to destroy the session and free up resources.
|
||||
|
||||
6. Get Error name
|
||||
8. Destroy the JPEG stream handle
|
||||
====================================================
|
||||
|
||||
You must call the ``rocJpegStreamDestroy()`` to release the stream parser object and resources.
|
||||
|
||||
9. Get Error name
|
||||
====================================================
|
||||
|
||||
You can call ``rocJpegGetErrorName`` to retrieve the name of the specified error code in text form returned from rocJPEG APIs.
|
||||
@@ -43,6 +43,7 @@ int main(int argc, char **argv) {
|
||||
RocJpegChromaSubsampling subsampling;
|
||||
RocJpegBackend rocjpeg_backend = ROCJPEG_BACKEND_HARDWARE;
|
||||
RocJpegHandle rocjpeg_handle = nullptr;
|
||||
RocJpegStreamHandle rocjpeg_stream_handle = nullptr;
|
||||
RocJpegImage output_image = {};
|
||||
RocJpegDecodeParams decode_params = {};
|
||||
RocJpegUtils rocjpeg_utils;
|
||||
@@ -58,6 +59,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegCreate(rocjpeg_backend, device_id, &rocjpeg_handle));
|
||||
CHECK_ROCJPEG(rocJpegStreamCreate(&rocjpeg_stream_handle));
|
||||
|
||||
std::vector<char> file_data;
|
||||
for (auto file_path : file_paths) {
|
||||
@@ -82,7 +84,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, reinterpret_cast<uint8_t*>(file_data.data()), file_size, &num_components, &subsampling, widths, heights));
|
||||
CHECK_ROCJPEG(rocJpegStreamParse(reinterpret_cast<uint8_t*>(file_data.data()), file_size, rocjpeg_stream_handle));
|
||||
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, rocjpeg_stream_handle, &num_components, &subsampling, widths, heights));
|
||||
|
||||
rocjpeg_utils.GetChromaSubsamplingStr(subsampling, chroma_sub_sampling);
|
||||
std::cout << "Input file name: " << base_file_name << std::endl;
|
||||
@@ -115,7 +118,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
std::cout << "Decoding started, please wait! ... " << std::endl;
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t*>(file_data.data()), file_size, &decode_params, &output_image));
|
||||
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, rocjpeg_stream_handle, &decode_params, &output_image));
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
double time_per_image_in_milli_sec = std::chrono::duration<double, std::milli>(end_time - start_time).count();
|
||||
double image_size_in_mpixels = (static_cast<double>(widths[0]) * static_cast<double>(heights[0]) / 1000000);
|
||||
@@ -164,6 +167,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegDestroy(rocjpeg_handle));
|
||||
CHECK_ROCJPEG(rocJpegStreamDestroy(rocjpeg_stream_handle));
|
||||
std::cout << "Decoding completed!" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ THE SOFTWARE.
|
||||
|
||||
#include "../rocjpeg_samples_utils.h"
|
||||
|
||||
void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_handle, RocJpegUtils rocjpeg_util, RocJpegImage *output_image, std::mutex &mutex,
|
||||
void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_handle, RocJpegStreamHandle rocjpeg_stream, RocJpegUtils rocjpeg_util, RocJpegImage *output_image, std::mutex &mutex,
|
||||
RocJpegDecodeParams &decode_params, bool save_images, std::string &output_file_path, uint64_t *num_decoded_images, double *image_size_in_mpixels) {
|
||||
|
||||
std::vector<char> file_data;
|
||||
@@ -69,7 +69,8 @@ void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_h
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, reinterpret_cast<uint8_t *>(file_data.data()), file_size, &num_components, &subsampling, widths, heights));
|
||||
CHECK_ROCJPEG(rocJpegStreamParse(reinterpret_cast<uint8_t *>(file_data.data()), file_size, rocjpeg_stream));
|
||||
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, rocjpeg_stream, &num_components, &subsampling, widths, heights));
|
||||
if (subsampling == ROCJPEG_CSS_440 || subsampling == ROCJPEG_CSS_411) {
|
||||
std::cout << "The chroma sub-sampling is not supported by VCN Hardware" << std::endl;
|
||||
std::cout << "Skipping decoding file " << base_file_name << std::endl;
|
||||
@@ -92,7 +93,7 @@ void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_h
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t *>(file_data.data()), file_size, &decode_params, output_image));
|
||||
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, rocjpeg_stream, &decode_params, output_image));
|
||||
*image_size_in_mpixels += (static_cast<double>(widths[0]) * static_cast<double>(heights[0]) / 1000000);
|
||||
*num_decoded_images += 1;
|
||||
|
||||
@@ -123,6 +124,7 @@ int main(int argc, char **argv) {
|
||||
RocJpegBackend rocjpeg_backend = ROCJPEG_BACKEND_HARDWARE;
|
||||
RocJpegDecodeParams decode_params = {};
|
||||
std::vector<RocJpegHandle> rocjpeg_handles;
|
||||
std::vector<RocJpegStreamHandle> rocjpeg_streams;
|
||||
std::mutex mutex;
|
||||
std::vector<uint64_t> num_decoded_images_per_thread;
|
||||
std::vector<double> image_size_in_mpixels_per_thread;
|
||||
@@ -146,9 +148,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
std::cout << "Creating decoder objects, please wait!" << std::endl;
|
||||
for (int i = 0; i < num_threads; i++) {
|
||||
RocJpegStreamHandle rocjpeg_stream;
|
||||
RocJpegHandle rocjpeg_handle;
|
||||
CHECK_ROCJPEG(rocJpegCreate(rocjpeg_backend, device_id, &rocjpeg_handle));
|
||||
rocjpeg_handles.push_back(std::move(rocjpeg_handle));
|
||||
CHECK_ROCJPEG(rocJpegStreamCreate(&rocjpeg_stream));
|
||||
rocjpeg_streams.push_back(std::move(rocjpeg_stream));
|
||||
}
|
||||
num_decoded_images_per_thread.resize(num_threads, 0);
|
||||
image_size_in_mpixels_per_thread.resize(num_threads, 0);
|
||||
@@ -157,7 +162,7 @@ int main(int argc, char **argv) {
|
||||
std::cout << "Decoding started with " << num_threads << " threads, please wait!" << std::endl;
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < num_threads; ++i) {
|
||||
threads.emplace_back(ThreadFunction, std::ref(file_paths), rocjpeg_handles[i], rocjpeg_utils, &rocjpeg_images[i], std::ref(mutex), std::ref(decode_params), save_images, std::ref(output_file_path),
|
||||
threads.emplace_back(ThreadFunction, std::ref(file_paths), rocjpeg_handles[i], rocjpeg_streams[i], rocjpeg_utils, &rocjpeg_images[i], std::ref(mutex), std::ref(decode_params), save_images, std::ref(output_file_path),
|
||||
&num_decoded_images_per_thread[i], &image_size_in_mpixels_per_thread[i]);
|
||||
}
|
||||
for (auto& thread : threads) {
|
||||
@@ -191,6 +196,9 @@ int main(int argc, char **argv) {
|
||||
for (auto& handle : rocjpeg_handles) {
|
||||
CHECK_ROCJPEG(rocJpegDestroy(handle));
|
||||
}
|
||||
for (auto& rocjpecg_stream : rocjpeg_streams) {
|
||||
CHECK_ROCJPEG(rocJpegStreamDestroy(rocjpecg_stream));
|
||||
}
|
||||
std::cout << "Decoding completed!" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -20,11 +20,64 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "rocjpeg_api_handle.h"
|
||||
#include "rocjpeg_api_stream_handle.h"
|
||||
#include "rocjpeg_api_decoder_handle.h"
|
||||
#include "rocjpeg_commons.h"
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Create the rocJPEG stream parser handle. This handle is used to parse and retrieve the information from the JPEG stream.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle) {
|
||||
if (jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
RocJpegStreamHandle rocjpeg_stream_handle = nullptr;
|
||||
try {
|
||||
rocjpeg_stream_handle = new RocJpegStreamParserHandle();
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
ERR(STR("Failed to init the rocJPEG stream handle, ") + STR(e.what()));
|
||||
return ROCJPEG_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
*jpeg_stream_handle = rocjpeg_stream_handle;
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Parses a jpeg stream and stores the information from the stream to be used in subsequent API calls for retrieving the image information and decoding it.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle) {
|
||||
if (data == nullptr || jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
if (!rocjpeg_stream_handle->rocjpeg_stream->ParseJpegStream(data, length)) {
|
||||
return ROCJPEG_STATUS_BAD_JPEG;
|
||||
}
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Release the jpeg parser object and resources.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle) {
|
||||
if (jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
delete rocjpeg_stream_handle;
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, RocJpegHandle *handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Create the decoder object based on backend and device_id. A handle to the created decoder is returned
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, RocJpegHandle *handle) {
|
||||
@@ -44,6 +97,7 @@ RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, Ro
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Release the decoder object and resources.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle) {
|
||||
@@ -56,20 +110,21 @@ RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle) {
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t *data, size_t length,
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle,
|
||||
//! int *num_components, RocJpegChromaSubsampling *subsampling, int *widths, int *heights)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Retrieve the image info, including channel, width and height of each component, and chroma subsampling.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t *data, size_t length, uint8_t *num_components,
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, uint8_t *num_components,
|
||||
RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights) {
|
||||
if (handle == nullptr || data == nullptr || num_components == nullptr ||
|
||||
if (handle == nullptr || num_components == nullptr ||
|
||||
subsampling == nullptr || widths == nullptr || heights == 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->GetImageInfo(data, length, num_components, subsampling, widths, heights);
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->GetImageInfo(jpeg_stream_handle, num_components, subsampling, widths, heights);
|
||||
} catch (const std::exception& e) {
|
||||
rocjpeg_handle->CaptureError(e.what());
|
||||
ERR(e.what());
|
||||
@@ -80,24 +135,25 @@ RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Decodes single image based on the backend used to create the rocJpeg handle in rocJpegCreate API.
|
||||
//! Destination buffers should be large enough to be able to store output of specified format. These buffers should be pre-allocted by the user in the device memories.
|
||||
//! Destination buffers should be large enough to be able to store output of specified format.
|
||||
//! These buffers should be pre-allocted by the user in the device memories.
|
||||
//! For each color plane (channel) sizes could be retrieved for image using rocJpegGetImageInfo API
|
||||
//! and minimum required memory buffer for each plane is plane_height * plane_pitch where plane_pitch >= plane_width for
|
||||
//! planar output formats and plane_pitch >= plane_width * num_components for interleaved output format.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params,
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params,
|
||||
RocJpegImage *destination) {
|
||||
|
||||
if (handle == nullptr || data == nullptr || decode_params == nullptr || destination == nullptr) {
|
||||
if (handle == nullptr || decode_params == nullptr || destination == 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->Decode(data, length, decode_params, destination);
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->Decode(jpeg_stream_handle, decode_params, destination);
|
||||
} catch (const std::exception& e) {
|
||||
rocjpeg_handle->CaptureError(e.what());
|
||||
ERR(e.what());
|
||||
|
||||
+7
-10
@@ -20,25 +20,22 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ROC_JPEG_HANDLE_H
|
||||
#define ROC_JPEG_HANDLE_H
|
||||
#ifndef ROC_JPEG_DECODER_HANDLE_H
|
||||
#define ROC_JPEG_DECODER_HANDLE_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "rocjpeg_decoder.h"
|
||||
|
||||
/**
|
||||
* @brief RocJpegHandle class
|
||||
*
|
||||
* @brief RocJpegDecoderHandle class
|
||||
* This class wraps around RocJpegDecoder to decode a JPEG stream.
|
||||
*/
|
||||
class RocJpegDecoderHandle {
|
||||
public:
|
||||
explicit RocJpegDecoderHandle(RocJpegBackend backend, int device_id) : rocjpeg_decoder(std::make_shared<ROCJpegDecoder>(backend, device_id)) {};
|
||||
explicit RocJpegDecoderHandle(RocJpegBackend backend, int device_id) : rocjpeg_decoder(std::make_shared<RocJpegDecoder>(backend, device_id)) {};
|
||||
~RocJpegDecoderHandle() { ClearErrors(); }
|
||||
std::shared_ptr<ROCJpegDecoder> rocjpeg_decoder;
|
||||
std::shared_ptr<RocJpegDecoder> rocjpeg_decoder;
|
||||
bool NoError() { return error_.empty(); }
|
||||
const char* ErrorMsg() { return error_.c_str(); }
|
||||
void CaptureError(const std::string& err_msg) { error_ = err_msg; }
|
||||
@@ -47,4 +44,4 @@ class RocJpegDecoderHandle {
|
||||
std::string error_;
|
||||
};
|
||||
|
||||
#endif //ROC_JPEG_HANDLE_H
|
||||
#endif //ROC_JPEG_DECODER_HANDLE_H
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ROC_JPEG_STREAM_HANDLE_H
|
||||
#define ROC_JPEG_STREAM_HANDLE_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "rocjpeg_parser.h"
|
||||
|
||||
/**
|
||||
* @brief RocJpegStreamParserHandle class
|
||||
* This class wraps around RocJpegStreamParser to parse and store information from a JPEG stream.
|
||||
*/
|
||||
class RocJpegStreamParserHandle {
|
||||
public:
|
||||
explicit RocJpegStreamParserHandle() : rocjpeg_stream(std::make_shared<RocJpegStreamParser>()) {};
|
||||
~RocJpegStreamParserHandle() { ClearErrors(); }
|
||||
std::shared_ptr<RocJpegStreamParser> rocjpeg_stream;
|
||||
bool NoError() { return error_.empty(); }
|
||||
const char* ErrorMsg() { return error_.c_str(); }
|
||||
void CaptureError(const std::string& err_msg) { error_ = err_msg; }
|
||||
private:
|
||||
void ClearErrors() { error_ = "";}
|
||||
std::string error_;
|
||||
};
|
||||
|
||||
#endif //ROC_JPEG_STREAM_HANDLE_H
|
||||
@@ -22,16 +22,16 @@ THE SOFTWARE.
|
||||
|
||||
#include "rocjpeg_decoder.h"
|
||||
|
||||
ROCJpegDecoder::ROCJpegDecoder(RocJpegBackend backend, int device_id) :
|
||||
RocJpegDecoder::RocJpegDecoder(RocJpegBackend backend, int device_id) :
|
||||
num_devices_{0}, device_id_ {device_id}, hip_stream_ {0}, backend_{backend} {}
|
||||
|
||||
ROCJpegDecoder::~ROCJpegDecoder() {
|
||||
RocJpegDecoder::~RocJpegDecoder() {
|
||||
if (hip_stream_) {
|
||||
hipError_t hip_status = hipStreamDestroy(hip_stream_);
|
||||
}
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::InitHIP(int device_id) {
|
||||
RocJpegStatus RocJpegDecoder::InitHIP(int device_id) {
|
||||
hipError_t hip_status = hipSuccess;
|
||||
CHECK_HIP(hipGetDeviceCount(&num_devices_));
|
||||
if (num_devices_ < 1) {
|
||||
@@ -48,7 +48,7 @@ RocJpegStatus ROCJpegDecoder::InitHIP(int device_id) {
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::InitializeDecoder() {
|
||||
RocJpegStatus RocJpegDecoder::InitializeDecoder() {
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
rocjpeg_status = InitHIP(device_id_);
|
||||
if (rocjpeg_status != ROCJPEG_STATUS_SUCCESS) {
|
||||
@@ -67,16 +67,15 @@ RocJpegStatus ROCJpegDecoder::InitializeDecoder() {
|
||||
return rocjpeg_status;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::Decode(const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::Decode(RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params, RocJpegImage *destination) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
|
||||
if (!jpeg_parser_.ParseJpegStream(data, length)) {
|
||||
ERR("ERROR: Failed to parse the jpeg stream!");
|
||||
return ROCJPEG_STATUS_BAD_JPEG;
|
||||
if (jpeg_stream_handle == nullptr || decode_params == nullptr || destination == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
const JpegStreamParameters *jpeg_stream_params = rocjpeg_stream_handle->rocjpeg_stream->GetJpegStreamParameters();
|
||||
|
||||
const JpegStreamParameters *jpeg_stream_params = jpeg_parser_.GetJpegStreamParameters();
|
||||
VASurfaceID current_surface_id;
|
||||
CHECK_ROCJPEG(jpeg_vaapi_decoder_.SubmitDecode(jpeg_stream_params, current_surface_id, decode_params->output_format));
|
||||
|
||||
@@ -129,16 +128,14 @@ RocJpegStatus ROCJpegDecoder::Decode(const uint8_t *data, size_t length, const R
|
||||
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::GetImageInfo(const uint8_t *data, size_t length, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights){
|
||||
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_);
|
||||
if (widths == nullptr || heights == nullptr || num_components == nullptr) {
|
||||
if (jpeg_stream_handle == nullptr || num_components == nullptr || subsampling == nullptr || widths == nullptr || heights == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!jpeg_parser_.ParseJpegStream(data, length)) {
|
||||
ERR("ERROR: jpeg parser failed!");
|
||||
return ROCJPEG_STATUS_BAD_JPEG;
|
||||
}
|
||||
const JpegStreamParameters *jpeg_stream_params = jpeg_parser_.GetJpegStreamParameters();
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
const JpegStreamParameters *jpeg_stream_params = rocjpeg_stream_handle->rocjpeg_stream->GetJpegStreamParameters();
|
||||
|
||||
*num_components = jpeg_stream_params->picture_parameter_buffer.num_components;
|
||||
widths[0] = jpeg_stream_params->picture_parameter_buffer.picture_width;
|
||||
heights[0] = jpeg_stream_params->picture_parameter_buffer.picture_height;
|
||||
@@ -184,7 +181,7 @@ RocJpegStatus ROCJpegDecoder::GetImageInfo(const uint8_t *data, size_t length, u
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::CopyChannel(HipInteropDeviceMem& hip_interop_dev_mem, uint16_t channel_height, uint8_t channel_index, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::CopyChannel(HipInteropDeviceMem& hip_interop_dev_mem, uint16_t channel_height, uint8_t channel_index, RocJpegImage *destination) {
|
||||
if (hip_interop_dev_mem.pitch[channel_index] != 0 && destination->pitch[channel_index] != 0 && destination->channel[channel_index] != nullptr) {
|
||||
if (destination->pitch[channel_index] == hip_interop_dev_mem.pitch[channel_index]) {
|
||||
uint32_t channel_size = destination->pitch[channel_index] * channel_height;
|
||||
@@ -197,7 +194,7 @@ RocJpegStatus ROCJpegDecoder::CopyChannel(HipInteropDeviceMem& hip_interop_dev_m
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::GetChromaHeight(uint32_t surface_format, uint16_t picture_height, uint16_t &chroma_height) {
|
||||
RocJpegStatus RocJpegDecoder::GetChromaHeight(uint32_t surface_format, uint16_t picture_height, uint16_t &chroma_height) {
|
||||
switch (surface_format) {
|
||||
case VA_FOURCC_NV12: /*NV12: two-plane 8-bit YUV 4:2:0*/
|
||||
chroma_height = picture_height >> 1;
|
||||
@@ -217,7 +214,7 @@ RocJpegStatus ROCJpegDecoder::GetChromaHeight(uint32_t surface_format, uint16_t
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::ColorConvertToRGB(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::ColorConvertToRGB(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
switch (hip_interop_dev_mem.surface_format) {
|
||||
case VA_FOURCC_444P:
|
||||
ColorConvertYUV444ToRGB(hip_stream_, picture_width, picture_height, destination->channel[0], destination->pitch[0],
|
||||
@@ -247,7 +244,7 @@ RocJpegStatus ROCJpegDecoder::ColorConvertToRGB(HipInteropDeviceMem& hip_interop
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::ColorConvertToRGBPlanar(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::ColorConvertToRGBPlanar(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
switch (hip_interop_dev_mem.surface_format) {
|
||||
case VA_FOURCC_444P:
|
||||
ColorConvertYUV444ToRGBPlanar(hip_stream_, picture_width, picture_height, destination->channel[0], destination->channel[1], destination->channel[2], destination->pitch[0],
|
||||
@@ -279,7 +276,7 @@ RocJpegStatus ROCJpegDecoder::ColorConvertToRGBPlanar(HipInteropDeviceMem& hip_i
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::GetPlanarYUVOutputFormat(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, uint16_t chroma_height, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::GetPlanarYUVOutputFormat(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, uint16_t chroma_height, RocJpegImage *destination) {
|
||||
if (hip_interop_dev_mem.surface_format == ROCJPEG_FOURCC_YUYV) {
|
||||
// Extract the packed YUYV and copy them into the first, second, and thrid channels of the destination.
|
||||
ConvertPackedYUYVToPlanarYUV(hip_stream_, picture_width, picture_height, destination->channel[0], destination->channel[1], destination->channel[2],
|
||||
@@ -299,7 +296,7 @@ RocJpegStatus ROCJpegDecoder::GetPlanarYUVOutputFormat(HipInteropDeviceMem& hip_
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RocJpegStatus ROCJpegDecoder::GetYOutputFormat(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
RocJpegStatus RocJpegDecoder::GetYOutputFormat(HipInteropDeviceMem& hip_interop_dev_mem, uint32_t picture_width, uint32_t picture_height, RocJpegImage *destination) {
|
||||
if (hip_interop_dev_mem.surface_format == ROCJPEG_FOURCC_YUYV) {
|
||||
ExtractYFromPackedYUYV(hip_stream_, picture_width, picture_height, destination->channel[0], destination->pitch[0],
|
||||
hip_interop_dev_mem.hip_mapped_device_mem, hip_interop_dev_mem.pitch[0]);
|
||||
|
||||
@@ -28,18 +28,19 @@ THE SOFTWARE.
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include "../api/rocjpeg.h"
|
||||
#include "rocjpeg_api_stream_handle.h"
|
||||
#include "rocjpeg_parser.h"
|
||||
#include "rocjpeg_commons.h"
|
||||
#include "rocjpeg_vaapi_decoder.h"
|
||||
#include "rocjpeg_hip_kernels.h"
|
||||
|
||||
class ROCJpegDecoder {
|
||||
class RocJpegDecoder {
|
||||
public:
|
||||
ROCJpegDecoder(RocJpegBackend backend = ROCJPEG_BACKEND_HARDWARE, int device_id = 0);
|
||||
~ROCJpegDecoder();
|
||||
RocJpegDecoder(RocJpegBackend backend = ROCJPEG_BACKEND_HARDWARE, int device_id = 0);
|
||||
~RocJpegDecoder();
|
||||
RocJpegStatus InitializeDecoder();
|
||||
RocJpegStatus GetImageInfo(const uint8_t *data, size_t length, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights);
|
||||
RocJpegStatus Decode(const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
RocJpegStatus GetImageInfo(RocJpegStreamHandle jpeg_stream, uint8_t *num_components, RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights);
|
||||
RocJpegStatus Decode(RocJpegStreamHandle jpeg_stream, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
private:
|
||||
RocJpegStatus InitHIP(int device_id);
|
||||
RocJpegStatus GetChromaHeight(uint32_t surface_format, uint16_t picture_height, uint16_t &chroma_height);
|
||||
@@ -53,7 +54,6 @@ class ROCJpegDecoder {
|
||||
hipDeviceProp_t hip_dev_prop_;
|
||||
hipStream_t hip_stream_;
|
||||
std::mutex mutex_;
|
||||
JpegParser jpeg_parser_;
|
||||
RocJpegBackend backend_;
|
||||
RocJpegVappiDecoder jpeg_vaapi_decoder_;
|
||||
};
|
||||
|
||||
@@ -21,17 +21,18 @@ THE SOFTWARE.
|
||||
*/
|
||||
#include "rocjpeg_parser.h"
|
||||
|
||||
JpegParser::JpegParser() : stream_{nullptr}, stream_end_{nullptr}, stream_length_{0},
|
||||
RocJpegStreamParser::RocJpegStreamParser() : stream_{nullptr}, stream_end_{nullptr}, stream_length_{0},
|
||||
jpeg_stream_parameters_{{}} {
|
||||
}
|
||||
|
||||
JpegParser::~JpegParser() {
|
||||
RocJpegStreamParser::~RocJpegStreamParser() {
|
||||
stream_ = nullptr;
|
||||
stream_end_ = nullptr;
|
||||
stream_length_ = 0;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseJpegStream(const uint8_t *jpeg_stream, uint32_t jpeg_stream_size) {
|
||||
bool RocJpegStreamParser::ParseJpegStream(const uint8_t *jpeg_stream, uint32_t jpeg_stream_size) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (jpeg_stream == nullptr) {
|
||||
ERR("invalid argument!");
|
||||
return false;
|
||||
@@ -113,7 +114,7 @@ bool JpegParser::ParseJpegStream(const uint8_t *jpeg_stream, uint32_t jpeg_strea
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseSOI() {
|
||||
bool RocJpegStreamParser::ParseSOI() {
|
||||
if (stream_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -129,7 +130,7 @@ bool JpegParser::ParseSOI() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseSOF() {
|
||||
bool RocJpegStreamParser::ParseSOF() {
|
||||
uint32_t component_id, sampling_factor;
|
||||
uint8_t quantiser_table_selector;
|
||||
|
||||
@@ -178,7 +179,7 @@ bool JpegParser::ParseSOF() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseDQT() {
|
||||
bool RocJpegStreamParser::ParseDQT() {
|
||||
int32_t quantization_table_index = 0;
|
||||
const uint8_t *dqt_block_end;
|
||||
|
||||
@@ -209,7 +210,7 @@ bool JpegParser::ParseDQT() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseDHT() {
|
||||
bool RocJpegStreamParser::ParseDHT() {
|
||||
uint32_t count, i;
|
||||
int32_t length, index;
|
||||
uint8_t ac_huffman_table, huffman_table_id;
|
||||
@@ -268,7 +269,7 @@ bool JpegParser::ParseDHT() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseSOS() {
|
||||
bool RocJpegStreamParser::ParseSOS() {
|
||||
uint32_t component_id, table;
|
||||
|
||||
if (stream_ == nullptr) {
|
||||
@@ -310,7 +311,7 @@ bool JpegParser::ParseSOS() {
|
||||
}
|
||||
|
||||
|
||||
bool JpegParser::ParseDRI() {
|
||||
bool RocJpegStreamParser::ParseDRI() {
|
||||
uint32_t length;
|
||||
|
||||
if (stream_ == nullptr) {
|
||||
@@ -328,7 +329,7 @@ bool JpegParser::ParseDRI() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JpegParser::ParseEOI() {
|
||||
bool RocJpegStreamParser::ParseEOI() {
|
||||
|
||||
if (stream_ == nullptr) {
|
||||
return false;
|
||||
@@ -346,7 +347,7 @@ bool JpegParser::ParseEOI() {
|
||||
return true;
|
||||
}
|
||||
|
||||
ChromaSubsampling JpegParser::GetChromaSubsampling(uint8_t c1_h_sampling_factor, uint8_t c2_h_sampling_factor, uint8_t c3_h_sampling_factor,
|
||||
ChromaSubsampling RocJpegStreamParser::GetChromaSubsampling(uint8_t c1_h_sampling_factor, uint8_t c2_h_sampling_factor, uint8_t c3_h_sampling_factor,
|
||||
uint8_t c1_v_sampling_factor, uint8_t c2_v_sampling_factor, uint8_t c3_v_sampling_factor) {
|
||||
|
||||
ChromaSubsampling subsampling;
|
||||
|
||||
@@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include "rocjpeg_commons.h"
|
||||
|
||||
#pragma once
|
||||
@@ -152,10 +153,10 @@ typedef struct JpegParameterBuffersType {
|
||||
const uint8_t* slice_data_buffer;
|
||||
} JpegStreamParameters;
|
||||
|
||||
class JpegParser {
|
||||
class RocJpegStreamParser {
|
||||
public:
|
||||
JpegParser();
|
||||
~JpegParser();
|
||||
RocJpegStreamParser();
|
||||
~RocJpegStreamParser();
|
||||
bool ParseJpegStream(const uint8_t* jpeg_stream, uint32_t jpeg_stream_size);
|
||||
const JpegStreamParameters* GetJpegStreamParameters() const {return &jpeg_stream_parameters_;};
|
||||
private:
|
||||
@@ -172,6 +173,7 @@ class JpegParser {
|
||||
const uint8_t *stream_end_;
|
||||
uint32_t stream_length_;
|
||||
JpegStreamParameters jpeg_stream_parameters_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
#endif // ROC_JPEG_PARSER_H_
|
||||
Referencia en una nueva incidencia
Block a user