// File: /workspace/github_cpp_makefile_star2_O1/zhangk145[P]video_envalue/Decoder.cpp
// Function: Decoder::decode_packet(AVPacket*, AVFrame*, int*)
int Decoder::decode_packet(AVPacket *pkt, AVFrame *frame, int *got_frame)
{
    int ret = 0;
    int decoded = pkt->size;
    int width = mWidth;
    int height = mHeight;

    *got_frame = 0;

    if (pkt->stream_index == mStreamIndex) {
        /* decode video frame */
        ret = avcodec_decode_video2(mCodecCtx, frame, got_frame, pkt);
        if (ret < 0) {
            fprintf(stderr, "Error decoding video frame (%s)\n", av_err2str(ret));
            return ret;
        }

        if (*got_frame) {
            // printf("[%s:%d]==width:%d height:%d\n", __FUNCTION__, __LINE__, frame->width, frame->height);
            if (frame->width != width || frame->height != height ||
                frame->format != mPixFmt) {
                /* To handle this change, one could call av_image_alloc again and
                 * decode the following frames into another rawvideo file. */
                fprintf(stderr, "Error: Width, height and pixel format have to be "
                        "constant in a rawvideo file, but the width, height or "
                        "pixel format of the input video changed:\n"
                        "old: width = %d, height = %d, format = %s\n"
                        "new: width = %d, height = %d, format = %s\n",
                        width, height, av_get_pix_fmt_name(mPixFmt),
                        frame->width, frame->height,
                        av_get_pix_fmt_name((enum AVPixelFormat)frame->format));
                return -1;
            }

            // printf("mFrameCount:%d coded_n:%d\n",
            //        mFrameCount++, frame->coded_picture_number);

            /* copy decoded frame to destination buffer:
             * this is required since rawvideo expects non aligned data */
            // av_image_copy(mImageData, mImageLinesize,
            //               (const uint8_t **)(frame->data), frame->linesize,
            //               mPixFmt, width, height);

            /* write to rawvideo file */
            // fwrite(video_dst_data[0], 1, video_dst_bufsize, video_dst_file);
        }
    }

    /* If we use frame reference counting, we own the data and need
     * to de-reference it when we don't use it anymore */
    // if (*got_frame)
    //     av_frame_unref(frame);

    return decoded;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r13
movq %rdx, %r14
movl 0x20(%rsi), %ebp
movl 0x20(%rdi), %edx
movl 0x24(%rdi), %ebx
movl $0x0, (%rcx)
movl 0x24(%rsi), %eax
cmpl 0x18(%rdi), %eax
jne 0x2962
movq %rsi, %rcx
movq %rdi, %r12
movl %edx, 0xc(%rsp)
movq 0x8(%rdi), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x21b0
testl %eax, %eax
js 0x29d5
cmpl $0x0, (%r13)
je 0x2962
movl 0xc(%rsp), %ecx
cmpl %ecx, 0x68(%r14)
jne 0x2973
cmpl %ebx, 0x6c(%r14)
jne 0x2973
movl 0x74(%r14), %eax
cmpl 0x1c(%r12), %eax
jne 0x2973
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3666(%rip), %rax      # 0x5fe0
movq (%rax), %r15
movl 0x1c(%r12), %edi
movl %ebx, %r13d
movl %ecx, %ebx
callq 0x2230
movq %rax, %r12
movl 0x68(%r14), %ebp
movl 0x6c(%r14), %eax
movq %rax, 0x10(%rsp)
movl 0x74(%r14), %edi
callq 0x2230
movq %rax, %r10
leaq 0x1793(%rip), %rsi      # 0x4142
movq %r15, %rdi
movl %ebx, %edx
movl %r13d, %ecx
movq %r12, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq 0x18(%rsp)
callq 0x2080
addq $0x10, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2962
movl %eax, %r15d
movl %eax, %edi
callq 0x23b6
movl %r15d, %ebp
jmp 0x2962
nop