| 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/ffmpeg_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DCHECK(!*has_produced_frame); | 179 DCHECK(!*has_produced_frame); |
| 180 | 180 |
| 181 AVPacket packet; | 181 AVPacket packet; |
| 182 av_init_packet(&packet); | 182 av_init_packet(&packet); |
| 183 if (buffer->end_of_stream()) { | 183 if (buffer->end_of_stream()) { |
| 184 packet.data = NULL; | 184 packet.data = NULL; |
| 185 packet.size = 0; | 185 packet.size = 0; |
| 186 } else { | 186 } else { |
| 187 packet.data = const_cast<uint8_t*>(buffer->data()); | 187 packet.data = const_cast<uint8_t*>(buffer->data()); |
| 188 packet.size = buffer->data_size(); | 188 packet.size = buffer->data_size(); |
| 189 |
| 190 // Since we're not at EOS and there is no data available in the current |
| 191 // buffer, simply return and let the caller provide more data. |
| 192 // crbug.com/663438 has more context on 0-byte buffers. |
| 193 if (!packet.size) |
| 194 return true; |
| 189 } | 195 } |
| 190 | 196 |
| 191 // Each audio packet may contain several frames, so we must call the decoder | 197 // Each audio packet may contain several frames, so we must call the decoder |
| 192 // until we've exhausted the packet. Regardless of the packet size we always | 198 // until we've exhausted the packet. Regardless of the packet size we always |
| 193 // want to hand it to the decoder at least once, otherwise we would end up | 199 // want to hand it to the decoder at least once, otherwise we would end up |
| 194 // skipping end of stream packets since they have a size of zero. | 200 // skipping end of stream packets since they have a size of zero. |
| 195 do { | 201 do { |
| 196 int frame_decoded = 0; | 202 int frame_decoded = 0; |
| 197 const int result = avcodec_decode_audio4( | 203 const int result = avcodec_decode_audio4( |
| 198 codec_context_.get(), av_frame_.get(), &frame_decoded, &packet); | 204 codec_context_.get(), av_frame_.get(), &frame_decoded, &packet); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // Now create an AVBufferRef for the data just allocated. It will own the | 457 // Now create an AVBufferRef for the data just allocated. It will own the |
| 452 // reference to the AudioBuffer object. | 458 // reference to the AudioBuffer object. |
| 453 AudioBuffer* opaque = buffer.get(); | 459 AudioBuffer* opaque = buffer.get(); |
| 454 opaque->AddRef(); | 460 opaque->AddRef(); |
| 455 frame->buf[0] = av_buffer_create(frame->data[0], buffer_size_in_bytes, | 461 frame->buf[0] = av_buffer_create(frame->data[0], buffer_size_in_bytes, |
| 456 ReleaseAudioBufferImpl, opaque, 0); | 462 ReleaseAudioBufferImpl, opaque, 0); |
| 457 return 0; | 463 return 0; |
| 458 } | 464 } |
| 459 | 465 |
| 460 } // namespace media | 466 } // namespace media |
| OLD | NEW |