OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "media/base/demuxer.h" | 12 #include "media/base/demuxer.h" |
13 #include "media/base/filter_host.h" | |
14 #include "media/base/filters.h" | 13 #include "media/base/filters.h" |
15 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
16 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
17 #include "media/base/video_util.h" | 16 #include "media/base/video_util.h" |
18 #include "third_party/libjingle/source/talk/session/phone/videoframe.h" | 17 #include "third_party/libjingle/source/talk/session/phone/videoframe.h" |
19 | 18 |
20 using media::CopyUPlane; | 19 using media::CopyUPlane; |
21 using media::CopyVPlane; | 20 using media::CopyVPlane; |
22 using media::CopyYPlane; | 21 using media::CopyYPlane; |
23 using media::DemuxerStream; | 22 using media::DemuxerStream; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 base::AutoLock auto_lock(lock_); | 99 base::AutoLock auto_lock(lock_); |
101 if (!read_cb_.is_null()) { | 100 if (!read_cb_.is_null()) { |
102 std::swap(read_cb, read_cb_); | 101 std::swap(read_cb, read_cb_); |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 if (!read_cb.is_null()) { | 105 if (!read_cb.is_null()) { |
107 scoped_refptr<media::VideoFrame> video_frame = | 106 scoped_refptr<media::VideoFrame> video_frame = |
108 media::VideoFrame::CreateBlackFrame(visible_size_.width(), | 107 media::VideoFrame::CreateBlackFrame(visible_size_.width(), |
109 visible_size_.height()); | 108 visible_size_.height()); |
110 read_cb.Run(video_frame); | 109 read_cb.Run(kOk, video_frame); |
111 } | 110 } |
112 | 111 |
113 VideoDecoder::Flush(callback); | 112 VideoDecoder::Flush(callback); |
114 } | 113 } |
115 | 114 |
116 void RTCVideoDecoder::Stop(const base::Closure& callback) { | 115 void RTCVideoDecoder::Stop(const base::Closure& callback) { |
117 if (MessageLoop::current() != message_loop_) { | 116 if (MessageLoop::current() != message_loop_) { |
118 message_loop_->PostTask(FROM_HERE, | 117 message_loop_->PostTask(FROM_HERE, |
119 base::Bind(&RTCVideoDecoder::Stop, | 118 base::Bind(&RTCVideoDecoder::Stop, |
120 this, callback)); | 119 this, callback)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 read_cb_ = callback; | 153 read_cb_ = callback; |
155 } | 154 } |
156 | 155 |
157 const gfx::Size& RTCVideoDecoder::natural_size() { | 156 const gfx::Size& RTCVideoDecoder::natural_size() { |
158 // TODO(vrk): Return natural size when aspect ratio support is implemented. | 157 // TODO(vrk): Return natural size when aspect ratio support is implemented. |
159 return visible_size_; | 158 return visible_size_; |
160 } | 159 } |
161 | 160 |
162 bool RTCVideoDecoder::SetSize(int width, int height, int reserved) { | 161 bool RTCVideoDecoder::SetSize(int width, int height, int reserved) { |
163 visible_size_.SetSize(width, height); | 162 visible_size_.SetSize(width, height); |
164 | |
165 // TODO(vrk): Provide natural size when aspect ratio support is implemented. | |
166 | |
167 // TODO(xhwang) host() can be NULL after r128289. Remove this check when | |
168 // it is no longer needed. | |
169 if (host()) | |
170 host()->SetNaturalVideoSize(visible_size_); | |
171 return true; | 163 return true; |
172 } | 164 } |
173 | 165 |
174 // TODO(wjia): this function can be split into two parts so that the |lock_| | 166 // TODO(wjia): this function can be split into two parts so that the |lock_| |
175 // can be removed. | 167 // can be removed. |
176 // First creates media::VideoFrame, then post a task onto |message_loop_| | 168 // First creates media::VideoFrame, then post a task onto |message_loop_| |
177 // to deliver that frame. | 169 // to deliver that frame. |
178 bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { | 170 bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { |
179 // Called from libjingle thread. | 171 // Called from libjingle thread. |
180 DCHECK(frame); | 172 DCHECK(frame); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Aspect ratio unsupported; DCHECK when there are non-square pixels. | 209 // Aspect ratio unsupported; DCHECK when there are non-square pixels. |
218 DCHECK_EQ(frame->GetPixelWidth(), 1u); | 210 DCHECK_EQ(frame->GetPixelWidth(), 1u); |
219 DCHECK_EQ(frame->GetPixelHeight(), 1u); | 211 DCHECK_EQ(frame->GetPixelHeight(), 1u); |
220 | 212 |
221 int y_rows = frame->GetHeight(); | 213 int y_rows = frame->GetHeight(); |
222 int uv_rows = frame->GetHeight() / 2; // YV12 format. | 214 int uv_rows = frame->GetHeight() / 2; // YV12 format. |
223 CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame); | 215 CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame); |
224 CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame); | 216 CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame); |
225 CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame); | 217 CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame); |
226 | 218 |
227 read_cb.Run(video_frame); | 219 read_cb.Run(kOk, video_frame); |
228 return true; | 220 return true; |
229 } | 221 } |
OLD | NEW |