| Index: media/tools/media_bench/media_bench.cc
|
| diff --git a/media/tools/media_bench/media_bench.cc b/media/tools/media_bench/media_bench.cc
|
| index 532aa7d493e61398f121fa8cfbbd695c228a74ff..abba5f0c51c6c072ed0a17d3efa242a2a4870c74 100644
|
| --- a/media/tools/media_bench/media_bench.cc
|
| +++ b/media/tools/media_bench/media_bench.cc
|
| @@ -357,13 +357,18 @@ int main(int argc, const char** argv) {
|
| }
|
|
|
| // Buffer used for audio decoding.
|
| - scoped_ptr_malloc<int16, media::ScopedPtrAVFree> samples(
|
| - reinterpret_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE)));
|
| + scoped_ptr_malloc<AVFrame, media::ScopedPtrAVFree> audio_frame(
|
| + avcodec_alloc_frame());
|
| + if (!audio_frame.get()) {
|
| + std::cerr << "Error: avcodec_alloc_frame for "
|
| + << in_path.value() << std::endl;
|
| + return 1;
|
| + }
|
|
|
| // Buffer used for video decoding.
|
| - scoped_ptr_malloc<AVFrame, media::ScopedPtrAVFree> frame(
|
| + scoped_ptr_malloc<AVFrame, media::ScopedPtrAVFree> video_frame(
|
| avcodec_alloc_frame());
|
| - if (!frame.get()) {
|
| + if (!video_frame.get()) {
|
| std::cerr << "Error: avcodec_alloc_frame for "
|
| << in_path.value() << std::endl;
|
| return 1;
|
| @@ -405,20 +410,29 @@ int main(int argc, const char** argv) {
|
| if (packet.stream_index == target_stream) {
|
| int result = -1;
|
| if (target_codec == AVMEDIA_TYPE_AUDIO) {
|
| - int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE;
|
| + int size_out = 0;
|
| + int got_audio = 0;
|
| +
|
| + avcodec_get_frame_defaults(audio_frame.get());
|
|
|
| base::TimeTicks decode_start = base::TimeTicks::HighResNow();
|
| - result = avcodec_decode_audio3(codec_context, samples.get(), &size_out,
|
| - &packet);
|
| + result = avcodec_decode_audio4(codec_context, audio_frame.get(),
|
| + &got_audio, &packet);
|
| base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start;
|
|
|
| - if (size_out) {
|
| + if (got_audio) {
|
| + size_out = av_samples_get_buffer_size(
|
| + NULL, codec_context->channels, audio_frame->nb_samples,
|
| + codec_context->sample_fmt, 1);
|
| + }
|
| +
|
| + if (got_audio && size_out) {
|
| decode_times.push_back(delta.InMillisecondsF());
|
| ++frames;
|
| read_result = 0; // Force continuation.
|
|
|
| if (output) {
|
| - if (fwrite(samples.get(), 1, size_out, output) !=
|
| + if (fwrite(audio_frame->data[0], 1, size_out, output) !=
|
| static_cast<size_t>(size_out)) {
|
| std::cerr << "Error: Could not write "
|
| << size_out << " bytes for " << in_path.value()
|
| @@ -428,7 +442,7 @@ int main(int argc, const char** argv) {
|
| }
|
|
|
| const uint8* u8_samples =
|
| - reinterpret_cast<const uint8*>(samples.get());
|
| + reinterpret_cast<const uint8*>(audio_frame->data[0]);
|
| if (hash_djb2) {
|
| hash_value = DJB2Hash(u8_samples, size_out, hash_value);
|
| }
|
| @@ -442,8 +456,10 @@ int main(int argc, const char** argv) {
|
| } else if (target_codec == AVMEDIA_TYPE_VIDEO) {
|
| int got_picture = 0;
|
|
|
| + avcodec_get_frame_defaults(video_frame.get());
|
| +
|
| base::TimeTicks decode_start = base::TimeTicks::HighResNow();
|
| - result = avcodec_decode_video2(codec_context, frame.get(),
|
| + result = avcodec_decode_video2(codec_context, video_frame.get(),
|
| &got_picture, &packet);
|
| base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start;
|
|
|
| @@ -453,8 +469,8 @@ int main(int argc, const char** argv) {
|
| read_result = 0; // Force continuation.
|
|
|
| for (int plane = 0; plane < 3; ++plane) {
|
| - const uint8* source = frame->data[plane];
|
| - const size_t source_stride = frame->linesize[plane];
|
| + const uint8* source = video_frame->data[plane];
|
| + const size_t source_stride = video_frame->linesize[plane];
|
| size_t bytes_per_line = codec_context->width;
|
| size_t copy_lines = codec_context->height;
|
| if (plane != 0) {
|
|
|