Commit c104b1c4 authored by xlai's avatar xlai Committed by Commit bot

Revert of MediaRecorder: use VideoTrackRecorder::GetPreferredCodecId() when...

Revert of MediaRecorder: use VideoTrackRecorder::GetPreferredCodecId() when available (patchset #5 id:250001 of https://codereview.chromium.org/2624053002/ )

Reason for revert:
Suspected CL-to-blame for webkit tests failing on Mac Retina:
fast/mediacapturefromelement/HTMLMediaElementCapture-capture.html
fast/mediacapturefromelement/CanvasCaptureMediaStream-framerate-0.html

https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Mac10.11%20%28retina%29/builds/10965

Original issue's description:
> MediaRecorder: use VideoTrackRecorder::GetPreferredCodecId() when available
>
> This CL adds a static method to VTR to query which
> one, if any, is the preferred video codec.
>
> A new singleton Lazy Leaky class CodecEnumerator is
> added to encapsulate poking the VEA to see which
> codecs are supported, and to further query
> a) the preferred codec id
> b) if a given codec is supported
> and wraps the previous CodecIdToVEAProfile()
> functionality.
>
> BUG=679946
>
> Review-Url: https://codereview.chromium.org/2624053002
> Cr-Commit-Position: refs/heads/master@{#443165}
> Committed: https://chromium.googlesource.com/chromium/src/+/904b7a6f6dffa9cee5ac930c37dd591c330d14c6

TBR=emircan@chromium.org,chfremer@chromium.org,mcasas@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=679946

Review-Url: https://codereview.chromium.org/2622273006
Cr-Commit-Position: refs/heads/master@{#443251}
parent b2ea4c9c
...@@ -23,7 +23,6 @@ static struct EncodingParameters { ...@@ -23,7 +23,6 @@ static struct EncodingParameters {
{true, "video/webm;codecs=VP8"}, {true, "video/webm;codecs=VP8"},
{true, "video/webm;codecs=VP9"}, {true, "video/webm;codecs=VP9"},
{true, "video/x-matroska;codecs=AVC1"}, {true, "video/x-matroska;codecs=AVC1"},
{false, ""}, // Instructs the platform to choose any accelerated codec.
{false, "video/webm;codecs=VP8"}, {false, "video/webm;codecs=VP8"},
{false, "video/webm;codecs=VP9"}, {false, "video/webm;codecs=VP9"},
{false, "video/x-matroska;codecs=AVC1"}, {false, "video/x-matroska;codecs=AVC1"},
......
...@@ -42,8 +42,6 @@ media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) { ...@@ -42,8 +42,6 @@ media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) {
return media::kCodecVP9; return media::kCodecVP9;
case VideoTrackRecorder::CodecId::H264: case VideoTrackRecorder::CodecId::H264:
return media::kCodecH264; return media::kCodecH264;
case VideoTrackRecorder::CodecId::LAST:
return media::kUnknownVideoCodec;
} }
NOTREACHED() << "Unsupported codec"; NOTREACHED() << "Unsupported codec";
return media::kUnknownVideoCodec; return media::kUnknownVideoCodec;
...@@ -121,7 +119,8 @@ bool MediaRecorderHandler::initialize( ...@@ -121,7 +119,8 @@ bool MediaRecorderHandler::initialize(
UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER);
if (!canSupportMimeType(type, codecs)) { if (!canSupportMimeType(type, codecs)) {
DLOG(ERROR) << "Unsupported " << type.utf8() << ";codecs=" << codecs.utf8(); DLOG(ERROR) << "Can't support " << type.utf8()
<< ";codecs=" << codecs.utf8();
return false; return false;
} }
...@@ -137,11 +136,6 @@ bool MediaRecorderHandler::initialize( ...@@ -137,11 +136,6 @@ bool MediaRecorderHandler::initialize(
else if (codecs_str.find("avc1") != std::string::npos) else if (codecs_str.find("avc1") != std::string::npos)
codec_id_ = VideoTrackRecorder::CodecId::H264; codec_id_ = VideoTrackRecorder::CodecId::H264;
#endif #endif
else
codec_id_ = VideoTrackRecorder::GetPreferredCodecId();
DVLOG_IF(1, codecs_str.empty()) << "Falling back to preferred codec id "
<< static_cast<int>(codec_id_);
media_stream_ = media_stream; media_stream_ = media_stream;
DCHECK(client); DCHECK(client);
......
...@@ -60,98 +60,60 @@ const int kVEADefaultBitratePerPixel = 2; ...@@ -60,98 +60,60 @@ const int kVEADefaultBitratePerPixel = 2;
// encoders. // encoders.
const int kVEAEncoderOutputBufferCount = 4; const int kVEAEncoderOutputBufferCount = 4;
using CodecId = VideoTrackRecorder::CodecId; static struct {
VideoTrackRecorder::CodecId codec_id;
static const struct {
CodecId codec_id;
media::VideoCodecProfile min_profile; media::VideoCodecProfile min_profile;
media::VideoCodecProfile max_profile; media::VideoCodecProfile max_profile;
} kPreferredCodecIdAndVEAProfiles[] = { } const kSupportedVideoCodecIdToProfile[] = {
{CodecId::VP8, media::VP8PROFILE_MIN, media::VP8PROFILE_MAX}, {VideoTrackRecorder::CodecId::VP8,
{CodecId::VP9, media::VP9PROFILE_MIN, media::VP9PROFILE_MAX}, media::VP8PROFILE_MIN,
{CodecId::H264, media::H264PROFILE_MIN, media::H264PROFILE_MAX}}; media::VP8PROFILE_MAX},
{VideoTrackRecorder::CodecId::VP9,
static_assert(arraysize(kPreferredCodecIdAndVEAProfiles) == media::VP9PROFILE_MIN,
static_cast<int>(CodecId::LAST), media::VP9PROFILE_MAX},
"|kPreferredCodecIdAndVEAProfiles| should consider all CodecIds"); {VideoTrackRecorder::CodecId::H264,
media::H264PROFILE_MIN,
// Class to encapsulate the enumeration of CodecIds/VideoCodecProfiles supported media::H264PROFILE_MAX}};
// by the VEA underlying platform. Provides methods to query the preferred
// CodecId and to check if a given CodecId is supported. // Returns the corresponding codec profile from VEA supported codecs. If no
class CodecEnumerator { // profile is found, returns VIDEO_CODEC_PROFILE_UNKNOWN.
public: media::VideoCodecProfile CodecIdToVEAProfile(
CodecEnumerator(); content::VideoTrackRecorder::CodecId codec) {
~CodecEnumerator() = default;
// Returns the first CodecId that has an associated VEA VideoCodecProfile, or
// VP8 if none available.
CodecId GetPreferredCodecId();
// Returns the VEA VideoCodedProfile for a given CodecId, if supported, or
// VIDEO_CODEC_PROFILE_UNKNOWN otherwise.
media::VideoCodecProfile CodecIdToVEAProfile(CodecId codec);
private:
// A map of VEA-supported CodecId-and-VEA-profile pairs.
std::map<CodecId, media::VideoCodecProfile> codec_id_to_profile_;
DISALLOW_COPY_AND_ASSIGN(CodecEnumerator);
};
static base::LazyInstance<CodecEnumerator>::Leaky g_codec_enumerator =
LAZY_INSTANCE_INITIALIZER;
CodecEnumerator::CodecEnumerator() {
#if defined(OS_CHROMEOS)
// See https://crbug.com/616659. // See https://crbug.com/616659.
return; #if defined(OS_CHROMEOS)
#endif return media::VIDEO_CODEC_PROFILE_UNKNOWN;
#endif // defined(OS_CHROMEOS)
// See https://crbug.com/653864.
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// See https://crbug.com/653864. return media::VIDEO_CODEC_PROFILE_UNKNOWN;
return; #endif // defined(OS_ANDROID)
#endif
content::RenderThreadImpl* const render_thread_impl = content::RenderThreadImpl* const render_thread_impl =
content::RenderThreadImpl::current(); content::RenderThreadImpl::current();
if (!render_thread_impl) { if (!render_thread_impl) {
DVLOG(2) << "Couldn't access the render thread"; DVLOG(3) << "Couldn't access the render thread";
return; return media::VIDEO_CODEC_PROFILE_UNKNOWN;
} }
media::GpuVideoAcceleratorFactories* const gpu_factories = media::GpuVideoAcceleratorFactories* const gpu_factories =
render_thread_impl->GetGpuFactories(); render_thread_impl->GetGpuFactories();
if (!gpu_factories || !gpu_factories->IsGpuVideoAcceleratorEnabled()) { if (!gpu_factories || !gpu_factories->IsGpuVideoAcceleratorEnabled()) {
DVLOG(2) << "Couldn't initialize GpuVideoAcceleratorFactories"; DVLOG(3) << "Couldn't initialize GpuVideoAcceleratorFactories";
return; return media::VIDEO_CODEC_PROFILE_UNKNOWN;
} }
const auto vea_supported_profiles = const media::VideoEncodeAccelerator::SupportedProfiles& vea_profiles =
gpu_factories->GetVideoEncodeAcceleratorSupportedProfiles(); gpu_factories->GetVideoEncodeAcceleratorSupportedProfiles();
for (const auto& supported_profile : vea_supported_profiles) { for (const auto& vea_profile : vea_profiles) {
for (auto& codec_id_and_profile : kPreferredCodecIdAndVEAProfiles) { for (const auto& supported_profile : kSupportedVideoCodecIdToProfile) {
if (supported_profile.profile >= codec_id_and_profile.min_profile && if (codec == supported_profile.codec_id &&
supported_profile.profile <= codec_id_and_profile.max_profile) { vea_profile.profile >= supported_profile.min_profile &&
DVLOG(2) << "Accelerated codec found: " vea_profile.profile <= supported_profile.max_profile)
<< media::GetProfileName(supported_profile.profile); return vea_profile.profile;
codec_id_to_profile_.insert(std::make_pair(
codec_id_and_profile.codec_id, supported_profile.profile));
}
} }
} }
} return media::VIDEO_CODEC_PROFILE_UNKNOWN;
CodecId CodecEnumerator::GetPreferredCodecId() {
if (codec_id_to_profile_.empty())
return CodecId::VP8;
return codec_id_to_profile_.begin()->first;
}
media::VideoCodecProfile CodecEnumerator::CodecIdToVEAProfile(CodecId codec) {
const auto profile = codec_id_to_profile_.find(codec);
return profile == codec_id_to_profile_.end()
? media::VIDEO_CODEC_PROFILE_UNKNOWN
: profile->second;
} }
} // anonymous namespace } // anonymous namespace
...@@ -1113,11 +1075,6 @@ void H264Encoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { ...@@ -1113,11 +1075,6 @@ void H264Encoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
} // anonymous namespace } // anonymous namespace
// static
VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() {
return g_codec_enumerator.Get().GetPreferredCodecId();
}
VideoTrackRecorder::VideoTrackRecorder( VideoTrackRecorder::VideoTrackRecorder(
CodecId codec, CodecId codec,
const blink::WebMediaStreamTrack& track, const blink::WebMediaStreamTrack& track,
...@@ -1186,8 +1143,7 @@ void VideoTrackRecorder::InitializeEncoder( ...@@ -1186,8 +1143,7 @@ void VideoTrackRecorder::InitializeEncoder(
MediaStreamVideoSink::DisconnectFromTrack(); MediaStreamVideoSink::DisconnectFromTrack();
const gfx::Size& input_size = frame->visible_rect().size(); const gfx::Size& input_size = frame->visible_rect().size();
const auto& vea_supported_profile = const auto& vea_supported_profile = CodecIdToVEAProfile(codec);
g_codec_enumerator.Get().CodecIdToVEAProfile(codec);
if (vea_supported_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN && if (vea_supported_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN &&
input_size.width() >= kVEAEncoderMinResolutionWidth && input_size.width() >= kVEAEncoderMinResolutionWidth &&
input_size.height() >= kVEAEncoderMinResolutionHeight) { input_size.height() >= kVEAEncoderMinResolutionHeight) {
......
...@@ -37,12 +37,10 @@ namespace content { ...@@ -37,12 +37,10 @@ namespace content {
class CONTENT_EXPORT VideoTrackRecorder class CONTENT_EXPORT VideoTrackRecorder
: NON_EXPORTED_BASE(public MediaStreamVideoSink) { : NON_EXPORTED_BASE(public MediaStreamVideoSink) {
public: public:
// Do not change the order of codecs; add new ones right before LAST.
enum class CodecId { enum class CodecId {
VP8, VP8,
VP9, VP9,
H264, H264,
LAST
}; };
class Encoder; class Encoder;
...@@ -52,8 +50,6 @@ class CONTENT_EXPORT VideoTrackRecorder ...@@ -52,8 +50,6 @@ class CONTENT_EXPORT VideoTrackRecorder
base::TimeTicks capture_timestamp, base::TimeTicks capture_timestamp,
bool is_key_frame)>; bool is_key_frame)>;
static CodecId GetPreferredCodecId();
VideoTrackRecorder(CodecId codec, VideoTrackRecorder(CodecId codec,
const blink::WebMediaStreamTrack& track, const blink::WebMediaStreamTrack& track,
const OnEncodedVideoCB& on_encoded_video_cb, const OnEncodedVideoCB& on_encoded_video_cb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment