| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/media/webrtc/media_stream_remote_video_source.h" | 5 #include "content/renderer/media/webrtc/media_stream_remote_video_source.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "content/renderer/media/webrtc/track_observer.h" | 14 #include "content/renderer/media/webrtc/track_observer.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/timestamp_constants.h" | 16 #include "media/base/timestamp_constants.h" |
| 17 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 18 #include "media/base/video_util.h" | 18 #include "media/base/video_util.h" |
| 19 #include "third_party/webrtc/media/base/videoframe.h" | 19 #include "third_party/webrtc/media/base/videoframe.h" |
| 20 #include "third_party/webrtc/media/base/videosinkinterface.h" | 20 #include "third_party/webrtc/media/base/videosinkinterface.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 namespace { |
| 25 |
| 26 media::VideoRotation WebRTCToMediaVideoRotation( |
| 27 webrtc::VideoRotation rotation) { |
| 28 switch (rotation) { |
| 29 case webrtc::kVideoRotation_0: |
| 30 return media::VIDEO_ROTATION_0; |
| 31 case webrtc::kVideoRotation_90: |
| 32 return media::VIDEO_ROTATION_90; |
| 33 case webrtc::kVideoRotation_180: |
| 34 return media::VIDEO_ROTATION_180; |
| 35 case webrtc::kVideoRotation_270: |
| 36 return media::VIDEO_ROTATION_270; |
| 37 } |
| 38 return media::VIDEO_ROTATION_0; |
| 39 } |
| 40 |
| 41 } // anonymous namespace |
| 42 |
| 24 // Internal class used for receiving frames from the webrtc track on a | 43 // Internal class used for receiving frames from the webrtc track on a |
| 25 // libjingle thread and forward it to the IO-thread. | 44 // libjingle thread and forward it to the IO-thread. |
| 26 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate | 45 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate |
| 27 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, | 46 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, |
| 28 public rtc::VideoSinkInterface<cricket::VideoFrame> { | 47 public rtc::VideoSinkInterface<cricket::VideoFrame> { |
| 29 public: | 48 public: |
| 30 RemoteVideoSourceDelegate( | 49 RemoteVideoSourceDelegate( |
| 31 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 50 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 32 const VideoCaptureDeliverFrameCB& new_frame_callback); | 51 const VideoCaptureDeliverFrameCB& new_frame_callback); |
| 33 | 52 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (start_timestamp_ == media::kNoTimestamp()) | 109 if (start_timestamp_ == media::kNoTimestamp()) |
| 91 start_timestamp_ = incoming_timestamp; | 110 start_timestamp_ = incoming_timestamp; |
| 92 const base::TimeDelta elapsed_timestamp = | 111 const base::TimeDelta elapsed_timestamp = |
| 93 incoming_timestamp - start_timestamp_; | 112 incoming_timestamp - start_timestamp_; |
| 94 | 113 |
| 95 scoped_refptr<media::VideoFrame> video_frame; | 114 scoped_refptr<media::VideoFrame> video_frame; |
| 96 scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 115 scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
| 97 incoming_frame.video_frame_buffer()); | 116 incoming_frame.video_frame_buffer()); |
| 98 | 117 |
| 99 if (buffer->native_handle() != NULL) { | 118 if (buffer->native_handle() != NULL) { |
| 100 video_frame = | 119 video_frame = static_cast<media::VideoFrame*>(buffer->native_handle()); |
| 101 static_cast<media::VideoFrame*>(buffer->native_handle()); | |
| 102 video_frame->set_timestamp(elapsed_timestamp); | 120 video_frame->set_timestamp(elapsed_timestamp); |
| 121 if (incoming_frame.rotation() != webrtc::kVideoRotation_0) { |
| 122 video_frame->metadata()->SetRotation( |
| 123 media::VideoFrameMetadata::ROTATION, |
| 124 WebRTCToMediaVideoRotation(incoming_frame.rotation())); |
| 125 } |
| 103 } else { | 126 } else { |
| 104 // Note that the GetCopyWithRotationApplied returns a pointer to a | 127 // Note that the GetCopyWithRotationApplied returns a pointer to a |
| 105 // frame owned by incoming_frame. | 128 // frame owned by incoming_frame. |
| 106 buffer = | 129 buffer = |
| 107 incoming_frame.GetCopyWithRotationApplied()->video_frame_buffer(); | 130 incoming_frame.GetCopyWithRotationApplied()->video_frame_buffer(); |
| 108 gfx::Size size(buffer->width(), buffer->height()); | 131 gfx::Size size(buffer->width(), buffer->height()); |
| 109 | 132 |
| 110 // Make a shallow copy. Both |frame| and |video_frame| will share a single | 133 // Make a shallow copy. Both |frame| and |video_frame| will share a single |
| 111 // reference counted frame buffer. Const cast and hope no one will overwrite | 134 // reference counted frame buffer. Const cast and hope no one will overwrite |
| 112 // the data. | 135 // the data. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 case webrtc::MediaStreamTrackInterface::kEnded: | 242 case webrtc::MediaStreamTrackInterface::kEnded: |
| 220 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 243 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 221 break; | 244 break; |
| 222 default: | 245 default: |
| 223 NOTREACHED(); | 246 NOTREACHED(); |
| 224 break; | 247 break; |
| 225 } | 248 } |
| 226 } | 249 } |
| 227 | 250 |
| 228 } // namespace content | 251 } // namespace content |
| OLD | NEW |