// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x30(%rbp)
movl 0x20(%rcx), %eax
movl %eax, -0x34(%rbp)
movl 0x24(%rcx), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
cmpl 0x18(%rcx), %eax
jne 0x2a12
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x21e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2931
movq 0x46fd(%rip), %rax      # 0x6fe0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x20b0
leaq -0x78(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x40, %esi
callq 0x2a30
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x2802(%rip), %rsi      # 0x5121
movb $0x0, %al
callq 0x2090
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2a18
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2a10
movq -0x20(%rbp), %rax
movl 0x68(%rax), %eax
cmpl -0x34(%rbp), %eax
jne 0x296a
movq -0x20(%rbp), %rax
movl 0x6c(%rax), %eax
cmpl -0x38(%rbp), %eax
jne 0x296a
movq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movl 0x74(%rax), %eax
cmpl 0x1c(%rcx), %eax
je 0x2a0e
movq -0x80(%rbp), %rax
movq 0x466b(%rip), %rcx      # 0x6fe0
movq (%rcx), %rcx
movq %rcx, -0xa8(%rbp)
movl -0x34(%rbp), %ecx
movl %ecx, -0xa0(%rbp)
movl -0x38(%rbp), %ecx
movl %ecx, -0x9c(%rbp)
movl 0x1c(%rax), %edi
callq 0x2260
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movl 0x74(%rax), %edi
callq 0x2260
movq -0xa8(%rbp), %rdi
movl -0xa0(%rbp), %edx
movl -0x9c(%rbp), %ecx
movq -0x98(%rbp), %r8
movl -0x90(%rbp), %r9d
movl -0x8c(%rbp), %r10d
leaq 0x274d(%rip), %rsi      # 0x5142
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2090
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2a18
jmp 0x2a10
jmp 0x2a12
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)