// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rcx, %rbp
movl 0x20(%rsi), %r14d
movl 0x20(%rdi), %ebx
movl 0x24(%rdi), %r13d
andl $0x0, (%rcx)
movl 0x24(%rsi), %eax
cmpl 0x18(%rdi), %eax
jne 0x2732
movq %rsi, %rcx
movq %rdi, %r12
movq %rdx, %r15
movq 0x8(%rdi), %rdi
movq %rdx, %rsi
movq %rbp, %rdx
callq 0x21b0
testl %eax, %eax
js 0x279e
cmpl $0x0, (%rbp)
je 0x2732
cmpl %ebx, 0x68(%r15)
jne 0x2744
cmpl %r13d, 0x6c(%r15)
jne 0x2744
movl 0x74(%r15), %eax
cmpl 0x1c(%r12), %eax
jne 0x2744
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3895(%rip), %rax      # 0x5fe0
movq (%rax), %r14
movl 0x1c(%r12), %edi
callq 0x2230
movq %rax, %r12
movl 0x68(%r15), %ebp
movl 0x6c(%r15), %eax
movq %rax, 0x8(%rsp)
movl 0x74(%r15), %edi
callq 0x2230
movq %rax, %r10
leaq 0x19c7(%rip), %rsi      # 0x4142
movq %r14, %rdi
movl %ebx, %edx
movl %r13d, %ecx
movq %r12, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq 0x10(%rsp)
callq 0x2080
popq %rcx
popq %rdx
pushq $-0x1
popq %r14
jmp 0x2732
movq 0x383b(%rip), %rcx      # 0x5fe0
movq (%rcx), %r15
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
pushq $0x40
popq %rdx
movl %eax, %ebx
movl %eax, %edi
movq %r14, %rsi
callq 0x2140
leaq 0x1948(%rip), %rsi      # 0x4121
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2080
movl %ebx, %r14d
jmp 0x2732