diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 23:09:56 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 23:09:56 +0000 |
commit | b2579c047080258aecf3cfcfc15c750590f25187 (patch) | |
tree | 10900e71ada6b371b1e4c1d37be45ab7f21b2a6c /content | |
parent | 992e454546e7592443c1967c3e5b9262420f2ae0 (diff) | |
download | chromium_src-b2579c047080258aecf3cfcfc15c750590f25187.zip chromium_src-b2579c047080258aecf3cfcfc15c750590f25187.tar.gz chromium_src-b2579c047080258aecf3cfcfc15c750590f25187.tar.bz2 |
Deduplicate YUV copying code, update call sites, and add some unit tests.
Historically such code is a source of out-of-bound reads/writes.
TEST=media_unittests
Review URL: http://codereview.chromium.org/7452009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93276 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/renderer/media/rtc_video_decoder.cc | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc index 847091c..e96d3dc 100644 --- a/content/renderer/media/rtc_video_decoder.cc +++ b/content/renderer/media/rtc_video_decoder.cc @@ -13,7 +13,11 @@ #include "media/base/limits.h" #include "media/base/media_format.h" #include "media/base/video_frame.h" +#include "media/base/video_util.h" +using media::CopyUPlane; +using media::CopyVPlane; +using media::CopyYPlane; using media::DemuxerStream; using media::FilterCallback; using media::FilterStatusCB; @@ -199,28 +203,11 @@ bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { video_frame->SetTimestamp(host()->GetTime()); video_frame->SetDuration(base::TimeDelta::FromMilliseconds(30)); - // TODO(scherkus): deduplicate YUV copying code. - uint8* y_plane = video_frame->data(VideoFrame::kYPlane); - const uint8* y_plane_src = frame->GetYPlane(); - for (size_t row = 0; row < video_frame->height(); ++row) { - memcpy(y_plane, y_plane_src, frame->GetYPitch()); - y_plane += video_frame->stride(VideoFrame::kYPlane); - y_plane_src += frame->GetYPitch(); - } - uint8* u_plane = video_frame->data(VideoFrame::kUPlane); - const uint8* u_plane_src = frame->GetUPlane(); - for (size_t row = 0; row < video_frame->height(); row += 2) { - memcpy(u_plane, u_plane_src, frame->GetUPitch()); - u_plane += video_frame->stride(VideoFrame::kUPlane); - u_plane_src += frame->GetUPitch(); - } - uint8* v_plane = video_frame->data(VideoFrame::kVPlane); - const uint8* v_plane_src = frame->GetVPlane(); - for (size_t row = 0; row < video_frame->height(); row += 2) { - memcpy(v_plane, v_plane_src, frame->GetVPitch()); - v_plane += video_frame->stride(VideoFrame::kVPlane); - v_plane_src += frame->GetVPitch(); - } + int y_rows = frame->GetHeight(); + int uv_rows = frame->GetHeight() / 2; // YV12 format. + CopyYPlane(frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame); + CopyUPlane(frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame); + CopyVPlane(frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame); if (MessageLoop::current() != message_loop_) { message_loop_->PostTask( |