diff options
Diffstat (limited to 'modules/avcodec')
-rw-r--r-- | modules/avcodec/avcodec.h | 8 | ||||
-rw-r--r-- | modules/avcodec/decode.c | 42 | ||||
-rw-r--r-- | modules/avcodec/encode.c | 26 |
3 files changed, 54 insertions, 22 deletions
diff --git a/modules/avcodec/avcodec.h b/modules/avcodec/avcodec.h index f3a2b70..3511145 100644 --- a/modules/avcodec/avcodec.h +++ b/modules/avcodec/avcodec.h @@ -16,6 +16,14 @@ #endif +#if LIBAVUTIL_VERSION_MAJOR < 52 +#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P +#define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P +#define AV_PIX_FMT_NV12 PIX_FMT_NV12 +#define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P +#endif + + extern const uint8_t h264_level_idc; extern AVCodec *avcodec_h264enc; extern AVCodec *avcodec_h264dec; diff --git a/modules/avcodec/decode.c b/modules/avcodec/decode.c index 77e6e77..759535c 100644 --- a/modules/avcodec/decode.c +++ b/modules/avcodec/decode.c @@ -16,13 +16,6 @@ #include "avcodec.h" -#if LIBAVUTIL_VERSION_MAJOR < 52 -#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P -#define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P -#define AV_PIX_FMT_NV12 PIX_FMT_NV12 -#endif - - enum { DECODE_MAXSZ = 524288, }; @@ -37,6 +30,7 @@ struct viddec_state { size_t frag_start; bool frag; uint16_t frag_seq; + double fps; struct { unsigned n_key; @@ -192,7 +186,9 @@ static int ffdecode(struct viddec_state *st, struct vidframe *frame) ret = avcodec_send_packet(st->ctx, &avpkt); if (ret < 0) { - warning("avcodec_send_packet error ret=%d\n", ret); + warning("avcodec: avcodec_send_packet error," + " packet=%zu bytes, ret=%d (%s)\n", + st->mb->end, ret, av_err2str(ret)); err = EBADMSG; goto out; } @@ -235,6 +231,8 @@ static int ffdecode(struct viddec_state *st, struct vidframe *frame) if (got_picture) { + double fps; + #if LIBAVCODEC_VERSION_INT >= ((53<<16)+(5<<8)+0) switch (st->pict->format) { @@ -247,6 +245,10 @@ static int ffdecode(struct viddec_state *st, struct vidframe *frame) frame->fmt = VID_FMT_NV12; break; + case AV_PIX_FMT_YUV444P: + frame->fmt = VID_FMT_YUV444P; + break; + default: warning("avcodec: decode: bad pixel format" " (%i) (%s)\n", @@ -264,6 +266,18 @@ static int ffdecode(struct viddec_state *st, struct vidframe *frame) } frame->size.w = st->ctx->width; frame->size.h = st->ctx->height; + +#if LIBAVCODEC_VERSION_INT > ((56<<16)+(1<<8)+0) + /* get the framerate of the decoded bitstream */ + fps = av_q2d(st->ctx->framerate); + if (st->fps != fps) { + st->fps = fps; + debug("avcodec: current decoder framerate" + " is %.2f fps\n", fps); + } +#else + (void)fps; +#endif } out: @@ -285,10 +299,11 @@ int decode_h264(struct viddec_state *st, struct vidframe *frame, return err; #if 0 - re_printf("avcodec: decode: %s %s type=%2d \n", + re_printf("avcodec: decode: %s %s type=%2d %s \n", marker ? "[M]" : " ", h264_is_keyframe(h264_hdr.type) ? "<KEY>" : " ", - h264_hdr.type); + h264_hdr.type, + h264_nalunit_name(h264_hdr.type)); #endif if (h264_hdr.f) { @@ -329,8 +344,8 @@ int decode_h264(struct viddec_state *st, struct vidframe *frame, if (fu.s) { if (st->frag) { - debug("avcodec: lost fragments;" - " ignoring NAL\n"); + debug("avcodec: start: lost fragments;" + " ignoring previous NAL\n"); fragment_rewind(st); ++st->stats.n_lost; } @@ -349,7 +364,8 @@ int decode_h264(struct viddec_state *st, struct vidframe *frame, } else { if (!st->frag) { - debug("avcodec: ignoring fragment\n"); + debug("avcodec: ignoring fragment" + " (nal=%u)\n", fu.type); ++st->stats.n_lost; return 0; } diff --git a/modules/avcodec/encode.c b/modules/avcodec/encode.c index d0d5d83..ea543d8 100644 --- a/modules/avcodec/encode.c +++ b/modules/avcodec/encode.c @@ -20,9 +20,8 @@ #include "avcodec.h" -#if LIBAVUTIL_VERSION_MAJOR < 52 -#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P -#define AV_PIX_FMT_NV12 PIX_FMT_NV12 +#ifndef AV_INPUT_BUFFER_MIN_SIZE +#define AV_INPUT_BUFFER_MIN_SIZE FF_MIN_BUFFER_SIZE #endif @@ -341,7 +340,7 @@ static void param_handler(const struct pl *name, const struct pl *val, } -static int general_packetize(uint32_t rtp_ts, struct mbuf *mb, size_t pktsize, +static int general_packetize(uint64_t rtp_ts, struct mbuf *mb, size_t pktsize, videnc_packet_h *pkth, void *arg) { int err = 0; @@ -366,7 +365,7 @@ static int general_packetize(uint32_t rtp_ts, struct mbuf *mb, size_t pktsize, static int h263_packetize(struct videnc_state *st, - uint32_t rtp_ts, struct mbuf *mb, + uint64_t rtp_ts, struct mbuf *mb, videnc_packet_h *pkth, void *arg) { struct h263_strm h263_strm; @@ -513,7 +512,7 @@ int encode_update(struct videnc_state **vesp, const struct vidcodec *vc, goto out; } - st->mb = mbuf_alloc(FF_MIN_BUFFER_SIZE * 20); + st->mb = mbuf_alloc(AV_INPUT_BUFFER_MIN_SIZE * 20); st->mb_frag = mbuf_alloc(1024); if (!st->mb || !st->mb_frag) { err = ENOMEM; @@ -542,7 +541,7 @@ int encode_update(struct videnc_state **vesp, const struct vidcodec *vc, fmt_param_apply(&sdp_fmtp, param_handler, st); } - debug("avcodec: video encoder %s: %d fps, %d bit/s, pktsize=%u\n", + debug("avcodec: video encoder %s: %.2f fps, %d bit/s, pktsize=%u\n", vc->name, prm->fps, prm->bitrate, prm->pktsize); out: @@ -564,7 +563,7 @@ int encode_x264(struct videnc_state *st, bool update, int i_nal; int i, err, ret; int csp, pln; - uint32_t ts; + uint64_t ts; if (!st || !frame) return EINVAL; @@ -581,6 +580,11 @@ int encode_x264(struct videnc_state *st, bool update, pln = 2; break; + case VID_FMT_YUV444P: + csp = X264_CSP_I444; + pln = 3; + break; + default: warning("avcodec: pixel format not supported (%s)\n", vidfmt_name(frame->fmt)); @@ -660,7 +664,7 @@ int encode(struct videnc_state *st, bool update, const struct vidframe *frame) { int i, err, ret; int pix_fmt; - uint32_t ts; + uint64_t ts; if (!st || !frame) return EINVAL; @@ -675,6 +679,10 @@ int encode(struct videnc_state *st, bool update, const struct vidframe *frame) pix_fmt = AV_PIX_FMT_NV12; break; + case VID_FMT_YUV444P: + pix_fmt = AV_PIX_FMT_YUV444P; + break; + default: warning("avcodec: pixel format not supported (%s)\n", vidfmt_name(frame->fmt)); |