Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1461)

Unified Diff: content/renderer/media/media_recorder_handler.cc

Issue 1534553003: MediaRecorder: correct MIME type parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated content_unittests, updated vp9 handling Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_recorder_handler.cc
diff --git a/content/renderer/media/media_recorder_handler.cc b/content/renderer/media/media_recorder_handler.cc
index 6b8b0541cc10748f740225738f4d063c7b124a7a..800708f3a44673288a6da4152d92424b011cdee9 100644
--- a/content/renderer/media/media_recorder_handler.cc
+++ b/content/renderer/media/media_recorder_handler.cc
@@ -16,6 +16,7 @@
#include "media/audio/audio_parameters.h"
#include "media/base/audio_bus.h"
#include "media/base/bind_to_current_loop.h"
+#include "media/base/mime_util.h"
#include "media/base/video_frame.h"
#include "media/capture/webm_muxer.h"
#include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h"
@@ -40,42 +41,57 @@ MediaRecorderHandler::~MediaRecorderHandler() {
}
bool MediaRecorderHandler::canSupportMimeType(
- const blink::WebString& mimeType) {
+ const blink::WebString& type, const blink::WebString& codecs) {
DCHECK(main_render_thread_checker_.CalledOnValidThread());
- // Ensure we can support each passed MIME type.
- const std::string input = mimeType.utf8(); // Must outlive tokenizer!
- base::StringTokenizer tokenizer(input, ",");
- while (tokenizer.GetNext()) {
- // Strip whitespace.
- const std::string token(base::CollapseWhitespaceASCII(
- tokenizer.token(), true /* trim sequences with line breaks*/));
- if (!token.empty() &&
- !base::EqualsCaseInsensitiveASCII(token, "video/vp8") &&
- !base::EqualsCaseInsensitiveASCII(token, "video/vp9") &&
- !base::EqualsCaseInsensitiveASCII(token, "audio/opus") &&
- !base::EqualsCaseInsensitiveASCII(token, "video/webm") &&
- !base::EqualsCaseInsensitiveASCII(token, "audio/webm")) {
- return false;
- }
+ if (type.utf8().empty())
tommi (sloooow) - chröme 2015/12/18 10:06:30 utf8() creates a new std::string every time you ca
mcasas 2015/12/18 21:27:44 Done.
+ return true;
tommi (sloooow) - chröme 2015/12/18 10:06:29 Is it right to say we can support an empty mime ty
mcasas 2015/12/18 21:27:44 There is a bit of confusion in the spec about it,
philipj_slow 2016/01/26 04:30:28 See discussion in https://github.com/w3c/mediacapt
+ // Supported |type|s are {video,audio}/webm. Both support empty |codecs|,
+ // |type| == "video" supports vp8, vp9 or opus; "audio", supports only opus.
+ // http://www.webmproject.org/docs/container/, "HTML5 Video Type Parameters"
+ if ((base::EqualsCaseInsensitiveASCII(type.utf8(), "video/webm") ||
+ base::EqualsCaseInsensitiveASCII(type.utf8(), "audio/webm")) &&
+ codecs.utf8().empty()) {
tommi (sloooow) - chröme 2015/12/18 10:06:29 codecs.isEmpty() Looks like this will then be the
mcasas 2015/12/18 21:27:44 Refactored.
+ return true;
}
- return true;
+ std::vector<std::string> codecs_list;
+ media::ParseCodecString(codecs.utf8(), &codecs_list, true /* strip */);
+ if (base::EqualsCaseInsensitiveASCII(type.utf8(), "video/webm")) {
tommi (sloooow) - chröme 2015/12/18 10:06:30 this check has already been done before
mcasas 2015/12/18 21:27:45 Refactored.
+ for (const auto& codec : codecs_list) {
+ if (!base::EqualsCaseInsensitiveASCII(codec, "vp8") &&
+ !base::EqualsCaseInsensitiveASCII(codec, "vp9") &&
+ !base::EqualsCaseInsensitiveASCII(codec, "opus")) {
+ return false;
+ }
+ }
+ return true;
+ }
+ if (base::EqualsCaseInsensitiveASCII(type.utf8(), "audio/webm")) {
tommi (sloooow) - chröme 2015/12/18 10:06:30 this check might have been done before
mcasas 2015/12/18 21:27:45 Refactored.
+ for (const auto& codec : codecs_list) {
+ if (!base::EqualsCaseInsensitiveASCII(codec, "opus"))
+ return false;
+ }
+ return true;
+ }
+ return false;
tommi (sloooow) - chröme 2015/12/18 10:06:30 Here's an alternate implementation proposal that h
mcasas 2015/12/18 21:27:45 Gosh, almost right first time! Done.
}
bool MediaRecorderHandler::initialize(
blink::WebMediaRecorderHandlerClient* client,
const blink::WebMediaStream& media_stream,
- const blink::WebString& mimeType) {
+ const blink::WebString& type,
+ const blink::WebString& codecs) {
DCHECK(main_render_thread_checker_.CalledOnValidThread());
// Save histogram data so we can see how much MediaStream Recorder is used.
// The histogram counts the number of calls to the JS API.
UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER);
- if (!canSupportMimeType(mimeType)) {
- DLOG(ERROR) << "Can't support type " << mimeType.utf8();
+ if (!canSupportMimeType(type, codecs)) {
+ DLOG(ERROR) << "Can't support " << type.utf8()
+ << ";codecs=" << codecs.utf8();
return false;
}
- use_vp9_ = mimeType.utf8().compare("video/vp9") == 0;
+ use_vp9_ = codecs.utf8().find("vp9") != std::string::npos;
tommi (sloooow) - chröme 2015/12/18 10:06:29 this isn't case sensitive like the code in canSupp
mcasas 2015/12/18 21:27:45 Done.
media_stream_ = media_stream;
DCHECK(client);
client_ = client;

Powered by Google App Engine
This is Rietveld 408576698