OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cast/video_sender/external_video_encoder.h" | 5 #include "media/cast/video_sender/external_video_encoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 case transport::kVp8: | 100 case transport::kVp8: |
101 output_profile = media::VP8PROFILE_MAIN; | 101 output_profile = media::VP8PROFILE_MAIN; |
102 break; | 102 break; |
103 case transport::kH264: | 103 case transport::kH264: |
104 output_profile = media::H264PROFILE_MAIN; | 104 output_profile = media::H264PROFILE_MAIN; |
105 break; | 105 break; |
106 } | 106 } |
107 codec_ = video_config.codec; | 107 codec_ = video_config.codec; |
108 max_frame_rate_ = video_config.max_frame_rate; | 108 max_frame_rate_ = video_config.max_frame_rate; |
109 | 109 |
110 // Asynchronous initialization call; NotifyInitializeDone or NotifyError | 110 if (!video_encode_accelerator_->Initialize( |
111 // will be called once the HW is initialized. | 111 media::VideoFrame::I420, |
112 video_encode_accelerator_->Initialize( | 112 gfx::Size(video_config.width, video_config.height), |
113 media::VideoFrame::I420, | 113 output_profile, |
114 gfx::Size(video_config.width, video_config.height), | 114 video_config.start_bitrate, |
115 output_profile, | 115 this)) { |
116 video_config.start_bitrate, | 116 NotifyError(VideoEncodeAccelerator::kInvalidArgumentError); |
117 this); | 117 return; |
| 118 } |
| 119 |
| 120 // Wait until shared memory is allocated to indicate that encoder is |
| 121 // initialized. |
118 } | 122 } |
119 | 123 |
120 // Free the HW. | 124 // Free the HW. |
121 void Destroy() { | 125 void Destroy() { |
122 DCHECK(encoder_task_runner_); | 126 DCHECK(encoder_task_runner_); |
123 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | 127 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); |
124 | 128 |
125 if (video_encode_accelerator_) { | 129 if (video_encode_accelerator_) { |
126 video_encode_accelerator_.release()->Destroy(); | 130 video_encode_accelerator_.release()->Destroy(); |
127 } | 131 } |
(...skipping 16 matching lines...) Expand all Loading... |
144 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | 148 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); |
145 | 149 |
146 encoded_frame_data_storage_.push_back( | 150 encoded_frame_data_storage_.push_back( |
147 EncodedFrameReturnData(capture_time, frame_encoded_callback)); | 151 EncodedFrameReturnData(capture_time, frame_encoded_callback)); |
148 | 152 |
149 // BitstreamBufferReady will be called once the encoder is done. | 153 // BitstreamBufferReady will be called once the encoder is done. |
150 video_encode_accelerator_->Encode(video_frame, key_frame_requested); | 154 video_encode_accelerator_->Encode(video_frame, key_frame_requested); |
151 } | 155 } |
152 | 156 |
153 protected: | 157 protected: |
154 virtual void NotifyInitializeDone() OVERRIDE { | |
155 DCHECK(encoder_task_runner_); | |
156 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | |
157 | |
158 // Wait until shared memory is allocated to indicate that encoder is | |
159 // initialized. | |
160 } | |
161 | |
162 virtual void NotifyError(VideoEncodeAccelerator::Error error) OVERRIDE { | 158 virtual void NotifyError(VideoEncodeAccelerator::Error error) OVERRIDE { |
163 DCHECK(encoder_task_runner_); | 159 DCHECK(encoder_task_runner_); |
164 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | 160 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); |
165 VLOG(1) << "ExternalVideoEncoder NotifyError: " << error; | 161 VLOG(1) << "ExternalVideoEncoder NotifyError: " << error; |
166 | 162 |
167 if (video_encode_accelerator_) { | 163 if (video_encode_accelerator_) { |
168 video_encode_accelerator_.release()->Destroy(); | 164 video_encode_accelerator_.release()->Destroy(); |
169 } | 165 } |
170 cast_environment_->PostTask( | 166 cast_environment_->PostTask( |
171 CastEnvironment::MAIN, | 167 CastEnvironment::MAIN, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // Do nothing not supported. | 430 // Do nothing not supported. |
435 } | 431 } |
436 | 432 |
437 int ExternalVideoEncoder::NumberOfSkippedFrames() const { | 433 int ExternalVideoEncoder::NumberOfSkippedFrames() const { |
438 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 434 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
439 return skip_count_; | 435 return skip_count_; |
440 } | 436 } |
441 | 437 |
442 } // namespace cast | 438 } // namespace cast |
443 } // namespace media | 439 } // namespace media |
OLD | NEW |