| | |
| | | #include "../ffmpeg/format/FormatIn.hpp" |
| | | #include "../ffmpeg/data/CodedData.hpp" |
| | | #include "../ffmpeg/log/log.hpp" |
| | | #include "../common.hpp" |
| | | |
| | | extern "C"{ |
| | | #include <libavformat/avformat.h> |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int decoder::saveFrame(AVFrame *frame, int64_t &id){ |
| | | int decoder::saveFrame(AVFrame *frame, const int64_t &id){ |
| | | FRM frm; |
| | | frm.width = frame->width; |
| | | frm.height = frame->height; |
| | | frm.format = frame->format; |
| | | frm.id = id; |
| | | frm.data = cvbridge::extractFrame(frame, &frm.length); |
| | | |
| | | uint8_t *tmp = cvbridge::extractFrame(frame, &frm.length); |
| | | uint8_t *data = NULL; |
| | | if (frame->format == AV_PIX_FMT_YUV420P){ |
| | | data = tmp; |
| | | }else if (frame->format == AV_PIX_FMT_NV12){ |
| | | data = (uint8_t*)malloc(frm.length); |
| | | |
| | | int i, j; |
| | | int y_size = frame->width * frame->height; |
| | | |
| | | unsigned char* y = tmp; |
| | | unsigned char* uv = tmp + y_size; |
| | | |
| | | unsigned char* y_tmp = data; |
| | | unsigned char* u_tmp = data + y_size; |
| | | unsigned char* v_tmp = data + y_size * 5 / 4; |
| | | |
| | | // y |
| | | memcpy(y_tmp, y, y_size); |
| | | |
| | | // uv |
| | | for (j = 0, i = 0; j < y_size/2; j+=2, i++) |
| | | { |
| | | u_tmp[i] = uv[j]; |
| | | v_tmp[i] = uv[j+1]; |
| | | } |
| | | free(tmp); |
| | | }else{ |
| | | return 0; |
| | | } |
| | | frm.data = data; |
| | | std::lock_guard<std::mutex> l(mutex_frm_); |
| | | while(list_frm_.size() > 50){ |
| | | for(int i = 0; i < 12; i++){ |
| | |
| | | return list_frm_.size(); |
| | | } |
| | | |
| | | int decoder::SetFrame(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id){ |
| | | int decoder::SetFrame(const CPacket &pkt){ |
| | | auto data = pkt.data; |
| | | |
| | | if (!data) return -10; |
| | | if (!decRef_->isVideoPkt(&data->getAVPacket())) return -20; |
| | |
| | | av_packet_unref(&np); |
| | | |
| | | if (ret == 0){ |
| | | saveFrame(frame, id); |
| | | saveFrame(frame, pkt.v_id); |
| | | } |
| | | av_frame_free(&frame); |
| | | return ret; |