Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/video_destination_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "content/renderer/media/media_stream_dependency_factory.h" | |
| 11 #include "content/renderer/media/media_stream_registry_interface.h" | |
| 12 #include "content/renderer/render_thread_impl.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" | |
| 14 | |
| 15 using cricket::CaptureState; | |
| 16 using cricket::VideoFormat; | |
| 17 | |
| 18 static const cricket::FourCC kEffectColorFormat = cricket::FOURCC_BGRA; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 PpFrameWriter::PpFrameWriter() | |
| 23 : started_(false) {} | |
| 24 | |
| 25 PpFrameWriter::~PpFrameWriter() {} | |
| 26 | |
| 27 CaptureState PpFrameWriter::Start(const VideoFormat& capture_format) { | |
| 28 if (started_) { | |
| 29 LOG(ERROR) << "PpFrameWriter::Start - " | |
| 30 << "Got a StartCapture when already started!"; | |
| 31 return cricket::CS_FAILED; | |
| 32 } | |
| 33 started_ = true; | |
| 34 return cricket::CS_STARTING; | |
| 35 } | |
| 36 | |
| 37 void PpFrameWriter::Stop() { | |
| 38 started_ = false; | |
| 39 SignalStateChange(this, cricket::CS_STOPPED); | |
| 40 } | |
| 41 | |
| 42 bool PpFrameWriter::IsRunning() { | |
| 43 return started_; | |
| 44 } | |
| 45 | |
| 46 bool PpFrameWriter::GetPreferredFourccs(std::vector<uint32>* fourccs) { | |
| 47 if (!fourccs) { | |
| 48 LOG(ERROR) << "PpFrameWriter::GetPreferredFourccs - " | |
| 49 << "fourccs is NULL."; | |
| 50 return false; | |
| 51 } | |
| 52 // The effects plugin output BGRA. | |
| 53 fourccs->push_back(kEffectColorFormat); | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 bool PpFrameWriter::GetBestCaptureFormat(const VideoFormat& desired, | |
| 58 VideoFormat* best_format) { | |
| 59 if (!best_format) { | |
| 60 LOG(ERROR) << "PpFrameWriter::GetBestCaptureFormat - " | |
| 61 << "best_format is NULL."; | |
| 62 return false; | |
| 63 return false; | |
|
juberti
2013/04/30 22:54:49
once is enough
Ronghua Wu (Left Chromium)
2013/04/30 23:07:14
indeed.
| |
| 64 } | |
| 65 | |
| 66 // Use the desired format as the best format. | |
| 67 // TODO(ronghuawu): How to handle this better? | |
|
juberti
2013/04/30 22:54:49
I think this approach is fine.
Ronghua Wu (Left Chromium)
2013/04/30 23:07:14
Done.
| |
| 68 best_format->width = desired.width; | |
| 69 best_format->height = desired.height; | |
| 70 best_format->fourcc = kEffectColorFormat; | |
| 71 best_format->interval = desired.interval; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 bool PpFrameWriter::IsScreencast() const { | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 void PpFrameWriter::PutFrame(cricket::CapturedFrame* frame) { | |
|
juberti
2013/04/30 22:54:49
Should this take an ImageData, so the surrounding
Ronghua Wu (Left Chromium)
2013/04/30 23:07:14
I talked to Bill about this he thought we should u
| |
| 80 // This signals to libJingle that a new VideoFrame is available. | |
| 81 // libJingle have no assumptions on what thread this signal come from. | |
| 82 SignalFrameCaptured(this, frame); | |
| 83 } | |
| 84 | |
| 85 VideoDestinationHandler::VideoDestinationHandler( | |
| 86 MediaStreamDependencyFactory* factory, | |
| 87 MediaStreamRegistryInterface* registry) | |
| 88 : factory_(factory), | |
| 89 registry_(registry) { | |
| 90 ASSERT(factory_ != NULL); | |
| 91 } | |
| 92 | |
| 93 bool VideoDestinationHandler::Open( | |
| 94 const std::string& url, FrameWriterInterface** frame_writer) { | |
| 95 WebKit::WebMediaStream stream; | |
| 96 if (registry_) { | |
| 97 stream = registry_->GetMediaStream(url); | |
| 98 } else { | |
| 99 stream = | |
| 100 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); | |
| 101 } | |
| 102 if (stream.isNull() || !stream.extraData()) { | |
| 103 LOG(ERROR) << "VideoDestinationHandler::Open - invalid url: " << url; | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 // Create a new native video track and add it to |stream|. | |
| 108 std::string track_id = talk_base::ToString(talk_base::CreateRandomId64()); | |
| 109 PpFrameWriter* capturer = new PpFrameWriter(); | |
| 110 if (!factory_->AddNativeVideoMediaTrack(track_id, &stream, capturer)) { | |
| 111 delete capturer; | |
| 112 return false; | |
| 113 } | |
| 114 | |
| 115 *frame_writer = capturer; | |
|
juberti
2013/04/30 22:54:49
should the capturer be Start()ed here, and stopped
Ronghua Wu (Left Chromium)
2013/04/30 23:07:14
Once a capturer is added to the video source, it w
| |
| 116 return true; | |
| 117 } | |
| 118 | |
| 119 VideoDestinationHandler::~VideoDestinationHandler() { | |
| 120 } | |
| 121 | |
| 122 } // namespace content | |
| 123 | |
| OLD | NEW |