Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Unified Diff: media/test/ffmpeg_tests/ffmpeg_tests.cc

Issue 10540067: Switch to using avcodec_decode_audio4, avcodec_alloc_context3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tools. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/ffmpeg_video_decoder.cc ('k') | media/tools/media_bench/media_bench.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/test/ffmpeg_tests/ffmpeg_tests.cc
diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc
index 557925f21234d4832202a035c10aca5bc7fcc344..fb62b64f6bfe89437ba4f598a79e4048dca792db 100644
--- a/media/test/ffmpeg_tests/ffmpeg_tests.cc
+++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc
@@ -238,13 +238,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;
@@ -284,20 +289,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()
@@ -307,22 +321,24 @@ 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);
}
if (hash_md5) {
base::MD5Update(
&ctx,
- base::StringPiece(
- reinterpret_cast<const char*>(u8_samples), size_out));
+ base::StringPiece(reinterpret_cast<const char*>(u8_samples),
+ size_out));
}
}
} 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;
@@ -332,8 +348,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) {
« no previous file with comments | « media/filters/ffmpeg_video_decoder.cc ('k') | media/tools/media_bench/media_bench.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698