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

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: tommi@s comments 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..9a2c21096f2d149706e7121b826668af3c56a351 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& web_type, const blink::WebString& web_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")) {
+ // An empty |web_type| means MediaRecorderHandler can choose its preferred
+ // codecs.
+ if (web_type.isEmpty())
+ return true;
+
+ const std::string type(web_type.utf8());
+ const bool video = base::EqualsCaseInsensitiveASCII(type, "video/webm");
+ const bool audio =
+ video ? false : base::EqualsCaseInsensitiveASCII(type, "audio/webm");
+ if (!video && !audio)
+ return false;
+
+ // Both |video| and |audio| support empty |codecs|; |type| == "video" supports
+ // vp8, vp9 or opus; |type| = "audio", supports only opus.
+ // http://www.webmproject.org/docs/container Sec:"HTML5 Video Type Parameters"
+ static const char* kVideoCodecs[] = { "vp8", "vp9", "opus" };
+ static const char* kAudioCodecs[] = { "opus" };
+ const char** codecs = video ? &kVideoCodecs[0] : &kAudioCodecs[0];
+ int codecs_count = video ? arraysize(kVideoCodecs) : arraysize(kAudioCodecs);
+
+ std::vector<std::string> codecs_list;
+ media::ParseCodecString(web_codecs.utf8(), &codecs_list, true /* strip */);
+ for (const auto& codec : codecs_list) {
+ const auto found = std::find_if(
+ &codecs[0], &codecs[codecs_count], [&codec](const char* name) {
+ return base::EqualsCaseInsensitiveASCII(codec, name);
+ });
+ if (found == &codecs[codecs_count])
return false;
- }
}
-
return true;
}
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_ = base::ToLowerASCII(codecs.utf8()).find("vp9") != std::string::npos;
media_stream_ = media_stream;
DCHECK(client);
client_ = client;
« no previous file with comments | « content/renderer/media/media_recorder_handler.h ('k') | content/renderer/media/media_recorder_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698