Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg software decoder implementation #461

Open
wants to merge 12 commits into
base: beta-testing
Choose a base branch
from

Conversation

rrawther
Copy link
Collaborator

Implemented ffmpeg based software decoder
Modified videoDecode sample to allow ffmpeg based decoding

@kiritigowda kiritigowda added enhancement New feature or request ci:precheckin run mainline precheckin CI job labels Nov 26, 2024
Copy link
Contributor

@spolifroni-amd spolifroni-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the additional lines in the changelogs are for 6.3, please let me know.

CHANGELOG.md Show resolved Hide resolved
Copy link
Member

@AryanSalmanpour AryanSalmanpour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few minor formatting and some suggestions.

void DecodeThread();
int DecodeAvFrame(AVPacket *av_pkt, AVFrame *p_frame);
void InitOutputFrameInfo(AVFrame *p_frame);
void PushPacket(AVPacket *pkt){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting: add a space *pkt){ -> *pkt) {

cv_pkt_.notify_one();
}

AVPacket *PopPacket(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting: add a space *PopPacket(){ -> *PopPacket() {

return pkt;
}

void PushFrame(AVFrame *av_frame){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting: add a space *av_frame){ -> *av_frame) {

cv_frame_.notify_one();
};

AVFrame *PopFrame(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting: add a space *PopFrame(){ -> *PopFrame() {

switch (av_pixel_format) {
case AV_PIX_FMT_YUV420P :
case AV_PIX_FMT_YUVJ420P :
return rocDecVideoSurfaceFormat_YUV420; // need to see if this is actually correct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still relevant? If so, what needs to be done to ensure we return the correct rocdecode surface format?

// vp_frames_ffmpeg_.size() is empty, wait for decoding to finish
// this will happen during PopFrame()
AVFrame *p_av_frame;
//std::cout << "Before pop frame " << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment if it is unnecessary.

std::cerr << "Invalid avframe decode output" << std::endl;
return 0;
}
void * src_ptr[3] = { 0 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting: remove the space -> void * -> void*

{
std::lock_guard<std::mutex> lock(mtx_vp_frame_);
// if not enough frames in stock, allocate
if ((unsigned)++output_frame_cnt_ > vp_frames_ffmpeg_.size()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use static_cast here

// so we need to flush FFMpeg decoder when we have received the lastpacket with 0 bytes
if (!last_packet_.payload_size && !end_of_stream_) {
AVPacket pkt = { 0 };
#if NO_DECODE_THREAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using an environment variable to control whether decoding is performed with or without a thread. This change would enable us to test both options without the need to recompile the program. For instance, we could create an environment variable called ROCDEC_FFMPEG_DISABLE_DECODE_THREAD. By setting it with the command export ROCDEC_FFMPEG_DISABLE_DECODE_THREAD=1, we can disable threading for FFMPEG. The following code can then be used to check whether threading is disabled.

const char *is_threading_disabled = std::getenv("ROCDEC_FFMPEG_DISABLE_DECODE_THREAD");

if (std::string(is_threading_disabled) != "1") 
   DecodeAvFrame(&pkt, dec_frames_[av_frame_cnt_]);
else
 PushPacket(&pkt);

// this will happen during PopFrame()
AVFrame *p_av_frame;
//std::cout << "Before pop frame " << std::endl;
#if NO_DECODE_THREAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, it is recommended to use an environment variable to check if threading is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:precheckin run mainline precheckin CI job enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants