Re: [FFmpeg-devel] [PATCH] Fixes the bug of comparing zero bytes. Also new check for linesize is added.
On Sat, Jun 27, 2015 at 02:01:15AM +0300, Ludmila Glinskih wrote: --- libavcodec/api-flac-test.c | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libavcodec/api-flac-test.c b/libavcodec/api-flac-test.c index 402d4df..4cd0db7 100644 --- a/libavcodec/api-flac-test.c +++ b/libavcodec/api-flac-test.c @@ -112,10 +112,10 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, AVFrame *in_frame, *out_frame; uint8_t *raw_in = NULL, *raw_out = NULL; int in_offset = 0, out_offset = 0; -int frame_data_size = 0; int result = 0; int got_output = 0; int i = 0; +int in_frame_bytes, out_frame_bytes; in_frame = av_frame_alloc(); if (!in_frame) { @@ -156,8 +156,13 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, generate_raw_frame((uint16_t*)(in_frame-data[0]), i, enc_ctx-sample_rate, enc_ctx-channels, enc_ctx-frame_size); -memcpy(raw_in + in_offset, in_frame-data[0], in_frame-linesize[0]); -in_offset += in_frame-linesize[0]; +in_frame_bytes = in_frame-nb_samples * in_frame-channels * sizeof(uint16_t); +if (in_frame_bytes != in_frame-linesize[0]) { +av_log(NULL, AV_LOG_ERROR, Incorrect value of input frame linesize\n); +return 1; +} The linesize is not guranteed to match the active area i think you can just ignore the linesize completely or if you like check that it is = in_frame_bytes +memcpy(raw_in + in_offset, in_frame-data[0], in_frame_bytes); +in_offset += in_frame_bytes; result = avcodec_encode_audio2(enc_ctx, enc_pkt, in_frame, got_output); if (result 0) { av_log(NULL, AV_LOG_ERROR, Error encoding audio frame\n); @@ -192,14 +197,19 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, av_log(NULL, AV_LOG_ERROR, Error frames before and after decoding has different sample format\n); return AVERROR_UNKNOWN; } -memcpy(raw_out + out_offset, out_frame-data[0], out_frame-linesize[0]); -out_offset += out_frame-linesize[0]; +out_frame_bytes = out_frame-nb_samples * out_frame-channels * sizeof(uint16_t); AVFrame.channels should e accessed through av_frame_get_channels() libavutil/frame.h lists which AVFrame fields can be accessed directly from outide avutil [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Fixes the bug of comparing zero bytes. Also new check for linesize is added.
--- libavcodec/api-flac-test.c | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libavcodec/api-flac-test.c b/libavcodec/api-flac-test.c index 402d4df..4cd0db7 100644 --- a/libavcodec/api-flac-test.c +++ b/libavcodec/api-flac-test.c @@ -112,10 +112,10 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, AVFrame *in_frame, *out_frame; uint8_t *raw_in = NULL, *raw_out = NULL; int in_offset = 0, out_offset = 0; -int frame_data_size = 0; int result = 0; int got_output = 0; int i = 0; +int in_frame_bytes, out_frame_bytes; in_frame = av_frame_alloc(); if (!in_frame) { @@ -156,8 +156,13 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, generate_raw_frame((uint16_t*)(in_frame-data[0]), i, enc_ctx-sample_rate, enc_ctx-channels, enc_ctx-frame_size); -memcpy(raw_in + in_offset, in_frame-data[0], in_frame-linesize[0]); -in_offset += in_frame-linesize[0]; +in_frame_bytes = in_frame-nb_samples * in_frame-channels * sizeof(uint16_t); +if (in_frame_bytes != in_frame-linesize[0]) { +av_log(NULL, AV_LOG_ERROR, Incorrect value of input frame linesize\n); +return 1; +} +memcpy(raw_in + in_offset, in_frame-data[0], in_frame_bytes); +in_offset += in_frame_bytes; result = avcodec_encode_audio2(enc_ctx, enc_pkt, in_frame, got_output); if (result 0) { av_log(NULL, AV_LOG_ERROR, Error encoding audio frame\n); @@ -192,14 +197,19 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, av_log(NULL, AV_LOG_ERROR, Error frames before and after decoding has different sample format\n); return AVERROR_UNKNOWN; } -memcpy(raw_out + out_offset, out_frame-data[0], out_frame-linesize[0]); -out_offset += out_frame-linesize[0]; +out_frame_bytes = out_frame-nb_samples * out_frame-channels * sizeof(uint16_t); +if (out_frame_bytes out_frame-linesize[0]) { +av_log(NULL, AV_LOG_ERROR, Incorrect value of output frame linesize\n); +return 1; +} +memcpy(raw_out + out_offset, out_frame-data[0], out_frame_bytes); +out_offset += out_frame_bytes; } } av_free_packet(enc_pkt); } -if (memcmp(raw_in, raw_out, frame_data_size * NUMBER_OF_FRAMES) != 0) { +if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_FRAMES) != 0) { av_log(NULL, AV_LOG_ERROR, Output differs\n); return 1; } -- 1.9.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel