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

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

Issue 149573: Refactor WritableBuffer interface for more useful ptr management. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // of a size_t. 100 // of a size_t.
101 if (result < 0 || 101 if (result < 0 ||
102 output_buffer_size < 0 || 102 output_buffer_size < 0 ||
103 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { 103 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) {
104 host()->Error(PIPELINE_ERROR_DECODE); 104 host()->Error(PIPELINE_ERROR_DECODE);
105 return; 105 return;
106 } 106 }
107 107
108 // If we have decoded something, enqueue the result. 108 // If we have decoded something, enqueue the result.
109 if (output_buffer_size) { 109 if (output_buffer_size) {
110 DataBuffer* result_buffer = new DataBuffer(); 110 DataBuffer* result_buffer = new DataBuffer(output_buffer_size);
111 memcpy(result_buffer->GetWritableData(output_buffer_size), 111 uint8* data = result_buffer->GetWritableData();
112 output_buffer, output_buffer_size); 112 memcpy(data, output_buffer, output_buffer_size);
113 113
114 // Determine the duration if the demuxer couldn't figure it out, otherwise 114 // Determine the duration if the demuxer couldn't figure it out, otherwise
115 // copy it over. 115 // copy it over.
116 if (input->GetDuration().InMicroseconds() == 0) { 116 if (input->GetDuration().InMicroseconds() == 0) {
117 result_buffer->SetDuration(CalculateDuration(output_buffer_size)); 117 result_buffer->SetDuration(CalculateDuration(output_buffer_size));
118 } else { 118 } else {
119 result_buffer->SetDuration(input->GetDuration()); 119 result_buffer->SetDuration(input->GetDuration());
120 } 120 }
121 121
122 // Copy over the timestamp. 122 // Copy over the timestamp.
123 result_buffer->SetTimestamp(input->GetTimestamp()); 123 result_buffer->SetTimestamp(input->GetTimestamp());
124 124
125 EnqueueResult(result_buffer); 125 EnqueueResult(result_buffer);
126 return; 126 return;
127 } 127 }
128 128
129 // Three conditions to meet to declare end of stream for this decoder: 129 // Three conditions to meet to declare end of stream for this decoder:
130 // 1. FFmpeg didn't read anything. 130 // 1. FFmpeg didn't read anything.
131 // 2. FFmpeg didn't output anything. 131 // 2. FFmpeg didn't output anything.
132 // 3. An end of stream buffer is received. 132 // 3. An end of stream buffer is received.
133 if (result == 0 && output_buffer_size == 0 && input->IsEndOfStream()) { 133 if (result == 0 && output_buffer_size == 0 && input->IsEndOfStream()) {
134 DataBuffer* result_buffer = new DataBuffer(); 134 DataBuffer* result_buffer = new DataBuffer(0);
135 result_buffer->SetTimestamp(input->GetTimestamp()); 135 result_buffer->SetTimestamp(input->GetTimestamp());
136 result_buffer->SetDuration(input->GetDuration()); 136 result_buffer->SetDuration(input->GetDuration());
137 EnqueueResult(result_buffer); 137 EnqueueResult(result_buffer);
138 } 138 }
139 } 139 }
140 140
141 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { 141 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) {
142 int64 denominator = codec_context_->channels * 142 int64 denominator = codec_context_->channels *
143 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * 143 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 *
144 codec_context_->sample_rate; 144 codec_context_->sample_rate;
145 double microseconds = size / 145 double microseconds = size /
146 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); 146 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
147 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); 147 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
148 } 148 }
149 149
150 } // namespace 150 } // namespace
OLDNEW
« no previous file with comments | « media/filters/audio_renderer_algorithm_ola.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698