OLD | NEW |
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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 696 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
697 | 697 |
698 base::Optional<MediaTrack::Id> selected_video_track_id; | 698 base::Optional<MediaTrack::Id> selected_video_track_id; |
699 if (selectedTrackId && !video_track_disabled_) | 699 if (selectedTrackId && !video_track_disabled_) |
700 selected_video_track_id = MediaTrack::Id(selectedTrackId->utf8().data()); | 700 selected_video_track_id = MediaTrack::Id(selectedTrackId->utf8().data()); |
701 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" | 701 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" |
702 << selected_video_track_id.value_or("") << "]"; | 702 << selected_video_track_id.value_or("") << "]"; |
703 pipeline_controller_.OnSelectedVideoTrackChanged(selected_video_track_id); | 703 pipeline_controller_.OnSelectedVideoTrackChanged(selected_video_track_id); |
704 } | 704 } |
705 | 705 |
| 706 bool WebMediaPlayerImpl::getLastUploadedFrameInfo(unsigned* width, |
| 707 unsigned* height, |
| 708 double* timestamp) { |
| 709 *width = last_uploaded_frame_size_.width(); |
| 710 *height = last_uploaded_frame_size_.height(); |
| 711 *timestamp = last_uploaded_frame_timestamp_.InSecondsF(); |
| 712 return true; |
| 713 } |
| 714 |
706 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 715 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
707 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 716 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
708 | 717 |
709 return blink::WebSize(pipeline_metadata_.natural_size); | 718 return blink::WebSize(pipeline_metadata_.natural_size); |
710 } | 719 } |
711 | 720 |
712 bool WebMediaPlayerImpl::paused() const { | 721 bool WebMediaPlayerImpl::paused() const { |
713 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 722 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
714 | 723 |
715 #if defined(OS_ANDROID) // WMPI_CAST | 724 #if defined(OS_ANDROID) // WMPI_CAST |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); | 1835 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); |
1827 event->Signal(); | 1836 event->Signal(); |
1828 } | 1837 } |
1829 | 1838 |
1830 scoped_refptr<VideoFrame> WebMediaPlayerImpl::GetCurrentFrameFromCompositor() { | 1839 scoped_refptr<VideoFrame> WebMediaPlayerImpl::GetCurrentFrameFromCompositor() { |
1831 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1840 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1832 TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor"); | 1841 TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor"); |
1833 | 1842 |
1834 // Needed when the |main_task_runner_| and |compositor_task_runner_| are the | 1843 // Needed when the |main_task_runner_| and |compositor_task_runner_| are the |
1835 // same to avoid deadlock in the Wait() below. | 1844 // same to avoid deadlock in the Wait() below. |
1836 if (compositor_task_runner_->BelongsToCurrentThread()) | 1845 if (compositor_task_runner_->BelongsToCurrentThread()) { |
1837 return compositor_->GetCurrentFrameAndUpdateIfStale(); | 1846 scoped_refptr<VideoFrame> video_frame = |
| 1847 compositor_->GetCurrentFrameAndUpdateIfStale(); |
| 1848 if (!video_frame) { |
| 1849 return nullptr; |
| 1850 } |
| 1851 last_uploaded_frame_size_ = video_frame->natural_size(); |
| 1852 last_uploaded_frame_timestamp_ = video_frame->timestamp(); |
| 1853 return video_frame; |
| 1854 } |
1838 | 1855 |
1839 // Use a posted task and waitable event instead of a lock otherwise | 1856 // Use a posted task and waitable event instead of a lock otherwise |
1840 // WebGL/Canvas can see different content than what the compositor is seeing. | 1857 // WebGL/Canvas can see different content than what the compositor is seeing. |
1841 scoped_refptr<VideoFrame> video_frame; | 1858 scoped_refptr<VideoFrame> video_frame; |
1842 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 1859 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
1843 base::WaitableEvent::InitialState::NOT_SIGNALED); | 1860 base::WaitableEvent::InitialState::NOT_SIGNALED); |
1844 compositor_task_runner_->PostTask( | 1861 compositor_task_runner_->PostTask( |
1845 FROM_HERE, | 1862 FROM_HERE, |
1846 base::Bind(&GetCurrentFrameAndSignal, base::Unretained(compositor_), | 1863 base::Bind(&GetCurrentFrameAndSignal, base::Unretained(compositor_), |
1847 &video_frame, &event)); | 1864 &video_frame, &event)); |
1848 event.Wait(); | 1865 event.Wait(); |
| 1866 |
| 1867 if (!video_frame) { |
| 1868 return nullptr; |
| 1869 } |
| 1870 last_uploaded_frame_size_ = video_frame->natural_size(); |
| 1871 last_uploaded_frame_timestamp_ = video_frame->timestamp(); |
1849 return video_frame; | 1872 return video_frame; |
1850 } | 1873 } |
1851 | 1874 |
1852 void WebMediaPlayerImpl::UpdatePlayState() { | 1875 void WebMediaPlayerImpl::UpdatePlayState() { |
1853 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1876 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1854 | 1877 |
1855 #if defined(OS_ANDROID) // WMPI_CAST | 1878 #if defined(OS_ANDROID) // WMPI_CAST |
1856 bool is_remote = isRemote(); | 1879 bool is_remote = isRemote(); |
1857 bool can_auto_suspend = true; | 1880 bool can_auto_suspend = true; |
1858 #else | 1881 #else |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 | 2355 |
2333 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { | 2356 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { |
2334 DCHECK(data_source_ || chunk_demuxer_); | 2357 DCHECK(data_source_ || chunk_demuxer_); |
2335 if (data_source_) | 2358 if (data_source_) |
2336 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); | 2359 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); |
2337 else | 2360 else |
2338 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); | 2361 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); |
2339 } | 2362 } |
2340 | 2363 |
2341 } // namespace media | 2364 } // namespace media |
OLD | NEW |