| 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/pepper/pepper_media_stream_video_track_host.h" | 5 #include "content/renderer/pepper/pepper_media_stream_video_track_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/c/ppb_video_frame.h" | 9 #include "ppapi/c/ppb_video_frame.h" |
| 10 #include "ppapi/shared_impl/media_stream_frame.h" | 10 #include "ppapi/shared_impl/media_stream_buffer.h" |
| 11 | 11 |
| 12 using media::VideoFrame; | 12 using media::VideoFrame; |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // TODO(penghuang): make it configurable. | 16 // TODO(penghuang): make it configurable. |
| 17 const int32_t kNumberOfFrames = 4; | 17 const int32_t kNumberOfFrames = 4; |
| 18 | 18 |
| 19 PP_VideoFrame_Format ToPpapiFormat(VideoFrame::Format format) { | 19 PP_VideoFrame_Format ToPpapiFormat(VideoFrame::Format format) { |
| 20 switch (format) { | 20 switch (format) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (ppformat == PP_VIDEOFRAME_FORMAT_UNKNOWN) | 70 if (ppformat == PP_VIDEOFRAME_FORMAT_UNKNOWN) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 if (frame_size_ != frame->coded_size() || frame_format_ != frame->format()) { | 73 if (frame_size_ != frame->coded_size() || frame_format_ != frame->format()) { |
| 74 frame_size_ = frame->coded_size(); | 74 frame_size_ = frame->coded_size(); |
| 75 frame_format_ = frame->format(); | 75 frame_format_ = frame->format(); |
| 76 // TODO(penghuang): Support changing |frame_size_| & |frame_format_| more | 76 // TODO(penghuang): Support changing |frame_size_| & |frame_format_| more |
| 77 // than once. | 77 // than once. |
| 78 DCHECK(!frame_data_size_); | 78 DCHECK(!frame_data_size_); |
| 79 frame_data_size_ = VideoFrame::AllocationSize(frame_format_, frame_size_); | 79 frame_data_size_ = VideoFrame::AllocationSize(frame_format_, frame_size_); |
| 80 int32_t size = sizeof(ppapi::MediaStreamFrame::Video) + frame_data_size_; | 80 int32_t size = sizeof(ppapi::MediaStreamBuffer::Video) + frame_data_size_; |
| 81 bool result = InitFrames(kNumberOfFrames, size); | 81 bool result = InitBuffers(kNumberOfFrames, size); |
| 82 // TODO(penghuang): Send PP_ERROR_NOMEMORY to plugin. | 82 // TODO(penghuang): Send PP_ERROR_NOMEMORY to plugin. |
| 83 CHECK(result); | 83 CHECK(result); |
| 84 } | 84 } |
| 85 | 85 |
| 86 int32_t index = frame_buffer()->DequeueFrame(); | 86 int32_t index = buffer_manager()->DequeueBuffer(); |
| 87 // Drop frames if the underlying buffer is full. | 87 // Drop frames if the underlying buffer is full. |
| 88 if (index < 0) | 88 if (index < 0) |
| 89 return; | 89 return; |
| 90 | 90 |
| 91 // TODO(penghuang): support format conversion and size scaling. | 91 // TODO(penghuang): support format conversion and size scaling. |
| 92 ppapi::MediaStreamFrame::Video* ppframe = | 92 ppapi::MediaStreamBuffer::Video* buffer = |
| 93 &(frame_buffer()->GetFramePointer(index)->video); | 93 &(buffer_manager()->GetBufferPointer(index)->video); |
| 94 ppframe->header.size = frame_buffer()->frame_size(); | 94 buffer->header.size = buffer_manager()->buffer_size(); |
| 95 ppframe->header.type = ppapi::MediaStreamFrame::TYPE_VIDEO; | 95 buffer->header.type = ppapi::MediaStreamBuffer::TYPE_VIDEO; |
| 96 ppframe->timestamp = frame->GetTimestamp().InSecondsF(); | 96 buffer->timestamp = frame->GetTimestamp().InSecondsF(); |
| 97 ppframe->format = ppformat; | 97 buffer->format = ppformat; |
| 98 ppframe->size.width = frame->coded_size().width(); | 98 buffer->size.width = frame->coded_size().width(); |
| 99 ppframe->size.height = frame->coded_size().height(); | 99 buffer->size.height = frame->coded_size().height(); |
| 100 ppframe->data_size = frame_data_size_; | 100 buffer->data_size = frame_data_size_; |
| 101 | 101 |
| 102 COMPILE_ASSERT(VideoFrame::kYPlane == 0, y_plane_should_be_0); | 102 COMPILE_ASSERT(VideoFrame::kYPlane == 0, y_plane_should_be_0); |
| 103 COMPILE_ASSERT(VideoFrame::kUPlane == 1, u_plane_should_be_1); | 103 COMPILE_ASSERT(VideoFrame::kUPlane == 1, u_plane_should_be_1); |
| 104 COMPILE_ASSERT(VideoFrame::kVPlane == 2, v_plane_should_be_2); | 104 COMPILE_ASSERT(VideoFrame::kVPlane == 2, v_plane_should_be_2); |
| 105 | 105 |
| 106 uint8_t* dst = ppframe->data; | 106 uint8_t* dst = buffer->data; |
| 107 size_t num_planes = VideoFrame::NumPlanes(frame->format()); | 107 size_t num_planes = VideoFrame::NumPlanes(frame->format()); |
| 108 for (size_t i = 0; i < num_planes; ++i) { | 108 for (size_t i = 0; i < num_planes; ++i) { |
| 109 const uint8_t* src = frame->data(i); | 109 const uint8_t* src = frame->data(i); |
| 110 const size_t row_bytes = frame->row_bytes(i); | 110 const size_t row_bytes = frame->row_bytes(i); |
| 111 const size_t src_stride = frame->stride(i); | 111 const size_t src_stride = frame->stride(i); |
| 112 int rows = frame->rows(i); | 112 int rows = frame->rows(i); |
| 113 for (int j = 0; j < rows; ++j) { | 113 for (int j = 0; j < rows; ++j) { |
| 114 memcpy(dst, src, row_bytes); | 114 memcpy(dst, src, row_bytes); |
| 115 dst += row_bytes; | 115 dst += row_bytes; |
| 116 src += src_stride; | 116 src += src_stride; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 SendEnqueueFrameMessageToPlugin(index); | 120 SendEnqueueBufferMessageToPlugin(index); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void PepperMediaStreamVideoTrackHost::DidConnectPendingHostToResource() { | 123 void PepperMediaStreamVideoTrackHost::DidConnectPendingHostToResource() { |
| 124 if (!connected_) { | 124 if (!connected_) { |
| 125 MediaStreamVideoSink::AddToVideoTrack(this, track_); | 125 MediaStreamVideoSink::AddToVideoTrack(this, track_); |
| 126 connected_ = true; | 126 connected_ = true; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace content | 130 } // namespace content |
| OLD | NEW |