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

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

Issue 10832087: Remove VideoDecoderConfig.frame_rate_xxx() & VideoFrame:Get/SetDuration() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more CR comments. Created 8 years, 4 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
« no previous file with comments | « media/filters/gpu_video_decoder.h ('k') | media/filters/video_frame_generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gpu_video_decoder.h" 5 #include "media/filters/gpu_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 18 matching lines...) Expand all
29 29
30 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} 30 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {}
31 31
32 GpuVideoDecoder::BufferPair::BufferPair( 32 GpuVideoDecoder::BufferPair::BufferPair(
33 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b) 33 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b)
34 : shm_buffer(s), buffer(b) { 34 : shm_buffer(s), buffer(b) {
35 } 35 }
36 36
37 GpuVideoDecoder::BufferPair::~BufferPair() {} 37 GpuVideoDecoder::BufferPair::~BufferPair() {}
38 38
39 GpuVideoDecoder::BufferTimeData::BufferTimeData(
40 int32 bbid, base::TimeDelta ts, base::TimeDelta dur)
41 : bitstream_buffer_id(bbid), timestamp(ts), duration(dur) {
42 }
43
44 GpuVideoDecoder::BufferTimeData::~BufferTimeData() {}
45
46 GpuVideoDecoder::GpuVideoDecoder( 39 GpuVideoDecoder::GpuVideoDecoder(
47 MessageLoop* message_loop, 40 MessageLoop* message_loop,
48 MessageLoop* vda_loop, 41 MessageLoop* vda_loop,
49 const scoped_refptr<Factories>& factories) 42 const scoped_refptr<Factories>& factories)
50 : gvd_loop_proxy_(message_loop->message_loop_proxy()), 43 : gvd_loop_proxy_(message_loop->message_loop_proxy()),
51 vda_loop_proxy_(vda_loop->message_loop_proxy()), 44 vda_loop_proxy_(vda_loop->message_loop_proxy()),
52 factories_(factories), 45 factories_(factories),
53 state_(kNormal), 46 state_(kNormal),
54 demuxer_read_in_progress_(false), 47 demuxer_read_in_progress_(false),
55 decoder_texture_target_(0), 48 decoder_texture_target_(0),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return; 149 return;
157 } 150 }
158 151
159 demuxer_stream_ = stream; 152 demuxer_stream_ = stream;
160 statistics_cb_ = statistics_cb; 153 statistics_cb_ = statistics_cb;
161 154
162 if (config.codec() == kCodecH264) 155 if (config.codec() == kCodecH264)
163 demuxer_stream_->EnableBitstreamConverter(); 156 demuxer_stream_->EnableBitstreamConverter();
164 157
165 natural_size_ = config.natural_size(); 158 natural_size_ = config.natural_size();
166 config_frame_duration_ = GetFrameDuration(config);
167 159
168 DVLOG(1) << "GpuVideoDecoder::Initialize() succeeded."; 160 DVLOG(1) << "GpuVideoDecoder::Initialize() succeeded.";
169 vda_loop_proxy_->PostTaskAndReply( 161 vda_loop_proxy_->PostTaskAndReply(
170 FROM_HERE, 162 FROM_HERE,
171 base::Bind(&GpuVideoDecoder::SetVDA, this, vda), 163 base::Bind(&GpuVideoDecoder::SetVDA, this, vda),
172 base::Bind(status_cb, PIPELINE_OK)); 164 base::Bind(status_cb, PIPELINE_OK));
173 } 165 }
174 166
175 void GpuVideoDecoder::SetVDA(VideoDecodeAccelerator* vda) { 167 void GpuVideoDecoder::SetVDA(VideoDecodeAccelerator* vda) {
176 DCHECK(vda_loop_proxy_->BelongsToCurrentThread()); 168 DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; 259 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second;
268 DCHECK(inserted); 260 DCHECK(inserted);
269 RecordBufferTimeData(bitstream_buffer, *buffer); 261 RecordBufferTimeData(bitstream_buffer, *buffer);
270 262
271 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( 263 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
272 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); 264 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer));
273 } 265 }
274 266
275 void GpuVideoDecoder::RecordBufferTimeData( 267 void GpuVideoDecoder::RecordBufferTimeData(
276 const BitstreamBuffer& bitstream_buffer, const Buffer& buffer) { 268 const BitstreamBuffer& bitstream_buffer, const Buffer& buffer) {
277 base::TimeDelta duration = buffer.GetDuration();
278 if (duration == base::TimeDelta())
279 duration = config_frame_duration_;
280 input_buffer_time_data_.push_front(BufferTimeData( 269 input_buffer_time_data_.push_front(BufferTimeData(
281 bitstream_buffer.id(), buffer.GetTimestamp(), duration)); 270 bitstream_buffer.id(), buffer.GetTimestamp()));
282 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but 271 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but
283 // that's too small for some pathological B-frame test videos. The cost of 272 // that's too small for some pathological B-frame test videos. The cost of
284 // using too-high a value is low (192 bits per extra slot). 273 // using too-high a value is low (192 bits per extra slot).
285 static const size_t kMaxInputBufferTimeDataSize = 128; 274 static const size_t kMaxInputBufferTimeDataSize = 128;
286 // Pop from the back of the list, because that's the oldest and least likely 275 // Pop from the back of the list, because that's the oldest and least likely
287 // to be useful in the future data. 276 // to be useful in the future data.
288 if (input_buffer_time_data_.size() > kMaxInputBufferTimeDataSize) 277 if (input_buffer_time_data_.size() > kMaxInputBufferTimeDataSize)
289 input_buffer_time_data_.pop_back(); 278 input_buffer_time_data_.pop_back();
290 } 279 }
291 280
292 void GpuVideoDecoder::GetBufferTimeData( 281 base::TimeDelta GpuVideoDecoder::GetBufferTimestamp(int32 id) {
293 int32 id, base::TimeDelta* timestamp, base::TimeDelta* duration) {
294 // If all else fails later, at least we can set a default duration if there
295 // was one in the config.
296 *duration = config_frame_duration_;
297 for (std::list<BufferTimeData>::const_iterator it = 282 for (std::list<BufferTimeData>::const_iterator it =
298 input_buffer_time_data_.begin(); it != input_buffer_time_data_.end(); 283 input_buffer_time_data_.begin(); it != input_buffer_time_data_.end();
299 ++it) { 284 ++it) {
300 if (it->bitstream_buffer_id != id) 285 if (it->first == id)
301 continue; 286 return it->second;
302 *timestamp = it->timestamp;
303 *duration = it->duration;
304 return;
305 } 287 }
306 NOTREACHED() << "Missing bitstreambuffer id: " << id; 288 NOTREACHED() << "Missing bitstreambuffer id: " << id;
289 return kNoTimestamp();
307 } 290 }
308 291
309 const gfx::Size& GpuVideoDecoder::natural_size() { 292 const gfx::Size& GpuVideoDecoder::natural_size() {
310 return natural_size_; 293 return natural_size_;
311 } 294 }
312 295
313 bool GpuVideoDecoder::HasAlpha() const { 296 bool GpuVideoDecoder::HasAlpha() const {
314 return true; 297 return true;
315 } 298 }
316 299
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 std::map<int32, PictureBuffer>::iterator it = 369 std::map<int32, PictureBuffer>::iterator it =
387 picture_buffers_in_decoder_.find(picture.picture_buffer_id()); 370 picture_buffers_in_decoder_.find(picture.picture_buffer_id());
388 if (it == picture_buffers_in_decoder_.end()) { 371 if (it == picture_buffers_in_decoder_.end()) {
389 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); 372 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id();
390 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); 373 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE);
391 return; 374 return;
392 } 375 }
393 const PictureBuffer& pb = it->second; 376 const PictureBuffer& pb = it->second;
394 377
395 // Update frame's timestamp. 378 // Update frame's timestamp.
396 base::TimeDelta timestamp; 379 base::TimeDelta timestamp = GetBufferTimestamp(picture.bitstream_buffer_id());
397 base::TimeDelta duration;
398 GetBufferTimeData(picture.bitstream_buffer_id(), &timestamp, &duration);
399
400 DCHECK(decoder_texture_target_); 380 DCHECK(decoder_texture_target_);
401 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( 381 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture(
402 pb.texture_id(), decoder_texture_target_, pb.size().width(), 382 pb.texture_id(), decoder_texture_target_, pb.size().width(),
403 pb.size().height(), timestamp, duration, 383 pb.size().height(), timestamp,
404 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this, 384 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this,
405 picture.picture_buffer_id()))); 385 picture.picture_buffer_id())));
406 386
407 EnqueueFrameAndTriggerFrameDelivery(frame); 387 EnqueueFrameAndTriggerFrameDelivery(frame);
408 } 388 }
409 389
410 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( 390 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery(
411 const scoped_refptr<VideoFrame>& frame) { 391 const scoped_refptr<VideoFrame>& frame) {
412 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); 392 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread());
413 393
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 547
568 error_occured_ = true; 548 error_occured_ = true;
569 549
570 if (!pending_read_cb_.is_null()) { 550 if (!pending_read_cb_.is_null()) {
571 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); 551 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL);
572 return; 552 return;
573 } 553 }
574 } 554 }
575 555
576 } // namespace media 556 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/gpu_video_decoder.h ('k') | media/filters/video_frame_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698