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

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

Issue 1871553003: [chrome.displaySource][WiFi Display] Send media stream to sink (renderer part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_pipeline
Patch Set: Created 4 years, 8 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 _pipeline.h" 5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media _pipeline.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "content/public/renderer/video_encode_accelerator.h" 9 #include "content/public/renderer/video_encode_accelerator.h"
10 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_eleme ntary_stream_descriptor.h" 10 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_eleme ntary_stream_descriptor.h"
11 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_eleme ntary_stream_info.h" 11 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_eleme ntary_stream_info.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 namespace { 15 namespace {
16 16
17 const char kErrorVideoEncoderError[] = "Unrepairable video encoder error"; 17 const char kErrorVideoEncoderError[] = "Unrepairable video encoder error";
18 const char kErrorUnableSendMedia[] = "Unable to send media";
18 19
19 } // namespace 20 } // namespace
20 21
21 WiFiDisplayMediaPipeline::WiFiDisplayMediaPipeline( 22 WiFiDisplayMediaPipeline::WiFiDisplayMediaPipeline(
22 wds::SessionType type, 23 wds::SessionType type,
23 const WiFiDisplayVideoEncoder::InitParameters& video_parameters, 24 const WiFiDisplayVideoEncoder::InitParameters& video_parameters,
24 const wds::AudioCodec& audio_codec, 25 const wds::AudioCodec& audio_codec,
26 const std::string& sink_ip_address,
27 const std::pair<int, int>& sink_rtp_ports,
28 const RegisterMediaServiceCallback& service_callback,
25 const ErrorCallback& error_callback) 29 const ErrorCallback& error_callback)
26 : type_(type), 30 : type_(type),
27 video_parameters_(video_parameters), 31 video_parameters_(video_parameters),
28 audio_codec_(audio_codec), 32 audio_codec_(audio_codec),
33 sink_ip_address_(sink_ip_address),
34 sink_rtp_ports_(sink_rtp_ports),
35 service_callback_(service_callback),
29 error_callback_(error_callback), 36 error_callback_(error_callback),
30 weak_factory_(this) { 37 weak_factory_(this) {
31 } 38 }
32 39
33 // static 40 // static
34 std::unique_ptr<WiFiDisplayMediaPipeline> WiFiDisplayMediaPipeline::Create( 41 std::unique_ptr<WiFiDisplayMediaPipeline> WiFiDisplayMediaPipeline::Create(
35 wds::SessionType type, 42 wds::SessionType type,
36 const WiFiDisplayVideoEncoder::InitParameters& video_parameters, 43 const WiFiDisplayVideoEncoder::InitParameters& video_parameters,
37 const wds::AudioCodec& audio_codec, 44 const wds::AudioCodec& audio_codec,
45 const std::string& sink_ip_address,
46 const std::pair<int, int>& sink_rtp_ports,
47 const RegisterMediaServiceCallback& service_callback,
38 const ErrorCallback& error_callback) { 48 const ErrorCallback& error_callback) {
39 return std::unique_ptr<WiFiDisplayMediaPipeline>( 49 return std::unique_ptr<WiFiDisplayMediaPipeline>(
40 new WiFiDisplayMediaPipeline(type, 50 new WiFiDisplayMediaPipeline(type,
41 video_parameters, 51 video_parameters,
42 audio_codec, 52 audio_codec,
53 sink_ip_address,
54 sink_rtp_ports,
55 service_callback,
43 error_callback)); 56 error_callback));
44 } 57 }
45 58
46 WiFiDisplayMediaPipeline::~WiFiDisplayMediaPipeline() { 59 WiFiDisplayMediaPipeline::~WiFiDisplayMediaPipeline() {
47 } 60 }
48 61
49 void WiFiDisplayMediaPipeline::InsertRawVideoFrame( 62 void WiFiDisplayMediaPipeline::InsertRawVideoFrame(
50 const scoped_refptr<media::VideoFrame>& video_frame, 63 const scoped_refptr<media::VideoFrame>& video_frame,
51 base::TimeTicks reference_time) { 64 base::TimeTicks reference_time) {
52 DCHECK(video_encoder_); 65 DCHECK(video_encoder_);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (!video_encoder) { 134 if (!video_encoder) {
122 init_completion_callback_.Run(false); 135 init_completion_callback_.Run(false);
123 return; 136 return;
124 } 137 }
125 video_encoder_ = std::move(video_encoder); 138 video_encoder_ = std::move(video_encoder);
126 auto encoded_callback = base::Bind( 139 auto encoded_callback = base::Bind(
127 &WiFiDisplayMediaPipeline::OnEncodedVideoFrame, 140 &WiFiDisplayMediaPipeline::OnEncodedVideoFrame,
128 weak_factory_.GetWeakPtr()); 141 weak_factory_.GetWeakPtr());
129 auto error_callback = base::Bind(error_callback_, kErrorVideoEncoderError); 142 auto error_callback = base::Bind(error_callback_, kErrorVideoEncoderError);
130 video_encoder_->SetCallbacks(encoded_callback, error_callback); 143 video_encoder_->SetCallbacks(encoded_callback, error_callback);
144
145 service_callback_.Run(
146 mojo::GetProxy(&media_service_),
147 base::Bind(&WiFiDisplayMediaPipeline::OnMediaServiceRegistered,
148 base::Unretained(this)));
149 }
150
151 void WiFiDisplayMediaPipeline::OnMediaServiceRegistered() {
152 DCHECK(media_service_);
153 auto error_callback = base::Bind(error_callback_, kErrorUnableSendMedia);
154 media_service_.set_connection_error_handler(error_callback);
155 media_service_->SetDesinationPoint(
156 sink_ip_address_, static_cast<int32_t>(sink_rtp_ports_.first));
131 init_completion_callback_.Run(true); 157 init_completion_callback_.Run(true);
132 } 158 }
133 159
134 void WiFiDisplayMediaPipeline::OnEncodedVideoFrame( 160 void WiFiDisplayMediaPipeline::OnEncodedVideoFrame(
135 const WiFiDisplayEncodedFrame& frame) { 161 const WiFiDisplayEncodedFrame& frame) {
136 DCHECK(packetizer_); 162 DCHECK(packetizer_);
137 if (!packetizer_->EncodeElementaryStreamUnit( 163 if (!packetizer_->EncodeElementaryStreamUnit(
138 0u, frame.bytes(), frame.data.size(), frame.key_frame, frame.pts, 164 0u, frame.bytes(), frame.data.size(), frame.key_frame, frame.pts,
139 frame.dts, true)) { 165 frame.dts, true)) {
140 DVLOG(1) << "Couldn't write video mpegts packet"; 166 DVLOG(1) << "Couldn't write video mpegts packet";
141 } 167 }
142 } 168 }
143 169
144 bool WiFiDisplayMediaPipeline::OnPacketizedMediaDatagramPacket( 170 bool WiFiDisplayMediaPipeline::OnPacketizedMediaDatagramPacket(
145 WiFiDisplayMediaDatagramPacket media_datagram_packet) { 171 WiFiDisplayMediaDatagramPacket media_datagram_packet) {
146 NOTIMPLEMENTED(); 172 DCHECK(media_service_);
173 media_service_->SendMediaPacket(std::move(media_datagram_packet));
147 return true; 174 return true;
148 } 175 }
149 176
150 } // namespace extensions 177 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698