| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/pepper_to_video_track_adapter.h" | 5 #include "content/renderer/media/pepper_to_video_track_adapter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
| 11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "content/renderer/media/media_stream.h" | 15 #include "content/renderer/media/media_stream.h" |
| 15 #include "content/renderer/media/media_stream_registry_interface.h" | 16 #include "content/renderer/media/media_stream_registry_interface.h" |
| 16 #include "content/renderer/media/media_stream_video_source.h" | 17 #include "content/renderer/media/media_stream_video_source.h" |
| 17 #include "content/renderer/media/media_stream_video_track.h" | 18 #include "content/renderer/media/media_stream_video_track.h" |
| 18 #include "content/renderer/pepper/ppb_image_data_impl.h" | 19 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 19 #include "content/renderer/render_thread_impl.h" | 20 #include "content/renderer/render_thread_impl.h" |
| 20 #include "media/base/video_capture_types.h" | 21 #include "media/base/video_capture_types.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 // Effects plugin) to inject the processed frame. | 34 // Effects plugin) to inject the processed frame. |
| 34 class PpFrameWriter : public MediaStreamVideoSource, | 35 class PpFrameWriter : public MediaStreamVideoSource, |
| 35 public FrameWriterInterface, | 36 public FrameWriterInterface, |
| 36 public base::SupportsWeakPtr<PpFrameWriter> { | 37 public base::SupportsWeakPtr<PpFrameWriter> { |
| 37 public: | 38 public: |
| 38 PpFrameWriter(); | 39 PpFrameWriter(); |
| 39 ~PpFrameWriter() override; | 40 ~PpFrameWriter() override; |
| 40 | 41 |
| 41 // FrameWriterInterface implementation. | 42 // FrameWriterInterface implementation. |
| 42 // This method will be called by the Pepper host from render thread. | 43 // This method will be called by the Pepper host from render thread. |
| 43 void PutFrame(PPB_ImageData_Impl* image_data, int64 time_stamp_ns) override; | 44 void PutFrame(PPB_ImageData_Impl* image_data, int64_t time_stamp_ns) override; |
| 44 | 45 |
| 45 protected: | 46 protected: |
| 46 // MediaStreamVideoSource implementation. | 47 // MediaStreamVideoSource implementation. |
| 47 void GetCurrentSupportedFormats( | 48 void GetCurrentSupportedFormats( |
| 48 int max_requested_width, | 49 int max_requested_width, |
| 49 int max_requested_height, | 50 int max_requested_height, |
| 50 double max_requested_frame_rate, | 51 double max_requested_frame_rate, |
| 51 const VideoCaptureDeviceFormatsCB& callback) override; | 52 const VideoCaptureDeviceFormatsCB& callback) override; |
| 52 void StartSourceImpl( | 53 void StartSourceImpl( |
| 53 const media::VideoCaptureFormat& format, | 54 const media::VideoCaptureFormat& format, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 OnStartDone(MEDIA_DEVICE_OK); | 139 OnStartDone(MEDIA_DEVICE_OK); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void PpFrameWriter::StopSourceImpl() { | 142 void PpFrameWriter::StopSourceImpl() { |
| 142 DCHECK(CalledOnValidThread()); | 143 DCHECK(CalledOnValidThread()); |
| 143 } | 144 } |
| 144 | 145 |
| 145 // Note: PutFrame must copy or process image_data directly in this function, | 146 // Note: PutFrame must copy or process image_data directly in this function, |
| 146 // because it may be overwritten as soon as we return from this function. | 147 // because it may be overwritten as soon as we return from this function. |
| 147 void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data, | 148 void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data, |
| 148 int64 time_stamp_ns) { | 149 int64_t time_stamp_ns) { |
| 149 DCHECK(CalledOnValidThread()); | 150 DCHECK(CalledOnValidThread()); |
| 150 TRACE_EVENT0("video", "PpFrameWriter::PutFrame"); | 151 TRACE_EVENT0("video", "PpFrameWriter::PutFrame"); |
| 151 DVLOG(3) << "PpFrameWriter::PutFrame()"; | 152 DVLOG(3) << "PpFrameWriter::PutFrame()"; |
| 152 | 153 |
| 153 if (!image_data) { | 154 if (!image_data) { |
| 154 LOG(ERROR) << "PpFrameWriter::PutFrame - Called with NULL image_data."; | 155 LOG(ERROR) << "PpFrameWriter::PutFrame - Called with NULL image_data."; |
| 155 return; | 156 return; |
| 156 } | 157 } |
| 157 ImageDataAutoMapper mapper(image_data); | 158 ImageDataAutoMapper mapper(image_data); |
| 158 if (!mapper.is_valid()) { | 159 if (!mapper.is_valid()) { |
| 159 LOG(ERROR) << "PpFrameWriter::PutFrame - " | 160 LOG(ERROR) << "PpFrameWriter::PutFrame - " |
| 160 << "The image could not be mapped and is unusable."; | 161 << "The image could not be mapped and is unusable."; |
| 161 return; | 162 return; |
| 162 } | 163 } |
| 163 const SkBitmap* bitmap = image_data->GetMappedBitmap(); | 164 const SkBitmap* bitmap = image_data->GetMappedBitmap(); |
| 164 if (!bitmap) { | 165 if (!bitmap) { |
| 165 LOG(ERROR) << "PpFrameWriter::PutFrame - " | 166 LOG(ERROR) << "PpFrameWriter::PutFrame - " |
| 166 << "The image_data's mapped bitmap is NULL."; | 167 << "The image_data's mapped bitmap is NULL."; |
| 167 return; | 168 return; |
| 168 } | 169 } |
| 169 | 170 |
| 170 const uint8* src_data = static_cast<uint8*>(bitmap->getPixels()); | 171 const uint8_t* src_data = static_cast<uint8_t*>(bitmap->getPixels()); |
| 171 const int src_stride = static_cast<int>(bitmap->rowBytes()); | 172 const int src_stride = static_cast<int>(bitmap->rowBytes()); |
| 172 const int width = bitmap->width(); | 173 const int width = bitmap->width(); |
| 173 const int height = bitmap->height(); | 174 const int height = bitmap->height(); |
| 174 | 175 |
| 175 // We only support PP_IMAGEDATAFORMAT_BGRA_PREMUL at the moment. | 176 // We only support PP_IMAGEDATAFORMAT_BGRA_PREMUL at the moment. |
| 176 DCHECK(image_data->format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL); | 177 DCHECK(image_data->format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL); |
| 177 | 178 |
| 178 const gfx::Size frame_size(width, height); | 179 const gfx::Size frame_size(width, height); |
| 179 | 180 |
| 180 if (state() != MediaStreamVideoSource::STARTED) | 181 if (state() != MediaStreamVideoSource::STARTED) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 206 // is released). | 207 // is released). |
| 207 class PpFrameWriterProxy : public FrameWriterInterface { | 208 class PpFrameWriterProxy : public FrameWriterInterface { |
| 208 public: | 209 public: |
| 209 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) | 210 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) |
| 210 : writer_(writer) { | 211 : writer_(writer) { |
| 211 DCHECK(writer_ != NULL); | 212 DCHECK(writer_ != NULL); |
| 212 } | 213 } |
| 213 | 214 |
| 214 ~PpFrameWriterProxy() override {} | 215 ~PpFrameWriterProxy() override {} |
| 215 | 216 |
| 216 void PutFrame(PPB_ImageData_Impl* image_data, int64 time_stamp_ns) override { | 217 void PutFrame(PPB_ImageData_Impl* image_data, |
| 218 int64_t time_stamp_ns) override { |
| 217 writer_->PutFrame(image_data, time_stamp_ns); | 219 writer_->PutFrame(image_data, time_stamp_ns); |
| 218 } | 220 } |
| 219 | 221 |
| 220 private: | 222 private: |
| 221 base::WeakPtr<PpFrameWriter> writer_; | 223 base::WeakPtr<PpFrameWriter> writer_; |
| 222 | 224 |
| 223 DISALLOW_COPY_AND_ASSIGN(PpFrameWriterProxy); | 225 DISALLOW_COPY_AND_ASSIGN(PpFrameWriterProxy); |
| 224 }; | 226 }; |
| 225 | 227 |
| 226 bool PepperToVideoTrackAdapter::Open(MediaStreamRegistryInterface* registry, | 228 bool PepperToVideoTrackAdapter::Open(MediaStreamRegistryInterface* registry, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 267 |
| 266 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 268 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( |
| 267 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 269 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
| 268 track_enabled)); | 270 track_enabled)); |
| 269 | 271 |
| 270 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); | 272 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); |
| 271 return true; | 273 return true; |
| 272 } | 274 } |
| 273 | 275 |
| 274 } // namespace content | 276 } // namespace content |
| OLD | NEW |