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

Side by Side Diff: content/renderer/media/rtc_video_encoder.cc

Issue 22935009: Add content::SurfaceCapturer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screencast_stride
Patch Set: cff149b4 WIP Created 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/rtc_video_encoder.h" 5 #include "content/renderer/media/rtc_video_encoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 << ", output_buffer_size=" << output_buffer_size; 261 << ", output_buffer_size=" << output_buffer_size;
262 DCHECK(thread_checker_.CalledOnValidThread()); 262 DCHECK(thread_checker_.CalledOnValidThread());
263 263
264 if (!video_encoder_) 264 if (!video_encoder_)
265 return; 265 return;
266 266
267 input_frame_coded_size_ = input_coded_size; 267 input_frame_coded_size_ = input_coded_size;
268 268
269 for (unsigned int i = 0; i < input_count + kInputBufferExtraCount; ++i) { 269 for (unsigned int i = 0; i < input_count + kInputBufferExtraCount; ++i) {
270 base::SharedMemory* shm = 270 base::SharedMemory* shm =
271 gpu_factories_->CreateSharedMemory(input_coded_size.GetArea() * 3 / 2); 271 gpu_factories_->CreateSharedMemory(
272 media::VideoFrame::AllocationSize(media::VideoFrame::I420,
273 input_coded_size));
272 if (!shm) { 274 if (!shm) {
273 DLOG(ERROR) << "Impl::RequireBitstreamBuffers(): " 275 DLOG(ERROR) << "Impl::RequireBitstreamBuffers(): "
274 "failed to create input buffer " << i; 276 "failed to create input buffer " << i;
275 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError); 277 NOTIFY_ERROR(media::VideoEncodeAccelerator::kPlatformFailureError);
276 return; 278 return;
277 } 279 }
278 input_buffers_.push_back(shm); 280 input_buffers_.push_back(shm);
279 input_buffers_free_.push_back(i); 281 input_buffers_free_.push_back(i);
280 } 282 }
281 283
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 dst += width; 429 dst += width;
428 } 430 }
429 431
430 scoped_refptr<media::VideoFrame> frame = 432 scoped_refptr<media::VideoFrame> frame =
431 media::VideoFrame::WrapExternalSharedMemory( 433 media::VideoFrame::WrapExternalSharedMemory(
432 media::VideoFrame::I420, 434 media::VideoFrame::I420,
433 input_frame_coded_size_, 435 input_frame_coded_size_,
434 gfx::Rect(input_visible_size_), 436 gfx::Rect(input_visible_size_),
435 input_visible_size_, 437 input_visible_size_,
436 y_dst, 438 y_dst,
439 dst - y_dst,
437 input_buffer->handle(), 440 input_buffer->handle(),
438 base::TimeDelta(), 441 base::TimeDelta(),
439 base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index)); 442 base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index));
440 443
441 video_encoder_->Encode(frame, next_frame_keyframe); 444 video_encoder_->Encode(frame, next_frame_keyframe);
442 input_buffers_free_.pop_back(); 445 input_buffers_free_.pop_back();
443 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK); 446 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK);
444 } 447 }
445 448
446 void RTCVideoEncoder::Impl::EncodeFrameFinished(int index) { 449 void RTCVideoEncoder::Impl::EncodeFrameFinished(int index) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // 481 //
479 //////////////////////////////////////////////////////////////////////////////// 482 ////////////////////////////////////////////////////////////////////////////////
480 483
481 RTCVideoEncoder::RTCVideoEncoder( 484 RTCVideoEncoder::RTCVideoEncoder(
482 webrtc::VideoCodecType type, 485 webrtc::VideoCodecType type,
483 media::VideoCodecProfile profile, 486 media::VideoCodecProfile profile,
484 const scoped_refptr<RendererGpuVideoAcceleratorFactories>& gpu_factories) 487 const scoped_refptr<RendererGpuVideoAcceleratorFactories>& gpu_factories)
485 : video_codec_type_(type), 488 : video_codec_type_(type),
486 video_codec_profile_(profile), 489 video_codec_profile_(profile),
487 gpu_factories_(gpu_factories), 490 gpu_factories_(gpu_factories),
491 weak_this_factory_(this),
488 encoded_image_callback_(NULL), 492 encoded_image_callback_(NULL),
489 impl_status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) { 493 impl_status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) {
490 DVLOG(1) << "RTCVideoEncoder(): profile=" << profile; 494 DVLOG(1) << "RTCVideoEncoder(): profile=" << profile;
491 } 495 }
492 496
493 RTCVideoEncoder::~RTCVideoEncoder() { 497 RTCVideoEncoder::~RTCVideoEncoder() {
494 DCHECK(thread_checker_.CalledOnValidThread()); 498 DCHECK(thread_checker_.CalledOnValidThread());
495 Release(); 499 Release();
496 DCHECK(!impl_); 500 DCHECK(!impl_);
497 } 501 }
498 502
499 int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, 503 int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings,
500 int32_t number_of_cores, 504 int32_t number_of_cores,
501 uint32_t max_payload_size) { 505 uint32_t max_payload_size) {
502 DVLOG(1) << "InitEncode(): codecType=" << codec_settings->codecType 506 DVLOG(1) << "InitEncode(): codecType=" << codec_settings->codecType
503 << ", width=" << codec_settings->width 507 << ", width=" << codec_settings->width
504 << ", height=" << codec_settings->height 508 << ", height=" << codec_settings->height
505 << ", startBitrate=" << codec_settings->startBitrate; 509 << ", startBitrate=" << codec_settings->startBitrate;
506 DCHECK(thread_checker_.CalledOnValidThread()); 510 DCHECK(thread_checker_.CalledOnValidThread());
507 DCHECK(!impl_); 511 DCHECK(!impl_);
508 512
509 weak_this_factory_.reset(new base::WeakPtrFactory<RTCVideoEncoder>(this)); 513 weak_this_factory_.InvalidateWeakPtrs();
510 impl_ = new Impl(weak_this_factory_->GetWeakPtr(), gpu_factories_); 514 impl_ = new Impl(weak_this_factory_.GetWeakPtr(), gpu_factories_);
511 base::WaitableEvent initialization_waiter(true, false); 515 base::WaitableEvent initialization_waiter(true, false);
512 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; 516 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED;
513 gpu_factories_->GetMessageLoop()->PostTask( 517 gpu_factories_->GetMessageLoop()->PostTask(
514 FROM_HERE, 518 FROM_HERE,
515 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA, 519 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA,
516 impl_, 520 impl_,
517 gfx::Size(codec_settings->width, codec_settings->height), 521 gfx::Size(codec_settings->width, codec_settings->height),
518 codec_settings->startBitrate, 522 codec_settings->startBitrate,
519 video_codec_profile_, 523 video_codec_profile_,
520 &initialization_waiter, 524 &initialization_waiter,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 DVLOG(3) << "Release()"; 575 DVLOG(3) << "Release()";
572 DCHECK(thread_checker_.CalledOnValidThread()); 576 DCHECK(thread_checker_.CalledOnValidThread());
573 577
574 // Reset the gpu_factory_, in case we reuse this encoder. 578 // Reset the gpu_factory_, in case we reuse this encoder.
575 gpu_factories_->Abort(); 579 gpu_factories_->Abort();
576 gpu_factories_ = gpu_factories_->Clone(); 580 gpu_factories_ = gpu_factories_->Clone();
577 if (impl_) { 581 if (impl_) {
578 gpu_factories_->GetMessageLoop()->PostTask( 582 gpu_factories_->GetMessageLoop()->PostTask(
579 FROM_HERE, base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_)); 583 FROM_HERE, base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_));
580 impl_ = NULL; 584 impl_ = NULL;
581 weak_this_factory_.reset(); 585 weak_this_factory_.InvalidateWeakPtrs();
582 impl_status_ = WEBRTC_VIDEO_CODEC_UNINITIALIZED; 586 impl_status_ = WEBRTC_VIDEO_CODEC_UNINITIALIZED;
583 } 587 }
584 return WEBRTC_VIDEO_CODEC_OK; 588 return WEBRTC_VIDEO_CODEC_OK;
585 } 589 }
586 590
587 int32_t RTCVideoEncoder::SetChannelParameters(uint32_t packet_loss, int rtt) { 591 int32_t RTCVideoEncoder::SetChannelParameters(uint32_t packet_loss, int rtt) {
588 DVLOG(3) << "SetChannelParameters(): packet_loss=" << packet_loss 592 DVLOG(3) << "SetChannelParameters(): packet_loss=" << packet_loss
589 << ", rtt=" << rtt; 593 << ", rtt=" << rtt;
590 DCHECK(thread_checker_.CalledOnValidThread()); 594 DCHECK(thread_checker_.CalledOnValidThread());
591 // Ignored. 595 // Ignored.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 DCHECK(thread_checker_.CalledOnValidThread()); 653 DCHECK(thread_checker_.CalledOnValidThread());
650 DVLOG(1) << "NotifyError(): error=" << error; 654 DVLOG(1) << "NotifyError(): error=" << error;
651 655
652 impl_status_ = error; 656 impl_status_ = error;
653 gpu_factories_->GetMessageLoop()->PostTask( 657 gpu_factories_->GetMessageLoop()->PostTask(
654 FROM_HERE, base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_)); 658 FROM_HERE, base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_));
655 impl_ = NULL; 659 impl_ = NULL;
656 } 660 }
657 661
658 } // namespace content 662 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698