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

Side by Side Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 113611: Handle end of stream for media... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "media/base/data_buffer.h" 5 #include "media/base/data_buffer.h"
6 #include "media/filters/ffmpeg_audio_decoder.h" 6 #include "media/filters/ffmpeg_audio_decoder.h"
7 #include "media/filters/ffmpeg_common.h" 7 #include "media/filters/ffmpeg_common.h"
8 #include "media/filters/ffmpeg_demuxer.h" 8 #include "media/filters/ffmpeg_demuxer.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 output_buffer, 92 output_buffer,
93 &output_buffer_size, 93 &output_buffer_size,
94 &packet); 94 &packet);
95 95
96 // TODO(ajwong): Consider if kOutputBufferSize should just be an int instead 96 // TODO(ajwong): Consider if kOutputBufferSize should just be an int instead
97 // of a size_t. 97 // of a size_t.
98 if (result < 0 || 98 if (result < 0 ||
99 output_buffer_size < 0 || 99 output_buffer_size < 0 ||
100 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { 100 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) {
101 host_->Error(PIPELINE_ERROR_DECODE); 101 host_->Error(PIPELINE_ERROR_DECODE);
102 } else if (result == 0) { 102 return;
103 // TODO(scherkus): does this mark EOS? Do we want to fulfill a read request 103 }
104 // with zero size? 104
105 } else { 105 // If we have decoded something, enqueue the result.
106 if (output_buffer_size) {
106 DataBuffer* result_buffer = new DataBuffer(); 107 DataBuffer* result_buffer = new DataBuffer();
107 memcpy(result_buffer->GetWritableData(output_buffer_size), 108 memcpy(result_buffer->GetWritableData(output_buffer_size),
108 output_buffer, output_buffer_size); 109 output_buffer, output_buffer_size);
109 110
110 // Determine the duration if the demuxer couldn't figure it out, otherwise 111 // Determine the duration if the demuxer couldn't figure it out, otherwise
111 // copy it over. 112 // copy it over.
112 if (input->GetDuration().InMicroseconds() == 0) { 113 if (input->GetDuration().InMicroseconds() == 0) {
113 result_buffer->SetDuration(CalculateDuration(output_buffer_size)); 114 result_buffer->SetDuration(CalculateDuration(output_buffer_size));
114 } else { 115 } else {
115 result_buffer->SetDuration(input->GetDuration()); 116 result_buffer->SetDuration(input->GetDuration());
116 } 117 }
117 118
118 // Copy over the timestamp. 119 // Copy over the timestamp.
119 result_buffer->SetTimestamp(input->GetTimestamp()); 120 result_buffer->SetTimestamp(input->GetTimestamp());
120 121
121 EnqueueResult(result_buffer); 122 EnqueueResult(result_buffer);
123 return;
124 }
125
126 // Three conditions to meet to declare end of stream for this decoder:
127 // 1. FFmpeg didn't read anything.
128 // 2. FFmpeg didn't output anything.
129 // 3. An end of stream buffer is received.
130 if (result == 0 && output_buffer_size == 0 && input->IsEndOfStream()) {
131 DataBuffer* result_buffer = new DataBuffer();
132 result_buffer->SetTimestamp(input->GetTimestamp());
133 result_buffer->SetDuration(input->GetDuration());
134 EnqueueResult(result_buffer);
122 } 135 }
123 } 136 }
124 137
125 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { 138 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) {
126 int64 denominator = codec_context_->channels * 139 int64 denominator = codec_context_->channels *
127 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * 140 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 *
128 codec_context_->sample_rate; 141 codec_context_->sample_rate;
129 double microseconds = size / 142 double microseconds = size /
130 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); 143 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
131 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); 144 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
132 } 145 }
133 146
134 } // namespace 147 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698