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 "chrome/renderer/media/cast_rtp_stream.h" | 5 #include "chrome/renderer/media/cast_rtp_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/renderer/media_stream_audio_sink.h" | 23 #include "content/public/renderer/media_stream_audio_sink.h" |
24 #include "content/public/renderer/media_stream_video_sink.h" | 24 #include "content/public/renderer/media_stream_video_sink.h" |
25 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
26 #include "content/public/renderer/video_encode_accelerator.h" | 26 #include "content/public/renderer/video_encode_accelerator.h" |
27 #include "media/audio/audio_parameters.h" | 27 #include "media/audio/audio_parameters.h" |
28 #include "media/base/audio_bus.h" | 28 #include "media/base/audio_bus.h" |
29 #include "media/base/audio_converter.h" | 29 #include "media/base/audio_converter.h" |
30 #include "media/base/bind_to_current_loop.h" | 30 #include "media/base/bind_to_current_loop.h" |
31 #include "media/base/limits.h" | 31 #include "media/base/limits.h" |
32 #include "media/base/video_frame.h" | 32 #include "media/base/video_frame.h" |
| 33 #include "media/base/video_util.h" |
33 #include "media/cast/cast_config.h" | 34 #include "media/cast/cast_config.h" |
34 #include "media/cast/cast_sender.h" | 35 #include "media/cast/cast_sender.h" |
35 #include "media/cast/net/cast_transport_config.h" | 36 #include "media/cast/net/cast_transport_config.h" |
36 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 37 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
37 #include "ui/gfx/geometry/size.h" | 38 #include "ui/gfx/geometry/size.h" |
38 | 39 |
39 using media::cast::AudioSenderConfig; | 40 using media::cast::AudioSenderConfig; |
40 using media::cast::VideoSenderConfig; | 41 using media::cast::VideoSenderConfig; |
41 | 42 |
42 namespace { | 43 namespace { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 if (sink_added_) | 316 if (sink_added_) |
316 RemoveFromVideoTrack(this, track_); | 317 RemoveFromVideoTrack(this, track_); |
317 } | 318 } |
318 | 319 |
319 // This static method is used to forward video frames to |frame_input|. | 320 // This static method is used to forward video frames to |frame_input|. |
320 static void OnVideoFrame( | 321 static void OnVideoFrame( |
321 // These parameters are already bound when callback is created. | 322 // These parameters are already bound when callback is created. |
322 const CastRtpStream::ErrorCallback& error_callback, | 323 const CastRtpStream::ErrorCallback& error_callback, |
323 const scoped_refptr<media::cast::VideoFrameInput> frame_input, | 324 const scoped_refptr<media::cast::VideoFrameInput> frame_input, |
324 // These parameters are passed for each frame. | 325 // These parameters are passed for each frame. |
325 const scoped_refptr<media::VideoFrame>& frame, | 326 const scoped_refptr<media::VideoFrame>& video_frame, |
326 base::TimeTicks estimated_capture_time) { | 327 base::TimeTicks estimated_capture_time) { |
327 const base::TimeTicks timestamp = estimated_capture_time.is_null() | 328 const base::TimeTicks timestamp = estimated_capture_time.is_null() |
328 ? base::TimeTicks::Now() | 329 ? base::TimeTicks::Now() |
329 : estimated_capture_time; | 330 : estimated_capture_time; |
330 | 331 |
| 332 if (!(video_frame->format() == media::PIXEL_FORMAT_I420 || |
| 333 video_frame->format() == media::PIXEL_FORMAT_YV12 || |
| 334 video_frame->format() == media::PIXEL_FORMAT_YV12A)) { |
| 335 NOTREACHED(); |
| 336 return; |
| 337 } |
| 338 scoped_refptr<media::VideoFrame> frame = video_frame; |
| 339 // Drop alpha channel since we do not support it yet. |
| 340 if (frame->format() == media::PIXEL_FORMAT_YV12A) |
| 341 frame = media::WrapAsI420VideoFrame(video_frame); |
| 342 |
331 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 343 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
332 TRACE_EVENT_INSTANT2( | 344 TRACE_EVENT_INSTANT2( |
333 "cast_perf_test", "MediaStreamVideoSink::OnVideoFrame", | 345 "cast_perf_test", "MediaStreamVideoSink::OnVideoFrame", |
334 TRACE_EVENT_SCOPE_THREAD, | 346 TRACE_EVENT_SCOPE_THREAD, |
335 "timestamp", timestamp.ToInternalValue(), | 347 "timestamp", timestamp.ToInternalValue(), |
336 "time_delta", frame->timestamp().ToInternalValue()); | 348 "time_delta", frame->timestamp().ToInternalValue()); |
337 frame_input->InsertRawVideoFrame(frame, timestamp); | 349 frame_input->InsertRawVideoFrame(frame, timestamp); |
338 } | 350 } |
339 | 351 |
340 // Attach this sink to a video track represented by |track_|. | 352 // Attach this sink to a video track represented by |track_|. |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 DCHECK(content::RenderThread::Get()); | 643 DCHECK(content::RenderThread::Get()); |
632 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " | 644 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " |
633 << (IsAudio() ? "audio" : "video"); | 645 << (IsAudio() ? "audio" : "video"); |
634 // Save the WeakPtr first because the error callback might delete this object. | 646 // Save the WeakPtr first because the error callback might delete this object. |
635 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 647 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
636 error_callback_.Run(message); | 648 error_callback_.Run(message); |
637 base::ThreadTaskRunnerHandle::Get()->PostTask( | 649 base::ThreadTaskRunnerHandle::Get()->PostTask( |
638 FROM_HERE, | 650 FROM_HERE, |
639 base::Bind(&CastRtpStream::Stop, ptr)); | 651 base::Bind(&CastRtpStream::Stop, ptr)); |
640 } | 652 } |
OLD | NEW |