| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "remoting/client/decoder_verbatim.h" | 5 #include "remoting/client/decoder_verbatim.h" |
| 6 | 6 |
| 7 #include "remoting/base/protocol_util.h" |
| 8 |
| 7 namespace remoting { | 9 namespace remoting { |
| 8 | 10 |
| 9 DecoderVerbatim::DecoderVerbatim() | 11 DecoderVerbatim::DecoderVerbatim() |
| 10 : updated_rects_(NULL) { | 12 : updated_rects_(NULL) { |
| 11 } | 13 } |
| 12 | 14 |
| 13 bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame, | 15 bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame, |
| 14 UpdatedRects* updated_rects, | 16 UpdatedRects* updated_rects, |
| 15 Task* partial_decode_done, | 17 Task* partial_decode_done, |
| 16 Task* decode_done) { | 18 Task* decode_done) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 | 32 |
| 31 bool DecoderVerbatim::PartialDecode(HostMessage* message) { | 33 bool DecoderVerbatim::PartialDecode(HostMessage* message) { |
| 32 scoped_ptr<HostMessage> msg_deleter(message); | 34 scoped_ptr<HostMessage> msg_deleter(message); |
| 33 | 35 |
| 34 int width = message->update_stream_packet().header().width(); | 36 int width = message->update_stream_packet().header().width(); |
| 35 int height = message->update_stream_packet().header().height(); | 37 int height = message->update_stream_packet().header().height(); |
| 36 int x = message->update_stream_packet().header().x(); | 38 int x = message->update_stream_packet().header().x(); |
| 37 int y = message->update_stream_packet().header().y(); | 39 int y = message->update_stream_packet().header().y(); |
| 38 PixelFormat pixel_format = | 40 PixelFormat pixel_format = |
| 39 message->update_stream_packet().header().pixel_format(); | 41 message->update_stream_packet().header().pixel_format(); |
| 40 int bytes_per_pixel = 0; | |
| 41 | |
| 42 // TODO(hclam): Extract the following to an util function. | |
| 43 if (pixel_format == PixelFormatRgb24) { | |
| 44 bytes_per_pixel = 3; | |
| 45 } else if (pixel_format == PixelFormatRgb565) { | |
| 46 bytes_per_pixel = 2; | |
| 47 } else if (pixel_format == PixelFormatRgb32) { | |
| 48 bytes_per_pixel = 4; | |
| 49 } else if (pixel_format == PixelFormatAscii) { | |
| 50 bytes_per_pixel = 1; | |
| 51 } else { | |
| 52 NOTREACHED() << "Pixel format not supported"; | |
| 53 } | |
| 54 | 42 |
| 55 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { | 43 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { |
| 56 NOTREACHED() << "Pixel format of message doesn't match the video frame. " | 44 NOTREACHED() << "Pixel format of message doesn't match the video frame. " |
| 57 "Expected vs received = " | 45 "Expected vs received = " |
| 58 << frame_->format() << " vs " << pixel_format | 46 << frame_->format() << " vs " << pixel_format |
| 59 << " Color space conversion required."; | 47 << " Color space conversion required."; |
| 60 } | 48 } |
| 61 | 49 |
| 50 int bytes_per_pixel = GetBytesPerPixel(pixel_format); |
| 62 // Copy the data line by line. | 51 // Copy the data line by line. |
| 63 const int src_stride = bytes_per_pixel * width; | 52 const int src_stride = bytes_per_pixel * width; |
| 64 const char* src = message->update_stream_packet().data().c_str(); | 53 const char* src = message->update_stream_packet().data().c_str(); |
| 65 const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane); | 54 const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane); |
| 66 uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) + | 55 uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) + |
| 67 dest_stride * y + bytes_per_pixel * x; | 56 dest_stride * y + bytes_per_pixel * x; |
| 68 for (int i = 0; i < height; ++i) { | 57 for (int i = 0; i < height; ++i) { |
| 69 memcpy(dest, src, src_stride); | 58 memcpy(dest, src, src_stride); |
| 70 dest += dest_stride; | 59 dest += dest_stride; |
| 71 src += src_stride; | 60 src += src_stride; |
| 72 } | 61 } |
| 73 | 62 |
| 74 updated_rects_->clear(); | 63 updated_rects_->clear(); |
| 75 updated_rects_->push_back(gfx::Rect(x, y, width, height)); | 64 updated_rects_->push_back(gfx::Rect(x, y, width, height)); |
| 76 partial_decode_done_->Run(); | 65 partial_decode_done_->Run(); |
| 77 return true; | 66 return true; |
| 78 } | 67 } |
| 79 | 68 |
| 80 void DecoderVerbatim::EndDecode() { | 69 void DecoderVerbatim::EndDecode() { |
| 81 decode_done_->Run(); | 70 decode_done_->Run(); |
| 82 | 71 |
| 83 partial_decode_done_.reset(); | 72 partial_decode_done_.reset(); |
| 84 decode_done_.reset(); | 73 decode_done_.reset(); |
| 85 frame_ = NULL; | 74 frame_ = NULL; |
| 86 updated_rects_ = NULL; | 75 updated_rects_ = NULL; |
| 87 } | 76 } |
| 88 | 77 |
| 89 } // namespace remoting | 78 } // namespace remoting |
| OLD | NEW |