| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/audio_file_reader.h" | 5 #include "media/filters/audio_file_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 DCHECK(glue_.get() && codec_context_) << | 127 DCHECK(glue_.get() && codec_context_) << |
| 128 "AudioFileReader::Read() : reader is not opened!"; | 128 "AudioFileReader::Read() : reader is not opened!"; |
| 129 | 129 |
| 130 DCHECK_EQ(audio_bus->channels(), channels()); | 130 DCHECK_EQ(audio_bus->channels(), channels()); |
| 131 if (audio_bus->channels() != channels()) | 131 if (audio_bus->channels() != channels()) |
| 132 return 0; | 132 return 0; |
| 133 | 133 |
| 134 size_t bytes_per_sample = av_get_bytes_per_sample(codec_context_->sample_fmt); | 134 size_t bytes_per_sample = av_get_bytes_per_sample(codec_context_->sample_fmt); |
| 135 | 135 |
| 136 // Holds decoded audio. | 136 // Holds decoded audio. |
| 137 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame(av_frame_alloc()); | 137 std::unique_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame(av_frame_alloc()); |
| 138 | 138 |
| 139 // Read until we hit EOF or we've read the requested number of frames. | 139 // Read until we hit EOF or we've read the requested number of frames. |
| 140 AVPacket packet; | 140 AVPacket packet; |
| 141 int current_frame = 0; | 141 int current_frame = 0; |
| 142 bool continue_decoding = true; | 142 bool continue_decoding = true; |
| 143 | 143 |
| 144 while (current_frame < audio_bus->frames() && continue_decoding && | 144 while (current_frame < audio_bus->frames() && continue_decoding && |
| 145 ReadPacket(&packet)) { | 145 ReadPacket(&packet)) { |
| 146 // Make a shallow copy of packet so we can slide packet.data as frames are | 146 // Make a shallow copy of packet so we can slide packet.data as frames are |
| 147 // decoded from the packet; otherwise av_packet_unref() will corrupt memory. | 147 // decoded from the packet; otherwise av_packet_unref() will corrupt memory. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 stream_index_, | 299 stream_index_, |
| 300 ConvertToTimeBase(codec_context_->time_base, seek_time), | 300 ConvertToTimeBase(codec_context_->time_base, seek_time), |
| 301 AVSEEK_FLAG_BACKWARD) >= 0; | 301 AVSEEK_FLAG_BACKWARD) >= 0; |
| 302 } | 302 } |
| 303 | 303 |
| 304 const AVStream* AudioFileReader::GetAVStreamForTesting() const { | 304 const AVStream* AudioFileReader::GetAVStreamForTesting() const { |
| 305 return glue_->format_context()->streams[stream_index_]; | 305 return glue_->format_context()->streams[stream_index_]; |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace media | 308 } // namespace media |
| OLD | NEW |