| 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/common/gpu/media/android_video_encode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 17 #include "media/base/android/media_codec_bridge.h" | 17 #include "media/base/android/media_codec_util.h" |
| 18 #include "media/base/bitstream_buffer.h" | 18 #include "media/base/bitstream_buffer.h" |
| 19 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 20 #include "media/video/picture.h" | 20 #include "media/video/picture.h" |
| 21 #include "third_party/libyuv/include/libyuv/convert_from.h" | 21 #include "third_party/libyuv/include/libyuv/convert_from.h" |
| 22 #include "ui/gl/android/scoped_java_surface.h" | 22 #include "ui/gl/android/scoped_java_surface.h" |
| 23 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
| 24 | 24 |
| 25 using media::MediaCodecBridge; | |
| 26 using media::VideoCodecBridge; | 25 using media::VideoCodecBridge; |
| 27 using media::VideoFrame; | 26 using media::VideoFrame; |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 31 // Limit default max video codec size for Android to avoid | 30 // Limit default max video codec size for Android to avoid |
| 32 // HW codec initialization failure for resolution higher than 720p. | 31 // HW codec initialization failure for resolution higher than 720p. |
| 33 // Default values are from Libjingle "jsepsessiondescription.cc". | 32 // Default values are from Libjingle "jsepsessiondescription.cc". |
| 34 const int kMaxEncodeFrameWidth = 1280; | 33 const int kMaxEncodeFrameWidth = 1280; |
| 35 const int kMaxEncodeFrameHeight = 720; | 34 const int kMaxEncodeFrameHeight = 720; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 75 |
| 77 static inline const base::TimeDelta NoWaitTimeOut() { | 76 static inline const base::TimeDelta NoWaitTimeOut() { |
| 78 return base::TimeDelta::FromMicroseconds(0); | 77 return base::TimeDelta::FromMicroseconds(0); |
| 79 } | 78 } |
| 80 | 79 |
| 81 static bool GetSupportedColorFormatForMime(const std::string& mime, | 80 static bool GetSupportedColorFormatForMime(const std::string& mime, |
| 82 PixelFormat* pixel_format) { | 81 PixelFormat* pixel_format) { |
| 83 if (mime.empty()) | 82 if (mime.empty()) |
| 84 return false; | 83 return false; |
| 85 | 84 |
| 86 std::set<int> formats = MediaCodecBridge::GetEncoderColorFormats(mime); | 85 std::set<int> formats = media::MediaCodecUtil::GetEncoderColorFormats(mime); |
| 87 if (formats.count(COLOR_FORMAT_YUV420_SEMIPLANAR) > 0) | 86 if (formats.count(COLOR_FORMAT_YUV420_SEMIPLANAR) > 0) |
| 88 *pixel_format = COLOR_FORMAT_YUV420_SEMIPLANAR; | 87 *pixel_format = COLOR_FORMAT_YUV420_SEMIPLANAR; |
| 89 else if (formats.count(COLOR_FORMAT_YUV420_PLANAR) > 0) | 88 else if (formats.count(COLOR_FORMAT_YUV420_PLANAR) > 0) |
| 90 *pixel_format = COLOR_FORMAT_YUV420_PLANAR; | 89 *pixel_format = COLOR_FORMAT_YUV420_PLANAR; |
| 91 else | 90 else |
| 92 return false; | 91 return false; |
| 93 | 92 |
| 94 return true; | 93 return true; |
| 95 } | 94 } |
| 96 | 95 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Client* client) { | 149 Client* client) { |
| 151 DVLOG(3) << __PRETTY_FUNCTION__ << " format: " << format | 150 DVLOG(3) << __PRETTY_FUNCTION__ << " format: " << format |
| 152 << ", input_visible_size: " << input_visible_size.ToString() | 151 << ", input_visible_size: " << input_visible_size.ToString() |
| 153 << ", output_profile: " << output_profile | 152 << ", output_profile: " << output_profile |
| 154 << ", initial_bitrate: " << initial_bitrate; | 153 << ", initial_bitrate: " << initial_bitrate; |
| 155 DCHECK(!media_codec_); | 154 DCHECK(!media_codec_); |
| 156 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
| 157 | 156 |
| 158 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 157 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
| 159 | 158 |
| 160 if (!(media::MediaCodecBridge::SupportsSetParameters() && | 159 if (!(media::MediaCodecUtil::SupportsSetParameters() && |
| 161 format == media::PIXEL_FORMAT_I420)) { | 160 format == media::PIXEL_FORMAT_I420)) { |
| 162 DLOG(ERROR) << "Unexpected combo: " << format << ", " << output_profile; | 161 DLOG(ERROR) << "Unexpected combo: " << format << ", " << output_profile; |
| 163 return false; | 162 return false; |
| 164 } | 163 } |
| 165 | 164 |
| 166 std::string mime_type; | 165 std::string mime_type; |
| 167 media::VideoCodec codec; | 166 media::VideoCodec codec; |
| 168 if (output_profile == media::VP8PROFILE_ANY) { | 167 if (output_profile == media::VP8PROFILE_ANY) { |
| 169 codec = media::kCodecVP8; | 168 codec = media::kCodecVP8; |
| 170 mime_type = "video/x-vnd.on2.vp8"; | 169 mime_type = "video/x-vnd.on2.vp8"; |
| 171 } else if (output_profile == media::H264PROFILE_BASELINE || | 170 } else if (output_profile == media::H264PROFILE_BASELINE || |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 base::MessageLoop::current()->PostTask( | 446 base::MessageLoop::current()->PostTask( |
| 448 FROM_HERE, | 447 FROM_HERE, |
| 449 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 448 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
| 450 client_ptr_factory_->GetWeakPtr(), | 449 client_ptr_factory_->GetWeakPtr(), |
| 451 bitstream_buffer.id(), | 450 bitstream_buffer.id(), |
| 452 size, | 451 size, |
| 453 key_frame)); | 452 key_frame)); |
| 454 } | 453 } |
| 455 | 454 |
| 456 } // namespace content | 455 } // namespace content |
| OLD | NEW |