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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 1122393004: Add support for switching the audio output device for HTMLMediaElements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes to MediaPlayers so that they invoke callbacks in the correct threads. First complete implem… Created 5 years, 6 months 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 unified diff | Download patch
OLDNEW
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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 } 364 }
365 365
366 void WebMediaPlayerImpl::setVolume(double volume) { 366 void WebMediaPlayerImpl::setVolume(double volume) {
367 DVLOG(1) << __FUNCTION__ << "(" << volume << ")"; 367 DVLOG(1) << __FUNCTION__ << "(" << volume << ")";
368 DCHECK(main_task_runner_->BelongsToCurrentThread()); 368 DCHECK(main_task_runner_->BelongsToCurrentThread());
369 369
370 pipeline_.SetVolume(volume); 370 pipeline_.SetVolume(volume);
371 } 371 }
372 372
373 void WebMediaPlayerImpl::FinishSetAudioOutputRequest(
374 blink::WebSetAudioOutputDeviceRequest *request,
375 int result) {
376 DCHECK(main_task_runner_->BelongsToCurrentThread());
377 DVLOG(1) << __PRETTY_FUNCTION__;
378 request->finish(result);
379 delete request;
380 }
381
382 void WebMediaPlayerImpl::PrepareFinishSetAudioOutputRequest(
383 WebMediaPlayerImpl* media_player,
384 const scoped_refptr<base::SingleThreadTaskRunner> task_runner,
385 blink::WebSetAudioOutputDeviceRequest *request,
386 int result) {
387 DCHECK(!task_runner->BelongsToCurrentThread());
388 DVLOG(1) << __PRETTY_FUNCTION__;
389 // TODO(guidou): Change base::Unretained to a weak pointer
miu 2015/06/03 21:01:02 This TODO needs to be resolved before committing.
390 task_runner->PostTask(
391 FROM_HERE, base::Bind(&WebMediaPlayerImpl::FinishSetAudioOutputRequest,
392 base::Unretained(media_player),
393 request,
394 result));
395 }
396
397 void WebMediaPlayerImpl::setAudioOutputDevice(
398 const blink::WebSetAudioOutputDeviceRequest& request) {
399 DCHECK(main_task_runner_->BelongsToCurrentThread());
400 std::string device_id_str(request.deviceID().utf8());
401 GURL security_origin(request.securityOrigin().toString().utf8());
402 DVLOG(1) << __FUNCTION__ << "(" << device_id_str << ", "
403 << security_origin << ")";
404
405 blink::WebSetAudioOutputDeviceRequest *request_ptr =
406 new blink::WebSetAudioOutputDeviceRequest(request);
407 pipeline_.SwitchAudioOutputDevice(
408 device_id_str,
409 security_origin,
410 base::Bind(&WebMediaPlayerImpl::PrepareFinishSetAudioOutputRequest,
411 base::Unretained(this),
412 main_task_runner_,
413 request_ptr));
414 }
415
373 #define STATIC_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ 416 #define STATIC_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
374 static_assert(static_cast<int>(WebMediaPlayer::webkit_name) == \ 417 static_assert(static_cast<int>(WebMediaPlayer::webkit_name) == \
375 static_cast<int>(BufferedDataSource::chromium_name), \ 418 static_cast<int>(BufferedDataSource::chromium_name), \
376 "mismatching enum values: " #webkit_name) 419 "mismatching enum values: " #webkit_name)
377 STATIC_ASSERT_MATCHING_ENUM(PreloadNone, NONE); 420 STATIC_ASSERT_MATCHING_ENUM(PreloadNone, NONE);
378 STATIC_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); 421 STATIC_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA);
379 STATIC_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); 422 STATIC_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO);
380 #undef STATIC_ASSERT_MATCHING_ENUM 423 #undef STATIC_ASSERT_MATCHING_ENUM
381 424
382 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { 425 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) {
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1058
1016 // pause() may be called after playback has ended and the HTMLMediaElement 1059 // pause() may be called after playback has ended and the HTMLMediaElement
1017 // requires that currentTime() == duration() after ending. We want to ensure 1060 // requires that currentTime() == duration() after ending. We want to ensure
1018 // |paused_time_| matches currentTime() in this case or a future seek() may 1061 // |paused_time_| matches currentTime() in this case or a future seek() may
1019 // incorrectly discard what it thinks is a seek to the existing time. 1062 // incorrectly discard what it thinks is a seek to the existing time.
1020 paused_time_ = 1063 paused_time_ =
1021 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); 1064 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime();
1022 } 1065 }
1023 1066
1024 } // namespace media 1067 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698