Skip to content

Commit

Permalink
Revert of MediaRecorder: use VideoTrackRecorder::GetPreferredCodecId(…
Browse files Browse the repository at this point in the history
…) when available (patchset chromium#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}
  • Loading branch information
xlai-o authored and Commit bot committed Jan 12, 2017
1 parent b2ea4c9 commit c104b1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ static struct EncodingParameters {
{true, "video/webm;codecs=VP8"},
{true, "video/webm;codecs=VP9"},
{true, "video/x-matroska;codecs=AVC1"},
{false, ""}, // Instructs the platform to choose any accelerated codec.
{false, "video/webm;codecs=VP8"},
{false, "video/webm;codecs=VP9"},
{false, "video/x-matroska;codecs=AVC1"},
Expand Down
10 changes: 2 additions & 8 deletions content/renderer/media/media_recorder_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) {
return media::kCodecVP9;
case VideoTrackRecorder::CodecId::H264:
return media::kCodecH264;
case VideoTrackRecorder::CodecId::LAST:
return media::kUnknownVideoCodec;
}
NOTREACHED() << "Unsupported codec";
return media::kUnknownVideoCodec;
Expand Down Expand Up @@ -121,7 +119,8 @@ bool MediaRecorderHandler::initialize(
UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER);

if (!canSupportMimeType(type, codecs)) {
DLOG(ERROR) << "Unsupported " << type.utf8() << ";codecs=" << codecs.utf8();
DLOG(ERROR) << "Can't support " << type.utf8()
<< ";codecs=" << codecs.utf8();
return false;
}

Expand All @@ -137,11 +136,6 @@ bool MediaRecorderHandler::initialize(
else if (codecs_str.find("avc1") != std::string::npos)
codec_id_ = VideoTrackRecorder::CodecId::H264;
#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;
DCHECK(client);
Expand Down
116 changes: 36 additions & 80 deletions content/renderer/media/video_track_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,98 +60,60 @@ const int kVEADefaultBitratePerPixel = 2;
// encoders.
const int kVEAEncoderOutputBufferCount = 4;

using CodecId = VideoTrackRecorder::CodecId;

static const struct {
CodecId codec_id;
static struct {
VideoTrackRecorder::CodecId codec_id;
media::VideoCodecProfile min_profile;
media::VideoCodecProfile max_profile;
} kPreferredCodecIdAndVEAProfiles[] = {
{CodecId::VP8, media::VP8PROFILE_MIN, media::VP8PROFILE_MAX},
{CodecId::VP9, media::VP9PROFILE_MIN, media::VP9PROFILE_MAX},
{CodecId::H264, media::H264PROFILE_MIN, media::H264PROFILE_MAX}};

static_assert(arraysize(kPreferredCodecIdAndVEAProfiles) ==
static_cast<int>(CodecId::LAST),
"|kPreferredCodecIdAndVEAProfiles| should consider all CodecIds");

// Class to encapsulate the enumeration of CodecIds/VideoCodecProfiles supported
// by the VEA underlying platform. Provides methods to query the preferred
// CodecId and to check if a given CodecId is supported.
class CodecEnumerator {
public:
CodecEnumerator();
~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)
} const kSupportedVideoCodecIdToProfile[] = {
{VideoTrackRecorder::CodecId::VP8,
media::VP8PROFILE_MIN,
media::VP8PROFILE_MAX},
{VideoTrackRecorder::CodecId::VP9,
media::VP9PROFILE_MIN,
media::VP9PROFILE_MAX},
{VideoTrackRecorder::CodecId::H264,
media::H264PROFILE_MIN,
media::H264PROFILE_MAX}};

// Returns the corresponding codec profile from VEA supported codecs. If no
// profile is found, returns VIDEO_CODEC_PROFILE_UNKNOWN.
media::VideoCodecProfile CodecIdToVEAProfile(
content::VideoTrackRecorder::CodecId codec) {
// See https://crbug.com/616659.
return;
#endif
#if defined(OS_CHROMEOS)
return media::VIDEO_CODEC_PROFILE_UNKNOWN;
#endif // defined(OS_CHROMEOS)

// See https://crbug.com/653864.
#if defined(OS_ANDROID)
// See https://crbug.com/653864.
return;
#endif
return media::VIDEO_CODEC_PROFILE_UNKNOWN;
#endif // defined(OS_ANDROID)

content::RenderThreadImpl* const render_thread_impl =
content::RenderThreadImpl::current();
if (!render_thread_impl) {
DVLOG(2) << "Couldn't access the render thread";
return;
DVLOG(3) << "Couldn't access the render thread";
return media::VIDEO_CODEC_PROFILE_UNKNOWN;
}

media::GpuVideoAcceleratorFactories* const gpu_factories =
render_thread_impl->GetGpuFactories();
if (!gpu_factories || !gpu_factories->IsGpuVideoAcceleratorEnabled()) {
DVLOG(2) << "Couldn't initialize GpuVideoAcceleratorFactories";
return;
DVLOG(3) << "Couldn't initialize GpuVideoAcceleratorFactories";
return media::VIDEO_CODEC_PROFILE_UNKNOWN;
}

const auto vea_supported_profiles =
const media::VideoEncodeAccelerator::SupportedProfiles& vea_profiles =
gpu_factories->GetVideoEncodeAcceleratorSupportedProfiles();
for (const auto& supported_profile : vea_supported_profiles) {
for (auto& codec_id_and_profile : kPreferredCodecIdAndVEAProfiles) {
if (supported_profile.profile >= codec_id_and_profile.min_profile &&
supported_profile.profile <= codec_id_and_profile.max_profile) {
DVLOG(2) << "Accelerated codec found: "
<< media::GetProfileName(supported_profile.profile);
codec_id_to_profile_.insert(std::make_pair(
codec_id_and_profile.codec_id, supported_profile.profile));
}
for (const auto& vea_profile : vea_profiles) {
for (const auto& supported_profile : kSupportedVideoCodecIdToProfile) {
if (codec == supported_profile.codec_id &&
vea_profile.profile >= supported_profile.min_profile &&
vea_profile.profile <= supported_profile.max_profile)
return vea_profile.profile;
}
}
}

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;
return media::VIDEO_CODEC_PROFILE_UNKNOWN;
}

} // anonymous namespace
Expand Down Expand Up @@ -1113,11 +1075,6 @@ void H264Encoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {

} // anonymous namespace

// static
VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() {
return g_codec_enumerator.Get().GetPreferredCodecId();
}

VideoTrackRecorder::VideoTrackRecorder(
CodecId codec,
const blink::WebMediaStreamTrack& track,
Expand Down Expand Up @@ -1186,8 +1143,7 @@ void VideoTrackRecorder::InitializeEncoder(
MediaStreamVideoSink::DisconnectFromTrack();

const gfx::Size& input_size = frame->visible_rect().size();
const auto& vea_supported_profile =
g_codec_enumerator.Get().CodecIdToVEAProfile(codec);
const auto& vea_supported_profile = CodecIdToVEAProfile(codec);
if (vea_supported_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN &&
input_size.width() >= kVEAEncoderMinResolutionWidth &&
input_size.height() >= kVEAEncoderMinResolutionHeight) {
Expand Down
4 changes: 0 additions & 4 deletions content/renderer/media/video_track_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ namespace content {
class CONTENT_EXPORT VideoTrackRecorder
: NON_EXPORTED_BASE(public MediaStreamVideoSink) {
public:
// Do not change the order of codecs; add new ones right before LAST.
enum class CodecId {
VP8,
VP9,
H264,
LAST
};
class Encoder;

Expand All @@ -52,8 +50,6 @@ class CONTENT_EXPORT VideoTrackRecorder
base::TimeTicks capture_timestamp,
bool is_key_frame)>;

static CodecId GetPreferredCodecId();

VideoTrackRecorder(CodecId codec,
const blink::WebMediaStreamTrack& track,
const OnEncodedVideoCB& on_encoded_video_cb,
Expand Down

0 comments on commit c104b1c

Please sign in to comment.