core: always pass data via packet fields to video decoders

Makes the code a bit simpler to follow, at least in the "modern"
decoding path (update_video_nocorrect_pts() is used with old demuxers,
which don't return proper packets and need further parsing, so this code
looks less simple now).
This commit is contained in:
wm4 2013-03-28 20:16:11 +01:00
parent ac1c5e6e18
commit 3374a43998
5 changed files with 20 additions and 26 deletions

View File

@ -2437,9 +2437,13 @@ static double update_video_nocorrect_pts(struct MPContext *mpctx)
update_fps(mpctx); update_fps(mpctx);
int framedrop_type = check_framedrop(mpctx, frame_time); int framedrop_type = check_framedrop(mpctx, frame_time);
void *decoded_frame; struct demux_packet pkt = {0};
decoded_frame = decode_video(sh_video, sh_video->ds->current, packet, if (sh_video->ds->current)
in_size, framedrop_type, sh_video->pts); pkt = *sh_video->ds->current;
pkt.buffer = packet;
pkt.len = in_size;
void *decoded_frame = decode_video(sh_video, &pkt, framedrop_type,
sh_video->pts);
if (decoded_frame) { if (decoded_frame) {
filter_video(mpctx, decoded_frame); filter_video(mpctx, decoded_frame);
} }
@ -2495,8 +2499,6 @@ static double update_video(struct MPContext *mpctx)
break; break;
if (filter_output_queued_frame(mpctx)) if (filter_output_queued_frame(mpctx))
break; break;
int in_size = 0;
unsigned char *buf = NULL;
pts = MP_NOPTS_VALUE; pts = MP_NOPTS_VALUE;
struct demux_packet *pkt; struct demux_packet *pkt;
while (1) { while (1) {
@ -2507,11 +2509,8 @@ static double update_video(struct MPContext *mpctx)
* but to indicate the absence of a frame in formats like AVI * but to indicate the absence of a frame in formats like AVI
* that must have packets at fixed timecode intervals. */ * that must have packets at fixed timecode intervals. */
} }
if (pkt) { if (pkt)
in_size = pkt->len;
buf = pkt->buffer;
pts = pkt->pts; pts = pkt->pts;
}
if (pts != MP_NOPTS_VALUE) if (pts != MP_NOPTS_VALUE)
pts += mpctx->video_offset; pts += mpctx->video_offset;
if (pts >= mpctx->hrseek_pts - .005) if (pts >= mpctx->hrseek_pts - .005)
@ -2519,7 +2518,7 @@ static double update_video(struct MPContext *mpctx)
int framedrop_type = mpctx->hrseek_framedrop ? 1 : int framedrop_type = mpctx->hrseek_framedrop ? 1 :
check_framedrop(mpctx, sh_video->frametime); check_framedrop(mpctx, sh_video->frametime);
struct mp_image *decoded_frame = struct mp_image *decoded_frame =
decode_video(sh_video, pkt, buf, in_size, framedrop_type, pts); decode_video(sh_video, pkt, framedrop_type, pts);
if (decoded_frame) { if (decoded_frame) {
determine_frame_pts(mpctx); determine_frame_pts(mpctx);
filter_video(mpctx, decoded_frame); filter_video(mpctx, decoded_frame);

View File

@ -275,7 +275,6 @@ int init_best_video_codec(sh_video_t *sh_video, char* video_decoders)
} }
void *decode_video(sh_video_t *sh_video, struct demux_packet *packet, void *decode_video(sh_video_t *sh_video, struct demux_packet *packet,
unsigned char *start, int in_size,
int drop_frame, double pts) int drop_frame, double pts)
{ {
mp_image_t *mpi = NULL; mp_image_t *mpi = NULL;
@ -311,8 +310,7 @@ void *decode_video(sh_video_t *sh_video, struct demux_packet *packet,
} }
} }
mpi = sh_video->vd_driver->decode(sh_video, packet, start, in_size, mpi = sh_video->vd_driver->decode(sh_video, packet, drop_frame, &pts);
drop_frame, &pts);
//------------------------ frame decoded. -------------------- //------------------------ frame decoded. --------------------

