Chromium Code Reviews| Index: content/renderer/media/video_destination_handler.cc |
| =================================================================== |
| --- content/renderer/media/video_destination_handler.cc (revision 0) |
| +++ content/renderer/media/video_destination_handler.cc (revision 0) |
| @@ -0,0 +1,128 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/media/video_destination_handler.h" |
| + |
| +#include <string> |
| + |
| +#include "base/logging.h" |
| +#include "content/renderer/media/media_stream_dependency_factory.h" |
| +#include "content/renderer/media/media_stream_registry_interface.h" |
| +#include "content/renderer/render_thread_impl.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistry.h" |
| + |
| +using cricket::CaptureState; |
| +using cricket::VideoFormat; |
| + |
| +static const cricket::FourCC kEffectColorFormat = cricket::FOURCC_BGRA; |
| + |
| +namespace content { |
| + |
| +PpFrameWriter::PpFrameWriter() |
| + : started_(false) {} |
| + |
| +PpFrameWriter::~PpFrameWriter() {} |
| + |
| +CaptureState PpFrameWriter::Start(const VideoFormat& capture_format) { |
| + if (started_) { |
| + LOG(ERROR) << "PpFrameWriter::Start - " |
| + << "Got a StartCapture when already started!"; |
| + return cricket::CS_FAILED; |
| + } |
| + started_ = true; |
| + return cricket::CS_STARTING; |
| +} |
| + |
| +void PpFrameWriter::Stop() { |
| + started_ = false; |
| + SignalStateChange(this, cricket::CS_STOPPED); |
| +} |
| + |
| +bool PpFrameWriter::IsRunning() { |
| + return started_; |
| +} |
| + |
| +bool PpFrameWriter::GetPreferredFourccs(std::vector<uint32>* fourccs) { |
| + if (!fourccs) { |
| + LOG(ERROR) << "PpFrameWriter::GetPreferredFourccs - " |
| + << "fourccs is NULL."; |
| + return false; |
| + } |
| + // The effects plugin output BGRA. |
| + fourccs->push_back(kEffectColorFormat); |
| + return true; |
| +} |
| + |
| +bool PpFrameWriter::GetBestCaptureFormat(const VideoFormat& desired, |
| + VideoFormat* best_format) { |
| + if (!best_format) { |
| + LOG(ERROR) << "PpFrameWriter::GetBestCaptureFormat - " |
| + << "best_format is NULL."; |
| + return false; |
| + return false; |
| + } |
| + |
| + // Use the desired format as the best format. |
| + // TODO(ronghuawu): How to handle this better? |
| + best_format->width = desired.width; |
| + best_format->height = desired.height; |
| + best_format->fourcc = kEffectColorFormat; |
| + best_format->interval = desired.interval; |
| + return true; |
| +} |
| + |
| +bool PpFrameWriter::IsScreencast() const { |
| + return false; |
| +} |
| + |
| +void PpFrameWriter::PutFrame(cricket::CapturedFrame* frame) { |
| + if (!started_) { |
|
wjia(left Chromium)
2013/04/30 18:32:11
Is there race condition to access |started_|? AFAI
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
Stop will be called from a libjingle worker thread
|
| + LOG(ERROR) << "Got a PutFrame when the capturer is not started!"; |
| + return; |
| + } |
| + |
| + // This signals to libJingle that a new VideoFrame is available. |
| + // libJingle have no assumptions on what thread this signal come from. |
| + SignalFrameCaptured(this, frame); |
| +} |
| + |
| +VideoDestinationHandler::VideoDestinationHandler( |
| + MediaStreamDependencyFactory* factory, |
| + MediaStreamRegistryInterface* registry) |
|
wjia(left Chromium)
2013/04/30 18:32:11
What's the life time of factory and registry? How
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
VideoDestinationHandler, the factory and the regis
|
| + : factory_(factory), |
| + registry_(registry) { |
| + ASSERT(factory_ != NULL); |
| +} |
| + |
| +bool VideoDestinationHandler::Open( |
| + const std::string& url, FrameWriterInterface** frame_writer) { |
| + WebKit::WebMediaStream stream; |
| + if (registry_) { |
| + stream = registry_->GetMediaStream(url); |
| + } else { |
| + stream = |
| + WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); |
| + } |
| + if (stream.isNull() || !stream.extraData()) { |
| + LOG(ERROR) << "VideoDestinationHandler::Open - invalid url: " << url; |
| + return false; |
| + } |
| + |
| + // Create a new native video track and add it to |stream|. |
| + std::string track_id = talk_base::ToString(talk_base::CreateRandomId64()); |
| + PpFrameWriter* capturer = new PpFrameWriter(); |
|
wjia(left Chromium)
2013/04/30 18:32:11
Does it make sense to make PpFrameWriter class int
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
It makes sense. But also what to have unit tests f
|
| + if (!factory_->AddNativeVideoMediaTrack(track_id, &stream, capturer)) { |
| + delete capturer; |
| + return false; |
| + } |
| + |
| + *frame_writer = capturer; |
| + return true; |
| +} |
| + |
| +VideoDestinationHandler::~VideoDestinationHandler() { |
| +} |
| + |
| +} // namespace content |
| + |
| Property changes on: content/renderer/media/video_destination_handler.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |