Files
rocm-systems/tests/bin/rocdecode/rocdecode.cpp
T
Trowbridge, Ian e307b89ca4 rocDecode API Tracing Support (#49)
* rocDecode API Tracing support

* Test bin file added to rocdecode. Need to add validate python methods

* Added option to not make rocDecode tests

* Added rocdecode and rocprofv3 tests

* Added csv test

* Address PR comments. Changed tests to use built-in rocstreambit decoder to remove ffmpeg dependancy. Changed cmake option to disbale tests rather than not build them. Tests work locally, but will fail until rocDecode is built with tracing enabled on CI

* Add option to avoid building rocdecode tests

* Added option to avoid building rocdecode bin file

* Merge conflict error

* CMake files changed in response to review comments. Attempting to implement callbacks.

* Turned off test building for rocdecode

* Minor fixes for review comments

* Review comments

* Updated formatting

* Document changes and format.hpp reversion. Need to remove iterate args support for now for later update.

* Remove iterate args support

* Remove iterate-args

* enforce abi versioning in macro if

* Fix doc error

* removed spaces to fix indentation error

---------

Co-authored-by: Madsen, Jonathan <Jonathan.Madsen@amd.com>
2025-01-17 14:42:25 -08:00

110 líneas
4.2 KiB
C++

/*
Copyright (c) 2024 - 2025 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.
*/
#include <rocdecode/roc_bitstream_reader.h>
#include <rocdecode/rocdecode.h>
#include <rocdecode/rocparser.h>
#include <iostream>
#include "roc_video_dec.h"
int
main(int argc, char** argv)
{
// Get input file
std::string input_file_path{};
for(int i = 1; i < argc; i++)
{
if(!strcmp(argv[i], "-i"))
{
if(++i == argc)
{
std::cerr << "Provide path to input file" << std::endl;
}
input_file_path = argv[i];
continue;
}
}
// Set up bitstreamreader
RocdecBitstreamReader bs_reader = nullptr;
rocDecVideoCodec rocdec_codec_id{};
int bit_depth{};
if(rocDecCreateBitstreamReader(&bs_reader, input_file_path.c_str()) != ROCDEC_SUCCESS)
{
std::cerr << "Failed to create the bitstream reader." << std::endl;
return 1;
}
if(rocDecGetBitstreamCodecType(bs_reader, &rocdec_codec_id) != ROCDEC_SUCCESS)
{
std::cerr << "Failed to get stream codec type." << std::endl;
return 1;
}
if(rocdec_codec_id >= rocDecVideoCodec_NumCodecs)
{
std::cerr << "Unsupported stream file type or codec type by the bitstream reader. Exiting."
<< std::endl;
return 1;
}
if(rocDecGetBitstreamBitDepth(bs_reader, &bit_depth) != ROCDEC_SUCCESS)
{
std::cerr << "Failed to get stream bit depth." << std::endl;
return 1;
}
// Set up video decoder
int device_id = 0;
OutputSurfaceMemoryType mem_type = OUT_SURFACE_MEM_DEV_INTERNAL;
bool b_force_zero_latency = false;
Rect* p_crop_rect = nullptr;
int disp_delay = 1;
bool b_extract_sei_messages = false;
RocVideoDecoder* viddec = new RocVideoDecoder(device_id,
mem_type,
rocdec_codec_id,
b_force_zero_latency,
p_crop_rect,
b_extract_sei_messages,
disp_delay);
uint8_t* pvideo = nullptr;
int n_video_bytes = 0;
int64_t pts = 0;
int pkg_flags = 0;
int decoded_pics = 0;
if(rocDecGetBitstreamPicData(bs_reader, &pvideo, &n_video_bytes, &pts) != ROCDEC_SUCCESS)
{
std::cerr << "Failed to get picture data." << std::endl;
return 1;
}
// Treat 0 bitstream size as end of stream indicator
if(n_video_bytes == 0)
{
pkg_flags |= ROCDEC_PKT_ENDOFSTREAM;
}
viddec->DecodeFrame(pvideo, n_video_bytes, pkg_flags, pts, &decoded_pics);
viddec->DecodeFrame(pvideo, n_video_bytes, pkg_flags, pts, &decoded_pics);
viddec->DecodeFrame(pvideo, n_video_bytes, pkg_flags, pts, &decoded_pics);
if(bs_reader)
{
rocDecDestroyBitstreamReader(bs_reader);
}
}