Commit 7cb892de authored by magjed's avatar magjed Committed by Commit bot

PepperVideoSourceHost: Change endianness of color format of frames sent to the plugin

BUG=426020

Review URL: https://codereview.chromium.org/675513002

Cr-Commit-Position: refs/heads/master@{#302247}
parent c75d18e9
...@@ -73,7 +73,7 @@ void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO( ...@@ -73,7 +73,7 @@ void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO(
new_frame_callback_.Run(frame, format, base::TimeTicks()); new_frame_callback_.Run(frame, format, base::TimeTicks());
} }
PpFrameWriter::PpFrameWriter() : endian_(UNKNOWN) { PpFrameWriter::PpFrameWriter() {
DVLOG(3) << "PpFrameWriter ctor"; DVLOG(3) << "PpFrameWriter ctor";
} }
...@@ -157,46 +157,16 @@ void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data, ...@@ -157,46 +157,16 @@ void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data,
MediaStreamVideoSource::kUnknownFrameRate, MediaStreamVideoSource::kUnknownFrameRate,
media::PIXEL_FORMAT_YV12); media::PIXEL_FORMAT_YV12);
// TODO(magjed): Remove this and always use libyuv::ARGBToI420 when libyuv::ARGBToI420(src_data,
// crbug/426020 is fixed. src_stride,
// Due to a change in endianness, we try to determine it from the data. new_frame->data(media::VideoFrame::kYPlane),
// The alpha channel is always 255. It is unlikely for other color channels to new_frame->stride(media::VideoFrame::kYPlane),
// be 255, so we will most likely break on the first few pixels in the first new_frame->data(media::VideoFrame::kUPlane),
// frame. new_frame->stride(media::VideoFrame::kUPlane),
const uint8* row_ptr = src_data; new_frame->data(media::VideoFrame::kVPlane),
// Note that we only do this if endian_ is still UNKNOWN. new_frame->stride(media::VideoFrame::kVPlane),
for (int y = 0; y < height && endian_ == UNKNOWN; ++y) { width,
for (int x = 0; x < width; ++x) { height);
if (row_ptr[x * 4 + 0] != 255) { // First byte is not Alpha => XXXA.
endian_ = XXXA;
break;
}
if (row_ptr[x * 4 + 3] != 255) { // Fourth byte is not Alpha => AXXX.
endian_ = AXXX;
break;
}
}
row_ptr += src_stride;
}
if (endian_ == UNKNOWN) {
LOG(WARNING) << "PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO - "
<< "Could not determine endianness.";
}
// libyuv specifies fourcc/channel ordering the same as webrtc. That is why
// the naming is reversed compared to PixelEndian and PP_ImageDataFormat which
// describes the memory layout from the lowest address to the highest.
auto xxxxToI420 =
(endian_ == AXXX) ? &libyuv::BGRAToI420 : &libyuv::ARGBToI420;
xxxxToI420(src_data,
src_stride,
new_frame->data(media::VideoFrame::kYPlane),
new_frame->stride(media::VideoFrame::kYPlane),
new_frame->data(media::VideoFrame::kUPlane),
new_frame->stride(media::VideoFrame::kUPlane),
new_frame->data(media::VideoFrame::kVPlane),
new_frame->stride(media::VideoFrame::kVPlane),
width,
height);
delegate_->DeliverFrame(new_frame, format); delegate_->DeliverFrame(new_frame, format);
} }
......
...@@ -60,18 +60,10 @@ class CONTENT_EXPORT PpFrameWriter ...@@ -60,18 +60,10 @@ class CONTENT_EXPORT PpFrameWriter
void StopSourceImpl() override; void StopSourceImpl() override;
private: private:
// Endian in memory order, e.g. AXXX stands for uint8 pixel[4] = {A, x, x, x};
enum PixelEndian {
UNKNOWN,
AXXX,
XXXA,
};
media::VideoFramePool frame_pool_; media::VideoFramePool frame_pool_;
class FrameWriterDelegate; class FrameWriterDelegate;
scoped_refptr<FrameWriterDelegate> delegate_; scoped_refptr<FrameWriterDelegate> delegate_;
PixelEndian endian_;
DISALLOW_COPY_AND_ASSIGN(PpFrameWriter); DISALLOW_COPY_AND_ASSIGN(PpFrameWriter);
}; };
......
...@@ -224,7 +224,7 @@ void PepperVideoSourceHost::SendGetFrameReply() { ...@@ -224,7 +224,7 @@ void PepperVideoSourceHost::SendGetFrameReply() {
const uint8* src_v = frame->data(media::VideoFrame::kVPlane) + const uint8* src_v = frame->data(media::VideoFrame::kVPlane) +
(center * vert_crop + horiz_crop) / 2; (center * vert_crop + horiz_crop) / 2;
libyuv::I420ToBGRA(src_y, libyuv::I420ToARGB(src_y,
frame->stride(media::VideoFrame::kYPlane), frame->stride(media::VideoFrame::kYPlane),
src_u, src_u,
frame->stride(media::VideoFrame::kUPlane), frame->stride(media::VideoFrame::kUPlane),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment