OLD | NEW |
---|---|
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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "media/base/bind_to_current_loop.h" | |
16 #include "media/base/bitstream_buffer.h" | 17 #include "media/base/bitstream_buffer.h" |
17 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
18 #include "media/base/video_util.h" | 19 #include "media/base/video_util.h" |
19 #include "media/filters/h264_parser.h" | 20 #include "media/filters/h264_parser.h" |
20 #include "media/renderers/gpu_video_accelerator_factories.h" | 21 #include "media/renderers/gpu_video_accelerator_factories.h" |
21 #include "media/video/video_encode_accelerator.h" | 22 #include "media/video/video_encode_accelerator.h" |
22 #include "third_party/libyuv/include/libyuv.h" | 23 #include "third_party/libyuv/include/libyuv.h" |
23 #include "third_party/webrtc/system_wrappers/interface/tick_util.h" | 24 #include "third_party/webrtc/system_wrappers/interface/tick_util.h" |
24 | 25 |
25 #define NOTIFY_ERROR(x) \ | 26 #define NOTIFY_ERROR(x) \ |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 bool next_frame_keyframe = input_next_frame_keyframe_; | 485 bool next_frame_keyframe = input_next_frame_keyframe_; |
485 input_next_frame_ = NULL; | 486 input_next_frame_ = NULL; |
486 input_next_frame_keyframe_ = false; | 487 input_next_frame_keyframe_ = false; |
487 | 488 |
488 if (!video_encoder_) { | 489 if (!video_encoder_) { |
489 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_ERROR); | 490 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_ERROR); |
490 return; | 491 return; |
491 } | 492 } |
492 | 493 |
493 const int index = input_buffers_free_.back(); | 494 const int index = input_buffers_free_.back(); |
495 | |
496 if (next_frame->native_handle()) { | |
497 scoped_refptr<media::VideoFrame> frame( | |
498 static_cast<media::VideoFrame*>(next_frame->native_handle())); | |
499 frame->AddDestructionObserver(media::BindToCurrentLoop( | |
500 base::Bind(&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index))); | |
501 video_encoder_->Encode(frame, next_frame_keyframe); | |
Pawel Osciak
2015/06/03 10:28:56
Could we please not duplicate these lines, but ins
emircan
2015/06/03 20:56:12
Done.
I am preparing a followup CL for RTCVideoE
| |
502 input_buffers_free_.pop_back(); | |
503 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK); | |
504 return; | |
505 } | |
506 | |
494 base::SharedMemory* input_buffer = input_buffers_[index]; | 507 base::SharedMemory* input_buffer = input_buffers_[index]; |
495 scoped_refptr<media::VideoFrame> frame = | 508 scoped_refptr<media::VideoFrame> frame = |
496 media::VideoFrame::WrapExternalSharedMemory( | 509 media::VideoFrame::WrapExternalSharedMemory( |
497 media::VideoFrame::I420, | 510 media::VideoFrame::I420, |
498 input_frame_coded_size_, | 511 input_frame_coded_size_, |
499 gfx::Rect(input_visible_size_), | 512 gfx::Rect(input_visible_size_), |
500 input_visible_size_, | 513 input_visible_size_, |
501 reinterpret_cast<uint8*>(input_buffer->memory()), | 514 reinterpret_cast<uint8*>(input_buffer->memory()), |
502 input_buffer->mapped_size(), | 515 input_buffer->mapped_size(), |
503 input_buffer->handle(), | 516 input_buffer->handle(), |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 792 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
780 init_retval == WEBRTC_VIDEO_CODEC_OK); | 793 init_retval == WEBRTC_VIDEO_CODEC_OK); |
781 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 794 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
782 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 795 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
783 profile, | 796 profile, |
784 media::VIDEO_CODEC_PROFILE_MAX + 1); | 797 media::VIDEO_CODEC_PROFILE_MAX + 1); |
785 } | 798 } |
786 } | 799 } |
787 | 800 |
788 } // namespace content | 801 } // namespace content |
OLD | NEW |