View File

@ -31,8 +31,7 @@ void uninit_video(sh_video_t *sh_video);
struct demux_packet; struct demux_packet;
void *decode_video(sh_video_t *sh_video, struct demux_packet *packet, void *decode_video(sh_video_t *sh_video, struct demux_packet *packet,
unsigned char *start, int in_size, int drop_frame, int drop_frame, double pts);
double pts);
int get_video_quality_max(sh_video_t *sh_video); int get_video_quality_max(sh_video_t *sh_video);

View File

@ -34,8 +34,7 @@ typedef struct vd_functions
void (*uninit)(sh_video_t *sh); void (*uninit)(sh_video_t *sh);
int (*control)(sh_video_t *sh, int cmd, void *arg); int (*control)(sh_video_t *sh, int cmd, void *arg);
struct mp_image *(*decode)(struct sh_video *sh, struct demux_packet *pkt, struct mp_image *(*decode)(struct sh_video *sh, struct demux_packet *pkt,
void *data, int len, int flags, int flags, double *reordered_pts);
double *reordered_pts);
} vd_functions_t; } vd_functions_t;
// NULL terminated array of all drivers // NULL terminated array of all drivers

View File

@ -636,9 +636,8 @@ static struct mp_image *image_from_decoder(struct sh_video *sh)
#endif /* HAVE_AVUTIL_REFCOUNTING */ #endif /* HAVE_AVUTIL_REFCOUNTING */
static int decode(struct sh_video *sh, struct demux_packet *packet, void *data, static int decode(struct sh_video *sh, struct demux_packet *packet,
int len, int flags, double *reordered_pts, int flags, double *reordered_pts, struct mp_image **out_image)
struct mp_image **out_image)
{ {
int got_picture = 0; int got_picture = 0;
int ret; int ret;
@ -655,8 +654,8 @@ static int decode(struct sh_video *sh, struct demux_packet *packet, void *data,
avctx->skip_frame = ctx->skip_frame; avctx->skip_frame = ctx->skip_frame;
av_init_packet(&pkt); av_init_packet(&pkt);
pkt.data = data; pkt.data = packet ? packet->buffer : NULL;
pkt.size = len; pkt.size = packet ? packet->len : 0;
/* Some codecs (ZeroCodec, some cases of PNG) may want keyframe info /* Some codecs (ZeroCodec, some cases of PNG) may want keyframe info
* from demuxer. */ * from demuxer. */
if (packet && packet->keyframe) if (packet && packet->keyframe)
@ -692,15 +691,15 @@ static int decode(struct sh_video *sh, struct demux_packet *packet, void *data,
} }
static struct mp_image *decode_with_fallback(struct sh_video *sh, static struct mp_image *decode_with_fallback(struct sh_video *sh,
struct demux_packet *packet, void *data, struct demux_packet *packet,
int len, int flags, double *reordered_pts) int flags, double *reordered_pts)
{ {
vd_ffmpeg_ctx *ctx = sh->context; vd_ffmpeg_ctx *ctx = sh->context;
if (!ctx->avctx) if (!ctx->avctx)
return NULL; return NULL;
struct mp_image *mpi = NULL; struct mp_image *mpi = NULL;
int res = decode(sh, packet, data, len, flags, reordered_pts, &mpi); int res = decode(sh, packet, flags, reordered_pts, &mpi);
if (res >= 0) if (res >= 0)
return mpi; return mpi;
@ -714,7 +713,7 @@ static struct mp_image *decode_with_fallback(struct sh_video *sh,
ctx->software_fallback_decoder = NULL; ctx->software_fallback_decoder = NULL;
if (init_avctx(sh, decoder, NULL)) { if (init_avctx(sh, decoder, NULL)) {
mpi = NULL; mpi = NULL;
decode(sh, packet, data, len, flags, reordered_pts, &mpi); decode(sh, packet, flags, reordered_pts, &mpi);
return mpi; return mpi;
} }
} }