-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH264Decoder.cpp
More file actions
33 lines (29 loc) · 917 Bytes
/
H264Decoder.cpp
File metadata and controls
33 lines (29 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "H264Decoder.h"
H264Decoder::H264Decoder()
: FFmpeg_Decoder(AV_CODEC_ID_H264)
, frameCallBack(nullptr)
, buf(nullptr) {
buf = new BYTE[MAX_BUF_SIZE];
}
H264Decoder::~H264Decoder() {
if(buf) {
delete [] buf;
buf = nullptr;
}
}
void H264Decoder::setFrameCallBack(FrameCallBack cb) {
this->frameCallBack = cb;
}
void H264Decoder::handleOneFrame(AVFrame* frame) {
UINT32 width = frame->width;
UINT32 height = frame->height;
UINT32 fps = codec_ctx->framerate.num;
// debug("获得一帧", width, height);
int ysize = width * height;
int uvsize = ysize >> 2;
int bufsize = ysize + (uvsize << 1);
memcpy(buf, frame->data[0], ysize);
memcpy(buf + ysize, frame->data[1], uvsize);
memcpy(buf + ysize + uvsize, frame->data[2], uvsize);
frameCallBack(buf, bufsize, width, height, fps, codec_ctx->pix_fmt);
}