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

Side by Side Diff: extensions/renderer/api/display_source/wifi_display/wifi_display_media_manager.cc

Issue 1783843002: [chrome.displaySource][WiFi Display] Video formats capability negotiation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@export_video_format
Patch Set: rebased Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h" 5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "content/public/renderer/media_stream_api.h"
9 10
10 namespace extensions { 11 namespace extensions {
11 12
12 WiFiDisplayMediaManager::WiFiDisplayMediaManager() { 13 namespace {
14
15 const char kErrorNoVideoFormatData[] =
16 "Failed to get video format data from the given MediaStreamTrack object";
17 const char kErrorSinkCannotPlayVideo[] =
18 "The sink cannot play video from the given MediaStreamTrack object";
19
20 } // namespace
21
22 WiFiDisplayMediaManager::WiFiDisplayMediaManager(
23 const blink::WebMediaStreamTrack& video_track,
24 const blink::WebMediaStreamTrack& audio_track,
25 const ErrorCallback& error_callback)
26 : video_track_(video_track),
27 audio_track_(audio_track),
28 error_callback_(error_callback) {
29 DCHECK(!video_track.isNull() || !audio_track.isNull());
30 DCHECK(!error_callback_.is_null());
13 } 31 }
14 32
15 WiFiDisplayMediaManager::~WiFiDisplayMediaManager() { 33 WiFiDisplayMediaManager::~WiFiDisplayMediaManager() {
16 } 34 }
17 35
18 void WiFiDisplayMediaManager::Play() { 36 void WiFiDisplayMediaManager::Play() {
19 NOTIMPLEMENTED(); 37 NOTIMPLEMENTED();
20 } 38 }
21 39
22 void WiFiDisplayMediaManager::Teardown() { 40 void WiFiDisplayMediaManager::Teardown() {
23 NOTIMPLEMENTED(); 41 NOTIMPLEMENTED();
24 } 42 }
25 43
26 void WiFiDisplayMediaManager::Pause() { 44 void WiFiDisplayMediaManager::Pause() {
27 NOTIMPLEMENTED(); 45 NOTIMPLEMENTED();
28 } 46 }
29 47
30 bool WiFiDisplayMediaManager::IsPaused() const { 48 bool WiFiDisplayMediaManager::IsPaused() const {
31 NOTIMPLEMENTED(); 49 NOTIMPLEMENTED();
32 return true; 50 return true;
33 } 51 }
34 52
35 wds::SessionType WiFiDisplayMediaManager::GetSessionType() const { 53 wds::SessionType WiFiDisplayMediaManager::GetSessionType() const {
36 NOTIMPLEMENTED(); 54 unsigned session_type = 0;
asargent_no_longer_on_chrome 2016/03/16 21:29:57 Should this be an explicitly sized type like uint3
37 return wds::AudioVideoSession; 55 if (!video_track_.isNull())
56 session_type |= wds::VideoSession;
57
58 if (!audio_track_.isNull())
59 session_type |= wds::AudioSession;
60
61 return static_cast<wds::SessionType>(session_type);
38 } 62 }
39 63
40 void WiFiDisplayMediaManager::SetSinkRtpPorts(int port1, int port2) { 64 void WiFiDisplayMediaManager::SetSinkRtpPorts(int port1, int port2) {
41 NOTIMPLEMENTED(); 65 sink_rtp_ports_ = std::pair<int,int>(port1, port2);
42 } 66 }
43 67
44 std::pair<int,int> WiFiDisplayMediaManager::GetSinkRtpPorts() const { 68 std::pair<int,int> WiFiDisplayMediaManager::GetSinkRtpPorts() const {
45 NOTIMPLEMENTED(); 69 return sink_rtp_ports_;
46 return std::pair<int,int>();
47 } 70 }
48 71
49 int WiFiDisplayMediaManager::GetLocalRtpPort() const { 72 int WiFiDisplayMediaManager::GetLocalRtpPort() const {
50 NOTIMPLEMENTED(); 73 NOTIMPLEMENTED();
51 return 0; 74 return 0;
52 } 75 }
53 76
77 namespace {
78 struct VideoFormat {
79 wds::RateAndResolution rr;
80 int width;
81 int height;
82 int frame_rate;
83 };
84
85 const VideoFormat cea_table[] = {
86 {wds::CEA640x480p60, 640, 480, 60},
87 {wds::CEA720x480p60, 720, 480, 60},
88 {wds::CEA720x576p50, 720, 576, 50},
89 {wds::CEA1280x720p30, 1280, 720, 30},
90 {wds::CEA1280x720p60, 1280, 720, 60},
91 {wds::CEA1920x1080p30, 1920, 1080, 30},
92 {wds::CEA1920x1080p60, 1920, 1080, 60},
93 {wds::CEA1280x720p25, 1280, 720, 25},
94 {wds::CEA1280x720p50, 1280, 720, 50},
95 {wds::CEA1920x1080p25, 1920, 1080, 25},
96 {wds::CEA1920x1080p50, 1920, 1080, 50},
97 {wds::CEA1280x720p24, 1280, 720, 24},
98 {wds::CEA1920x1080p24, 1920, 1080, 24}
99 };
100
101 const VideoFormat vesa_table[] = {
102 {wds::VESA800x600p30, 800, 600, 30},
103 {wds::VESA800x600p60, 800, 600, 60},
104 {wds::VESA1024x768p30, 1024, 768, 30},
105 {wds::VESA1024x768p60, 1024, 768, 60},
106 {wds::VESA1152x864p30, 1152, 864, 30},
107 {wds::VESA1152x864p60, 1152, 864, 60},
108 {wds::VESA1280x768p30, 1280, 768, 30},
109 {wds::VESA1280x768p60, 1280, 768, 60},
110 {wds::VESA1280x800p30, 1280, 800, 30},
111 {wds::VESA1280x800p60, 1280, 800, 60},
112 {wds::VESA1360x768p30, 1360, 768, 30},
113 {wds::VESA1360x768p60, 1360, 768, 60},
114 {wds::VESA1366x768p30, 1366, 768, 30},
115 {wds::VESA1366x768p60, 1366, 768, 60},
116 {wds::VESA1280x1024p30, 1280, 1024, 30},
117 {wds::VESA1280x1024p60, 1280, 1024, 60},
118 {wds::VESA1400x1050p30, 1400, 1050, 30},
119 {wds::VESA1400x1050p60, 1400, 1050, 60},
120 {wds::VESA1440x900p30, 1440, 900, 30},
121 {wds::VESA1440x900p60, 1440, 900, 60},
122 {wds::VESA1600x900p30, 1600, 900, 30},
123 {wds::VESA1600x900p60, 1600, 900, 60},
124 {wds::VESA1600x1200p30, 1600, 1200, 30},
125 {wds::VESA1600x1200p60, 1600, 1200, 60},
126 {wds::VESA1680x1024p30, 1680, 1024, 30},
127 {wds::VESA1680x1024p60, 1680, 1024, 60},
128 {wds::VESA1680x1050p30, 1680, 1050, 30},
129 {wds::VESA1680x1050p60, 1680, 1050, 60},
130 {wds::VESA1920x1200p30, 1920, 1200, 30}
131 };
132
133 const VideoFormat hh_table[] = {
134 {wds::HH800x480p30, 800, 480, 30},
135 {wds::HH800x480p60, 800, 480, 60},
136 {wds::HH854x480p30, 854, 480, 30},
137 {wds::HH854x480p60, 854, 480, 60},
138 {wds::HH864x480p30, 864, 480, 30},
139 {wds::HH864x480p60, 864, 480, 60},
140 {wds::HH640x360p30, 640, 360, 30},
141 {wds::HH640x360p60, 640, 360, 60},
142 {wds::HH960x540p30, 960, 540, 30},
143 {wds::HH960x540p60, 960, 540, 60},
144 {wds::HH848x480p30, 848, 480, 30},
145 {wds::HH848x480p60, 848, 480, 60}
146 };
147
148 template <wds::ResolutionType type, unsigned N>
149 bool FindRateResolution(const media::VideoCaptureFormat* format,
150 const wds::RateAndResolutionsBitmap& bitmap,
151 const VideoFormat (&table)[N],
152 wds::H264VideoFormat* result /*out*/) {
153 for (unsigned i = 0; i < N; ++i) {
154 if (bitmap.test(table[i].rr)) {
155 if (format->frame_size.width() == table[i].width &&
156 format->frame_size.height() == table[i].height &&
157 format->frame_rate == table[i].frame_rate) {
158 result->rate_resolution = table[i].rr;
159 result->type = type;
160 return true;
161 }
162 }
163 }
164 return false;
165 }
166
167 bool FindOptimalFormat(
168 const media::VideoCaptureFormat* capture_format,
169 const std::vector<wds::H264VideoCodec>& sink_supported_codecs,
170 wds::H264VideoFormat* result /*out*/) {
171 DCHECK(result);
172 for (const wds::H264VideoCodec& codec : sink_supported_codecs) {
173 bool found =
174 FindRateResolution<wds::CEA>(
175 capture_format, codec.cea_rr, cea_table, result) ||
176 FindRateResolution<wds::VESA>(
177 capture_format, codec.vesa_rr, vesa_table, result) ||
178 FindRateResolution<wds::HH>(
179 capture_format, codec.hh_rr, hh_table, result);
180 if (found) {
181 result->profile = codec.profile;
182 result->level = codec.level;
183 return true;
184 }
185 }
186 return false;
187 }
188
189 } // namespace
190
54 wds::H264VideoFormat WiFiDisplayMediaManager::GetOptimalVideoFormat() const { 191 wds::H264VideoFormat WiFiDisplayMediaManager::GetOptimalVideoFormat() const {
55 NOTIMPLEMENTED(); 192 return optimal_video_format_;
56 return wds::H264VideoFormat();
57 } 193 }
58 194
59 void WiFiDisplayMediaManager::SendIDRPicture() { 195 void WiFiDisplayMediaManager::SendIDRPicture() {
60 NOTIMPLEMENTED(); 196 NOTIMPLEMENTED();
61 } 197 }
62 198
63 std::string WiFiDisplayMediaManager::GetSessionId() const { 199 std::string WiFiDisplayMediaManager::GetSessionId() const {
64 return base::RandBytesAsString(8); 200 return base::RandBytesAsString(8);
65 } 201 }
66 202
67 bool WiFiDisplayMediaManager::InitOptimalVideoFormat( 203 bool WiFiDisplayMediaManager::InitOptimalVideoFormat(
68 const wds::NativeVideoFormat& sink_native_format, 204 const wds::NativeVideoFormat& sink_native_format,
69 const std::vector<wds::H264VideoCodec>& sink_supported_codecs) { 205 const std::vector<wds::H264VideoCodec>& sink_supported_codecs) {
70 NOTIMPLEMENTED(); 206 const media::VideoCaptureFormat* capture_format =
71 return false; 207 content::GetCurrentVideoTrackFormat(video_track_);
208 if (!capture_format) {
209 error_callback_.Run(kErrorNoVideoFormatData);
210 return false;
211 }
212
213 if (!FindOptimalFormat(
214 capture_format, sink_supported_codecs, &optimal_video_format_)) {
215 error_callback_.Run(kErrorSinkCannotPlayVideo);
216 return false;
217 }
218
219 return true;
72 } 220 }
73 221
74 bool WiFiDisplayMediaManager::InitOptimalAudioFormat( 222 bool WiFiDisplayMediaManager::InitOptimalAudioFormat(
75 const std::vector<wds::AudioCodec>& sink_codecs) { 223 const std::vector<wds::AudioCodec>& sink_codecs) {
76 NOTIMPLEMENTED(); 224 NOTIMPLEMENTED();
77 return false; 225 return false;
78 } 226 }
79 227
80 wds::AudioCodec WiFiDisplayMediaManager::GetOptimalAudioFormat() const { 228 wds::AudioCodec WiFiDisplayMediaManager::GetOptimalAudioFormat() const {
81 NOTIMPLEMENTED(); 229 NOTIMPLEMENTED();
82 return wds::AudioCodec(); 230 return wds::AudioCodec();
83 } 231 }
84 232
85 } // namespace extensions 233 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698